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 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 /** Has to be implemented by each filter to return the table style list. */ 96 virtual const ::oox::drawingml::table::TableStyleListPtr getTableStyles() = 0; 97 98 // ------------------------------------------------------------------------ 99 100 /** Returns the fragment path from the first relation of the passed type, 101 used for fragments referred by the root relations. */ 102 ::rtl::OUString getFragmentPathFromFirstType( const ::rtl::OUString& rType ); 103 104 /** Imports a fragment using the passed fragment handler, which contains 105 the full path to the fragment stream. 106 107 @return True, if the fragment could be imported. 108 */ 109 bool importFragment( const ::rtl::Reference< FragmentHandler >& rxHandler ); 110 111 /** Imports the relations fragment associated with the specified fragment. 112 113 @return The relations collection of the specified fragment. 114 */ 115 RelationsRef importRelations( const ::rtl::OUString& rFragmentPath ); 116 117 /** Adds new relation. 118 119 @param rType 120 Relation type. 121 122 @param rTarget 123 Relation target. 124 125 @return Added relation Id. 126 */ 127 ::rtl::OUString addRelation( const ::rtl::OUString& rType, const ::rtl::OUString& rTarget, bool bExternal = false ); 128 129 /** Adds new relation to part's relations. 130 131 @param rPartName 132 Part name the relations are related to. The relations will be stored in <rPartName::path>/_rels/<rPartName::name>.rels. 133 134 @param rType 135 Relation type. 136 137 @param rTarget 138 Relation target. 139 140 @return Added relation Id. 141 */ 142 ::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 ); 143 144 /** Returns a stack of used textfields, used by the pptx importer to replace links to slidepages with rhe real page name */ 145 TextFieldStack& getTextFieldStack() const; 146 147 /** Opens and returns the specified output stream from the base storage with specified media type. 148 149 @param rStreamName 150 The name of the embedded storage stream. The name may contain 151 slashes to open streams from embedded substorages. If base stream 152 access has been enabled in the storage, the base stream can be 153 accessed by passing an empty string as stream name. 154 155 @param rMediaType 156 The media type string, used in [Content_Types].xml stream in base 157 storage. 158 159 @return The opened output stream. 160 */ 161 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > 162 openFragmentStream( 163 const ::rtl::OUString& rStreamName, 164 const ::rtl::OUString& rMediaType ); 165 166 /** Opens specified output stream from the base storage with specified 167 media type and returns new fast serializer for that stream. 168 169 @param rStreamName 170 The name of the embedded storage stream. The name may contain 171 slashes to open streams from embedded substorages. If base stream 172 access has been enabled in the storage, the base stream can be 173 accessed by passing an empty string as stream name. 174 175 @param rMediaType 176 The media type string, used in [Content_Types].xml stream in base 177 storage. 178 179 @return newly created serializer helper. 180 */ 181 ::sax_fastparser::FSHelperPtr 182 openFragmentStreamWithSerializer( 183 const ::rtl::OUString& rStreamName, 184 const ::rtl::OUString& rMediaType ); 185 186 /** Returns new unique ID for exported document. 187 188 @return newly created ID. 189 */ GetUniqueId()190 inline sal_Int32 GetUniqueId() { return mnMaxDocId++; } GetUniqueIdOString()191 inline ::rtl::OString GetUniqueIdOString() { return ::rtl::OString::valueOf( mnMaxDocId++ ); } GetUniqueIdOUString()192 inline ::rtl::OUString GetUniqueIdOUString() { return ::rtl::OUString::valueOf( mnMaxDocId++ ); } 193 194 /** Write the document properties into into the current OPC package. 195 196 @param xProperties The document properties to export. 197 198 @return *this 199 */ 200 XmlFilterBase& exportDocumentProperties( ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > xProperties ); 201 202 protected: 203 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 204 implGetInputStream( ::comphelper::MediaDescriptor& rMediaDesc ) const; 205 206 private: 207 virtual StorageRef implCreateStorage( 208 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStream ) const; 209 virtual StorageRef implCreateStorage( 210 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rxOutStream ) const; 211 212 private: 213 ::std::auto_ptr< XmlFilterBaseImpl > mxImpl; 214 sal_Int32 mnRelId; 215 sal_Int32 mnMaxDocId; 216 }; 217 218 typedef ::rtl::Reference< XmlFilterBase > XmlFilterRef; 219 220 // ============================================================================ 221 222 } // namespace core 223 } // namespace oox 224 225 #endif 226