diff --git a/unoxml/source/dom/documentbuilder.cxx b/unoxml/source/dom/documentbuilder.cxx index 2e8146f09c41..ec85c525bcd1 100644 --- a/unoxml/source/dom/documentbuilder.cxx +++ b/unoxml/source/dom/documentbuilder.cxx @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -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(ctxt->lastError.line); @@ -343,14 +327,15 @@ namespace DOM xmlCharEncoding enc = xmlParseCharEncoding(encstr); */ - xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); + ::boost::shared_ptr 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 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 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;