summaryrefslogtreecommitdiff
path: root/unoxml
diff options
context:
space:
mode:
authorMichael Stahl <mst@openoffice.org>2011-01-19 20:27:28 +0100
committerMichael Stahl <mst@openoffice.org>2011-01-19 20:27:28 +0100
commit76eac88260284d6c85c693f7186186a05e053c54 (patch)
tree02e5f98d81cdeb33d1f08cf292b8a34d0567a1d4 /unoxml
parent75b70f1477292cf3cff3905fbcf3a3c387c17c7e (diff)
xmlfix3: unoxml: CDocumentBuilder cleanup
Diffstat (limited to 'unoxml')
-rw-r--r--unoxml/source/dom/documentbuilder.cxx64
1 files changed, 25 insertions, 39 deletions
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 <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;