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 _OHIERARCHYHOLDER_HXX_ 25 #define _OHIERARCHYHOLDER_HXX_ 26 27 #include <com/sun/star/embed/XStorage.hpp> 28 #include <com/sun/star/embed/XTransactionListener.hpp> 29 #include <com/sun/star/embed/XExtendedStorageStream.hpp> 30 #include <cppuhelper/implbase1.hxx> 31 32 #include <comphelper/sequenceashashmap.hxx> 33 34 #include <rtl/ref.hxx> 35 36 #include <hash_map> 37 #include <list> 38 #include <vector> 39 40 struct OHierarchyElement_Impl; 41 42 struct eqFunc 43 { operator ()eqFunc44 sal_Bool operator()( const rtl::OUString &r1, 45 const rtl::OUString &r2) const 46 { 47 return r1 == r2; 48 } 49 }; 50 typedef ::std::hash_map< ::rtl::OUString, 51 ::rtl::Reference< OHierarchyElement_Impl >, 52 ::rtl::OUStringHash, 53 eqFunc > OHierarchyElementList_Impl; 54 55 typedef ::std::vector< ::rtl::OUString > OStringList_Impl; 56 typedef ::std::list< ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XExtendedStorageStream > > 57 OWeakStorRefList_Impl; 58 59 struct OHierarchyElement_Impl : public cppu::WeakImplHelper1< ::com::sun::star::embed::XTransactionListener > 60 { 61 ::osl::Mutex m_aMutex; 62 63 ::rtl::Reference< OHierarchyElement_Impl > m_rParent; 64 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xOwnStorage; 65 ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakOwnStorage; 66 67 OHierarchyElementList_Impl m_aChildren; 68 69 OWeakStorRefList_Impl m_aOpenStreams; 70 71 public: OHierarchyElement_ImplOHierarchyElement_Impl72 OHierarchyElement_Impl( OHierarchyElement_Impl* pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ) 73 : m_rParent( pParent ) 74 , m_xOwnStorage( xStorage ) 75 {} 76 OHierarchyElement_ImplOHierarchyElement_Impl77 OHierarchyElement_Impl( const ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage >& xWeakStorage ) 78 : m_rParent( NULL ) 79 , m_xWeakOwnStorage( xWeakStorage ) 80 {} 81 82 void Commit(); 83 SetParentOHierarchyElement_Impl84 void SetParent( const ::rtl::Reference< OHierarchyElement_Impl >& rParent ) { m_rParent = rParent; } 85 86 void TestForClosing(); 87 88 void RemoveElement( const ::rtl::Reference< OHierarchyElement_Impl >& aRef ); 89 90 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > 91 GetStreamHierarchically( sal_Int32 nStorageMode, 92 OStringList_Impl& aPath, 93 sal_Int32 nStreamMode, 94 const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() ); 95 96 void RemoveStreamHierarchically( OStringList_Impl& aListPath ); 97 98 // XEventListener 99 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ); 100 101 102 // XTransactionListener 103 virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent ); 104 virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent ); 105 virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent ); 106 virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& aEvent ); 107 108 }; 109 110 class OHierarchyHolder_Impl : public ::cppu::OWeakObject 111 { 112 ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakOwnStorage; 113 ::rtl::Reference< OHierarchyElement_Impl > m_xChild; 114 public: OHierarchyHolder_Impl(const::com::sun::star::uno::Reference<::com::sun::star::embed::XStorage> & xOwnStorage)115 OHierarchyHolder_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xOwnStorage ) 116 : m_xWeakOwnStorage( xOwnStorage ) 117 , m_xChild( new OHierarchyElement_Impl( ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage >( xOwnStorage ) ) ) 118 {} 119 120 static OStringList_Impl GetListPathFromString( const ::rtl::OUString& aPath ); 121 122 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > 123 GetStreamHierarchically( sal_Int32 nStorageMode, 124 OStringList_Impl& aListPath, 125 sal_Int32 nStreamMode, 126 const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() ); 127 128 void RemoveStreamHierarchically( OStringList_Impl& aListPath ); 129 }; 130 131 #endif // _OHIERARCHYHOLDER 132