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/08/05 13:31:50 UTC

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

juergen     2002/08/05 04:31:50

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        PropFindMethod.java
  Log:
  Provided a possibility to optimize the output of the PropFindMethod, means instead of creating a large JDOM document first and then outputting the document to the response stream, any piece of the output is written to the stream as soon as it is available. This will reduce memory consumption in the case of large responses (PROPFIND on many resources). Since the output differs slightly, there is a switch in the web.xml to turn it off.
  (See description of "optimizePropfindOutpu" in web.xml)
  (ralf)
  
  Revision  Changes    Path
  1.77      +79 -10    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.76
  retrieving revision 1.77
  diff -u -r1.76 -r1.77
  --- PropFindMethod.java	31 Jul 2002 19:25:55 -0000	1.76
  +++ PropFindMethod.java	5 Aug 2002 11:31:50 -0000	1.77
  @@ -183,6 +183,12 @@
        */
       protected String labelHeader = null;
       
  +    /**
  +     * If set <code>true</code>, instead of creating the complete response document
  +     * in memory and then sending it to the client, available parts of the response
  +     * are send immediatly in order to reduce the memory footprint.
  +     */
  +    protected boolean outputOptimized = true;
       
       // ----------------------------------------------------------- Constructors
       
  @@ -215,9 +221,8 @@
           
           depth = INFINITY;
           propFindType = FIND_ALL_PROP;
  -        String pval = getConfig().getInitParameter( "allpropIncludesDeltav" );
  -        if( "true".equalsIgnoreCase(pval) )
  -            allpropIncludesDeltav = true;
  +        allpropIncludesDeltav = getBooleanInitParameter( "allpropIncludesDeltav" );
  +        outputOptimized = getBooleanInitParameter( "optimizePropfindOutput" );
           
           resourcePath = requestUri;
           if (resourcePath == null) {
  @@ -354,14 +359,16 @@
               throw new WebdavException(WebdavStatus.SC_ACCEPTED, false); // abort the TA
           }
           
  -        resp.setContentType("text/xml; charset=UTF-8");
  +        resp.setContentType(TEXT_XML_UTF_8);
           
           // Create multistatus object
           Element multistatusElement = new Element(E_MULTISTATUS, NamespaceCache.DEFAULT_NAMESPACE);
  +        XMLOutputter xmlOutputter = new XMLOutputter(XML_REPONSE_INDENT, true);
           
           if (resource != null) {
               if (depth == 0) {
                   multistatusElement.addContent(getPropertiesOfObject(resource.getUri()));
  +                xmlOutputter.output(new Document(multistatusElement), resp.getWriter());
               } else {
                   // The stack always contains the object of the current level
                   Stack stack = new Stack();
  @@ -370,10 +377,46 @@
                   // Stack of the objects one level below
                   Stack stackBelow = new Stack();
                   
  +                StringBuffer buffer = new StringBuffer();
  +                if (outputOptimized) {
  +                    
  +                    resp.getWriter().write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  +                    resp.getWriter().write("\n");
  +                    String namespacePrefix = multistatusElement.getNamespacePrefix();
  +                    if ( (namespacePrefix != null) && (namespacePrefix.length() == 0) ) {
  +                        namespacePrefix = null;
  +                    }
  +                    String namespaceUri = multistatusElement.getNamespaceURI();
  +                    if ( (namespaceUri != null) && (namespaceUri.length() == 0) ) {
  +                        namespaceUri = null;
  +                    }
  +                    buffer.append("<");
  +                    buffer.append(multistatusElement.getQualifiedName());
  +                    if (namespaceUri != null) {
  +                        buffer.append(" xmlns");
  +                        if (namespacePrefix != null) {
  +                            buffer.append(":");
  +                            buffer.append(namespacePrefix);
  +                        }
  +                        buffer.append("=\"");
  +                        buffer.append(namespaceUri);
  +                        buffer.append("\"");
  +                    }
  +                    buffer.append(">");
  +                    resp.getWriter().write(buffer.toString());
  +                    resp.getWriter().write("\n");
  +                }
  +                
                   while ((!stack.isEmpty()) && (depth >= 0)) {
                       
                       ObjectNode cur = (ObjectNode) stack.pop();
  -                    multistatusElement.addContent(getPropertiesOfObject(cur.getUri()));
  +                    Element response = getPropertiesOfObject(cur.getUri());
  +                    if (outputOptimized) {
  +                        xmlOutputter.output(response, resp.getWriter());
  +                    }
  +                    else {
  +                        multistatusElement.addContent(response);
  +                    }
                       
                       if (depth > 0) {
                           
  @@ -399,10 +442,22 @@
                       }
                       
                   }
  +                
  +                if (outputOptimized) {
  +                    resp.getWriter().write("\n");
  +                    buffer.setLength(0);
  +                    buffer.append("</");
  +                    buffer.append(multistatusElement.getQualifiedName());
  +                    buffer.append(">");
  +                    resp.getWriter().write(buffer.toString());
  +                    resp.getWriter().write("\n");
  +                }
  +                else {
  +                    xmlOutputter.output(new Document(multistatusElement), resp.getWriter());
  +                }
               }
           }
           
  -        new XMLOutputter(XML_REPONSE_INDENT, true).output(new Document(multistatusElement), resp.getWriter());
       }
       
       
  @@ -616,7 +671,21 @@
           return response;
       }
       
  -    
  +    /**
  +     * Returns the value of a boolean init parameter of the servlet.
  +     * If the parameter is not set or is neither <code>true</code>
  +     * nor <code>false</code>, <code>false</code> is assumed as
  +     * default value.
  +     *
  +     * @param      name  the name of the parameter.
  +     *
  +     * @return     the boolean value of the parameter.
  +     *
  +     * @throws
  +     */
  +    private boolean getBooleanInitParameter(String name) {
  +        return "true".equalsIgnoreCase(getConfig().getInitParameter(name));
  +    }
   }
   
   
  
  
  

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