xref: /trunk/main/oox/inc/oox/core/xmlfilterbase.hxx (revision 46c69c84579d1f1df536015e7d54c9965db90b69)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef OOX_CORE_XMLFILTERBASE_HXX
25 #define OOX_CORE_XMLFILTERBASE_HXX
26 
27 #include <com/sun/star/text/XText.hpp>
28 #include <com/sun/star/text/XTextCursor.hpp>
29 #include <com/sun/star/text/XTextField.hpp>
30 #include <rtl/ref.hxx>
31 #include <rtl/string.hxx>
32 #include <rtl/ustring.hxx>
33 #include "oox/core/filterbase.hxx"
34 #include "oox/core/relations.hxx"
35 #include "oox/drawingml/table/tablestylelist.hxx"
36 #include "oox/dllapi.h"
37 
38 namespace com { namespace sun { namespace star {
39     namespace container { class XNameContainer; }
40     namespace document { class XDocumentProperties; }
41     namespace xml { namespace sax { class XLocator; } }
42     namespace xml { namespace sax { class XFastDocumentHandler; } }
43 } } }
44 
45 namespace oox {
46     namespace drawingml { class Theme; }
47     namespace drawingml { namespace chart { class ChartConverter; } }
48     namespace vml { class Drawing; }
49 }
50 
51 namespace sax_fastparser {
52     class FastSerializerHelper;
53 
54     typedef boost::shared_ptr< FastSerializerHelper > FSHelperPtr;
55 }
56 
57 namespace oox {
58 namespace core {
59 
60 class FragmentHandler;
61 
62 // ============================================================================
63 
64 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 
81     virtual             ~XmlFilterBase();
82 
83     /** Has to be implemented by each filter, returns the current theme. */
84     virtual const ::oox::drawingml::Theme*
85                         getCurrentTheme() const = 0;
86 
87     /** Has to be implemented by each filter to return the collection of VML shapes. */
88     virtual ::oox::vml::Drawing* getVmlDrawing() = 0;
89 
90     /** Has to be implemented by each filter, returns a filter-specific chart
91         converter object, that should be global per imported document. */
92     virtual ::oox::drawingml::chart::ChartConverter& getChartConverter() = 0;
93 
94     /** Has to be implemented by each filter to return the table style list. */
95     virtual const ::oox::drawingml::table::TableStyleListPtr getTableStyles() = 0;
96 
97     // ------------------------------------------------------------------------
98 
99     /** Returns the fragment path from the first relation of the passed type,
100         used for fragments referred by the root relations. */
101     ::rtl::OUString     getFragmentPathFromFirstType( const ::rtl::OUString& rType );
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 
110     /** Imports the relations fragment associated with the specified fragment.
111 
112         @return  The relations collection of the specified fragment.
113      */
114     RelationsRef        importRelations( const ::rtl::OUString& rFragmentPath );
115 
116     /** Adds new relation.
117 
118         @param rType
119             Relation type.
120 
121         @param rTarget
122             Relation target.
123 
124         @return  Added relation Id.
125      */
126     ::rtl::OUString     addRelation( const ::rtl::OUString& rType, const ::rtl::OUString& rTarget, bool bExternal = false );
127 
128     /** Adds new relation to part's relations.
129 
130         @param rPartName
131             Part name the relations are related to. The relations will be stored in <rPartName::path>/_rels/<rPartName::name>.rels.
132 
133         @param rType
134             Relation type.
135 
136         @param rTarget
137             Relation target.
138 
139         @return  Added relation Id.
140      */
141     ::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 );
142 
143     /** Returns a stack of used textfields, used by the pptx importer to replace links to slidepages with rhe real page name */
144     TextFieldStack& getTextFieldStack() const;
145 
146     /** Opens and returns the specified output stream from the base storage with specified media type.
147 
148         @param rStreamName
149             The name of the embedded storage stream. The name may contain
150             slashes to open streams from embedded substorages. If base stream
151             access has been enabled in the storage, the base stream can be
152             accessed by passing an empty string as stream name.
153 
154         @param rMediaType
155             The media type string, used in [Content_Types].xml stream in base
156             storage.
157 
158         @return The opened output stream.
159      */
160     ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
161                         openFragmentStream(
162                             const ::rtl::OUString& rStreamName,
163                             const ::rtl::OUString& rMediaType );
164 
165     /** Opens specified output stream from the base storage with specified
166         media type and returns new fast serializer for that stream.
167 
168         @param rStreamName
169             The name of the embedded storage stream. The name may contain
170             slashes to open streams from embedded substorages. If base stream
171             access has been enabled in the storage, the base stream can be
172             accessed by passing an empty string as stream name.
173 
174         @param rMediaType
175             The media type string, used in [Content_Types].xml stream in base
176             storage.
177 
178         @return newly created serializer helper.
179      */
180     ::sax_fastparser::FSHelperPtr
181                         openFragmentStreamWithSerializer(
182                             const ::rtl::OUString& rStreamName,
183                             const ::rtl::OUString& rMediaType );
184 
185     /** Returns new unique ID for exported document.
186 
187         @return newly created ID.
188      */
GetUniqueId()189     inline sal_Int32 GetUniqueId() { return mnMaxDocId++; }
GetUniqueIdOString()190     inline ::rtl::OString GetUniqueIdOString() { return ::rtl::OString::valueOf( mnMaxDocId++ ); }
GetUniqueIdOUString()191     inline ::rtl::OUString GetUniqueIdOUString() { return ::rtl::OUString::valueOf( mnMaxDocId++ ); }
192 
193     /** Write the document properties into into the current OPC package.
194 
195         @param xProperties  The document properties to export.
196 
197         @return *this
198      */
199     XmlFilterBase& exportDocumentProperties( ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > xProperties );
200 
201 protected:
202     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
203                         implGetInputStream( ::comphelper::MediaDescriptor& rMediaDesc ) const;
204 
205 private:
206     virtual StorageRef  implCreateStorage(
207                             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStream ) const;
208     virtual StorageRef  implCreateStorage(
209                             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rxOutStream ) const;
210 
211 private:
212     ::std::unique_ptr< XmlFilterBaseImpl > mxImpl;
213     sal_Int32 mnRelId;
214     sal_Int32 mnMaxDocId;
215 };
216 
217 typedef ::rtl::Reference< XmlFilterBase > XmlFilterRef;
218 
219 // ============================================================================
220 
221 } // namespace core
222 } // namespace oox
223 
224 #endif
225