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 re...@apache.org on 2001/07/22 07:59:31 UTC

cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method PropFindMethod.java PropPatchMethod.java WebdavMethod.java

remm        01/07/21 22:59:31

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        PropFindMethod.java PropPatchMethod.java
                        WebdavMethod.java
  Log:
  - Cleanup of namespace handling, using DOM2.
  - The code is now simpler, and avoids one unnecessary hashtable creation.
  - Start switching to Java2 collections.
  - Tested with the Slide client and DAV Explorer. Apparently, everything works
    fine.
  - Should fix namespace related failures reported at the interop event (did not
    test yet with SkunkDAV's test suite, though).
  
  Revision  Changes    Path
  1.30      +55 -106   jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java
  
  Index: PropFindMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- PropFindMethod.java	2001/07/18 13:18:18	1.29
  +++ PropFindMethod.java	2001/07/22 05:59:31	1.30
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v 1.29 2001/07/18 13:18:18 dirkv Exp $
  - * $Revision: 1.29 $
  - * $Date: 2001/07/18 13:18:18 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v 1.30 2001/07/22 05:59:31 remm Exp $
  + * $Revision: 1.30 $
  + * $Date: 2001/07/22 05:59:31 $
    *
    * ====================================================================
    *
  @@ -278,12 +278,6 @@
       
       
       /**
  -     * MS Proprietary properties support.
  -     */
  -    protected boolean msProprietarySupport;
  -    
  -    
  -    /**
        * Current namespace number used to generate namespace abbreviations.
        */
       protected int namespaceNumber = 0;
  @@ -292,7 +286,7 @@
       /**
        * Namespaces list. Keyed by namespace names.
        */
  -    protected Hashtable namespaceAbbrevs;
  +    protected HashMap namespaces;
       
       
       // ----------------------------------------------------------- Constructors
  @@ -312,7 +306,8 @@
           this.depthLimit = depthLimit;
           readRequestContent();
           
  -        namespaceAbbrevs = new Hashtable();
  +        namespaces = new HashMap();
  +        namespaces.put(SLIDE_NAMESPACE, SLIDE_NAMESPACE_ABBREV);
           depth = INFINITY;
           propFindType = FIND_ALL_PROP;
       }
  @@ -329,8 +324,6 @@
       protected void parseRequest()
           throws WebdavException {
       
  -        msProprietarySupport = isMsProprietarySupport();
  -        
           String depthStr = req.getHeader("Depth");
           
           if (depthStr == null) {
  @@ -367,15 +360,12 @@
                   Element rootElement = document.getDocumentElement();
                   NodeList childList = rootElement.getChildNodes();
                   
  -                parseNodeNamespaceDeclarations(rootElement);
  -                
                   for (int i=0; i < childList.getLength(); i++) {
                       Node currentNode = childList.item(i);
                       switch (currentNode.getNodeType()) {
                       case Node.TEXT_NODE:
                           break;
                       case Node.ELEMENT_NODE:
  -                        parseNodeNamespaceDeclarations(currentNode);
                           if (currentNode.getNodeName().endsWith("prop")) {
                               propFindType = FIND_BY_PROPERTY;
                               propNode = currentNode;
  @@ -405,7 +395,6 @@
                       case Node.TEXT_NODE:
                           break;
                       case Node.ELEMENT_NODE:
  -                        parseNodeNamespaceDeclarations(currentNode);
                           Property property = getProperty(currentNode);
                           propertyVector.addElement(property);
                           break;
  @@ -420,6 +409,25 @@
       
       
       /**
  +     * Parse the namespace info of a node name.
  +     *
  +     * @param node The DOM node to parse
  +     * @return The corresponding Property object
  +     */
  +    protected Property getProperty(Node node) {
  +        
  +        Property property = new Property();
  +        
  +        property.name = node.getLocalName();
  +        property.namespace = node.getNamespaceURI();
  +        generateNamespaceAbbreviation(property.namespace);
  +        
  +        return property;
  +        
  +    }
  +    
  +    
  +    /**
        * Execute the request.
        *
        * @exception WebdavException
  @@ -682,7 +690,7 @@
                       String namespace = currentProperty.getNamespace();
                       generateNamespaceAbbreviation(namespace);
                       String namespaceAbbrev =
  -                        (String) namespaceAbbrevs.get(namespace);
  +                        (String) namespaces.get(namespace);
                       Object currentPropertyValue = currentProperty.getValue();
                       if ((currentPropertyValue == null) ||
                           (currentPropertyValue.toString().equals(""))) {
  @@ -751,8 +759,9 @@
                       (NodeProperty) propertyList.nextElement();
                   if (currentProperty != null) {
                       String namespace = currentProperty.getNamespace();
  +                    generateNamespaceAbbreviation(namespace);
                       String namespaceAbbrev =
  -                        (String) namespaceAbbrevs.get(namespace);
  +                        (String) namespaces.get(namespace);
                       generatedXML.writeElement
                           (namespaceAbbrev, namespace,
                            currentProperty.getName(),
  @@ -838,28 +847,33 @@
                           revisionDescriptor.getProperty(propertyName,
                                                          propertyNamespace);
                       if (currentProperty != null) {
  +                        
  +                        String namespace = currentProperty.getNamespace();
  +                        String namespaceAbbrev =
  +                            (String) namespaces.get(namespace);
                           Object currentPropertyValue =
                               currentProperty.getValue();
                           if ((currentPropertyValue == null) ||
                               (currentPropertyValue.toString().equals(""))) {
                               generatedXML.writeElement
  -                                (property.namespaceAbbrev, null,
  +                                (namespaceAbbrev, null,
                                    currentProperty.getName(),
                                    XMLPrinter.NO_CONTENT);
                           } else {
                               generatedXML.writeElement
  -                                (property.namespaceAbbrev, null,
  +                                (namespaceAbbrev, null,
                                    currentProperty.getName(),
                                    XMLPrinter.OPENING);
                               generatedXML.writeText
                                   (currentPropertyValue.toString());
                               generatedXML.writeElement
  -                                (property.namespaceAbbrev, null,
  +                                (namespaceAbbrev, null,
                                    currentProperty.getName(),
                                    XMLPrinter.CLOSING);
                           }
  +                        
                       } else {
  -                        propertiesNotFoundVector.addElement(propertyName);
  +                        propertiesNotFoundVector.addElement(property);
                       }
                   }
                   
  @@ -885,9 +899,14 @@
                                             XMLPrinter.OPENING);
                   
                   while (propertiesNotFoundList.hasMoreElements()) {
  +                    Property propertyNotFound = 
  +                        (Property) propertiesNotFoundList.nextElement();
  +                    String name = propertyNotFound.name;
  +                    String namespace = propertyNotFound.namespace;
  +                    String namespaceAbbrev =
  +                        (String) namespaces.get(namespace);
                       generatedXML.writeElement
  -                        (null, (String) propertiesNotFoundList.nextElement(),
  -                         XMLPrinter.NO_CONTENT);
  +                        (namespaceAbbrev, null, name, XMLPrinter.NO_CONTENT);
                   }
                   
                   generatedXML.writeElement(null, "prop",
  @@ -906,95 +925,24 @@
       }
       
       
  -    /**
  -     * Parse a node for namespace declaration attributes.
  -     *
  -     * @param node DOM node
  -     */
  -    protected void parseNodeNamespaceDeclarations(Node node) {
  -        
  -        NamedNodeMap nodeMap = node.getAttributes();
  -        if (nodeMap != null) {
  -            for (int i = 0; i < nodeMap.getLength(); i++) {
  -                Node currentNode = nodeMap.item(i);
  -                if (currentNode.getNodeType() != Node.ATTRIBUTE_NODE)
  -                    continue;
  -                String attributeName = currentNode.getNodeName();
  -                if (attributeName.startsWith("xmlns")) {
  -                    // We found a namespace declaration
  -                    if (attributeName.equals("xmlns")) {
  -                        defaultNamespace = currentNode.getNodeValue();
  -                    } else {
  -                        // Stripping out the prefix
  -                        if (attributeName.startsWith("xmlns:")) {
  -                            String namespaceAbbreviation =
  -                                attributeName.substring(6);
  -                            namespaces.put(namespaceAbbreviation,
  -                                           currentNode.getNodeValue());
  -                            namespaceAbbrevs.put(currentNode.getNodeValue(),
  -                                                 namespaceAbbreviation);
  -                        }
  -                    }
  -                }
  -            }
  -        }
  -        
  -    }
  -    
  -    
       // ------------------------------------------------------ Protected Methods
       
       
       /**
  -     * Parse the namespace info of a node name.
  -     *
  -     * @param node The DOM node to parse
  -     * @return The corresponding Property object
  -     */
  -    protected Property getProperty(Node node) {
  -        
  -        Property property = new Property();
  -        
  -        String nodeName = node.getNodeName();
  -        int colon = nodeName.indexOf(':');
  -        if (colon != -1) {
  -            property.name = nodeName.substring(colon + 1);
  -            property.namespaceAbbrev = nodeName.substring(0, colon);
  -            String namespace =
  -                (String) namespaces.get(property.namespaceAbbrev);
  -            if ((namespace) != null) {
  -                property.namespace = namespace;
  -            } else {
  -                property.namespace = defaultNamespace;
  -            }
  -        } else {
  -            property.name = nodeName;
  -            property.namespace = defaultNamespace;
  -        }
  -        
  -        return property;
  -        
  -    }
  -    
  -    
  -    /**
        * Generate a namespace abbreviation for the given namespace.
        *
        * @param namespaceName Name of the namespace
        */
       protected void generateNamespaceAbbreviation(String namespaceName) {
           
  -        if (namespaceAbbrevs.get(namespaceName) != null)
  +        if (namespaces.get(namespaceName) != null)
               return;
  +
  +        if (namespaceName.equals(NodeProperty.DEFAULT_NAMESPACE))
  +            return;
           
           String namespaceAbbrev = "ns" + namespaceNumber++;
  -        // Make sure it doesn't already exist
  -        while (namespaces.get(namespaceAbbrev) != null) {
  -            namespaceAbbrev = "ns" + namespaceNumber++;
  -        }
  -        
  -        namespaces.put(namespaceAbbrev, namespaceName);
  -        namespaceAbbrevs.put(namespaceName, namespaceAbbrev);
  +        namespaces.put(namespaceName, namespaceAbbrev);
           
       }
       
  @@ -1008,13 +956,14 @@
           
           StringBuffer result = new StringBuffer();
           
  -        result.append(" xmlns=\"").append(defaultNamespace).append("\" ");
  +        result.append(" xmlns=\"").append(NodeProperty.DEFAULT_NAMESPACE)
  +            .append("\" ");
           
  -        Enumeration abbreviationList = namespaces.keys();
  -        while (abbreviationList.hasMoreElements()) {
  +        Iterator namespaceList = namespaces.keySet().iterator();
  +        while (namespaceList.hasNext()) {
               
  -            String abbrev = (String) abbreviationList.nextElement();
  -            String namespace = (String) namespaces.get(abbrev);
  +            String namespace = (String) namespaceList.next();
  +            String abbrev = (String) namespaces.get(namespace);
               result.append("xmlns:").append(abbrev).append("=\"")
                   .append(namespace).append("\" ");
               
  
  
  
  1.15      +11 -33    jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java
  
  Index: PropPatchMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- PropPatchMethod.java	2001/07/20 13:00:30	1.14
  +++ PropPatchMethod.java	2001/07/22 05:59:31	1.15
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v 1.14 2001/07/20 13:00:30 juergen Exp $
  - * $Revision: 1.14 $
  - * $Date: 2001/07/20 13:00:30 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v 1.15 2001/07/22 05:59:31 remm Exp $
  + * $Revision: 1.15 $
  + * $Date: 2001/07/22 05:59:31 $
    *
    * ====================================================================
    *
  @@ -165,31 +165,28 @@
                   Node setNode = null;
                   Node removeNode = null;
                   
  -                Document document = documentBuilder.parse(new InputSource(
  -                                                                             (new StringReader(requestBody))));
  +                Document document = 
  +                    documentBuilder.parse
  +                    (new InputSource(new StringReader(requestBody)));
                   
                   // Get the root element of the document
                   Element rootElement = document.getDocumentElement();
                   NodeList childList = rootElement.getChildNodes();
                   
  -                parseNodeNamespaceDeclarations(rootElement);
  -                
                   for (int i=0; i < childList.getLength(); i++) {
                       Node currentNode = childList.item(i);
                       switch (currentNode.getNodeType()) {
                           case Node.TEXT_NODE:
                               break;
                           case Node.ELEMENT_NODE:
  -                            parseNodeNamespaceDeclarations(currentNode);
                               if (currentNode.getNodeName().endsWith("set")) {
  -                                NodeList tempList = currentNode.getChildNodes();
  +                                NodeList tempList = 
  +                                    currentNode.getChildNodes();
                                   for (int j=0; j < tempList.getLength(); j++) {
                                       switch (tempList.item(j).getNodeType()) {
                                           case Node.TEXT_NODE:
                                               break;
                                           case Node.ELEMENT_NODE:
  -                                            parseNodeNamespaceDeclarations
  -                                                (tempList.item(j));
                                               if (tempList.item(j).getNodeName()
                                                   .endsWith("prop")) {
                                                   parseSetNode(tempList.item(j));
  @@ -205,8 +202,6 @@
                                           case Node.TEXT_NODE:
                                               break;
                                           case Node.ELEMENT_NODE:
  -                                            parseNodeNamespaceDeclarations
  -                                                (tempList.item(j));
                                               if (tempList.item(j).getNodeName()
                                                   .endsWith("prop")) {
                                                   parseRemoveNode(tempList.item(j));
  @@ -381,8 +376,6 @@
                       break;
                   case Node.ELEMENT_NODE:
                       
  -                    parseNodeNamespaceDeclarations(currentNode);
  -                    
                       Property propertyToSet = getProperty(currentNode);
                       
                       StringWriter writer = new StringWriter();
  @@ -422,8 +415,6 @@
                       break;
                   case Node.ELEMENT_NODE:
                       
  -                    parseNodeNamespaceDeclarations(currentNode);
  -                    
                       Property propertyToRemove = getProperty(currentNode);
                       
                       propertiesToRemove.addElement(propertyToRemove);
  @@ -444,22 +435,9 @@
           
           Property property = new Property();
           
  -        String nodeName = node.getNodeName();
  -        int colon = nodeName.indexOf(':');
  -        if (colon != -1) {
  -            property.name = nodeName.substring(colon + 1);
  -            property.namespaceAbbrev = nodeName.substring(0, colon);
  -            String namespace =
  -                (String) namespaces.get(property.namespaceAbbrev);
  -            if ((namespace) != null) {
  -                property.namespace = namespace;
  -            } else {
  -                property.namespace = defaultNamespace;
  -            }
  -        } else {
  -            property.name = nodeName;
  -            property.namespace = defaultNamespace;
  -        }
  +        property.name = node.getLocalName();
  +        property.namespace = node.getNamespaceURI();
  +        property.namespaceAbbrev = node.getPrefix();
           
           return property;
           
  
  
  
  1.27      +5 -54     jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/WebdavMethod.java
  
  Index: WebdavMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/WebdavMethod.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- WebdavMethod.java	2001/07/18 14:37:34	1.26
  +++ WebdavMethod.java	2001/07/22 05:59:31	1.27
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/WebdavMethod.java,v 1.26 2001/07/18 14:37:34 juergen Exp $
  - * $Revision: 1.26 $
  - * $Date: 2001/07/18 14:37:34 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/WebdavMethod.java,v 1.27 2001/07/22 05:59:31 remm Exp $
  + * $Revision: 1.27 $
  + * $Date: 2001/07/22 05:59:31 $
    *
    * ====================================================================
    *
  @@ -211,18 +211,6 @@
       
       
       /**
  -     * Namespaces list. Keyed by abbreviation.
  -     */
  -    protected Hashtable namespaces;
  -    
  -    
  -    /**
  -     * Default namespace.
  -     */
  -    protected String defaultNamespace = NodeProperty.DEFAULT_NAMESPACE;
  -    
  -    
  -    /**
        * MD5 message digest provider.
        */
       protected static MessageDigest md5Helper;
  @@ -418,40 +406,6 @@
   
       
       /**
  -     * Parse a node for namespace declaration attributes.
  -     *
  -     * @param node DOM node
  -     */
  -    protected void parseNodeNamespaceDeclarations(Node node) {
  -        
  -        NamedNodeMap nodeMap = node.getAttributes();
  -        if (nodeMap != null) {
  -            for (int i = 0; i < nodeMap.getLength(); i++) {
  -                Node currentNode = nodeMap.item(i);
  -                if (currentNode.getNodeType() != Node.ATTRIBUTE_NODE)
  -                    continue;
  -                String attributeName = currentNode.getNodeName();
  -                if (attributeName.startsWith("xmlns")) {
  -                    // We found a namespace declaration
  -                    if (attributeName.equals("xmlns")) {
  -                        defaultNamespace = currentNode.getNodeValue();
  -                    } else {
  -                        // Stripping out the prefix
  -                        if (attributeName.startsWith("xmlns:")) {
  -                            String namespaceAbbreviation =
  -                                attributeName.substring(6);
  -                            namespaces.put(namespaceAbbreviation,
  -                                           currentNode.getNodeValue());
  -                        }
  -                    }
  -                }
  -            }
  -        }
  -        
  -    }
  -    
  -    
  -    /**
        * Read request contents.
        *
        * @param req Request object handed out by the servlet container
  @@ -459,9 +413,6 @@
        */
       protected void readRequestContent() {
           
  -        namespaces = new Hashtable();
  -        namespaces.put(SLIDE_NAMESPACE_ABBREV, SLIDE_NAMESPACE);
  -        
           if (req.getContentLength() == 0)
               return;
           
  @@ -564,9 +515,9 @@
           } catch(SlideException e) { // this is the default
               return true;
           }
  -     }
  +    }
                   
  -         
  +    
       /**
        * Tests if a resource is a collection.
        */