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 _XMLEOHLP_HXX 25 #define _XMLEOHLP_HXX 26 27 #include <cppuhelper/compbase2.hxx> 28 #include <osl/mutex.hxx> 29 #include <sot/storage.hxx> 30 #include <map> 31 #include <com/sun/star/container/XNameContainer.hpp> 32 #include <com/sun/star/document/XEmbeddedObjectResolver.hpp> 33 #include <com/sun/star/container/XNameAccess.hpp> 34 #include <com/sun/star/embed/XEmbeddedObject.hpp> 35 #include "svx/svxdllapi.h" 36 37 // ----------------------------- 38 // - SvXMLEmbeddedObjectHelper - 39 // ----------------------------- 40 41 enum SvXMLEmbeddedObjectHelperMode 42 { 43 EMBEDDEDOBJECTHELPER_MODE_READ = 0, 44 EMBEDDEDOBJECTHELPER_MODE_WRITE = 1 45 }; 46 47 // ----------------------------- 48 // - SvXMLEmbeddedObjectHelper - 49 // ----------------------------- 50 51 namespace comphelper { 52 class IEmbeddedHelper; 53 } 54 class SvGlobalName; 55 struct OUStringLess; 56 class OutputStorageWrapper_Impl; 57 58 class SVX_DLLPUBLIC SvXMLEmbeddedObjectHelper : public ::cppu::WeakComponentImplHelper2< 59 ::com::sun::star::document::XEmbeddedObjectResolver, 60 ::com::sun::star::container::XNameAccess > 61 { 62 typedef ::std::map< ::rtl::OUString, OutputStorageWrapper_Impl*, 63 OUStringLess > SvXMLEmbeddedObjectHelper_Impl; 64 private: 65 66 ::osl::Mutex maMutex; 67 68 const ::rtl::OUString maReplacementGraphicsContainerStorageName; 69 const ::rtl::OUString maReplacementGraphicsContainerStorageName60; 70 ::rtl::OUString maCurContainerStorageName; 71 72 73 com::sun::star::uno::Reference < com::sun::star::embed::XStorage > mxRootStorage; // package 74 ::comphelper::IEmbeddedHelper* mpDocPersist; 75 com::sun::star::uno::Reference < com::sun::star::embed::XStorage > mxContainerStorage; // container sub package for 76 com::sun::star::uno::Reference < com::sun::star::embed::XStorage > mxTempStorage; // package 77 // objects 78 SvXMLEmbeddedObjectHelperMode meCreateMode; 79 SvXMLEmbeddedObjectHelper_Impl *mpStreamMap; 80 81 SVX_DLLPRIVATE sal_Bool ImplGetStorageNames( 82 const ::rtl::OUString& rURLStr, 83 ::rtl::OUString& rContainerStorageName, 84 ::rtl::OUString& rObjectStorageName, 85 sal_Bool bInternalToExternal, 86 sal_Bool *pGraphicRepl=0, 87 sal_Bool *pOasisFormat=0 ) const; 88 89 SVX_DLLPRIVATE com::sun::star::uno::Reference < com::sun::star::embed::XStorage > ImplGetContainerStorage( 90 const ::rtl::OUString& rStorageName ); 91 92 SVX_DLLPRIVATE String ImplGetUniqueName( ::comphelper::IEmbeddedHelper*, const sal_Char* p ) const; 93 SVX_DLLPRIVATE sal_Bool ImplReadObject( 94 const ::rtl::OUString& rContainerStorageName, 95 ::rtl::OUString& rObjName, 96 const SvGlobalName *pClassId, 97 SvStream* pTemp ); 98 99 SVX_DLLPRIVATE ::rtl::OUString ImplInsertEmbeddedObjectURL( 100 const ::rtl::OUString& rURLStr ); 101 102 SVX_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > ImplGetReplacementImage( 103 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XEmbeddedObject >& xObj ); 104 105 protected: 106 107 SvXMLEmbeddedObjectHelper(); 108 ~SvXMLEmbeddedObjectHelper(); 109 void Init( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >&, 110 ::comphelper::IEmbeddedHelper& rDocPersist, 111 SvXMLEmbeddedObjectHelperMode eCreateMode ); 112 113 virtual void SAL_CALL disposing(); 114 115 public: 116 SvXMLEmbeddedObjectHelper( 117 ::comphelper::IEmbeddedHelper& rDocPersist, 118 SvXMLEmbeddedObjectHelperMode eCreateMode ); 119 120 static SvXMLEmbeddedObjectHelper* Create( 121 const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >&, 122 ::comphelper::IEmbeddedHelper& rDocPersist, 123 SvXMLEmbeddedObjectHelperMode eCreateMode, 124 sal_Bool bDirect = sal_True ); 125 static SvXMLEmbeddedObjectHelper* Create( 126 ::comphelper::IEmbeddedHelper& rDocPersist, 127 SvXMLEmbeddedObjectHelperMode eCreateMode ); 128 static void Destroy( SvXMLEmbeddedObjectHelper* pSvXMLEmbeddedObjectHelper ); 129 130 void Flush(); 131 132 // XEmbeddedObjectResolver 133 virtual ::rtl::OUString SAL_CALL resolveEmbeddedObjectURL( const ::rtl::OUString& aURL ) throw(::com::sun::star::uno::RuntimeException); 134 135 // XNameAccess 136 virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 137 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (::com::sun::star::uno::RuntimeException); 138 virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException); 139 140 // XNameAccess 141 virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw (::com::sun::star::uno::RuntimeException); 142 virtual sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException); 143 }; 144 145 #endif 146