LibreOffice Module oox (master)  1
filterdetect.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_OOX_CORE_FILTERDETECT_HXX
21 #define INCLUDED_OOX_CORE_FILTERDETECT_HXX
22 
23 #include <vector>
24 
25 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
31 #include <cppuhelper/implbase.hxx>
32 #include <oox/dllapi.h>
33 #include <rtl/ustring.hxx>
34 #include <sal/types.h>
35 
36 namespace com::sun::star {
37  namespace beans { struct PropertyValue; }
38  namespace io { class XInputStream; }
39  namespace uno { class XComponentContext; }
40  namespace xml::sax { class XFastAttributeList; }
41  namespace xml::sax { class XFastContextHandler; }
42  namespace xml::sax { class XLocator; }
43 }
44 
45 namespace utl { class MediaDescriptor; }
46 
47 namespace oox { class AttributeList; }
48 
49 namespace oox::core {
50 
51 enum class OOXMLVariant {
55 };
56 
57 
63 class FilterDetectDocHandler final : public ::cppu::WeakImplHelper< css::xml::sax::XFastDocumentHandler >
64 {
65 public:
66  explicit FilterDetectDocHandler( const css::uno::Reference< css::uno::XComponentContext >& rxContext, OUString& rFilter, const OUString& rFileName );
67  virtual ~FilterDetectDocHandler() override;
68 
69  // XFastDocumentHandler
70  virtual void SAL_CALL startDocument() override;
71  virtual void SAL_CALL endDocument() override;
72  virtual void SAL_CALL processingInstruction( const OUString& rTarget, const OUString& rData ) override;
73  virtual void SAL_CALL setDocumentLocator( const css::uno::Reference< css::xml::sax::XLocator >& xLocator ) override;
74 
75  // XFastContextHandler
76  virtual void SAL_CALL startFastElement( sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs ) override;
77  virtual void SAL_CALL startUnknownElement( const OUString& Namespace, const OUString& Name, const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs ) override;
78  virtual void SAL_CALL endFastElement( sal_Int32 Element ) override;
79  virtual void SAL_CALL endUnknownElement( const OUString& Namespace, const OUString& Name ) override;
80  virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs ) override;
81  virtual css::uno::Reference< XFastContextHandler > SAL_CALL createUnknownChildContext( const OUString& Namespace, const OUString& Name, const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs ) override;
82  virtual void SAL_CALL characters( const OUString& aChars ) override;
83 
84 private:
85  void parseRelationship( const AttributeList& rAttribs );
86 
87  OUString getFilterNameFromContentType( std::u16string_view rContentType, const OUString& rFileName );
88  void parseContentTypesDefault( const AttributeList& rAttribs );
89  void parseContentTypesOverride( const AttributeList& rAttribs );
90 
91 private:
92  typedef ::std::vector< sal_Int32 > ContextVector;
93 
94  OUString& mrFilterName;
95  OUString maFileName;
96  ContextVector maContextStack;
97  OUString maTargetPath;
99  css::uno::Reference< css::uno::XComponentContext > mxContext;
100 };
101 
102 
103 class OOX_DLLPUBLIC FilterDetect final : public ::cppu::WeakImplHelper<css::document::XExtendedFilterDetection, css::lang::XServiceInfo>
104 {
105 public:
107  explicit FilterDetect( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
108  virtual ~FilterDetect() override;
109 
133  css::uno::Reference< css::io::XInputStream >
134  extractUnencryptedPackage( utl::MediaDescriptor& rMediaDesc ) const;
135 
136  // com.sun.star.lang.XServiceInfo interface -------------------------------
137 
138  virtual OUString SAL_CALL getImplementationName() override;
139  virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override;
140  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
141 
142  // com.sun.star.document.XExtendedFilterDetection interface ---------------
143 
160  virtual OUString SAL_CALL
161  detect( css::uno::Sequence< css::beans::PropertyValue >& rMediaDescSeq ) override;
162 
163 private:
164  css::uno::Reference< css::uno::XComponentContext > mxContext;
165 };
166 
167 
168 } // namespace oox::core
169 
170 #endif
171 
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Document handler specifically designed for detecting OOXML file formats.
css::uno::Reference< css::uno::XComponentContext > mxContext
exports com.sun.star. io
FilterGroup & rTarget
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
const ContentProperties & rData
OUString Name
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > &xLocator) override
virtual void SAL_CALL endDocument() override
::std::vector< sal_Int32 > ContextVector
void parseContentTypesOverride(const AttributeList &rAttribs)
void parseContentTypesDefault(const AttributeList &rAttribs)
void parseRelationship(const AttributeList &rAttribs)
virtual void SAL_CALL processingInstruction(const OUString &rTarget, const OUString &rData) override
unsigned char sal_Bool
Provides access to attribute values of an element.
virtual void SAL_CALL startUnknownElement(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
exports com.sun.star. beans
virtual void SAL_CALL endUnknownElement(const OUString &Namespace, const OUString &Name) override
css::uno::Reference< css::uno::XComponentContext > mxContext
FilterDetectDocHandler(const css::uno::Reference< css::uno::XComponentContext > &rxContext, OUString &rFilter, const OUString &rFileName)
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
#define OOX_DLLPUBLIC
Definition: dllapi.h:28
virtual void SAL_CALL characters(const OUString &aChars) override
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
virtual void SAL_CALL startDocument() override
OUString getFilterNameFromContentType(std::u16string_view rContentType, const OUString &rFileName)
virtual ~FilterDetectDocHandler() override