22#include <com/sun/star/io/XStream.hpp>
31#include <oox/token/namespaces.hxx>
32#include <oox/token/tokens.hxx>
36#include <com/sun/star/uri/UriReferenceFactory.hpp>
37#include <com/sun/star/beans/NamedValue.hpp>
56 mrFilterName( rFilterName ),
57 maFileName(
std::move(aFileName)),
85 sal_Int32 nElement,
const Reference< XFastAttributeList >& rAttribs )
91 case PR_TOKEN( Relationships ):
99 case PC_TOKEN(
Types ):
105 case PC_TOKEN( Override ):
114 const OUString& ,
const OUString& ,
const Reference<XFastAttributeList>& )
124 const OUString& ,
const OUString& )
129 sal_Int32 ,
const Reference<XFastAttributeList>& )
135 const OUString& ,
const OUString& ,
const Reference<XFastAttributeList>& )
149 if (aType.startsWithIgnoreAsciiCase(
"http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties"))
151 else if (aType.startsWithIgnoreAsciiCase(
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"))
153 else if (aType.startsWithIgnoreAsciiCase(
"http://purl.oclc.org/ooxml/officeDocument"))
156 if ( aType !=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
157 && aType !=
"http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument" )
160 Reference<XUriReferenceFactory>
xFactory = UriReferenceFactory::create(
mxContext );
165 Reference< XUriReference > xBase =
xFactory->parse(
"file:///" );
168 Reference< XUriReference > xAbs =
xFactory->makeAbsolute( xBase, xPart,
true, RelativeUriExcessParentSegments_RETAIN );
180 bool bDocm = rFileName.endsWithIgnoreAsciiCase(
".docm");
182 if( rContentType ==
u"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" && !bDocm )
188 return "writer_OOXML";
190 return "writer_MS_Word_2007";
194 if( rContentType ==
u"application/vnd.ms-word.document.macroEnabled.main+xml" || bDocm )
195 return "writer_MS_Word_2007_VBA";
197 if( rContentType ==
u"application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml" ||
198 rContentType ==
u"application/vnd.ms-word.template.macroEnabledTemplate.main+xml" )
204 return "writer_OOXML_Text_Template";
206 return "writer_MS_Word_2007_Template";
210 if( rContentType ==
u"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml")
211 return "MS Excel 2007 XML";
213 if (rContentType ==
u"application/vnd.ms-excel.sheet.macroEnabled.main+xml")
214 return "MS Excel 2007 VBA XML";
216 if( rContentType ==
u"application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml" ||
217 rContentType ==
u"application/vnd.ms-excel.template.macroEnabled.main+xml" )
218 return "MS Excel 2007 XML Template";
220 if ( rContentType ==
u"application/vnd.ms-excel.sheet.binary.macroEnabled.main" )
221 return "MS Excel 2007 Binary";
223 if (rContentType ==
u"application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml")
224 return "MS PowerPoint 2007 XML";
226 if (rContentType ==
u"application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml")
227 return "MS PowerPoint 2007 XML VBA";
229 if( rContentType ==
u"application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml" ||
230 rContentType ==
u"application/vnd.ms-powerpoint.slideshow.macroEnabled.main+xml" )
231 return "MS PowerPoint 2007 XML AutoPlay";
233 if( rContentType ==
u"application/vnd.openxmlformats-officedocument.presentationml.template.main+xml" ||
234 rContentType ==
u"application/vnd.ms-powerpoint.template.macroEnabled.main+xml" )
235 return "MS PowerPoint 2007 XML Template";
247 sal_Int32 nExtPos =
maTargetPath.getLength() - aExtension.getLength();
271bool lclIsZipPackage(
const Reference< XComponentContext >& rxContext,
const Reference< XInputStream >& rxInStrm )
273 ZipStorage aZipStorage( rxContext, rxInStrm );
274 return aZipStorage.isStorage();
277class PasswordVerifier :
public IDocPasswordVerifier
282 virtual DocPasswordVerifierResult verifyPassword(
const OUString& rPassword, Sequence<NamedValue>& rEncryptionData )
override;
289PasswordVerifier::PasswordVerifier( crypto::DocumentDecryption& aDecryptor ) :
297 if (
mDecryptor.generateEncryptionKey(rPassword))
298 rEncryptionData =
mDecryptor.createEncryptionData(rPassword);
316Reference< XInputStream > FilterDetect::extractUnencryptedPackage(
MediaDescriptor& rMediaDescriptor )
const
319 Reference<XInputStream> xInputStream( rMediaDescriptor[ MediaDescriptor::PROP_INPUTSTREAM ], UNO_QUERY );
320 if( !xInputStream.is() || lclIsZipPackage(
mxContext, xInputStream ) )
324 Reference<XStream> xDecrypted( rMediaDescriptor.
getComponentDataEntry(
"DecryptedPackage" ), UNO_QUERY );
325 if( xDecrypted.is() )
327 Reference<XInputStream> xDecryptedInputStream = xDecrypted->getInputStream();
328 if( lclIsZipPackage(
mxContext, xDecryptedInputStream ) )
329 return xDecryptedInputStream;
346 std::vector<OUString> aDefaultPasswords;
347 aDefaultPasswords.emplace_back(
"VelvetSweatshop");
353 PasswordVerifier aVerifier( aDecryptor );
357 &aDefaultPasswords );
359 if( !aEncryptionData.hasElements() )
361 rMediaDescriptor[ MediaDescriptor::PROP_ABORTED ] <<=
true;
366 Reference<XStream>
const xTempStream(
367 mxContext->getServiceManager()->createInstanceWithContext(
368 "com.sun.star.comp.MemoryStream",
mxContext),
372 if (!aDecryptor.
decrypt(xTempStream))
374 rMediaDescriptor[ MediaDescriptor::PROP_ABORTED ] <<=
true;
381 Reference<XInputStream> xDecryptedInputStream = xTempStream->getInputStream();
382 if( lclIsZipPackage(
mxContext, xDecryptedInputStream ) )
383 return xDecryptedInputStream;
392 return Reference<XInputStream>();
399 return "com.sun.star.comp.oox.FormatDetector";
409 return {
"com.sun.star.frame.ExtendedTypeDetection" };
416 OUString aFilterName;
421 aMediaDescriptor.addInputStream();
427 Reference< XInputStream > xInputStream( extractUnencryptedPackage( aMediaDescriptor ), UNO_SET_THROW );
430 ZipStorage aZipStorage( mxContext, xInputStream );
431 if( aZipStorage.isStorage() )
447 aParser.
parseStream( aZipStorage,
"[Content_Types].xml" );
450 catch(
const Exception& )
452 if ( aMediaDescriptor.getUnpackedValueOrDefault( MediaDescriptor::PROP_ABORTED,
false ) )
463 aFilterName = aMediaDescriptor.getUnpackedValueOrDefault( MediaDescriptor::PROP_TYPENAME, OUString() );
467 aMediaDescriptor >> rMediaDescSeq;
473extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
475 uno::Sequence<uno::Any>
const& )
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
virtual OUString SAL_CALL detect(css::uno::Sequence< css::beans::PropertyValue > &lDescriptor) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Provides access to attribute values of an element.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
bool isStorage() const
Returns true, if the object represents a valid storage.
Implements stream access for ZIP storages containing XML streams.
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.
Document handler specifically designed for detecting OOXML file formats.
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
virtual void SAL_CALL endUnknownElement(const OUString &Namespace, const OUString &Name) override
void parseRelationship(const AttributeList &rAttribs)
ContextVector maContextStack
OOXMLVariant maOOXMLVariant
void parseContentTypesOverride(const AttributeList &rAttribs)
virtual void SAL_CALL startUnknownElement(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
virtual void SAL_CALL endDocument() override
virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > &xLocator) override
virtual void SAL_CALL processingInstruction(const OUString &rTarget, const OUString &rData) override
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
void parseContentTypesDefault(const AttributeList &rAttribs)
FilterDetectDocHandler(const css::uno::Reference< css::uno::XComponentContext > &rxContext, OUString &rFilter, OUString aFileName)
virtual void SAL_CALL characters(const OUString &aChars) override
virtual ~FilterDetectDocHandler() override
virtual void SAL_CALL startDocument() override
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
OUString getFilterNameFromContentType(std::u16string_view rContentType, const OUString &rFileName)
virtual ~FilterDetect() override
FilterDetect(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
bool readEncryptionInfo()
bool decrypt(const css::uno::Reference< css::io::XStream > &xDocumentStream)
Implements stream access for binary OLE storages.
Reference< XSingleServiceFactory > xFactory
crypto::DocumentDecryption & mDecryptor
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_oox_FormatDetector_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
DocPasswordVerifierResult
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)