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