diff options
-rw-r--r-- | comphelper/source/xml/ofopxmlhelper.cxx | 111 | ||||
-rw-r--r-- | include/comphelper/ofopxmlhelper.hxx | 62 | ||||
-rw-r--r-- | package/source/xstor/xstorage.hxx | 1 |
3 files changed, 102 insertions, 72 deletions
diff --git a/comphelper/source/xml/ofopxmlhelper.cxx b/comphelper/source/xml/ofopxmlhelper.cxx index d110a48c2145..ab813567f4ee 100644 --- a/comphelper/source/xml/ofopxmlhelper.cxx +++ b/comphelper/source/xml/ofopxmlhelper.cxx @@ -18,6 +18,11 @@ */ +#include <comphelper/ofopxmlhelper.hxx> +#include <comphelper/attributelist.hxx> + +#include <cppuhelper/implbase.hxx> + #include <com/sun/star/beans/StringPair.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/io/XActiveDataSource.hpp> @@ -26,9 +31,6 @@ #include <com/sun/star/xml/sax/Writer.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <comphelper/ofopxmlhelper.hxx> -#include <comphelper/attributelist.hxx> - #define RELATIONINFO_FORMAT 0 #define CONTENTTYPE_FORMAT 1 #define FORMAT_MAX_ID CONTENTTYPE_FORMAT @@ -37,7 +39,62 @@ using namespace ::com::sun::star; namespace comphelper { -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OFOPXMLHelper::ReadRelationsInfoSequence( const uno::Reference< io::XInputStream >& xInStream, const OUString & aStreamName, const uno::Reference< uno::XComponentContext >& rContext ) +// this helper class is designed to allow to parse ContentType- and Relationship-related information from OfficeOpenXML format +class OFOPXMLHelper_Impl + : public cppu::WeakImplHelper< com::sun::star::xml::sax::XDocumentHandler > +{ + sal_uInt16 m_nFormat; // which format to parse + + // Relations info related strings + OUString m_aRelListElement; + OUString m_aRelElement; + OUString m_aIDAttr; + OUString m_aTypeAttr; + OUString m_aTargetModeAttr; + OUString m_aTargetAttr; + + // ContentType related strings + OUString m_aTypesElement; + OUString m_aDefaultElement; + OUString m_aOverrideElement; + OUString m_aExtensionAttr; + OUString m_aPartNameAttr; + OUString m_aContentTypeAttr; + + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aResultSeq; + ::com::sun::star::uno::Sequence< OUString > m_aElementsSeq; // stack of elements being parsed + + +public: + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > GetParsingResult(); + + OFOPXMLHelper_Impl( sal_uInt16 nFormat ); // must not be created directly + virtual ~OFOPXMLHelper_Impl(); + + // XDocumentHandler + virtual void SAL_CALL startDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL endDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL startElement( const OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL endElement( const OUString& aName ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL characters( const OUString& aChars ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; +}; + + +namespace OFOPXMLHelper { + +static uno::Sequence<uno::Sequence< beans::StringPair>> ReadSequence_Impl( + const uno::Reference<io::XInputStream>& xInStream, + const OUString& aStringID, sal_uInt16 nFormat, + const uno::Reference<uno::XComponentContext>& xContext) +throw (uno::Exception); + +uno::Sequence< uno::Sequence< beans::StringPair > > ReadRelationsInfoSequence( + const uno::Reference< io::XInputStream >& xInStream, + const OUString & aStreamName, + const uno::Reference< uno::XComponentContext >& rContext ) throw( uno::Exception ) { OUString aStringID = "_rels/"; @@ -46,7 +103,9 @@ uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OFOPXMLHelper::Read } -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OFOPXMLHelper::ReadContentTypeSequence( const uno::Reference< io::XInputStream >& xInStream, const uno::Reference< uno::XComponentContext >& rContext ) +uno::Sequence< uno::Sequence< beans::StringPair > > ReadContentTypeSequence( + const uno::Reference< io::XInputStream >& xInStream, + const uno::Reference< uno::XComponentContext >& rContext ) throw( uno::Exception ) { OUString aStringID = "[Content_Types].xml"; @@ -54,7 +113,10 @@ uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OFOPXMLHelper::Read } -void SAL_CALL OFOPXMLHelper::WriteRelationsInfoSequence( const uno::Reference< io::XOutputStream >& xOutStream, const uno::Sequence< uno::Sequence< beans::StringPair > >& aSequence, const uno::Reference< uno::XComponentContext >& rContext ) +void WriteRelationsInfoSequence( + const uno::Reference< io::XOutputStream >& xOutStream, + const uno::Sequence< uno::Sequence< beans::StringPair > >& aSequence, + const uno::Reference< uno::XComponentContext >& rContext ) throw( uno::Exception ) { if ( !xOutStream.is() ) @@ -115,7 +177,11 @@ void SAL_CALL OFOPXMLHelper::WriteRelationsInfoSequence( const uno::Reference< i } -void SAL_CALL OFOPXMLHelper::WriteContentSequence( const uno::Reference< io::XOutputStream >& xOutStream, const uno::Sequence< beans::StringPair >& aDefaultsSequence, const uno::Sequence< beans::StringPair >& aOverridesSequence, const uno::Reference< uno::XComponentContext >& rContext ) +void WriteContentSequence( + const uno::Reference< io::XOutputStream >& xOutStream, + const uno::Sequence< beans::StringPair >& aDefaultsSequence, + const uno::Sequence< beans::StringPair >& aOverridesSequence, + const uno::Reference< uno::XComponentContext >& rContext ) throw( uno::Exception ) { if ( !xOutStream.is() ) @@ -175,7 +241,10 @@ void SAL_CALL OFOPXMLHelper::WriteContentSequence( const uno::Reference< io::XOu } -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OFOPXMLHelper::ReadSequence_Impl( const uno::Reference< io::XInputStream >& xInStream, const OUString& aStringID, sal_uInt16 nFormat, const uno::Reference< uno::XComponentContext >& rContext ) +uno::Sequence< uno::Sequence< beans::StringPair > > ReadSequence_Impl( + const uno::Reference< io::XInputStream >& xInStream, + const OUString& aStringID, sal_uInt16 nFormat, + const uno::Reference< uno::XComponentContext >& rContext ) throw( uno::Exception ) { if ( !rContext.is() || !xInStream.is() || nFormat > FORMAT_MAX_ID ) @@ -183,7 +252,7 @@ uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OFOPXMLHelper::Read uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( rContext ); - OFOPXMLHelper* pHelper = new OFOPXMLHelper( nFormat ); + OFOPXMLHelper_Impl *const pHelper = new OFOPXMLHelper_Impl( nFormat ); uno::Reference< xml::sax::XDocumentHandler > xHelper( static_cast< xml::sax::XDocumentHandler* >( pHelper ) ); xml::sax::InputSource aParserInput; aParserInput.aInputStream = xInStream; @@ -195,7 +264,9 @@ uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OFOPXMLHelper::Read return pHelper->GetParsingResult(); } -OFOPXMLHelper::OFOPXMLHelper( sal_uInt16 nFormat ) +} // namespace OFOPXMLHelper + +OFOPXMLHelper_Impl::OFOPXMLHelper_Impl( sal_uInt16 nFormat ) : m_nFormat( nFormat ) , m_aRelListElement( "Relationships" ) , m_aRelElement( "Relationship" ) @@ -213,12 +284,12 @@ OFOPXMLHelper::OFOPXMLHelper( sal_uInt16 nFormat ) } -OFOPXMLHelper::~OFOPXMLHelper() +OFOPXMLHelper_Impl::~OFOPXMLHelper_Impl() { } -uno::Sequence< uno::Sequence< beans::StringPair > > OFOPXMLHelper::GetParsingResult() +uno::Sequence< uno::Sequence< beans::StringPair > > OFOPXMLHelper_Impl::GetParsingResult() { if ( m_aElementsSeq.getLength() ) throw uno::RuntimeException(); // the parsing has still not finished! @@ -227,19 +298,19 @@ uno::Sequence< uno::Sequence< beans::StringPair > > OFOPXMLHelper::GetParsingRes } -void SAL_CALL OFOPXMLHelper::startDocument() +void SAL_CALL OFOPXMLHelper_Impl::startDocument() throw(xml::sax::SAXException, uno::RuntimeException, std::exception) { } -void SAL_CALL OFOPXMLHelper::endDocument() +void SAL_CALL OFOPXMLHelper_Impl::endDocument() throw(xml::sax::SAXException, uno::RuntimeException, std::exception) { } -void SAL_CALL OFOPXMLHelper::startElement( const OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs ) +void SAL_CALL OFOPXMLHelper_Impl::startElement( const OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs ) throw( xml::sax::SAXException, uno::RuntimeException, std::exception ) { if ( m_nFormat == RELATIONINFO_FORMAT ) @@ -387,7 +458,7 @@ void SAL_CALL OFOPXMLHelper::startElement( const OUString& aName, const uno::Ref } -void SAL_CALL OFOPXMLHelper::endElement( const OUString& aName ) +void SAL_CALL OFOPXMLHelper_Impl::endElement( const OUString& aName ) throw( xml::sax::SAXException, uno::RuntimeException, std::exception ) { if ( m_nFormat == RELATIONINFO_FORMAT || m_nFormat == CONTENTTYPE_FORMAT ) @@ -404,25 +475,25 @@ void SAL_CALL OFOPXMLHelper::endElement( const OUString& aName ) } -void SAL_CALL OFOPXMLHelper::characters( const OUString& /*aChars*/ ) +void SAL_CALL OFOPXMLHelper_Impl::characters( const OUString& /*aChars*/ ) throw(xml::sax::SAXException, uno::RuntimeException, std::exception) { } -void SAL_CALL OFOPXMLHelper::ignorableWhitespace( const OUString& /*aWhitespaces*/ ) +void SAL_CALL OFOPXMLHelper_Impl::ignorableWhitespace( const OUString& /*aWhitespaces*/ ) throw(xml::sax::SAXException, uno::RuntimeException, std::exception) { } -void SAL_CALL OFOPXMLHelper::processingInstruction( const OUString& /*aTarget*/, const OUString& /*aData*/ ) +void SAL_CALL OFOPXMLHelper_Impl::processingInstruction( const OUString& /*aTarget*/, const OUString& /*aData*/ ) throw(xml::sax::SAXException, uno::RuntimeException, std::exception) { } -void SAL_CALL OFOPXMLHelper::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& /*xLocator*/ ) +void SAL_CALL OFOPXMLHelper_Impl::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& /*xLocator*/ ) throw(xml::sax::SAXException, uno::RuntimeException, std::exception) { } diff --git a/include/comphelper/ofopxmlhelper.hxx b/include/comphelper/ofopxmlhelper.hxx index 4c7495328f51..7ab7e3818512 100644 --- a/include/comphelper/ofopxmlhelper.hxx +++ b/include/comphelper/ofopxmlhelper.hxx @@ -20,56 +20,24 @@ #ifndef INCLUDED_COMPHELPER_OFOPXMLHELPER_HXX #define INCLUDED_COMPHELPER_OFOPXMLHELPER_HXX -#include <com/sun/star/xml/sax/XDocumentHandler.hpp> #include <com/sun/star/beans/StringPair.hpp> #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XOutputStream.hpp> -#include <cppuhelper/implbase.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> + #include <comphelper/comphelperdllapi.h> namespace comphelper { -// this helper class is designed to allow to parse ContentType- and Relationship-related information from OfficeOpenXML format -class COMPHELPER_DLLPUBLIC OFOPXMLHelper : public cppu::WeakImplHelper< com::sun::star::xml::sax::XDocumentHandler > -{ - sal_uInt16 m_nFormat; // which format to parse - - // Relations info related strings - OUString m_aRelListElement; - OUString m_aRelElement; - OUString m_aIDAttr; - OUString m_aTypeAttr; - OUString m_aTargetModeAttr; - OUString m_aTargetAttr; - - // ContentType related strings - OUString m_aTypesElement; - OUString m_aDefaultElement; - OUString m_aOverrideElement; - OUString m_aExtensionAttr; - OUString m_aPartNameAttr; - OUString m_aContentTypeAttr; - - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aResultSeq; - ::com::sun::star::uno::Sequence< OUString > m_aElementsSeq; // stack of elements being parsed - - OFOPXMLHelper( sal_uInt16 nFormat ); // must not be created directly - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > GetParsingResult(); - - static COMPHELPER_DLLPRIVATE ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL ReadSequence_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, const OUString& aStringID, sal_uInt16 nFormat, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rContext ) - throw( ::com::sun::star::uno::Exception ); - -public: - virtual ~OFOPXMLHelper(); +namespace OFOPXMLHelper { // returns sequence of elements, where each element is described by sequence of tags, // where each tag is described by StringPair ( First - name, Second - value ) // the first tag of each element sequence must be "Id" - static + COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > - SAL_CALL ReadRelationsInfoSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, const OUString & aStreamName, @@ -81,9 +49,8 @@ public: // by StringPair object ( First - Extension, Second - ContentType ) // the second sequence describes "Override" elements, where each element is described // by StringPair object ( First - PartName, Second - ContentType ) - static + COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > - SAL_CALL ReadContentTypeSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rContext ) @@ -92,8 +59,8 @@ public: // writes sequence of elements, where each element is described by sequence of tags, // where each tag is described by StringPair ( First - name, Second - value ) // the first tag of each element sequence must be "Id" - static - void SAL_CALL WriteRelationsInfoSequence( + COMPHELPER_DLLPUBLIC + void WriteRelationsInfoSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aSequence, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rContext ) @@ -104,24 +71,15 @@ public: // by StringPair object ( First - Extension, Second - ContentType ) // the second sequence describes "Override" elements, where each element is described // by StringPair object ( First - PartName, Second - ContentType ) - static - void SAL_CALL WriteContentSequence( + COMPHELPER_DLLPUBLIC + void WriteContentSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aDefaultsSequence, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aOverridesSequence, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rContext ) throw( ::com::sun::star::uno::Exception ); - // XDocumentHandler - virtual void SAL_CALL startDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual void SAL_CALL endDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual void SAL_CALL startElement( const OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual void SAL_CALL endElement( const OUString& aName ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual void SAL_CALL characters( const OUString& aChars ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; - virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; -}; +} // namespace OFOPXMLHelper } // namespace comphelper diff --git a/package/source/xstor/xstorage.hxx b/package/source/xstor/xstorage.hxx index c1371a367c86..09114739a7e7 100644 --- a/package/source/xstor/xstorage.hxx +++ b/package/source/xstor/xstorage.hxx @@ -45,6 +45,7 @@ #include <com/sun/star/logging/XSimpleLogRing.hpp> #include <cppuhelper/weak.hxx> +#include <cppuhelper/weakref.hxx> #include <cppuhelper/interfacecontainer.h> #include <comphelper/sequenceashashmap.hxx> |