auriemma    01/04/20 06:48:10

  Modified:    c/src/XalanTransformer XalanTransformer.cpp
                        XalanTransformer.hpp
  Log:
  Added support for external functions.
  
  Revision  Changes    Path
  1.15      +77 -0     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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- XalanTransformer.cpp      2001/04/11 22:40:03     1.14
  +++ XalanTransformer.cpp      2001/04/20 13:48:09     1.15
  @@ -84,6 +84,7 @@
        m_compiledStylesheets(),
        m_parsedSources(),
       m_paramPairs(),
  +     m_functionPairs(),
        m_errorMessage()
   {
        m_errorMessage.push_back(0);
  @@ -106,6 +107,13 @@
        for_each(m_parsedSources.begin(),
                         m_parsedSources.end(),
                         DeleteFunctor<XalanParsedSource>());
  +
  +     for (FunctionParamPairVectorType::size_type i = 0; i < 
m_functionPairs.size(); ++i)
  +     {                       
  +             delete m_functionPairs[i].second;
  +             m_functionPairs.erase(m_functionPairs.begin() + i);             
        
  +     }       
  +
   }
   
   
  @@ -198,6 +206,7 @@
   
                m_stylesheetExecutionContext.setXSLTProcessor(&theProcessor);
   
  +             // Set the parameters if any.
                for (ParamPairVectorType::size_type i = 0; i < 
m_paramPairs.size(); ++i)
                {
                        theProcessor.setStylesheetParam(
  @@ -205,6 +214,15 @@
                                        m_paramPairs[i].second);
                }
   
  +             // Set the functions if any.
  +             for (FunctionParamPairVectorType::size_type f = 0; f < 
m_functionPairs.size(); ++f)
  +             {
  +                     theXSLTProcessorEnvSupport.installExternalFunctionLocal(
  +                                     m_functionPairs[f].first.getNamespace(),
  +                                     m_functionPairs[f].first.getLocalPart(),
  +                                     *(m_functionPairs[f].second));
  +             }
  +
                // Do the transformation...
                theProcessor.process(
                                        theParsedXML.getParsedSource(),
  @@ -350,6 +368,7 @@
                // Set the compiled stylesheet.
                
theCompiledStylesheet->setStylesheetRoot(m_stylesheetExecutionContext);
   
  +             // Set the parameters if any.
                for (ParamPairVectorType::size_type i = 0; i < 
m_paramPairs.size(); ++i)
                {
                        theProcessor.setStylesheetParam(
  @@ -357,6 +376,15 @@
                                        m_paramPairs[i].second);
                }
   
  +             // Set the functions if any.
  +             for (FunctionParamPairVectorType::size_type f = 0; f < 
m_functionPairs.size(); ++f)
  +             {
  +                     theXSLTProcessorEnvSupport.installExternalFunctionLocal(
  +                                     m_functionPairs[f].first.getNamespace(),
  +                                     m_functionPairs[f].first.getLocalPart(),
  +                                     *(m_functionPairs[f].second));
  +             }
  +
                // Do the transformation...
                theProcessor.process(
                                        theParsedXML.getParsedSource(),         
  @@ -772,6 +800,55 @@
        setStylesheetParam(
                                        XalanDOMString(key),  
                                        XalanDOMString(expression));
  +}
  +
  +
  +
  +void
  +XalanTransformer::installExternalFunction(
  +                     const XalanDOMString&   theNamespace,
  +                     const XalanDOMString&   functionName,
  +                     const Function&                 function)
  +{
  +     m_functionPairs.push_back(FunctionPairType(QNameByValue(theNamespace, 
functionName), function.clone()));
  +}
  +
  +
  +
  +void
  +XalanTransformer::installExternalFunction(
  +                     const char*                             theNamespace,
  +                     const char*                             functionName,
  +                     const Function&                 function)
  +{
  +     installExternalFunction(theNamespace, functionName, function);
  +}
  +
  +
  +
  +void
  +XalanTransformer::uninstallExternalFunction(
  +                     const XalanDOMString&   theNamespace,
  +                     const XalanDOMString&   functionName)
  +{
  +     for (FunctionParamPairVectorType::size_type i = 0; i < 
m_functionPairs.size(); ++i)
  +     {
  +             if(QNameByReference(theNamespace, 
functionName).equals(m_functionPairs[i].first))
  +             {       
  +                     delete m_functionPairs[i].second;
  +                     m_functionPairs.erase(m_functionPairs.begin() + i);     
        
  +             }
  +     }       
  +}
  +
  +
  +
  +void
  +XalanTransformer::uninstallExternalFunction(
  +                     const char*                             theNamespace,
  +                     const char*                             functionName)
  +{
  +     uninstallExternalFunction(theNamespace, functionName);
   }
   
   
  
  
  
  1.18      +55 -13    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- XalanTransformer.hpp      2001/04/11 22:40:04     1.17
  +++ XalanTransformer.hpp      2001/04/20 13:48:09     1.18
  @@ -72,6 +72,7 @@
   
   
   
  +#include <XPath/QNameByValue.hpp>
   #include <XPath/XObjectFactoryDefault.hpp>
   #include <XPath/XPathFactoryBlock.hpp>
   #include <XPath/XPathFactoryDefault.hpp>
  @@ -314,6 +315,54 @@
        compileStylesheet(const XSLTInputSource&                
theStylesheetSource);
   
        /**
  +      * 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);
  +
  +     /**
  +      * Install an external function in the local space.
  +      *
  +      * @param theNamespace The namespace for the functionl
  +      * @param functionName The name of the function.
  +      * @param function The function to install.
  +      */
  +     void
  +     installExternalFunction(
  +                     const XalanDOMString&   theNamespace,
  +                     const XalanDOMString&   functionName,
  +                     const Function&                 function);
  +
  +     void
  +     installExternalFunction(
  +                     const char*                             theNamespace,
  +                     const char*                             functionName,
  +                     const Function&                 function);
  +
  +     /**
  +      * Uninstall an external function from the local space.
  +      *
  +      * @param theNamespace The namespace for the function
  +      * @param functionName The name of the function.
  +      */
  +     void
  +     uninstallExternalFunction(
  +                     const XalanDOMString&   theNamespace,
  +                     const XalanDOMString&   functionName);
  +
  +     void
  +     uninstallExternalFunction(
  +                     const char*                             theNamespace,
  +                     const char*                             functionName);
  +
  +     /**
         * Set a top-level stylesheet parameter.  This value can be evaluated 
via
         * xsl:param-variable.
         *
  @@ -330,19 +379,6 @@
                        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. 
         *
  @@ -357,11 +393,15 @@
        typedef vector<XalanParsedSource*>                                      
ParsedSourcePtrVectorType;
        typedef pair<XalanDOMString, XalanDOMString>            ParamPairType;
        typedef vector<ParamPairType>                           
ParamPairVectorType;
  +     typedef pair<QNameByValue, Function*>                           
FunctionPairType;
  +     typedef vector<FunctionPairType>                            
FunctionParamPairVectorType;
   #else
        typedef std::vector<const XalanCompiledStylesheet*>     
CompiledStylesheetPtrVectorType;
        typedef std::vector<const XalanParsedSource*>           
ParsedSourcePtrVectorType;
        typedef std::pair<XalanDOMString, XalanDOMString>       ParamPairType;
        typedef std::vector<ParamPairType>                      
ParamPairVectorType;
  +     typedef std::pair<QNameByValue, Function*>              
FunctionPairType;
  +     typedef std::vector<FunctionPairType>                   
FunctionParamPairVectorType;
   #endif
   
   protected:
  @@ -378,6 +418,8 @@
        ParsedSourcePtrVectorType                               m_parsedSources;
   
       ParamPairVectorType                     m_paramPairs;
  +
  +     FunctionParamPairVectorType                             m_functionPairs;
   
        CharVectorType                                                  
m_errorMessage;
   
  
  
  

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

Reply via email to