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 CHART2_XMLFILTER_HXX 24 #define CHART2_XMLFILTER_HXX 25 26 #include <cppuhelper/implbase4.hxx> 27 #include <com/sun/star/beans/XPropertySet.hpp> 28 #include <com/sun/star/document/XFilter.hpp> 29 #include <com/sun/star/document/XImporter.hpp> 30 #include <com/sun/star/document/XExporter.hpp> 31 #include <com/sun/star/lang/XServiceInfo.hpp> 32 #include <com/sun/star/uno/XComponentContext.hpp> 33 #include <com/sun/star/io/XActiveDataSource.hpp> 34 #include <osl/mutex.hxx> 35 36 // for APPHELPER_... macros 37 #include "ServiceMacros.hxx" 38 39 namespace com { namespace sun { namespace star { 40 namespace embed 41 { 42 class XStorage; 43 } 44 namespace xml { namespace sax 45 { 46 class XParser; 47 }} 48 namespace document 49 { 50 class XGraphicObjectResolver; 51 } 52 }}} 53 54 namespace chart 55 { 56 57 class XMLFilter : public 58 ::cppu::WeakImplHelper4< 59 ::com::sun::star::document::XFilter, 60 ::com::sun::star::document::XExporter, 61 ::com::sun::star::document::XImporter, 62 ::com::sun::star::lang::XServiceInfo > 63 { 64 public: 65 explicit XMLFilter( ::com::sun::star::uno::Reference< 66 ::com::sun::star::uno::XComponentContext > const & xContext ); 67 virtual ~XMLFilter(); 68 69 /// establish methods for factory instatiation 70 APPHELPER_SERVICE_FACTORY_HELPER( XMLFilter ) 71 /// XServiceInfo declarations 72 APPHELPER_XSERVICEINFO_DECL() 73 74 protected: 75 // ____ XFilter ____ 76 virtual sal_Bool SAL_CALL filter( 77 const ::com::sun::star::uno::Sequence< 78 ::com::sun::star::beans::PropertyValue >& aDescriptor ) 79 throw (::com::sun::star::uno::RuntimeException); 80 virtual void SAL_CALL cancel() 81 throw (::com::sun::star::uno::RuntimeException); 82 83 // ____ XImporter ____ 84 virtual void SAL_CALL setTargetDocument( 85 const ::com::sun::star::uno::Reference< 86 ::com::sun::star::lang::XComponent >& Document ) 87 throw (::com::sun::star::lang::IllegalArgumentException, 88 ::com::sun::star::uno::RuntimeException); 89 90 // ____ XExporter ____ 91 virtual void SAL_CALL setSourceDocument( 92 const ::com::sun::star::uno::Reference< 93 ::com::sun::star::lang::XComponent >& Document ) 94 throw (::com::sun::star::lang::IllegalArgumentException, 95 ::com::sun::star::uno::RuntimeException); 96 getDocumentHandler() const97 inline ::rtl::OUString getDocumentHandler() const { return m_sDocumentHandler; } setDocumentHandler(const::rtl::OUString & _sDocumentHandler)98 inline void setDocumentHandler(const ::rtl::OUString& _sDocumentHandler) { m_sDocumentHandler = _sDocumentHandler; } 99 100 virtual ::rtl::OUString getMediaType(bool _bOasis); 101 102 /** fills the oasis flag only when a filtername was set 103 * 104 * \param _rMediaDescriptor 105 * \param _rOutOASIS 106 */ 107 virtual void isOasisFormat(const ::com::sun::star::uno::Sequence< 108 ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, bool & _rOutOASIS ); 109 110 private: 111 // methods 112 113 /// @return a warning code, or 0 for successful operation 114 sal_Int32 impl_Import( const ::com::sun::star::uno::Reference< 115 ::com::sun::star::lang::XComponent > & xDocumentComp, 116 const ::com::sun::star::uno::Sequence< 117 ::com::sun::star::beans::PropertyValue > & aMediaDescriptor ); 118 /// @return a warning code, or 0 for successful operation 119 sal_Int32 impl_ImportStream( 120 const ::rtl::OUString & rStreamName, 121 const ::rtl::OUString & rServiceName, 122 const ::com::sun::star::uno::Reference< 123 ::com::sun::star::embed::XStorage > & xStorage, 124 const ::com::sun::star::uno::Reference< 125 ::com::sun::star::xml::sax::XParser > & xParser, 126 const ::com::sun::star::uno::Reference< 127 ::com::sun::star::lang::XMultiComponentFactory > & xFactory, 128 const ::com::sun::star::uno::Reference< 129 ::com::sun::star::document::XGraphicObjectResolver > & xGraphicObjectResolver, 130 ::com::sun::star::uno::Reference< 131 ::com::sun::star::beans::XPropertySet >& xPropSet ); 132 133 /// @return a warning code, or 0 for successful operation 134 sal_Int32 impl_Export( const ::com::sun::star::uno::Reference< 135 ::com::sun::star::lang::XComponent > & xDocumentComp, 136 const ::com::sun::star::uno::Sequence< 137 ::com::sun::star::beans::PropertyValue > & aMediaDescriptor ); 138 /// @return a warning code, or 0 for successful operation 139 sal_Int32 impl_ExportStream( 140 const ::rtl::OUString & rStreamName, 141 const ::rtl::OUString & rServiceName, 142 const ::com::sun::star::uno::Reference< 143 ::com::sun::star::embed::XStorage > & xStorage, 144 const ::com::sun::star::uno::Reference< 145 ::com::sun::star::io::XActiveDataSource >& xActiveDataSource, 146 const ::com::sun::star::uno::Reference< 147 ::com::sun::star::lang::XMultiServiceFactory > & xFactory, 148 const ::com::sun::star::uno::Sequence< 149 ::com::sun::star::uno::Any > & rFilterProperties ); 150 151 // members 152 ::com::sun::star::uno::Reference< 153 ::com::sun::star::uno::XComponentContext > m_xContext; 154 ::com::sun::star::uno::Reference< 155 ::com::sun::star::lang::XComponent > m_xTargetDoc; 156 ::com::sun::star::uno::Reference< 157 ::com::sun::star::lang::XComponent > m_xSourceDoc; 158 ::rtl::OUString m_sDocumentHandler; // when set it will be set as doc handler 159 160 volatile bool m_bCancelOperation; 161 ::osl::Mutex m_aMutex; 162 }; 163 164 // ============================================================================= 165 class XMLReportFilterHelper : public XMLFilter 166 { 167 virtual void isOasisFormat(const ::com::sun::star::uno::Sequence< 168 ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, bool & _rOutOASIS ); 169 public: XMLReportFilterHelper(::com::sun::star::uno::Reference<::com::sun::star::uno::XComponentContext> const & _xContext)170 explicit XMLReportFilterHelper( ::com::sun::star::uno::Reference< 171 ::com::sun::star::uno::XComponentContext > const & _xContext ) 172 :XMLFilter(_xContext) 173 {} 174 /// establish methods for factory instatiation create(::com::sun::star::uno::Reference<::com::sun::star::uno::XComponentContext> const & xContext)175 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL create( 176 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext) throw(::com::sun::star::uno::Exception) 177 { 178 return (::cppu::OWeakObject *)new XMLReportFilterHelper( xContext ); 179 } getImplementationName_Static()180 static ::rtl::OUString getImplementationName_Static() 181 { 182 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.chart2.report.XMLFilter" )); 183 } 184 protected: 185 virtual ::rtl::OUString SAL_CALL getImplementationName()186 getImplementationName() 187 throw( ::com::sun::star::uno::RuntimeException ) 188 { 189 return getImplementationName_Static(); 190 } 191 // ____ XImporter ____ setTargetDocument(const::com::sun::star::uno::Reference<::com::sun::star::lang::XComponent> & Document)192 virtual void SAL_CALL setTargetDocument( 193 const ::com::sun::star::uno::Reference< 194 ::com::sun::star::lang::XComponent >& Document ) 195 throw (::com::sun::star::lang::IllegalArgumentException, 196 ::com::sun::star::uno::RuntimeException) 197 { 198 setDocumentHandler(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.ImportDocumentHandler"))); 199 XMLFilter::setTargetDocument(Document); 200 } 201 202 // ____ XExporter ____ setSourceDocument(const::com::sun::star::uno::Reference<::com::sun::star::lang::XComponent> & Document)203 virtual void SAL_CALL setSourceDocument( 204 const ::com::sun::star::uno::Reference< 205 ::com::sun::star::lang::XComponent >& Document ) 206 throw (::com::sun::star::lang::IllegalArgumentException, 207 ::com::sun::star::uno::RuntimeException) 208 { 209 setDocumentHandler(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.ExportDocumentHandler"))); 210 XMLFilter::setSourceDocument(Document); 211 } 212 213 virtual ::rtl::OUString getMediaType(bool _bOasis); 214 }; 215 216 } // namespace chart 217 218 // CHART2_XMLFILTER_HXX 219 #endif 220