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>
57 mrFilterName( rFilterName ),
58 maFileName(
std::move(aFileName)),
86 sal_Int32 nElement,
const Reference< XFastAttributeList >& rAttribs )
92 case PR_TOKEN( Relationships ):
100 case PC_TOKEN(
Types ):
106 case PC_TOKEN( Override ):
115 const OUString& ,
const OUString& ,
const Reference<XFastAttributeList>& )
125 const OUString& ,
const OUString& )
130 sal_Int32 ,
const Reference<XFastAttributeList>& )
136 const OUString& ,
const OUString& ,
const Reference<XFastAttributeList>& )
150 if (aType.startsWithIgnoreAsciiCase(
"http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties"))
152 else if (aType.startsWithIgnoreAsciiCase(
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"))
154 else if (aType.startsWithIgnoreAsciiCase(
"http://purl.oclc.org/ooxml/officeDocument"))
157 if ( aType !=
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
158 && aType !=
"http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument" )
161 Reference<XUriReferenceFactory>
xFactory = UriReferenceFactory::create(
mxContext );
166 Reference< XUriReference > xBase =
xFactory->parse(
"file:///" );
169 Reference< XUriReference > xAbs =
xFactory->makeAbsolute( xBase, xPart,
true, RelativeUriExcessParentSegments_RETAIN );
183 if( rContentType ==
u"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" && !bDocm )
189 return "writer_OOXML";
191 return "writer_MS_Word_2007";
195 if( rContentType ==
u"application/vnd.ms-word.document.macroEnabled.main+xml" || bDocm )
196 return "writer_MS_Word_2007_VBA";
198 if( rContentType ==
u"application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml" ||
199 rContentType ==
u"application/vnd.ms-word.template.macroEnabledTemplate.main+xml" )
205 return "writer_OOXML_Text_Template";
207 return "writer_MS_Word_2007_Template";
211 if( rContentType ==
u"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml")
212 return "MS Excel 2007 XML";
214 if (rContentType ==
u"application/vnd.ms-excel.sheet.macroEnabled.main+xml")
215 return "MS Excel 2007 VBA XML";
217 if( rContentType ==
u"application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml" ||
218 rContentType ==
u"application/vnd.ms-excel.template.macroEnabled.main+xml" )
219 return "MS Excel 2007 XML Template";
221 if ( rContentType ==
u"application/vnd.ms-excel.sheet.binary.macroEnabled.main" )
222 return "MS Excel 2007 Binary";
224 if (rContentType ==
u"application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml")
225 return "MS PowerPoint 2007 XML";
227 if (rContentType ==
u"application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml")
228 return "MS PowerPoint 2007 XML VBA";
230 if( rContentType ==
u"application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml" ||
231 rContentType ==
u"application/vnd.ms-powerpoint.slideshow.macroEnabled.main+xml" )
232 return "MS PowerPoint 2007 XML AutoPlay";
234 if( rContentType ==
u"application/vnd.openxmlformats-officedocument.presentationml.template.main+xml" ||
235 rContentType ==
u"application/vnd.ms-powerpoint.template.macroEnabled.main+xml" )
236 return "MS PowerPoint 2007 XML Template";
248 sal_Int32 nExtPos =
maTargetPath.getLength() - aExtension.getLength();
272bool lclIsZipPackage(
const Reference< XComponentContext >& rxContext,
const Reference< XInputStream >& rxInStrm )
274 ZipStorage aZipStorage( rxContext, rxInStrm );
275 return aZipStorage.isStorage();
278class PasswordVerifier :
public IDocPasswordVerifier
283 virtual DocPasswordVerifierResult verifyPassword(
const OUString& rPassword, Sequence<NamedValue>& rEncryptionData )
override;
290PasswordVerifier::PasswordVerifier( crypto::DocumentDecryption& aDecryptor ) :
298 if (
mDecryptor.generateEncryptionKey(rPassword))
299 rEncryptionData =
mDecryptor.createEncryptionData(rPassword);
317Reference< XInputStream > FilterDetect::extractUnencryptedPackage(
MediaDescriptor& rMediaDescriptor )
const
320 Reference<XInputStream> xInputStream( rMediaDescriptor[ MediaDescriptor::PROP_INPUTSTREAM ], UNO_QUERY );
321 if( !xInputStream.is() || lclIsZipPackage(
mxContext, xInputStream ) )
325 Reference<XStream> xDecrypted( rMediaDescriptor.
getComponentDataEntry(
"DecryptedPackage" ), UNO_QUERY );
326 if( xDecrypted.is() )
328 Reference<XInputStream> xDecryptedInputStream = xDecrypted->getInputStream();
329 if( lclIsZipPackage(
mxContext, xDecryptedInputStream ) )
330 return xDecryptedInputStream;
347 std::vector<OUString> aDefaultPasswords;
348 aDefaultPasswords.emplace_back(
"VelvetSweatshop");
354 PasswordVerifier aVerifier( aDecryptor );
358 &aDefaultPasswords );
360 if( !aEncryptionData.hasElements() )
362 rMediaDescriptor[ MediaDescriptor::PROP_ABORTED ] <<=
true;
367 Reference<XStream>
const xTempStream(
368 mxContext->getServiceManager()->createInstanceWithContext(
369 "com.sun.star.comp.MemoryStream",
mxContext),
373 if (!aDecryptor.
decrypt(xTempStream))
375 rMediaDescriptor[ MediaDescriptor::PROP_ABORTED ] <<=
true;
382 Reference<XInputStream> xDecryptedInputStream = xTempStream->getInputStream();
383 if( lclIsZipPackage(
mxContext, xDecryptedInputStream ) )
384 return xDecryptedInputStream;
393 return Reference<XInputStream>();
400 return "com.sun.star.comp.oox.FormatDetector";
410 return {
"com.sun.star.frame.ExtendedTypeDetection" };
417 OUString aFilterName;
422 aMediaDescriptor.addInputStream();
428 Reference< XInputStream > xInputStream( extractUnencryptedPackage( aMediaDescriptor ), UNO_SET_THROW );
431 ZipStorage aZipStorage( mxContext, xInputStream );
432 if( aZipStorage.isStorage() )
448 aParser.
parseStream( aZipStorage,
"[Content_Types].xml" );
451 catch(
const Exception& )
453 if ( aMediaDescriptor.getUnpackedValueOrDefault( MediaDescriptor::PROP_ABORTED,
false ) )
464 aFilterName = aMediaDescriptor.getUnpackedValueOrDefault( MediaDescriptor::PROP_TYPENAME, OUString() );
468 aMediaDescriptor >> rMediaDescSeq;
474extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
476 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.
OUString getFilterNameFromContentType(std::u16string_view rContentType, std::u16string_view rFileName)
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
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)
bool endsWithIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2, std::u16string_view *rest=nullptr)