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 #ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFILTER_HXX 20 #define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFILTER_HXX 21 22 #include <com/sun/star/container/XNamed.hpp> 23 #include <com/sun/star/document/XFilter.hpp> 24 #include <com/sun/star/document/XImporter.hpp> 25 #include <com/sun/star/document/XExporter.hpp> 26 #include <com/sun/star/lang/XInitialization.hpp> 27 #include <com/sun/star/lang/XServiceInfo.hpp> 28 #include <com/sun/star/beans/XPropertySet.hpp> 29 #include <com/sun/star/lang/XComponent.hpp> 30 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 31 #include <com/sun/star/io/XActiveDataSource.hpp> 32 #include <com/sun/star/report/XReportDefinition.hpp> 33 #include <osl/diagnose.h> 34 #include <unotools/tempfile.hxx> 35 #include <unotools/localfilehelper.hxx> 36 #include <xmloff/xmlimp.hxx> 37 #include <com/sun/star/uno/XComponentContext.hpp> 38 #include <map> 39 #include <memory> 40 #include <xmloff/prhdlfac.hxx> 41 #include <xmloff/xmlprmap.hxx> 42 43 namespace rptui 44 { 45 class OReportModel; 46 } 47 namespace rptxml 48 { 49 using namespace ::xmloff::token; 50 using namespace ::com::sun::star::uno; 51 using namespace ::com::sun::star::container; 52 using namespace ::com::sun::star::lang; 53 using namespace ::com::sun::star::beans; 54 using namespace ::com::sun::star::document; 55 using namespace ::com::sun::star::text; 56 using namespace ::com::sun::star::io; 57 using namespace ::com::sun::star::report; 58 using namespace ::com::sun::star::xml::sax; 59 60 61 class ORptFilter : public SvXMLImport 62 { 63 public: 64 typedef std::map< OUString, Sequence<PropertyValue> > TPropertyNameMap; 65 typedef std::map< OUString, Reference<XFunction> > TGroupFunctionMap; 66 private: 67 68 TGroupFunctionMap m_aFunctions; 69 70 mutable ::std::unique_ptr<SvXMLTokenMap> m_pDocElemTokenMap; 71 mutable ::std::unique_ptr<SvXMLTokenMap> m_pDocContentElemTokenMap; 72 mutable ::std::unique_ptr<SvXMLTokenMap> m_pReportElemTokenMap; 73 mutable ::std::unique_ptr<SvXMLTokenMap> m_pGroupElemTokenMap; 74 mutable ::std::unique_ptr<SvXMLTokenMap> m_pSectionElemTokenMap; 75 mutable ::std::unique_ptr<SvXMLTokenMap> m_pComponentElemTokenMap; 76 mutable ::std::unique_ptr<SvXMLTokenMap> m_pElemTokenMap; 77 mutable ::std::unique_ptr<SvXMLTokenMap> m_pControlElemTokenMap; 78 mutable ::std::unique_ptr<SvXMLTokenMap> m_pFunctionElemTokenMap; 79 mutable ::std::unique_ptr<SvXMLTokenMap> m_pSubDocumentElemTokenMap; 80 mutable ::std::unique_ptr<SvXMLTokenMap> m_pFormatElemTokenMap; 81 mutable ::std::unique_ptr<SvXMLTokenMap> m_pColumnTokenMap; 82 mutable ::std::unique_ptr<SvXMLTokenMap> m_pCellElemTokenMap; 83 84 rtl::Reference < XMLPropertyHandlerFactory > m_xPropHdlFactory; 85 rtl::Reference < XMLPropertySetMapper > m_xCellStylesPropertySetMapper; 86 rtl::Reference < XMLPropertySetMapper > m_xColumnStylesPropertySetMapper; 87 rtl::Reference < XMLPropertySetMapper > m_xRowStylesPropertySetMapper; 88 89 Reference<XReportDefinition> m_xReportDefinition; 90 std::shared_ptr<rptui::OReportModel> m_pReportModel; 91 92 /// @throws RuntimeException 93 bool implImport( const Sequence< PropertyValue >& rDescriptor ); 94 95 public: 96 using SvXMLImport::SetMasterStyles; 97 SvXMLImportContext* CreateStylesContext(const OUString& rLocalName, 98 const Reference< XAttributeList>& xAttrList, bool bIsAutoStyle ); 99 SvXMLImportContext* CreateMetaContext(const sal_Int32 nElement); 100 SvXMLImportContext* CreateFontDeclsContext(const OUString& rLocalName, 101 const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ); 102 protected: 103 // SvXMLImport 104 virtual SvXMLImportContext *CreateDocumentContext( sal_uInt16 nPrefix, 105 const OUString& rLocalName, 106 const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override; 107 108 virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement, 109 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; 110 111 virtual XMLShapeImportHelper* CreateShapeImport() override; 112 113 virtual ~ORptFilter() throw() override; 114 public: 115 116 ORptFilter( const Reference< XComponentContext >& _rxContext, SvXMLImportFlags nImportFlags = SvXMLImportFlags::ALL ); 117 118 // XFilter 119 virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& rDescriptor ) override; 120 121 /// @throws css::uno::RuntimeException 122 static css::uno::Sequence< OUString > getSupportedServiceNames_Static(); 123 /// @throws css::uno::RuntimeException 124 static OUString getImplementationName_Static(); 125 static css::uno::Reference< css::uno::XInterface > 126 create(css::uno::Reference< css::uno::XComponentContext > const & xContext); 127 getReportDefinition() const128 const Reference<XReportDefinition>& getReportDefinition() const { 129 return m_xReportDefinition; 130 } 131 void FinishStyles(); 132 133 virtual void SAL_CALL startDocument() override; 134 virtual void SAL_CALL endDocument() override; 135 136 const SvXMLTokenMap& GetDocElemTokenMap() const; 137 const SvXMLTokenMap& GetDocContentElemTokenMap() const; 138 const SvXMLTokenMap& GetReportElemTokenMap() const; 139 const SvXMLTokenMap& GetGroupElemTokenMap() const; 140 const SvXMLTokenMap& GetSectionElemTokenMap() const; 141 const SvXMLTokenMap& GetComponentElemTokenMap() const; 142 const SvXMLTokenMap& GetReportElementElemTokenMap() const; 143 const SvXMLTokenMap& GetControlElemTokenMap() const; 144 const SvXMLTokenMap& GetControlPropertyElemTokenMap() const; 145 const SvXMLTokenMap& GetFunctionElemTokenMap() const; 146 const SvXMLTokenMap& GetFormatElemTokenMap() const; 147 const SvXMLTokenMap& GetSubDocumentElemTokenMap() const; 148 const SvXMLTokenMap& GetColumnTokenMap() const; 149 const SvXMLTokenMap& GetCellElemTokenMap() const; 150 GetCellStylesPropertySetMapper() const151 const rtl::Reference< XMLPropertySetMapper >& GetCellStylesPropertySetMapper() const { 152 return m_xCellStylesPropertySetMapper; 153 } GetColumnStylesPropertySetMapper() const154 const rtl::Reference< XMLPropertySetMapper >& GetColumnStylesPropertySetMapper() const { 155 return m_xColumnStylesPropertySetMapper; 156 } GetRowStylesPropertySetMapper() const157 const rtl::Reference< XMLPropertySetMapper >& GetRowStylesPropertySetMapper() const { 158 return m_xRowStylesPropertySetMapper; 159 } 160 static const OUString& convertFormula(const OUString& _sFormula); 161 /** inserts a new function 162 * 163 * \param _xFunction 164 */ 165 void insertFunction(const css::uno::Reference< css::report::XFunction > & _xFunction); 166 void removeFunction(const OUString& _sFunctionName); getFunctions() const167 const TGroupFunctionMap& getFunctions() const { 168 return m_aFunctions; 169 } 170 171 bool isOldFormat() const; 172 }; 173 174 /** Imports only settings 175 * \ingroup reportdesign_source_filter_xml 176 * 177 */ 178 class ORptImportHelper 179 { 180 public: 181 /// @throws css::uno::RuntimeException 182 static OUString getImplementationName_Static( ); 183 /// @throws css::uno::RuntimeException 184 static Sequence< OUString > getSupportedServiceNames_Static( ); 185 static css::uno::Reference< css::uno::XInterface > 186 create(css::uno::Reference< css::uno::XComponentContext > const & xContext); 187 }; 188 189 /** Imports only content 190 * \ingroup reportdesign_source_filter_xml 191 * 192 */ 193 class ORptContentImportHelper 194 { 195 public: 196 /// @throws css::uno::RuntimeException 197 static OUString getImplementationName_Static( ); 198 /// @throws css::uno::RuntimeException 199 static Sequence< OUString > getSupportedServiceNames_Static( ); 200 static css::uno::Reference< css::uno::XInterface > 201 create(css::uno::Reference< css::uno::XComponentContext > const & xContext); 202 }; 203 204 /** Imports only styles 205 * \ingroup reportdesign_source_filter_xml 206 * 207 */ 208 class ORptStylesImportHelper 209 { 210 public: 211 /// @throws css::uno::RuntimeException 212 static OUString getImplementationName_Static( ); 213 /// @throws css::uno::RuntimeException 214 static Sequence< OUString > getSupportedServiceNames_Static( ); 215 static css::uno::Reference< css::uno::XInterface > 216 create(css::uno::Reference< css::uno::XComponentContext > const & xContext); 217 }; 218 219 /** Imports only meta data 220 * \ingroup reportdesign_source_filter_xml 221 * 222 */ 223 class ORptMetaImportHelper 224 { 225 public: 226 /// @throws css::uno::RuntimeException 227 static OUString getImplementationName_Static( ); 228 /// @throws css::uno::RuntimeException 229 static Sequence< OUString > getSupportedServiceNames_Static( ); 230 static css::uno::Reference< css::uno::XInterface > 231 create(css::uno::Reference< css::uno::XComponentContext > const & xContext); 232 }; 233 234 235 class RptXMLDocumentBodyContext : public SvXMLImportContext 236 { 237 public: RptXMLDocumentBodyContext(SvXMLImport & rImport,sal_uInt16 const nPrefix,const OUString & rLocalName)238 RptXMLDocumentBodyContext(SvXMLImport & rImport, 239 sal_uInt16 const nPrefix, 240 const OUString& rLocalName) 241 : SvXMLImportContext(rImport, nPrefix, rLocalName) 242 { 243 } 244 245 virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 const nPrefix, 246 const OUString& rLocalName, 247 const css::uno::Reference<css::xml::sax::XAttributeList> & xAttrList) override; 248 }; 249 250 } // rptxml 251 252 #endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFILTER_HXX 253 254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 255