Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

FormatterToXML.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #if !defined(FORMATTERTOXML_HEADER_GUARD_1357924680)
17 #define FORMATTERTOXML_HEADER_GUARD_1357924680
18 
19 
20 
21 
22 // Base include file. Must be first.
24 
25 
26 
28 
29 
30 
32 
33 
34 
37 
38 
39 
40 // Base class header file.
42 
43 
44 
45 XALAN_CPP_NAMESPACE_BEGIN
46 
47 
48 
49 class Writer;
50 class XalanOutputStream;
51 
52 
53 
58 {
59 public:
60 
61  enum eDummy
62  {
63  eDefaultIndentAmount = 0
64  };
65 
88  Writer& writer,
90  bool doIndent = false,
91  int indent = eDefaultIndentAmount,
96  bool xmlDecl = true,
98  eFormat format = OUTPUT_METHOD_XML,
99  bool fBufferData = true,
101 
102  static FormatterToXML*
103  create(
104  MemoryManagerType& theManager,
105  Writer& writer,
107  bool doIndent = false,
108  int indent = eDefaultIndentAmount,
113  bool xmlDecl = true,
115  eFormat format = OUTPUT_METHOD_XML,
116  bool fBufferData = true);
117 
118  virtual
119  ~FormatterToXML();
120 
123  {
124  return m_stringBuffer.getMemoryManager();
125  }
126 
127  // These methods are inherited from FormatterListener ...
128 
129  virtual void
130  setDocumentLocator(const LocatorType* const locator);
131 
132  virtual void
133  startDocument();
134 
135  virtual void
136  endDocument();
137 
138  virtual void
139  startElement(
140  const XMLCh* const name,
141  AttributeListType& attrs);
142 
143  virtual void
144  endElement(const XMLCh* const name);
145 
146  virtual void
147  characters(
148  const XMLCh* const chars,
149  const unsigned int length);
150 
151  virtual void
153  const XMLCh* const chars,
154  const unsigned int length);
155 
156  virtual void
157  entityReference(const XMLCh* const name);
158 
159  virtual void
161  const XMLCh* const chars,
162  const unsigned int length);
163 
164  virtual void
166  const XMLCh* const target,
167  const XMLCh* const data);
168 
169 
170  virtual void
171  resetDocument();
172 
173  virtual void
174  comment(const XMLCh* const data);
175 
176  virtual void
177  cdata(
178  const XMLCh* const ch,
179  const unsigned int length);
180 
181  virtual Writer*
182  getWriter() const;
183 
184  virtual const XalanDOMString&
185  getDoctypeSystem() const;
186 
187  virtual const XalanDOMString&
188  getDoctypePublic() const;
189 
190  virtual const XalanDOMString&
191  getEncoding() const;
192 
193  virtual const XalanDOMString&
194  getMediaType() const;
195 
196  virtual int
197  getIndent() const;
198 
199  const XalanDOMString&
200  getVersion() const
201  {
202  return m_version;
203  }
204 
205  const XalanDOMString&
207  {
208  return m_standalone;
209  }
210 
211  bool
213  {
214  return m_shouldWriteXMLHeader;
215  }
216 
217  void
219  {
220  m_shouldWriteXMLHeader = b;
221  }
222 
223  bool
225  {
226  return m_stripCData;
227  }
228 
229  void
231  {
232  m_stripCData = b;
233  }
234 
235  bool
237  {
238  return m_escapeCData;
239  }
240 
241  void
243  {
244  m_escapeCData = b;
245  }
246 
247  bool
248  getDoIndent() const
249  {
250  return m_doIndent;
251  }
252 
253  void
254  setDoIndent(bool value)
255  {
256  m_doIndent = value;
257  }
258 
259  void
260  setIndent(int value)
261  {
262  m_indent = value;
263  }
264 
265 
269 
270 
271 protected:
272 
276  Writer* const m_writer;
277 
282 
286  void
287  outputLineSep();
288 
289  typedef void (FormatterToXML::*AccumCharFunctionType)(XalanDOMChar);
290 
291  typedef void (FormatterToXML::*AccumStringFunctionType)(const XalanDOMChar*);
292 
293  typedef void (FormatterToXML::*AccumDOMStringFunctionType)(const XalanDOMString&);
294 
295  typedef void (FormatterToXML::*AccumArrayFunctionType)(
296  const XalanDOMChar[],
299 
300  typedef void (FormatterToXML::*FlushFunctionType)();
301 
311  void
312  accumName(XalanDOMChar ch)
313  {
314  assert(m_accumNameCharFunction != 0);
315 
316  (this->*m_accumNameCharFunction)(ch);
317  }
318 
324  void
325  accumContent(XalanDOMChar ch)
326  {
327  assert(m_accumContentCharFunction != 0);
328 
329  (this->*m_accumContentCharFunction)(ch);
330  }
331 
342  void
343  accumName(const XalanDOMChar* chars)
344  {
345  assert(m_accumNameStringFunction != 0);
346 
347  (this->*m_accumNameStringFunction)(chars);
348  }
349 
356  void
357  accumContent(const XalanDOMChar* chars)
358  {
359  assert(m_accumContentStringFunction != 0);
360 
361  (this->*m_accumContentStringFunction)(chars);
362  }
363 
375  void
377  const XalanDOMChar chars[],
380  {
381  assert(m_accumNameArrayFunction != 0);
382 
383  (this->*m_accumNameArrayFunction)(chars, start, length);
384  }
385 
393  void
395  const XalanDOMChar chars[],
398  {
399  assert(m_accumContentArrayFunction != 0);
400 
401  (this->*m_accumContentArrayFunction)(chars, start, length);
402  }
403 
413  void
415  {
416  assert(m_accumNameDOMStringFunction != 0);
417 
418  (this->*m_accumNameDOMStringFunction)(str);
419  }
420 
426  void
428  {
429  assert(m_accumContentDOMStringFunction != 0);
430 
431  (this->*m_accumContentDOMStringFunction)(str);
432  }
433 
438  accumDefaultEscape(
439  XalanDOMChar ch,
441  const XalanDOMChar chars[],
443  bool escLF);
444 
449  virtual bool
450  accumDefaultEntity(
451  XalanDOMChar ch,
452  bool escLF);
453 
457  void
458  initAttrCharsMap();
459 
463  void
464  initCharsMap();
465 
469  void
470  flushChars();
471 
475  void
476  flushBytes();
477 
478  void
479  flushWriter();
480 
481  void
482  openElementForChildren();
483 
484  bool
485  childNodesWereAdded();
486 
487  bool
488  shouldIndent() const
489  {
490  return m_doIndent && (!m_ispreserve && !m_isprevtext);
491  }
492 
497  void
498  writeParentTagEnd();
499 
504  void
505  indent(int n);
506 
514  virtual void
515  writeNormalizedChars(
516  const XalanDOMChar ch[],
519  bool isCData);
520 
526  void
527  writeNumberedEntityReference(unsigned long theNumber);
528 
535  virtual void
536  writeAttrString(
537  const XalanDOMChar* theString,
538  XalanDOMString::size_type theStringLength);
539 
544  virtual void
545  accumCommentData(const XalanDOMChar* data);
546 
553  static void
554  throwInvalidUTF16SurrogateException(
555  XalanDOMChar ch,
556  MemoryManagerType& theManager);
557 
565  static void
566  throwInvalidUTF16SurrogateException(
567  XalanDOMChar ch,
568  XalanDOMChar next,
569  MemoryManagerType& theManager);
570 
571 
578  static void
579  throwInvalidCharacterException(
580  unsigned int ch,
581  MemoryManagerType& theManager);
582 
583  static bool
584  isUTF16Surrogate(XalanDOMChar ch)
585  {
586  return (ch & 0xFC00) == 0xD800 ? true : false;
587  }
588 
589  enum eDummyTwo { SPECIALSSIZE = 256};
590 
595  XalanDOMChar m_maxCharacter;
596 
597  XalanDOMChar m_attrCharsMap[SPECIALSSIZE];
598 
599  XalanDOMChar m_charsMap[SPECIALSSIZE];
600 
605 
611 
616 
621 
628 
634 
640 
645 
649  bool m_inCData;
650 
656 
661 
666 
671 
676 
680  int m_indent;
681 
687 
688  // A text buffer. We use it mostly for converting
689  // to string values. See uses of UnsignedLongToString()
690  // and UnsignedLongToHexString().
692 
693 private:
694 
695  // These are not implemented.
697 
699  operator=(const FormatterToXML&);
700 
701  bool
702  operator==(const FormatterToXML&) const;
703 
712  void
713  accumNameAsByte(XalanDOMChar ch);
714 
723  void
724  accumNameAsByteDirect(XalanDOMChar ch);
725 
733  void
734  accumContentAsByte(XalanDOMChar ch);
735 
743  void
744  accumContentAsByteDirect(XalanDOMChar ch);
745 
754  void
755  accumNameAsChar(XalanDOMChar ch);
756 
765  void
766  accumNameAsCharDirect(XalanDOMChar ch);
767 
773  void
774  accumContentAsChar(XalanDOMChar ch);
775 
781  void
782  accumContentAsCharDirect(XalanDOMChar ch);
783 
791  void
792  accumCharUTF(XalanDOMChar ch);
793 
801  void
802  accumCharUTFDirect(XalanDOMChar ch);
803 
812  void
813  accumNameString(const XalanDOMChar* chars);
814 
822  void
823  accumStringUTF(const XalanDOMChar* chars);
824 
832  void
833  accumStringUTFDirect(const XalanDOMChar* chars);
834 
842  void
843  accumContentString(const XalanDOMChar* chars);
844 
854  void
855  accumNameArray(
856  const XalanDOMChar chars[],
859 
869  void
870  accumContentArray(
871  const XalanDOMChar chars[],
874 
884  void
885  accumArrayUTF(
886  const XalanDOMChar chars[],
889 
899  void
900  accumArrayUTFDirect(
901  const XalanDOMChar chars[],
904 
912  void
913  accumNameDOMString(const XalanDOMString& str);
914 
922  void
923  accumContentDOMString(const XalanDOMString& str);
924 
932  void
933  accumDOMStringUTF(const XalanDOMString& str);
934 
942  void
943  accumDOMStringUTFDirect(const XalanDOMString& str);
944 
950  void
951  outputDocTypeDecl(const XalanDOMChar* name);
952 
958  void
959  processAttribute(
960  const XalanDOMChar* name,
961  const XalanDOMChar* value);
962 
967  void
968  printSpace(int n);
969 
975  void
976  accumNormalizedPIData(
977  const XalanDOMChar* theData,
978  XalanDOMString::size_type theLength);
979 
980 
981  // Data members...
985  bool m_bytesEqualChars;
986 
987  bool m_shouldFlush;
988 
992  bool m_spaceBeforeClose;
993 
999  bool m_escapeCData;
1000 
1004  const XalanDOMString m_version;
1005 
1009  const XalanDOMString m_standalone;
1010 
1014  const XalanDOMString m_mediaType;
1015 
1019  const XalanDOMString m_attrSpecialChars;
1020 
1022 
1026  static const XalanDOMChar s_doctypeHeaderStartString[];
1027 
1028  static const size_type s_doctypeHeaderStartStringLength;
1029 
1033  static const XalanDOMChar s_doctypeHeaderPublicString[];
1034 
1035  static const size_type s_doctypeHeaderPublicStringLength;
1036 
1040  static const XalanDOMChar s_doctypeHeaderSystemString[];
1041 
1042  static const size_type s_doctypeHeaderSystemStringLength;
1043 
1047  static const XalanDOMChar s_xmlHeaderStartString[];
1048 
1049  static const size_type s_xmlHeaderStartStringLength;
1050 
1054  static const XalanDOMChar s_xmlHeaderEncodingString[];
1055 
1056  static const size_type s_xmlHeaderEncodingStringLength;
1057 
1061  static const XalanDOMChar s_xmlHeaderStandaloneString[];
1062 
1063  static const size_type s_xmlHeaderStandaloneStringLength;
1064 
1068  static const XalanDOMChar s_xmlHeaderEndString[];
1069 
1070  static const size_type s_xmlHeaderEndStringLength;
1071 
1075  static const XalanDOMChar s_defaultVersionString[];
1076 
1077  static const size_type s_defaultVersionStringLength;
1078 
1082  static const XalanDOMChar s_xhtmlDocTypeString[];
1083 
1084  static const size_type s_xhtmlDocTypeStringLength;
1085 
1089  static const XalanDOMChar s_dtdCDATACloseString[];
1090 
1091  static const size_type s_dtdCDATACloseStringLength;
1092 
1093  DOMCharBufferType m_charBuf;
1094 
1096 
1097  ByteBufferType m_byteBuf;
1098 
1099  static const XalanDOMString::size_type s_maxBufferSize;
1100 
1105  BoolStackType m_elemStack;
1106 
1111  AccumCharFunctionType m_accumNameCharFunction;
1112 
1117  AccumStringFunctionType m_accumNameStringFunction;
1118 
1123  AccumDOMStringFunctionType m_accumNameDOMStringFunction;
1124 
1129  AccumArrayFunctionType m_accumNameArrayFunction;
1130 
1135  AccumCharFunctionType m_accumContentCharFunction;
1136 
1141  AccumStringFunctionType m_accumContentStringFunction;
1142 
1147  AccumDOMStringFunctionType m_accumContentDOMStringFunction;
1148 
1153  AccumArrayFunctionType m_accumContentArrayFunction;
1154 
1158  FlushFunctionType m_flushFunction;
1159 
1163  const XalanDOMChar* m_newlineString;
1164 
1168  XalanDOMString::size_type m_newlineStringLength;
1169 
1170  bool m_isXML1_1;
1171 };
1172 
1173 
1174 
1175 XALAN_CPP_NAMESPACE_END
1176 
1177 
1178 
1179 #endif // FORMATTERTOXML_HEADER_GUARD_1357924680
void accumContent(const XalanDOMString &str)
Append a string to the buffer.
Definition: FormatterToXML.hpp:427
const XalanDOMString m_doctypeSystem
The System ID for the doc type.
Definition: FormatterToXML.hpp:660
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1111
bool m_ispreserve
State flag to tell if preservation of whitespace is important.
Definition: FormatterToXML.hpp:610
virtual const XalanDOMString & getEncoding() const
void accumName(const XalanDOMChar *chars)
Append a null-terminated array of wide characters to the buffer.
Definition: FormatterToXML.hpp:343
virtual const XalanDOMString & getDoctypePublic() const
bool m_shouldWriteXMLHeader
If true, XML header should be written to output.
Definition: FormatterToXML.hpp:604
XERCES_CPP_NAMESPACE_QUALIFIER AttributeList AttributeListType
Definition: AttributeListImpl.hpp:39
XALAN_CPP_NAMESPACE_BEGIN typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager MemoryManagerType
Definition: XalanMemoryManagement.hpp:39
Definition: Writer.hpp:42
virtual void startDocument()=0
void accumContent(const XalanDOMChar chars[], XalanDOMString::size_type start, XalanDOMString::size_type length)
Append an array of wide character to the buffer.
Definition: FormatterToXML.hpp:394
void setEscapeCData(bool b)
Definition: FormatterToXML.hpp:242
bool getStripCData() const
Definition: FormatterToXML.hpp:224
virtual void setDocumentLocator(const Locator *const locator)=0
void setShouldWriteXMLHeader(bool b)
Definition: FormatterToXML.hpp:218
virtual void startElement(const XMLCh *const name, AttributeList &attrs)=0
eDummy
Definition: FormatterToXML.hpp:61
bool getShouldWriteXMLHeader() const
Definition: FormatterToXML.hpp:212
void setStripCData(bool b)
Definition: FormatterToXML.hpp:230
bool shouldIndent() const
Definition: FormatterToXML.hpp:488
virtual void ignorableWhitespace(const XMLCh *const chars, const size_type length)=0
static bool isUTF16Surrogate(XalanDOMChar ch)
Definition: FormatterToXML.hpp:584
int m_currentIndent
Flag to keep track of the indent amount.
Definition: FormatterToXML.hpp:675
virtual int getIndent() const
virtual Writer * getWriter() const
int m_indent
Amount to indent.
Definition: FormatterToXML.hpp:680
XalanVector< XalanDOMChar > DOMCharBufferType
Definition: FormatterToXML.hpp:267
#define XALAN_DEFAULT_MEMMGR
Definition: XalanMemoryManagement.hpp:402
bool m_isprevtext
State flag that tells if the previous node processed was text, so we can tell if we should preserve w...
Definition: FormatterToXML.hpp:633
virtual void resetDocument()=0
virtual const XalanDOMString & getMediaType() const
void accumName(XalanDOMChar ch)
Append a wide character to the buffer.
Definition: FormatterToXML.hpp:312
void accumContent(const XalanDOMChar *chars)
Append a null-terminated array of wide characters to the buffer.
Definition: FormatterToXML.hpp:357
eDummyTwo
Definition: FormatterToXML.hpp:589
virtual void charactersRaw(const XMLCh *const chars, const size_type length)=0
Receive notification of character data.
virtual void characters(const XMLCh *const chars, const size_type length)=0
void accumName(const XalanDOMString &str)
Append a string to the buffer.
Definition: FormatterToXML.hpp:414
XalanVector< bool > BoolStackType
Definition: FormatterToXML.hpp:266
A SAX-based formatter interface for the XSL processor.
Definition: FormatterListener.hpp:62
virtual void endDocument()=0
unsigned int size_type
Definition: FormatterListener.hpp:69
static MemoryManager & getDummyMemMgr()
bool getDoIndent() const
Definition: FormatterToXML.hpp:248
bool m_doIndent
Flag to tell if indenting (pretty-printing) is on.
Definition: FormatterToXML.hpp:615
#define XALAN_XMLSUPPORT_EXPORT
Definition: XMLSupportDefinitions.hpp:33
XalanDOMString m_stringBuffer
Definition: FormatterToXML.hpp:691
bool m_inCData
Tells if we're in CData section.
Definition: FormatterToXML.hpp:649
virtual void entityReference(const XMLCh *const name)=0
Receive notification of a entityReference.
virtual void cdata(const XMLCh *const ch, const size_type length)=0
Receive notification of cdata.
void accumName(const XalanDOMChar chars[], XalanDOMString::size_type start, XalanDOMString::size_type length)
Append an array of wide character to the buffer.
Definition: FormatterToXML.hpp:376
void setIndent(int value)
Definition: FormatterToXML.hpp:260
bool getEscapeCData() const
Definition: FormatterToXML.hpp:236
Writer *const m_writer
The writer where the XML will be written.
Definition: FormatterToXML.hpp:276
virtual void endElement(const XMLCh *const name)=0
const XalanDOMString & getVersion() const
Definition: FormatterToXML.hpp:200
XERCES_CPP_NAMESPACE_QUALIFIER Locator LocatorType
Definition: FormatterListener.hpp:47
bool m_startNewLine
Flag to signal that a newline should be added.
Definition: FormatterToXML.hpp:620
bool m_needToOutputDocTypeDecl
Flag to tell that we need to add the doctype decl, which we can't do until the first element is encou...
Definition: FormatterToXML.hpp:627
Definition: XalanOutputStream.hpp:47
FormatterToXML formats SAX-style events into XML.
Definition: FormatterToXML.hpp:57
virtual const XalanDOMString & getDoctypeSystem() const
XalanVector< char > ByteBufferType
Definition: FormatterToXML.hpp:268
bool m_stripCData
If true, cdata sections are simply stripped of their CDATA brackets, without escaping.
Definition: FormatterToXML.hpp:639
const XalanDOMString & getStandalone() const
Definition: FormatterToXML.hpp:206
bool m_nextIsRaw
Tell if the next text should be raw.
Definition: FormatterToXML.hpp:644
Definition: XalanDOMString.hpp:42
bool m_encodingIsUTF
Flag to quickly tell if the encoding is capable of full Unicode support.
Definition: FormatterToXML.hpp:655
MemoryManagerType & getMemoryManager()
Definition: FormatterToXML.hpp:122
XalanDOMString::size_type length(const XalanDOMString &theString)
Get the length of a XalanDOMString.
Definition: DOMStringHelper.hpp:277
virtual void processingInstruction(const XMLCh *const target, const XMLCh *const data)=0
XalanOutputStream *const m_stream
The stream where the XML will be written.
Definition: FormatterToXML.hpp:281
void accumContent(XalanDOMChar ch)
Append a wide character to the buffer.
Definition: FormatterToXML.hpp:325
const XalanDOMString m_doctypePublic
The public ID for the doc type.
Definition: FormatterToXML.hpp:665
unsigned int size_type
Definition: XalanDOMString.hpp:53
void setDoIndent(bool value)
Definition: FormatterToXML.hpp:254
XalanDOMString m_encoding
The character encoding.
Definition: FormatterToXML.hpp:670
XalanDOMChar m_maxCharacter
The maximum character size before we have to resort to escaping.
Definition: FormatterToXML.hpp:595
virtual void comment(const XMLCh *const data)=0
Called when a Comment is to be constructed.
BoolStackType m_preserves
Stack to keep track of whether or not we need to preserve whitespace.
Definition: FormatterToXML.hpp:686

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

dot

Xalan-C++ XSLT Processor Version 1.10
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.

Apache Logo