76 }
77
78 /**
79 * true if we still need to call startDocumentInternal()
80 */
81 protected boolean m_needToCallStartDocument = true;
82
83 /** True if a trailing "]]>" still needs to be written to be
84 * written out. Used to merge adjacent CDATA sections
85 */
86 protected boolean m_cdataTagOpen = false;
87
88 /**
89 * All the attributes of the current element, collected from
90 * startPrefixMapping() calls, or addAddtribute() calls, or
91 * from the SAX attributes in a startElement() call.
92 */
93 protected AttributesImplSerializer m_attributes = new AttributesImplSerializer();
94
95 /**
96 * Tells if we're in an EntityRef event.
97 */
98 protected boolean m_inEntityRef = false;
99
100 /** This flag is set while receiving events from the external DTD */
101 protected boolean m_inExternalDTD = false;
102
103 /**
104 * The System ID for the doc type.
105 */
106 protected String m_doctypeSystem;
107
108 /**
109 * The public ID for the doc type.
110 */
111 protected String m_doctypePublic;
112
113 /**
114 * Flag to tell that we need to add the doctype decl, which we can't do
115 * until the first element is encountered.
116 */
117 boolean m_needToOutputDocTypeDecl = true;
118
127 private String m_standalone;
128
129 /**
130 * True if standalone was specified.
131 */
132 protected boolean m_standaloneWasSpecified = false;
133
134 /**
135 * Determine if the output is a standalone.
136 */
137 protected boolean m_isStandalone = false;
138
139 /**
140 * Flag to tell if indenting (pretty-printing) is on.
141 */
142 protected boolean m_doIndent = false;
143
144 /**
145 * Amount to indent.
146 */
147 protected int m_indentAmount = 0;
148
149 /**
150 * Tells the XML version, for writing out to the XML decl.
151 */
152 protected String m_version = null;
153
154 /**
155 * The mediatype. Not used right now.
156 */
157 protected String m_mediatype;
158
159 /**
160 * The transformer that was around when this output handler was created (if
161 * any).
162 */
163 private Transformer m_transformer;
164
165 /**
166 * Namespace support, that keeps track of currently defined
167 * prefix/uri mappings. As processed elements come and go, so do
427 * interface, it should return null.
428 *
429 * @return A {@link ContentHandler} interface into this serializer,
430 * or null if the serializer is not SAX 2 capable
431 * @throws IOException An I/O exception occured
432 */
433 public ContentHandler asContentHandler() throws IOException {
434 return this;
435 }
436
437 /**
438 * Report the end of an entity.
439 *
440 * @param name The name of the entity that is ending.
441 * @throws org.xml.sax.SAXException The application may raise an exception.
442 * @see #startEntity
443 */
444 public void endEntity(String name) throws org.xml.sax.SAXException {
445 if (name.equals("[dtd]"))
446 m_inExternalDTD = false;
447 m_inEntityRef = false;
448
449 if (m_tracer != null)
450 this.fireEndEntity(name);
451 }
452
453 /**
454 * Flush and close the underlying java.io.Writer. This method applies to
455 * ToStream serializers, not ToSAXHandler serializers.
456 * @see ToStream
457 */
458 public void close() {
459 // do nothing (base behavior)
460 }
461
462 /**
463 * Initialize global variables
464 */
465 protected void initCDATA() {
466 // CDATA stack
467 // _cdataStack = new Stack();
468 // _cdataStack.push(new Integer(-1)); // push dummy value
469 }
470
471 /**
472 * Returns the character encoding to be used in the output document.
473 * @return the character encoding to be used in the output document.
1122 public void setNamespaceMappings(NamespaceMappings mappings) {
1123 m_prefixMap = mappings;
1124 }
1125
1126 public boolean reset() {
1127 resetSerializerBase();
1128 return true;
1129 }
1130
1131 /**
1132 * Reset all of the fields owned by SerializerBase
1133 *
1134 */
1135 private void resetSerializerBase() {
1136 this.m_attributes.clear();
1137 this.m_StringOfCDATASections = null;
1138 this.m_elemContext = new ElemContext();
1139 this.m_doctypePublic = null;
1140 this.m_doctypeSystem = null;
1141 this.m_doIndent = false;
1142 this.m_indentAmount = 0;
1143 this.m_inEntityRef = false;
1144 this.m_inExternalDTD = false;
1145 this.m_mediatype = null;
1146 this.m_needToCallStartDocument = true;
1147 this.m_needToOutputDocTypeDecl = false;
1148 if (this.m_prefixMap != null)
1149 this.m_prefixMap.reset();
1150 this.m_shouldNotWriteXMLHeader = false;
1151 this.m_sourceLocator = null;
1152 this.m_standalone = null;
1153 this.m_standaloneWasSpecified = false;
1154 this.m_tracer = null;
1155 this.m_transformer = null;
1156 this.m_version = null;
1157 // don't set writer to null, so that it might be re-used
1158 //this.m_writer = null;
1159 }
1160
1161 /**
1162 * Returns true if the serializer is used for temporary output rather than
1163 * final output.
|
76 }
77
78 /**
79 * true if we still need to call startDocumentInternal()
80 */
81 protected boolean m_needToCallStartDocument = true;
82
83 /** True if a trailing "]]>" still needs to be written to be
84 * written out. Used to merge adjacent CDATA sections
85 */
86 protected boolean m_cdataTagOpen = false;
87
88 /**
89 * All the attributes of the current element, collected from
90 * startPrefixMapping() calls, or addAddtribute() calls, or
91 * from the SAX attributes in a startElement() call.
92 */
93 protected AttributesImplSerializer m_attributes = new AttributesImplSerializer();
94
95 /**
96 * Tells if we're in an EntityRef event, true if it's greater than 0. Use
97 * integer type to handle nested entity reference, increase m_inEntityRef in
98 * startEntity, decrease m_inEntityRef in endEntity.
99 */
100 protected int m_inEntityRef = 0;
101
102 /** This flag is set while receiving events from the external DTD */
103 protected boolean m_inExternalDTD = false;
104
105 /**
106 * The System ID for the doc type.
107 */
108 protected String m_doctypeSystem;
109
110 /**
111 * The public ID for the doc type.
112 */
113 protected String m_doctypePublic;
114
115 /**
116 * Flag to tell that we need to add the doctype decl, which we can't do
117 * until the first element is encountered.
118 */
119 boolean m_needToOutputDocTypeDecl = true;
120
129 private String m_standalone;
130
131 /**
132 * True if standalone was specified.
133 */
134 protected boolean m_standaloneWasSpecified = false;
135
136 /**
137 * Determine if the output is a standalone.
138 */
139 protected boolean m_isStandalone = false;
140
141 /**
142 * Flag to tell if indenting (pretty-printing) is on.
143 */
144 protected boolean m_doIndent = false;
145
146 /**
147 * Amount to indent.
148 */
149 protected int m_indentAmount = 4;
150
151 /**
152 * Tells the XML version, for writing out to the XML decl.
153 */
154 protected String m_version = null;
155
156 /**
157 * The mediatype. Not used right now.
158 */
159 protected String m_mediatype;
160
161 /**
162 * The transformer that was around when this output handler was created (if
163 * any).
164 */
165 private Transformer m_transformer;
166
167 /**
168 * Namespace support, that keeps track of currently defined
169 * prefix/uri mappings. As processed elements come and go, so do
429 * interface, it should return null.
430 *
431 * @return A {@link ContentHandler} interface into this serializer,
432 * or null if the serializer is not SAX 2 capable
433 * @throws IOException An I/O exception occured
434 */
435 public ContentHandler asContentHandler() throws IOException {
436 return this;
437 }
438
439 /**
440 * Report the end of an entity.
441 *
442 * @param name The name of the entity that is ending.
443 * @throws org.xml.sax.SAXException The application may raise an exception.
444 * @see #startEntity
445 */
446 public void endEntity(String name) throws org.xml.sax.SAXException {
447 if (name.equals("[dtd]"))
448 m_inExternalDTD = false;
449
450 if (!m_inExternalDTD)
451 m_inEntityRef--;
452
453 if (m_tracer != null)
454 this.fireEndEntity(name);
455 }
456
457 /**
458 * This method checks if current node is in entity reference.
459 *
460 * @return True if current node is in entity reference.
461 */
462 protected boolean isInEntityRef() {
463 return m_inEntityRef > 0;
464 }
465
466 /**
467 * Flush and close the underlying java.io.Writer. This method applies to
468 * ToStream serializers, not ToSAXHandler serializers.
469 * @see ToStream
470 */
471 public void close() {
472 // do nothing (base behavior)
473 }
474
475 /**
476 * Initialize global variables
477 */
478 protected void initCDATA() {
479 // CDATA stack
480 // _cdataStack = new Stack();
481 // _cdataStack.push(new Integer(-1)); // push dummy value
482 }
483
484 /**
485 * Returns the character encoding to be used in the output document.
486 * @return the character encoding to be used in the output document.
1135 public void setNamespaceMappings(NamespaceMappings mappings) {
1136 m_prefixMap = mappings;
1137 }
1138
1139 public boolean reset() {
1140 resetSerializerBase();
1141 return true;
1142 }
1143
1144 /**
1145 * Reset all of the fields owned by SerializerBase
1146 *
1147 */
1148 private void resetSerializerBase() {
1149 this.m_attributes.clear();
1150 this.m_StringOfCDATASections = null;
1151 this.m_elemContext = new ElemContext();
1152 this.m_doctypePublic = null;
1153 this.m_doctypeSystem = null;
1154 this.m_doIndent = false;
1155 this.m_indentAmount = 4;
1156 this.m_inEntityRef = 0;
1157 this.m_inExternalDTD = false;
1158 this.m_mediatype = null;
1159 this.m_needToCallStartDocument = true;
1160 this.m_needToOutputDocTypeDecl = false;
1161 if (this.m_prefixMap != null)
1162 this.m_prefixMap.reset();
1163 this.m_shouldNotWriteXMLHeader = false;
1164 this.m_sourceLocator = null;
1165 this.m_standalone = null;
1166 this.m_standaloneWasSpecified = false;
1167 this.m_tracer = null;
1168 this.m_transformer = null;
1169 this.m_version = null;
1170 // don't set writer to null, so that it might be re-used
1171 //this.m_writer = null;
1172 }
1173
1174 /**
1175 * Returns true if the serializer is used for temporary output rather than
1176 * final output.
|