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 _XMLGRHLP_HXX 25 #define _XMLGRHLP_HXX 26 27 #include <cppuhelper/compbase2.hxx> 28 #include <osl/mutex.hxx> 29 #include <svtools/grfmgr.hxx> 30 #include <vector> 31 #include <set> 32 #include <utility> 33 #include <com/sun/star/document/XGraphicObjectResolver.hpp> 34 #include <com/sun/star/document/XBinaryStreamResolver.hpp> 35 #include <com/sun/star/embed/XStorage.hpp> 36 #include "svx/svxdllapi.h" 37 38 // ---------------------- 39 // - SvXMLGraphicHelper - 40 // ---------------------- 41 42 enum SvXMLGraphicHelperMode 43 { 44 GRAPHICHELPER_MODE_READ = 0, 45 GRAPHICHELPER_MODE_WRITE = 1 46 }; 47 48 // ---------------------- 49 // - SvXMLGraphicHelper - 50 // ---------------------- 51 struct SvxGraphicHelperStream_Impl 52 { 53 ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > xStorage; 54 ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream > xStream; 55 }; 56 57 class SVX_DLLPUBLIC SvXMLGraphicHelper : public ::cppu::WeakComponentImplHelper2< ::com::sun::star::document::XGraphicObjectResolver, 58 ::com::sun::star::document::XBinaryStreamResolver > 59 { 60 private: 61 62 typedef ::std::pair< ::rtl::OUString, ::rtl::OUString > URLPair; 63 typedef ::std::vector< URLPair > URLPairVector; 64 typedef ::std::vector< GraphicObject > GraphicObjectVector; 65 typedef ::std::set< ::rtl::OUString > URLSet; 66 typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > > GraphicOutputStreamVector; 67 68 ::osl::Mutex maMutex; 69 ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > mxRootStorage; 70 ::rtl::OUString maCurStorageName; 71 URLPairVector maGrfURLs; 72 GraphicObjectVector maGrfObjs; 73 GraphicOutputStreamVector maGrfStms; 74 URLSet maURLSet; 75 SvXMLGraphicHelperMode meCreateMode; 76 sal_Bool mbDirect; 77 78 SVX_DLLPRIVATE sal_Bool ImplGetStreamNames( const ::rtl::OUString& rURLStr, 79 ::rtl::OUString& rPictureStorageName, 80 ::rtl::OUString& rPictureStreamName ); 81 SVX_DLLPRIVATE ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage > ImplGetGraphicStorage( const ::rtl::OUString& rPictureStorageName ); 82 SVX_DLLPRIVATE SvxGraphicHelperStream_Impl ImplGetGraphicStream( const ::rtl::OUString& rPictureStorageName, 83 const ::rtl::OUString& rPictureStreamName, 84 sal_Bool bTruncate ); 85 SVX_DLLPRIVATE String ImplGetGraphicMimeType( const String& rFileName ) const; 86 SVX_DLLPRIVATE Graphic ImplReadGraphic( const ::rtl::OUString& rPictureStorageName, 87 const ::rtl::OUString& rPictureStreamName ); 88 SVX_DLLPRIVATE sal_Bool ImplWriteGraphic( const ::rtl::OUString& rPictureStorageName, 89 const ::rtl::OUString& rPictureStreamName, 90 const ::rtl::OUString& rGraphicId ); 91 SVX_DLLPRIVATE void ImplInsertGraphicURL( const ::rtl::OUString& rURLStr, sal_uInt32 nInsertPos, rtl::OUString& rRequestedFileName ); 92 93 protected: 94 SvXMLGraphicHelper(); 95 ~SvXMLGraphicHelper(); 96 void Init( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage >& xXMLStorage, 97 SvXMLGraphicHelperMode eCreateMode, 98 sal_Bool bDirect ); 99 100 virtual void SAL_CALL disposing(); 101 102 public: 103 SvXMLGraphicHelper( SvXMLGraphicHelperMode eCreateMode ); 104 105 static SvXMLGraphicHelper* Create( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XStorage >& rXMLStorage, 106 SvXMLGraphicHelperMode eCreateMode, 107 sal_Bool bDirect = sal_True ); 108 static SvXMLGraphicHelper* Create( SvXMLGraphicHelperMode eCreateMode ); 109 110 static void Destroy( SvXMLGraphicHelper* pSvXMLGraphicHelper ); 111 112 public: 113 114 // XGraphicObjectResolver 115 virtual ::rtl::OUString SAL_CALL resolveGraphicObjectURL( const ::rtl::OUString& aURL ) throw(::com::sun::star::uno::RuntimeException); 116 117 // XBinaryStreamResolver 118 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( const ::rtl::OUString& rURL ) throw (::com::sun::star::uno::RuntimeException); 119 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL createOutputStream( ) throw (::com::sun::star::uno::RuntimeException); 120 virtual ::rtl::OUString SAL_CALL resolveOutputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rxBinaryStream ) throw (::com::sun::star::uno::RuntimeException); 121 }; 122 123 124 // for instantiation via service manager 125 namespace svx 126 { 127 /** Create this with createInstanceWithArguments. service name 128 "com.sun.star.comp.Svx.GraphicImportHelper", one argument which is the 129 XStorage. Without arguments no helper class is created. With an empty 130 argument the helper class is created and initialized like in the CTOR to 131 SvXMLGraphicHelper that only gets the create mode. 132 133 You should call dispose after you no longer need this component. 134 135 uses eCreateMode == GRAPHICHELPER_MODE_READ, bDirect == sal_True in 136 SvXMLGraphicHelper 137 */ 138 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 ); 139 SVX_DLLPUBLIC ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL SvXMLGraphicImportHelper_getSupportedServiceNames() throw(); 140 SVX_DLLPUBLIC ::rtl::OUString SAL_CALL SvXMLGraphicImportHelper_getImplementationName() throw(); 141 142 /** Create this with createInstanceWithArguments. service name 143 "com.sun.star.comp.Svx.GraphicExportHelper", one argument which is the 144 XStorage. Without arguments no helper class is created. With an empty 145 argument the helper class is created and initialized like in the CTOR to 146 SvXMLGraphicHelper that only gets the create mode 147 148 To write the Pictures stream, you have to call dispose at this component. 149 Make sure you call dipose before you commit the parent storage. 150 151 uses eCreateMode == GRAPHICHELPER_MODE_WRITE, bDirect == sal_True in 152 SvXMLGraphicHelper 153 */ 154 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 ); 155 SVX_DLLPUBLIC ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL SvXMLGraphicExportHelper_getSupportedServiceNames() throw(); 156 SVX_DLLPUBLIC ::rtl::OUString SAL_CALL SvXMLGraphicExportHelper_getImplementationName() throw(); 157 } 158 159 #endif 160