| 1 | // | 
|---|
| 2 | // SAXException.cpp | 
|---|
| 3 | // | 
|---|
| 4 | // Library: XML | 
|---|
| 5 | // Package: SAX | 
|---|
| 6 | // Module:  SAX | 
|---|
| 7 | // | 
|---|
| 8 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. | 
|---|
| 9 | // and Contributors. | 
|---|
| 10 | // | 
|---|
| 11 | // SPDX-License-Identifier:	BSL-1.0 | 
|---|
| 12 | // | 
|---|
| 13 |  | 
|---|
| 14 |  | 
|---|
| 15 | #include "Poco/SAX/SAXException.h" | 
|---|
| 16 | #include "Poco/SAX/Locator.h" | 
|---|
| 17 | #include <typeinfo> | 
|---|
| 18 | #include <sstream> | 
|---|
| 19 |  | 
|---|
| 20 |  | 
|---|
| 21 | namespace Poco { | 
|---|
| 22 | namespace XML { | 
|---|
| 23 |  | 
|---|
| 24 |  | 
|---|
| 25 | POCO_IMPLEMENT_EXCEPTION(SAXException, XMLException, "SAX Exception") | 
|---|
| 26 | POCO_IMPLEMENT_EXCEPTION(SAXNotRecognizedException, SAXException, "Unrecognized SAX feature or property identifier") | 
|---|
| 27 | POCO_IMPLEMENT_EXCEPTION(SAXNotSupportedException, SAXException, "Unsupported SAX feature or property identifier") | 
|---|
| 28 |  | 
|---|
| 29 |  | 
|---|
| 30 | SAXParseException::SAXParseException(const std::string& msg, const Locator& loc): | 
|---|
| 31 | SAXException(buildMessage(msg, loc.getPublicId(), loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber())), | 
|---|
| 32 | _publicId(loc.getPublicId()), | 
|---|
| 33 | _systemId(loc.getSystemId()), | 
|---|
| 34 | _lineNumber(loc.getLineNumber()), | 
|---|
| 35 | _columnNumber(loc.getColumnNumber()) | 
|---|
| 36 | { | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 |  | 
|---|
| 40 | SAXParseException::SAXParseException(const std::string& msg, const Locator& loc, const Poco::Exception& exc): | 
|---|
| 41 | SAXException(buildMessage(msg, loc.getPublicId(), loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber()), exc), | 
|---|
| 42 | _publicId(loc.getPublicId()), | 
|---|
| 43 | _systemId(loc.getSystemId()), | 
|---|
| 44 | _lineNumber(loc.getLineNumber()), | 
|---|
| 45 | _columnNumber(loc.getColumnNumber()) | 
|---|
| 46 | { | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 |  | 
|---|
| 50 | SAXParseException::SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber): | 
|---|
| 51 | SAXException(buildMessage(msg, publicId, systemId, lineNumber, columnNumber)), | 
|---|
| 52 | _publicId(publicId), | 
|---|
| 53 | _systemId(systemId), | 
|---|
| 54 | _lineNumber(lineNumber), | 
|---|
| 55 | _columnNumber(columnNumber) | 
|---|
| 56 | { | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 |  | 
|---|
| 60 | SAXParseException::SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber, const Poco::Exception& exc): | 
|---|
| 61 | SAXException(buildMessage(msg, publicId, systemId, lineNumber, columnNumber), exc), | 
|---|
| 62 | _publicId(publicId), | 
|---|
| 63 | _systemId(systemId), | 
|---|
| 64 | _lineNumber(lineNumber), | 
|---|
| 65 | _columnNumber(columnNumber) | 
|---|
| 66 | { | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 |  | 
|---|
| 70 | SAXParseException::SAXParseException(const SAXParseException& exc): | 
|---|
| 71 | SAXException(exc), | 
|---|
| 72 | _publicId(exc._publicId), | 
|---|
| 73 | _systemId(exc._systemId), | 
|---|
| 74 | _lineNumber(exc._lineNumber), | 
|---|
| 75 | _columnNumber(exc._columnNumber) | 
|---|
| 76 | { | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 |  | 
|---|
| 80 | SAXParseException::~SAXParseException() throw() | 
|---|
| 81 | { | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 |  | 
|---|
| 85 | SAXParseException& SAXParseException::operator = (const SAXParseException& exc) | 
|---|
| 86 | { | 
|---|
| 87 | if (&exc != this) | 
|---|
| 88 | { | 
|---|
| 89 | SAXException::operator = (exc); | 
|---|
| 90 | _publicId     = exc._publicId; | 
|---|
| 91 | _systemId     = exc._systemId; | 
|---|
| 92 | _lineNumber   = exc._lineNumber; | 
|---|
| 93 | _columnNumber = exc._columnNumber; | 
|---|
| 94 | } | 
|---|
| 95 | return *this; | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 |  | 
|---|
| 99 | const char* SAXParseException::name() const throw() | 
|---|
| 100 | { | 
|---|
| 101 | return "SAXParseException"; | 
|---|
| 102 | } | 
|---|
| 103 |  | 
|---|
| 104 |  | 
|---|
| 105 | const char* SAXParseException::className() const throw() | 
|---|
| 106 | { | 
|---|
| 107 | return typeid(*this).name(); | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 |  | 
|---|
| 111 | Poco::Exception* SAXParseException::clone() const | 
|---|
| 112 | { | 
|---|
| 113 | return new SAXParseException(*this); | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 |  | 
|---|
| 117 | void SAXParseException::rethrow() const | 
|---|
| 118 | { | 
|---|
| 119 | throw *this; | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 |  | 
|---|
| 123 | std::string SAXParseException::buildMessage(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber) | 
|---|
| 124 | { | 
|---|
| 125 | std::ostringstream result; | 
|---|
| 126 | if (!msg.empty()) result << msg << " "; | 
|---|
| 127 | result << "in "; | 
|---|
| 128 | if (!systemId.empty()) | 
|---|
| 129 | result << "'"<< fromXMLString(systemId) << "', "; | 
|---|
| 130 | else if (!publicId.empty()) | 
|---|
| 131 | result << "'"<< fromXMLString(publicId) << "', "; | 
|---|
| 132 | if (lineNumber > 0) | 
|---|
| 133 | result << "line "<< lineNumber << " column "<< columnNumber; | 
|---|
| 134 | return result.str(); | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 |  | 
|---|
| 138 | } } // namespace Poco::XML | 
|---|
| 139 |  | 
|---|