Xalan-C++ API Reference  1.12.0
XMLParserLiaison.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(XMLPARSERLIAISON_HEADER_GUARD_1357924680)
19 #define XMLPARSERLIAISON_HEADER_GUARD_1357924680
20 
21 
22 
23 // Base include file. Must be first.
25 
26 
27 
29 
30 
31 
32 namespace XERCES_CPP_NAMESPACE
33 {
34  class DocumentHandler;
35  class EntityResolver;
36  class ErrorHandler;
37  class InputSource;
38  class XMLEntityResolver;
39 }
40 
41 
42 
43 namespace XALAN_CPP_NAMESPACE {
44 
45 
46 
47 typedef xercesc::DocumentHandler DocumentHandlerType;
48 typedef xercesc::EntityResolver EntityResolverType;
49 typedef xercesc::ErrorHandler ErrorHandlerType;
50 typedef xercesc::InputSource InputSourceType;
51 
52 using xercesc::DocumentHandler;
53 using xercesc::EntityResolver;
54 using xercesc::ErrorHandler;
55 using xercesc::InputSource;
56 using xercesc::XMLEntityResolver;
57 
58 
59 
60 class ExecutionContext;
61 class FormatterListener;
62 class XalanAttr;
63 class XalanDocument;
64 class XalanElement;
65 
66 
67 
69 {
70 
71 public:
72 
74 
75  virtual
77 
78 
79  // These interfaces are new to XMLParserLiaison
80 
81  /**
82  * Reset the instance, freeing any XalanDocument instances created
83  * through parseXMLStream().
84  */
85  virtual void
86  reset() = 0;
87 
88  /**
89  * Get a pointer to the current ExecutionContext instance, which
90  * may be null.
91  *
92  * @return A pointer to the current ExecutionContext, if any.
93  */
94  virtual ExecutionContext*
95  getExecutionContext() const = 0;
96 
97  /**
98  * Get a reference to the current MemoryManager instance.
99  *
100  * @return A pointer to the current ExecutionContext, if any.
101  */
102  virtual MemoryManager&
103  getMemoryManager() = 0;
104 
105  /**
106  * Set the current ExecutionContext instance.
107  *
108  * @parameter theContext A reference to the new ExecutionContext instance.
109  */
110  virtual void
111  setExecutionContext(ExecutionContext& theContext) = 0;
112 
113  /**
114  * Parse the text pointed at by the reader as XML, and return a DOM
115  * Document interface. It is recommended that you pass in some sort of
116  * recognizable name, such as the filename or URI, with which the reader
117  * can be recognized if the parse fails.
118  *
119  * The liaison owns the XalanDocument instance, and will delete it when
120  * asked (see DestroyDocument()), or when the liaison is reset, or goes
121  * out of scope.
122  *
123  * This function is not reentrant, so you cannot call it again until
124  * the current call exits.
125  *
126  * @param reader stream that should hold valid XML
127  * @param identifier used for diagnostic purposes only, some sort of
128  * identification for error reporting, default an empty
129  * string
130  * @return DOM document created
131  */
132  virtual XalanDocument*
133  parseXMLStream(
134  const InputSource& inputSource,
135  const XalanDOMString& identifier) = 0;
136 
137  /**
138  * Parse the text pointed at by the reader as XML. It is recommended that
139  * you pass in some sort of recognizable name, such as the filename or URI,
140  * with which the reader can be recognized if the parse fails.
141  *
142  * This function is reentrant, so you can call it again before any
143  * other call exits. However, it is not thread-safe.
144  *
145  * @param inputSource input source that should hold valid XML
146  * @param handler instance of a DocumentHandler
147  * @param identifier used for diagnostic purposes only, some sort of
148  * identification for error reporting, default an
149  * empty string
150  */
151  virtual void
152  parseXMLStream(
153  const InputSource& inputSource,
154  DocumentHandler& handler,
155  const XalanDOMString& identifier) = 0;
156 
157  /**
158  * Destroy the supplied XalanDocument instance. It must be an instance that
159  * was created by a previous call to parseXMLStream().
160  *
161  * @param theDocument The XalanDocument instance to destroy.
162  */
163  virtual void
164  destroyDocument(XalanDocument* theDocument) = 0;
165 
166  /**
167  * Get the amount to indent when indent-result="yes".
168  *
169  * @deprecated
170  *
171  * @return number of characters to indent
172  */
173  virtual int
174  getIndent() const = 0;
175 
176  /**
177  * Set the amount to indent when indent-result="yes".
178  *
179  * @deprecated
180  *
181  * @param i number of characters to indent
182  */
183  virtual void
184  setIndent(int i) = 0;
185 
186  /**
187  * Get whether or not validation will be performed. Validation is off by
188  * default.
189  *
190  * @return true to perform validation
191  */
192  virtual bool
193  getUseValidation() const = 0;
194 
195  /**
196  * If set to true, validation will be performed. Validation is off by
197  * default.
198  *
199  * @param b true to perform validation
200  */
201  virtual void
202  setUseValidation(bool b) = 0;
203 
204  /**
205  * Return a string suitable for telling the user what parser is being used.
206  *
207  * @return string describing parser
208  */
209  virtual const XalanDOMString&
210  getParserDescription(XalanDOMString& theResult) const = 0;
211 
212  /**
213  * This method returns the installed EntityResolver.
214  *
215  * @return The pointer to the installed EntityResolver object.
216  */
217  virtual EntityResolver*
218  getEntityResolver() const = 0;
219 
220  /**
221  * This method installs the user-specified EntityResolver on the
222  * parser. It allows applications to trap and redirect calls to
223  * external entities.
224  *
225  * A call to setEntityResolver with a non-null pointer will
226  * uninstall any XMLEntityResolver previously installed.
227  *
228  * @param handler A pointer to the EntityResolver to be called
229  * when the parser encounters references to
230  * external entities.
231  */
232  virtual void
233  setEntityResolver(EntityResolver* resolver) = 0;
234 
235  /**
236  * This method returns the installed XMLEntityResolver.
237  *
238  * @return The pointer to the installed XMLEntityResolver object.
239  */
240  virtual XMLEntityResolver*
241  getXMLEntityResolver() const = 0;
242 
243  /**
244  * This method installs the user-specified XMLEntityResolver on the
245  * parser. It allows applications to trap and redirect calls to
246  * external entities.
247  *
248  * A call to setXMLEntityResolver with a non-null pointer will
249  * uninstall any EntityResolver previously installed.
250  *
251  * @param handler A pointer to the entity resolver to be called
252  * when the parser encounters references to
253  * external entities.
254  */
255  virtual void
256  setXMLEntityResolver(XMLEntityResolver* resolver) = 0;
257 
258  /**
259  * This method returns the installed error handler.
260  *
261  * @return The pointer to the installed error handler object.
262  */
263  virtual ErrorHandler*
264  getErrorHandler() const = 0;
265 
266  /**
267  * This method installs the user-specified error handler.
268  *
269  * @param handler A pointer to the error handler to be called upon error.
270  */
271  virtual void
272  setErrorHandler(ErrorHandler* handler) = 0;
273 
274  // A utility class for classes to use.
276  {
277  public:
278 
280  XMLParserLiaison* theLiaison = 0,
281  ErrorHandler* theErrorHandler = 0) :
282  m_liaison(theLiaison),
283  m_errorHandler(theErrorHandler)
284  {
285  if (theLiaison != 0)
286  {
287  theLiaison->setErrorHandler(theErrorHandler);
288  }
289  }
290 
292  {
293  if (m_liaison != 0)
294  {
295  m_liaison->setErrorHandler(m_errorHandler);
296  }
297  }
298 
299  void
301  XMLParserLiaison* theLiaison,
302  ErrorHandler* theErrorHandler)
303  {
304  m_liaison = theLiaison;
305 
306  m_errorHandler = theErrorHandler;
307 
308  if (theLiaison != 0)
309  {
310  theLiaison->setErrorHandler(theErrorHandler);
311  }
312  }
313 
314  private:
315 
316  XMLParserLiaison* m_liaison;
317 
318  ErrorHandler* m_errorHandler;
319  };
320 
321 protected:
322 
323  // A utility class for derived classes to use.
325  {
326  public:
327 
329  XMLParserLiaison& theLiaison,
330  XalanDocument* theDocument) :
331  m_liaison(theLiaison),
332  m_document(theDocument)
333  {
334  }
335 
337  {
338  if (m_document != 0)
339  {
340  m_liaison.destroyDocument(m_document);
341  }
342  }
343 
345  get() const
346  {
347  return m_document;
348  }
349 
352  {
353  XalanDocument* theDocument = m_document;
354 
355  m_document = 0;
356 
357  return theDocument;
358  }
359 
360  private:
361 
362  XMLParserLiaison& m_liaison;
363 
364  XalanDocument* m_document;
365  };
366 
367 private:
368 
369  // Not implemented
371 
373  operator=(const XMLParserLiaison&);
374 };
375 
376 
377 
378 }
379 
380 
381 
382 #endif // XMLPARSERLIAISON_HEADER_GUARD_1357924680
xalanc::XMLParserLiaison::EnsureDestroyDocument::EnsureDestroyDocument
EnsureDestroyDocument(XMLParserLiaison &theLiaison, XalanDocument *theDocument)
Definition: XMLParserLiaison.hpp:328
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
XalanDOMString.hpp
xalanc::XMLParserLiaison::EnsureResetErrorHandler::~EnsureResetErrorHandler
~EnsureResetErrorHandler()
Definition: XMLParserLiaison.hpp:291
xalanc::XMLParserLiaison::EnsureDestroyDocument
Definition: XMLParserLiaison.hpp:324
xalanc::XMLParserLiaison::EnsureResetErrorHandler::set
void set(XMLParserLiaison *theLiaison, ErrorHandler *theErrorHandler)
Definition: XMLParserLiaison.hpp:300
xalanc::XalanDocument
Definition: XalanDocument.hpp:36
xalanc::XMLParserLiaison::EnsureDestroyDocument::release
XalanDocument * release()
Definition: XMLParserLiaison.hpp:351
xalanc::ErrorHandlerType
xercesc::ErrorHandler ErrorHandlerType
Definition: XalanCompiledStylesheetDefault.hpp:58
xalanc::XMLParserLiaison::setErrorHandler
virtual void setErrorHandler(ErrorHandler *handler)=0
This method installs the user-specified error handler.
xalanc::DocumentHandlerType
xercesc::DocumentHandler DocumentHandlerType
Definition: XMLParserLiaison.hpp:47
xalanc::XMLParserLiaison::EnsureDestroyDocument::~EnsureDestroyDocument
~EnsureDestroyDocument()
Definition: XMLParserLiaison.hpp:336
xalanc::XalanAttr
Definition: XalanAttr.hpp:40
xalanc::ExecutionContext
Definition: ExecutionContext.hpp:60
xalanc::XMLParserLiaison::EnsureDestroyDocument::get
XalanDocument * get() const
Definition: XMLParserLiaison.hpp:345
xalanc::XMLParserLiaison::EnsureResetErrorHandler::EnsureResetErrorHandler
EnsureResetErrorHandler(XMLParserLiaison *theLiaison=0, ErrorHandler *theErrorHandler=0)
Definition: XMLParserLiaison.hpp:279
xalanc::XMLParserLiaison::EnsureResetErrorHandler
Definition: XMLParserLiaison.hpp:275
xalanc::EntityResolverType
xercesc::EntityResolver EntityResolverType
Definition: XalanCompiledStylesheetDefault.hpp:57
xalanc::XMLParserLiaison
Definition: XMLParserLiaison.hpp:68
xalanc::InputSourceType
xercesc::InputSource InputSourceType
Definition: XMLParserLiaison.hpp:50
xalanc::XalanElement
Definition: XalanElement.hpp:44
xalanc::FormatterListener
A SAX-based formatter interface for the XSL processor.
Definition: FormatterListener.hpp:56
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
XMLSupportDefinitions.hpp
XALAN_XMLSUPPORT_EXPORT
#define XALAN_XMLSUPPORT_EXPORT
Definition: XMLSupportDefinitions.hpp:35