juergen     02/03/13 01:22:38

  Modified:    src/webdav/server/org/apache/slide/webdav/util
                        PropertyRetrieverImpl.java
  Log:
  Method(s) getPropertiesOfObject() now returns a List of <propstat> Elements instead 
of a single one.
  Added a signature that takes the NodeRevisionDescriptors and NodeRevisionDescriptor 
(needed for PropfindMethod).
  Also fixed bug in the area of computing the DeltaV properties.
  (ralf)
  
  Revision  Changes    Path
  1.5       +110 -89   
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java
  
  Index: PropertyRetrieverImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PropertyRetrieverImpl.java        12 Mar 2002 07:22:02 -0000      1.4
  +++ PropertyRetrieverImpl.java        13 Mar 2002 09:22:38 -0000      1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java,v
 1.4 2002/03/12 07:22:02 juergen Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/03/12 07:22:02 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java,v
 1.5 2002/03/13 09:22:38 juergen Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/03/13 09:22:38 $
    *
    * ====================================================================
    *
  @@ -117,6 +117,8 @@
   import java.util.Enumeration;
   import java.util.Date;
   import java.util.Set;
  +import java.util.List;
  +import java.util.ArrayList;
   
   import org.jdom.Document;
   import org.jdom.Element;
  @@ -132,7 +134,7 @@
    * providing property information (<code>PropFindMethod</code>,
    * <code>ReportMethod</code>) should use this class.
    *
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Ralf Stuckert</a>
    */
  @@ -173,6 +175,8 @@
       protected static SAXBuilder saxBuilder = null;
       
       
  +    private static final String START_TAG = "<root>";
  +    private static final String END_TAG = "</root>";
       
       /**
        * The NamespaceAccessToken used to access the helpers.
  @@ -268,26 +272,41 @@
   
       /**
        * Converts the XML written into the <code>XMLPrinter</code> to a
  -     * JDOM document.
  +     * list of JDOM Elements.
        *
        * @param      xmlPrinter  the XMLPrinter which contains the XML as a String.
        *
  -     * @return     the JDOM Document that represents the XML written into the
  +     * @return     the list of Elements that represents the XML written into the
        *             given <code>XMLPrinter</code>
        *
        * @throws     JDOMException  if the transforming the String into a
        *                            JDOM Document fails.
        */
  -    protected Document getJDOMDocumentFromXMLPrinter(XMLPrinter xmlPrinter) throws 
JDOMException {
  -        return getSAXBuilder().build(new StringReader(xmlPrinter.toString()));
  +    protected List getElementListFromXMLPrinter(XMLPrinter xmlPrinter) throws 
JDOMException {
  +        
  +        String xmlString = xmlPrinter.toString();
  +        StringBuffer buffer = new StringBuffer(START_TAG.length() + 
xmlString.length() + END_TAG.length());
  +        buffer.append(START_TAG);
  +        buffer.append(xmlString);
  +        buffer.append(END_TAG);
  +        Document document = getSAXBuilder().build(new 
StringReader(buffer.toString()));
  +        
  +        List children = document.getRootElement().getChildren();
  +        List clonedChildren = new ArrayList(children.size());
  +        Iterator iterator = children.iterator();
  +        while (iterator.hasNext()) {
  +            clonedChildren.add(((Element)iterator.next()).clone());
  +        }
  +        
  +        return clonedChildren;
       }
       
       
       
       /**
  -     * Returnes the requested properties of the last revision of the resource
  -     * identified by the given <code>uri</code> as an XML JDOM Element (which
  -     * is the <code>&lt;propstat&gt;</code>).
  +     * Returns the requested properties of the last revision of the resource
  +     * identified by the given <code>uri</code> as list of 
<code>&lt;propstat&gt;</code>
  +     * JDOM Elements.
        *
        * @param      requestedProperties  the requested properties.
        * @param      uri                  the URI of the resource.
  @@ -299,7 +318,8 @@
        *                                    properties should be included in case
        *                                    all properties are requested.
        *
  -     * @return     the requested properties as an XML JDOM Element.
  +     * @return     the requested properties as list of <code>&lt;propstat&gt;</code>
  +     *             JDOM Element.
        *
        * @throws     ObjectLockedException
        * @throws     ServiceAccessException
  @@ -310,21 +330,59 @@
        * @throws     LockTokenNotFoundException
        * @throws     JDOMException  if creating the JDOM Element fails.
        */
  -    public Element getPropertiesOfObject(RequestedProperties requestedProperties, 
String uri, String contextPath, String serverURL, boolean allpropSupportsDeltaV) 
throws ObjectLockedException, ServiceAccessException, LinkedObjectNotFoundException, 
AccessDeniedException, ObjectNotFoundException, RevisionDescriptorNotFoundException, 
LockTokenNotFoundException, JDOMException  {
  +    public List getPropertiesOfObject(RequestedProperties requestedProperties, 
String uri, String contextPath, String serverURL, boolean allpropSupportsDeltaV) 
throws ObjectLockedException, ServiceAccessException, LinkedObjectNotFoundException, 
AccessDeniedException, ObjectNotFoundException, RevisionDescriptorNotFoundException, 
LockTokenNotFoundException, JDOMException  {
           
  -        XMLPrinter xmlPrinter = new XMLPrinter();
  -        writePropertiesOfObject(requestedProperties, uri, contextPath, serverURL, 
allpropSupportsDeltaV, xmlPrinter);
  +        NodeRevisionDescriptors revisionDescriptors = null;
  +        NodeRevisionDescriptor revisionDescriptor = null;
  +        
  +        boolean isCollection = false;
  +        
  +        try {
  +            revisionDescriptors =
  +                content.retrieve(slideToken, uri);
  +            
  +            try {
  +                
  +                revisionDescriptor = content.retrieve(slideToken,
  +                                                      revisionDescriptors);
  +                isCollection = WebdavUtils.isCollection(revisionDescriptor);
  +                
  +                
  +            } catch (RevisionDescriptorNotFoundException e) {
  +                
  +                // The object doesn't have any revision, we create a dummy
  +                // NodeRevisionDescriptor object
  +                isCollection = true;
  +                revisionDescriptor = new NodeRevisionDescriptor(0);
           
  -        return (Element) 
getJDOMDocumentFromXMLPrinter(xmlPrinter).getRootElement().clone();
  +                String resourceName = uri;
  +                int lastSlash = resourceName.lastIndexOf('/');
  +                if (lastSlash != -1)
  +                    resourceName = resourceName.substring(lastSlash + 1);
  +                revisionDescriptor.setName(resourceName);
  +            }
  +            
  +        } catch (AccessDeniedException e) {
  +            if (revisionDescriptor == null) {
  +                revisionDescriptor = new NodeRevisionDescriptor(0);
  +            }
  +        }
  +        //      catch (Exception e) {
  +        //          // resp.setStatus(getErrorCode(e));
  +        //          throw new WebdavException(getErrorCode(e)); // abort the TA
  +        //      }
  +        
  +        return getPropertiesOfObject(requestedProperties, revisionDescriptors, 
revisionDescriptor, contextPath, serverURL, allpropSupportsDeltaV);
       }
       
       /**
  -     * Returnes the requested properties of the resource identified by the given
  -     * <code>uri</code> and <code>revisionNumber</code> as an XML Document (starting
  -     * with the <code>&lt;propstat&gt;</code>).
  +     * Returns the requested properties of the resource identified by the given
  +     * <code>uri</code> and <code>revisionNumber</code> as list of
  +     * <code>&lt;propstat&gt;</code> JDOM Elements.
        *
        * @param      requestedProperties  the requested properties.
        * @param      uri                  the URI of the resource.
  +     * @param      revisionNumber       the revision number of the requested 
resource.
        * @param      contextPath          the context path of the uri. The 
concatenation of
        *                                  
<code>serverURL</code>/<code>contextPath</code>
        *                                  /<code>uri</code> gives the absolute URL of 
the resource.
  @@ -333,6 +391,9 @@
        *                                    properties should be included in case
        *                                    all properties are requested.
        *
  +     * @return     the requested properties as list of <code>&lt;propstat&gt;</code>
  +     *             JDOM Element.
  +     *
        * @throws     ObjectLockedException
        * @throws     ServiceAccessException
        * @throws     LinkedObjectNotFoundException
  @@ -342,22 +403,23 @@
        * @throws     LockTokenNotFoundException
        * @throws     JDOMException  if creating the JDOM Element fails.
        */
  -    public Element getPropertiesOfObject(RequestedProperties requestedProperties, 
String uri, NodeRevisionNumber revisionNumber, String contextPath, String serverURL, 
boolean allpropSupportsDeltaV) throws ObjectLockedException, ServiceAccessException, 
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, 
RevisionDescriptorNotFoundException, LockTokenNotFoundException, JDOMException {
  +    public List getPropertiesOfObject(RequestedProperties requestedProperties, 
String uri, NodeRevisionNumber revisionNumber, String contextPath, String serverURL, 
boolean allpropSupportsDeltaV) throws ObjectLockedException, ServiceAccessException, 
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, 
RevisionDescriptorNotFoundException, LockTokenNotFoundException, JDOMException {
   
  -        XMLPrinter xmlPrinter = new XMLPrinter();
  -        writePropertiesOfObject(requestedProperties, uri, revisionNumber, 
contextPath, serverURL, allpropSupportsDeltaV, xmlPrinter);
  -        
  -        return (Element) 
getJDOMDocumentFromXMLPrinter(xmlPrinter).getRootElement().clone();
  +        NodeRevisionDescriptors revisionDescriptors = content.retrieve(slideToken, 
uri);
  +        NodeRevisionDescriptor revisionDescriptor = content.retrieve(slideToken,
  +                                                                     
revisionDescriptors,
  +                                                                     
revisionNumber);
  +        return getPropertiesOfObject(requestedProperties, revisionDescriptors, 
revisionDescriptor, contextPath, serverURL, allpropSupportsDeltaV);
       }
       
  -    
       /**
  -     * Writes the requested properties of the last revision of the resource
  -     * identified by the given <code>uri</code> as an XML text (starting with
  -     * the <code>&lt;propstat&gt;</code>) into the given <code>XMLPrinter</code>.
  +     * Returns the requested properties of the resource identified by the given
  +     * <code>uri</code> and <code>revisionNumber</code> as list of
  +     * <code>&lt;propstat&gt;</code> JDOM Elements.
        *
        * @param      requestedProperties  the requested properties.
  -     * @param      uri                  the URI of the resource.
  +     * @param      revisionDescriptors    the NodeRevisionDescriptors of the 
resource.
  +     * @param      revisionDescriptor     the NodeRevisionDescriptor of the 
resource.
        * @param      contextPath          the context path of the uri. The 
concatenation of
        *                                  
<code>serverURL</code>/<code>contextPath</code>
        *                                  /<code>uri</code> gives the absolute URL of 
the resource.
  @@ -365,7 +427,9 @@
        * @param      allpropSupportsDeltaV  indicates if the <code>DeltaV</code> 
specific
        *                                    properties should be included in case
        *                                    all properties are requested.
  -     * @param      generatedXML         the XMLPrinter to write the output to.
  +     *
  +     * @return     the requested properties as list of <code>&lt;propstat&gt;</code>
  +     *             JDOM Element.
        *
        * @throws     ObjectLockedException
        * @throws     ServiceAccessException
  @@ -374,50 +438,13 @@
        * @throws     ObjectNotFoundException
        * @throws     RevisionDescriptorNotFoundException
        * @throws     LockTokenNotFoundException
  +     * @throws     JDOMException  if creating the JDOM Element fails.
        */
  -    public void writePropertiesOfObject(RequestedProperties requestedProperties, 
String uri, String contextPath, String serverURL, boolean allpropSupportsDeltaV, 
XMLPrinter generatedXML) throws ObjectLockedException, ServiceAccessException, 
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, 
RevisionDescriptorNotFoundException, LockTokenNotFoundException  {
  -        
  -        NodeRevisionDescriptors revisionDescriptors = null;
  -        NodeRevisionDescriptor revisionDescriptor = null;
  -        
  -        boolean isCollection = false;
  -        
  -        try {
  -            revisionDescriptors =
  -                content.retrieve(slideToken, uri);
  -            
  -            try {
  -                
  -                revisionDescriptor = content.retrieve(slideToken,
  -                                                      revisionDescriptors);
  -                isCollection = WebdavUtils.isCollection(revisionDescriptor);
  -                
  -                
  -            } catch (RevisionDescriptorNotFoundException e) {
  -                
  -                // The object doesn't have any revision, we create a dummy
  -                // NodeRevisionDescriptor object
  -                isCollection = true;
  -                revisionDescriptor = new NodeRevisionDescriptor(0);
  -                
  -                String resourceName = uri;
  -                int lastSlash = resourceName.lastIndexOf('/');
  -                if (lastSlash != -1)
  -                    resourceName = resourceName.substring(lastSlash + 1);
  -                revisionDescriptor.setName(resourceName);
  -            }
  -            
  -        } catch (AccessDeniedException e) {
  -            if (revisionDescriptor == null) {
  -                revisionDescriptor = new NodeRevisionDescriptor(0);
  -            }
  -        }
  -//      catch (Exception e) {
  -//          // resp.setStatus(getErrorCode(e));
  -//          throw new WebdavException(getErrorCode(e)); // abort the TA
  -//      }
  +    public List getPropertiesOfObject(RequestedProperties requestedProperties, 
NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor 
revisionDescriptor, String contextPath, String serverURL, boolean 
allpropSupportsDeltaV) throws ObjectLockedException, ServiceAccessException, 
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException, 
RevisionDescriptorNotFoundException, LockTokenNotFoundException, JDOMException {
           
  -        writePropertiesOfObject(requestedProperties, uri, 
revisionDescriptor.getRevisionNumber(), contextPath, serverURL, allpropSupportsDeltaV, 
generatedXML);
  +        XMLPrinter xmlPrinter = new XMLPrinter();
  +        writePropertiesOfObject(requestedProperties, revisionDescriptors, 
revisionDescriptor, contextPath, serverURL, allpropSupportsDeltaV, xmlPrinter);
  +        return getElementListFromXMLPrinter(xmlPrinter);
       }
       
       
  @@ -428,7 +455,8 @@
        * with the generatedXML.writeElement(null, DEFAULT_NAMESPACE</code>) into the 
given <code>XMLPrinter</code>.
        *
        * @param      requestedProperties    the requested properties.
  -     * @param      uri                    the URI of the resource.
  +     * @param      revisionDescriptors    the NodeRevisionDescriptors of the 
resource.
  +     * @param      revisionDescriptor     the NodeRevisionDescriptor of the 
resource.
        * @param      contextPath          the context path of the uri. The 
concatenation of
        *                                  
<code>serverURL</code>/<code>contextPath</code>
        *                                  /<code>uri</code> gives the absolute URL of 
the resource.
  @@ -446,27 +474,19 @@
        * @throws     RevisionDescriptorNotFoundException
        * @throws     LockTokenNotFoundException
        */
  -    public void writePropertiesOfObject(RequestedProperties requestedProperties, 
String uri, NodeRevisionNumber revisionNumber, String contextPath, String serverURL, 
boolean allpropSupportsDeltaV, XMLPrinter generatedXML) throws ObjectLockedException, 
ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, 
ObjectNotFoundException, RevisionDescriptorNotFoundException, 
LockTokenNotFoundException {
  +    public void writePropertiesOfObject(RequestedProperties requestedProperties, 
NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor 
revisionDescriptor, String contextPath, String serverURL, boolean 
allpropSupportsDeltaV, XMLPrinter generatedXML) throws ObjectLockedException, 
ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, 
ObjectNotFoundException, RevisionDescriptorNotFoundException, 
LockTokenNotFoundException {
           
           String status = new String("HTTP/1.1 " + WebdavStatus.SC_OK + " "
                                          + WebdavStatus.getStatusText
                                          (WebdavStatus.SC_OK));
  -        NodeRevisionDescriptors revisionDescriptors = null;
  -        NodeRevisionDescriptor revisionDescriptor = null;
           
           boolean isCollection = false;
  -        
           NodeLock objectLockToken = null;
           
   //      try {
  -        revisionDescriptors = content.retrieve(slideToken, uri);
  -        
  -        revisionDescriptor = content.retrieve(slideToken,
  -                                              revisionDescriptors,
  -                                              revisionNumber);
           isCollection = WebdavUtils.isCollection(revisionDescriptor);
           
  -        Enumeration lockTokens = lock.enumerateLocks(slideToken, uri, true);
  +        Enumeration lockTokens = lock.enumerateLocks(slideToken, 
revisionDescriptors.getUri(), true);
           if (lockTokens.hasMoreElements()) {
               objectLockToken = (NodeLock) lockTokens.nextElement();
           }
  @@ -480,7 +500,7 @@
           
           ObjectNode object = null;
   //      try {
  -        object = structure.retrieve(slideToken, uri);
  +        object = structure.retrieve(slideToken, revisionDescriptors.getUri());
   //      }
   //      catch (SlideException e) {
   //          throw new WebdavException(WebdavStatus.SC_NOT_FOUND);
  @@ -654,8 +674,8 @@
                   }
                       
                       // now the computed (DeltaV) properties
  -                else if (resourceKind.isSupportedLiveProperty(property.getName())) {
  -                    writeLiveProperty(property.getName(), revisionDescriptors, 
revisionDescriptor, contextPath, serverURL, propertyHelper, generatedXML);
  +                else if 
(resourceKind.getSupportedLiveProperties(Q_COMPUTED_ONLY).contains(property.getName()))
 {
  +                    writeComputedProperty(property.getName(), revisionDescriptors, 
revisionDescriptor, contextPath, serverURL, propertyHelper, generatedXML);
                   }
                       
                   else {
  @@ -665,6 +685,7 @@
                       NodeProperty currentProperty =
                           revisionDescriptor.getProperty(property.getName(),
                                                          property.getNamespace());
  +                    
                       if (currentProperty != null) {
                           writeSingleProperty(generatedXML, currentProperty, 
contextPath, serverURL);
                       } else {
  @@ -1552,7 +1573,7 @@
       }
       
       /**
  -     * Writes the specified (live) property to the given XMLPrinter.
  +     * Writes the specified computed property to the given XMLPrinter.
        *
        * @param      propertyName
        * @param      revisionDescriptors
  @@ -1572,7 +1593,7 @@
        * @throws     RevisionDescriptorNotFoundException
        * @throws     LockTokenNotFoundException
        */
  -    protected void writeLiveProperty(String propertyName, NodeRevisionDescriptors 
revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String contextPath, 
String serverURL, PropertyHelper propertyHelper, XMLPrinter generatedXML) throws 
ObjectLockedException, ServiceAccessException, LinkedObjectNotFoundException, 
AccessDeniedException, ObjectNotFoundException, RevisionDescriptorNotFoundException, 
LockTokenNotFoundException {
  +    protected void writeComputedProperty(String propertyName, 
NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor 
revisionDescriptor, String contextPath, String serverURL, PropertyHelper 
propertyHelper, XMLPrinter generatedXML) throws ObjectLockedException, 
ServiceAccessException, LinkedObjectNotFoundException, AccessDeniedException, 
ObjectNotFoundException, RevisionDescriptorNotFoundException, 
LockTokenNotFoundException {
   
           NodeProperty property = propertyHelper.getProperty(propertyName, 
revisionDescriptors, revisionDescriptor, contextPath, serverURL);
           if (property != null) {
  @@ -1608,7 +1629,7 @@
           Set computedLivePropertyNames = 
resourceKind.getSupportedLiveProperties(Q_COMPUTED_ONLY, new String[] 
{F_ACCESS_CONTROL, F_LOCKING, F_UPDATE});
           Iterator iterator = computedLivePropertyNames.iterator();
           while (iterator.hasNext()) {
  -            writeLiveProperty((String)iterator.next(), revisionDescriptors, 
revisionDescriptor, contextPath, serverURL, propertyHelper, generatedXML);
  +            writeComputedProperty((String)iterator.next(), revisionDescriptors, 
revisionDescriptor, contextPath, serverURL, propertyHelper, generatedXML);
           }
   }
       
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to