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 OOX_CORE_XMLFILTERBASE_HXX
21 : #define 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/drawingml/table/tablestylelist.hxx"
32 : #include "oox/dllapi.h"
33 :
34 : namespace com { namespace sun { namespace star {
35 : namespace container { class XNameContainer; }
36 : namespace document { class XDocumentProperties; }
37 : namespace xml { namespace dom { class XDocument; } }
38 : namespace xml { namespace sax { class XLocator; } }
39 : namespace xml { namespace sax { class XFastDocumentHandler; } }
40 : namespace xml { namespace sax { class XFastSAXSerializable; } }
41 : } } }
42 :
43 : namespace oox {
44 : namespace drawingml { class Theme; }
45 : namespace drawingml { namespace chart { class ChartConverter; } }
46 : namespace vml { class Drawing; }
47 : }
48 :
49 : namespace sax_fastparser {
50 : class FastSerializerHelper;
51 :
52 : typedef boost::shared_ptr< FastSerializerHelper > FSHelperPtr;
53 : }
54 :
55 : namespace oox {
56 : namespace core {
57 :
58 : class FragmentHandler;
59 :
60 : // ============================================================================
61 :
62 0 : struct TextField {
63 : com::sun::star::uno::Reference< com::sun::star::text::XText > xText;
64 : com::sun::star::uno::Reference< com::sun::star::text::XTextCursor > xTextCursor;
65 : com::sun::star::uno::Reference< com::sun::star::text::XTextField > xTextField;
66 : };
67 : typedef std::vector< TextField > TextFieldStack;
68 :
69 : // ============================================================================
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 : /** Has to be implemented by each filter to return the table style list. */
94 : virtual const ::oox::drawingml::table::TableStyleListPtr getTableStyles() = 0;
95 :
96 : // ------------------------------------------------------------------------
97 :
98 : /** Returns the fragment path from the first relation of the passed type,
99 : used for fragments referred by the root relations. */
100 : ::rtl::OUString getFragmentPathFromFirstType( const ::rtl::OUString& rType );
101 :
102 : /** Imports a fragment using the passed fragment handler, which contains
103 : the full path to the fragment stream.
104 :
105 : @return True, if the fragment could be imported.
106 : */
107 : bool importFragment( const ::rtl::Reference< FragmentHandler >& rxHandler );
108 :
109 : /** Imports a fragment into an xml::dom::XDocument.
110 :
111 : @param rFragmentPath path to fragment
112 :
113 : @return a non-empty reference to the XDocument, if the
114 : fragment could be imported.
115 : */
116 : ::com::sun::star::uno::Reference<
117 : ::com::sun::star::xml::dom::XDocument> importFragment( const ::rtl::OUString& rFragmentPath );
118 :
119 : /** Imports a fragment from an xml::dom::XDocument using the
120 : passed fragment handler
121 :
122 : @param rxHandler fragment handler; path to fragment is
123 : ignored, input source is the rxSerializer
124 :
125 : @param rxSerializer usually retrieved from a
126 : xml::dom::XDocument, will get serialized into rxHandler
127 :
128 : @return true, if the fragment could be imported.
129 : */
130 : bool importFragment( const ::rtl::Reference< FragmentHandler >& rxHandler,
131 : const ::com::sun::star::uno::Reference<
132 : ::com::sun::star::xml::sax::XFastSAXSerializable >& rxSerializer );
133 :
134 : /** Imports the relations fragment associated with the specified fragment.
135 :
136 : @return The relations collection of the specified fragment.
137 : */
138 : RelationsRef importRelations( const ::rtl::OUString& rFragmentPath );
139 :
140 : /** Adds new relation.
141 :
142 : @param rType
143 : Relation type.
144 :
145 : @param rTarget
146 : Relation target.
147 :
148 : @return Added relation Id.
149 : */
150 : ::rtl::OUString addRelation( const ::rtl::OUString& rType, const ::rtl::OUString& rTarget, bool bExternal = false );
151 :
152 : /** Adds new relation to part's relations.
153 :
154 : @param rPartName
155 : Part name the relations are related to. The relations will be stored in <rPartName::path>/_rels/<rPartName::name>.rels.
156 :
157 : @param rType
158 : Relation type.
159 :
160 : @param rTarget
161 : Relation target.
162 :
163 : @return Added relation Id.
164 : */
165 : ::rtl::OUString addRelation( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xOutputStream, const ::rtl::OUString& rType, const ::rtl::OUString& rTarget, bool bExternal = false );
166 :
167 : /** Returns a stack of used textfields, used by the pptx importer to replace links to slidepages with rhe real page name */
168 : TextFieldStack& getTextFieldStack() const;
169 :
170 : /** Opens and returns the specified output stream from the base storage with specified media type.
171 :
172 : @param rStreamName
173 : The name of the embedded storage stream. The name may contain
174 : slashes to open streams from embedded substorages. If base stream
175 : access has been enabled in the storage, the base stream can be
176 : accessed by passing an empty string as stream name.
177 :
178 : @param rMediaType
179 : The media type string, used in [Content_Types].xml stream in base
180 : storage.
181 :
182 : @return The opened output stream.
183 : */
184 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
185 : openFragmentStream(
186 : const ::rtl::OUString& rStreamName,
187 : const ::rtl::OUString& rMediaType );
188 :
189 : /** Opens specified output stream from the base storage with specified
190 : media type and returns new fast serializer for that stream.
191 :
192 : @param rStreamName
193 : The name of the embedded storage stream. The name may contain
194 : slashes to open streams from embedded substorages. If base stream
195 : access has been enabled in the storage, the base stream can be
196 : accessed by passing an empty string as stream name.
197 :
198 : @param rMediaType
199 : The media type string, used in [Content_Types].xml stream in base
200 : storage.
201 :
202 : @return newly created serializer helper.
203 : */
204 : ::sax_fastparser::FSHelperPtr
205 : openFragmentStreamWithSerializer(
206 : const ::rtl::OUString& rStreamName,
207 : const ::rtl::OUString& rMediaType );
208 :
209 : /** Returns new unique ID for exported document.
210 :
211 : @return newly created ID.
212 : */
213 0 : inline sal_Int32 GetUniqueId() { return mnMaxDocId++; }
214 : inline ::rtl::OString GetUniqueIdOString() { return ::rtl::OString::valueOf( mnMaxDocId++ ); }
215 : inline ::rtl::OUString GetUniqueIdOUString() { return ::rtl::OUString::valueOf( mnMaxDocId++ ); }
216 :
217 : /** Write the document properties into into the current OPC package.
218 :
219 : @param xProperties The document properties to export.
220 :
221 : @return *this
222 : */
223 : XmlFilterBase& exportDocumentProperties( ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > xProperties );
224 :
225 : ::rtl::OUString getNamespaceURL( const ::rtl::OUString& rPrefix );
226 :
227 : sal_Int32 getNamespaceId( const ::rtl::OUString& rUrl );
228 :
229 : void importDocumentProperties();
230 :
231 : protected:
232 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
233 : implGetInputStream( ::comphelper::MediaDescriptor& rMediaDesc ) const;
234 :
235 : private:
236 : virtual StorageRef implCreateStorage(
237 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStream ) const;
238 : virtual StorageRef implCreateStorage(
239 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rxOutStream ) const;
240 :
241 : private:
242 : ::std::auto_ptr< XmlFilterBaseImpl > mxImpl;
243 : sal_Int32 mnRelId;
244 : sal_Int32 mnMaxDocId;
245 : };
246 :
247 : typedef ::rtl::Reference< XmlFilterBase > XmlFilterRef;
248 :
249 : // ============================================================================
250 :
251 : } // namespace core
252 : } // namespace oox
253 :
254 : #endif
255 :
256 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|