Annotation of parser3/src/classes/xalan-patched/XalanTransformer2.hpp, revision 1.1

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

E-mail: