1*3334a7e6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*3334a7e6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*3334a7e6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*3334a7e6SAndrew Rist * distributed with this work for additional information 6*3334a7e6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*3334a7e6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*3334a7e6SAndrew Rist * "License"); you may not use this file except in compliance 9*3334a7e6SAndrew Rist * with the License. You may obtain a copy of the License at 10*3334a7e6SAndrew Rist * 11*3334a7e6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*3334a7e6SAndrew Rist * 13*3334a7e6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*3334a7e6SAndrew Rist * software distributed under the License is distributed on an 15*3334a7e6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*3334a7e6SAndrew Rist * KIND, either express or implied. See the License for the 17*3334a7e6SAndrew Rist * specific language governing permissions and limitations 18*3334a7e6SAndrew Rist * under the License. 19*3334a7e6SAndrew Rist * 20*3334a7e6SAndrew Rist *************************************************************/ 21*3334a7e6SAndrew Rist 22*3334a7e6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _XMLGRHLP_HXX 25cdf0e10cSrcweir #define _XMLGRHLP_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx> 28cdf0e10cSrcweir #include <osl/mutex.hxx> 29cdf0e10cSrcweir #include <svtools/grfmgr.hxx> 30cdf0e10cSrcweir #include <vector> 31cdf0e10cSrcweir #include <set> 32cdf0e10cSrcweir #include <utility> 33cdf0e10cSrcweir #include <com/sun/star/document/XGraphicObjectResolver.hpp> 34cdf0e10cSrcweir #include <com/sun/star/document/XBinaryStreamResolver.hpp> 35cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp> 36cdf0e10cSrcweir #include "svx/svxdllapi.h" 37cdf0e10cSrcweir 38cdf0e10cSrcweir // ---------------------- 39cdf0e10cSrcweir // - SvXMLGraphicHelper - 40cdf0e10cSrcweir // ---------------------- 41cdf0e10cSrcweir 42cdf0e10cSrcweir enum SvXMLGraphicHelperMode 43cdf0e10cSrcweir { 44cdf0e10cSrcweir GRAPHICHELPER_MODE_READ = 0, 45cdf0e10cSrcweir GRAPHICHELPER_MODE_WRITE = 1 46cdf0e10cSrcweir }; 47cdf0e10cSrcweir 48cdf0e10cSrcweir // ---------------------- 49cdf0e10cSrcweir // - SvXMLGraphicHelper - 50cdf0e10cSrcweir // ---------------------- 51cdf0e10cSrcweir struct SvxGraphicHelperStream_Impl 52cdf0e10cSrcweir { 53cdf0e10cSrcweir ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > xStorage; 54cdf0e10cSrcweir ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream > xStream; 55cdf0e10cSrcweir }; 56cdf0e10cSrcweir 57cdf0e10cSrcweir class SVX_DLLPUBLIC SvXMLGraphicHelper : public ::cppu::WeakComponentImplHelper2< ::com::sun::star::document::XGraphicObjectResolver, 58cdf0e10cSrcweir ::com::sun::star::document::XBinaryStreamResolver > 59cdf0e10cSrcweir { 60cdf0e10cSrcweir private: 61cdf0e10cSrcweir 62cdf0e10cSrcweir typedef ::std::pair< ::rtl::OUString, ::rtl::OUString > URLPair; 63cdf0e10cSrcweir typedef ::std::vector< URLPair > URLPairVector; 64cdf0e10cSrcweir typedef ::std::vector< GraphicObject > GraphicObjectVector; 65cdf0e10cSrcweir typedef ::std::set< ::rtl::OUString > URLSet; 66cdf0e10cSrcweir typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > > GraphicOutputStreamVector; 67cdf0e10cSrcweir 68cdf0e10cSrcweir ::osl::Mutex maMutex; 69cdf0e10cSrcweir ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > mxRootStorage; 70cdf0e10cSrcweir ::rtl::OUString maCurStorageName; 71cdf0e10cSrcweir URLPairVector maGrfURLs; 72cdf0e10cSrcweir GraphicObjectVector maGrfObjs; 73cdf0e10cSrcweir GraphicOutputStreamVector maGrfStms; 74cdf0e10cSrcweir URLSet maURLSet; 75cdf0e10cSrcweir SvXMLGraphicHelperMode meCreateMode; 76cdf0e10cSrcweir sal_Bool mbDirect; 77cdf0e10cSrcweir 78cdf0e10cSrcweir SVX_DLLPRIVATE sal_Bool ImplGetStreamNames( const ::rtl::OUString& rURLStr, 79cdf0e10cSrcweir ::rtl::OUString& rPictureStorageName, 80cdf0e10cSrcweir ::rtl::OUString& rPictureStreamName ); 81cdf0e10cSrcweir SVX_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > ImplGetGraphicStorage( const ::rtl::OUString& rPictureStorageName ); 82cdf0e10cSrcweir SVX_DLLPRIVATE SvxGraphicHelperStream_Impl ImplGetGraphicStream( const ::rtl::OUString& rPictureStorageName, 83cdf0e10cSrcweir const ::rtl::OUString& rPictureStreamName, 84cdf0e10cSrcweir sal_Bool bTruncate ); 85cdf0e10cSrcweir SVX_DLLPRIVATE String ImplGetGraphicMimeType( const String& rFileName ) const; 86cdf0e10cSrcweir SVX_DLLPRIVATE Graphic ImplReadGraphic( const ::rtl::OUString& rPictureStorageName, 87cdf0e10cSrcweir const ::rtl::OUString& rPictureStreamName ); 88cdf0e10cSrcweir SVX_DLLPRIVATE sal_Bool ImplWriteGraphic( const ::rtl::OUString& rPictureStorageName, 89cdf0e10cSrcweir const ::rtl::OUString& rPictureStreamName, 90cdf0e10cSrcweir const ::rtl::OUString& rGraphicId ); 91cdf0e10cSrcweir SVX_DLLPRIVATE void ImplInsertGraphicURL( const ::rtl::OUString& rURLStr, sal_uInt32 nInsertPos, rtl::OUString& rRequestedFileName ); 92cdf0e10cSrcweir 93cdf0e10cSrcweir protected: 94cdf0e10cSrcweir SvXMLGraphicHelper(); 95cdf0e10cSrcweir ~SvXMLGraphicHelper(); 96cdf0e10cSrcweir void Init( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage >& xXMLStorage, 97cdf0e10cSrcweir SvXMLGraphicHelperMode eCreateMode, 98cdf0e10cSrcweir sal_Bool bDirect ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir virtual void SAL_CALL disposing(); 101cdf0e10cSrcweir 102cdf0e10cSrcweir public: 103cdf0e10cSrcweir SvXMLGraphicHelper( SvXMLGraphicHelperMode eCreateMode ); 104cdf0e10cSrcweir 105cdf0e10cSrcweir static SvXMLGraphicHelper* Create( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage >& rXMLStorage, 106cdf0e10cSrcweir SvXMLGraphicHelperMode eCreateMode, 107cdf0e10cSrcweir sal_Bool bDirect = sal_True ); 108cdf0e10cSrcweir static SvXMLGraphicHelper* Create( SvXMLGraphicHelperMode eCreateMode ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir static void Destroy( SvXMLGraphicHelper* pSvXMLGraphicHelper ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir public: 113cdf0e10cSrcweir 114cdf0e10cSrcweir // XGraphicObjectResolver 115cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL resolveGraphicObjectURL( const ::rtl::OUString& aURL ) throw(::com::sun::star::uno::RuntimeException); 116cdf0e10cSrcweir 117cdf0e10cSrcweir // XBinaryStreamResolver 118cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( const ::rtl::OUString& rURL ) throw (::com::sun::star::uno::RuntimeException); 119cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL createOutputStream( ) throw (::com::sun::star::uno::RuntimeException); 120cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL resolveOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rxBinaryStream ) throw (::com::sun::star::uno::RuntimeException); 121cdf0e10cSrcweir }; 122cdf0e10cSrcweir 123cdf0e10cSrcweir 124cdf0e10cSrcweir // for instantiation via service manager 125cdf0e10cSrcweir namespace svx 126cdf0e10cSrcweir { 127cdf0e10cSrcweir /** Create this with createInstanceWithArguments. service name 128cdf0e10cSrcweir "com.sun.star.comp.Svx.GraphicImportHelper", one argument which is the 129cdf0e10cSrcweir XStorage. Without arguments no helper class is created. With an empty 130cdf0e10cSrcweir argument the helper class is created and initialized like in the CTOR to 131cdf0e10cSrcweir SvXMLGraphicHelper that only gets the create mode. 132cdf0e10cSrcweir 133cdf0e10cSrcweir You should call dispose after you no longer need this component. 134cdf0e10cSrcweir 135cdf0e10cSrcweir uses eCreateMode == GRAPHICHELPER_MODE_READ, bDirect == sal_True in 136cdf0e10cSrcweir SvXMLGraphicHelper 137cdf0e10cSrcweir */ 138cdf0e10cSrcweir SVX_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SvXMLGraphicImportHelper_createInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) throw( ::com::sun::star::uno::Exception ); 139cdf0e10cSrcweir SVX_DLLPUBLIC ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL SvXMLGraphicImportHelper_getSupportedServiceNames() throw(); 140cdf0e10cSrcweir SVX_DLLPUBLIC ::rtl::OUString SAL_CALL SvXMLGraphicImportHelper_getImplementationName() throw(); 141cdf0e10cSrcweir 142cdf0e10cSrcweir /** Create this with createInstanceWithArguments. service name 143cdf0e10cSrcweir "com.sun.star.comp.Svx.GraphicExportHelper", one argument which is the 144cdf0e10cSrcweir XStorage. Without arguments no helper class is created. With an empty 145cdf0e10cSrcweir argument the helper class is created and initialized like in the CTOR to 146cdf0e10cSrcweir SvXMLGraphicHelper that only gets the create mode 147cdf0e10cSrcweir 148cdf0e10cSrcweir To write the Pictures stream, you have to call dispose at this component. 149cdf0e10cSrcweir Make sure you call dipose before you commit the parent storage. 150cdf0e10cSrcweir 151cdf0e10cSrcweir uses eCreateMode == GRAPHICHELPER_MODE_WRITE, bDirect == sal_True in 152cdf0e10cSrcweir SvXMLGraphicHelper 153cdf0e10cSrcweir */ 154cdf0e10cSrcweir SVX_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SvXMLGraphicExportHelper_createInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) throw( ::com::sun::star::uno::Exception ); 155cdf0e10cSrcweir SVX_DLLPUBLIC ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL SvXMLGraphicExportHelper_getSupportedServiceNames() throw(); 156cdf0e10cSrcweir SVX_DLLPUBLIC ::rtl::OUString SAL_CALL SvXMLGraphicExportHelper_getImplementationName() throw(); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir #endif 160