summaryrefslogtreecommitdiff
path: root/sdext/source/pdfimport/sax
diff options
context:
space:
mode:
Diffstat (limited to 'sdext/source/pdfimport/sax')
-rw-r--r--sdext/source/pdfimport/sax/emitcontext.cxx190
-rw-r--r--sdext/source/pdfimport/sax/emitcontext.hxx60
-rw-r--r--sdext/source/pdfimport/sax/makefile.mk51
-rw-r--r--sdext/source/pdfimport/sax/saxattrlist.cxx104
-rw-r--r--sdext/source/pdfimport/sax/saxattrlist.hxx76
5 files changed, 481 insertions, 0 deletions
diff --git a/sdext/source/pdfimport/sax/emitcontext.cxx b/sdext/source/pdfimport/sax/emitcontext.cxx
new file mode 100644
index 000000000000..6ea6a977b20f
--- /dev/null
+++ b/sdext/source/pdfimport/sax/emitcontext.cxx
@@ -0,0 +1,190 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sdext.hxx"
+
+#include "saxemitter.hxx"
+#include "emitcontext.hxx"
+#include "saxattrlist.hxx"
+
+#include <rtl/strbuf.hxx>
+#include <cppuhelper/exc_hlp.hxx>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+
+#if OSL_DEBUG_LEVEL > 1
+#include <osl/file.hxx>
+static osl::File* pStream = NULL;
+static int nIndent = 0;
+#endif
+
+using namespace com::sun::star;
+
+namespace pdfi
+{
+
+SaxEmitter::SaxEmitter( const uno::Reference< xml::sax::XDocumentHandler >& xDocHdl ) :
+ m_xDocHdl( xDocHdl )
+{
+ OSL_PRECOND(m_xDocHdl.is(), "SaxEmitter(): invalid doc handler");
+ try
+ {
+ m_xDocHdl->startDocument();
+ }
+ catch( xml::sax::SAXException& )
+ {
+ }
+#if OSL_DEBUG_LEVEL > 1
+ static const char* pDir = getenv( "DBG_PDFIMPORT_DIR" );
+ if( pDir )
+ {
+ rtl::OUString aStr( rtl::OStringToOUString( pDir, RTL_TEXTENCODING_UTF8 ) );
+ rtl::OUString aFileURL;
+ osl_getFileURLFromSystemPath( aStr.pData, &aFileURL.pData );
+ rtl::OUStringBuffer aBuf( 256 );
+ aBuf.append( aFileURL );
+ aBuf.appendAscii( "/pdfimport.xml" );
+ pStream = new osl::File( aBuf.makeStringAndClear() );
+ if( pStream->open( OpenFlag_Write | OpenFlag_Create ) )
+ {
+ pStream->open( OpenFlag_Write );
+ pStream->setSize( 0 );
+ }
+ }
+ else
+ pStream = 0;
+#endif
+}
+
+SaxEmitter::~SaxEmitter()
+{
+ try
+ {
+ m_xDocHdl->endDocument();
+ }
+ catch( xml::sax::SAXException& )
+ {
+ }
+#if OSL_DEBUG_LEVEL > 1
+ if( pStream )
+ {
+ pStream->close();
+ delete pStream;
+ pStream = 0;
+ }
+#endif
+}
+
+void SaxEmitter::beginTag( const char* pTag, const PropertyMap& rProperties )
+{
+ rtl::OUString aTag = rtl::OUString::createFromAscii( pTag );
+ uno::Reference< xml::sax::XAttributeList > xAttr(
+ new SaxAttrList( rProperties ) );
+ try
+ {
+ m_xDocHdl->startElement( aTag, xAttr );
+ }
+ catch( xml::sax::SAXException& )
+ {
+ }
+#if OSL_DEBUG_LEVEL > 1
+ if( pStream )
+ {
+ sal_uInt64 nWritten = 0;
+ for( int i = 0; i < nIndent; i++ )
+ pStream->write( " ", 4, nWritten );
+
+ rtl::OStringBuffer aBuf( 1024 );
+ aBuf.append( '<' );
+ aBuf.append( pTag );
+ for( PropertyMap::const_iterator it = rProperties.begin(); it != rProperties.end(); ++it )
+ {
+ aBuf.append( ' ' );
+ aBuf.append( rtl::OUStringToOString( it->first, RTL_TEXTENCODING_UTF8 ) );
+ aBuf.append( "=\"" );
+ aBuf.append( rtl::OUStringToOString( it->second, RTL_TEXTENCODING_UTF8 ) );
+ aBuf.append( "\"" );
+ }
+ aBuf.append( ">\n" );
+ pStream->write( aBuf.getStr(), aBuf.getLength(), nWritten );
+ nIndent++;
+ }
+#endif
+}
+
+void SaxEmitter::write( const rtl::OUString& rText )
+{
+ try
+ {
+ m_xDocHdl->characters( rText );
+ }
+ catch( xml::sax::SAXException& )
+ {
+ }
+#if OSL_DEBUG_LEVEL > 1
+ if( pStream )
+ {
+ rtl::OString aStr( rtl::OUStringToOString( rText, RTL_TEXTENCODING_UTF8 ) );
+ sal_uInt64 nWritten = 0;
+ pStream->write( aStr.getStr(), aStr.getLength(), nWritten );
+ }
+#endif
+}
+
+void SaxEmitter::endTag( const char* pTag )
+{
+ rtl::OUString aTag = rtl::OUString::createFromAscii( pTag );
+ try
+ {
+ m_xDocHdl->endElement( aTag );
+ }
+ catch( xml::sax::SAXException& )
+ {
+ }
+#if OSL_DEBUG_LEVEL > 1
+ if( pStream )
+ {
+ sal_uInt64 nWritten = 0;
+ for( int i = 0; i < nIndent; i++ )
+ pStream->write( " ", 4, nWritten );
+
+ rtl::OStringBuffer aBuf( 1024 );
+ aBuf.append( "</" );
+ aBuf.append( pTag );
+ aBuf.append( ">\n" );
+ pStream->write( aBuf.getStr(), aBuf.getLength(), nWritten );
+ nIndent--;
+ }
+#endif
+}
+
+XmlEmitterSharedPtr createSaxEmitter( const uno::Reference< xml::sax::XDocumentHandler >& xDocHdl )
+{
+ return XmlEmitterSharedPtr(new SaxEmitter(xDocHdl));
+}
+
+}
diff --git a/sdext/source/pdfimport/sax/emitcontext.hxx b/sdext/source/pdfimport/sax/emitcontext.hxx
new file mode 100644
index 000000000000..880aaa90d4e8
--- /dev/null
+++ b/sdext/source/pdfimport/sax/emitcontext.hxx
@@ -0,0 +1,60 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_PDFI_EMITCONTEXT_HXX
+#define INCLUDED_PDFI_EMITCONTEXT_HXX
+
+#include "xmlemitter.hxx"
+
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+
+#include <rtl/ustring.hxx>
+
+
+namespace pdfi
+{
+ class PDFIProcessor;
+ class StyleContainer;
+ class SaxEmitter : public XmlEmitter
+ {
+ private:
+ com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler > m_xDocHdl;
+
+ public:
+ explicit SaxEmitter( const com::sun::star::uno::Reference<
+ com::sun::star::xml::sax::XDocumentHandler >& xDocHdl );
+ ~SaxEmitter();
+
+ virtual void beginTag( const char* pTag, const PropertyMap& rProperties );
+ virtual void write( const rtl::OUString& rString );
+ virtual void endTag( const char* pTag );
+ };
+}
+
+#endif
+
diff --git a/sdext/source/pdfimport/sax/makefile.mk b/sdext/source/pdfimport/sax/makefile.mk
new file mode 100644
index 000000000000..39c3c9f1e4d2
--- /dev/null
+++ b/sdext/source/pdfimport/sax/makefile.mk
@@ -0,0 +1,51 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..$/..
+
+PRJNAME=sdext
+TARGET=pdfsax
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE: settings.mk
+
+# --- Files --------------------------------------------------------
+
+SLOFILES=\
+ $(SLO)$/emitcontext.obj \
+ $(SLO)$/saxattrlist.obj
+
+# --- Targets ------------------------------------------------------
+
+.IF "$(ENABLE_PDFIMPORT)" == "NO"
+@all:
+ @echo "PDF Import extension disabled."
+.ENDIF
+
+.INCLUDE: target.mk
diff --git a/sdext/source/pdfimport/sax/saxattrlist.cxx b/sdext/source/pdfimport/sax/saxattrlist.cxx
new file mode 100644
index 000000000000..4b5cf9c7a4df
--- /dev/null
+++ b/sdext/source/pdfimport/sax/saxattrlist.cxx
@@ -0,0 +1,104 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sdext.hxx"
+
+#include "saxattrlist.hxx"
+
+namespace pdfi
+{
+
+SaxAttrList::SaxAttrList( const std::hash_map< rtl::OUString, rtl::OUString, rtl::OUStringHash >& rMap )
+{
+ m_aAttributes.reserve(rMap.size());
+ for( std::hash_map< rtl::OUString,
+ rtl::OUString,
+ rtl::OUStringHash >::const_iterator it = rMap.begin();
+ it != rMap.end(); ++it )
+ {
+ m_aIndexMap[ it->first ] = m_aAttributes.size();
+ m_aAttributes.push_back( AttrEntry( it->first, it->second ) );
+ }
+}
+
+SaxAttrList::SaxAttrList( const SaxAttrList& rClone ) :
+ cppu::WeakImplHelper2<com::sun::star::xml::sax::XAttributeList, com::sun::star::util::XCloneable>(rClone),
+ m_aAttributes( rClone.m_aAttributes ),
+ m_aIndexMap( rClone.m_aIndexMap )
+{
+}
+
+SaxAttrList::~SaxAttrList()
+{
+}
+
+namespace {
+ static const rtl::OUString& getCDATAString()
+ {
+ static rtl::OUString aStr( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) );
+ return aStr;
+ }
+}
+
+sal_Int16 SAL_CALL SaxAttrList::getLength() throw()
+{
+ return sal_Int16(m_aAttributes.size());
+}
+rtl::OUString SAL_CALL SaxAttrList::getNameByIndex( sal_Int16 i_nIndex ) throw()
+{
+ return (i_nIndex < sal_Int16(m_aAttributes.size())) ? m_aAttributes[i_nIndex].m_aName : rtl::OUString();
+}
+
+rtl::OUString SAL_CALL SaxAttrList::getTypeByIndex( sal_Int16 i_nIndex) throw()
+{
+ return (i_nIndex < sal_Int16(m_aAttributes.size())) ? getCDATAString() : rtl::OUString();
+}
+
+rtl::OUString SAL_CALL SaxAttrList::getTypeByName( const ::rtl::OUString& i_rName ) throw()
+{
+ return (m_aIndexMap.find( i_rName ) != m_aIndexMap.end()) ? getCDATAString() : rtl::OUString();
+}
+
+rtl::OUString SAL_CALL SaxAttrList::getValueByIndex( sal_Int16 i_nIndex ) throw()
+{
+ return (i_nIndex < sal_Int16(m_aAttributes.size())) ? m_aAttributes[i_nIndex].m_aValue : rtl::OUString();
+}
+
+rtl::OUString SAL_CALL SaxAttrList::getValueByName(const ::rtl::OUString& i_rName) throw()
+{
+ std::hash_map< rtl::OUString, size_t, rtl::OUStringHash >::const_iterator it = m_aIndexMap.find( i_rName );
+ return (it != m_aIndexMap.end()) ? m_aAttributes[it->second].m_aValue : rtl::OUString();
+}
+
+com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL SaxAttrList::createClone() throw()
+{
+ return new SaxAttrList( *this );
+}
+
+}
+
diff --git a/sdext/source/pdfimport/sax/saxattrlist.hxx b/sdext/source/pdfimport/sax/saxattrlist.hxx
new file mode 100644
index 000000000000..0866467e2d1f
--- /dev/null
+++ b/sdext/source/pdfimport/sax/saxattrlist.hxx
@@ -0,0 +1,76 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_PDFI_SAXATTRLIST_HXX
+#define INCLUDED_PDFI_SAXATTRLIST_HXX
+
+#include <rtl/ustring.hxx>
+#include <vector>
+#include <hash_map>
+#include <cppuhelper/implbase2.hxx>
+
+#include <com/sun/star/util/XCloneable.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+
+namespace pdfi
+{
+ class SaxAttrList : public ::cppu::WeakImplHelper2<
+ com::sun::star::xml::sax::XAttributeList,
+ com::sun::star::util::XCloneable
+ >
+ {
+ struct AttrEntry
+ {
+ rtl::OUString m_aName;
+ rtl::OUString m_aValue;
+
+ AttrEntry( const rtl::OUString& i_rName, const rtl::OUString& i_rValue )
+ : m_aName( i_rName ), m_aValue( i_rValue ) {}
+ };
+ std::vector< AttrEntry > m_aAttributes;
+ std::hash_map< rtl::OUString, size_t, rtl::OUStringHash > m_aIndexMap;
+
+ public:
+ SaxAttrList() {}
+ SaxAttrList( const std::hash_map< rtl::OUString, rtl::OUString, rtl::OUStringHash >& );
+ SaxAttrList( const SaxAttrList& );
+ virtual ~SaxAttrList();
+
+ // ::com::sun::star::xml::sax::XAttributeList
+ virtual sal_Int16 SAL_CALL getLength() throw();
+ virtual rtl::OUString SAL_CALL getNameByIndex(sal_Int16 i) throw();
+ virtual rtl::OUString SAL_CALL getTypeByIndex(sal_Int16 i) throw();
+ virtual rtl::OUString SAL_CALL getTypeByName(const ::rtl::OUString& aName) throw();
+ virtual rtl::OUString SAL_CALL getValueByIndex(sal_Int16 i) throw();
+ virtual rtl::OUString SAL_CALL getValueByName(const ::rtl::OUString& aName) throw();
+
+ // ::com::sun::star::util::XCloneable
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() throw();
+ };
+}
+
+#endif