Line data Source code
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_XMLFILTERBASE_HXX
21 : #define INCLUDED_OOX_CORE_XMLFILTERBASE_HXX
22 :
23 : #include <com/sun/star/text/XText.hpp>
24 : #include <com/sun/star/text/XTextCursor.hpp>
25 : #include <com/sun/star/text/XTextField.hpp>
26 : #include <rtl/ref.hxx>
27 : #include <rtl/string.hxx>
28 : #include <rtl/ustring.hxx>
29 : #include <oox/core/filterbase.hxx>
30 : #include <oox/core/relations.hxx>
31 : #include <oox/dllapi.h>
32 :
33 : namespace com { namespace sun { namespace star {
34 : namespace container { class XNameContainer; }
35 : namespace document { class XDocumentProperties; }
36 : namespace xml { namespace dom { class XDocument; } }
37 : namespace xml { namespace sax { class XLocator; } }
38 : namespace xml { namespace sax { class XFastDocumentHandler; } }
39 : namespace xml { namespace sax { class XFastSAXSerializable; } }
40 : } } }
41 :
42 : namespace oox {
43 : namespace drawingml { class Theme; }
44 : namespace drawingml { namespace chart { class ChartConverter; } }
45 : namespace drawingml { namespace table {
46 : class TableStyleList;
47 : typedef std::shared_ptr< TableStyleList > TableStyleListPtr;
48 : } }
49 : namespace vml { class Drawing; }
50 : }
51 :
52 : namespace sax_fastparser {
53 : class FastSerializerHelper;
54 :
55 : typedef std::shared_ptr< FastSerializerHelper > FSHelperPtr;
56 : }
57 :
58 : namespace oox {
59 : namespace core {
60 :
61 : class FragmentHandler;
62 : class FastParser;
63 :
64 0 : struct TextField {
65 : com::sun::star::uno::Reference< com::sun::star::text::XText > xText;
66 : com::sun::star::uno::Reference< com::sun::star::text::XTextCursor > xTextCursor;
67 : com::sun::star::uno::Reference< com::sun::star::text::XTextField > xTextField;
68 : };
69 : typedef std::vector< TextField > TextFieldStack;
70 :
71 : struct XmlFilterBaseImpl;
72 :
73 : class OOX_DLLPUBLIC XmlFilterBase : public FilterBase
74 : {
75 : public:
76 : explicit XmlFilterBase(
77 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext )
78 : throw( ::com::sun::star::uno::RuntimeException );
79 :
80 : virtual ~XmlFilterBase();
81 :
82 : /** Has to be implemented by each filter, returns the current theme. */
83 : virtual const ::oox::drawingml::Theme*
84 : getCurrentTheme() const = 0;
85 :
86 : /** Has to be implemented by each filter to return the collection of VML shapes. */
87 : virtual ::oox::vml::Drawing* getVmlDrawing() = 0;
88 :
89 : /** Has to be implemented by each filter, returns a filter-specific chart
90 : converter object, that should be global per imported document. */
91 : virtual ::oox::drawingml::chart::ChartConverter* getChartConverter() = 0;
92 :
93 : /** Helper to switch chart data table - specifically for xlsx imports */
94 0 : virtual void useInternalChartDataTable( bool /*bInternal*/ ) { }
95 :
96 : /** Has to be implemented by each filter to return the table style list. */
97 : virtual const ::oox::drawingml::table::TableStyleListPtr getTableStyles() = 0;
98 :
99 :
100 :
101 : OUString getFragmentPathFromFirstTypeFromOfficeDoc( const OUString& rPart );
102 :
103 : /** Imports a fragment using the passed fragment handler, which contains
104 : the full path to the fragment stream.
105 :
106 : @return True, if the fragment could be imported.
107 : */
108 : bool importFragment( const rtl::Reference<FragmentHandler>& rxHandler );
109 : bool importFragment( const rtl::Reference<FragmentHandler>& rxHandler, FastParser& rParser );
110 :
111 : /** Imports a fragment into an xml::dom::XDocument.
112 :
113 : @param rFragmentPath path to fragment
114 :
115 : @return a non-empty reference to the XDocument, if the
116 : fragment could be imported.
117 : */
118 : ::com::sun::star::uno::Reference<
119 : ::com::sun::star::xml::dom::XDocument> importFragment( const OUString& rFragmentPath );
120 :
121 : /** Imports a fragment from an xml::dom::XDocument using the
122 : passed fragment handler
123 :
124 : @param rxHandler fragment handler; path to fragment is
125 : ignored, input source is the rxSerializer
126 :
127 : @param rxSerializer usually retrieved from a
128 : xml::dom::XDocument, will get serialized into rxHandler
129 :
130 : @return true, if the fragment could be imported.
131 : */
132 : bool importFragment( const ::rtl::Reference< FragmentHandler >& rxHandler,
133 : const ::com::sun::star::uno::Reference<
134 : ::com::sun::star::xml::sax::XFastSAXSerializable >& rxSerializer );
135 :
136 : /** Imports the relations fragment associated with the specified fragment.
137 :
138 : @return The relations collection of the specified fragment.
139 : */
140 : RelationsRef importRelations( const OUString& rFragmentPath );
141 :
142 : /** Adds new relation.
143 :
144 : @param rType
145 : Relation type.
146 :
147 : @param rTarget
148 : Relation target.
149 :
150 : @return Added relation Id.
151 : */
152 : OUString addRelation( const OUString& rType, const OUString& rTarget, bool bExternal = false );
153 :
154 : /** Adds new relation to part's relations.
155 :
156 : @param rPartName
157 : Part name the relations are related to. The relations will be stored in <rPartName::path>/_rels/<rPartName::name>.rels.
158 :
159 : @param rType
160 : Relation type.
161 :
162 : @param rTarget
163 : Relation target.
164 :
165 : @return Added relation Id.
166 : */
167 : OUString addRelation( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rOutputStream, const OUString& rType, const OUString& rTarget, bool bExternal = false );
168 :
169 : /** Returns a stack of used textfields, used by the pptx importer to replace links to slidepages with the real page name */
170 : TextFieldStack& getTextFieldStack() const;
171 :
172 : /** Opens and returns the specified output stream from the base storage with specified media type.
173 :
174 : @param rStreamName
175 : The name of the embedded storage stream. The name may contain
176 : slashes to open streams from embedded substorages. If base stream
177 : access has been enabled in the storage, the base stream can be
178 : accessed by passing an empty string as stream name.
179 :
180 : @param rMediaType
181 : The media type string, used in [Content_Types].xml stream in base
182 : storage.
183 :
184 : @return The opened output stream.
185 : */
186 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
187 : openFragmentStream(
188 : const OUString& rStreamName,
189 : const OUString& rMediaType );
190 :
191 : /** Opens specified output stream from the base storage with specified
192 : media type and returns new fast serializer for that stream.
193 :
194 : @param rStreamName
195 : The name of the embedded storage stream. The name may contain
196 : slashes to open streams from embedded substorages. If base stream
197 : access has been enabled in the storage, the base stream can be
198 : accessed by passing an empty string as stream name.
199 :
200 : @param rMediaType
201 : The media type string, used in [Content_Types].xml stream in base
202 : storage.
203 :
204 : @return newly created serializer helper.
205 : */
206 : ::sax_fastparser::FSHelperPtr
207 : openFragmentStreamWithSerializer(
208 : const OUString& rStreamName,
209 : const OUString& rMediaType );
210 :
211 : /** Returns new unique ID for exported document.
212 :
213 : @return newly created ID.
214 : */
215 1194 : sal_Int32 GetUniqueId() { return mnMaxDocId++; }
216 : OString GetUniqueIdOString() { return OString::number( mnMaxDocId++ ); }
217 : OUString GetUniqueIdOUString() { return OUString::number( mnMaxDocId++ ); }
218 :
219 : /** Write the document properties into into the current OPC package.
220 :
221 : @param xProperties The document properties to export.
222 :
223 : @return *this
224 : */
225 : XmlFilterBase& exportDocumentProperties( ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > xProperties );
226 :
227 : OUString getNamespaceURL( const OUString& rPrefix );
228 :
229 : bool hasNamespaceURL( const OUString& rPrefix ) const;
230 :
231 : sal_Int32 getNamespaceId( const OUString& rUrl );
232 :
233 : void importDocumentProperties();
234 :
235 : FastParser* createParser() const;
236 :
237 : bool isMSO2007Document() const;
238 :
239 : void checkDocumentProperties(
240 : com::sun::star::uno::Reference<com::sun::star::document::XDocumentProperties> xDocProps);
241 :
242 : protected:
243 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
244 : implGetInputStream( utl::MediaDescriptor& rMediaDesc ) const SAL_OVERRIDE;
245 :
246 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >
247 : implGetOutputStream( utl::MediaDescriptor& rMediaDesc ) const SAL_OVERRIDE;
248 :
249 : virtual bool implFinalizeExport( utl::MediaDescriptor& rMediaDescriptor ) SAL_OVERRIDE;
250 :
251 : private:
252 : virtual StorageRef implCreateStorage(
253 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStream ) const SAL_OVERRIDE;
254 : virtual StorageRef implCreateStorage(
255 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rxOutStream ) const SAL_OVERRIDE;
256 :
257 : private:
258 : ::std::unique_ptr< XmlFilterBaseImpl > mxImpl;
259 : sal_Int32 mnRelId;
260 : sal_Int32 mnMaxDocId;
261 : bool mbMSO2007;
262 : };
263 :
264 : typedef ::rtl::Reference< XmlFilterBase > XmlFilterRef;
265 :
266 : } // namespace core
267 : } // namespace oox
268 :
269 : #endif
270 :
271 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|