You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2002/09/23 15:28:55 UTC

cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/util PropertyRetrieverImpl.java

juergen     2002/09/23 06:28:54

  Modified:    src/webdav/server/org/apache/slide/webdav/util
                        PropertyRetrieverImpl.java
  Log:
  Do not (re-) throw AccessDeniedException but create a <propstat> element with an appropriate status text.
  (ralf)
  
  Revision  Changes    Path
  1.25      +113 -42   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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- PropertyRetrieverImpl.java	5 Aug 2002 12:25:55 -0000	1.24
  +++ PropertyRetrieverImpl.java	23 Sep 2002 13:28:54 -0000	1.25
  @@ -112,6 +112,8 @@
   import java.util.Set;
   import java.util.List;
   import java.util.ArrayList;
  +import java.util.Map;
  +import java.util.HashMap;
   
   import org.jdom.Document;
   import org.jdom.Element;
  @@ -388,28 +390,44 @@
               Element propertyElement = null;
           boolean anyPropertyFound = false;
               
  +        // maps the code of the error (that occurred when retrieving the property)
  +        // to the List of RequestedProperty that caused that error
  +        Map erroneousPropertiesMap = new HashMap();
  +        
           String status = new String("HTTP/1.1 " + WebdavStatus.SC_OK
                                       + " " + WebdavStatus.getStatusText
                                       (WebdavStatus.SC_OK));
               
  -            Vector propertiesNotFoundVector = new Vector();
  +        while (propertyIterator.hasNext()) {
               
  -            while (propertyIterator.hasNext()) {
                   RequestedProperty property = (RequestedProperty)propertyIterator.next();
  -                
  -                    
  -                    NodeProperty currentProperty =
  -                requestedResource.getProperty(property.getName(),
  +            NodeProperty currentProperty = null;
  +            Integer errorCode = null;
  +            try {
  +                currentProperty = requestedResource.getProperty(property.getName(),
                                                          property.getNamespace());
  +                if (currentProperty == null) {
  +                    errorCode = new Integer(WebdavStatus.SC_NOT_FOUND);
  +                }
  +            }
  +            catch (AccessDeniedException e) {
  +                errorCode = new Integer(WebdavStatus.SC_FORBIDDEN);
  +            }
                       
  -                    if (currentProperty != null) {
  +            if (errorCode != null) {
  +                List erroneousPropertiesList = (List)erroneousPropertiesMap.get(errorCode);
  +                if (erroneousPropertiesList == null) {
  +                    erroneousPropertiesList = new ArrayList();
  +                    erroneousPropertiesMap.put(errorCode, erroneousPropertiesList);
  +                }
  +                erroneousPropertiesList.add(new PropertyName(property.getName(), property.getNamespace()));
  +            }
  +            else {
                           propertyElement = getPropertyElement(currentProperty, contextPath, serverURL);
                   if (propertyElement != null) {
                       anyPropertyFound = true;
                       prop.addContent(propertyElement);
                   }
  -                    } else {
  -                        propertiesNotFoundVector.addElement(property);
                       }
                   }
               
  @@ -420,35 +438,8 @@
               elementList.add(propstat);
           }
               
  +        elementList.addAll(getPropstatForErroneousProperties(erroneousPropertiesMap, contextPath, serverURL));
               
  -        Enumeration propertiesNotFoundEnum = propertiesNotFoundVector.elements();
  -            if (propertiesNotFoundEnum.hasMoreElements()) {
  -                
  -                propstat = new Element(E_PROPSTAT, NamespaceCache.DEFAULT_NAMESPACE);
  -                elementList.add(propstat);
  -                prop = new Element(E_PROP, NamespaceCache.DEFAULT_NAMESPACE);
  -                propstat.addContent(prop);
  -                
  -                status = new String("HTTP/1.1 " + WebdavStatus.SC_NOT_FOUND
  -                                        + " " + WebdavStatus.getStatusText
  -                                        (WebdavStatus.SC_NOT_FOUND));
  -                
  -                
  -                while (propertiesNotFoundEnum.hasMoreElements()) {
  -                    RequestedProperty propertyNotFound =
  -                        (RequestedProperty) propertiesNotFoundEnum.nextElement();
  -                    propertyElement = getPropertyElement(propertyNotFound.getNamespace(),
  -                                                         propertyNotFound.getName(),
  -                                                         null,
  -                                                         contextPath,
  -                                                         serverURL);
  -                    if (propertyElement != null) {prop.addContent(propertyElement);}
  -                }
  -                
  -            Element statusElement = new Element(E_STATUS, NamespaceCache.DEFAULT_NAMESPACE);
  -                statusElement.setText(status);
  -                propstat.addContent(statusElement);
  -            }
           return elementList;
       }
       
  @@ -480,6 +471,11 @@
           propstat.addContent(prop);
           Element propertyElement = null;
           
  +        // maps the code of the error (that occurred when retrieving the property)
  +        // to the List of RequestedProperty that caused that error
  +        Map erroneousPropertiesMap = new HashMap();
  +        
  +        
           String status = new String("HTTP/1.1 " + WebdavStatus.SC_OK
                                          + " " + WebdavStatus.getStatusText
                                          (WebdavStatus.SC_OK));
  @@ -501,15 +497,90 @@
                       continue;
                   }
                   
  -                propertyElement = getPropertyElement(requestedResource.getProperty(currentPropertyName), contextPath, serverURL);
  +                NodeProperty currentProperty = null;
  +                Integer errorCode = null;
  +                try {
  +                    currentProperty = requestedResource.getProperty(currentPropertyName);
  +                    if (currentProperty == null) {
  +                        errorCode = new Integer(WebdavStatus.SC_NOT_FOUND);
  +                    }
  +                }
  +                catch (AccessDeniedException e) {
  +                    errorCode = new Integer(WebdavStatus.SC_FORBIDDEN);
  +                }
  +                
  +                if (errorCode != null) {
  +                    List erroneousPropertiesList = (List)erroneousPropertiesMap.get(errorCode);
  +                    if (erroneousPropertiesList == null) {
  +                        erroneousPropertiesList = new ArrayList();
  +                        erroneousPropertiesMap.put(errorCode, erroneousPropertiesList);
  +                    }
  +                    erroneousPropertiesList.add(currentPropertyName);
  +                }
  +                else {
  +                    propertyElement = getPropertyElement(currentProperty, contextPath, serverURL);
                   if (propertyElement != null) {prop.addContent(propertyElement);}
               }
           }
  +        }
           
           
           Element statusElement = new Element(E_STATUS, NamespaceCache.DEFAULT_NAMESPACE);
           statusElement.setText(status);
           propstat.addContent(statusElement);
  +        
  +        elementList.addAll(getPropstatForErroneousProperties(erroneousPropertiesMap, contextPath, serverURL));
  +        
  +        return elementList;
  +    }
  +    
  +    /**
  +     * Returns a list of <code>&lt;propstat&gt;</code> JDOM Elements for the properties
  +     * that could not be retrieved due to an error.
  +     *
  +     * @param      erroneousPropertiesMap  maps the (Integer) code of the error (that occurred
  +     *                                     when retrieving the property) to the List of
  +     *                                     PropertyName that caused that error.
  +     * @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.
  +     * @param      serverURL               the URL of the server (e.g. <code>http://www.abc.com</code>).
  +     *
  +     * @return     A List of <code>&lt;propstat&gt;</code> JDOM Elements for the erroneous properties.
  +     */
  +    protected List getPropstatForErroneousProperties(Map erroneousPropertiesMap, String contextPath, String serverURL) {
  +        
  +        List elementList = new ArrayList();
  +        Iterator iterator = erroneousPropertiesMap.keySet().iterator();
  +        while (iterator.hasNext()) {
  +            
  +            Integer errorCode = (Integer)iterator.next();
  +            List erroneousPropertiesList = (List)erroneousPropertiesMap.get(errorCode);
  +            Element propstat = new Element(E_PROPSTAT, NamespaceCache.DEFAULT_NAMESPACE);
  +            elementList.add(propstat);
  +            Element prop = new Element(E_PROP, NamespaceCache.DEFAULT_NAMESPACE);
  +            propstat.addContent(prop);
  +        
  +            String status = new String("HTTP/1.1 " + errorCode.intValue()
  +                                           + " " + WebdavStatus.getStatusText(errorCode.intValue()));
  +            
  +            Iterator propertyIterator = erroneousPropertiesList.iterator();
  +            while (propertyIterator.hasNext()) {
  +                
  +                PropertyName erroneousProperty =
  +                    (PropertyName) propertyIterator.next();
  +                Element propertyElement = getPropertyElement(erroneousProperty.getNamespace(),
  +                                                             erroneousProperty.getName(),
  +                                                             null,
  +                                                             contextPath,
  +                                                             serverURL);
  +                if (propertyElement != null) {prop.addContent(propertyElement);}
  +            }
  +        
  +        Element statusElement = new Element(E_STATUS, NamespaceCache.DEFAULT_NAMESPACE);
  +        statusElement.setText(status);
  +        propstat.addContent(statusElement);
  +        }
           
           return elementList;
       }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>