Annotation of parser3/src/classes/xalan-patched/XalanTransformer2.hpp, revision 1.4
1.2 parser 1: /** @file
2: Parser: patched transform method to
3: 1. return exceptions
4: 2. pass string params
5: impl.
6:
7: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
8: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
9:
1.4 ! paf 10: $Id: XalanTransformer2.hpp,v 1.3 2001/10/18 11:49:02 parser Exp $
1.2 parser 11:
12: based on:
13: */
1.1 parser 14: /*
15: * The Apache Software License, Version 1.1
16: *
17: *
18: * Copyright (c) 2001 The Apache Software Foundation. All rights
19: * reserved.
20: *
21: * Redistribution and use in source and binary forms, with or without
22: * modification, are permitted provided that the following conditions
23: * are met:
24: *
25: * 1. Redistributions of source code must retain the above copyright
26: * notice, this list of conditions and the following disclaimer.
27: *
28: * 2. Redistributions in binary form must reproduce the above copyright
29: * notice, this list of conditions and the following disclaimer in
30: * the documentation and/or other materials provided with the
31: * distribution.
32: *
33: * 3. The end-user documentation included with the redistribution,
34: * if any, must include the following acknowledgment:
35: * "This product includes software developed by the
36: * Apache Software Foundation (http://www.apache.org/)."
37: * Alternately, this acknowledgment may appear in the software itself,
38: * if and wherever such third-party acknowledgments normally appear.
39: *
40: * 4. The names "Xalan" and "Apache Software Foundation" must
41: * not be used to endorse or promote products derived from this
42: * software without prior written permission. For written
43: * permission, please contact apache@apache.org.
44: *
45: * 5. Products derived from this software may not be called "Apache",
46: * nor may "Apache" appear in their name, without prior written
47: * permission of the Apache Software Foundation.
48: *
49: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
50: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
52: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
53: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
56: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
57: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
58: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
59: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60: * SUCH DAMAGE.
61: * ====================================================================
62: *
63: * This software consists of voluntary contributions made by many
64: * individuals on behalf of the Apache Software Foundation and was
65: * originally based on software copyright (c) 1999, International
66: * Business Machines, Inc., http://www.ibm.com. For more
67: * information on the Apache Software Foundation, please see
68: * <http://www.apache.org/>.
69: */
70: #if !defined(XALANTRANSFORMER_HEADER_GUARD)
71: #define XALANTRANSFORMER_HEADER_GUARD
72:
73:
74:
75: // Base include file. Must be first.
76: #include <XalanTransformer/XalanTransformerDefinitions.hpp>
77:
78:
79:
80: #include <vector>
81:
82:
83:
84: #include <XPath/XalanQNameByValue.hpp>
85:
86:
87:
88: #include <XSLT/XSLTInputSource.hpp>
89: #include <XSLT/XSLTResultTarget.hpp>
90:
91:
92:
93: class Function;
94: class StylesheetExecutionContextDefault;
95: class XSLTInit;
96: class XalanDocumentBuilder;
97: class XalanCompiledStylesheet;
98: class XalanParsedSource;
99: class XalanTransformerOutputStream;
100:
101:
102:
103: /**
104: * This is a simple C++ interface for some common usage patterns. It's
105: * the user's responsibility to call initialize and terminate for Xerces
1.2 parser 106: * and Xalan before creating and after deleting any XalanTransformer2
1.1 parser 107: * instances.
108: */
1.2 parser 109: class /*XALAN_TRANSFORMER_EXPORT*/ XalanTransformer2
1.1 parser 110: {
111: public:
112:
1.2 parser 113: XalanTransformer2();
1.1 parser 114:
115: virtual
1.2 parser 116: ~XalanTransformer2();
1.1 parser 117:
118: /**
119: * Initialize Xalan.
120: * Should be called only once per process before creating any
1.2 parser 121: * instances of XalanTransformer2. See class XSLTInit.
1.1 parser 122: */
123: static void
124: initialize();
125:
126: /**
127: * Terminate Xalan.
128: * Should be called only once per process after deleting all
1.2 parser 129: * instances of XalanTransformer2. See class XSLTInit.
1.1 parser 130: */
131: static void
132: terminate();
133:
134: /**
135: * Transform will apply the stylesheet source to the parsed xml source
136: * and write the transformation output to the target.
137: *
138: * @param theParsedXML the parsed input source
139: * @param theStylesheetSource stylesheet source
140: * @param theResultTarget output source
141: * @return 0 for success
142: */
143: int
144: transform(
145: const XalanParsedSource& theParsedXML,
146: const XSLTInputSource& theStylesheetSource,
147: const XSLTResultTarget& theResultTarget);
148:
149: /**
150: * Transform will apply the compiled stylesheet to the parsed xml source
151: * and write the transformation output to the target.
152: *
153: * @param theParsedXML the parsed input source
154: * @param theCompiledStylesheet pointer to a compiled stylesheet
155: * @param theResultTarget output source
156: * @return 0 for success
157: */
158: int
159: transform(
160: const XalanParsedSource& theParsedXML,
161: const XalanCompiledStylesheet* theCompiledStylesheet,
162: const XSLTResultTarget& theResultTarget);
163:
1.2 parser 164: // PAF@design.ru
165: /**
166: * Transform will apply the compiled stylesheet to the parsed xml source
167: * and write the transformation output to the target.
168: *
169: * @param theParsedXML the parsed input source
170: * @param theCompiledStylesheet pointer to a compiled stylesheet
171: * @param theResultTarget output source
172: * @throws exceptions: XSLException, SAXException, XMLException, XalanDOMException
173: */
1.4 ! paf 174: void
1.3 parser 175: transform2(
176: const XalanParsedSource& theParsedXML,
177: const XalanCompiledStylesheet* theCompiledStylesheet,
1.4 ! paf 178: const XSLTResultTarget& theResultTarget);
! 179:
1.2 parser 180: void
181: transform2(
1.4 ! paf 182: XalanDocument& theDocument,
1.2 parser 183: const XalanCompiledStylesheet* theCompiledStylesheet,
184: const XSLTResultTarget& theResultTarget);
1.1 parser 185: /**
186: * Transform will apply the stylesheet source to the input source
187: * and write the transformation output to the target. The input
188: * source and result target can be a file name, a stream or a root
189: * node.
190: *
191: * @param theInputSource input source
192: * @param theStylesheetSource stylesheet source
193: * @param theResultTarget output source
194: * @return 0 for success
195: */
196: int
197: transform(
198: const XSLTInputSource& theInputSource,
199: const XSLTInputSource& theStylesheetSource,
200: const XSLTResultTarget& theResultTarget);
201:
202: /**
203: * Transform will apply the stylesheet provided as a PI in the
204: * XML of the input source and write the transformation output to
205: * the target. The input source and result target can be a file
206: * name, a stream or a root node.
207: *
208: * @param theInputSource input source
209: * @param theResultTarget output source tree
210: * @return 0 for success
211: */
212: int
213: transform(
214: const XSLTInputSource& theInputSource,
215: const XSLTResultTarget& theResultTarget);
216:
217: /**
218: * Transform will apply the stylesheet source to the input source
219: * and write the transformation result to a callback function
220: * in pre-allocated blocks. The input source can be a file name,
221: * a stream or a root node. Upon termination, Xalan releases any
222: * allocated memory. Data passed to the callback is not guaranteed to
223: * be null terminated.
224: *
225: * - See XalanTransformerOutputStream and XalanOutputHandlerType
226: * for more details.
227: *
228: * @param theInputSource input source
229: * @param theStylesheetSource stylesheet source
230: * @param theOutputHandle void pointer passed through to callback.
231: * @param theOutputHandler a user defined (callback) function.
232: * @param theFlushHandler (optional) a user defined (callback) function.
233: * @return 0 for success
234: */
235: int
236: transform(
237: const XSLTInputSource& theInputSource,
238: const XSLTInputSource& theStylesheetSource,
239: void* theOutputHandle,
240: XalanOutputHandlerType theOutputHandler,
241: XalanFlushHandlerType theFlushHandler = 0);
242:
243: /**
244: * Transform will apply the compiled stylesheet to the input source
245: * and write the transformation output to the target. The input
246: * source and result target can be a file name, a stream or a root
247: * node.
248: *
249: * @param theInputSource input source
250: * @param theCompiledStylesheet pointer to a compiled stylesheet
251: * @param theResultTarget output source
252: * @return 0 for success
253: */
254: int
255: transform(
256: const XSLTInputSource& theInputSource,
257: const XalanCompiledStylesheet* theCompiledStylesheet,
258: const XSLTResultTarget& theResultTarget);
259:
260: /**
261: * Transform will apply the compiled stylesheet to the source
262: * and write the transformation result to a callback function
263: * in pre-allocated blocks. The input source can be a file name,
264: * a stream or a root node. Upon termination, Xalan releases any
265: * allocated memory. Data passed to the callback is not guaranteed to
266: * be null terminated.
267: *
268: * - See XalanTransformerOutputStream and XalanOutputHandlerType
269: * for more details.
270: *
271: * @param theParsedSource Parsed source instance
272: * @param theCompiledStylesheet pointer to a compiled stylesheet
273: * @param theOutputHandle void pointer passed through to callback.
274: * @param theOutputHandler a user defined callback function.
275: * @param theFlushHandler An optional user-defined callback function.
276: * @return 0 for success
277: */
278: int
279: transform(
280: const XalanParsedSource& theParsedSource,
281: const XalanCompiledStylesheet* theCompiledStylesheet,
282: void* theOutputHandle,
283: XalanOutputHandlerType theOutputHandler,
284: XalanFlushHandlerType theFlushHandler = 0);
285:
286: /**
287: * Transform will apply the stylesheet provided as a PI in the
288: * XML of the input source and write the transformation result to a
289: * callback function in pre-allocated blocks. The input source can be
290: * a file name, a stream or a root node. Upon termination, Xalan
291: * releases any allocated memory. Data passed to the callback is not
292: * guaranteed to be null terminated.
293: *
294: * - See XalanTransformerOutputStream and XalanOutputHandlerType
295: * for more details.
296: *
297: * @param theInputSource input source
298: * @param theOutputHandle void pointer passed through to callback.
299: * @param theOutputHandler a user defined callback function.
300: * @param theFlushHandler an optional user-defined callback function.
301: * @return 0 for success
302: */
303: int
304: transform(
305: const XSLTInputSource& theInputSource,
306: void* theOutputHandle,
307: XalanOutputHandlerType theOutputHandler,
308: XalanFlushHandlerType theFlushHandler = 0);
309:
310: /**
311: * Creates a compeled stylesheet. The input source can be
1.2 parser 312: * a file name, a stream or a root node. The XalanTransformer2
1.1 parser 313: * instance owns the XalanCompiledStylesheet instance and will
1.2 parser 314: * delete it when the XalanTransformer2 instance goes out of scope,
1.1 parser 315: * or you explicitly call destroyStylesheet(). You must not delete
316: * the instance yourself.
317: *
318: * @param theStylesheetSource input source
319: * @param theCompiledStylesheet a reference to a pointer to a XalanCompileStylesheet.
320: * @return 0 for success
321: */
322: int
323: compileStylesheet(
324: const XSLTInputSource& theStylesheetSource,
325: const XalanCompiledStylesheet*& theCompiledStylesheet);
326:
327: /**
1.2 parser 328: * Creates a compeled stylesheet. The input source can be
329: * a file name, a stream or a root node. The XalanTransformer2
330: * instance owns the XalanCompiledStylesheet instance and will
331: * delete it when the XalanTransformer2 instance goes out of scope,
332: * or you explicitly call destroyStylesheet(). You must not delete
333: * the instance yourself.
334: *
335: * @param theStylesheetSource input source
336: * @param theCompiledStylesheet a reference to a pointer to a XalanCompileStylesheet.
337: * @throws exceptions: XSLException, SAXException, XMLException, XalanDOMException
338: */
339: void
340: compileStylesheet2(
341: const XSLTInputSource& theStylesheetSource,
342: const XalanCompiledStylesheet*& theCompiledStylesheet); // PAF@design.ru
343:
344: /**
1.1 parser 345: * Destroy a XalanCompiledStylesheet instance created by a previous
346: * call to compileStylesheet().
347: *
348: * @param theStylesheet The instance to destroy.
349: * @return 0 for success
350: */
351: int
352: destroyStylesheet(const XalanCompiledStylesheet* theStylesheet);
353:
354: /**
355: * Parse a source XML document. The input source can be
1.2 parser 356: * a file name, a stream or a root node. The XalanTransformer2
1.1 parser 357: * instance owns the XalanParsedSource instance and will
1.2 parser 358: * delete it when the XalanTransformer2 instance goes out of scope,
1.1 parser 359: * or you explicitly call destroyParsedSource(). You must not
360: * delete the instance yourself.
361: *
362: * @param theInputSource input source
363: * @param theParsedSource a reference to a pointer to a XalanParsedSource.
364: * @param useXercesDOM input use default or xerces dom source tree
365: * @return 0 for success
366: */
367: int
368: parseSource(
369: const XSLTInputSource& theInputSource,
370: const XalanParsedSource*& theParsedSource,
371: bool useXercesDOM = false);
372:
373: /**
374: * Destroy a parsed source created by a previous call to parseSource().
375: *
376: * @param theParsedSource The XalanParsedSource instance to destroy.
377: * @return 0 for success
378: */
379: int
380: destroyParsedSource(const XalanParsedSource* theParsedSource);
381:
382: /**
383: * Create a document builder. Using the document builder, you
1.2 parser 384: * can construct a document using SAX2 interfaces. The XalanTransformer2
1.1 parser 385: * instance owns the document builder and will delete it when the
1.2 parser 386: * XalanTransformer2 instance goes out of scope, or you explicitly call
1.1 parser 387: * deleteDocumentBuilder(). You must not delete the instance yourself.
388: *
389: * @return a pointer to a XalanDocumentBuilder instance or 0 for failure.
390: */
391: XalanDocumentBuilder*
392: createDocumentBuilder();
393:
394: /**
395: * Destroy a document builder created by a previous call to createDocumentBuilder().
396: * Passing a pointer that is not created by a call to createDocumentBuilder() can
397: * result in undefined behavior.
398: *
399: * @param theDocumentBuilder The document builder to destroy.
400: */
401: void
402: destroyDocumentBuilder(XalanDocumentBuilder* theDocumentBuilder);
403:
404: /**
405: * Install an external function in the local space.
406: *
407: * @param theNamespace The namespace for the functionl
408: * @param functionName The name of the function.
409: * @param function The function to install.
410: */
411: void
412: installExternalFunction(
413: const XalanDOMString& theNamespace,
414: const XalanDOMString& functionName,
415: const Function& function);
416:
417: /**
418: * Install an external function in the global space.
419: *
420: * @param theNamespace The namespace for the functionl
421: * @param functionName The name of the function.
422: * @param function The function to install.
423: */
424: static void
425: installExternalFunctionGlobal(
426: const XalanDOMString& theNamespace,
427: const XalanDOMString& functionName,
428: const Function& function);
429:
430: /**
431: * Uninstall an external local function.
432: *
433: * @param theNamespace The namespace for the function
434: * @param functionName The name of the function.
435: */
436: void
437: uninstallExternalFunction(
438: const XalanDOMString& theNamespace,
439: const XalanDOMString& functionName);
440:
441: /**
442: * Uninstall an external global function.
443: *
444: * @param theNamespace The namespace for the function
445: * @param functionName The name of the function.
446: */
447: static void
448: uninstallExternalFunctionGlobal(
449: const XalanDOMString& theNamespace,
450: const XalanDOMString& functionName);
451:
452: /**
453: * Set a top-level stylesheet parameter. This value can be evaluated via
454: * xsl:param-variable.
455: *
456: * @param key name of the param
457: * @param expression expression that will be evaluated
458: */
459: void
460: setStylesheetParam(
461: const XalanDOMString& key,
462: const XalanDOMString& expression);
463:
464: /**
465: * Returns the last error that occurred as a
466: * result of calling transform.
467: *
468: * @return error message const character pointer.
469: */
470: const char*
471: getLastError() const;
472:
473:
474: #if defined(XALAN_NO_NAMESPACES)
475: typedef vector<const XalanCompiledStylesheet*> CompiledStylesheetPtrVectorType;
476: typedef vector<const XalanParsedSource*> ParsedSourcePtrVectorType;
477: typedef pair<XalanDOMString, XalanDOMString> ParamPairType;
478: typedef vector<ParamPairType> ParamPairVectorType;
479: typedef pair<XalanQNameByValue, Function*> FunctionPairType;
480: typedef vector<FunctionPairType> FunctionParamPairVectorType;
481: #else
482: typedef std::vector<const XalanCompiledStylesheet*> CompiledStylesheetPtrVectorType;
483: typedef std::vector<const XalanParsedSource*> ParsedSourcePtrVectorType;
484: typedef std::pair<XalanDOMString, XalanDOMString> ParamPairType;
485: typedef std::vector<ParamPairType> ParamPairVectorType;
486: typedef std::pair<XalanQNameByValue, Function*> FunctionPairType;
487: typedef std::vector<FunctionPairType> FunctionParamPairVectorType;
488: #endif
489:
490: class EnsureDestroyParsedSource
491: {
492: public:
493:
494: EnsureDestroyParsedSource(
1.2 parser 495: XalanTransformer2& theTransformer,
1.1 parser 496: const XalanParsedSource* theParsedSource) :
497: m_transformer(theTransformer),
498: m_parsedSource(theParsedSource)
499: {
500: }
501:
502: ~EnsureDestroyParsedSource()
503: {
504: m_transformer.destroyParsedSource(m_parsedSource);
505: }
506:
507: private:
508:
1.2 parser 509: XalanTransformer2& m_transformer;
1.1 parser 510:
511: const XalanParsedSource* const m_parsedSource;
512: };
513:
514: struct EnsureDestroyCompiledStylesheet
515: {
516: EnsureDestroyCompiledStylesheet(
1.2 parser 517: XalanTransformer2& theTransformer,
1.1 parser 518: const XalanCompiledStylesheet* theCompiledStylesheet) :
519: m_transformer(theTransformer),
520: m_compiledStylesheet(theCompiledStylesheet)
521: {
522: }
523:
524: ~EnsureDestroyCompiledStylesheet()
525: {
526: m_transformer.destroyStylesheet(m_compiledStylesheet);
527: }
528:
529: private:
530:
1.2 parser 531: XalanTransformer2& m_transformer;
1.1 parser 532:
533: const XalanCompiledStylesheet* const m_compiledStylesheet;
534: };
535:
536: struct EnsureDestroyDocumentBuilder
537: {
538: EnsureDestroyDocumentBuilder(
1.2 parser 539: XalanTransformer2& theTransformer,
1.1 parser 540: XalanDocumentBuilder* theDocumentBuilder) :
541: m_transformer(theTransformer),
542: m_documentBuilder(theDocumentBuilder)
543: {
544: }
545:
546: ~EnsureDestroyDocumentBuilder()
547: {
548: m_transformer.destroyDocumentBuilder(m_documentBuilder);
549: }
550:
551: private:
552:
1.2 parser 553: XalanTransformer2& m_transformer;
1.1 parser 554:
555: XalanDocumentBuilder* const m_documentBuilder;
556: };
557:
558: protected:
559:
560: private:
561:
562: void
563: reset();
564:
565: class EnsureReset
566: {
567: public:
568:
1.2 parser 569: EnsureReset(XalanTransformer2& theTransformer) :
1.1 parser 570: m_transformer(theTransformer)
571: {
572: }
573:
574: ~EnsureReset();
575:
576: private:
577:
1.2 parser 578: XalanTransformer2& m_transformer;
1.1 parser 579: };
580:
581: friend class EnsureReset;
582:
583: CompiledStylesheetPtrVectorType m_compiledStylesheets;
584:
585: ParsedSourcePtrVectorType m_parsedSources;
586:
587: ParamPairVectorType m_paramPairs;
588:
589: FunctionParamPairVectorType m_functionPairs;
590:
591: CharVectorType m_errorMessage;
592:
593: StylesheetExecutionContextDefault* m_stylesheetExecutionContext;
594:
595: static XSLTInit* s_xsltInit;
596: };
597:
598: #endif // XALANTRANSFORMER_HEADER_GUARD
599:
600:
601:
E-mail: