diff options
author | Daniel Rentz [dr] <daniel.rentz@oracle.com> | 2010-11-08 13:47:01 +0100 |
---|---|---|
committer | Daniel Rentz [dr] <daniel.rentz@oracle.com> | 2010-11-08 13:47:01 +0100 |
commit | 6cafb68322fa85a54a6fa1ca47239af459f519ce (patch) | |
tree | 41d02f348e9dd2c6791347563d7f5b9205a3b458 /oox/source/docprop | |
parent | 0b66e33ee50cd1c77bd9b1073ab298bac03bcfb7 (diff) |
dr77: optimizations in generation of XML tokens, XML namespaces, property names; code cleanup
Diffstat (limited to 'oox/source/docprop')
-rw-r--r-- | oox/source/docprop/docprophandler.cxx | 138 | ||||
-rw-r--r-- | oox/source/docprop/docprophandler.hxx | 10 | ||||
-rw-r--r-- | oox/source/docprop/ooxmldocpropimport.cxx | 261 | ||||
-rw-r--r-- | oox/source/docprop/ooxmldocpropimport.hxx | 40 |
4 files changed, 210 insertions, 239 deletions
diff --git a/oox/source/docprop/docprophandler.cxx b/oox/source/docprop/docprophandler.cxx index 1830a8c5d5f9..560fcf141c19 100644 --- a/oox/source/docprop/docprophandler.cxx +++ b/oox/source/docprop/docprophandler.cxx @@ -33,9 +33,7 @@ #include <osl/time.h> -#include "tokens.hxx" #include "oox/helper/attributelist.hxx" -#include "oox/core/namespaces.hxx" using namespace ::com::sun::star; @@ -226,19 +224,19 @@ void OOXMLDocPropHandler::UpdateDocStatistic( const ::rtl::OUString& aChars ) switch( m_nBlock ) { - case XML_Characters|NMSP_EXTPR: + case EXTPR_TOKEN( Characters ): aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterCount" ) ); break; - case XML_Pages|NMSP_EXTPR: + case EXTPR_TOKEN( Pages ): aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageCount" ) ); break; - case XML_Words|NMSP_EXTPR: + case EXTPR_TOKEN( Words ): aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WordCount" ) ); break; - case XML_Paragraphs|NMSP_EXTPR: + case EXTPR_TOKEN( Paragraphs ): aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphCount" ) ); break; @@ -299,9 +297,9 @@ void SAL_CALL OOXMLDocPropHandler::startFastElement( ::sal_Int32 nElement, const { if ( !m_nInBlock && !m_nState ) { - if ( nElement == ( XML_coreProperties|NMSP_COREPR ) - || nElement == ( XML_Properties|NMSP_EXTPR ) - || nElement == ( XML_Properties|NMSP_CUSTPR ) ) + if ( nElement == COREPR_TOKEN( coreProperties ) + || nElement == EXTPR_TOKEN( Properties ) + || nElement == CUSTPR_TOKEN( Properties ) ) { m_nState = nElement; } @@ -320,7 +318,7 @@ void SAL_CALL OOXMLDocPropHandler::startFastElement( ::sal_Int32 nElement, const if ( xAttribs.is() && xAttribs->hasAttribute( XML_name ) ) m_aCustomPropertyName = xAttribs->getValue( XML_name ); } - else if ( m_nState && m_nInBlock && m_nInBlock == 2 && ( nElement >> 16 ) == ( NMSP_VT >> 16 ) ) + else if ( m_nState && m_nInBlock && m_nInBlock == 2 && getNamespace( nElement ) == NMSP_officeDocPropsVT ) { m_nType = nElement; } @@ -402,72 +400,72 @@ void SAL_CALL OOXMLDocPropHandler::characters( const ::rtl::OUString& aChars ) { if ( (m_nInBlock == 2) || ((m_nInBlock == 3) && m_nType) ) { - if ( m_nState == ( XML_coreProperties|NMSP_COREPR ) ) + if ( m_nState == COREPR_TOKEN( coreProperties ) ) { switch( m_nBlock ) { - case XML_category|NMSP_COREPR: + case COREPR_TOKEN( category ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "category" ) ); AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type break; - case XML_contentStatus|NMSP_COREPR: + case COREPR_TOKEN( contentStatus ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "contentStatus" ) ); AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type break; - case XML_contentType|NMSP_COREPR: + case COREPR_TOKEN( contentType ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "contentType" ) ); AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type break; - case XML_identifier|NMSP_COREPR: + case COREPR_TOKEN( identifier ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "identifier" ) ); AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type break; - case XML_version|NMSP_COREPR: + case COREPR_TOKEN( version ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "version" ) ); AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type break; - case XML_created|NMSP_DCTERMS: + case DCT_TOKEN( created ): if ( aChars.getLength() >= 4 ) m_xDocProp->setCreationDate( GetDateTimeFromW3CDTF( aChars ) ); break; - case XML_creator|NMSP_DC: + case DC_TOKEN( creator ): m_xDocProp->setAuthor( aChars ); break; - case XML_description|NMSP_DC: + case DC_TOKEN( description ): m_xDocProp->setDescription( aChars ); break; - case XML_keywords|NMSP_COREPR: + case COREPR_TOKEN( keywords ): m_xDocProp->setKeywords( GetKeywordsSet( aChars ) ); break; - case XML_language|NMSP_DC: + case DC_TOKEN( language ): if ( aChars.getLength() >= 2 ) m_xDocProp->setLanguage( GetLanguage( aChars ) ); break; - case XML_lastModifiedBy|NMSP_COREPR: + case COREPR_TOKEN( lastModifiedBy ): m_xDocProp->setModifiedBy( aChars ); break; - case XML_lastPrinted|NMSP_COREPR: + case COREPR_TOKEN( lastPrinted ): if ( aChars.getLength() >= 4 ) m_xDocProp->setPrintDate( GetDateTimeFromW3CDTF( aChars ) ); break; - case XML_modified|NMSP_DCTERMS: + case DCT_TOKEN( modified ): if ( aChars.getLength() >= 4 ) m_xDocProp->setModificationDate( GetDateTimeFromW3CDTF( aChars ) ); break; - case XML_revision|NMSP_COREPR: + case COREPR_TOKEN( revision ): try { m_xDocProp->setEditingCycles( @@ -479,11 +477,11 @@ void SAL_CALL OOXMLDocPropHandler::characters( const ::rtl::OUString& aChars ) } break; - case XML_subject|NMSP_DC: + case DC_TOKEN( subject ): m_xDocProp->setSubject( aChars ); break; - case XML_title|NMSP_DC: + case DC_TOKEN( title ): m_xDocProp->setTitle( aChars ); break; @@ -491,19 +489,19 @@ void SAL_CALL OOXMLDocPropHandler::characters( const ::rtl::OUString& aChars ) OSL_ASSERT( "Unexpected core property!" ); } } - else if ( m_nState == ( XML_Properties|NMSP_EXTPR ) ) + else if ( m_nState == EXTPR_TOKEN( Properties ) ) { switch( m_nBlock ) { - case XML_Application|NMSP_EXTPR: + case EXTPR_TOKEN( Application ): m_xDocProp->setGenerator( aChars ); break; - case XML_Template|NMSP_EXTPR: + case EXTPR_TOKEN( Template ): m_xDocProp->setTemplateName( aChars ); break; - case XML_TotalTime|NMSP_EXTPR: + case EXTPR_TOKEN( TotalTime ): try { m_xDocProp->setEditingDuration( aChars.toInt32() ); @@ -514,89 +512,89 @@ void SAL_CALL OOXMLDocPropHandler::characters( const ::rtl::OUString& aChars ) } break; - case XML_Characters|NMSP_EXTPR: - case XML_Pages|NMSP_EXTPR: - case XML_Words|NMSP_EXTPR: - case XML_Paragraphs|NMSP_EXTPR: + case EXTPR_TOKEN( Characters ): + case EXTPR_TOKEN( Pages ): + case EXTPR_TOKEN( Words ): + case EXTPR_TOKEN( Paragraphs ): UpdateDocStatistic( aChars ); break; - case XML_HyperlinksChanged|NMSP_EXTPR: + case EXTPR_TOKEN( HyperlinksChanged ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HyperlinksChanged" ) ); AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type break; - case XML_LinksUpToDate|NMSP_EXTPR: + case EXTPR_TOKEN( LinksUpToDate ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LinksUpToDate" ) ); AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type break; - case XML_ScaleCrop|NMSP_EXTPR: + case EXTPR_TOKEN( ScaleCrop ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScaleCrop" ) ); AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type break; - case XML_SharedDoc|NMSP_EXTPR: + case EXTPR_TOKEN( SharedDoc ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ShareDoc" ) ); AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type break; - case XML_DocSecurity|NMSP_EXTPR: + case EXTPR_TOKEN( DocSecurity ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocSecurity" ) ); AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type break; - case XML_HiddenSlides|NMSP_EXTPR: + case EXTPR_TOKEN( HiddenSlides ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HiddenSlides" ) ); AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type break; - case XML_MMClips|NMSP_EXTPR: + case EXTPR_TOKEN( MMClips ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MMClips" ) ); AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type break; - case XML_Notes|NMSP_EXTPR: + case EXTPR_TOKEN( Notes ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Notes" ) ); AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type break; - case XML_Slides|NMSP_EXTPR: + case EXTPR_TOKEN( Slides ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Slides" ) ); AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type break; - case XML_AppVersion|NMSP_EXTPR: + case EXTPR_TOKEN( AppVersion ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AppVersion" ) ); AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type break; - case XML_Company|NMSP_EXTPR: + case EXTPR_TOKEN( Company ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Company" ) ); AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type break; - case XML_HyperlinkBase|NMSP_EXTPR: + case EXTPR_TOKEN( HyperlinkBase ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HyperlinkBase" ) ); AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type break; - case XML_Manager|NMSP_EXTPR: + case EXTPR_TOKEN( Manager ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Manager" ) ); AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type break; - case XML_PresentationFormat|NMSP_EXTPR: + case EXTPR_TOKEN( PresentationFormat ): m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PresentationFormat" ) ); AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type break; - case XML_CharactersWithSpaces|NMSP_EXTPR: - case XML_Lines|NMSP_EXTPR: - case XML_DigSig|NMSP_EXTPR: - case XML_HeadingPairs|NMSP_EXTPR: - case XML_HLinks|NMSP_EXTPR: - case XML_TitlesOfParts|NMSP_EXTPR: + case EXTPR_TOKEN( CharactersWithSpaces ): + case EXTPR_TOKEN( Lines ): + case EXTPR_TOKEN( DigSig ): + case EXTPR_TOKEN( HeadingPairs ): + case EXTPR_TOKEN( HLinks ): + case EXTPR_TOKEN( TitlesOfParts ): // ignored during the import currently break; @@ -604,46 +602,46 @@ void SAL_CALL OOXMLDocPropHandler::characters( const ::rtl::OUString& aChars ) OSL_ASSERT( "Unexpected extended property!" ); } } - else if ( m_nState == ( XML_Properties|NMSP_CUSTPR ) ) + else if ( m_nState == CUSTPR_TOKEN( Properties ) ) { - if ( m_nBlock == ( XML_property|NMSP_CUSTPR ) ) + if ( m_nBlock == CUSTPR_TOKEN( property ) ) { // this is a custom property switch( m_nType ) { - case XML_bool|NMSP_VT: + case VT_TOKEN( bool ): AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); break; - case XML_bstr|NMSP_VT: - case XML_lpstr|NMSP_VT: - case XML_lpwstr|NMSP_VT: + case VT_TOKEN( bstr ): + case VT_TOKEN( lpstr ): + case VT_TOKEN( lpwstr ): AddCustomProperty( uno::makeAny( AttributeConversion::decodeXString( aChars ) ) ); // the property has string type break; - case XML_date|NMSP_VT: - case XML_filetime|NMSP_VT: + case VT_TOKEN( date ): + case VT_TOKEN( filetime ): AddCustomProperty( uno::makeAny( GetDateTimeFromW3CDTF( aChars ) ) ); - case XML_i1|NMSP_VT: - case XML_i2|NMSP_VT: + case VT_TOKEN( i1 ): + case VT_TOKEN( i2 ): AddCustomProperty( uno::makeAny( (sal_Int16)aChars.toInt32() ) ); break; - case XML_i4|NMSP_VT: - case XML_int|NMSP_VT: + case VT_TOKEN( i4 ): + case VT_TOKEN( int ): AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); break; - case XML_i8|NMSP_VT: + case VT_TOKEN( i8 ): AddCustomProperty( uno::makeAny( aChars.toInt64() ) ); break; - case XML_r4|NMSP_VT: + case VT_TOKEN( r4 ): AddCustomProperty( uno::makeAny( aChars.toFloat() ) ); break; - case XML_r8|NMSP_VT: + case VT_TOKEN( r8 ): AddCustomProperty( uno::makeAny( aChars.toDouble() ) ); break; diff --git a/oox/source/docprop/docprophandler.hxx b/oox/source/docprop/docprophandler.hxx index bb2cff323159..13e6e47b025e 100644 --- a/oox/source/docprop/docprophandler.hxx +++ b/oox/source/docprop/docprophandler.hxx @@ -34,9 +34,19 @@ #include <cppuhelper/implbase1.hxx> +#include "oox/token/namespaces.hxx" +#include "oox/token/tokens.hxx" + namespace oox { namespace docprop { +#define COREPR_TOKEN( token ) (::oox::NMSP_packageMetaCorePr | XML_##token) +#define CUSTPR_TOKEN( token ) (::oox::NMSP_officeCustomPr | XML_##token) +#define EXTPR_TOKEN( token ) (::oox::NMSP_officeExtPr | XML_##token) +#define VT_TOKEN( token ) (::oox::NMSP_officeDocPropsVT | XML_##token) +#define DC_TOKEN( token ) (::oox::NMSP_dc | XML_##token) +#define DCT_TOKEN( token ) (::oox::NMSP_dcTerms | XML_##token) + class OOXMLDocPropHandler : public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XFastDocumentHandler > { ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; diff --git a/oox/source/docprop/ooxmldocpropimport.cxx b/oox/source/docprop/ooxmldocpropimport.cxx index de34f592e98a..794950e0fbf3 100644 --- a/oox/source/docprop/ooxmldocpropimport.cxx +++ b/oox/source/docprop/ooxmldocpropimport.cxx @@ -25,203 +25,166 @@ * ************************************************************************/ -#include <com/sun/star/embed/XStorage.hpp> +#include "ooxmldocpropimport.hxx" + +#include <vector> +#include <com/sun/star/embed/ElementModes.hpp> #include <com/sun/star/embed/XHierarchicalStorageAccess.hpp> #include <com/sun/star/embed/XRelationshipAccess.hpp> -#include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/xml/sax/XFastParser.hpp> -#include <com/sun/star/xml/sax/XFastTokenHandler.hpp> -#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp> - -#include <cppuhelper/factory.hxx> -#include <cppuhelper/implementationentry.hxx> - -#include <oox/core/namespaces.hxx> +#include <com/sun/star/embed/XStorage.hpp> +#include "oox/core/fastparser.hxx" +#include "oox/core/relations.hxx" +#include "oox/helper/containerhelper.hxx" +#include "oox/helper/helper.hxx" #include "docprophandler.hxx" -#include "ooxmldocpropimport.hxx" - -using namespace ::com::sun::star; namespace oox { namespace docprop { -// ----------------------------------------------------------- -::rtl::OUString SAL_CALL OOXMLDocPropImportImpl_getImplementationName() +// ============================================================================ + +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::embed; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::xml::sax; + +using ::rtl::OUString; + +// ============================================================================ + +OUString SAL_CALL DocumentPropertiesImport_getImplementationName() { - return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.comp.oox.docprop.OOXMLDocumentPropertiesImporter")); + return CREATE_OUSTRING( "com.sun.star.comp.oox.docprop.DocumentPropertiesImport" ); } -// ----------------------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL OOXMLDocPropImportImpl_getSupportedServiceNames() +Sequence< OUString > SAL_CALL DocumentPropertiesImport_getSupportedServiceNames() { - uno::Sequence< ::rtl::OUString > s(1); - s[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.document.OOXMLDocumentPropertiesImporter")); - return s; + Sequence< OUString > aServices( 1 ); + aServices[ 0 ] = CREATE_OUSTRING( "com.sun.star.document.OOXMLDocumentPropertiesImporter" ); + return aServices; } -// ----------------------------------------------------------- -uno::Reference< uno::XInterface > SAL_CALL OOXMLDocPropImportImpl_createInstance( - const uno::Reference< uno::XComponentContext > & context) - SAL_THROW((uno::Exception)) +Reference< XInterface > SAL_CALL DocumentPropertiesImport_createInstance( const Reference< XComponentContext >& rxContext ) SAL_THROW((Exception)) { - return static_cast< ::cppu::OWeakObject * >(new OOXMLDocPropImportImpl(context)); + return static_cast< ::cppu::OWeakObject* >( new DocumentPropertiesImport( rxContext ) ); } +// ============================================================================ -// ----------------------------------------------------------- -OOXMLDocPropImportImpl::OOXMLDocPropImportImpl(uno::Reference< uno::XComponentContext > const & xContext) : - m_xContext( xContext ) -{} +namespace { -// ----------------------------------------------------------- -uno::Sequence< xml::sax::InputSource > OOXMLDocPropImportImpl::GetRelatedStreams( const uno::Reference< embed::XStorage > xStorage, const ::rtl::OUString& aStreamType ) +Sequence< InputSource > lclGetRelatedStreams( const Reference< XStorage >& rxStorage, const OUString& rStreamType ) throw (RuntimeException) { - if ( !xStorage.is() ) - throw uno::RuntimeException(); + Reference< XRelationshipAccess > xRelation( rxStorage, UNO_QUERY_THROW ); + Reference< XHierarchicalStorageAccess > xHierarchy( rxStorage, UNO_QUERY_THROW ); - uno::Reference< embed::XRelationshipAccess > xRelation( xStorage, uno::UNO_QUERY_THROW ); - uno::Reference< embed::XHierarchicalStorageAccess > xHierarchy( xStorage, uno::UNO_QUERY_THROW ); - - uno::Sequence< uno::Sequence< beans::StringPair > > aPropsInfo = xRelation->getRelationshipsByType( aStreamType ); + Sequence< Sequence< StringPair > > aPropsInfo = xRelation->getRelationshipsByType( rStreamType ); sal_Int32 nLength = 0; - uno::Sequence< xml::sax::InputSource > aResult( aPropsInfo.getLength() ); - if ( aPropsInfo.getLength() ) + ::std::vector< InputSource > aResult; + + for( sal_Int32 nIndex = 0, nLength = aPropsInfo.getLength(); nIndex < nLength; ++nIndex ) { - for ( sal_Int32 nInd = 0; nInd < aPropsInfo.getLength(); nInd++ ) - for ( sal_Int32 nEntryInd = 0; nEntryInd < aPropsInfo[nInd].getLength(); nEntryInd++ ) - if ( aPropsInfo[nInd][nEntryInd].First.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Target" ) ) ) ) + const Sequence< StringPair >& rEntries = aPropsInfo[ nIndex ]; + for( sal_Int32 nEntryIndex = 0, nEntryLength = rEntries.getLength(); nEntryIndex < nEntryLength; ++nEntryIndex ) + { + const StringPair& rEntry = rEntries[ nEntryIndex ]; + if( rEntry.First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Target" ) ) ) + { + Reference< XExtendedStorageStream > xExtStream( + xHierarchy->openStreamElementByHierarchicalName( rEntry.Second, ElementModes::READ ), UNO_QUERY_THROW ); + Reference< XInputStream > xInStream = xExtStream->getInputStream(); + if( xInStream.is() ) { - uno::Reference< embed::XExtendedStorageStream > xExtStream = xHierarchy->openStreamElementByHierarchicalName( aPropsInfo[nInd][nEntryInd].Second, embed::ElementModes::READ ); - if ( !xExtStream.is() ) - throw uno::RuntimeException(); - - aResult[nLength].sSystemId = aPropsInfo[nInd][nEntryInd].Second; - aResult[nLength++].aInputStream = xExtStream->getInputStream(); - break; + aResult.resize( aResult.size() + 1 ); + aResult.back().sSystemId = rEntry.Second; + aResult.back().aInputStream = xExtStream->getInputStream(); } - - aResult.realloc( nLength ); + break; + } + } } - return aResult; + return ContainerHelper::vectorToSequence( aResult ); } -// com.sun.star.uno.XServiceInfo: -// ----------------------------------------------------------- -::rtl::OUString SAL_CALL OOXMLDocPropImportImpl::getImplementationName() throw (uno::RuntimeException) +} // namespace + +// ============================================================================ + +DocumentPropertiesImport::DocumentPropertiesImport( const Reference< XComponentContext >& rxContext ) : + mxContext( rxContext ) { - return OOXMLDocPropImportImpl_getImplementationName(); } -// ----------------------------------------------------------- -::sal_Bool SAL_CALL OOXMLDocPropImportImpl::supportsService(::rtl::OUString const & serviceName) throw (uno::RuntimeException) -{ - uno::Sequence< ::rtl::OUString > serviceNames = OOXMLDocPropImportImpl_getSupportedServiceNames(); - for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) - { - if (serviceNames[i] == serviceName) - return sal_True; - } +// XServiceInfo - return sal_False; +OUString SAL_CALL DocumentPropertiesImport::getImplementationName() throw (RuntimeException) +{ + return DocumentPropertiesImport_getImplementationName(); } -// ----------------------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL OOXMLDocPropImportImpl::getSupportedServiceNames() throw (uno::RuntimeException) +sal_Bool SAL_CALL DocumentPropertiesImport::supportsService( const OUString& rServiceName ) throw (RuntimeException) { - return OOXMLDocPropImportImpl_getSupportedServiceNames(); + Sequence< OUString > aServiceNames = DocumentPropertiesImport_getSupportedServiceNames(); + for( sal_Int32 nIndex = 0, nLength = aServiceNames.getLength(); nIndex < nLength; ++nIndex ) + if( aServiceNames[ nIndex ] == rServiceName ) + return sal_True; + return sal_False; } -// ----------------------------------------------------------- -// ::com::sun::star::document::XOOXMLDocumentPropertiesImporter: -void SAL_CALL OOXMLDocPropImportImpl::importProperties(const uno::Reference< embed::XStorage > & xSource, const uno::Reference< document::XDocumentProperties > & xDocumentProperties) throw (uno::RuntimeException, lang::IllegalArgumentException, xml::sax::SAXException, uno::Exception) +Sequence< OUString > SAL_CALL DocumentPropertiesImport::getSupportedServiceNames() throw (RuntimeException) { - // TODO: Insert your implementation for "importProperties" here. - if ( !m_xContext.is() ) - throw uno::RuntimeException(); + return DocumentPropertiesImport_getSupportedServiceNames(); +} - if ( !xSource.is() || !xDocumentProperties.is() ) - throw lang::IllegalArgumentException(); +// XOOXMLDocumentPropertiesImporter - // the MS Office seems to have a bug, so we have to do similar handling - ::rtl::OUString aCoreType( RTL_CONSTASCII_USTRINGPARAM( "http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties" ) ); - ::rtl::OUString aCoreWorkaroundType( RTL_CONSTASCII_USTRINGPARAM( "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" ) ); +void SAL_CALL DocumentPropertiesImport::importProperties( + const Reference< XStorage >& rxSource, const Reference< XDocumentProperties >& rxDocumentProperties ) + throw (RuntimeException, IllegalArgumentException, SAXException, Exception) +{ + if( !mxContext.is() ) + throw RuntimeException(); - ::rtl::OUString aExtType( RTL_CONSTASCII_USTRINGPARAM( "http://schemas.openxmlformats.org/officedocument/2006/relationships/extended-properties" ) ); - ::rtl::OUString aCustomType( RTL_CONSTASCII_USTRINGPARAM( "http://schemas.openxmlformats.org/officedocument/2006/relationships/custom-properties" ) ); + if( !rxSource.is() || !rxDocumentProperties.is() ) + throw IllegalArgumentException(); - uno::Sequence< xml::sax::InputSource > aCoreStreams = GetRelatedStreams( xSource, aCoreType ); - if ( !aCoreStreams.getLength() ) - aCoreStreams = GetRelatedStreams( xSource, aCoreWorkaroundType ); + Sequence< InputSource > aCoreStreams = lclGetRelatedStreams( rxSource, CREATE_OFFICEDOC_RELATION_TYPE( "metadata/core-properties" ) ); + // MS Office seems to have a bug, so we have to do similar handling + if( !aCoreStreams.hasElements() ) + aCoreStreams = lclGetRelatedStreams( rxSource, CREATE_PACKAGE_RELATION_TYPE( "metadata/core-properties" ) ); - uno::Sequence< xml::sax::InputSource > aExtStreams = GetRelatedStreams( xSource, aExtType ); - uno::Sequence< xml::sax::InputSource > aCustomStreams = GetRelatedStreams( xSource, aCustomType ); + Sequence< InputSource > aExtStreams = lclGetRelatedStreams( rxSource, CREATE_OFFICEDOC_RELATION_TYPE( "extended-properties" ) ); + Sequence< InputSource > aCustomStreams = lclGetRelatedStreams( rxSource, CREATE_OFFICEDOC_RELATION_TYPE( "custom-properties" ) ); - if ( aCoreStreams.getLength() || aExtStreams.getLength() || aCustomStreams.getLength() ) + if( aCoreStreams.hasElements() || aExtStreams.hasElements() || aCustomStreams.hasElements() ) { - if ( aCoreStreams.getLength() > 1 ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected core properties stream!" ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< lang::XMultiComponentFactory > xFactory( m_xContext->getServiceManager(), uno::UNO_QUERY_THROW ); - - uno::Reference< xml::sax::XFastParser > xParser( - xFactory->createInstanceWithContext( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.FastParser" ) ), - m_xContext ), - uno::UNO_QUERY_THROW ); - - uno::Reference< xml::sax::XFastTokenHandler > xTokenHandler( - xFactory->createInstanceWithContext( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.oox.FastTokenHandlerService" ) ), - m_xContext ), - uno::UNO_QUERY_THROW ); - - uno::Reference< xml::sax::XFastDocumentHandler > xDocHandler( static_cast< xml::sax::XFastDocumentHandler* >( new OOXMLDocPropHandler( m_xContext, xDocumentProperties ) ) ); - - xParser->setFastDocumentHandler( xDocHandler ); - xParser->setTokenHandler( xTokenHandler ); - - xParser->registerNamespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "http://schemas.openxmlformats.org/package/2006/metadata/core-properties" ) ), NMSP_COREPR ); - xParser->registerNamespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "http://purl.org/dc/elements/1.1/" ) ), NMSP_DC ); - xParser->registerNamespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "http://purl.org/dc/terms/" ) ), NMSP_DCTERMS ); - xParser->registerNamespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" ) ), NMSP_EXTPR ); - xParser->registerNamespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" ) ), NMSP_CUSTPR ); - xParser->registerNamespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes" ) ), NMSP_VT ); - - // #158414# XFastParser::parseStream() throws on invalid XML - if ( aCoreStreams.getLength() ) try - { - if ( aCoreStreams[0].aInputStream.is() ) - { - xParser->parseStream( aCoreStreams[0] ); - aCoreStreams[0].aInputStream->closeInput(); - } - } - catch( uno::Exception& ) - { - } - - sal_Int32 nInd = 0; - for ( nInd = 0; nInd < aExtStreams.getLength(); nInd++ ) - { - xParser->parseStream( aExtStreams[nInd] ); - if ( aExtStreams[nInd].aInputStream.is() ) - aExtStreams[nInd].aInputStream->closeInput(); - } - - for ( nInd = 0; nInd < aCustomStreams.getLength(); nInd++ ) - { - xParser->parseStream( aCustomStreams[nInd] ); - if ( aCustomStreams[nInd].aInputStream.is() ) - aCustomStreams[nInd].aInputStream->closeInput(); - } + if( aCoreStreams.getLength() > 1 ) + throw IOException( CREATE_OUSTRING( "Unexpected core properties stream!" ), Reference< XInterface >() ); + + ::oox::core::FastParser aParser( mxContext ); + aParser.registerNamespace( NMSP_packageMetaCorePr ); + aParser.registerNamespace( NMSP_dc ); + aParser.registerNamespace( NMSP_dcTerms ); + aParser.registerNamespace( NMSP_officeExtPr ); + aParser.registerNamespace( NMSP_officeCustomPr ); + aParser.registerNamespace( NMSP_officeDocPropsVT ); + aParser.setDocumentHandler( new OOXMLDocPropHandler( mxContext, rxDocumentProperties ) ); + + if( aCoreStreams.hasElements() ) + aParser.parseStream( aCoreStreams[ 0 ], true ); + for( sal_Int32 nIndex = 0; nIndex < aExtStreams.getLength(); ++nIndex ) + aParser.parseStream( aExtStreams[ nIndex ], true ); + for( sal_Int32 nIndex = 0; nIndex < aCustomStreams.getLength(); ++nIndex ) + aParser.parseStream( aCustomStreams[ nIndex ], true ); } } +// ============================================================================ + } // namespace docprop } // namespace oox - - diff --git a/oox/source/docprop/ooxmldocpropimport.hxx b/oox/source/docprop/ooxmldocpropimport.hxx index a10eafbe1eb4..79f4d1f7e60b 100644 --- a/oox/source/docprop/ooxmldocpropimport.hxx +++ b/oox/source/docprop/ooxmldocpropimport.hxx @@ -28,44 +28,44 @@ #ifndef OOX_DOCPROP_OOXMLDOCPROPIMPORT_HXX #define OOX_DOCPROP_OOXMLDOCPROPIMPORT_HXX -#include <sal/config.h> -#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/document/XOOXMLDocumentPropertiesImporter.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/xml/sax/InputSource.hpp> -#include <com/sun/star/document/XOOXMLDocumentPropertiesImporter.hpp> +#include <cppuhelper/implbase2.hxx> namespace oox { namespace docprop { -class OOXMLDocPropImportImpl: +// ============================================================================ + +class DocumentPropertiesImport : public ::cppu::WeakImplHelper2< ::com::sun::star::lang::XServiceInfo, - ::com::sun::star::document::XOOXMLDocumentPropertiesImporter> + ::com::sun::star::document::XOOXMLDocumentPropertiesImporter > { -private: - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; - - OOXMLDocPropImportImpl(const OOXMLDocPropImportImpl &); // not defined - OOXMLDocPropImportImpl& operator=(const OOXMLDocPropImportImpl &); // not defined - public: - explicit OOXMLDocPropImportImpl(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context); - virtual ~OOXMLDocPropImportImpl() {} - - ::com::sun::star::uno::Sequence< ::com::sun::star::xml::sax::InputSource > GetRelatedStreams( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > xStorage, const ::rtl::OUString& aStreamType ); + explicit DocumentPropertiesImport( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ); - // ::com::sun::star::lang::XServiceInfo: + // XServiceInfo virtual ::rtl::OUString SAL_CALL getImplementationName() throw (::com::sun::star::uno::RuntimeException); - virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString & ServiceName) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& rServiceName ) throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException); - // ::com::sun::star::document::XOOXMLDocumentPropertiesImporter: - virtual void SAL_CALL importProperties(const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > & xSource, const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > & xDocumentProperties) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::Exception); + // XOOXMLDocumentPropertiesImporter + virtual void SAL_CALL importProperties( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxSource, + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties >& rxDocumentProperties ) + throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::Exception); +private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext; }; +// ============================================================================ + } // namespace docprop } // namespace oox #endif - |