dbertoni    01/05/21 20:52:23

  Modified:    c/src/XalanTransformer XalanTransformer.hpp
                        XalanTransformer.cpp
  Log:
  Fixed problem with not destroying parsed source.  Fixed some error handling 
problems.
  
  Revision  Changes    Path
  1.21      +69 -1     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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- XalanTransformer.hpp      2001/05/11 16:53:26     1.20
  +++ XalanTransformer.hpp      2001/05/22 03:52:21     1.21
  @@ -457,6 +457,74 @@
        typedef std::vector<FunctionPairType>                   
FunctionParamPairVectorType;
   #endif
   
  +     class EnsureDestroyParsedSource
  +     {
  +     public:
  +
  +             EnsureDestroyParsedSource(
  +                             XalanTransformer&       theTransformer,
  +                             XalanParsedSource*      theParsedSource) :
  +                     m_transformer(theTransformer),
  +                     m_parsedSource(theParsedSource)
  +             {
  +             }
  +
  +             ~EnsureDestroyParsedSource()
  +             {
  +                     m_transformer.destroyParsedSource(m_parsedSource);
  +             }
  +
  +     private:
  +
  +             XalanTransformer&                       m_transformer;
  +
  +             XalanParsedSource* const        m_parsedSource;
  +     };
  +
  +     struct EnsureDestroyCompiledStylesheet
  +     {
  +             EnsureDestroyCompiledStylesheet(
  +                             XalanTransformer&                       
theTransformer,
  +                             XalanCompiledStylesheet*        
theCompiledStylesheet) :
  +                     m_transformer(theTransformer),
  +                     m_compiledStylesheet(theCompiledStylesheet)
  +             {
  +             }
  +
  +             ~EnsureDestroyCompiledStylesheet()
  +             {
  +                     m_transformer.destroyStylesheet(m_compiledStylesheet);
  +             }
  +
  +     private:
  +
  +             XalanTransformer&                               m_transformer;
  +
  +             XalanCompiledStylesheet* const  m_compiledStylesheet;
  +     };
  +
  +     struct EnsureDestroyDocumentBuilder
  +     {
  +             EnsureDestroyDocumentBuilder(
  +                             XalanTransformer&               theTransformer,
  +                             XalanDocumentBuilder*   theDocumentBuilder) :
  +                     m_transformer(theTransformer),
  +                     m_documentBuilder(theDocumentBuilder)
  +             {
  +             }
  +
  +             ~EnsureDestroyDocumentBuilder()
  +             {
  +                     m_transformer.destroyDocumentBuilder(m_documentBuilder);
  +             }
  +
  +     private:
  +
  +             XalanTransformer&                       m_transformer;
  +
  +             XalanDocumentBuilder* const     m_documentBuilder;
  +     };
  +
   protected:
   
   private:
  @@ -494,7 +562,7 @@
   
        CharVectorType                                                  
m_errorMessage;
   
  -     static XSLTInit*                                                
m_xsltInit;
  +     static XSLTInit*                                                
s_xsltInit;
   };
   
   #endif       // XALANTRANSFORMER_HEADER_GUARD
  
  
  
  1.18      +43 -60    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- XalanTransformer.cpp      2001/05/11 16:53:23     1.17
  +++ XalanTransformer.cpp      2001/05/22 03:52:22     1.18
  @@ -103,7 +103,7 @@
   
   
   
  -XSLTInit*    XalanTransformer::m_xsltInit = 0;
  +XSLTInit*    XalanTransformer::s_xsltInit = 0;
   
   
   
  @@ -139,9 +139,9 @@
        for (FunctionParamPairVectorType::size_type i = 0; i < 
m_functionPairs.size(); ++i)
        {                       
                delete m_functionPairs[i].second;
  -             m_functionPairs.erase(m_functionPairs.begin() + i);             
        
  -     }       
  +     }
   
  +     m_functionPairs.clear();
   }
   
   
  @@ -150,7 +150,7 @@
   XalanTransformer::initialize()
   {
        // Initialize Xalan. 
  -     m_xsltInit = new XSLTInit;
  +     s_xsltInit = new XSLTInit;
   }
   
   
  @@ -159,7 +159,9 @@
   XalanTransformer::terminate()
   {
        // Terminate Xalan and release memory.
  -     delete m_xsltInit;
  +     delete s_xsltInit;
  +
  +     s_xsltInit = 0;
   }
   
   
  @@ -373,7 +375,9 @@
   
                theProcessor.setProblemListener(&theProblemListener);
   
  -             // Hack used to cast away const.
  +             // Since the result target is not const in our
  +             // internal intefaces, we'll pass in a local copy
  +             // of the one provided...
                XSLTResultTarget        tempResultTarget(theResultTarget);
   
                // Set up the stylesheet execution context.
  @@ -483,7 +487,12 @@
        const XSLTResultTarget&         theResultTarget)
   {
        // Parse the source document.
  -     XalanParsedSource* theParsedXML = parseSource(theInputSource);
  +     XalanParsedSource* const        theParsedXML =
  +             parseSource(theInputSource);
  +
  +     // Make sure the parsed source is destroyed when
  +     // the transformation is finished...
  +     EnsureDestroyParsedSource       theGuard(*this, theParsedXML);
   
        // Do the transformation...
        return transform(
  @@ -501,8 +510,13 @@
                        const XSLTResultTarget&                 theResultTarget)
   {
        // Parse the source document.
  -     XalanParsedSource* theParsedXML = parseSource(theInputSource);
  +     XalanParsedSource* const        theParsedXML =
  +             parseSource(theInputSource);
   
  +     // Make sure the parsed source is destroyed when
  +     // the transformation is finished...
  +     EnsureDestroyParsedSource       theGuard(*this, theParsedXML);
  +
        // Do the transformation...
        return transform(
                                        *theParsedXML, 
  @@ -528,11 +542,11 @@
   
   int
   XalanTransformer::transform(
  -                     const XSLTInputSource&                  theInputSource, 
  -                     const XSLTInputSource&                  
theStylesheetSource,
  -                     const void*                                             
theOutputHandle, 
  -                     XalanOutputHandlerType                  
theOutputHandler,
  -                     XalanFlushHandlerType                   theFlushHandler)
  +                     const XSLTInputSource&  theInputSource, 
  +                     const XSLTInputSource&  theStylesheetSource,
  +                     const void*                             
theOutputHandle, 
  +                     XalanOutputHandlerType  theOutputHandler,
  +                     XalanFlushHandlerType   theFlushHandler)
   {
        // Set to output target to the callback 
        XalanTransformerOutputStream    theOutputStream(theOutputHandle, 
theOutputHandler, theFlushHandler);
  @@ -609,8 +623,7 @@
        XalanDOMString  theErrorMessage;
   
        try
  -     {       
  -
  +     {
                // Create some support objects that are necessary for running 
the processor...
                XalanSourceTreeDOMSupport               theDOMSupport;
   
  @@ -634,6 +647,13 @@
                                theXObjectFactory,
                                theXPathFactory);
   
  +             // Create a problem listener and send output to a 
XalanDOMString.
  +             DOMStringPrintWriter    thePrintWriter(theErrorMessage);
  +             
  +             ProblemListenerDefault  theProblemListener(&thePrintWriter);
  +
  +             theProcessor.setProblemListener(&theProblemListener);
  +
                // Create a new XalanCompiledStylesheet.
                XalanCompiledStylesheet* const theCompiledStylesheet =
                        new XalanCompiledStylesheet(
  @@ -656,7 +676,6 @@
                {
                        TranscodeToLocalCodePage(e.getMessage(), 
m_errorMessage, true);
                }
  -             
        }
        catch (SAXException& e)
        {
  @@ -667,8 +686,7 @@
                else
                {
                        TranscodeToLocalCodePage(e.getMessage(), 
m_errorMessage, true);
  -             }
  -             
  +             }               
        }
        catch (XMLException& e)
        {
  @@ -680,7 +698,6 @@
                {
                        TranscodeToLocalCodePage(e.getMessage(), 
m_errorMessage, true);
                }
  -             
        }
        catch(const XalanDOMException&  e)
        {
  @@ -737,9 +754,6 @@
        m_errorMessage.clear();
        m_errorMessage.push_back(0);
   
  -     // Store error messages from problem listener.
  -     XalanDOMString  theErrorMessage;
  -
        try
        {       
                XalanParsedSource* theParsedDocument = 0;
  @@ -760,56 +774,25 @@
        }       
        catch (XSLException& e)
        {
  -             if (length(theErrorMessage) != 0)
  -             {
  -                     TranscodeToLocalCodePage(theErrorMessage, 
m_errorMessage, true);
  -             }
  -             else
  -             {
  -                     TranscodeToLocalCodePage(e.getMessage(), 
m_errorMessage, true);
  -             }
  -             
  +             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);
  -             }
  -             
  +             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);
  -             }
  -             
  +             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 ");
  +             XalanDOMString theMessage("XalanDOMException caught.  The code 
is ");
                        
  -                     append(theMessage,  
LongToDOMString(long(e.getExceptionCode())));
  +             append(theMessage,  
LongToDOMString(long(e.getExceptionCode())));
   
  -                     append(theMessage,  XalanDOMString("."));               
                                 
  +             append(theMessage,  XalanDOMString("."));                       
                         
   
  -                     TranscodeToLocalCodePage(theMessage, m_errorMessage, 
true);
  -             }
  +             TranscodeToLocalCodePage(theMessage, m_errorMessage, true);
        }
   
        return 0;
  
  
  

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

Reply via email to