summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2021-11-24 14:50:12 +0300
committerThorsten Behrens <thorsten.behrens@allotropia.de>2021-12-21 23:23:51 +0100
commita4432eb0946c0bc775b3d30b634bef5d66544f8d (patch)
tree67b339d47ba727f55b989322091f20804d9c6c09 /oox
parentc3d3eb7bdcb07824af7d205112f36201634aee59 (diff)
tdf#104823: support for sdt plain text fields
This is a squashed commit containing set of changes: * Create a input field from sdt text block. * Advanced support for reading field data from data bindings which can point to custom xml or properties xml. For this XOOXMLDocumentPropertiesImporter idl interface was extrended with extra getterrs to get properties as xml dom elements. * Support for exporting of this feature back to docx. For this some extra parameters for sdt block are kept in newly introduced grabbag for input fields. If field does not contain grabbag it being exported as before (FILLIN or whatsoever), otherwise sdt block is counstructed based on data from grabbag. * Basic support for updating custom xml values back into custom xmls with usage of xslt transformations. To achieve this extra parameters were introduced to XXSLTTransformer: now it is able to support in-memory transformation stylesheets. Some unittests were corrected: since sdt plain text edit area is a field located inside paragraph in outout corresponding sdt is also located inside paragraph (instead of Word's approach with paragraph inside sdt). Seems this is not critical. Change-Id: I1a73ef300db3619804f7adf18579bea708764c14 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127015 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127127
Diffstat (limited to 'oox')
-rw-r--r--oox/source/docprop/ooxmldocpropimport.cxx88
-rw-r--r--oox/source/docprop/ooxmldocpropimport.hxx6
2 files changed, 79 insertions, 15 deletions
diff --git a/oox/source/docprop/ooxmldocpropimport.cxx b/oox/source/docprop/ooxmldocpropimport.cxx
index 4de14e0fca9f..30c058e209a4 100644
--- a/oox/source/docprop/ooxmldocpropimport.cxx
+++ b/oox/source/docprop/ooxmldocpropimport.cxx
@@ -86,6 +86,40 @@ Sequence< InputSource > lclGetRelatedStreams( const Reference< XStorage >& rxSto
return comphelper::containerToSequence( aResult );
}
+Sequence< InputSource > lclGetCoreStreams(const Reference< XStorage >& rxSource)
+{
+ Sequence< InputSource > aCoreStreams = lclGetRelatedStreams(rxSource, CREATE_OFFICEDOC_RELATION_TYPE("metadata/core-properties"));
+ // OOXML strict
+ if (!aCoreStreams.hasElements())
+ aCoreStreams = lclGetRelatedStreams(rxSource, CREATE_OFFICEDOC_RELATION_TYPE_STRICT("metadata/core-properties"));
+ // MS Office seems to have a bug, so we have to do similar handling
+ if (!aCoreStreams.hasElements())
+ aCoreStreams = lclGetRelatedStreams(rxSource, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties");
+
+ return aCoreStreams;
+}
+
+Sequence< InputSource > lclGetExtStreams(const Reference< XStorage >& rxSource)
+{
+ Sequence< InputSource > aExtStreams = lclGetRelatedStreams(rxSource, CREATE_OFFICEDOC_RELATION_TYPE("extended-properties"));
+ // OOXML strict
+ if (!aExtStreams.hasElements())
+ aExtStreams = lclGetRelatedStreams(rxSource, CREATE_OFFICEDOC_RELATION_TYPE_STRICT("extended-properties"));
+
+ return aExtStreams;
+}
+
+Sequence< InputSource > lclGetCustomStreams(const Reference< XStorage >& rxSource)
+{
+ Sequence< InputSource > aCustomStreams = lclGetRelatedStreams(rxSource, CREATE_OFFICEDOC_RELATION_TYPE("custom-properties"));
+ // OOXML strict
+ if (!aCustomStreams.hasElements())
+ aCustomStreams = lclGetRelatedStreams(rxSource, CREATE_OFFICEDOC_RELATION_TYPE_STRICT("custom-properties"));
+
+ return aCustomStreams;
+}
+
+
} // namespace
DocumentPropertiesImport::DocumentPropertiesImport( const Reference< XComponentContext >& rxContext ) :
@@ -120,22 +154,11 @@ void SAL_CALL DocumentPropertiesImport::importProperties(
if( !rxSource.is() || !rxDocumentProperties.is() )
throw IllegalArgumentException();
- Sequence< InputSource > aCoreStreams = lclGetRelatedStreams( rxSource, CREATE_OFFICEDOC_RELATION_TYPE( "metadata/core-properties" ) );
- // OOXML strict
- if( !aCoreStreams.hasElements() )
- aCoreStreams = lclGetRelatedStreams( rxSource, CREATE_OFFICEDOC_RELATION_TYPE_STRICT( "metadata/core-properties" ) );
- // MS Office seems to have a bug, so we have to do similar handling
- if( !aCoreStreams.hasElements() )
- aCoreStreams = lclGetRelatedStreams( rxSource, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" );
+ Sequence< InputSource > aCoreStreams = lclGetCoreStreams(rxSource);
- Sequence< InputSource > aExtStreams = lclGetRelatedStreams( rxSource, CREATE_OFFICEDOC_RELATION_TYPE( "extended-properties" ) );
- // OOXML strict
- if( !aExtStreams.hasElements() )
- aExtStreams = lclGetRelatedStreams( rxSource, CREATE_OFFICEDOC_RELATION_TYPE_STRICT( "extended-properties" ) );
- Sequence< InputSource > aCustomStreams = lclGetRelatedStreams( rxSource, CREATE_OFFICEDOC_RELATION_TYPE( "custom-properties" ) );
- // OOXML strict
- if( !aCustomStreams.hasElements() )
- aCustomStreams = lclGetRelatedStreams( rxSource, CREATE_OFFICEDOC_RELATION_TYPE_STRICT( "custom-properties" ) );
+ Sequence< InputSource > aExtStreams = lclGetExtStreams(rxSource);
+
+ Sequence< InputSource > aCustomStreams = lclGetCustomStreams(rxSource);
if( !(aCoreStreams.hasElements() || aExtStreams.hasElements() || aCustomStreams.hasElements()) )
return;
@@ -160,6 +183,41 @@ void SAL_CALL DocumentPropertiesImport::importProperties(
aParser.parseStream( rCustomStream, true );
}
+Reference < com::sun::star::io::XInputStream > SAL_CALL DocumentPropertiesImport::getCorePropertiesStream(
+ const Reference< XStorage >& rxSource)
+{
+ Sequence< InputSource > aCoreStreams = lclGetCoreStreams(rxSource);
+ if (!aCoreStreams.hasElements())
+ return nullptr;
+
+ return aCoreStreams[0].aInputStream;
+}
+
+Reference < com::sun::star::io::XInputStream > SAL_CALL DocumentPropertiesImport::getExtendedPropertiesStream(
+ const Reference< XStorage >& rxSource)
+{
+ Sequence< InputSource > aExtStreams = lclGetExtStreams(rxSource);
+ if (!aExtStreams.hasElements())
+ return nullptr;
+
+ return aExtStreams[0].aInputStream;
+}
+
+css::uno::Sequence< css::uno::Reference< com::sun::star::io::XInputStream > > SAL_CALL DocumentPropertiesImport::getCustomPropertiesStreams(
+ const Reference< XStorage >& rxSource)
+{
+ Sequence <InputSource> aExtStreams = lclGetCustomStreams(rxSource);
+
+ // Repack the sequence
+ std::vector<Reference<XInputStream>> aResult(aExtStreams.getLength());
+ for (const auto& aInputSource : aExtStreams)
+ {
+ aResult.push_back(aInputSource.aInputStream);
+ }
+
+ return comphelper::containerToSequence(aResult);
+}
+
} // namespace oox::docprop
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
diff --git a/oox/source/docprop/ooxmldocpropimport.hxx b/oox/source/docprop/ooxmldocpropimport.hxx
index f76d4feb7b46..ba406bae9aed 100644
--- a/oox/source/docprop/ooxmldocpropimport.hxx
+++ b/oox/source/docprop/ooxmldocpropimport.hxx
@@ -45,6 +45,12 @@ public:
virtual void SAL_CALL importProperties(
const css::uno::Reference< css::embed::XStorage >& rxSource,
const css::uno::Reference< css::document::XDocumentProperties >& rxDocumentProperties ) override;
+ virtual css::uno::Reference < com::sun::star::io::XInputStream > SAL_CALL getCorePropertiesStream(
+ const css::uno::Reference< css::embed::XStorage >& rxSource) override;
+ virtual css::uno::Reference < com::sun::star::io::XInputStream > SAL_CALL getExtendedPropertiesStream(
+ const css::uno::Reference< css::embed::XStorage >& rxSource) 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;
private:
css::uno::Reference< css::uno::XComponentContext > mxContext;