arabica/include/SAX/SAXParseException.hpp

171 lines
4.5 KiB
C++
Raw Normal View History

2003-09-12 16:09:13 +02:00
#ifndef ARABICA_SAXPARSEEXCEPTION_H
#define ARABICA_SAXPARSEEXCEPTION_H
2002-06-21 13:16:28 +02:00
// SAXParseException.h
// $Id$
2007-09-05 00:55:47 +02:00
#include <SAX/SAXException.hpp>
#include <SAX/Locator.hpp>
#include <Arabica/StringAdaptor.hpp>
2002-06-21 13:16:28 +02:00
2007-09-05 11:49:18 +02:00
namespace Arabica
{
2002-06-21 13:16:28 +02:00
namespace SAX
{
/**
* Encapsulate an XML parse error or warning.
*
* <p>This exception will include information for locating the error
* in the original XML document. Note that although the application
* will receive a SAXParseException as the argument to the handlers
* in the {@link ErrorHandler ErrorHandler} interface,
* the application is not actually required to throw the exception;
* instead, it can simply read the information in it and take a
* different action.</p>
*
* <p>Since this exception is a subclass of {@link SAXException
* SAXException}, it inherits the ability to wrap another exception.</p>
*
* @since SAX 1.0
* @author Jez Higgins,
* <a href="mailto:jez@jezuk.co.uk">jez@jezuk.co.uk</a>
* @version 2.0
* @see SAXException
* @see Locator
* @see ErrorHandler
2002-06-21 13:16:28 +02:00
*/
template<class string_type, class string_adaptor = Arabica::default_string_adaptor<string_type> >
class SAXParseException : public SAXException
2002-06-21 13:16:28 +02:00
{
public:
typedef Locator<string_type, string_adaptor> LocatorT;
2002-06-21 13:16:28 +02:00
SAXParseException(const std::string& message) :
SAXException(message),
publicId_(),
systemId_(),
lineNumber_(-1),
columnNumber_(-1)
{
setMsg();
} // SAXParseException
SAXParseException(const std::string& message,
2002-06-21 13:16:28 +02:00
const LocatorT& locator) :
SAXException(message),
publicId_(locator.getPublicId()),
systemId_(locator.getSystemId()),
lineNumber_(locator.getLineNumber()),
columnNumber_(locator.getColumnNumber())
{
setMsg();
} // SAXParseException
2002-06-21 13:16:28 +02:00
SAXParseException(const std::string& message,
const string_type& publicId,
const string_type& systemId,
2002-06-21 13:16:28 +02:00
int lineNumber,
int columnNumber) :
SAXException(message),
publicId_(publicId),
systemId_(systemId),
lineNumber_(lineNumber),
columnNumber_(columnNumber)
{
setMsg();
} // SAXParseException
2002-06-21 13:16:28 +02:00
SAXParseException(const SAXParseException& rhs) :
2002-06-21 13:16:28 +02:00
SAXException(rhs),
2004-02-24 12:22:19 +01:00
msg_(rhs.msg_),
2002-06-21 13:16:28 +02:00
publicId_(rhs.publicId_),
systemId_(rhs.systemId_),
lineNumber_(rhs.lineNumber_),
columnNumber_(rhs.columnNumber_)
{
} // SAXParseException
2002-06-21 13:16:28 +02:00
SAXParseException& operator=(const SAXParseException& rhs)
2002-06-21 13:16:28 +02:00
{
2004-02-24 12:22:19 +01:00
SAXException::operator=(rhs);
2002-06-21 13:16:28 +02:00
2004-02-24 12:22:19 +01:00
msg_ = rhs.msg_;
2002-06-21 13:16:28 +02:00
publicId_ = rhs.publicId_;
systemId_ = rhs.systemId_;
lineNumber_ = rhs.lineNumber_;
columnNumber_ = rhs.columnNumber_;
2004-02-24 12:22:19 +01:00
return *this;
2002-06-21 13:16:28 +02:00
} // operator=
virtual ~SAXParseException() throw() { }
2002-06-21 13:16:28 +02:00
/**
* Get the public identifier of the entity where the exception occurred.
*
* @return A string containing the public identifier, or an empty string
2002-06-21 13:16:28 +02:00
* if none is available.
* @see Locator#getPublicId
2002-06-21 13:16:28 +02:00
*/
const string_type& getPublicId() const { return publicId_; }
2002-06-21 13:16:28 +02:00
/**
* Get the system identifier of the entity where the exception occurred.
*
* <p>If the system identifier is a URL, it will be resolved
* fully.</p>
*
* @return A string containing the system identifier, or an empty string
2002-06-21 13:16:28 +02:00
* if none is available.
* @see Locator#getSystemId
2002-06-21 13:16:28 +02:00
*/
const string_type& getSystemId() const { return systemId_; }
2002-06-21 13:16:28 +02:00
/**
* The line number of the end of the text where the exception occurred.
*
* @return An integer representing the line number, or -1
* if none is available.
* @see Locator#getLineNumber
2002-06-21 13:16:28 +02:00
*/
int getLineNumber() const { return lineNumber_; }
/**
* The column number of the end of the text where the exception occurred.
*
* <p>The first column in a line is position 1.</p>
*
* @return An integer representing the column number, or -1
* if none is available.
* @see Locator#getColumnNumber
2002-06-21 13:16:28 +02:00
*/
int getColumnNumber() const { return columnNumber_; }
virtual const char* what() const throw()
{
2004-02-24 12:22:19 +01:00
return msg_.c_str();
2002-06-21 13:16:28 +02:00
} // what
private:
void setMsg()
{
std::ostringstream str;
str << "Parse exception at " << lineNumber_ << "," << columnNumber_ << std::endl;
str << SAXException::what();
2004-02-24 12:22:19 +01:00
msg_ = str.str();
2002-06-21 13:16:28 +02:00
} // setMsg
2004-02-24 12:22:19 +01:00
std::string msg_;
2002-06-21 13:16:28 +02:00
string_type publicId_;
string_type systemId_;
2002-06-21 13:16:28 +02:00
int lineNumber_;
int columnNumber_;
SAXParseException();
}; // class SAXParseException
2002-06-21 13:16:28 +02:00
2007-09-05 11:49:18 +02:00
} // namespace SAX
} // namespace Arabica
2002-06-21 13:16:28 +02:00
#endif
// end of file