mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
XML: complete merge from 1.4.2
This commit is contained in:
@@ -109,12 +109,13 @@ ParserEngine::ParserEngine():
|
||||
_parser(0),
|
||||
_pBuffer(0),
|
||||
_encodingSpecified(false),
|
||||
_expandInternalEntities(true),
|
||||
_externalGeneralEntities(false),
|
||||
_externalParameterEntities(false),
|
||||
_pNamespaceStrategy(new NoNamespacesStrategy()),
|
||||
_pEntityResolver(0),
|
||||
_pDTDHandler(0),
|
||||
_expandInternalEntities(true),
|
||||
_externalGeneralEntities(false),
|
||||
_externalParameterEntities(false),
|
||||
_enablePartialReads(false),
|
||||
_pNamespaceStrategy(new NoNamespacesStrategy()),
|
||||
_pEntityResolver(0),
|
||||
_pDTDHandler(0),
|
||||
_pDeclHandler(0),
|
||||
_pContentHandler(0),
|
||||
_pLexicalHandler(0),
|
||||
@@ -128,12 +129,13 @@ ParserEngine::ParserEngine(const XMLString& encoding):
|
||||
_pBuffer(0),
|
||||
_encodingSpecified(true),
|
||||
_encoding(encoding),
|
||||
_expandInternalEntities(true),
|
||||
_externalGeneralEntities(false),
|
||||
_externalParameterEntities(false),
|
||||
_pNamespaceStrategy(new NoNamespacesStrategy()),
|
||||
_pEntityResolver(0),
|
||||
_pDTDHandler(0),
|
||||
_expandInternalEntities(true),
|
||||
_externalGeneralEntities(false),
|
||||
_externalParameterEntities(false),
|
||||
_enablePartialReads(false),
|
||||
_pNamespaceStrategy(new NoNamespacesStrategy()),
|
||||
_pEntityResolver(0),
|
||||
_pDTDHandler(0),
|
||||
_pDeclHandler(0),
|
||||
_pContentHandler(0),
|
||||
_pLexicalHandler(0),
|
||||
@@ -232,9 +234,15 @@ void ParserEngine::setErrorHandler(ErrorHandler* pErrorHandler)
|
||||
}
|
||||
|
||||
|
||||
void ParserEngine::setEnablePartialReads(bool flag)
|
||||
{
|
||||
_enablePartialReads = flag;
|
||||
}
|
||||
|
||||
|
||||
void ParserEngine::parse(InputSource* pInputSource)
|
||||
{
|
||||
init();
|
||||
init();
|
||||
resetContext();
|
||||
pushContext(_parser, pInputSource);
|
||||
if (_pContentHandler) _pContentHandler->setDocumentLocator(this);
|
||||
@@ -266,41 +274,35 @@ void ParserEngine::parse(const char* pBuffer, std::size_t size)
|
||||
|
||||
void ParserEngine::parseByteInputStream(XMLByteInputStream& istr)
|
||||
{
|
||||
istr.read(_pBuffer, PARSE_BUFFER_SIZE);
|
||||
int n = static_cast<int>(istr.gcount());
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(_parser, _pBuffer, n, 0))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
if (istr.good())
|
||||
{
|
||||
istr.read(_pBuffer, PARSE_BUFFER_SIZE);
|
||||
n = static_cast<int>(istr.gcount());
|
||||
}
|
||||
else n = 0;
|
||||
}
|
||||
if (!XML_Parse(_parser, _pBuffer, 0, 1))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
std::streamsize n = readBytes(istr, _pBuffer, PARSE_BUFFER_SIZE);
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(_parser, _pBuffer, static_cast<int>(n), 0))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
if (istr.good())
|
||||
n = readBytes(istr, _pBuffer, PARSE_BUFFER_SIZE);
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
if (!XML_Parse(_parser, _pBuffer, 0, 1))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
}
|
||||
|
||||
|
||||
void ParserEngine::parseCharInputStream(XMLCharInputStream& istr)
|
||||
{
|
||||
istr.read(reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
int n = static_cast<int>(istr.gcount());
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(_parser, _pBuffer, n*sizeof(XMLChar), 0))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
if (istr.good())
|
||||
{
|
||||
istr.read(reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
n = static_cast<int>(istr.gcount());
|
||||
}
|
||||
else n = 0;
|
||||
}
|
||||
if (!XML_Parse(_parser, _pBuffer, 0, 1))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
std::streamsize n = readChars(istr, reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(_parser, _pBuffer, static_cast<int>(n*sizeof(XMLChar)), 0))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
if (istr.good())
|
||||
n = readChars(istr, reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
if (!XML_Parse(_parser, _pBuffer, 0, 1))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
}
|
||||
|
||||
|
||||
@@ -318,24 +320,21 @@ void ParserEngine::parseExternal(XML_Parser extParser, InputSource* pInputSource
|
||||
|
||||
void ParserEngine::parseExternalByteInputStream(XML_Parser extParser, XMLByteInputStream& istr)
|
||||
{
|
||||
char *pBuffer = new char[PARSE_BUFFER_SIZE];
|
||||
try
|
||||
{
|
||||
istr.read(pBuffer, PARSE_BUFFER_SIZE);
|
||||
int n = static_cast<int>(istr.gcount());
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(extParser, pBuffer, n, 0))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
if (istr.good())
|
||||
{
|
||||
istr.read(pBuffer, PARSE_BUFFER_SIZE);
|
||||
n = static_cast<int>(istr.gcount());
|
||||
}
|
||||
else n = 0;
|
||||
}
|
||||
if (!XML_Parse(extParser, pBuffer, 0, 1))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
char *pBuffer = new char[PARSE_BUFFER_SIZE];
|
||||
try
|
||||
{
|
||||
std::streamsize n = readBytes(istr, pBuffer, PARSE_BUFFER_SIZE);
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(extParser, pBuffer, static_cast<int>(n), 0))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
if (istr.good())
|
||||
n = readBytes(istr, pBuffer, PARSE_BUFFER_SIZE);
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
if (!XML_Parse(extParser, pBuffer, 0, 1))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -348,24 +347,21 @@ void ParserEngine::parseExternalByteInputStream(XML_Parser extParser, XMLByteInp
|
||||
|
||||
void ParserEngine::parseExternalCharInputStream(XML_Parser extParser, XMLCharInputStream& istr)
|
||||
{
|
||||
XMLChar *pBuffer = new XMLChar[PARSE_BUFFER_SIZE/sizeof(XMLChar)];
|
||||
try
|
||||
{
|
||||
istr.read(pBuffer, PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
int n = static_cast<int>(istr.gcount());
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(extParser, reinterpret_cast<char*>(pBuffer), n*sizeof(XMLChar), 0))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
if (istr.good())
|
||||
{
|
||||
istr.read(pBuffer, PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
n = static_cast<int>(istr.gcount());
|
||||
}
|
||||
else n = 0;
|
||||
}
|
||||
if (!XML_Parse(extParser, reinterpret_cast<char*>(pBuffer), 0, 1))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
XMLChar *pBuffer = new XMLChar[PARSE_BUFFER_SIZE/sizeof(XMLChar)];
|
||||
try
|
||||
{
|
||||
std::streamsize n = readChars(istr, pBuffer, PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(extParser, reinterpret_cast<char*>(pBuffer), static_cast<int>(n*sizeof(XMLChar)), 0))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
if (istr.good())
|
||||
n = readChars(istr, pBuffer, static_cast<int>(PARSE_BUFFER_SIZE/sizeof(XMLChar)));
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
if (!XML_Parse(extParser, reinterpret_cast<char*>(pBuffer), 0, 1))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -376,9 +372,49 @@ void ParserEngine::parseExternalCharInputStream(XML_Parser extParser, XMLCharInp
|
||||
}
|
||||
|
||||
|
||||
std::streamsize ParserEngine::readBytes(XMLByteInputStream& istr, char* pBuffer, std::streamsize bufferSize)
|
||||
{
|
||||
if (_enablePartialReads)
|
||||
{
|
||||
istr.read(pBuffer, 1);
|
||||
if (istr.gcount() == 1)
|
||||
{
|
||||
std::streamsize n = istr.readsome(pBuffer + 1, bufferSize - 1);
|
||||
return n + 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
istr.read(pBuffer, bufferSize);
|
||||
return istr.gcount();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::streamsize ParserEngine::readChars(XMLCharInputStream& istr, XMLChar* pBuffer, std::streamsize bufferSize)
|
||||
{
|
||||
if (_enablePartialReads)
|
||||
{
|
||||
istr.read(pBuffer, 1);
|
||||
if (istr.gcount() == 1)
|
||||
{
|
||||
std::streamsize n = istr.readsome(pBuffer + 1, bufferSize - 1);
|
||||
return n + 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
istr.read(pBuffer, bufferSize);
|
||||
return istr.gcount();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
XMLString ParserEngine::getPublicId() const
|
||||
{
|
||||
return locator().getPublicId();
|
||||
return locator().getPublicId();
|
||||
}
|
||||
|
||||
|
||||
@@ -400,12 +436,17 @@ int ParserEngine::getColumnNumber() const
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
static LocatorImpl nullLocator;
|
||||
}
|
||||
|
||||
|
||||
const Locator& ParserEngine::locator() const
|
||||
{
|
||||
static LocatorImpl nullLocator;
|
||||
if (_context.empty())
|
||||
return nullLocator;
|
||||
else
|
||||
if (_context.empty())
|
||||
return nullLocator;
|
||||
else
|
||||
return *_context.back();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user