[GME-commit]
GMESRC/GME/Parser MgaXslt.cpp,1.1,1.2 MgaXslt.h,1.1,1.2
gme-commit at list.isis.vanderbilt.edu
gme-commit at list.isis.vanderbilt.edu
Thu Apr 15 18:48:12 CDT 2004
Update of /var/lib/gme/GMESRC/GME/Parser
In directory braindrain:/tmp/cvs-serv6183
Modified Files:
MgaXslt.cpp MgaXslt.h
Log Message:
Beautifying and introducing MAGIC code for XalanTransformer.
Modified Files:
MgaXslt.cpp MgaXslt.h
CVS User: zolmol
Index: MgaXslt.cpp
===================================================================
RCS file: /var/lib/gme/GMESRC/GME/Parser/MgaXslt.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MgaXslt.cpp 8 Apr 2004 18:02:56 -0000 1.1
--- MgaXslt.cpp 15 Apr 2004 22:48:10 -0000 1.2
***************
*** 3,44 ****
#include "CommonStl.h"
- #if(1)
#include <xalanc/Include/PlatformDefinitions.hpp>
- //#include <cassert>
-
- #if defined(XALAN_CLASSIC_IOSTREAMS)
-
- #include "fstream.h"
- #include "iostream.h"
- #include "strstrea.h"
-
- #else
- #include "fstream"
- #include "iostream"
- #include "strstream"
-
- #endif
-
#include <xercesc/util/PlatformUtils.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
- #endif
-
-
- #define SIZE_OF_BUFFER 1024 //for storing filenames
! int CMgaXslt::transform(
! const char * stylesheet_file,
! const char * input_file,
! const char * output_file/*,
! string& error_msg*/)
{
- /*error_msg = "";*/
- #if(1)
- XALAN_USING_STD(cerr)
- XALAN_USING_STD(endl)
- XALAN_USING_STD(ostrstream)
- XALAN_USING_STD(ends)
-
XALAN_USING_XERCES(XMLPlatformUtils)
XALAN_USING_XERCES(XMLException)
--- 3,13 ----
#include "CommonStl.h"
#include <xalanc/Include/PlatformDefinitions.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
! STDMETHODIMP CMgaXslt::ApplyXslt( BSTR p_stylesheet_f_name, BSTR p_in_f_name, BSTR p_out_f_name, BSTR * out_error)
{
XALAN_USING_XERCES(XMLPlatformUtils)
XALAN_USING_XERCES(XMLException)
***************
*** 47,50 ****
--- 16,30 ----
XALAN_USING_XALAN(XalanCompiledStylesheet)
+ string style_sheet( 1 + GetCharLength( p_stylesheet_f_name), ' ');
+ string in_file( 1 + GetCharLength( p_in_f_name), ' ');
+ string out_file( 1 + GetCharLength( p_out_f_name), ' ');
+ string error;//( 1000, ' ');
+
+ char c[100]; // MAGIC needed, otherwise Transformer overwrites local vars ; by ZolMol
+
+ CopyTo( p_stylesheet_f_name, style_sheet);
+ CopyTo( p_in_f_name, in_file);
+ CopyTo( p_out_f_name, out_file);
+
int theResult = 0;
***************
*** 56,110 ****
catch (const XMLException& toCatch)
{
- //XmlStr xml_str( toCatch.getMessage());
- //error_msg = xml_str;
- //error_msg = toCatch.getMessage();
theResult = E_XSLT_XERCES_INIT;
}
! if ( theResult == 0)
{
! // Initialize Xalan.
! XalanTransformer::initialize();
!
! // Create a XalanTransformer.
! XalanTransformer theXalanTransformer;
!
! const char* theXSLFileName = stylesheet_file;
!
! // Compile the stylesheet.
! const XalanCompiledStylesheet* theCompiledStylesheet = 0;
!
! theResult = theXalanTransformer.compileStylesheet(theXSLFileName, theCompiledStylesheet);
!
! if (theResult == 0)
{
! assert(theCompiledStylesheet != 0);
!
! // Buffers passed in to ostrstream.
! char inBuffer[SIZE_OF_BUFFER];
! char outBuffer[SIZE_OF_BUFFER];
! // Generate the input and output file names.
! ostrstream theFormatterIn(inBuffer, sizeof(inBuffer));
! ostrstream theFormatterOut(outBuffer, sizeof(outBuffer));
! theFormatterIn << input_file << '\0';
! theFormatterOut << output_file << '\0';
! // Do the transform.
! theResult = theXalanTransformer.transform(
! inBuffer,
! theCompiledStylesheet,
! outBuffer);
! // I don't have to do this, since the transformer will
! // clean this up when it's destroyed, but why not...
! theResult = theXalanTransformer.destroyStylesheet(theCompiledStylesheet);
! }
! if ( theResult != 0)
! {
! /*error_msg = theXalanTransformer.getLastError();*/
! theResult = E_XSLT_TRANSF_ERROR;
}
}
--- 36,88 ----
catch (const XMLException& toCatch)
{
theResult = E_XSLT_XERCES_INIT;
}
! try
{
! if ( theResult == 0)
{
! // Initialize Xalan.
! XalanTransformer::initialize();
! // Create a XalanTransformer.
! XalanTransformer theXalanTransformer;
! // Compile the stylesheet.
! const XalanCompiledStylesheet* theCompiledStylesheet = 0;
! theResult = theXalanTransformer.compileStylesheet( style_sheet.c_str(), theCompiledStylesheet);
! if (theResult != 0)
! {
! theResult = E_XSLT_COMPILE_ERROR;
! error = theXalanTransformer.getLastError();
! }
! else
! {
! assert(theCompiledStylesheet != 0);
!
! // Do the transform.
! theResult = theXalanTransformer.transform
! ( in_file.c_str()
! , theCompiledStylesheet
! , out_file.c_str()
! );
!
! // I don't have to do this, since the transformer will
! // clean this up when it's destroyed, but why not...
! theResult = theXalanTransformer.destroyStylesheet(theCompiledStylesheet);
!
! if ( theResult != 0)
! {
! theResult = E_XSLT_TRANSF_ERROR;
! error = theXalanTransformer.getLastError();
! }
! }
}
+ }
+ catch( ...)
+ {
+ theResult = E_XSLT_ERROR;
}
***************
*** 118,149 ****
XalanTransformer::ICUCleanUp();
! return theResult;
! #endif
! }
!
!
!
! STDMETHODIMP CMgaXslt::ApplyXslt( BSTR p_stylesheet_f_name, BSTR p_in_f_name, BSTR p_out_f_name/*, BSTR * p_error_msg*/)
! {
! string style_sheet, in_file, out_file, error_msg;
!
! CopyTo( p_stylesheet_f_name, style_sheet);
! CopyTo( p_in_f_name, in_file);
! CopyTo( p_out_f_name, out_file);
!
! try
! {
! int res = transform( style_sheet.c_str(), in_file.c_str(), out_file.c_str()/*, error_msg*/);
! if ( res != 0)
! {
! //if ( !error_msg.empty()) CopyTo( error_msg.c_str(), error_msg.length(), p_error_msg);
! return res;
! }
! }
! catch( ...) //hresult_exception &e)
! {
! return E_XSLT_ERROR;
! }
! return S_OK;
}
--- 96,101 ----
XalanTransformer::ICUCleanUp();
! CopyTo( error, out_error);
! return (theResult == 0)? S_OK : theResult;
}
Index: MgaXslt.h
===================================================================
RCS file: /var/lib/gme/GMESRC/GME/Parser/MgaXslt.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MgaXslt.h 8 Apr 2004 18:02:56 -0000 1.1
--- MgaXslt.h 15 Apr 2004 22:48:10 -0000 1.2
***************
*** 14,18 ****
, public IDispatchImpl<IMgaXslt, &IID_IMgaXslt, &LIBID_PARSERLib>
, public IMgaVersionInfoImpl
- //, public IMgaXslt
{
public:
--- 14,17 ----
***************
*** 29,39 ****
// ------- Properties
! STDMETHOD(ApplyXslt)( BSTR in1, BSTR in2, BSTR in3/*, BSTR* msg*/);
// ------- Attributes and Methods
- protected:
- transform( const char * stylesheet, const char * in, const char * out/*, string& msg*/ );
- public:
};
--- 28,35 ----
// ------- Properties
! STDMETHOD(ApplyXslt)( BSTR in1, BSTR in2, BSTR in3, BSTR * error);
// ------- Attributes and Methods
};
More information about the GME-commit
mailing list