dbertoni 01/07/11 21:35:58 Modified: c/src/XPath XPath.cpp XPath.hpp XPathException.cpp XPathException.hpp XPathParserException.cpp XPathParserException.hpp XPathProcessor.hpp XPathProcessorImpl.cpp XPathProcessorImpl.hpp Log: Implemented improved exception information. Revision Changes Path 1.58 +2 -1 xml-xalan/c/src/XPath/XPath.cpp Index: XPath.cpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/XPath/XPath.cpp,v retrieving revision 1.57 retrieving revision 1.58 diff -u -r1.57 -r1.58 --- XPath.cpp 2001/07/08 18:40:08 1.57 +++ XPath.cpp 2001/07/12 04:35:43 1.58 @@ -88,8 +88,9 @@ -XPath::XPath() : +XPath::XPath(const Locator* theLocator) : m_expression(), + m_locator(theLocator), m_inStylesheet(false) { } 1.27 +21 -10 xml-xalan/c/src/XPath/XPath.hpp Index: XPath.hpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/XPath/XPath.hpp,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- XPath.hpp 2001/07/08 18:40:07 1.26 +++ XPath.hpp 2001/07/12 04:35:44 1.27 @@ -83,21 +83,13 @@ +class Locator; class PrefixResolver; class XObject; class XalanNode; -/** - * The XPath class represents the semantic parse tree of the XPath pattern. It - * is the representation of the grammar which filters out the choice for - * replacement order of the production rules. In order to conserve memory and - * reduce object creation, the tree is represented as an array of integers: - * [op code][length][...] - * where strings are represented within the array as indices into the token - * tree. - */ class XALAN_XPATH_EXPORT XPath { public: @@ -131,9 +123,11 @@ /** * Construct an XPath. + * + * @param theLocator The applicable Locator, if any. */ explicit - XPath(); + XPath(const Locator* theLocator = 0); virtual ~XPath(); @@ -414,6 +408,18 @@ m_inStylesheet = fValue; } + const Locator* + getLocator() const + { + return m_locator; + } + + void + setLocator(const Locator* theLocator) + { + m_locator = theLocator; + } + protected: /** @@ -811,6 +817,11 @@ * */ XPathExpression m_expression; + + /** + * A Locator for reporting errors. + */ + const Locator* m_locator; /** * If true, the XPath can allocated XObjects in more 1.4 +33 -0 xml-xalan/c/src/XPath/XPathException.cpp Index: XPathException.cpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathException.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XPathException.cpp 2001/03/29 22:17:05 1.3 +++ XPathException.cpp 2001/07/12 04:35:46 1.4 @@ -59,12 +59,45 @@ +const XalanDOMString XPathException::s_emptyString; + + XPathException::XPathException( const XalanDOMString& message, + const XalanDOMString& theURI, + int theLineNumber, + int theColumnNumber, + const XalanDOMString& theType) : + XSLException(message, theURI, theLineNumber, theColumnNumber, theType), + m_styleNode(0) +{ +} + + + +XPathException::XPathException( + const XalanDOMString& message, const XalanNode* styleNode, const XalanDOMString& theType) : XSLException(message, theType), m_styleNode(styleNode) +{ +} + + + +XPathException::XPathException( + const XalanDOMString& message, + const XalanDOMString& theType) : + XSLException(message, theType), + m_styleNode(0) +{ +} + + + +XPathException::XPathException() : + XSLException(s_emptyString, s_emptyString) { } 1.6 +41 -4 xml-xalan/c/src/XPath/XPathException.hpp Index: XPathException.hpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathException.hpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- XPathException.hpp 2001/03/29 22:17:05 1.5 +++ XPathException.hpp 2001/07/12 04:35:46 1.6 @@ -86,12 +86,38 @@ * Construct an XPath exeption object. * * @param message message explaining the problem. - * @param styleNode style tree node where the problem occurred + * @param theURI the URI of the related document, if known + * @param theLineNumber the line number of the related document, or -1 if not known + * @param theColumnNumber the column number of the related document, or -1 if not known + * @param theType type of exception, default is "XPathException" */ - explicit + XPathException( + const XalanDOMString& message, + const XalanDOMString& theURI, + int theLineNumber, + int theColumnNumber, + const XalanDOMString& theType = XalanDOMString(XALAN_STATIC_UCODE_STRING("XPathException"))); + + /** + * Construct an XPath exeption object. + * + * @param message message explaining the problem. + * @param styleNode the node in the stylesheet where the problem occurred + * @param theType type of exception, default is "XPathException" + */ + XPathException( + const XalanDOMString& message, + const XalanNode* styleNode, + const XalanDOMString& theType = XalanDOMString(XALAN_STATIC_UCODE_STRING("XPathException"))); + + /** + * Construct an XPath exeption object. + * + * @param message message explaining the problem. + * @param theType type of exception, default is "XPathException" + */ XPathException( - const XalanDOMString& message = XalanDOMString(), - const XalanNode* styleNode = 0, + const XalanDOMString& message, const XalanDOMString& theType = XalanDOMString(XALAN_STATIC_UCODE_STRING("XPathException"))); virtual @@ -103,9 +129,20 @@ return m_styleNode; } +protected: + + /** + * Construct an XPath exeption object. + * + */ + explicit + XPathException(); + private: const XalanNode* m_styleNode; + + static const XalanDOMString s_emptyString; }; 1.3 +14 -3 xml-xalan/c/src/XPath/XPathParserException.cpp Index: XPathParserException.cpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathParserException.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- XPathParserException.cpp 2000/04/11 14:46:20 1.2 +++ XPathParserException.cpp 2001/07/12 04:35:47 1.3 @@ -62,9 +62,20 @@ XPathParserException::XPathParserException( const XalanDOMString& message, - const XalanNode* styleNode) : - XPathException(message, - styleNode) + const XalanDOMString& theURI, + int theLineNumber, + int theColumnNumber, + const XalanDOMString& theType) : + XPathException(message, theURI, theLineNumber, theColumnNumber, theType) +{ +} + + + +XPathParserException::XPathParserException( + const XalanDOMString& message, + const XalanDOMString& theType) : + XPathException(message, theType) { } 1.4 +21 -6 xml-xalan/c/src/XPath/XPathParserException.hpp Index: XPathParserException.hpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathParserException.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XPathParserException.hpp 2000/04/11 14:46:20 1.3 +++ XPathParserException.hpp 2001/07/12 04:35:47 1.4 @@ -76,15 +76,30 @@ public: /** - * Construct an XPathParserException object. + * Constructor * - * @param message string error message - * @param styleNode The style tree node where the problem occurred + * @param theMessage message to write when exception thrown + * @param theURI the URI of the related document, if known + * @param theLineNumber the line number of the related document, or -1 if not known + * @param theColumnNumber the column number of the related document, or -1 if not known + * @param theType type of exception, default is "XPathParserException" */ - explicit XPathParserException( - const XalanDOMString& message = XalanDOMString(), - const XalanNode* styleNode = 0); + const XalanDOMString& theMessage, + const XalanDOMString& theURI, + int theLineNumber, + int theColumnNumber, + const XalanDOMString& theType = XalanDOMString(XALAN_STATIC_UCODE_STRING("XPathParserException"))); + + /** + * Constructor + * + * @param theMessage message to write when exception thrown + * @param theType type of exception, default is "XPathParserException" + */ + XPathParserException( + const XalanDOMString& theMessage, + const XalanDOMString& theType = XalanDOMString(XALAN_STATIC_UCODE_STRING("XPathParserException"))); virtual ~XPathParserException(); 1.7 +7 -3 xml-xalan/c/src/XPath/XPathProcessor.hpp Index: XPathProcessor.hpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathProcessor.hpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- XPathProcessor.hpp 2001/06/14 19:12:19 1.6 +++ XPathProcessor.hpp 2001/07/12 04:35:48 1.7 @@ -70,6 +70,7 @@ class Function; +class Locator; class PrefixResolver; class XPath; @@ -93,13 +94,14 @@ * @param expression expression that will be evaluated * @param resolver prefix resolver to use * @param xobjectFactory factory class instance for XObjects - * @param envSupport XPath environment support class instance + * @param locator the Locator to use for error report. May be null */ virtual void initXPath( XPath& pathObj, const XalanDOMString& expression, - const PrefixResolver& resolver) = 0; + const PrefixResolver& resolver, + const Locator* locator = 0) = 0; /** * Given a string, create an XSLT Match Pattern object. @@ -107,12 +109,14 @@ * @param pathObj XPath object to be initialized * @param expression expression that will be evaluated * @param resolver prefix resolver to use + * @param locator the Locator to use for error report. May be null */ virtual void initMatchPattern( XPath& pathObj, const XalanDOMString& expression, - const PrefixResolver& resolver) = 0; + const PrefixResolver& resolver, + const Locator* locator = 0) = 0; /** * Given a string, and a reference to a function object, install the 1.44 +68 -6 xml-xalan/c/src/XPath/XPathProcessorImpl.cpp Index: XPathProcessorImpl.cpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathProcessorImpl.cpp,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- XPathProcessorImpl.cpp 2001/07/08 18:23:04 1.43 +++ XPathProcessorImpl.cpp 2001/07/12 04:35:49 1.44 @@ -62,6 +62,10 @@ +#include <sax/Locator.hpp> + + + #include <PlatformSupport/DOMStringHelper.hpp> #include <PlatformSupport/DOMStringPrintWriter.hpp> #include <PlatformSupport/DoubleSupport.hpp> @@ -100,9 +104,10 @@ void XPathProcessorImpl::initXPath( - XPath& pathObj, - const XalanDOMString& expression, - const PrefixResolver& prefixResolver) + XPath& pathObj, + const XalanDOMString& expression, + const PrefixResolver& prefixResolver, + const Locator* locator) { m_requireLiterals = false; @@ -112,6 +117,10 @@ m_prefixResolver = &prefixResolver; + m_locator = locator; + + m_expression->reset(); + tokenize(expression); m_expression->appendOpCode(XPathExpression::eOP_XPATH); @@ -128,6 +137,7 @@ m_xpath = 0; m_expression = 0; m_prefixResolver = 0; + m_locator = 0; } @@ -136,7 +146,8 @@ XPathProcessorImpl::initMatchPattern( XPath& pathObj, const XalanDOMString& expression, - const PrefixResolver& prefixResolver) + const PrefixResolver& prefixResolver, + const Locator* locator) { m_xpath = &pathObj; @@ -144,6 +155,8 @@ m_prefixResolver = &prefixResolver; + m_locator = locator; + m_expression->reset(); tokenize(expression); @@ -167,6 +180,7 @@ m_xpath = 0; m_expression = 0; m_prefixResolver = 0; + m_locator = 0; } @@ -916,7 +930,34 @@ { thePrintWriter.print(XALAN_STATIC_UCODE_STRING("pattern = '")); thePrintWriter.print(theCurrentPattern); - thePrintWriter.println("'"); + + thePrintWriter.print("'"); + + if (m_locator != 0) + { + const XalanDOMChar* const theSystemID = + m_locator->getSystemId(); + + thePrintWriter.print("("); + + if (theSystemID == 0) + { + thePrintWriter.print("Unknown URI"); + } + else + { + thePrintWriter.print(theSystemID); + } + + thePrintWriter.print(", "); + thePrintWriter.print(m_locator->getLineNumber()); + thePrintWriter.print(", "); + thePrintWriter.print(m_locator->getColumnNumber()); + + thePrintWriter.print(")"); + } + + thePrintWriter.println(); } // Back up one token, since we've consumed one... @@ -925,8 +966,29 @@ // Ask the expression to dump the remaining tokens... m_expression->dumpRemainingTokenQueue(thePrintWriter); } + + if (m_locator != 0) + { + const XalanDOMChar* const theSystemID = + m_locator->getSystemId(); - throw XPathParserException(emsg); + XalanDOMString theURI; + + if (theSystemID != 0) + { + theURI = theSystemID; + } + + throw XPathParserException( + emsg, + theURI, + m_locator->getLineNumber(), + m_locator->getColumnNumber()); + } + else + { + throw XPathParserException(emsg); + } } 1.17 +6 -2 xml-xalan/c/src/XPath/XPathProcessorImpl.hpp Index: XPathProcessorImpl.hpp =================================================================== RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathProcessorImpl.hpp,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- XPathProcessorImpl.hpp 2001/07/08 18:23:04 1.16 +++ XPathProcessorImpl.hpp 2001/07/12 04:35:50 1.17 @@ -147,13 +147,15 @@ initXPath( XPath& pathObj, const XalanDOMString& expression, - const PrefixResolver& prefixResolver); + const PrefixResolver& prefixResolver, + const Locator* locator = 0); virtual void initMatchPattern( XPath& pathObj, const XalanDOMString& expression, - const PrefixResolver& prefixResolver); + const PrefixResolver& prefixResolver, + const Locator* locator = 0); private: @@ -796,6 +798,8 @@ const PrefixResolver* m_prefixResolver; bool m_requireLiterals; + + const Locator* m_locator; enum eDummy { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]