Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

XalanXMLSerializerBase.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(XALANXMLSERIALIZERBASE_HEADER_GUARD_1357924680)
17 #define XALANXMLSERIALIZERBASE_HEADER_GUARD_1357924680
18 
19 
20 
21 
22 // Base include file. Must be first.
24 
25 
26 
28 
29 
30 
32 
33 
34 
35 // Base class header file.
37 
38 
39 
40 XALAN_CPP_NAMESPACE_BEGIN
41 
42 
43 
44 class XalanOutputStream;
45 
46 
47 
48 XALAN_USING_XERCES(MemoryManager)
49 
50 
51 
52 
57 {
58 public:
59 
63  static void
64  initialize(MemoryManager& theManager);
65 
69  static void
70  terminate();
71 
72 
88  MemoryManager& theManager,
89  eXMLVersion theXMLVersion,
90  const XalanDOMString& theEncoding,
91  const XalanDOMString& theDoctypeSystem,
92  const XalanDOMString& theDoctypePublic,
93  bool xmlDecl,
94  const XalanDOMString& theStandalone);
95 
96  virtual
98 
101  {
102  return m_elemStack.getMemoryManager();
103  }
104 
105 
106  // These methods are inherited from FormatterListener ...
107 
108  virtual void
109  setDocumentLocator(const Locator* const locator);
110 
111  virtual void
112  startDocument();
113 
114  virtual void
115  startElement(
116  const XMLCh* const name,
117  AttributeList& attrs) = 0;
118 
119  virtual void
120  endElement(const XMLCh* const name) = 0;
121 
122  virtual void
123  characters(
124  const XMLCh* const chars,
125  const unsigned int length);
126 
127  virtual void
128  charactersRaw(
129  const XMLCh* const chars,
130  const unsigned int length) = 0;
131 
132  virtual void
133  entityReference(const XMLCh* const name) = 0;
134 
135  virtual void
136  ignorableWhitespace(
137  const XMLCh* const chars,
138  const unsigned int length);
139 
140  virtual void
141  processingInstruction(
142  const XMLCh* const target,
143  const XMLCh* const data);
144 
145  virtual void
146  resetDocument();
147 
148  virtual void
149  comment(const XMLCh* const data) = 0;
150 
151  virtual void
152  cdata(
153  const XMLCh* const ch,
154  const unsigned int length);
155 
156  virtual const XalanDOMString&
157  getDoctypeSystem() const;
158 
159  virtual const XalanDOMString&
160  getDoctypePublic() const;
161 
162  virtual const XalanDOMString&
163  getEncoding() const = 0;
164 
165  const XalanDOMString&
166  getVersion() const
167  {
168  return m_version;
169  }
170 
171  const XalanDOMString&
173  {
174  return m_standalone;
175  }
176 
177  bool
179  {
180  return m_shouldWriteXMLHeader;
181  }
182 
183  void
185  {
186  m_shouldWriteXMLHeader = b;
187  }
188 
190 
191 
193 
195 
196 
198  {
199  public:
200 
201  // Static data members...
206 
210  static const char s_doctypeHeaderStartString[];
211 
213 
217  static const char s_doctypeHeaderPublicString[];
218 
220 
224  static const char s_doctypeHeaderSystemString[];
225 
227 
231  static const char s_xmlHeaderStartString[];
232 
234 
238  static const char s_xmlHeaderEncodingString[];
239 
241 
245  static const char s_xmlHeaderStandaloneString[];
246 
248 
252  static const char s_xmlHeaderEndString[];
253 
255 
259  static const char s_defaultVersionString[];
260 
262 
266  static const XalanDOMChar s_xhtmlDocTypeString[];
267 
269 
273  static const char s_cdataOpenString[];
274 
276 
280  static const char s_cdataCloseString[];
281 
283 
287  static const char s_lessThanEntityString[];
288 
290 
294  static const char s_greaterThanEntityString[];
295 
297 
301  static const char s_ampersandEntityString[];
302 
304 
308  static const char s_quoteEntityString[];
309 
311  };
312 
314  {
315  public:
316 
321 
325  static const XalanDOMChar s_doctypeHeaderStartString[];
326 
328 
332  static const XalanDOMChar s_doctypeHeaderPublicString[];
333 
335 
339  static const XalanDOMChar s_doctypeHeaderSystemString[];
340 
342 
346  static const XalanDOMChar s_xmlHeaderStartString[];
347 
349 
353  static const XalanDOMChar s_xmlHeaderEncodingString[];
354 
356 
360  static const XalanDOMChar s_xmlHeaderStandaloneString[];
361 
363 
367  static const XalanDOMChar s_xmlHeaderEndString[];
368 
370 
374  static const XalanDOMChar s_defaultVersionString[];
375 
377 
381  static const XalanDOMChar s_xhtmlDocTypeString[];
382 
384 
388  static const XalanDOMChar s_cdataOpenString[];
389 
391 
395  static const XalanDOMChar s_cdataCloseString[];
396 
398 
402  static const XalanDOMChar s_lessThanEntityString[];
403 
405 
409  static const XalanDOMChar s_greaterThanEntityString[];
410 
412 
416  static const XalanDOMChar s_ampersandEntityString[];
417 
419 
423  static const XalanDOMChar s_quoteEntityString[];
424 
426  };
427 
428  enum
429  {
430  eBufferSize = 512 // The size of the buffer
431  };
432 
434  {
435  public:
436 
437  bool
438  attribute(XalanDOMChar theChar) const
439  {
440  return theChar > s_lastSpecial ?
441  false :
442  s_specialChars[theChar] > eNone;
443  }
444 
445  bool
446  content(XalanDOMChar theChar) const
447  {
448  return theChar > s_lastSpecial ?
449  false :
450  s_specialChars[theChar] > eAttr;
451  }
452 
453  bool
454  range(XalanDOMChar theChar) const
455  {
456  assert(theChar > 0);
457 
458  return theChar > s_lastSpecial;
459  }
460 
461  bool
462  isForbidden(XalanDOMChar theChar) const
463  {
464  return theChar > s_lastSpecial ?
465  false :
466  s_specialChars[theChar] == eForb;
467  }
468 
469  bool
470  isCharRefForbidden(XalanDOMChar theChar) const
471  {
472  return theChar > s_lastSpecial ?
473  false :
474  s_specialChars[theChar] == eForb;
475  }
476 
477 
478  private:
479  static const size_t s_lastSpecial;
480 
481  static const char s_specialChars[];
482  };
483 
484 
485 
487  {
488  public:
489 
490  bool
491  attribute(XalanDOMChar theChar) const
492  {
493  return theChar > s_lastSpecial ?
494  false :
495  s_specialChars[theChar] > eNone;
496  }
497 
498  bool
499  content(XalanDOMChar theChar) const
500  {
501  return theChar > s_lastSpecial ?
502  false :
503  s_specialChars[theChar] > eAttr;
504  }
505 
506  bool
507  range(XalanDOMChar theChar) const
508  {
509  assert(theChar > 0);
510 
511  return theChar > s_lastSpecial;
512  }
513 
514  bool
515  isForbidden(XalanDOMChar theChar) const
516  {
517  return theChar > s_lastSpecial ?
518  false :
519  s_specialChars[theChar] == eForb;
520  }
521 
522  bool
523  isCharRefForbidden(XalanDOMChar theChar) const
524  {
525  return theChar > s_lastSpecial ?
526  false :
527  s_specialChars[theChar] == eCRFb;
528  }
529 
530  private:
531  static const size_t s_lastSpecial;
532 
533  static const char s_specialChars[];
534 
535  };
536 
537 
538 
539 
540  enum
541  {
542  eNone = 0u,
543  eAttr = 1u, // A flag to indicate a value in s_specialChars applies to attributes
544  eBoth = 2u, // A flag to indicate a value in s_specialChars applies to both content and attributes
545  eForb = 4u, // A flag to indicate a forbidden value in s_specialChars
546  // XML1.1 put a requirement to output chars #x1...#x1F and #x7F...#x9F as charRefs only
547  // In the comments , PI and CDATA usage of charRefs is forbidden, so we will report an error in
548  eCRFb = 5u // that case. For the elemets and attributes is should work the same as eBoth
549  };
550 
551 
552 
553 protected:
554 
555  virtual void
556  writeXMLHeader() = 0;
557 
558  virtual void
559  flushBuffer() = 0;
560 
561  virtual void
562  writeDoctypeDecl(const XalanDOMChar* name) = 0;
563 
564  virtual void
565  writeProcessingInstruction(
566  const XMLCh* target,
567  const XMLCh* data) = 0;
568 
569  virtual void
570  writeCharacters(
571  const XMLCh* chars,
572  unsigned int length) = 0;
573 
574  virtual void
575  writeCDATA(
576  const XMLCh* chars,
577  unsigned int length) = 0;
578 
579  virtual void
580  outputNewline() = 0;
581 
590  bool
592  {
593  if(!m_elemStack.empty())
594  {
595  // See if the parent element has already been flagged as having children.
596  if(false == m_elemStack.back())
597  {
598  m_elemStack.back() = true;
599 
600  return true;
601  }
602  }
603 
604  return false;
605  }
606 
611  bool
613  {
614  return m_needToOutputDoctypeDecl;
615  }
616 
620  void
622  {
623  m_elemStack.push_back(false);
624  }
625 
626  bool
628  {
629  return m_elemStack.empty();
630  }
631 
637  bool
639  {
640  bool fResult = false;
641 
642  if (m_elemStack.empty() == false)
643  {
644  fResult = m_elemStack.back();
645 
646  m_elemStack.pop_back();
647  }
648 
649  return fResult;
650  }
651 
652  void
653  generateDoctypeDecl(const XalanDOMChar* name)
654  {
655  if(true == m_needToOutputDoctypeDecl)
656  {
657  assert(m_doctypeSystem.empty() == false);
658 
659  writeDoctypeDecl(name);
660 
661  m_needToOutputDoctypeDecl = false;
662  }
663  }
664 
669 
674 
679 
684 
689 
694 
696 
697  static bool
698  isUTF16HighSurrogate(XalanDOMChar theChar)
699  {
700  return 0xD800u <= theChar && theChar <= 0xDBFFu ? true : false;
701  }
702 
703  static bool
704  isUTF16LowSurrogate(XalanDOMChar theChar)
705  {
706  return 0xDC00u <= theChar && theChar <= 0xDFFFu ? true : false;
707  }
708 
709  static unsigned int
710  decodeUTF16SurrogatePair(
711  XalanDOMChar theHighSurrogate,
712  XalanDOMChar theLowSurrogate,
713  MemoryManager& theManager);
714 
720  static void
721  throwInvalidUTF16SurrogateException(
722  XalanDOMChar ch,
723  MemoryManager& theManager);
724 
731  static void
732  throwInvalidUTF16SurrogateException(
733  XalanDOMChar ch,
734  XalanDOMChar next,
735  MemoryManager& theManager);
736 
743  static void
744  throwInvalidCharacterException(
745  unsigned int ch,
746  MemoryManager& theManager);
747 
748 
755  static void
756  throwInvalidXMLCharacterException(
757  unsigned int ch,
758  const XalanDOMString& theXMLversion,
759  MemoryManager& theManager);
760 private:
761 
762  // These are not implemented.
764 
766  operator=(const XalanXMLSerializerBase&);
767 
768  bool
769  operator==(const XalanXMLSerializerBase&) const;
770 
771  // Data members...
777  bool m_needToOutputDoctypeDecl;
778 
782  bool m_shouldWriteXMLHeader;
783 
788  BoolStackType m_elemStack;
789 
793  static const XalanDOMChar s_xhtmlDocTypeString[];
794 
795  static const XalanDOMString::size_type s_xhtmlDocTypeStringLength;
796 };
797 
798 
799 
800 XALAN_CPP_NAMESPACE_END
801 
802 
803 
804 #endif // XALANXMLSERIALIZERBASE_HEADER_GUARD_1357924680

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