18 #if !defined(FORMATTERTOXML_UNICODE_HEADER_GUARD_1357924680)
19 #define FORMATTERTOXML_UNICODE_HEADER_GUARD_1357924680
31 #include "xercesc/sax/AttributeList.hpp"
56 FormatterListener::eXMLVersion XMLVersion>
65 eDefaultIndentAmount = 0
85 MemoryManager& theManager,
92 size_type indent = eDefaultIndentAmount) :
101 m_stringBuffer(theManager),
102 m_writer(writer, theManager),
105 m_indentHandler(m_writer , indent)
111 MemoryManager& theManager,
125 ThisType*
const theResult =
126 new (theGuard.
get()) ThisType(
149 return m_writer.getWriter();
157 m_indentHandler.setStartNewLine(
true);
159 m_indentHandler.indent();
168 const XMLCh*
const name,
169 AttributeList& attrs)
171 generateDoctypeDecl(name);
175 m_indentHandler.setPreserve(
false);
177 m_indentHandler.indent();
179 m_indentHandler.setStartNewLine(
true);
181 m_writer.write(
value_type(XalanUnicode::charLessThanSign));
185 const XalanSize_t nAttrs = attrs.getLength();
187 for (XalanSize_t i = 0; i < nAttrs ; i++)
189 processAttribute(attrs.getName(i), attrs.getValue(i));
193 openElementForChildren();
195 m_indentHandler.increaseIndent();
197 m_indentHandler.setPrevText(
false);
203 m_indentHandler.decreaseIndent();
205 const bool hasChildNodes = childNodesWereAdded();
207 if (hasChildNodes ==
true)
209 m_indentHandler.indent();
211 m_writer.write(
value_type(XalanUnicode::charLessThanSign));
212 m_writer.write(
value_type(XalanUnicode::charSolidus));
218 if(m_spaceBeforeClose ==
true)
220 m_writer.write(
value_type(XalanUnicode::charSpace));
223 m_writer.write(
value_type(XalanUnicode::charSolidus));
226 m_writer.write(
value_type(XalanUnicode::charGreaterThanSign));
228 if (hasChildNodes ==
true)
230 m_indentHandler.pop_preserve();
233 m_indentHandler.setPrevText(
false);
238 const XMLCh*
const chars,
243 m_indentHandler.setPreserve(
true);
245 m_writer.write(chars,
length);
254 m_indentHandler.indent();
256 m_writer.write(
value_type(XalanUnicode::charAmpersand));
260 m_writer.write(
value_type(XalanUnicode::charSemicolon));
268 m_indentHandler.indent();
270 m_writer.write(
value_type(XalanUnicode::charLessThanSign));
271 m_writer.write(
value_type(XalanUnicode::charExclamationMark));
272 m_writer.write(
value_type(XalanUnicode::charHyphenMinus));
273 m_writer.write(
value_type(XalanUnicode::charHyphenMinus));
277 m_writer.write(
value_type(XalanUnicode::charHyphenMinus));
278 m_writer.write(
value_type(XalanUnicode::charHyphenMinus));
279 m_writer.write(
value_type(XalanUnicode::charGreaterThanSign));
281 m_indentHandler.setStartNewLine(
true);
289 m_writer.flushBuffer();
295 m_writer.flushWriter();
303 m_constants.s_xmlHeaderStartString,
304 m_constants.s_xmlHeaderStartStringLength);
306 if (m_version.empty() ==
false)
308 m_writer.write(m_version);
313 m_constants.s_defaultVersionString,
314 m_constants.s_defaultVersionStringLength);
319 m_constants.s_xmlHeaderEncodingString,
320 m_constants.s_xmlHeaderEncodingStringLength);
322 m_writer.write(m_encoding);
324 if (m_standalone.empty() ==
false)
327 m_constants.s_xmlHeaderStandaloneString,
328 m_constants.s_xmlHeaderStandaloneStringLength);
330 m_writer.write(m_standalone);
334 m_constants.s_xmlHeaderEndString,
335 m_constants.s_xmlHeaderEndStringLength);
337 if (getNeedToOutputDoctypeDecl() ==
false)
339 m_indentHandler.outputLineSep();
349 m_constants.s_doctypeHeaderStartString,
350 m_constants.s_doctypeHeaderStartStringLength);
352 m_writer.write(name);
354 if (m_doctypePublic.empty() ==
false)
358 m_constants.s_doctypeHeaderPublicString,
359 m_constants.s_doctypeHeaderPublicStringLength);
361 writeName(m_doctypePublic.c_str());
363 m_writer.write(
value_type(XalanUnicode::charQuoteMark));
364 m_writer.write(
value_type(XalanUnicode::charSpace));
365 m_writer.write(
value_type(XalanUnicode::charQuoteMark));
371 m_constants.s_doctypeHeaderSystemString,
372 m_constants.s_doctypeHeaderSystemStringLength);
375 writeName(m_doctypeSystem.c_str());
377 m_writer.write(
value_type(XalanUnicode::charQuoteMark));
378 m_writer.write(
value_type(XalanUnicode::charGreaterThanSign));
391 m_indentHandler.indent();
393 m_writer.write(
value_type(XalanUnicode::charLessThanSign));
394 m_writer.write(
value_type(XalanUnicode::charQuestionMark));
403 m_writer.write(
value_type(XalanUnicode::charSpace));
406 writeNormalizedData(data, len);
408 m_writer.write(
value_type(XalanUnicode::charQuestionMark));
409 m_writer.write(
value_type(XalanUnicode::charGreaterThanSign));
421 m_indentHandler.setPreserve(
true);
428 const XalanDOMChar ch = chars[i];
430 if(m_charPredicate.range(ch) ==
true)
432 safeWriteContent(chars + firstIndex, i - firstIndex);
434 i = writeNormalizedCharBig(chars, i,
length);
440 else if(m_charPredicate.content(ch) ==
false)
446 safeWriteContent(chars + firstIndex, i - firstIndex);
448 writeDefaultEscape(ch);
456 safeWriteContent(chars + firstIndex, i - firstIndex);
458 m_indentHandler.setPrevText(
true);
471 m_indentHandler.setPreserve(
true);
473 m_indentHandler.indent();
476 m_constants.s_cdataOpenString,
477 m_constants.s_cdataOpenStringLength);
479 bool outsideCDATA =
false;
481 writeCDATAChars(chars,
length, outsideCDATA);
483 if (outsideCDATA ==
false)
486 m_constants.s_cdataCloseString,
487 m_constants.s_cdataCloseStringLength);
497 m_writer.outputNewline();
506 assert(m_charPredicate.content(ch) ==
true);
508 if(!writeDefaultEntity(ch))
510 if (XalanUnicode::charLF == ch)
516 if(m_charPredicate.isForbidden(ch) ==
true)
518 throwInvalidXMLCharacterException(
525 writeNumericCharacterReference(ch);
537 assert(m_charPredicate.attribute(ch) ==
true);
539 if(writeDefaultAttributeEntity(ch) ==
false)
541 if(m_charPredicate.isForbidden(ch) ==
true)
543 throwInvalidXMLCharacterException(
550 writeNumericCharacterReference(ch);
563 if (XalanUnicode::charLessThanSign == ch)
566 m_constants.s_lessThanEntityString,
567 m_constants.s_lessThanEntityStringLength);
569 else if (XalanUnicode::charGreaterThanSign == ch)
572 m_constants.s_greaterThanEntityString,
573 m_constants.s_greaterThanEntityStringLength);
575 else if (XalanUnicode::charAmpersand == ch)
578 m_constants.s_ampersandEntityString,
579 m_constants.s_ampersandEntityStringLength);
596 if (writeDefaultEntity(ch) ==
true)
600 else if (XalanUnicode::charQuoteMark == ch)
603 m_constants.s_quoteEntityString,
604 m_constants.s_quoteEntityStringLength);
621 if(markParentForChildren() ==
true)
623 m_writer.write(
value_type(XalanUnicode::charGreaterThanSign));
625 m_indentHandler.setPrevText(
false);
627 m_indentHandler.push_preserve();
640 const XalanDOMChar chars[],
644 if (XalanUnicode::charLF == ch)
650 if(m_charPredicate.isCharRefForbidden(ch))
652 throwInvalidXMLCharacterException(
659 start = m_writer.write( chars, start,
length);
669 m_writer.write(
value_type(XalanUnicode::charAmpersand));
670 m_writer.write(
value_type(XalanUnicode::charNumberSign));
673 m_stringBuffer.clear();
675 m_writer.write(
value_type(XalanUnicode::charSemicolon));
680 const XalanDOMChar chars[],
686 const XalanDOMChar ch = chars[start];
688 assert(m_charPredicate.range(ch) ==
true);
690 if (XMLVersion == XML_VERSION_1_1 &&
691 XalanUnicode::charLSEP == ch)
693 writeNumericCharacterReference(ch);
697 start = m_writer.write(chars, start,
length);
711 const XalanDOMChar chars[],
724 const XalanDOMChar theChar = chars[i];
726 if (theChar == XalanUnicode::charRightSquareBracket &&
728 XalanUnicode::charRightSquareBracket == chars[i + 1] &&
729 XalanUnicode::charGreaterThanSign == chars[i + 2])
731 if (outsideCDATA ==
true)
734 m_constants.s_cdataCloseString,
735 m_constants.s_cdataCloseStringLength);
738 m_writer.write(
value_type(XalanUnicode::charRightSquareBracket));
739 m_writer.write(
value_type(XalanUnicode::charRightSquareBracket));
742 m_constants.s_cdataCloseString,
743 m_constants.s_cdataCloseStringLength);
746 m_constants.s_cdataOpenString,
747 m_constants.s_cdataOpenStringLength);
749 m_writer.write(
value_type(XalanUnicode::charGreaterThanSign));
751 outsideCDATA =
false;
757 if (XalanUnicode::charLF == theChar)
761 else if(m_charPredicate.isCharRefForbidden(theChar))
763 throwInvalidXMLCharacterException(
770 i = m_writer.writeCDATAChar(chars, i,
length, outsideCDATA);
777 if(outsideCDATA ==
true)
780 m_constants.s_cdataOpenString,
781 m_constants.s_cdataOpenStringLength);
794 const XalanDOMChar* theString,
797 assert(theString != 0);
802 while(i < theStringLength)
804 const XalanDOMChar ch = theString[i];
806 if(m_charPredicate.range(ch) ==
true)
808 safeWriteContent(theString + firstIndex, i - firstIndex);
810 i = writeNormalizedCharBig(theString, i, theStringLength);
816 else if (m_charPredicate.attribute(ch) ==
false)
822 safeWriteContent(theString + firstIndex, i - firstIndex);
824 writeDefaultAttributeEscape(ch);
832 safeWriteContent(theString + firstIndex, i - firstIndex);
844 const XalanDOMChar* name,
845 const XalanDOMChar* value)
847 m_writer.write(value_type(XalanUnicode::charSpace));
849 m_writer.write(value_type(XalanUnicode::charEqualsSign));
850 m_writer.write(value_type(XalanUnicode::charQuoteMark));
851 writeAttrString(value,
length(value));
852 m_writer.write(value_type(XalanUnicode::charQuoteMark));
862 const XalanDOMChar* theData,
865 for (
size_type i = 0; i < theLength; ++i)
867 const XalanDOMChar theChar = theData[i];
869 i = writeNormalizedChar(theChar, theData, i, theLength);
875 const XalanDOMChar* theChars,
880 m_writer.write(value_type(theChars[i]));
885 writeName(
const XalanDOMChar* theChars)
887 assert( theChars != 0);
889 m_writer.writeNameChar(theChars,
length(theChars));
895 FormatterToXMLUnicode(
const FormatterToXMLUnicode&);
897 FormatterToXMLUnicode&
898 operator=(
const FormatterToXMLUnicode&);
901 operator==(
const FormatterToXMLUnicode&)
const;
905 XalanDOMString m_stringBuffer;
907 UnicodeWriter m_writer;
909 ConstantsType m_constants;
911 CharPredicate m_charPredicate;
913 IndentHandler m_indentHandler;
922 #endif // FORMATTERTOXML_UNICODE_HEADER_GUARD_1357924680