You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by au...@apache.org on 2001/02/03 01:09:10 UTC
cvs commit: xml-xalan/c/src/XalanTransformer XalanTransformer.hpp XalanTransformer.cpp XalanCAPI.h XalanCAPI.cpp
auriemma 01/02/02 16:09:10
Modified: c/src/XalanTransformer XalanTransformer.hpp
XalanTransformer.cpp XalanCAPI.h XalanCAPI.cpp
Log:
Added better exception handling and error reporting.
Revision Changes Path
1.5 +19 -5 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XalanTransformer.hpp 2001/02/01 19:11:40 1.4
+++ XalanTransformer.hpp 2001/02/03 00:09:08 1.5
@@ -140,6 +140,15 @@
terminate();
/**
+ * Returns the last error that occured as a
+ * result of callaing transform.
+ *
+ * @return error message int const c string
+ */
+ const char*
+ getLastError() const;
+
+ /**
* Transform the source tree to the output in the given result tree target.
* The processor will process the input source, the stylesheet source,
* and transform to the output target. Call internally by all transform
@@ -186,7 +195,7 @@
transform(
const char* theXMLFileName,
const char* theXSLFileName,
- ostream* theOutStream);
+ ostream& theOutStream);
/**
* Transform the XML source tree to an output stream.
@@ -200,9 +209,9 @@
*/
int
transform(
- istream* theXMLInStream,
- istream* theXSLInStream,
- ostream* theOutStream);
+ istream& theXMLInStream,
+ istream& theXSLInStream,
+ ostream& theOutStream);
/**
* Transform the XML source tree to the address of a callback.
@@ -230,6 +239,9 @@
private:
+ void
+ reset();
+
XalanSourceTreeDOMSupport m_domSupport;
XalanSourceTreeParserLiaison m_parserLiaison;
@@ -245,8 +257,10 @@
StylesheetConstructionContextDefault m_stylesheetConstructionContext;
StylesheetExecutionContextDefault m_stylesheetExecutionContext;
+
+ CharVectorType m_errorMessage;
- static XSLTInit* m_xsltInit;
+ static XSLTInit* m_xsltInit;
};
1.4 +141 -24 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XalanTransformer.cpp 2001/01/31 18:56:28 1.3
+++ XalanTransformer.cpp 2001/02/03 00:09:08 1.4
@@ -58,11 +58,20 @@
+#include <sax/SAXException.hpp>
+
+
+
+#include <XalanDOM/XalanDOMException.hpp>
+
+
+
#include <XalanTransformer/XalanTransformer.hpp>
#include <PlatformSupport/XalanOutputStreamPrintWriter.hpp>
+#include <PlatformSupport/DOMStringPrintWriter.hpp>
@@ -89,10 +98,12 @@
m_processor,
m_xsltprocessorEnvSupport,
m_domSupport,
- m_xobjectFactory)
+ m_xobjectFactory),
+ m_errorMessage()
{
m_domSupport.setParserLiaison(&m_parserLiaison);
m_xsltprocessorEnvSupport.setProcessor(&m_processor);
+ m_errorMessage.push_back(0);
}
@@ -110,7 +121,7 @@
XMLPlatformUtils::Initialize();
// Initialize Xalan.
- XalanTransformer::m_xsltInit = new XSLTInit;
+ m_xsltInit = new XSLTInit;
}
@@ -119,7 +130,7 @@
XalanTransformer::terminate()
{
// Terminate Xalan and release memory.
- delete XalanTransformer::m_xsltInit;
+ delete m_xsltInit;
// Call the static terminator for Xerces.
XMLPlatformUtils::Terminate();
@@ -133,8 +144,26 @@
const XSLTInputSource& theStylesheetSource,
XSLTResultTarget& theResultTarget)
{
+ int theResult = 0;
+
+ // Clear the error message.
+ m_errorMessage.clear();
+ m_errorMessage.push_back(0);
+
+ // Store error messages from problem listener.
+ XalanDOMString theErrorMessage;
+
try
{
+ // Create a problem listener and send output to a XalanDOMString.
+ DOMStringPrintWriter thePrintWriter(theErrorMessage);
+
+ ProblemListenerDefault theProblemListener(&thePrintWriter);
+
+ m_processor.setProblemListener(&theProblemListener);
+
+ m_parserLiaison.setExecutionContext(m_stylesheetExecutionContext);
+
// Do the transformation...
m_processor.process(
theInputSource,
@@ -142,17 +171,68 @@
theResultTarget,
m_stylesheetConstructionContext,
m_stylesheetExecutionContext);
-
- // Reset objects.
- m_stylesheetExecutionContext.reset();
- m_parserLiaison.reset();
}
- catch(...)
+ catch (XSLException& e)
+ {
+ if (length(theErrorMessage) != 0)
+ {
+ TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
+ }
+ else
+ {
+ TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
+ }
+
+ theResult = -1;
+ }
+ catch (SAXException& e)
{
- return 1;
+ if (length(theErrorMessage) != 0)
+ {
+ TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
+ }
+ else
+ {
+ TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
+ }
+
+ theResult = -2;
+ }
+ catch (XMLException& e)
+ {
+ if (length(theErrorMessage) != 0)
+ {
+ TranscodeToLocalCodePage(theErrorMessage, m_errorMessage, true);
+ }
+ else
+ {
+ TranscodeToLocalCodePage(e.getMessage(), m_errorMessage, true);
+ }
+
+ theResult = -3;
}
+ 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;
+ theResult = -4;
+ }
+
+ reset();
+
+ return theResult;
}
@@ -164,9 +244,12 @@
const char* theOutFileName)
{
// Set input sources
- XSLTInputSource theInputSource(c_wstr(XalanDOMString(theXMLFileName)));
- XSLTInputSource theStylesheetSource(c_wstr(XalanDOMString(theXSLFileName)));
+ const XalanDOMString theDOMStringXMLFileName(theXMLFileName);
+ const XalanDOMString theDOMStringXSLFileName(theXSLFileName);
+ XSLTInputSource theInputSource(c_wstr(theDOMStringXMLFileName));
+ XSLTInputSource theStylesheetSource(c_wstr(theDOMStringXSLFileName));
+
// Set output target
const XalanDOMString theDomStringOutFileName(theOutFileName);
@@ -185,14 +268,17 @@
XalanTransformer::transform(
const char* theXMLFileName,
const char* theXSLFileName,
- ostream* theOutStream)
+ ostream& theOutStream)
{
// Set input sources
- XSLTInputSource theInputSource(c_wstr(XalanDOMString(theXMLFileName)));
- XSLTInputSource theStylesheetSource(c_wstr(XalanDOMString(theXSLFileName)));
+ const XalanDOMString theDOMStringXMLFileName(theXMLFileName);
+ const XalanDOMString theDOMStringXSLFileName(theXSLFileName);
+
+ XSLTInputSource theInputSource(c_wstr(theDOMStringXMLFileName));
+ XSLTInputSource theStylesheetSource(c_wstr(theDOMStringXSLFileName));
// Set output target
- XSLTResultTarget theResultTarget(theOutStream);
+ XSLTResultTarget theResultTarget(&theOutStream);
// Do the transformation...
return transform(
@@ -205,16 +291,16 @@
int
XalanTransformer::transform(
- istream* theXMLInStream,
- istream* theXSLInStream,
- ostream* theOutStream)
+ istream& theXMLInStream,
+ istream& theXSLInStream,
+ ostream& theOutStream)
{
// Set input sources
- XSLTInputSource theInputSource(theXMLInStream);
- XSLTInputSource theStylesheetSource(theXSLInStream);
+ XSLTInputSource theInputSource(&theXMLInStream);
+ XSLTInputSource theStylesheetSource(&theXSLInStream);
// Set output target
- XSLTResultTarget theResultTarget(theOutStream);
+ XSLTResultTarget theResultTarget(&theOutStream);
// Do the transformation...
return transform(
@@ -233,8 +319,11 @@
XalanOutputHandlerType theOutputHandler)
{
// Set input sources
- XSLTInputSource theInputSource(c_wstr(XalanDOMString(theXMLFileName)));
- XSLTInputSource theStylesheetSource(c_wstr(XalanDOMString(theXSLFileName)));
+ const XalanDOMString theDOMStringXMLFileName(theXMLFileName);
+ const XalanDOMString theDOMStringXSLFileName(theXSLFileName);
+
+ const XSLTInputSource theInputSource(c_wstr(theDOMStringXMLFileName));
+ const XSLTInputSource theStylesheetSource(c_wstr(theDOMStringXSLFileName));
// Set to output target to the callback
XalanTransformerOutputStream theOutputStream(theOutputHandle, theOutputHandler);
@@ -248,6 +337,34 @@
theResultTarget);
}
+
+const char*
+XalanTransformer::getLastError() const
+{
+ return &m_errorMessage[0];
+}
+
+
+
+void
+XalanTransformer::reset()
+{
+ try
+ {
+ // Reset objects.
+ m_stylesheetExecutionContext.reset();
+
+ m_parserLiaison.reset();
+
+ m_stylesheetConstructionContext.reset();
+
+ // Clear the problem listener before it goes out of scope.
+ m_processor.setProblemListener(0);
+ }
+ catch(...)
+ {
+ }
+}
1.5 +19 -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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XalanCAPI.h 2001/02/02 14:16:30 1.4
+++ XalanCAPI.h 2001/02/03 00:09:09 1.5
@@ -202,6 +202,25 @@
const void* theOutputHandle,
XalanOutputHandlerType theOutputHandler);
+ /**
+ * This is a typedef to workaround limitations with
+ * the XALAN_TRANSFORMER_EXPORT_FUNCTION macro.
+ */
+ typedef const char* XalanCCharPtr;
+
+ /**
+ * Returns the last error that occured as a
+ * result of callaing transform.
+ *
+ * The signiture for following function is really:
+ * const char*
+ * XalanGetLastError(XalanHandle theXalanHandle) const;
+ *
+ * @return error message int cons c string
+ */
+ XALAN_TRANSFORMER_EXPORT_FUNCTION(XalanCCharPtr)
+ XalanGetLastError(XalanHandle theXalanHandle);
+
#if defined(__cplusplus)
}
#endif
1.6 +14 -2 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XalanCAPI.cpp 2001/02/02 14:16:30 1.5
+++ XalanCAPI.cpp 2001/02/03 00:09:09 1.6
@@ -132,9 +132,9 @@
// Do the transformation...
#if defined(XALAN_OLD_STYLE_CASTS)
- status = ((XalanTransformer*)theXalanHandle)->transform(theXMLFileName, theXSLFileName, &theOutputStream);
+ status = ((XalanTransformer*)theXalanHandle)->transform(theXMLFileName, theXSLFileName, theOutputStream);
#else
- status = static_cast<XalanTransformer*>(theXalanHandle)->transform(theXMLFileName, theXSLFileName, &theOutputStream);
+ status = static_cast<XalanTransformer*>(theXalanHandle)->transform(theXMLFileName, theXSLFileName, theOutputStream);
#endif
// Null-terminate the data.
theOutputStream << '\0';
@@ -168,3 +168,15 @@
return static_cast<XalanTransformer*>(theXalanHandle)->transform(theXMLFileName, theXSLFileName, theOutputHandle, theOutputHandler);
#endif
}
+
+
+
+XALAN_TRANSFORMER_EXPORT_FUNCTION(XalanCCharPtr)
+XalanGetLastError(XalanHandle theXalanHandle)
+{
+#if defined(XALAN_OLD_STYLE_CASTS)
+ return ((XalanTransformer*)theXalanHandle)->getLastError();
+#else
+ return static_cast<XalanTransformer*>(theXalanHandle)->getLastError();
+#endif
+}
\ No newline at end of file