Xalan-C++ API Reference  1.12.0
FormatterListener.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #if !defined(FORMATTERLISTENER_HEADER_GUARD_1357924680)
19 #define FORMATTERLISTENER_HEADER_GUARD_1357924680
20 
21 
22 
23 // Base include file. Must be first.
25 
26 
27 
28 #include <xercesc/sax/DocumentHandler.hpp>
29 
30 
31 
33 
34 
35 
36 namespace XALAN_CPP_NAMESPACE {
37 
38 
39 
40 class PrefixResolver;
41 class Writer;
42 
43 
44 
45 typedef xercesc::Locator LocatorType;
46 typedef xercesc::AttributeList AttributeListType;
47 
48 using xercesc::Locator;
49 using xercesc::AttributeList;
50 
51 
52 /**
53  * A SAX-based formatter interface for the XSL processor. This interface
54  * will be called as result tree elements are constructed.
55  */
56 class XALAN_PLATFORMSUPPORT_EXPORT FormatterListener : public xercesc::DocumentHandler
57 {
58 public:
59 
60  typedef xercesc::DocumentHandler ParentType;
61 
62  // A handy typedef... Must match DocumentHandler's type for characters(), etc...
63  typedef XalanSize_t size_type;
64 
65  enum eFormat
66  {
67  OUTPUT_METHOD_NONE = 0,
68  OUTPUT_METHOD_XML = 1,
69  OUTPUT_METHOD_HTML = 2,
70  OUTPUT_METHOD_TEXT = 3,
71  OUTPUT_METHOD_DOM = 4,
72  OUTPUT_METHOD_OTHER = 5
73  };
74 
76  {
77  XML_VERSION_1_0 = 0,
78  XML_VERSION_1_1 = 1
79  };
80 
81  FormatterListener(eFormat theFormat);
82 
83  virtual
85 
86  /**
87  * Get the output format for the instance.
88  *
89  * @return An enum indicating the output format.
90  */
91  eFormat
93  {
94  return m_outputFormat;
95  }
96 
97  /**
98  * Get the version of XML the FormatterListener is
99  * generating.
100  *
101  * @return An enum indication the XML version.
102  */
103  eXMLVersion
105  {
106  return m_XMLVersion;
107  }
108 
109  /**
110  * Determine if the version of XML output is 1.1.
111  *
112  * @return true if the output version is 1.1, false if not.
113  */
114  bool
116  {
117  return ( XML_VERSION_1_1 == m_XMLVersion );
118  }
119 
120  /**
121  * Get the PrefixResolver for the FormatterListener
122  *
123  * @return A pointer to the PrefixResolver, if any.
124  */
125  const PrefixResolver*
127  {
128  return m_prefixResolver;
129  }
130 
131  /**
132  * Set the PrefixResolver for the FormatterListener
133  *
134  * @param thePrefixResolver A pointer to the PrefixResolver, if any.
135  */
136  void
137  setPrefixResolver(const PrefixResolver* thePrefixResolver)
138  {
139  m_prefixResolver = thePrefixResolver;
140  }
141 
142  /**
143  * Receive notification of character data. If available, when the
144  * disable-output-escaping attribute is used, output raw text without
145  * escaping.
146  *
147  * @param chars pointer to characters from the XML document
148  * @param length number of characters to read from the array
149  * @exception SAXException
150  */
151  virtual void
152  charactersRaw(
153  const XMLCh* const chars,
154  const size_type length) = 0;
155 
156  /**
157  * Called when a Comment is to be constructed.
158  *
159  * @param data pointer to comment data
160  * @exception SAXException
161  */
162  virtual void
163  comment(const XMLCh* const data) = 0;
164 
165  /**
166  * Receive notification of cdata.
167  *
168  * <p>The Parser will call this method to report each chunk of
169  * character data. SAX parsers may return all contiguous character
170  * data in a single chunk, or they may split it into several
171  * chunks; however, all of the characters in any single event
172  * must come from the same external entity, so that the Locator
173  * provides useful information.</p>
174  *
175  * <p>The application must not attempt to read from the array
176  * outside of the specified range.</p>
177  *
178  * <p>Note that some parsers will report whitespace using the
179  * ignorableWhitespace() method rather than this one (validating
180  * parsers must do so).</p>
181  *
182  * @param ch pointer to characters from the XML document
183  * @param length number of characters to read from the array
184  * @exception SAXException
185  */
186  virtual void
187  cdata(
188  const XMLCh* const ch,
189  const size_type length) = 0;
190 
191  /**
192  * Receive notification of a entityReference.
193  *
194  * @param data pointer to characters from the XML document
195  * @exception SAXException
196  */
197  virtual void
198  entityReference(const XMLCh* const name) = 0;
199 
200 
201 // These methods are inherited from DocumentHandler ...
202 
203  virtual void
204  characters(
205  const XMLCh* const chars,
206  const size_type length) = 0;
207 
208  virtual void
209  endDocument() = 0;
210 
211  virtual void
212  endElement(const XMLCh* const name) = 0;
213 
214  virtual void
215  ignorableWhitespace(
216  const XMLCh* const chars,
217  const size_type length) = 0;
218 
219  virtual void
220  processingInstruction(
221  const XMLCh* const target,
222  const XMLCh* const data) = 0;
223 
224  virtual void
225  resetDocument() = 0;
226 
227  virtual void
228  setDocumentLocator(const Locator* const locator) = 0;
229 
230  virtual void
231  startDocument() = 0;
232 
233  virtual void
234  startElement(
235  const XMLCh* const name,
236  AttributeList& attrs) = 0;
237 
238  virtual Writer*
239  getWriter() const;
240 
241  virtual const XalanDOMString&
242  getDoctypeSystem() const;
243 
244  virtual const XalanDOMString&
245  getDoctypePublic() const;
246 
247  virtual const XalanDOMString&
248  getEncoding() const;
249 
250  virtual const XalanDOMString&
251  getMediaType() const;
252 
253  virtual int
254  getIndent() const;
255 
256 
257  // Used when creating PI to work around limitations of
258  // our interfaces...
259  static const XalanDOMChar s_piTarget[];
260 
261  static const XalanDOMChar s_piData[];
262 
265 
266 
267 protected:
268 
269  // Data membmers...
271 
273 
274  /**
275  * Set the output version during serializing.
276  *
277  * @param theVersion XML version of the output
278  */
279  void
281  {
282  m_XMLVersion = theVersion;
283  }
284 
285 private:
286 
287  // Not implemented...
289 
291  operator=(const FormatterListener&);
292 
293  bool
294  operator==(const FormatterListener&) const;
295 
296  // Data membmers...
297  const eFormat m_outputFormat;
298 
299  eXMLVersion m_XMLVersion;
300 };
301 
302 
303 
304 }
305 
306 
307 
308 #endif // FORMATTERLISTENER_HEADER_GUARD_1357924680
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::AttributeListType
xercesc::AttributeList AttributeListType
Definition: AttributeListImpl.hpp:41
xalanc::FormatterListener::m_prefixResolver
const PrefixResolver * m_prefixResolver
Definition: FormatterListener.hpp:270
XalanDOMString.hpp
xalanc::FormatterListener::eXMLVersion
eXMLVersion
Definition: FormatterListener.hpp:75
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
xalanc::FormatterListener::s_piTargetLength
static const XalanDOMString::size_type s_piTargetLength
Definition: FormatterListener.hpp:263
xalanc::operator==
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1118
xalanc::FormatterListener::eFormat
eFormat
Definition: FormatterListener.hpp:65
xalanc::FormatterListener::size_type
XalanSize_t size_type
Definition: FormatterListener.hpp:63
XALAN_PLATFORMSUPPORT_EXPORT
#define XALAN_PLATFORMSUPPORT_EXPORT
Definition: PlatformSupportDefinitions.hpp:35
PlatformSupportDefinitions.hpp
xalanc::FormatterListener::setXMLVersion
void setXMLVersion(eXMLVersion theVersion)
Set the output version during serializing.
Definition: FormatterListener.hpp:280
xalanc::FormatterListener::getOutputFormat
eFormat getOutputFormat() const
Get the output format for the instance.
Definition: FormatterListener.hpp:92
xalanc::FormatterListener::isXML1_1Version
bool isXML1_1Version() const
Determine if the version of XML output is 1.1.
Definition: FormatterListener.hpp:115
xalanc::FormatterListener::s_emptyString
static const XalanDOMString s_emptyString
Definition: FormatterListener.hpp:272
xalanc::length
XalanDOMString::size_type length(const XalanDOMString &theString)
Get the length of a XalanDOMString.
Definition: DOMStringHelper.hpp:235
xalanc::FormatterListener::setPrefixResolver
void setPrefixResolver(const PrefixResolver *thePrefixResolver)
Set the PrefixResolver for the FormatterListener.
Definition: FormatterListener.hpp:137
xalanc::PrefixResolver
This class defines an interface for classes that resolve namespace prefixes to their URIs.
Definition: PrefixResolver.hpp:39
xalanc::FormatterListener::s_piDataLength
static const XalanDOMString::size_type s_piDataLength
Definition: FormatterListener.hpp:264
xalanc::FormatterListener::getXMLVersion
eXMLVersion getXMLVersion() const
Get the version of XML the FormatterListener is generating.
Definition: FormatterListener.hpp:104
xalanc::FormatterListener::ParentType
xercesc::DocumentHandler ParentType
Definition: FormatterListener.hpp:60
xalanc::FormatterListener
A SAX-based formatter interface for the XSL processor.
Definition: FormatterListener.hpp:56
xalanc::XalanDOMString::size_type
XalanSize_t size_type
Definition: XalanDOMString.hpp:57
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::FormatterListener::getPrefixResolver
const PrefixResolver * getPrefixResolver() const
Get the PrefixResolver for the FormatterListener.
Definition: FormatterListener.hpp:126
xalanc::Writer
Definition: Writer.hpp:44
xalanc::LocatorType
xercesc::Locator LocatorType
Definition: ExecutionContext.hpp:47