xmlfix3: unoxml: CDocumentBuilder cleanup

This commit is contained in:
Michael Stahl 2011-01-19 20:27:28 +01:00
parent 75b70f1477
commit 76eac88260

View file

@ -34,6 +34,7 @@
#include <libxml/xmlerror.h>
#include <libxml/tree.h>
#include <boost/shared_ptr.hpp>
#include <rtl/alloc.h>
#include <rtl/memory.h>
@ -62,21 +63,6 @@ using ::com::sun::star::task::XInteractionHandler;
namespace DOM
{
extern "C" {
//char *strdup(const char *s);
/*
static char* strdupfunc(const char* s)
{
sal_Int32 len = 0;
while (s[len] != '\0') len++;
char *newStr = (char*)rtl_allocateMemory(len+1);
if (newStr != NULL)
rtl_copyMemory(newStr, s, len+1);
return newStr;
}
*/
}
class CDefaultEntityResolver : public cppu::WeakImplHelper1< XEntityResolver >
{
@ -118,7 +104,6 @@ namespace DOM
Reference< XInterface > CDocumentBuilder::_getInstance(const Reference< XMultiServiceFactory >& rSMgr)
{
// XXX
return static_cast< XDocumentBuilder* >(new CDocumentBuilder(rSMgr));
}
@ -324,7 +309,6 @@ namespace DOM
void throwEx(xmlParserCtxtPtr ctxt) {
OUString msg = make_error_message(ctxt);
xmlFreeParserCtxt(ctxt);
com::sun::star::xml::sax::SAXParseException saxex;
saxex.Message = msg;
saxex.LineNumber = static_cast<sal_Int32>(ctxt->lastError.line);
@ -343,14 +327,15 @@ namespace DOM
xmlCharEncoding enc = xmlParseCharEncoding(encstr);
*/
xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
::boost::shared_ptr<xmlParserCtxt> const pContext(
xmlNewParserCtxt(), xmlFreeParserCtxt);
// register error functions to prevent errors being printed
// on the console
ctxt->_private = this;
ctxt->sax->error = error_func;
ctxt->sax->warning = warning_func;
ctxt->sax->resolveEntity = resolve_func;
pContext->_private = this;
pContext->sax->error = error_func;
pContext->sax->warning = warning_func;
pContext->sax->resolveEntity = resolve_func;
// IO context struct
context_t c;
@ -359,13 +344,12 @@ namespace DOM
// we did not open the stream, thus we do not close it.
c.close = false;
c.freeOnClose = false;
xmlDocPtr pDoc = xmlCtxtReadIO(ctxt, xmlIO_read_func, xmlIO_close_func, &c,
0, 0, 0);
xmlDocPtr const pDoc = xmlCtxtReadIO(pContext.get(),
xmlIO_read_func, xmlIO_close_func, &c, 0, 0, 0);
if (pDoc == 0) {
throwEx(ctxt);
throwEx(pContext.get());
}
xmlFreeParserCtxt(ctxt);
Reference< XDocument > const xRet(
CDocument::CreateCDocument(pDoc).get());
return xRet;
@ -385,15 +369,17 @@ namespace DOM
}
// set up parser context
xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
::boost::shared_ptr<xmlParserCtxt> const pContext(
xmlNewParserCtxt(), xmlFreeParserCtxt);
// register error functions to prevent errors being printed
// on the console
ctxt->_private = this;
ctxt->sax->error = error_func;
ctxt->sax->warning = warning_func;
pContext->_private = this;
pContext->sax->error = error_func;
pContext->sax->warning = warning_func;
// setup entity resolver binding(s)
ctxt->sax->resolveEntity = resolve_func;
pContext->sax->resolveEntity = resolve_func;
xmlSetExternalEntityLoader(external_entity_loader);
// if an input stream is provided, use it
@ -408,19 +394,19 @@ namespace DOM
{
::osl::MutexGuard const g(m_Mutex);
xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
ctxt->_private = this;
ctxt->sax->error = error_func;
ctxt->sax->warning = warning_func;
ctxt->sax->resolveEntity = resolve_func;
::boost::shared_ptr<xmlParserCtxt> const pContext(
xmlNewParserCtxt(), xmlFreeParserCtxt);
pContext->_private = this;
pContext->sax->error = error_func;
pContext->sax->warning = warning_func;
pContext->sax->resolveEntity = resolve_func;
// xmlSetExternalEntityLoader(external_entity_loader);
OString oUri = OUStringToOString(sUri, RTL_TEXTENCODING_UTF8);
char *uri = (char*) oUri.getStr();
xmlDocPtr pDoc = xmlCtxtReadFile(ctxt, uri, 0, 0);
xmlDocPtr pDoc = xmlCtxtReadFile(pContext.get(), uri, 0, 0);
if (pDoc == 0) {
throwEx(ctxt);
throwEx(pContext.get());
}
xmlFreeParserCtxt(ctxt);
Reference< XDocument > const xRet(
CDocument::CreateCDocument(pDoc).get());
return xRet;