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 pn...@apache.org on 2004/09/01 16:26:16 UTC

cvs commit: jakarta-slide/src/share/org/apache/slide/util XMLValue.java

pnever      2004/09/01 07:26:15

  Modified:    src/share/org/apache/slide/util Tag:
                        SLIDE_2_0_RELEASE_BRANCH XMLValue.java
  Log:
  Performance issue: avoid parsing of trivial XML property values.
  Currently these are: emtpty_string and <collection/>
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.3.2.3   +35 -35    jakarta-slide/src/share/org/apache/slide/util/XMLValue.java
  
  Index: XMLValue.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/util/XMLValue.java,v
  retrieving revision 1.3.2.2
  retrieving revision 1.3.2.3
  diff -u -r1.3.2.2 -r1.3.2.3
  --- XMLValue.java	5 Feb 2004 16:05:14 -0000	1.3.2.2
  +++ XMLValue.java	1 Sep 2004 14:26:15 -0000	1.3.2.3
  @@ -5,7 +5,7 @@
    *
    * ====================================================================
    *
  - * Copyright 1999-2002 The Apache Software Foundation 
  + * Copyright 1999-2002 The Apache Software Foundation
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -21,6 +21,8 @@
    *
    */
   package org.apache.slide.util;
  +import org.jdom.*;
  +
   import java.io.IOException;
   import java.io.StringReader;
   import java.io.StringWriter;
  @@ -28,16 +30,8 @@
   import java.util.Iterator;
   import java.util.List;
   import org.apache.slide.content.NodeProperty;
  +import org.apache.slide.content.NodeRevisionDescriptor;
   import org.apache.slide.structure.SubjectNode;
  -import org.jdom.CDATA;
  -import org.jdom.Comment;
  -import org.jdom.Document;
  -import org.jdom.Element;
  -import org.jdom.EntityRef;
  -import org.jdom.JDOMException;
  -import org.jdom.Namespace;
  -import org.jdom.ProcessingInstruction;
  -import org.jdom.Text;
   import org.jdom.input.SAXBuilder;
   import org.jdom.output.XMLOutputter;
   import org.xml.sax.Attributes;
  @@ -315,28 +309,34 @@
        */
       public void add(String xmlString, Namespace defaultNamespace) throws JDOMException {
           
  -        if (xmlString != null) {
  -            StringBuffer buffer = new StringBuffer(START_TAG.length() +
  -                                                       xmlString.length() +
  -                                                       END_TAG.length());
  -            buffer.append(START_TAG);
  -            buffer.append(xmlString);
  -            buffer.append(END_TAG);
  -            SAXBuilder builder = new SAXBuilder();
  -            if (defaultNamespace != null) {
  -                builder.setXMLFilter(new DefaultNamespaceXMLFilter(defaultNamespace));
  -            }
  -            try {
  -                Document document = builder.build(new StringReader(buffer.toString()));
  -                List content = document.getRootElement().getContent();
  -                add( content );
  -                // detach elements from parent
  -                content.clear();
  +        if (xmlString != null && xmlString.length() > 0) {
  +            if (NodeRevisionDescriptor.COLLECTION_TYPE.equals(xmlString)) {
  +                // avoid trivial parsing
  +                add(new Element("collection", defaultNamespace));
               }
  -            catch (Exception e) {
  -                // should not happen since the StringReader does not
  -                // perform any "real" I/O
  -                throw new JDOMException(e.getMessage());
  +            else {
  +                StringBuffer buffer = new StringBuffer(START_TAG.length() +
  +                                                           xmlString.length() +
  +                                                           END_TAG.length());
  +                buffer.append(START_TAG);
  +                buffer.append(xmlString);
  +                buffer.append(END_TAG);
  +                SAXBuilder builder = new SAXBuilder();
  +                if (defaultNamespace != null) {
  +                    builder.setXMLFilter(new DefaultNamespaceXMLFilter(defaultNamespace));
  +                }
  +                try {
  +                    Document document = builder.build(new StringReader(buffer.toString()));
  +                    List content = document.getRootElement().getContent();
  +                    add( content );
  +                    // detach elements from parent
  +                    content.clear();
  +                }
  +                catch (Exception e) {
  +                    // should not happen since the StringReader does not
  +                    // perform any "real" I/O
  +                    throw new JDOMException(e.getMessage());
  +                }
               }
           }
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org