auriemma    01/03/30 13:35:20

  Modified:    c/src/XalanTransformer XalanCAPI.cpp XalanCAPI.h
                        XalanTransformer.cpp XalanTransformer.hpp
  Log:
  Added support for parsed xml source.
  
  Revision  Changes    Path
  1.12      +26 -0     xml-xalan/c/src/XalanTransformer/XalanCAPI.cpp
  
  Index: XalanCAPI.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanTransformer/XalanCAPI.cpp,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XalanCAPI.cpp     2001/03/29 23:06:25     1.11
  +++ XalanCAPI.cpp     2001/03/30 21:35:19     1.12
  @@ -296,6 +296,32 @@
   
   
   
  +XALAN_TRANSFORMER_EXPORT_FUNCTION(XalanPSHandle)
  +XalanParseSource(
  +                     const char*                             theXMLFileName,
  +                     XalanHandle                             theXalanHandle)
  +{
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +     return ((XalanTransformer*)theXalanHandle)->parseSource(theXMLFileName);
  +#else
  +     return  
static_cast<XalanTransformer*>(theXalanHandle)->parseSource(theXMLFileName);
  +#endif
  +}
  +
  +
  +
  +XALAN_TRANSFORMER_EXPORT_FUNCTION(XalanPSHandle)
  +XalanParseSourceUseXerceDOM(
  +                     const char*                             theXMLFileName,
  +                     XalanHandle                             theXalanHandle)
  +{
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +     return ((XalanTransformer*)theXalanHandle)->parseSource(theXMLFileName, 
1);
  +#else
  +     return  
static_cast<XalanTransformer*>(theXalanHandle)->parseSource(theXMLFileName, 1);
  +#endif
  +}
  +
   XALAN_TRANSFORMER_EXPORT_FUNCTION(void)
   XalanSetStylesheetParam(
                        const char*                             key,
  
  
  
  1.10      +25 -0     xml-xalan/c/src/XalanTransformer/XalanCAPI.h
  
  Index: XalanCAPI.h
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanTransformer/XalanCAPI.h,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XalanCAPI.h       2001/03/20 21:50:08     1.9
  +++ XalanCAPI.h       2001/03/30 21:35:19     1.10
  @@ -87,6 +87,11 @@
        typedef void* XalanCSSHandle;
   
        /**
  +      * Handle used to store the address of Parsed Source instance.
  +      */
  +     typedef void* XalanPSHandle;
  +
  +     /**
         * Callback function passed to XalanTransformToHandler. 
         * Used to process transformation output in blocks of data.
         * Caller is responsible for streaming or copying data to a user  
  @@ -305,6 +310,7 @@
         * a file name, a stream or a root node.
         *
         * @param theXSLFileName        filename of stylesheet source
  +      * @param theXalanHandle        handle of XalanTransformer instance.
         * @return      a CSSHandle or 0 for failure.
         */
        XALAN_TRANSFORMER_EXPORT_FUNCTION(XalanCSSHandle)
  @@ -313,11 +319,30 @@
                                XalanHandle                             
theXalanHandle);
   
        /**
  +      * Parse source document.  The input source can be 
  +      * a file name, a stream or a root node.
  +      *
  +      * @param theInputSource        input source    
  +      * @param theXalanHandle        handle of XalanTransformer instance.    
 
  +      * @return      a pointer to a XalanParsedSource or 0 for failure.
  +      */     
  +     XALAN_TRANSFORMER_EXPORT_FUNCTION(XalanPSHandle)
  +     XalanParseSource(
  +                     const char*                             theXMLFileName,
  +                     XalanHandle                             theXalanHandle);
  +
  +     XALAN_TRANSFORMER_EXPORT_FUNCTION(XalanPSHandle)
  +     XalanParseSourceUseXerceDOM(
  +                     const char*                             theXMLFileName,
  +                     XalanHandle                             theXalanHandle);
  +
  +     /**
         * Set a top-level stylesheet parameter.  This value can be evaluated 
via
         * xsl:param-variable.
         *
         * @param key name of the param
         * @param expression expression that will be evaluated
  +      * @param theXalanHandle        handle of XalanTransformer instance.
         */
        XALAN_TRANSFORMER_EXPORT_FUNCTION(void)
        XalanSetStylesheetParam(
  
  
  
  1.11      +237 -49   xml-xalan/c/src/XalanTransformer/XalanTransformer.cpp
  
  Index: XalanTransformer.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanTransformer/XalanTransformer.cpp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- XalanTransformer.cpp      2001/03/16 20:12:38     1.10
  +++ XalanTransformer.cpp      2001/03/30 21:35:19     1.11
  @@ -80,26 +80,11 @@
   
   
   XalanTransformer::XalanTransformer():
  -     m_domSupport(),
  -     m_parserLiaison(m_domSupport),
  -     m_xsltprocessorEnvSupport(),
  -     m_xobjectFactory(),
  -     m_xpathFactory(),
  -     m_processor(m_parserLiaison, 
  -                             m_xsltprocessorEnvSupport,
  -                             m_domSupport,
  -                             m_xobjectFactory,
  -                             m_xpathFactory),
  -     m_stylesheetExecutionContext(
  -                             m_processor,
  -                             m_xsltprocessorEnvSupport,
  -                             m_domSupport,
  -                             m_xobjectFactory),
  +     m_stylesheetExecutionContext(),
        m_compiledStylesheets(),
  +     m_parsedSources(),
        m_errorMessage()
   {
  -     m_domSupport.setParserLiaison(&m_parserLiaison);
  -     m_xsltprocessorEnvSupport.setProcessor(&m_processor);
        m_errorMessage.push_back(0);
   }
   
  @@ -115,6 +100,11 @@
        for_each(m_compiledStylesheets.begin(),
                         m_compiledStylesheets.end(),
                         DeleteFunctor<XalanCompiledStylesheet>());
  +
  +     // Clean up all entries in the compliledStylesheets vector.
  +     for_each(m_parsedSources.begin(),
  +                      m_parsedSources.end(),
  +                      DeleteFunctor<XalanParsedSource>());
   }
   
   
  @@ -139,7 +129,7 @@
   
   int
   XalanTransformer::transform(
  -     const XSLTInputSource&          theInputSource, 
  +     XalanParsedSource&                      theParsedXML, 
        const XSLTInputSource&          theStylesheetSource,
        const XSLTResultTarget&         theResultTarget)
   {
  @@ -153,32 +143,56 @@
        XalanDOMString  theErrorMessage;
   
        try
  -     {
  +     {               
  +             // Create some support objects that are necessary for running 
the processor...
  +             DOMSupport&                     theDOMSupport = 
*theParsedXML.getDOMSupport();
  +             XMLParserLiaison&       theParserLiaison = 
*theParsedXML.getParserLiaison();
  +
  +             // Create some more support objects...
  +             XSLTProcessorEnvSupportDefault  theXSLTProcessorEnvSupport;
  +             XObjectFactoryDefault                   theXObjectFactory;
  +             XPathFactoryDefault                             theXPathFactory;
  +
  +             // Create a processor...
  +             XSLTEngineImpl  theProcessor(
  +                             theParserLiaison,
  +                             theXSLTProcessorEnvSupport,
  +                             theDOMSupport,
  +                             theXObjectFactory,
  +                             theXPathFactory);
  +
                // Create a problem listener and send output to a 
XalanDOMString.
                DOMStringPrintWriter    thePrintWriter(theErrorMessage);
                
                ProblemListenerDefault  theProblemListener(&thePrintWriter);
   
  -             m_processor.setProblemListener(&theProblemListener);
  +             theProcessor.setProblemListener(&theProblemListener);
   
  -             
m_parserLiaison.setExecutionContext(m_stylesheetExecutionContext);
  +             
theParserLiaison.setExecutionContext(m_stylesheetExecutionContext);
   
                // Create a stylesheet construction context, using the
                // stylesheet's factory support objects.
                StylesheetConstructionContextDefault    
theStylesheetConstructionContext(
  -                                     m_processor,
  -                                     m_xsltprocessorEnvSupport,
  -                                     m_xpathFactory);
  -
  -             XSLTResultTarget        temp(theResultTarget);
  +                                     theProcessor,
  +                                     theXSLTProcessorEnvSupport,
  +                                     theXPathFactory);
  +
  +             XSLTResultTarget        tempResultTarget(theResultTarget);
  +
  +             
m_stylesheetExecutionContext.setXPathEnvSupport(&theXSLTProcessorEnvSupport);
  +             m_stylesheetExecutionContext.setDOMSupport(&theDOMSupport);
  +             
m_stylesheetExecutionContext.setXObjectFactory(&theXObjectFactory);
  +             m_stylesheetExecutionContext.setXSLTProcessor(&theProcessor);
   
                // Do the transformation...
  -             m_processor.process(
  -                                     theInputSource,
  +             theProcessor.process(
  +                                     theParsedXML.getParsedSource(),
                                        theStylesheetSource,
  -                                     temp,
  +                                     tempResultTarget,
                                        theStylesheetConstructionContext,
                                        m_stylesheetExecutionContext);
  +
  +             reset();
        }
        catch (XSLException& e)
        {
  @@ -238,8 +252,11 @@
                theResult = -4;
        }
   
  -     reset();
  -     
  +     m_stylesheetExecutionContext.setXPathEnvSupport(0);
  +     m_stylesheetExecutionContext.setDOMSupport(0);
  +     m_stylesheetExecutionContext.setXObjectFactory(0);
  +     m_stylesheetExecutionContext.setXSLTProcessor(0);
  +
        return theResult;
   }
   
  @@ -247,7 +264,7 @@
   
   int
   XalanTransformer::transform(
  -                     const XSLTInputSource&                  theInputSource, 
  +                     XalanParsedSource&                              
theParsedXML, 
                        const XalanCompiledStylesheet*  theCompiledStylesheet,
                        const XSLTResultTarget&                 theResultTarget)
   {
  @@ -262,22 +279,44 @@
   
        try
        {
  +             // Create some support objects that are necessary for running 
the processor...
  +             DOMSupport&                     theDOMSupport = 
*theParsedXML.getDOMSupport();
  +             XMLParserLiaison&       theParserLiaison = 
*theParsedXML.getParserLiaison();
  +
  +             // Create some more support objects...
  +             XSLTProcessorEnvSupportDefault  theXSLTProcessorEnvSupport;
  +             XObjectFactoryDefault                   theXObjectFactory;
  +             XPathFactoryDefault                             theXPathFactory;
  +
  +             // Create a processor...
  +             XSLTEngineImpl  theProcessor(
  +                             theParserLiaison,
  +                             theXSLTProcessorEnvSupport,
  +                             theDOMSupport,
  +                             theXObjectFactory,
  +                             theXPathFactory);
  +
                // Create a problem listener and send output to a 
XalanDOMString.
                DOMStringPrintWriter    thePrintWriter(theErrorMessage);
                
                ProblemListenerDefault  theProblemListener(&thePrintWriter);
   
  -             m_processor.setProblemListener(&theProblemListener);
  +             theProcessor.setProblemListener(&theProblemListener);
   
  +             XSLTResultTarget        tempResultTarget(theResultTarget);
  +
  +             
m_stylesheetExecutionContext.setXPathEnvSupport(&theXSLTProcessorEnvSupport);
  +             m_stylesheetExecutionContext.setDOMSupport(&theDOMSupport);
  +             
m_stylesheetExecutionContext.setXObjectFactory(&theXObjectFactory);
  +             m_stylesheetExecutionContext.setXSLTProcessor(&theProcessor);
  +
                // Set the compiled stylesheet.
                
theCompiledStylesheet->setStylesheetRoot(m_stylesheetExecutionContext);
   
  -             XSLTResultTarget        temp(theResultTarget);
  -
                // Do the transformation...
  -             m_processor.process(
  -                                     theInputSource,                         
  -                                     temp,                                   
  +             theProcessor.process(
  +                                     theParsedXML.getParsedSource(),         
  +                                     tempResultTarget,                       
                
                                        m_stylesheetExecutionContext);
        }
        catch (XSLException& e)
  @@ -338,6 +377,11 @@
                theResult = -4;
        }
   
  +     m_stylesheetExecutionContext.setXPathEnvSupport(0);
  +     m_stylesheetExecutionContext.setDOMSupport(0);
  +     m_stylesheetExecutionContext.setXObjectFactory(0);
  +     m_stylesheetExecutionContext.setXSLTProcessor(0);
  +
        reset();
        
        return theResult;
  @@ -347,6 +391,42 @@
   
   int
   XalanTransformer::transform(
  +     const XSLTInputSource&          theInputSource, 
  +     const XSLTInputSource&          theStylesheetSource,
  +     const XSLTResultTarget&         theResultTarget)
  +{
  +     // Parse the source document.
  +     XalanParsedSource* theParsedXML = parseSource(theInputSource);
  +
  +     // Do the transformation...
  +     return transform(
  +                                     *theParsedXML, 
  +                                     theStylesheetSource,
  +                                     theResultTarget);
  +}
  +
  +
  +
  +int
  +XalanTransformer::transform(
  +                     const XSLTInputSource&                  theInputSource, 
  +                     const XalanCompiledStylesheet*  theCompiledStylesheet,
  +                     const XSLTResultTarget&                 theResultTarget)
  +{
  +     // Parse the source document.
  +     XalanParsedSource* theParsedXML = parseSource(theInputSource);
  +
  +     // Do the transformation...
  +     return transform(
  +                                     *theParsedXML, 
  +                                     theCompiledStylesheet,
  +                                     theResultTarget);
  +}
  +
  +
  +
  +int
  +XalanTransformer::transform(
                        const XSLTInputSource&          theInputSource,         
        
                        const XSLTResultTarget&         theResultTarget)
   {
  @@ -436,12 +516,33 @@
   
        try
        {       
  +
  +             // Create some support objects that are necessary for running 
the processor...
  +             XalanSourceTreeDOMSupport               theDOMSupport;
  +             XalanSourceTreeParserLiaison    theParserLiaison(theDOMSupport);
  +
  +             // Hook the two together...
  +             theDOMSupport.setParserLiaison(&theParserLiaison);
  +
  +             // Create some more support objects...
  +             XSLTProcessorEnvSupportDefault  theXSLTProcessorEnvSupport;
  +             XObjectFactoryDefault                   theXObjectFactory;
  +             XPathFactoryDefault                             theXPathFactory;
  +
  +             // Create a processor...
  +             XSLTEngineImpl  theProcessor(
  +                             theParserLiaison,
  +                             theXSLTProcessorEnvSupport,
  +                             theDOMSupport,
  +                             theXObjectFactory,
  +                             theXPathFactory);
  +
                // Create a new XalanCompiledStylesheet.
                XalanCompiledStylesheet* const theCompiledStylesheet =
                        new XalanCompiledStylesheet(
                                                theStylesheetSource, 
  -                                             m_xsltprocessorEnvSupport,
  -                                             m_processor);
  +                                             theXSLTProcessorEnvSupport,
  +                                             theProcessor);
   
                // Store it in a vector.
                m_compiledStylesheets.push_back(theCompiledStylesheet);
  @@ -505,13 +606,100 @@
   
   
   
  +XalanParsedSource*
  +XalanTransformer::parseSource(
  +                     const XSLTInputSource&  theInputSource, 
  +                     bool                                    useXercesDOM)
  +{
  +     // Clear the error message.
  +     m_errorMessage.clear();
  +     m_errorMessage.push_back(0);
  +
  +     // Store error messages from problem listener.
  +     XalanDOMString  theErrorMessage;
  +
  +     try
  +     {       
  +             XalanParsedSource* theParsedDocument = 0;
  +
  +             if(useXercesDOM == 1)
  +             {
  +                     theParsedDocument = new 
XercesDOMParsedSource(theInputSource);
  +             }
  +             else
  +             {
  +                     theParsedDocument = new 
XalanDefaultParsedSource(theInputSource);
  +             }
  +
  +             // Store it in a vector.
  +             m_parsedSources.push_back(theParsedDocument);           
  +
  +             return theParsedDocument;
  +     }       
  +     catch (XSLException& e)
  +     {
  +             if (length(theErrorMessage) != 0)
  +             {
  +                     TranscodeToLocalCodePage(theErrorMessage, 
m_errorMessage, true);
  +             }
  +             else
  +             {
  +                     TranscodeToLocalCodePage(e.getMessage(), 
m_errorMessage, true);
  +             }
  +             
  +     }
  +     catch (SAXException& e)
  +     {
  +             if (length(theErrorMessage) != 0)
  +             {
  +                     TranscodeToLocalCodePage(theErrorMessage, 
m_errorMessage, true);
  +             }
  +             else
  +             {
  +                     TranscodeToLocalCodePage(e.getMessage(), 
m_errorMessage, true);
  +             }
  +             
  +     }
  +     catch (XMLException& e)
  +     {
  +             if (length(theErrorMessage) != 0)
  +             {
  +                     TranscodeToLocalCodePage(theErrorMessage, 
m_errorMessage, true);
  +             }
  +             else
  +             {
  +                     TranscodeToLocalCodePage(e.getMessage(), 
m_errorMessage, true);
  +             }
  +             
  +     }
  +     catch(const XalanDOMException&  e)
  +     {
  +             if (length(theErrorMessage) != 0)
  +             {
  +                     TranscodeToLocalCodePage(theErrorMessage, 
m_errorMessage, true);
  +             }
  +             else
  +             {
  +                     XalanDOMString theMessage("XalanDOMException caught.  
The code is ");
  +                     
  +                     append(theMessage,  
LongToDOMString(long(e.getExceptionCode())));
  +                     append(theMessage,  XalanDOMString("."));               
                                 
  +
  +                     TranscodeToLocalCodePage(theMessage, m_errorMessage, 
true);
  +             }
  +     }
  +     return 0;
  +}
  +
  +
  +
   void
   XalanTransformer::setStylesheetParam(
                        const XalanDOMString&   key,
                        const XalanDOMString&   expression)
   {
        // Set the stylesheet parameter.
  -     m_processor.setStylesheetParam(key,  expression);
  +//   m_processor.setStylesheetParam(key,  expression);
   }
   
   
  @@ -522,9 +710,9 @@
                        const char*                             expression)
   {
        // Set the stylesheet parameter.
  -     m_processor.setStylesheetParam(
  -                                     XalanDOMString(key),  
  -                                     XalanDOMString(expression));
  +//   m_processor.setStylesheetParam(
  +//                                   XalanDOMString(key),  
  +//                                   XalanDOMString(expression));
   }
   
   
  @@ -543,12 +731,12 @@
        try
        {
                // Reset objects.
  -             m_stylesheetExecutionContext.reset();
  -             
  -             m_parserLiaison.reset();
  +             m_stylesheetExecutionContext.setXPathEnvSupport(0);
  +             m_stylesheetExecutionContext.setDOMSupport(0);
  +             m_stylesheetExecutionContext.setXObjectFactory(0);
  +             m_stylesheetExecutionContext.setXSLTProcessor(0);
   
  -             // Clear the problem listener before it goes out of scope.
  -             m_processor.setProblemListener(0);
  +             m_stylesheetExecutionContext.reset();
        }
        catch(...)
        {
  
  
  
  1.14      +50 -12    xml-xalan/c/src/XalanTransformer/XalanTransformer.hpp
  
  Index: XalanTransformer.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanTransformer/XalanTransformer.hpp,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- XalanTransformer.hpp      2001/03/20 21:50:09     1.13
  +++ XalanTransformer.hpp      2001/03/30 21:35:19     1.14
  @@ -95,6 +95,9 @@
   
   
   #include <XalanTransformer/XalanCompiledStylesheet.hpp>
  +#include <XalanTransformer/XalanDefaultParsedSource.hpp>
  +#include <XalanTransformer/XalanParsedSource.hpp>
  +#include <XalanTransformer/XercesDOMParsedSource.hpp>
   #include <XalanTransformer/XalanTransformerOutputStream.hpp>
   
   
  @@ -145,6 +148,36 @@
        terminate();
   
        /**
  +      * Transform will apply the stylesheet source to the parsed xml source
  +      * and write the transformation output to the target. 
  +      *
  +      * @param theParsedXML                  the parsed input source
  +      * @param theStylesheetSource   stylesheet source
  +      * @param theResultTarget               output source
  +      * @return      0 for success
  +      */
  +     int
  +     transform(
  +                     XalanParsedSource&                      theParsedXML, 
  +                     const XSLTInputSource&          theStylesheetSource,
  +                     const XSLTResultTarget&         theResultTarget);
  +
  +     /**
  +      * Transform will apply the compiled stylesheet to the parsed xml source
  +      * and write the transformation output to the target. 
  +      *
  +      * @param theParsedXML                  the parsed input source
  +      * @param theCompiledStylesheet pointer to a compiled stylesheet
  +      * @param theResultTarget               output source 
  +      * @return      0 for success
  +      */
  +     int
  +     transform(
  +                     XalanParsedSource&                              
theParsedXML, 
  +                     const XalanCompiledStylesheet*  theCompiledStylesheet,
  +                     const XSLTResultTarget&                 
theResultTarget);
  +
  +     /**
         * Transform will apply the stylesheet source to the input source
         * and write the transformation output to the target. The input 
         * source and result target can be a file name, a stream or a root
  @@ -296,6 +329,19 @@
                        const char*                             expression);
   
        /**
  +      * Parse source document.  The input source can be 
  +      * a file name, a stream or a root node.
  +      *
  +      * @param theInputSource        input source
  +      * @param useXercesDOM          input use default or xerces dom source 
tree
  +      * @return      a pointer to a XalanParsedSource or 0 for failure.
  +      */
  +     XalanParsedSource*
  +     parseSource(
  +                     const XSLTInputSource&  theInputSource, 
  +                     bool  useXercesDOM = 0);
  +
  +     /**
         * Returns the last error that occurred as a 
         * result of calling transform. 
         *
  @@ -307,8 +353,10 @@
   
   #if defined(XALAN_NO_NAMESPACES)
        typedef vector<const XalanCompiledStylesheet*>          
CompiledStylesheetPtrVectorType;
  +     typedef vector<const ParsedDocument*>                           
ParsedSourcePtrVectorType;
   #else
        typedef std::vector<const XalanCompiledStylesheet*>     
CompiledStylesheetPtrVectorType;
  +     typedef std::vector<const XalanParsedSource*>           
ParsedSourcePtrVectorType;
   #endif
   
   protected:
  @@ -318,21 +366,11 @@
        void 
        reset();
   
  -     XalanSourceTreeDOMSupport                               m_domSupport;
  -
  -     XalanSourceTreeParserLiaison                    m_parserLiaison;
  -     
  -     XSLTProcessorEnvSupportDefault                  
m_xsltprocessorEnvSupport;
  -     
  -     XObjectFactoryDefault                                   
m_xobjectFactory;
  -     
  -     XPathFactoryDefault                                             
m_xpathFactory;
  -     
  -     XSLTEngineImpl                                                  
m_processor;
  -
        StylesheetExecutionContextDefault               
m_stylesheetExecutionContext;
   
        CompiledStylesheetPtrVectorType                 m_compiledStylesheets;
  +
  +     ParsedSourcePtrVectorType                               m_parsedSources;
   
        CharVectorType                                                  
m_errorMessage;
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to