dbertoni 2003/12/07 20:53:40
Modified: c/samples/CompileStylesheet CompileStylesheet.cpp
Log:
Patch for Bugzilla 22248.
Revision Changes Path
1.27 +59 -44
xml-xalan/c/samples/CompileStylesheet/CompileStylesheet.cpp
Index: CompileStylesheet.cpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/samples/CompileStylesheet/CompileStylesheet.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- CompileStylesheet.cpp 20 Aug 2003 15:53:38 -0000 1.26
+++ CompileStylesheet.cpp 8 Dec 2003 04:53:40 -0000 1.27
@@ -78,7 +78,6 @@
#include <xercesc/util/PlatformUtils.hpp>
-
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
@@ -103,63 +102,79 @@
else
{
XALAN_USING_XERCES(XMLPlatformUtils)
+ XALAN_USING_XERCES(XMLException)
XALAN_USING_XALAN(XalanTransformer)
XALAN_USING_XALAN(XalanCompiledStylesheet)
// Call the static initializer for Xerces.
- XMLPlatformUtils::Initialize();
-
- // Initialize Xalan.
- XalanTransformer::initialize();
+ try
+ {
+ XMLPlatformUtils::Initialize();
+ }
+ catch (const XMLException& toCatch)
{
- // Create a XalanTransformer.
- XalanTransformer theXalanTransformer;
+ cerr << "Error during Xerces initialization! "<< endl;
+
+ theResult = -1;
+ }
- // Our input files...The assumption is that the
executable will be run
- // from same directory as the input files.
- const char* theXSLFileName = "foo.xsl";
+ if ( theResult == 0)
+ {
+
+ // Initialize Xalan.
+ XalanTransformer::initialize();
- // Compile the stylesheet.
- const XalanCompiledStylesheet* theCompiledStylesheet =
0;
-
- theResult =
theXalanTransformer.compileStylesheet(theXSLFileName, theCompiledStylesheet);
-
- if (theResult == 0)
{
- assert(theCompiledStylesheet != 0);
-
- for (unsigned int i = 0; i < 10; ++i)
- {
- // Buffers passed in to ostrstream.
- char inBuffer[10];
- char outBuffer[10];
-
- // Generate the input and output file
names.
- ostrstream
theFormatterIn(inBuffer, sizeof(inBuffer));
- ostrstream
theFormatterOut(outBuffer, sizeof(outBuffer));
-
- theFormatterIn << "foo" << i + 1 <<
".xml" << '\0';
- theFormatterOut << "foo" << i + 1 <<
".out" << '\0';
-
- // Do the transform.
- theResult =
theXalanTransformer.transform(
+ // Create a XalanTransformer.
+ XalanTransformer theXalanTransformer;
+
+ // Our input files...The assumption is that the
executable will be run
+ // from same directory as the input files.
+ const char* theXSLFileName =
"foo.xsl";
+
+ // Compile the stylesheet.
+ const XalanCompiledStylesheet*
theCompiledStylesheet = 0;
+
+ theResult =
theXalanTransformer.compileStylesheet(theXSLFileName, theCompiledStylesheet);
+
+ if (theResult == 0)
+ {
+ assert(theCompiledStylesheet != 0);
+
+ for (unsigned int i = 0; i < 10; ++i)
+ {
+ // Buffers passed in to
ostrstream.
+ char inBuffer[10];
+ char outBuffer[10];
+
+ // Generate the input and
output file names.
+ ostrstream
theFormatterIn(inBuffer, sizeof(inBuffer));
+ ostrstream
theFormatterOut(outBuffer, sizeof(outBuffer));
+
+ theFormatterIn << "foo" << i +
1 << ".xml" << '\0';
+ theFormatterOut << "foo" << i +
1 << ".out" << '\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);
}
-
- // 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)
- {
- cerr << "CompileStylesheet Error: " <<
theXalanTransformer.getLastError()
- << endl
- << endl;
+
+ if(theResult != 0)
+ {
+ cerr << "CompileStylesheet Error: " <<
theXalanTransformer.getLastError()
+ << endl
+ << endl;
+ }
+
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]