23#include <com/sun/star/embed/ElementModes.hpp>
24#include <com/sun/star/embed/XHierarchicalStorageAccess.hpp>
25#include <com/sun/star/embed/XRelationshipAccess.hpp>
26#include <com/sun/star/embed/XStorage.hpp>
27#include <com/sun/star/io/IOException.hpp>
28#include <com/sun/star/lang/IllegalArgumentException.hpp>
29#include <com/sun/star/xml/sax/InputSource.hpp>
53Sequence< InputSource > lclGetRelatedStreams(
const Reference< XStorage >& rxStorage,
const OUString& rStreamType )
55 Reference< XRelationshipAccess > xRelation( rxStorage, UNO_QUERY_THROW );
56 Reference< XHierarchicalStorageAccess > xHierarchy( rxStorage, UNO_QUERY_THROW );
58 const Sequence< Sequence< StringPair > > aPropsInfo = xRelation->getRelationshipsByType( rStreamType );
60 ::std::vector< InputSource > aResult;
62 for(
const Sequence< StringPair >& rEntries : aPropsInfo )
64 auto pEntry = std::find_if(rEntries.begin(), rEntries.end(),
65 [](
const StringPair& rEntry) { return rEntry.First ==
"Target"; });
66 if (pEntry != rEntries.end())
69 OUString aStreamPath = pEntry->Second;
70 if (aStreamPath.startsWith(
"/"))
71 aStreamPath = aStreamPath.copy(1);
73 Reference< XExtendedStorageStream > xExtStream(
74 xHierarchy->openStreamElementByHierarchicalName( aStreamPath, ElementModes::READ ), UNO_SET_THROW );
75 Reference< XInputStream > xInStream = xExtStream->getInputStream();
78 aResult.emplace_back();
79 aResult.back().sSystemId = pEntry->Second;
80 aResult.back().aInputStream = xExtStream->getInputStream();
88Sequence< InputSource > lclGetCoreStreams(
const Reference< XStorage >& rxSource)
92 if (!aCoreStreams.hasElements())
95 if (!aCoreStreams.hasElements())
96 aCoreStreams = lclGetRelatedStreams(rxSource,
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties");
101Sequence< InputSource > lclGetExtStreams(
const Reference< XStorage >& rxSource)
105 if (!aExtStreams.hasElements())
111Sequence< InputSource > lclGetCustomStreams(
const Reference< XStorage >& rxSource)
115 if (!aCustomStreams.hasElements())
118 return aCustomStreams;
132 return "com.sun.star.comp.oox.docprop.DocumentPropertiesImporter";
142 Sequence<OUString> aServices {
"com.sun.star.document.OOXMLDocumentPropertiesImporter" };
148 const Reference< XStorage >& rxSource,
const Reference< XDocumentProperties >& rxDocumentProperties )
153 if( !rxSource.is() || !rxDocumentProperties.is() )
154 throw IllegalArgumentException();
156 Sequence< InputSource > aCoreStreams = lclGetCoreStreams(rxSource);
158 Sequence< InputSource > aExtStreams = lclGetExtStreams(rxSource);
160 Sequence< InputSource > aCustomStreams = lclGetCustomStreams(rxSource);
162 if( !(aCoreStreams.hasElements() || aExtStreams.hasElements() || aCustomStreams.hasElements()) )
165 if( aCoreStreams.getLength() > 1 )
166 throw IOException(
"Unexpected core properties stream!" );
177 if( aCoreStreams.hasElements() )
179 for(
const auto& rExtStream : std::as_const(aExtStreams) )
181 for(
const auto& rCustomStream : std::as_const(aCustomStreams) )
186 const Reference< XStorage >& rxSource)
188 Sequence< InputSource > aCoreStreams = lclGetCoreStreams(rxSource);
189 if (!aCoreStreams.hasElements())
192 return aCoreStreams[0].aInputStream;
196 const Reference< XStorage >& rxSource)
198 Sequence< InputSource > aExtStreams = lclGetExtStreams(rxSource);
199 if (!aExtStreams.hasElements())
202 return aExtStreams[0].aInputStream;
206 const Reference< XStorage >& rxSource)
208 Sequence <InputSource> aExtStreams = lclGetCustomStreams(rxSource);
211 std::vector<Reference<XInputStream>> aResult(aExtStreams.getLength());
212 for (
const auto& aInputSource : aExtStreams)
214 aResult.push_back(aInputSource.aInputStream);
222extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
224 uno::XComponentContext* pCtx, uno::Sequence<uno::Any>
const& )
Wrapper for a fast SAX parser that works on automatically generated OOXML token and namespace identif...
void parseStream(const css::xml::sax::InputSource &rInputSource, bool bCloseStream=false)
Parses the passed SAX input source.
void registerNamespace(sal_Int32 nNamespaceId)
Registers an OOXML namespace at the parser.
void setDocumentHandler(const css::uno::Reference< css::xml::sax::XFastDocumentHandler > &rxDocHandler)
Sets the passed document handler that will receive the SAX parser events.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL getCorePropertiesStream(const css::uno::Reference< css::embed::XStorage > &rxSource) override
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
DocumentPropertiesImport(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual css::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL getExtendedPropertiesStream(const css::uno::Reference< css::embed::XStorage > &rxSource) override
virtual void SAL_CALL importProperties(const css::uno::Reference< css::embed::XStorage > &rxSource, const css::uno::Reference< css::document::XDocumentProperties > &rxDocumentProperties) override
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< css::uno::Reference< com::sun::star::io::XInputStream > > SAL_CALL getCustomPropertiesStreams(const css::uno::Reference< css::embed::XStorage > &rxSource) override
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_oox_docprop_DocumentPropertiesImporter_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
#define CREATE_OFFICEDOC_RELATION_TYPE(ascii)
Expands to an OUString containing an 'officeDocument' transitional relation type created from the pas...
#define CREATE_OFFICEDOC_RELATION_TYPE_STRICT(ascii)
Expands to an OUString containing an 'officeDocument' strict relation type created from the passed li...