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