25#include <com/sun/star/beans/XPropertyAccess.hpp>
26#include <com/sun/star/beans/XPropertySet.hpp>
27#include <com/sun/star/beans/Pair.hpp>
28#include <com/sun/star/embed/XRelationshipAccess.hpp>
29#include <com/sun/star/frame/XModel.hpp>
30#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
31#include <com/sun/star/xml/sax/XSAXSerializable.hpp>
32#include <com/sun/star/xml/sax/Writer.hpp>
37#include <rtl/strbuf.hxx>
38#include <rtl/ustrbuf.hxx>
39#include <osl/diagnose.h>
49#include <oox/token/namespaces.hxx>
51#include <oox/token/properties.hxx>
52#include <oox/token/tokens.hxx>
53#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
54#include <com/sun/star/document/XOOXMLDocumentPropertiesImporter.hpp>
55#include <com/sun/star/xml/dom/DocumentBuilder.hpp>
65#include <com/sun/star/util/Date.hpp>
66#include <com/sun/star/util/Duration.hpp>
72using ::com::sun::star::xml::dom::DocumentBuilder;
73using ::com::sun::star::xml::dom::XDocument;
74using ::com::sun::star::xml::dom::XDocumentBuilder;
89using ::sax_fastparser::FSHelperPtr;
90using ::sax_fastparser::FastSerializerHelper;
94const Sequence< beans::Pair< OUString, sal_Int32 > >& NamespaceIds()
96 static const Sequence< beans::Pair< OUString, sal_Int32 > > SINGLETON
98 {
"http://www.w3.org/XML/1998/namespace", NMSP_xml},
99 {
"http://schemas.openxmlformats.org/package/2006/relationships",
101 {
"http://schemas.openxmlformats.org/officeDocument/2006/relationships",
103 {
"http://purl.oclc.org/ooxml/officeDocument/relationships",
105 {
"http://schemas.openxmlformats.org/drawingml/2006/main", NMSP_dml},
106 {
"http://purl.oclc.org/ooxml/drawingml/main", NMSP_dml},
107 {
"http://schemas.openxmlformats.org/drawingml/2006/diagram",
109 {
"http://purl.oclc.org/ooxml/drawingml/diagram", NMSP_dmlDiagram},
110 {
"http://schemas.openxmlformats.org/drawingml/2006/chart",
112 {
"http://schemas.openxmlformats.org/drawingml/2006/chartDrawing",
114 {
"urn:schemas-microsoft-com:vml", NMSP_vml},
115 {
"urn:schemas-microsoft-com:office:office", NMSP_vmlOffice},
116 {
"urn:schemas-microsoft-com:office:word", NMSP_vmlWord},
117 {
"urn:schemas-microsoft-com:office:excel", NMSP_vmlExcel},
118 {
"urn:schemas-microsoft-com:office:powerpoint", NMSP_vmlPowerpoint},
119 {
"http://schemas.microsoft.com/office/2006/activeX", NMSP_ax},
120 {
"http://schemas.openxmlformats.org/spreadsheetml/2006/main",
122 {
"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",
124 {
"http://schemas.microsoft.com/office/excel/2006/main",
126 {
"http://schemas.openxmlformats.org/presentationml/2006/main",
128 {
"http://schemas.openxmlformats.org/markup-compatibility/2006",
130 {
"http://schemas.openxmlformats.org/spreadsheetml/2006/main/v2",
132 {
"http://schemas.openxmlformats.org/officeDocument/2006/math",
134 {
"http://schemas.microsoft.com/office/drawing/2008/diagram",
136 {
"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",
138 {
"http://schemas.libreoffice.org/", NMSP_loext},
139 {
"http://schemas.microsoft.com/office/drawing/2010/main",
141 {
"http://schemas.microsoft.com/office/powerpoint/2010/main",
143 {
"http://schemas.microsoft.com/office/powerpoint/2012/main",
145 {
"http://schemas.microsoft.com/office/spreadsheetml/2011/1/ac",
147 {
"http://schemas.microsoft.com/office/drawing/2012/chart",
149 {
"http://schemas.microsoft.com/office/spreadsheetml/2015/revision2",
151 {
"http://schemas.microsoft.com/office/drawing/2017/decorative", NMSP_adec},
156void registerNamespaces( FastParser& rParser )
158 const Sequence< beans::Pair<OUString, sal_Int32> >& ids = NamespaceIds();
164 for (
const auto& rId : ids)
167 for (
auto const& elem : aSet)
168 rParser.registerNamespace(elem);
202 mbMissingExtDrawing(false)
215 mxImpl->maFastParser.clearDocumentHandler();
221 return std::shared_ptr<::oox::drawingml::Theme>();
227 if (!xDocProps->getGenerator().startsWithIgnoreAsciiCase(
"Microsoft"))
231 uno::Reference<beans::XPropertyAccess> xUserDefProps(xDocProps->getUserDefinedProperties(), uno::UNO_QUERY);
232 if (!xUserDefProps.is())
237 if (it == aUserDefinedProperties.
end())
241 if (!(it->second >>= aValue))
244 if (!aValue.startsWithIgnoreAsciiCase(
"12."))
247 SAL_INFO(
"oox",
"a MSO 2007 document");
256 uno::Reference<beans::XPropertySet> xDocProps(xDstDoc, uno::UNO_QUERY);
259 uno::Reference<beans::XPropertySetInfo> xPropsInfo = xDocProps->getPropertySetInfo();
261 static constexpr OUStringLiteral aGrabBagPropName =
u"InteropGrabBag";
262 if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(aGrabBagPropName))
268 aGrabBag.
update(rProperties);
275 catch (
const uno::Exception&)
277 SAL_WARN(
"oox",
"Failed to save documents grab bag");
284 Reference< XInputStream > xInputStream;
287 xInputStream = xDetector->extractUnencryptedPackage( aMediaDesc );
289 Reference< XStorage > xDocumentStorage (
291 Reference< XInterface > xTemp = xContext->getServiceManager()->createInstanceWithContext(
292 "com.sun.star.document.OOXMLDocumentPropertiesImporter",
294 Reference< XOOXMLDocumentPropertiesImporter > xImporter( xTemp, UNO_QUERY );
295 Reference< XDocumentPropertiesSupplier > xPropSupplier(
xModel, UNO_QUERY);
296 Reference< XDocumentProperties > xDocProps = xPropSupplier->getDocumentProperties();
297 xImporter->importProperties( xDocumentStorage, xDocProps );
306 registerNamespaces(*pParser);
312OUString getTransitionalRelationshipOfficeDocType(std::u16string_view rPart)
314 return OUString::Concat(
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/")
318OUString getStrictRelationshipOfficeDocType(std::u16string_view rPart)
320 return OUString::Concat(
"http://purl.oclc.org/ooxml/officeDocument/relationships/") + rPart;
328 const OUString aTransitionalRelationshipType = getTransitionalRelationshipOfficeDocType(rPart);
329 OUString aFragment =
importRelations( OUString() )->getFragmentPathFromFirstType( aTransitionalRelationshipType );
330 if(aFragment.isEmpty())
332 const OUString aStrictRelationshipType = getStrictRelationshipOfficeDocType(rPart);
333 aFragment =
importRelations( OUString() )->getFragmentPathFromFirstType( aStrictRelationshipType );
342 registerNamespaces(aParser);
348 OSL_ENSURE( rxHandler.is(),
"XmlFilterBase::importFragment - missing fragment handler" );
349 if( !rxHandler.is() )
353 OUString aFragmentPath = rxHandler->getFragmentPath();
354 OSL_ENSURE( !aFragmentPath.isEmpty(),
"XmlFilterBase::importFragment - missing fragment path" );
355 if( aFragmentPath.isEmpty() )
364 Reference< XInputStream > xInStrm(
openInputStream( aFragmentPath ), UNO_SET_THROW );
372 aSource.
mxInStream = std::make_shared<BinaryXInputStream>( xInStrm,
true );
384 if( !rxHandler.is() )
394 Reference< XInputStream > xInStrm = rxHandler->openFragmentStream();
399 sal_Int32 nPathLen = aFragmentPath.lastIndexOf(
'/') + 1;
400 OUString fileName = aFragmentPath.copy(nPathLen);
401 OUString sLowerCaseFileName = fileName.toAsciiLowerCase();
402 if ( fileName != sLowerCaseFileName )
404 aFragmentPath = aFragmentPath.subView(0, nPathLen) + sLowerCaseFileName;
410 if( xInStrm.is() )
try
418 OSL_FAIL( OStringBuffer(
"XmlFilterBase::importFragment - XML parser failed in fragment '" +
419 OUStringToOString( aFragmentPath, RTL_TEXTENCODING_ASCII_US ) +
"'" ).getStr() );
430 Reference<XDocument> xRet;
433 OSL_ENSURE( !aFragmentPath.isEmpty(),
"XmlFilterBase::importFragment - empty fragment path" );
434 if( aFragmentPath.isEmpty() )
450 Reference<XDocumentBuilder> xDomBuilder( DocumentBuilder::create(
getComponentContext() ) );
453 xRet = xDomBuilder->parse(xInStrm);
463 const Reference< XFastSAXSerializable >& rxSerializer )
465 if( !rxHandler.is() )
471 rxSerializer->fastSerialize( rxHandler,
472 mxImpl->maFastParser.getTokenHandler(),
473 Sequence< StringPair >(),
490 rxRelations = std::make_shared<Relations>( rFragmentPath );
500 aPropSet.
setProperty( PROP_MediaType, rMediaType );
501 return xOutputStream;
506 const bool bWriteHeader = rMediaType.indexOf(
"vml" ) < 0 || rMediaType.indexOf(
"+xml" ) >= 0;
507 return std::make_shared<FastSerializerHelper>(
openFragmentStream( rStreamName, rMediaType ), bWriteHeader );
512OUString lclAddRelation(
const Reference< XRelationshipAccess >& rRelations, sal_Int32
nId,
const OUString& rType, std::u16string_view rTarget,
bool bExternal )
514 OUString
sId =
"rId" + OUString::number(
nId );
516 Sequence< StringPair > aEntry( bExternal ? 3 : 2 );
517 auto pEntry = aEntry.getArray();
518 pEntry[0].First =
"Type";
519 pEntry[0].Second = rType;
520 pEntry[1].First =
"Target";
524 pEntry[2].First =
"TargetMode";
525 pEntry[2].Second =
"External";
527 rRelations->insertRelationshipByID( sId, aEntry,
true );
536 Reference< XRelationshipAccess > xRelations(
getStorage()->getXStorage(), UNO_QUERY );
537 if( xRelations.is() )
538 return lclAddRelation( xRelations,
mnRelId ++, rType,
rTarget,
false );
543OUString
XmlFilterBase::addRelation(
const Reference< XOutputStream >& rOutputStream,
const OUString& rType, std::u16string_view rTarget,
bool bExternal )
549 aPropSet.getProperty(
nId, PROP_RelId );
553 Reference< XRelationshipAccess > xRelations( rOutputStream, UNO_QUERY );
554 if( xRelations.is() )
555 return lclAddRelation( xRelations,
nId, rType, rTarget, bExternal );
563 pDoc->startElement(nXmlElement);
564 pDoc->writeEscaped( sValue );
565 pDoc->endElement( nXmlElement );
571 pDoc->startElement(nXmlElement);
573 pDoc->endElement( nXmlElement );
579 if( rTime.Year == 0 )
582 if ( ( nXmlElement >> 16 ) != XML_dcterms )
583 pDoc->startElement(nXmlElement);
585 pDoc->startElement(nXmlElement,
FSNS(XML_xsi,
XML_type),
"dcterms:W3CDTF");
588 snprintf( pStr,
sizeof( pStr ),
"%d-%02d-%02dT%02d:%02d:%02dZ",
589 rTime.Year, rTime.Month, rTime.Day,
590 rTime.Hours, rTime.Minutes, rTime.Seconds );
594 pDoc->endElement( nXmlElement );
600 if( !aItems.hasElements() )
605 ::comphelper::intersperse(aItems.begin(), aItems.end(),
629 sValue =
"http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties";
632 sValue =
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
637 "application/vnd.openxmlformats-package.core-properties+xml" );
638 pCoreProps->startElementNS( XML_cp, XML_coreProperties,
645 uno::Reference<beans::XPropertyAccess> xUserDefinedProperties(xProperties->getUserDefinedProperties(), uno::UNO_QUERY);
649 it = aUserDefinedProperties.
find(
"OOXMLCorePropertyCategory");
650 if (it != aUserDefinedProperties.
end())
653 if (it->second >>= aValue)
657 it = aUserDefinedProperties.
find(
"OOXMLCorePropertyContentStatus");
658 if (it != aUserDefinedProperties.
end())
661 if (it->second >>= aValue)
665 it = aUserDefinedProperties.
find(
"OOXMLCorePropertyContentType");
666 if (it != aUserDefinedProperties.
end())
669 if (it->second >>= aValue)
672 writeElement( pCoreProps,
FSNS( XML_dcterms, XML_created ), xProperties->getCreationDate() );
673 writeElement( pCoreProps,
FSNS( XML_dc, XML_creator ), xProperties->getAuthor() );
674 writeElement( pCoreProps,
FSNS( XML_dc, XML_description ), xProperties->getDescription() );
676 it = aUserDefinedProperties.
find(
"OOXMLCorePropertyIdentifier");
677 if (it != aUserDefinedProperties.
end())
680 if (it->second >>= aValue)
683 writeElement( pCoreProps,
FSNS( XML_cp, XML_keywords ), xProperties->getKeywords() );
685 writeElement( pCoreProps,
FSNS( XML_cp, XML_lastModifiedBy ), xProperties->getModifiedBy() );
686 writeElement( pCoreProps,
FSNS( XML_cp, XML_lastPrinted ), xProperties->getPrintDate() );
687 writeElement( pCoreProps,
FSNS( XML_dcterms, XML_modified ), xProperties->getModificationDate() );
688 writeElement( pCoreProps,
FSNS( XML_cp, XML_revision ), xProperties->getEditingCycles() );
689 writeElement( pCoreProps,
FSNS( XML_dc, XML_subject ), xProperties->getSubject() );
690 writeElement( pCoreProps,
FSNS( XML_dc, XML_title ), xProperties->getTitle() );
692 it = aUserDefinedProperties.
find(
"OOXMLCorePropertyVersion");
693 if (it != aUserDefinedProperties.
end())
696 if (it->second >>= aValue)
700 pCoreProps->endElementNS( XML_cp, XML_coreProperties );
702 pCoreProps->endDocument();
709 "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties",
710 u"docProps/app.xml" );
713 "application/vnd.openxmlformats-officedocument.extended-properties+xml" );
714 pAppProps->startElement( XML_Properties,
718 uno::Reference<beans::XPropertyAccess> xUserDefinedProperties(xProperties->getUserDefinedProperties(), uno::UNO_QUERY);
722 writeElement( pAppProps, XML_Template, xProperties->getTemplateName() );
724 it = aUserDefinedProperties.
find(
"Manager");
725 if (it != aUserDefinedProperties.
end())
728 if (it->second >>= aValue)
733 writeElement( pAppProps, XML_PresentationFormat,
"presentation format" );
739 writeElement( pAppProps, XML_TotalTime, xProperties->getEditingDuration() / 60 );
741 writeElement( pAppProps, XML_HiddenSlides,
"hidden slides" );
744 writeElement( pAppProps, XML_HeadingPairs,
"heading pairs" );
745 writeElement( pAppProps, XML_TitlesOfParts,
"titles of parts" );
746 writeElement( pAppProps, XML_LinksUpToDate,
"links up-to-date" );
749 writeElement( pAppProps, XML_HyperlinksChanged,
"hyperlinks changed" );
750 writeElement( pAppProps, XML_DigSig,
"digital signature" );
754 it = aUserDefinedProperties.
find(
"HyperlinkBase");
755 if (it != aUserDefinedProperties.
end())
758 if (it->second >>= aValue)
770 it = aUserDefinedProperties.
find(
"DocSecurity");
771 if (it != aUserDefinedProperties.
end())
774 if (it->second >>=
nValue)
781 it = aStats.
find(
"PageCount");
782 if (it != aStats.
end())
784 if (it->second >>=
nValue)
788 it = aStats.
find(
"WordCount");
789 if (it != aStats.
end())
791 if (it->second >>=
nValue)
795 it = aStats.
find(
"NonWhitespaceCharacterCount");
796 if (it != aStats.
end())
798 if (it->second >>=
nValue)
802 it = aStats.
find(
"CharacterCount");
803 if (it != aStats.
end())
805 if (it->second >>=
nValue)
809 it = aStats.
find(
"ParagraphCount");
810 if (it != aStats.
end())
812 if (it->second >>=
nValue)
816 it = aUserDefinedProperties.
find(
"Company");
817 if (it != aUserDefinedProperties.
end())
820 if (it->second >>= aValue)
824 pAppProps->endElement( XML_Properties );
826 pAppProps->endDocument();
832 uno::Reference<beans::XPropertyAccess> xUserDefinedProperties( xProperties->getUserDefinedProperties(), uno::UNO_QUERY );
833 auto aprop = comphelper::sequenceToContainer< std::vector<beans::PropertyValue> >(xUserDefinedProperties->getPropertyValues());
834 sal_Int32 nbCustomProperties = aprop.size();
838 if (!nbCustomProperties && !bSecurityOptOpenReadOnly)
841 if (bSecurityOptOpenReadOnly)
843 PropertyValue aPropertyValue;
845 aPropertyValue.Name =
"_MarkAsFinal";
846 aPropertyValue.Value <<=
true;
847 aprop.push_back(aPropertyValue);
851 "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties",
852 u"docProps/custom.xml" );
854 "docProps/custom.xml",
855 "application/vnd.openxmlformats-officedocument.custom-properties+xml" );
856 pAppProps->startElement( XML_Properties,
861 for (
const auto& rProp : aprop)
863 if ( !rProp.Name.isEmpty() )
866 if (( rProp.Name ==
"OOXMLCorePropertyCategory" ) ||
867 ( rProp.Name ==
"OOXMLCorePropertyContentStatus" ) ||
868 ( rProp.Name ==
"OOXMLCorePropertyContentType" ) ||
869 ( rProp.Name ==
"OOXMLCorePropertyIdentifier" ) ||
870 ( rProp.Name ==
"OOXMLCorePropertyVersion" ) ||
871 ( rProp.Name ==
"HyperlinkBase" ) ||
872 ( rProp.Name ==
"AppVersion" ) ||
873 ( rProp.Name ==
"DocSecurity" ) ||
874 ( rProp.Name ==
"Manager" ) ||
875 ( rProp.Name ==
"Company" ))
879 pAppProps->startElement( XML_property ,
880 XML_fmtid,
"{D5CDD505-2E9C-101B-9397-08002B2CF9AE}",
881 XML_pid, OString::number(
nIndex + 2),
882 XML_name, rProp.Name);
884 switch ( rProp.Value.getValueTypeClass() )
886 case TypeClass_STRING:
889 rProp.Value >>= aValue;
893 case TypeClass_BOOLEAN:
895 bool val = *o3tl::forceAccess<bool>(rProp.Value);
899 case TypeClass_DOUBLE:
902 if ( rProp.Value >>= num )
913 util::Duration aDuration;
914 util::DateTime aDateTime;
915 if ( rProp.Value >>= num )
920 else if ( rProp.Value >>= aDate )
922 aDateTime = util::DateTime( 0, 0 , 0, 0, aDate.Day, aDate.Month, aDate.Year,
true );
925 else if ( rProp.Value >>= aDuration )
929 OUString aDurationStr = buf.makeStringAndClear();
932 else if ( rProp.Value >>= aDateTime )
936 OSL_FAIL(
"XMLFilterBase::writeCustomProperties unsupported value type!" );
940 pAppProps->endElement( XML_property );
944 pAppProps->endElement( XML_Properties );
946 pAppProps->endDocument();
951 if( xProperties.is() )
967 return xDetector->extractUnencryptedPackage( rMediaDesc );
972 const Sequence< NamedValue > aMediaEncData = rMediaDescriptor.getUnpackedValueOrDefault(
974 Sequence< NamedValue >() );
976 if (aMediaEncData.getLength() == 0)
983 return Reference< XStream > (
984 xContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.comp.MemoryStream", xContext),
985 uno::UNO_QUERY_THROW );
993 const Sequence< NamedValue > aMediaEncData = rMediaDescriptor.getUnpackedValueOrDefault(
995 Sequence< NamedValue >() );
997 if (aMediaEncData.getLength())
1041 mxImpl->mpDiagramFontHeights = pDiagramFontHeights;
1048 auto itr =
mxImpl->mrNamespaceMap.maTransitionalNamespaceMap.find(nNSID);
1049 if (itr ==
mxImpl->mrNamespaceMap.maTransitionalNamespaceMap.end())
1051 SAL_WARN(
"oox",
"missing namespace in the namespace map for : " << nNSID);
1060 Reference<XRelationshipAccess> xRelations(xDocumentStorage, UNO_QUERY);
1061 if (!xRelations.is())
1064 const uno::Sequence<uno::Sequence<beans::StringPair>> aSeqs = xRelations->getAllRelationships();
1066 std::vector<StreamDataSequence> aCustomFragments;
1067 std::vector<OUString> aCustomFragmentTypes;
1068 std::vector<OUString> aCustomFragmentTargets;
1069 for (
const uno::Sequence<beans::StringPair>&
aSeq : aSeqs)
1073 for (
const beans::StringPair& aPair :
aSeq)
1075 if (aPair.First ==
"Target")
1076 sTarget = aPair.Second;
1077 else if (aPair.First ==
"Type")
1078 sType = aPair.Second;
1082 if (!
sType.match(
"http://schemas.openxmlformats.org")
1083 && !
sType.match(
"http://purl.oclc.org"))
1088 aCustomFragments.emplace_back(aDataSeq);
1089 aCustomFragmentTypes.emplace_back(
sType);
1090 aCustomFragmentTargets.emplace_back(sTarget);
1101 std::vector<uno::Reference<xml::dom::XDocument>> aCustomXmlDomList;
1102 std::vector<uno::Reference<xml::dom::XDocument>> aCustomXmlDomPropsList;
1105 for (
int i = 1; ; ++
i)
1107 Reference<XDocument> xCustDoc =
importFragment(
"customXml/item" + OUString::number(
i) +
".xml");
1108 Reference<XDocument> xCustDocProps =
importFragment(
"customXml/itemProps" + OUString::number(
i) +
".xml");
1109 if (xCustDoc && xCustDocProps)
1111 aCustomXmlDomList.emplace_back(xCustDoc);
1112 aCustomXmlDomPropsList.emplace_back(xCustDocProps);
1123 uno::Sequence<uno::Sequence<beans::StringPair>> aContentTypeInfo;
1124 uno::Reference<io::XInputStream> xInputStream =
openInputStream(
"[Content_Types].xml");
1125 if (xInputStream.is())
1128 aGrabBagProperties[
"OOXContentTypes"] <<= aContentTypeInfo;
1137 uno::Reference<beans::XPropertySet> xPropSet(
xModel, uno::UNO_QUERY_THROW);
1139 uno::Reference<beans::XPropertySetInfo> xPropSetInfo = xPropSet->getPropertySetInfo();
1143 uno::Sequence<uno::Reference<xml::dom::XDocument>> customXmlDomlist;
1144 uno::Sequence<uno::Reference<xml::dom::XDocument>> customXmlDomPropslist;
1145 uno::Sequence<StreamDataSequence> customFragments;
1146 uno::Sequence<OUString> customFragmentTypes;
1147 uno::Sequence<OUString> customFragmentTargets;
1148 uno::Sequence<uno::Sequence<beans::StringPair>> aContentTypes;
1150 uno::Sequence<beans::PropertyValue> propList;
1152 for (
const auto& rProp : std::as_const(propList))
1154 const OUString propName = rProp.Name;
1155 if (propName ==
"OOXCustomXml")
1157 rProp.Value >>= customXmlDomlist;
1159 else if (propName ==
"OOXCustomXmlProps")
1161 rProp.Value >>= customXmlDomPropslist;
1163 else if (propName ==
"OOXCustomFragments")
1165 rProp.Value >>= customFragments;
1167 else if (propName ==
"OOXCustomFragmentTypes")
1169 rProp.Value >>= customFragmentTypes;
1171 else if (propName ==
"OOXCustomFragmentTargets")
1173 rProp.Value >>= customFragmentTargets;
1175 else if (propName ==
"OOXContentTypes")
1177 rProp.Value >>= aContentTypes;
1182 for (sal_Int32 j = 0; j < customXmlDomlist.getLength(); j++)
1184 uno::Reference<xml::dom::XDocument> customXmlDom = customXmlDomlist[j];
1185 uno::Reference<xml::dom::XDocument> customXmlDomProps = customXmlDomPropslist[j];
1186 const OUString fragmentPath =
"customXml/item" + OUString::number(j+1) +
".xml";
1187 if (customXmlDom.is())
1191 uno::Reference<xml::sax::XSAXSerializable> serializer(customXmlDom, uno::UNO_QUERY);
1194 serializer->serialize(uno::Reference<xml::sax::XDocumentHandler>(writer, uno::UNO_QUERY_THROW),
1195 uno::Sequence<beans::StringPair>());
1198 if (customXmlDomProps.is())
1200 uno::Reference<xml::sax::XSAXSerializable> serializer(customXmlDomProps, uno::UNO_QUERY);
1202 writer->setOutputStream(
openFragmentStream(
"customXml/itemProps"+OUString::number(j+1)+
".xml",
1203 "application/vnd.openxmlformats-officedocument.customXmlProperties+xml"));
1204 serializer->serialize(uno::Reference<xml::sax::XDocumentHandler>(writer, uno::UNO_QUERY_THROW),
1205 uno::Sequence<beans::StringPair>());
1210 Concat2View(
"itemProps"+OUString::number(j+1)+
".xml"));
1215 for (sal_Int32 j = 0; j < customFragments.getLength(); j++)
1217 addRelation(customFragmentTypes[j], customFragmentTargets[j]);
1218 const OUString aFilename = customFragmentTargets[j];
1220 if (xOutStream.is())
1222 xOutStream->writeBytes(customFragments[j]);
1223 uno::Reference<XPropertySet> xProps(xOutStream, uno::UNO_QUERY);
1227 const OUString aContentType = (aType.getLength() ? aType : OUString(
"application/octet-stream"));
1228 xProps->setPropertyValue(
"MediaType",
uno::Any(aContentType));
static OUString decode(std::u16string_view rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
OUString getBcp47MS() const
static css::uno::Reference< css::embed::XStorage > GetStorageOfFormatFromInputStream(const OUString &aFormat, const css::uno::Reference< css::io::XInputStream > &xStream, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >(), bool bRepairStorage=false)
iterator find(const OUString &rKey)
SequenceAsHashMapBase::iterator iterator
css::uno::Sequence< css::beans::PropertyValue > getAsConstPropertyValueList() const
void update(const SequenceAsHashMap &rSource)
void reserve(size_type amount)
std::pair< const_iterator, bool > insert(Value &&x)
A wrapper for a UNO property set.
bool setProperty(sal_Int32 nPropId, const Type &rValue)
Puts the passed value into the property set.
void commit()
Commits the changes to the storage and all substorages.
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 setDocumentHandler(const css::uno::Reference< css::xml::sax::XFastDocumentHandler > &rxDocHandler)
Sets the passed document handler that will receive the SAX parser events.
bool importBinaryData(StreamDataSequence &orDataSeq, const OUString &rStreamName)
Imports the raw binary data from the specified stream.
utl::MediaDescriptor & getMediaDescriptor() const
Returns the media descriptor.
const css::uno::Reference< css::frame::XModel > & getModel() const
Returns the document model (always existing).
OoxmlVersion getVersion() const
void commitStorage() const
Commits changes to base storage (and substorages)
css::uno::Reference< css::io::XInputStream > openInputStream(const OUString &rStreamName) const
Opens and returns the specified input stream from the base storage.
virtual css::uno::Reference< css::io::XStream > implGetOutputStream(utl::MediaDescriptor &rMediaDesc) const
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
Returns the component context passed in the filter constructor (always existing).
css::uno::Reference< css::io::XStream > const & getMainDocumentStream() const
css::uno::Reference< css::io::XOutputStream > openOutputStream(const OUString &rStreamName) const
Opens and returns the specified output stream from the base storage.
StorageRef const & getStorage() const
Returns the base storage of the imported/exported file.
void setFragmentHandler(const ::rtl::Reference< FragmentHandler > &rxHandler)
void parseStream(const RecordInputSource &rInputSource)
virtual ~XmlFilterBase() override
void setDiagramFontHeights(NamedShapePairs *pDiagramFontHeights)
bool isMSODocument() const
RelationsRef importRelations(const OUString &rFragmentPath)
Imports the relations fragment associated with the specified fragment.
virtual css::uno::Reference< css::io::XStream > implGetOutputStream(utl::MediaDescriptor &rMediaDesc) const override
NamedShapePairs * getDiagramFontHeights()
void importDocumentProperties()
Read the document properties and also the customXml entries (xlsx and pptx only).
::sax_fastparser::FSHelperPtr openFragmentStreamWithSerializer(const OUString &rStreamName, const OUString &rMediaType)
Opens specified output stream from the base storage with specified media type and returns new fast se...
OUString addRelation(const OUString &rType, std::u16string_view rTarget)
Adds new relation.
static FastParser * createParser()
void setMissingExtDrawing()
Signal that an MSO 2007-created SmartArt was found, need to warn the user about it.
OUString getFragmentPathFromFirstTypeFromOfficeDoc(std::u16string_view rPart)
virtual std::shared_ptr<::oox::drawingml::Theme > getCurrentThemePtr() const
May be implemented by filters which handle Diagrams, default returns empty ptr.
bool importFragment(const rtl::Reference< FragmentHandler > &rxHandler)
Imports a fragment using the passed fragment handler, which contains the full path to the fragment st...
void checkDocumentProperties(const css::uno::Reference< css::document::XDocumentProperties > &xDocProps)
css::uno::Reference< css::io::XOutputStream > openFragmentStream(const OUString &rStreamName, const OUString &rMediaType)
Opens and returns the specified output stream from the base storage with specified media type.
XmlFilterBase(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
OUString getNamespaceURL(sal_Int32 nNSID) const
void exportCustomFragments()
Write the customXml entries we are preserving (xlsx and pptx only).
::std::unique_ptr< XmlFilterBaseImpl > mxImpl
virtual bool implFinalizeExport(utl::MediaDescriptor &rMediaDescriptor) override
void importCustomFragments(css::uno::Reference< css::embed::XStorage > const &xDocumentStorage)
virtual css::uno::Reference< css::io::XInputStream > implGetInputStream(utl::MediaDescriptor &rMediaDesc) const override
bool isMSO2007Document() const
virtual StorageRef implCreateStorage(const css::uno::Reference< css::io::XInputStream > &rxInStream) const override
static void putPropertiesToDocumentGrabBag(const css::uno::Reference< css::lang::XComponent > &xDstDoc, const comphelper::SequenceAsHashMap &rProperties)
void exportDocumentProperties(const css::uno::Reference< css::document::XDocumentProperties > &xProperties, bool bSecurityOptOpenReadOnly)
Write the document properties into into the current OPC package.
Implements stream access for binary OLE storages.
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
static OUString GetGeneratorString()
constexpr sal_Int32 FSNS(sal_Int32 namespc, sal_Int32 element)
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
uno::Sequence< uno::Sequence< beans::StringPair > > ReadContentTypeSequence(const uno::Reference< io::XInputStream > &xInStream, const uno::Reference< uno::XComponentContext > &rContext)
OUString GetContentTypeByName(const css::uno::Sequence< css::uno::Sequence< css::beans::StringPair > > &rContentTypes, const OUString &rFilename)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Reference< XComponentContext > getProcessComponentContext()
constexpr OUStringLiteral gaBinSuffix(u".bin")
static void writeAppProperties(XmlFilterBase &rSelf, const Reference< XDocumentProperties > &xProperties)
static void writeElement(const FSHelperPtr &pDoc, sal_Int32 nXmlElement, std::u16string_view sValue)
std::shared_ptr< Relations > RelationsRef
static void writeCoreProperties(XmlFilterBase &rSelf, const Reference< XDocumentProperties > &xProperties)
static void writeCustomProperties(XmlFilterBase &rSelf, const Reference< XDocumentProperties > &xProperties, bool bSecurityOptOpenReadOnly)
std::map< OUString, ShapePairs > NamedShapePairs
OUString getRelationship(Relationship eRelationship)
std::shared_ptr< StorageBase > StorageRef
css::uno::Sequence< sal_Int8 > StreamDataSequence
NamespaceMap & StaticNamespaceMap()
Thread-safe singleton of a map of all supported XML namespace URLs.
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
std::shared_ptr< FastSerializerHelper > FSHelperPtr
constexpr OUStringLiteral OFOPXML_STORAGE_FORMAT_STRING
A map that contains all XML namespace URLs used in the filters.
RefMap< OUString, Relations > RelationsMap
NamedShapePairs * mpDiagramFontHeights
const NamespaceMap & mrNamespaceMap
RelationsMap maRelationsMap
Reference< XModel > xModel
constexpr OUStringLiteral UNO_NAME_MISC_OBJ_INTEROPGRABBAG