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 #ifndef RPT_XMLFILTER_HXX 24 #define RPT_XMLFILTER_HXX 25 26 #include <com/sun/star/container/XNamed.hpp> 27 #include <com/sun/star/document/XFilter.hpp> 28 #include <com/sun/star/document/XImporter.hpp> 29 #include <com/sun/star/document/XExporter.hpp> 30 #include <com/sun/star/lang/XInitialization.hpp> 31 #include <com/sun/star/lang/XServiceInfo.hpp> 32 #include <com/sun/star/beans/XPropertySet.hpp> 33 #include <com/sun/star/lang/XComponent.hpp> 34 #include <cppuhelper/implbase1.hxx> 35 #include <cppuhelper/implbase5.hxx> 36 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 37 #include <com/sun/star/io/XActiveDataSource.hpp> 38 #include <com/sun/star/report/XReportDefinition.hpp> 39 #include <osl/diagnose.h> 40 #include <unotools/tempfile.hxx> 41 #include <unotools/localfilehelper.hxx> 42 #include <unotools/ucbstreamhelper.hxx> 43 #include <xmloff/xmlimp.hxx> 44 #include <comphelper/stl_types.hxx> 45 #include <comphelper/sequence.hxx> 46 #include <com/sun/star/uno/XComponentContext.hpp> 47 #include <memory> 48 #include <boost/shared_ptr.hpp> 49 #include <xmloff/prhdlfac.hxx> 50 #include <xmloff/xmlprmap.hxx> 51 52 namespace rptui 53 { 54 class OReportModel; 55 } 56 namespace rptxml 57 { 58 using namespace ::xmloff::token; 59 using namespace ::com::sun::star::uno; 60 using namespace ::com::sun::star::container; 61 using namespace ::com::sun::star::lang; 62 using namespace ::com::sun::star::beans; 63 using namespace ::com::sun::star::document; 64 using namespace ::com::sun::star::text; 65 using namespace ::com::sun::star::io; 66 using namespace ::com::sun::star::report; 67 using namespace ::com::sun::star::xml::sax; 68 69 // ------------- 70 // - ORptFilter - 71 // ------------- 72 class ORptFilter : public SvXMLImport 73 { 74 public: 75 DECLARE_STL_USTRINGACCESS_MAP(Sequence<PropertyValue>,TPropertyNameMap); 76 DECLARE_STL_USTRINGACCESS_MAP( Reference<XFunction> ,TGroupFunctionMap); 77 private: 78 79 TGroupFunctionMap m_aFunctions; 80 com::sun::star::uno::Any m_aViewSettings; 81 Reference< XComponent > m_xSrcDoc; 82 mutable ::std::auto_ptr<SvXMLTokenMap> m_pDocElemTokenMap; 83 mutable ::std::auto_ptr<SvXMLTokenMap> m_pReportElemTokenMap; 84 mutable ::std::auto_ptr<SvXMLTokenMap> m_pGroupsElemTokenMap; 85 mutable ::std::auto_ptr<SvXMLTokenMap> m_pGroupElemTokenMap; 86 mutable ::std::auto_ptr<SvXMLTokenMap> m_pSectionElemTokenMap; 87 mutable ::std::auto_ptr<SvXMLTokenMap> m_pComponentElemTokenMap; 88 mutable ::std::auto_ptr<SvXMLTokenMap> m_pElemTokenMap; 89 mutable ::std::auto_ptr<SvXMLTokenMap> m_pControlElemTokenMap; 90 mutable ::std::auto_ptr<SvXMLTokenMap> m_pFunctionElemTokenMap; 91 mutable ::std::auto_ptr<SvXMLTokenMap> m_pSubDocumentElemTokenMap; 92 mutable ::std::auto_ptr<SvXMLTokenMap> m_pFormatElemTokenMap; 93 mutable ::std::auto_ptr<SvXMLTokenMap> m_pColumnTokenMap; 94 mutable ::std::auto_ptr<SvXMLTokenMap> m_pCellElemTokenMap; 95 96 UniReference < XMLPropertyHandlerFactory > m_xPropHdlFactory; 97 UniReference < XMLPropertySetMapper > m_xCellStylesPropertySetMapper; 98 UniReference < XMLPropertySetMapper > m_xColumnStylesPropertySetMapper; 99 UniReference < XMLPropertySetMapper > m_xRowStylesPropertySetMapper; 100 UniReference < XMLPropertySetMapper > m_xTableStylesPropertySetMapper; 101 102 Reference<XReportDefinition> m_xReportDefinition; 103 ::boost::shared_ptr<rptui::OReportModel> m_pReportModel; 104 105 sal_Bool implImport( const Sequence< PropertyValue >& rDescriptor ) throw (RuntimeException); 106 107 SvXMLImportContext* CreateStylesContext(const ::rtl::OUString& rLocalName, 108 const Reference< XAttributeList>& xAttrList, sal_Bool bIsAutoStyle ); 109 SvXMLImportContext* CreateMetaContext(const ::rtl::OUString& rLocalName, 110 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); 111 SvXMLImportContext* CreateFontDeclsContext(const ::rtl::OUString& rLocalName, 112 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); 113 protected: 114 // SvXMLImport 115 virtual SvXMLImportContext *CreateContext( sal_uInt16 nPrefix, 116 const ::rtl::OUString& rLocalName, 117 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); 118 119 virtual XMLShapeImportHelper* CreateShapeImport(); 120 121 virtual ~ORptFilter() throw(); 122 public: 123 124 ORptFilter( const Reference< XMultiServiceFactory >& _rxMSF,sal_uInt16 nImportFlags = IMPORT_ALL ); 125 126 // XFilter 127 virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& rDescriptor ) throw(RuntimeException); 128 129 // ::com::sun::star::lang::XServiceInfo 130 virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); 131 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 132 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 133 134 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException ); 135 static ::rtl::OUString getImplementationName_Static(void) throw( ::com::sun::star::uno::RuntimeException ); 136 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL 137 create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext); 138 getORB()139 inline Reference< XMultiServiceFactory > getORB() { return SvXMLImport::getServiceFactory(); } getReportDefinition() const140 inline Reference<XReportDefinition> getReportDefinition() const { return m_xReportDefinition; } 141 /** return the SdrModel of the real model 142 * 143 * \return 144 */ getSdrModel() const145 ::boost::shared_ptr<rptui::OReportModel> getSdrModel() const { return m_pReportModel; } 146 void FinishStyles(); 147 148 virtual void SAL_CALL startDocument(void) 149 throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException ); 150 virtual void SAL_CALL endDocument(void) 151 throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException ); 152 153 const SvXMLTokenMap& GetDocElemTokenMap() const; 154 const SvXMLTokenMap& GetReportElemTokenMap() const; 155 const SvXMLTokenMap& GetGroupElemTokenMap() const; 156 const SvXMLTokenMap& GetSectionElemTokenMap() const; 157 const SvXMLTokenMap& GetComponentElemTokenMap() const; 158 const SvXMLTokenMap& GetReportElementElemTokenMap() const; 159 const SvXMLTokenMap& GetControlElemTokenMap() const; 160 const SvXMLTokenMap& GetControlPropertyElemTokenMap() const; 161 const SvXMLTokenMap& GetFunctionElemTokenMap() const; 162 const SvXMLTokenMap& GetFormatElemTokenMap() const; 163 const SvXMLTokenMap& GetSubDocumentElemTokenMap() const; 164 const SvXMLTokenMap& GetColumnTokenMap() const; 165 const SvXMLTokenMap& GetCellElemTokenMap() const; 166 GetCellStylesPropertySetMapper() const167 inline UniReference < XMLPropertySetMapper > GetCellStylesPropertySetMapper() const { return m_xCellStylesPropertySetMapper; } GetColumnStylesPropertySetMapper() const168 inline UniReference < XMLPropertySetMapper > GetColumnStylesPropertySetMapper() const { return m_xColumnStylesPropertySetMapper; } GetRowStylesPropertySetMapper() const169 inline UniReference < XMLPropertySetMapper > GetRowStylesPropertySetMapper() const { return m_xRowStylesPropertySetMapper; } GetTableStylesPropertySetMapper() const170 inline UniReference < XMLPropertySetMapper > GetTableStylesPropertySetMapper() const { return m_xTableStylesPropertySetMapper; } 171 static ::rtl::OUString convertFormula(const ::rtl::OUString& _sFormula); 172 /** inserts a new function 173 * 174 * \param _xFunction 175 */ 176 void insertFunction(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XFunction > & _xFunction); 177 void removeFunction(const ::rtl::OUString& _sFunctionName); getFunctions() const178 inline const TGroupFunctionMap& getFunctions() const { return m_aFunctions; } 179 180 virtual SvXMLImport& getGlobalContext(); 181 182 virtual void enterEventContext(); 183 virtual void leaveEventContext(); 184 185 sal_Bool isOldFormat() const; 186 }; 187 188 /** Imports only settings 189 * \ingroup reportdesign_source_filter_xml 190 * 191 */ 192 class ORptImportHelper 193 { 194 public: 195 static ::rtl::OUString getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException); 196 static Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException); 197 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL 198 create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext); 199 }; 200 201 /** Imports only content 202 * \ingroup reportdesign_source_filter_xml 203 * 204 */ 205 class ORptContentImportHelper 206 { 207 public: 208 static ::rtl::OUString getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException); 209 static Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException); 210 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL 211 create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext); 212 }; 213 214 /** Imports only styles 215 * \ingroup reportdesign_source_filter_xml 216 * 217 */ 218 class ORptStylesImportHelper 219 { 220 public: 221 static ::rtl::OUString getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException); 222 static Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException); 223 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL 224 create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext); 225 }; 226 227 /** Imports only meta data 228 * \ingroup reportdesign_source_filter_xml 229 * 230 */ 231 class ORptMetaImportHelper 232 { 233 public: 234 static ::rtl::OUString getImplementationName_Static( ) throw (::com::sun::star::uno::RuntimeException); 235 static Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw(::com::sun::star::uno::RuntimeException); 236 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL 237 create(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext); 238 }; 239 240 // ----------------------------------------------------------------------------- 241 } // rptxml 242 // ----------------------------------------------------------------------------- 243 #endif // RPT_XMLFILTER_HXX 244