Annotation of parser3/src/classes/xalan-patched/XalanTransformer2.hpp, revision 1.3
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.3 ! parser 10: $Id: XalanTransformer2.hpp,v 1.2 2001/10/09 14:25:15 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.3 ! parser 174: /* void
! 175: transform2(
! 176: const XalanParsedSource& theParsedXML,
! 177: const XalanCompiledStylesheet* theCompiledStylesheet,
! 178: const XSLTResultTarget& theResultTarget);*/
1.2 parser 179: void
180: transform2(
1.3 ! parser 181: XalanDocument *theDocument,
1.2 parser 182: const XalanCompiledStylesheet* theCompiledStylesheet,
183: const XSLTResultTarget& theResultTarget);
1.1 parser 184: /**
185: * Transform will apply the stylesheet source to the input source
186: * and write the transformation output to the target. The input
187: * source and result target can be a file name, a stream or a root
188: * node.
189: *
190: * @param theInputSource input source
191: * @param theStylesheetSource stylesheet source
192: * @param theResultTarget output source
193: * @return 0 for success
194: */
195: int
196: transform(
197: const XSLTInputSource& theInputSource,
198: const XSLTInputSource& theStylesheetSource,
199: const XSLTResultTarget& theResultTarget);
200:
201: /**
202: * Transform will apply the stylesheet provided as a PI in the
203: * XML of the input source and write the transformation output to
204: * the target. The input source and result target can be a file
205: * name, a stream or a root node.
206: *
207: * @param theInputSource input source
208: * @param theResultTarget output source tree
209: * @return 0 for success
210: */
211: int
212: transform(
213: const XSLTInputSource& theInputSource,
214: const XSLTResultTarget& theResultTarget);
215:
216: /**
217: * Transform will apply the stylesheet source to the input source
218: * and write the transformation result to a callback function
219: * in pre-allocated blocks. The input source can be a file name,
220: * a stream or a root node. Upon termination, Xalan releases any
221: * allocated memory. Data passed to the callback is not guaranteed to
222: * be null terminated.
223: *
224: * - See XalanTransformerOutputStream and XalanOutputHandlerType
225: * for more details.
226: *
227: * @param theInputSource input source
228: * @param theStylesheetSource stylesheet source
229: * @param theOutputHandle void pointer passed through to callback.
230: * @param theOutputHandler a user defined (callback) function.
231: * @param theFlushHandler (optional) a user defined (callback) function.
232: * @return 0 for success
233: */
234: int
235: transform(
236: const XSLTInputSource& theInputSource,
237: const XSLTInputSource& theStylesheetSource,
238: void* theOutputHandle,
239: XalanOutputHandlerType theOutputHandler,
240: XalanFlushHandlerType theFlushHandler = 0);
241:
242: /**
243: * Transform will apply the compiled stylesheet to the input source
244: * and write the transformation output to the target. The input
245: * source and result target can be a file name, a stream or a root
246: * node.
247: *
248: * @param theInputSource input source
249: * @param theCompiledStylesheet pointer to a compiled stylesheet
250: * @param theResultTarget output source
251: * @return 0 for success
252: */
253: int
254: transform(
255: const XSLTInputSource& theInputSource,
256: const XalanCompiledStylesheet* theCompiledStylesheet,
257: const XSLTResultTarget& theResultTarget);
258:
259: /**
260: * Transform will apply the compiled stylesheet to the source
261: * and write the transformation result to a callback function
262: * in pre-allocated blocks. The input source can be a file name,
263: * a stream or a root node. Upon termination, Xalan releases any
264: * allocated memory. Data passed to the callback is not guaranteed to
265: * be null terminated.
266: *
267: * - See XalanTransformerOutputStream and XalanOutputHandlerType
268: * for more details.
269: *
270: * @param theParsedSource Parsed source instance
271: * @param theCompiledStylesheet pointer to a compiled stylesheet
272: * @param theOutputHandle void pointer passed through to callback.
273: * @param theOutputHandler a user defined callback function.
274: * @param theFlushHandler An optional user-defined callback function.
275: * @return 0 for success
276: */
277: int
278: transform(
279: const XalanParsedSource& theParsedSource,
280: const XalanCompiledStylesheet* theCompiledStylesheet,
281: void* theOutputHandle,
282: XalanOutputHandlerType theOutputHandler,
283: XalanFlushHandlerType theFlushHandler = 0);
284:
285: /**
286: * Transform will apply the stylesheet provided as a PI in the
287: * XML of the input source and write the transformation result to a
288: * callback function in pre-allocated blocks. The input source can be
289: * a file name, a stream or a root node. Upon termination, Xalan
290: * releases any allocated memory. Data passed to the callback is not
291: * guaranteed to be null terminated.
292: *
293: * - See XalanTransformerOutputStream and XalanOutputHandlerType
294: * for more details.
295: *
296: * @param theInputSource input source
297: * @param theOutputHandle void pointer passed through to callback.
298: * @param theOutputHandler a user defined callback function.
299: * @param theFlushHandler an optional user-defined callback function.
300: * @return 0 for success
301: */
302: int
303: transform(
304: const XSLTInputSource& theInputSource,
305: void* theOutputHandle,
306: XalanOutputHandlerType theOutputHandler,
307: XalanFlushHandlerType theFlushHandler = 0);
308:
309: /**
310: * Creates a compeled stylesheet. The input source can be
1.2 parser 311: * a file name, a stream or a root node. The XalanTransformer2
1.1 parser 312: * instance owns the XalanCompiledStylesheet instance and will
1.2 parser 313: * delete it when the XalanTransformer2 instance goes out of scope,
1.1 parser 314: * or you explicitly call destroyStylesheet(). You must not delete
315: * the instance yourself.
316: *
317: * @param theStylesheetSource input source
318: * @param theCompiledStylesheet a reference to a pointer to a XalanCompileStylesheet.
319: * @return 0 for success
320: */
321: int
322: compileStylesheet(
323: const XSLTInputSource& theStylesheetSource,
324: const XalanCompiledStylesheet*& theCompiledStylesheet);
325:
326: /**
1.2 parser 327: * Creates a compeled stylesheet. The input source can be
328: * a file name, a stream or a root node. The XalanTransformer2
329: * instance owns the XalanCompiledStylesheet instance and will
330: * delete it when the XalanTransformer2 instance goes out of scope,
331: * or you explicitly call destroyStylesheet(). You must not delete
332: * the instance yourself.
333: *
334: * @param theStylesheetSource input source
335: * @param theCompiledStylesheet a reference to a pointer to a XalanCompileStylesheet.
336: * @throws exceptions: XSLException, SAXException, XMLException, XalanDOMException
337: */
338: void
339: compileStylesheet2(
340: const XSLTInputSource& theStylesheetSource,
341: const XalanCompiledStylesheet*& theCompiledStylesheet); // PAF@design.ru
342:
343: /**
1.1 parser 344: * Destroy a XalanCompiledStylesheet instance created by a previous
345: * call to compileStylesheet().
346: *
347: * @param theStylesheet The instance to destroy.
348: * @return 0 for success
349: */
350: int
351: destroyStylesheet(const XalanCompiledStylesheet* theStylesheet);
352:
353: /**
354: * Parse a source XML document. The input source can be
1.2 parser 355: * a file name, a stream or a root node. The XalanTransformer2
1.1 parser 356: * instance owns the XalanParsedSource instance and will
1.2 parser 357: * delete it when the XalanTransformer2 instance goes out of scope,
1.1 parser 358: * or you explicitly call destroyParsedSource(). You must not
359: * delete the instance yourself.
360: *
361: * @param theInputSource input source
362: * @param theParsedSource a reference to a pointer to a XalanParsedSource.
363: * @param useXercesDOM input use default or xerces dom source tree
364: * @return 0 for success
365: */
366: int
367: parseSource(
368: const XSLTInputSource& theInputSource,
369: const XalanParsedSource*& theParsedSource,
370: bool useXercesDOM = false);
371:
372: /**
373: * Destroy a parsed source created by a previous call to parseSource().
374: *
375: * @param theParsedSource The XalanParsedSource instance to destroy.
376: * @return 0 for success
377: */
378: int
379: destroyParsedSource(const XalanParsedSource* theParsedSource);
380:
381: /**
382: * Create a document builder. Using the document builder, you
1.2 parser 383: * can construct a document using SAX2 interfaces. The XalanTransformer2
1.1 parser 384: * instance owns the document builder and will delete it when the
1.2 parser 385: * XalanTransformer2 instance goes out of scope, or you explicitly call
1.1 parser 386: * deleteDocumentBuilder(). You must not delete the instance yourself.
387: *
388: * @return a pointer to a XalanDocumentBuilder instance or 0 for failure.
389: */
390: XalanDocumentBuilder*
391: createDocumentBuilder();
392:
393: /**
394: * Destroy a document builder created by a previous call to createDocumentBuilder().
395: * Passing a pointer that is not created by a call to createDocumentBuilder() can
396: * result in undefined behavior.
397: *
398: * @param theDocumentBuilder The document builder to destroy.
399: */
400: void
401: destroyDocumentBuilder(XalanDocumentBuilder* theDocumentBuilder);
402:
403: /**
404: * Install an external function in the local space.
405: *
406: * @param theNamespace The namespace for the functionl
407: * @param functionName The name of the function.
408: * @param function The function to install.
409: */
410: void
411: installExternalFunction(
412: const XalanDOMString& theNamespace,
413: const XalanDOMString& functionName,
414: const Function& function);
415:
416: /**
417: * Install an external function in the global space.
418: *
419: * @param theNamespace The namespace for the functionl
420: * @param functionName The name of the function.
421: * @param function The function to install.
422: */
423: static void
424: installExternalFunctionGlobal(
425: const XalanDOMString& theNamespace,
426: const XalanDOMString& functionName,
427: const Function& function);
428:
429: /**
430: * Uninstall an external local function.
431: *
432: * @param theNamespace The namespace for the function
433: * @param functionName The name of the function.
434: */
435: void
436: uninstallExternalFunction(
437: const XalanDOMString& theNamespace,
438: const XalanDOMString& functionName);
439:
440: /**
441: * Uninstall an external global function.
442: *
443: * @param theNamespace The namespace for the function
444: * @param functionName The name of the function.
445: */
446: static void
447: uninstallExternalFunctionGlobal(
448: const XalanDOMString& theNamespace,
449: const XalanDOMString& functionName);
450:
451: /**
452: * Set a top-level stylesheet parameter. This value can be evaluated via
453: * xsl:param-variable.
454: *
455: * @param key name of the param
456: * @param expression expression that will be evaluated
457: */
458: void
459: setStylesheetParam(
460: const XalanDOMString& key,
461: const XalanDOMString& expression);
462:
463: /**
464: * Returns the last error that occurred as a
465: * result of calling transform.
466: *
467: * @return error message const character pointer.
468: */
469: const char*
470: getLastError() const;
471:
472:
473: #if defined(XALAN_NO_NAMESPACES)
474: typedef vector<const XalanCompiledStylesheet*> CompiledStylesheetPtrVectorType;
475: typedef vector<const XalanParsedSource*> ParsedSourcePtrVectorType;
476: typedef pair<XalanDOMString, XalanDOMString> ParamPairType;
477: typedef vector<ParamPairType> ParamPairVectorType;
478: typedef pair<XalanQNameByValue, Function*> FunctionPairType;
479: typedef vector<FunctionPairType> FunctionParamPairVectorType;
480: #else
481: typedef std::vector<const XalanCompiledStylesheet*> CompiledStylesheetPtrVectorType;
482: typedef std::vector<const XalanParsedSource*> ParsedSourcePtrVectorType;
483: typedef std::pair<XalanDOMString, XalanDOMString> ParamPairType;
484: typedef std::vector<ParamPairType> ParamPairVectorType;
485: typedef std::pair<XalanQNameByValue, Function*> FunctionPairType;
486: typedef std::vector<FunctionPairType> FunctionParamPairVectorType;
487: #endif
488:
489: class EnsureDestroyParsedSource
490: {
491: public:
492:
493: EnsureDestroyParsedSource(
1.2 parser 494: XalanTransformer2& theTransformer,
1.1 parser 495: const XalanParsedSource* theParsedSource) :
496: m_transformer(theTransformer),
497: m_parsedSource(theParsedSource)
498: {
499: }
500:
501: ~EnsureDestroyParsedSource()
502: {
503: m_transformer.destroyParsedSource(m_parsedSource);
504: }
505:
506: private:
507:
1.2 parser 508: XalanTransformer2& m_transformer;
1.1 parser 509:
510: const XalanParsedSource* const m_parsedSource;
511: };
512:
513: struct EnsureDestroyCompiledStylesheet
514: {
515: EnsureDestroyCompiledStylesheet(
1.2 parser 516: XalanTransformer2& theTransformer,
1.1 parser 517: const XalanCompiledStylesheet* theCompiledStylesheet) :
518: m_transformer(theTransformer),
519: m_compiledStylesheet(theCompiledStylesheet)
520: {
521: }
522:
523: ~EnsureDestroyCompiledStylesheet()
524: {
525: m_transformer.destroyStylesheet(m_compiledStylesheet);
526: }
527:
528: private:
529:
1.2 parser 530: XalanTransformer2& m_transformer;
1.1 parser 531:
532: const XalanCompiledStylesheet* const m_compiledStylesheet;
533: };
534:
535: struct EnsureDestroyDocumentBuilder
536: {
537: EnsureDestroyDocumentBuilder(
1.2 parser 538: XalanTransformer2& theTransformer,
1.1 parser 539: XalanDocumentBuilder* theDocumentBuilder) :
540: m_transformer(theTransformer),
541: m_documentBuilder(theDocumentBuilder)
542: {
543: }
544:
545: ~EnsureDestroyDocumentBuilder()
546: {
547: m_transformer.destroyDocumentBuilder(m_documentBuilder);
548: }
549:
550: private:
551:
1.2 parser 552: XalanTransformer2& m_transformer;
1.1 parser 553:
554: XalanDocumentBuilder* const m_documentBuilder;
555: };
556:
557: protected:
558:
559: private:
560:
561: void
562: reset();
563:
564: class EnsureReset
565: {
566: public:
567:
1.2 parser 568: EnsureReset(XalanTransformer2& theTransformer) :
1.1 parser 569: m_transformer(theTransformer)
570: {
571: }
572:
573: ~EnsureReset();
574:
575: private:
576:
1.2 parser 577: XalanTransformer2& m_transformer;
1.1 parser 578: };
579:
580: friend class EnsureReset;
581:
582: CompiledStylesheetPtrVectorType m_compiledStylesheets;
583:
584: ParsedSourcePtrVectorType m_parsedSources;
585:
586: ParamPairVectorType m_paramPairs;
587:
588: FunctionParamPairVectorType m_functionPairs;
589:
590: CharVectorType m_errorMessage;
591:
592: StylesheetExecutionContextDefault* m_stylesheetExecutionContext;
593:
594: static XSLTInit* s_xsltInit;
595: };
596:
597: #endif // XALANTRANSFORMER_HEADER_GUARD
598:
599:
600:
E-mail: