You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mi...@apache.org on 2003/05/28 17:11:16 UTC
cvs commit: xml-xalan/java/src/org/apache/xml/serializer ToXMLSAXHandler.java ToHTMLStream.java ToXMLStream.java SerializerBase.java ToStream.java ToSAXHandler.java NamespaceMappings.java
minchau 2003/05/28 08:11:15
Modified: java/src/org/apache/xml/serializer ToXMLSAXHandler.java
ToHTMLStream.java ToXMLStream.java
SerializerBase.java ToStream.java ToSAXHandler.java
NamespaceMappings.java
Log:
Support for reset() for the stream serializers and for ToXMLSAXHandler.
These serializers can now be reset and re-used rather than creating a new one.
A reset() takes about 1/2 the time of creating a new one.
Submitted by: Brian Minchau
Revision Changes Path
1.5 +29 -8 xml-xalan/java/src/org/apache/xml/serializer/ToXMLSAXHandler.java
Index: ToXMLSAXHandler.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToXMLSAXHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ToXMLSAXHandler.java 13 May 2003 18:05:16 -0000 1.4
+++ ToXMLSAXHandler.java 28 May 2003 15:11:14 -0000 1.5
@@ -127,13 +127,6 @@
{
}
- /**
- * @see org.apache.xml.serializer.Serializer#reset()
- */
- public boolean reset()
- {
- return false;
- }
/**
* @see org.apache.xml.serializer.DOMSerializer#serialize(Node)
@@ -757,6 +750,34 @@
addAttributeAlways(uri, localName, rawName, type, value);
}
- }
+ }
+
+ /**
+ * Try's to reset the super class and reset this class for
+ * re-use, so that you don't need to create a new serializer
+ * (mostly for performance reasons).
+ *
+ * @return true if the class was successfuly reset.
+ * @see org.apache.xml.serializer.Serializer#reset()
+ */
+ public boolean reset()
+ {
+ boolean wasReset = false;
+ if (super.reset())
+ {
+ resetToXMLSAXHandler();
+ wasReset = true;
+ }
+ return wasReset;
+ }
+
+ /**
+ * Reset all of the fields owned by ToXMLSAXHandler class
+ *
+ */
+ private void resetToXMLSAXHandler()
+ {
+ this.m_escapeSetting = false;
+ }
}
1.8 +23 -4 xml-xalan/java/src/org/apache/xml/serializer/ToHTMLStream.java
Index: ToHTMLStream.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToHTMLStream.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ToHTMLStream.java 21 May 2003 18:37:40 -0000 1.7
+++ ToHTMLStream.java 28 May 2003 15:11:14 -0000 1.8
@@ -87,7 +87,7 @@
/** State stack to keep track of if the current element has output
* escaping disabled.
*/
- protected BoolStack m_isRawStack = new BoolStack();
+ protected final BoolStack m_isRawStack = new BoolStack();
/** This flag is set while receiving events from the DTD */
protected boolean m_inDTD = false;
@@ -100,12 +100,12 @@
* Map that tells which XML characters should have special treatment, and it
* provides character to entity name lookup.
*/
- protected static CharInfo m_htmlcharInfo =
+ protected static final CharInfo m_htmlcharInfo =
// new CharInfo(CharInfo.HTML_ENTITIES_RESOURCE);
CharInfo.getCharInfo(CharInfo.HTML_ENTITIES_RESOURCE);
/** A digital search trie for fast, case insensitive lookup of ElemDesc objects. */
- static Trie m_elementFlags = new Trie();
+ static final Trie m_elementFlags = new Trie();
static {
@@ -506,7 +506,7 @@
/**
* Dummy element for elements not found.
*/
- static private ElemDesc m_dummy = new ElemDesc(0 | ElemDesc.BLOCK);
+ static private final ElemDesc m_dummy = new ElemDesc(0 | ElemDesc.BLOCK);
/** True if URLs should be specially escaped with the %xx form. */
private boolean m_specialEscapeURLs = true;
@@ -1798,5 +1798,24 @@
if (m_inDTD)
return;
super.comment(ch, start, length);
+ }
+
+ public boolean reset()
+ {
+ boolean ret = super.reset();
+ if (!ret)
+ return false;
+ initToHTMLStream();
+ return true;
+ }
+
+ private void initToHTMLStream()
+ {
+ m_elementDesc = null;
+ m_inBlockElem = false;
+ m_inDTD = false;
+ m_isRawStack.clear();
+ m_omitMetaTag = false;
+ m_specialEscapeURLs = true;
}
}
1.3 +26 -0 xml-xalan/java/src/org/apache/xml/serializer/ToXMLStream.java
Index: ToXMLStream.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToXMLStream.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ToXMLStream.java 9 May 2003 18:47:56 -0000 1.2
+++ ToXMLStream.java 28 May 2003 15:11:14 -0000 1.3
@@ -560,6 +560,32 @@
}
return false;
}
+ /**
+ * Try's to reset the super class and reset this class for
+ * re-use, so that you don't need to create a new serializer
+ * (mostly for performance reasons).
+ *
+ * @return true if the class was successfuly reset.
+ */
+ public boolean reset()
+ {
+ boolean wasReset = false;
+ if (super.reset())
+ {
+ resetToXMLStream();
+ wasReset = true;
+ }
+ return wasReset;
+ }
+
+ /**
+ * Reset all of the fields owned by ToStream class
+ *
+ */
+ private void resetToXMLStream()
+ {
+ this.m_cdataTagOpen = false;
+ }
}
1.6 +44 -12 xml-xalan/java/src/org/apache/xml/serializer/SerializerBase.java
Index: SerializerBase.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/SerializerBase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SerializerBase.java 13 May 2003 18:05:16 -0000 1.5
+++ SerializerBase.java 28 May 2003 15:11:14 -0000 1.6
@@ -176,7 +176,7 @@
* at the end of an element the value is poped.
* It is True if the text of the element should be in CDATA section blocks.
*/
- protected BoolStack m_cdataSectionStates = new BoolStack();
+ protected final BoolStack m_cdataSectionStates = new BoolStack();
/**
* The System ID for the doc type.
@@ -200,17 +200,6 @@
*/
private String m_encoding = null;
- /**
- * The top of this stack contains an id of the element that last declared
- * a namespace. Used to ensure prefix/uri map scopes are closed correctly
- */
- protected Stack m_nodeStack;
-
- /**
- * The top of this stack is the prefix that was last mapped to an URI
- */
- protected Stack m_prefixStack;
-
/**
* Tells if we should write the XML declaration.
*/
@@ -1285,6 +1274,49 @@
*/
public void setNamespaceMappings(NamespaceMappings mappings) {
m_prefixMap = mappings;
+ }
+
+ public boolean reset()
+ {
+ resetSerializerBase();
+ return true;
+ }
+
+ /**
+ * Reset all of the fields owned by SerializerBase
+ *
+ */
+ private void resetSerializerBase()
+ {
+ this.m_attributes.clear();
+ this.m_cdataSectionElements = null;
+ this.m_cdataSectionStates.clear();
+ this.m_currentElemDepth = 0;
+ this.m_doctypePublic = null;
+ this.m_doctypeSystem = null;
+ this.m_doIndent = false;
+ this.m_elementLocalName = null;
+ this.m_elementLocalName = null;
+ this.m_elementName = null;
+ this.m_encoding = null;
+ this.m_indentAmount = 0;
+ this.m_inEntityRef = false;
+ this.m_inExternalDTD = false;
+ this.m_mediatype = null;
+ this.m_needToCallStartDocument = true;
+ this.m_needToOutputDocTypeDecl = false;
+ if (this.m_prefixMap != null)
+ this.m_prefixMap.reset();
+ this.m_shouldNotWriteXMLHeader = false;
+ this.m_sourceLocator = null;
+ this.m_standalone = null;
+ this.m_standaloneWasSpecified = false;
+ this.m_startTagOpen = false;
+ this.m_tracer = null;
+ this.m_transformer = null;
+ this.m_version = null;
+ // don't set writer to null, so that it might be re-used
+ //this.m_writer = null;
}
}
1.7 +48 -34 xml-xalan/java/src/org/apache/xml/serializer/ToStream.java
Index: ToStream.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToStream.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ToStream.java 13 May 2003 18:05:16 -0000 1.6
+++ ToStream.java 28 May 2003 15:11:14 -0000 1.7
@@ -152,20 +152,6 @@
protected boolean m_isprevtext = false;
/**
- * A stack of Boolean objects that tell if the given element
- * has children.
- */
- // protected BoolStack m_elemStack = new BoolStack();
-
- /**
- * Map that tells which XML characters should have special treatment, and it
- * provides character to entity name lookup.
- */
- private static CharInfo m_xmlcharInfo =
- // new CharInfo(CharInfo.XML_ENTITIES_RESOURCE);
- CharInfo.getCharInfo(CharInfo.XML_ENTITIES_RESOURCE);
-
- /**
* The maximum character size before we have to resort
* to escaping.
*/
@@ -189,14 +175,9 @@
*/
protected CharInfo m_charInfo;
- /** Table of user-specified char infos. */
- private static Hashtable m_charInfos = null;
-
/** True if we control the buffer, and we should flush the output on endDocument. */
boolean m_shouldFlush = true;
- // protected OutputBuffer _buffer = null;
-
/**
* Add space before '/>' for XHTML.
*/
@@ -769,21 +750,6 @@
}
- /**
- * Resets the serializer. If this method returns true, the
- * serializer may be used for subsequent serialization of new
- * documents. It is possible to change the output format and
- * output stream prior to serializing, or to use the existing
- * output format and output stream.
- *
- * @return True if serializer has been reset and can be reused
- */
- public boolean reset()
- {
- m_needToCallStartDocument = true;
-
- return false;
- }
/**
* Might print a newline character and the indentation amount
@@ -2845,4 +2811,52 @@
}
+ /**
+ * Try's to reset the super class and reset this class for
+ * re-use, so that you don't need to create a new serializer
+ * (mostly for performance reasons).
+ *
+ * @return true if the class was successfuly reset.
+ */
+ public boolean reset()
+ {
+ boolean wasReset = false;
+ if (super.reset())
+ {
+ resetToStream();
+ wasReset = true;
+ }
+ return wasReset;
+ }
+
+ /**
+ * Reset all of the fields owned by ToStream class
+ *
+ */
+ private void resetToStream()
+ {
+ this.m_canConvertMeth = null;
+ this.m_cdataStartCalled = false;
+ this.m_charInfo = null; // ??
+ this.m_charToByteConverter = null;
+ this.m_disableOutputEscapingStates.clear();
+
+ this.m_escaping = false;
+ // Leave m_format alone for now - bjm
+ // this.m_format = null;
+ this.m_inDoctype = false;
+ this.m_ispreserve = false;
+ this.m_ispreserve = false;
+ this.m_isprevtext = false;
+ this.m_isUTF8 = false; // ?? used anywhere ??
+ this.m_maxCharacter = Encodings.getLastPrintable();
+ this.m_preserves.clear();
+ this.m_shouldFlush = true;
+ this.m_spaceBeforeClose = false;
+ this.m_startNewLine = false;
+ this.m_triedToGetConverter = false;
+ // DON'T SET THE WRITER TO NULL, IT MAY BE REUSED !!
+ // this.m_writer = null;
+
+ }
}
1.3 +31 -1 xml-xalan/java/src/org/apache/xml/serializer/ToSAXHandler.java
Index: ToSAXHandler.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToSAXHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ToSAXHandler.java 9 May 2003 18:47:56 -0000 1.2
+++ ToSAXHandler.java 28 May 2003 15:11:14 -0000 1.3
@@ -412,5 +412,35 @@
if (m_saxHandler instanceof ErrorHandler)
((ErrorHandler)m_saxHandler).warning(exc);
}
-
+
+
+ /**
+ * Try's to reset the super class and reset this class for
+ * re-use, so that you don't need to create a new serializer
+ * (mostly for performance reasons).
+ *
+ * @return true if the class was successfuly reset.
+ * @see org.apache.xml.serializer.Serializer#reset()
+ */
+ public boolean reset()
+ {
+ boolean wasReset = false;
+ if (super.reset())
+ {
+ resetToSAXHandler();
+ wasReset = true;
+ }
+ return wasReset;
+ }
+
+ /**
+ * Reset all of the fields owned by ToSAXHandler class
+ *
+ */
+ private void resetToSAXHandler()
+ {
+ this.m_lexHandler = null;
+ this.m_saxHandler = null;
+ this.m_state = null;
+ }
}
1.2 +14 -7 xml-xalan/java/src/org/apache/xml/serializer/NamespaceMappings.java
Index: NamespaceMappings.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/NamespaceMappings.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NamespaceMappings.java 1 Apr 2003 19:24:54 -0000 1.1
+++ NamespaceMappings.java 28 May 2003 15:11:14 -0000 1.2
@@ -106,12 +106,12 @@
* on the m_nodeStack. That way all prefixes pushed at the current depth can
* be removed at the same time.
*/
- private java.util.Stack m_prefixStack;
+ private java.util.Stack m_prefixStack = new Stack();
/**
* Each entry (prefix) in this hashtable points to a Stack of URIs
*/
- private Hashtable m_namespaces;
+ private Hashtable m_namespaces = new Hashtable();
/**
* The top of this stack contains the nested element depth
@@ -125,7 +125,7 @@
* Used to ensure prefix/uri map scopes are closed correctly
*
*/
- private Stack m_nodeStack;
+ private Stack m_nodeStack = new Stack();
private static final String EMPTYSTRING = "";
private static final String XML_PREFIX = "xml"; // was "xmlns"
@@ -145,10 +145,7 @@
*/
private void initNamespaces()
{
- // Namespaces
- m_namespaces = new Hashtable();
- m_nodeStack = new Stack();
- m_prefixStack = new Stack();
+
// Define the default namespace (initially maps to "" uri)
Stack stack;
@@ -300,6 +297,16 @@
clone.count = count;
return clone;
+ }
+
+ public final void reset()
+ {
+ this.count = 0;
+ this.m_namespaces.clear();
+ this.m_nodeStack.clear();
+ this.m_prefixStack.clear();
+
+ initNamespaces();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org