1e1f63238SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3e1f63238SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4e1f63238SAndrew Rist * or more contributor license agreements. See the NOTICE file
5e1f63238SAndrew Rist * distributed with this work for additional information
6e1f63238SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7e1f63238SAndrew Rist * to you under the Apache License, Version 2.0 (the
8e1f63238SAndrew Rist * "License"); you may not use this file except in compliance
9e1f63238SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11e1f63238SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13e1f63238SAndrew Rist * Unless required by applicable law or agreed to in writing,
14e1f63238SAndrew Rist * software distributed under the License is distributed on an
15e1f63238SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16e1f63238SAndrew Rist * KIND, either express or implied. See the License for the
17e1f63238SAndrew Rist * specific language governing permissions and limitations
18e1f63238SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20e1f63238SAndrew Rist *************************************************************/
21e1f63238SAndrew Rist
22e1f63238SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_basic.hxx"
26cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
27cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp>
28cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
29cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
31cdf0e10cSrcweir #include <vcl/svapp.hxx>
32cdf0e10cSrcweir #include <vos/mutex.hxx>
33cdf0e10cSrcweir #include <tools/errinf.hxx>
34cdf0e10cSrcweir #include <osl/mutex.hxx>
35cdf0e10cSrcweir #include <vos/diagnose.hxx>
36cdf0e10cSrcweir #include <rtl/uri.hxx>
37cdf0e10cSrcweir #include <rtl/strbuf.hxx>
38cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
39cdf0e10cSrcweir #include <comphelper/anytostring.hxx>
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include "namecont.hxx"
42cdf0e10cSrcweir #include <basic/basicmanagerrepository.hxx>
43cdf0e10cSrcweir #include <tools/diagnose_ex.h>
44cdf0e10cSrcweir #include <tools/urlobj.hxx>
45cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
46cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
47cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
48cdf0e10cSrcweir #include <svtools/ehdl.hxx>
49cdf0e10cSrcweir #include <basic/basmgr.hxx>
50cdf0e10cSrcweir #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
51cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp>
52cdf0e10cSrcweir #include <com/sun/star/xml/sax/InputSource.hpp>
53cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
54cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
55cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
56cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
57cdf0e10cSrcweir #include <com/sun/star/uno/DeploymentException.hpp>
58cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
59cdf0e10cSrcweir #include <com/sun/star/script/LibraryNotLoadedException.hpp>
60cdf0e10cSrcweir #include <com/sun/star/script/vba/VBAScriptEventId.hpp>
61cdf0e10cSrcweir #include <com/sun/star/deployment/ExtensionManager.hpp>
62cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
63cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
64cdf0e10cSrcweir #include <basic/sbmod.hxx>
65cdf0e10cSrcweir
66cdf0e10cSrcweir namespace basic
67cdf0e10cSrcweir {
68cdf0e10cSrcweir
69cdf0e10cSrcweir using namespace com::sun::star::document;
70cdf0e10cSrcweir using namespace com::sun::star::container;
71cdf0e10cSrcweir using namespace com::sun::star::uno;
72cdf0e10cSrcweir using namespace com::sun::star::lang;
73cdf0e10cSrcweir using namespace com::sun::star::io;
74cdf0e10cSrcweir using namespace com::sun::star::ucb;
75cdf0e10cSrcweir using namespace com::sun::star::script;
76cdf0e10cSrcweir using namespace com::sun::star::beans;
77cdf0e10cSrcweir using namespace com::sun::star::xml::sax;
78cdf0e10cSrcweir using namespace com::sun::star::util;
79cdf0e10cSrcweir using namespace com::sun::star::task;
80cdf0e10cSrcweir using namespace com::sun::star::embed;
81cdf0e10cSrcweir using namespace com::sun::star::frame;
82cdf0e10cSrcweir using namespace com::sun::star::deployment;
83cdf0e10cSrcweir using namespace com::sun::star;
84cdf0e10cSrcweir using namespace cppu;
85cdf0e10cSrcweir using namespace rtl;
86cdf0e10cSrcweir using namespace osl;
87cdf0e10cSrcweir
88cdf0e10cSrcweir using com::sun::star::uno::Reference;
89cdf0e10cSrcweir
90cdf0e10cSrcweir // #i34411: Flag for error handling during migration
91cdf0e10cSrcweir static bool GbMigrationSuppressErrors = false;
92cdf0e10cSrcweir
93cdf0e10cSrcweir //============================================================================
94cdf0e10cSrcweir // Implementation class NameContainer
95cdf0e10cSrcweir
96cdf0e10cSrcweir // Methods XElementAccess
getElementType()97cdf0e10cSrcweir Type NameContainer::getElementType()
98cdf0e10cSrcweir throw(RuntimeException)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir return mType;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
hasElements()103cdf0e10cSrcweir sal_Bool NameContainer::hasElements()
104cdf0e10cSrcweir throw(RuntimeException)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir sal_Bool bRet = (mnElementCount > 0);
107cdf0e10cSrcweir return bRet;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir // Methods XNameAccess
getByName(const OUString & aName)111cdf0e10cSrcweir Any NameContainer::getByName( const OUString& aName )
112cdf0e10cSrcweir throw(NoSuchElementException, WrappedTargetException, RuntimeException)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir NameContainerNameMap::iterator aIt = mHashMap.find( aName );
115cdf0e10cSrcweir if( aIt == mHashMap.end() )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir throw NoSuchElementException();
118cdf0e10cSrcweir }
119cdf0e10cSrcweir sal_Int32 iHashResult = (*aIt).second;
120cdf0e10cSrcweir Any aRetAny = mValues.getConstArray()[ iHashResult ];
121cdf0e10cSrcweir return aRetAny;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
getElementNames()124cdf0e10cSrcweir Sequence< OUString > NameContainer::getElementNames()
125cdf0e10cSrcweir throw(RuntimeException)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir return mNames;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir
hasByName(const OUString & aName)130cdf0e10cSrcweir sal_Bool NameContainer::hasByName( const OUString& aName )
131cdf0e10cSrcweir throw(RuntimeException)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir NameContainerNameMap::iterator aIt = mHashMap.find( aName );
134cdf0e10cSrcweir sal_Bool bRet = ( aIt != mHashMap.end() );
135cdf0e10cSrcweir return bRet;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir
138cdf0e10cSrcweir
139cdf0e10cSrcweir // Methods XNameReplace
replaceByName(const OUString & aName,const Any & aElement)140cdf0e10cSrcweir void NameContainer::replaceByName( const OUString& aName, const Any& aElement )
141cdf0e10cSrcweir throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
142cdf0e10cSrcweir {
143cdf0e10cSrcweir Type aAnyType = aElement.getValueType();
144cdf0e10cSrcweir if( mType != aAnyType )
145cdf0e10cSrcweir throw IllegalArgumentException();
146cdf0e10cSrcweir
147cdf0e10cSrcweir NameContainerNameMap::iterator aIt = mHashMap.find( aName );
148cdf0e10cSrcweir if( aIt == mHashMap.end() )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir throw NoSuchElementException();
151cdf0e10cSrcweir }
152cdf0e10cSrcweir sal_Int32 iHashResult = (*aIt).second;
153cdf0e10cSrcweir Any aOldElement = mValues.getConstArray()[ iHashResult ];
154cdf0e10cSrcweir mValues.getArray()[ iHashResult ] = aElement;
155cdf0e10cSrcweir
156cdf0e10cSrcweir
157cdf0e10cSrcweir // Fire event
158cdf0e10cSrcweir if( maContainerListeners.getLength() > 0 )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir ContainerEvent aEvent;
161cdf0e10cSrcweir aEvent.Source = mpxEventSource;
162cdf0e10cSrcweir aEvent.Accessor <<= aName;
163cdf0e10cSrcweir aEvent.Element = aElement;
164cdf0e10cSrcweir aEvent.ReplacedElement = aOldElement;
165cdf0e10cSrcweir maContainerListeners.notifyEach( &XContainerListener::elementReplaced, aEvent );
166cdf0e10cSrcweir }
167cdf0e10cSrcweir
168cdf0e10cSrcweir /* After the container event has been fired (one listener will update the
169cdf0e10cSrcweir core Basic manager), fire change event. Listeners can rely that the
170cdf0e10cSrcweir Basic source code of the core Basic manager is up-to-date. */
171cdf0e10cSrcweir if( maChangesListeners.getLength() > 0 )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir ChangesEvent aEvent;
174cdf0e10cSrcweir aEvent.Source = mpxEventSource;
175cdf0e10cSrcweir aEvent.Base <<= aEvent.Source;
176cdf0e10cSrcweir aEvent.Changes.realloc( 1 );
177cdf0e10cSrcweir aEvent.Changes[ 0 ].Accessor <<= aName;
178cdf0e10cSrcweir aEvent.Changes[ 0 ].Element <<= aElement;
179cdf0e10cSrcweir aEvent.Changes[ 0 ].ReplacedElement = aOldElement;
180cdf0e10cSrcweir maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
181cdf0e10cSrcweir }
182cdf0e10cSrcweir }
183cdf0e10cSrcweir
184cdf0e10cSrcweir
185cdf0e10cSrcweir // Methods XNameContainer
insertByName(const OUString & aName,const Any & aElement)186cdf0e10cSrcweir void NameContainer::insertByName( const OUString& aName, const Any& aElement )
187cdf0e10cSrcweir throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir Type aAnyType = aElement.getValueType();
190cdf0e10cSrcweir if( mType != aAnyType )
191cdf0e10cSrcweir throw IllegalArgumentException();
192cdf0e10cSrcweir
193cdf0e10cSrcweir NameContainerNameMap::iterator aIt = mHashMap.find( aName );
194cdf0e10cSrcweir if( aIt != mHashMap.end() )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir throw ElementExistException();
197cdf0e10cSrcweir }
198cdf0e10cSrcweir
199cdf0e10cSrcweir sal_Int32 nCount = mNames.getLength();
200cdf0e10cSrcweir mNames.realloc( nCount + 1 );
201cdf0e10cSrcweir mValues.realloc( nCount + 1 );
202cdf0e10cSrcweir mNames.getArray()[ nCount ] = aName;
203cdf0e10cSrcweir mValues.getArray()[ nCount ] = aElement;
204cdf0e10cSrcweir
205cdf0e10cSrcweir mHashMap[ aName ] = nCount;
206cdf0e10cSrcweir mnElementCount++;
207cdf0e10cSrcweir
208cdf0e10cSrcweir // Fire event
209cdf0e10cSrcweir if( maContainerListeners.getLength() > 0 )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir ContainerEvent aEvent;
212cdf0e10cSrcweir aEvent.Source = mpxEventSource;
213cdf0e10cSrcweir aEvent.Accessor <<= aName;
214cdf0e10cSrcweir aEvent.Element = aElement;
215cdf0e10cSrcweir maContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent );
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
218cdf0e10cSrcweir /* After the container event has been fired (one listener will update the
219cdf0e10cSrcweir core Basic manager), fire change event. Listeners can rely that the
220cdf0e10cSrcweir Basic source code of the core Basic manager is up-to-date. */
221cdf0e10cSrcweir if( maChangesListeners.getLength() > 0 )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir ChangesEvent aEvent;
224cdf0e10cSrcweir aEvent.Source = mpxEventSource;
225cdf0e10cSrcweir aEvent.Base <<= aEvent.Source;
226cdf0e10cSrcweir aEvent.Changes.realloc( 1 );
227cdf0e10cSrcweir aEvent.Changes[ 0 ].Accessor <<= aName;
228cdf0e10cSrcweir aEvent.Changes[ 0 ].Element <<= aElement;
229cdf0e10cSrcweir maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
230cdf0e10cSrcweir }
231cdf0e10cSrcweir }
232cdf0e10cSrcweir
removeByName(const OUString & aName)233cdf0e10cSrcweir void NameContainer::removeByName( const OUString& aName )
234cdf0e10cSrcweir throw(NoSuchElementException, WrappedTargetException, RuntimeException)
235cdf0e10cSrcweir {
236cdf0e10cSrcweir NameContainerNameMap::iterator aIt = mHashMap.find( aName );
237cdf0e10cSrcweir if( aIt == mHashMap.end() )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir throw NoSuchElementException();
240cdf0e10cSrcweir }
241cdf0e10cSrcweir
242cdf0e10cSrcweir sal_Int32 iHashResult = (*aIt).second;
243cdf0e10cSrcweir Any aOldElement = mValues.getConstArray()[ iHashResult ];
244cdf0e10cSrcweir mHashMap.erase( aIt );
245cdf0e10cSrcweir sal_Int32 iLast = mNames.getLength() - 1;
246cdf0e10cSrcweir if( iLast != iHashResult )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir OUString* pNames = mNames.getArray();
249cdf0e10cSrcweir Any* pValues = mValues.getArray();
250cdf0e10cSrcweir pNames[ iHashResult ] = pNames[ iLast ];
251cdf0e10cSrcweir pValues[ iHashResult ] = pValues[ iLast ];
252cdf0e10cSrcweir mHashMap[ pNames[ iHashResult ] ] = iHashResult;
253cdf0e10cSrcweir }
254cdf0e10cSrcweir mNames.realloc( iLast );
255cdf0e10cSrcweir mValues.realloc( iLast );
256cdf0e10cSrcweir mnElementCount--;
257cdf0e10cSrcweir
258cdf0e10cSrcweir // Fire event
259cdf0e10cSrcweir if( maContainerListeners.getLength() > 0 )
260cdf0e10cSrcweir {
261cdf0e10cSrcweir ContainerEvent aEvent;
262cdf0e10cSrcweir aEvent.Source = mpxEventSource;
263cdf0e10cSrcweir aEvent.Accessor <<= aName;
264cdf0e10cSrcweir aEvent.Element = aOldElement;
265cdf0e10cSrcweir maContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvent );
266cdf0e10cSrcweir }
267cdf0e10cSrcweir
268cdf0e10cSrcweir /* After the container event has been fired (one listener will update the
269cdf0e10cSrcweir core Basic manager), fire change event. Listeners can rely that the
270cdf0e10cSrcweir Basic source code of the core Basic manager is up-to-date. */
271cdf0e10cSrcweir if( maChangesListeners.getLength() > 0 )
272cdf0e10cSrcweir {
273cdf0e10cSrcweir ChangesEvent aEvent;
274cdf0e10cSrcweir aEvent.Source = mpxEventSource;
275cdf0e10cSrcweir aEvent.Base <<= aEvent.Source;
276cdf0e10cSrcweir aEvent.Changes.realloc( 1 );
277cdf0e10cSrcweir aEvent.Changes[ 0 ].Accessor <<= aName;
278cdf0e10cSrcweir // aEvent.Changes[ 0 ].Element remains empty (meaning "replaced with nothing")
279cdf0e10cSrcweir aEvent.Changes[ 0 ].ReplacedElement = aOldElement;
280cdf0e10cSrcweir maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
281cdf0e10cSrcweir }
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
284cdf0e10cSrcweir
285cdf0e10cSrcweir // Methods XContainer
addContainerListener(const Reference<XContainerListener> & xListener)286cdf0e10cSrcweir void SAL_CALL NameContainer::addContainerListener( const Reference< XContainerListener >& xListener )
287cdf0e10cSrcweir throw (RuntimeException)
288cdf0e10cSrcweir {
289cdf0e10cSrcweir if( !xListener.is() )
290cdf0e10cSrcweir throw RuntimeException();
291cdf0e10cSrcweir Reference< XInterface > xIface( xListener, UNO_QUERY );
292cdf0e10cSrcweir maContainerListeners.addInterface( xIface );
293cdf0e10cSrcweir }
294cdf0e10cSrcweir
removeContainerListener(const Reference<XContainerListener> & xListener)295cdf0e10cSrcweir void SAL_CALL NameContainer::removeContainerListener( const Reference< XContainerListener >& xListener )
296cdf0e10cSrcweir throw (RuntimeException)
297cdf0e10cSrcweir {
298cdf0e10cSrcweir if( !xListener.is() )
299cdf0e10cSrcweir throw RuntimeException();
300cdf0e10cSrcweir Reference< XInterface > xIface( xListener, UNO_QUERY );
301cdf0e10cSrcweir maContainerListeners.removeInterface( xIface );
302cdf0e10cSrcweir }
303cdf0e10cSrcweir
304cdf0e10cSrcweir // Methods XChangesNotifier
addChangesListener(const Reference<XChangesListener> & xListener)305cdf0e10cSrcweir void SAL_CALL NameContainer::addChangesListener( const Reference< XChangesListener >& xListener )
306cdf0e10cSrcweir throw (RuntimeException)
307cdf0e10cSrcweir {
308cdf0e10cSrcweir if( !xListener.is() )
309cdf0e10cSrcweir throw RuntimeException();
310cdf0e10cSrcweir Reference< XInterface > xIface( xListener, UNO_QUERY );
311cdf0e10cSrcweir maChangesListeners.addInterface( xIface );
312cdf0e10cSrcweir }
313cdf0e10cSrcweir
removeChangesListener(const Reference<XChangesListener> & xListener)314cdf0e10cSrcweir void SAL_CALL NameContainer::removeChangesListener( const Reference< XChangesListener >& xListener )
315cdf0e10cSrcweir throw (RuntimeException)
316cdf0e10cSrcweir {
317cdf0e10cSrcweir if( !xListener.is() )
318cdf0e10cSrcweir throw RuntimeException();
319cdf0e10cSrcweir Reference< XInterface > xIface( xListener, UNO_QUERY );
320cdf0e10cSrcweir maChangesListeners.removeInterface( xIface );
321cdf0e10cSrcweir }
322cdf0e10cSrcweir
323cdf0e10cSrcweir //============================================================================
324cdf0e10cSrcweir // ModifiableHelper
325cdf0e10cSrcweir
setModified(sal_Bool _bModified)326cdf0e10cSrcweir void ModifiableHelper::setModified( sal_Bool _bModified )
327cdf0e10cSrcweir {
328cdf0e10cSrcweir if ( _bModified == mbModified )
329cdf0e10cSrcweir return;
330cdf0e10cSrcweir mbModified = _bModified;
331cdf0e10cSrcweir
332cdf0e10cSrcweir if ( m_aModifyListeners.getLength() == 0 )
333cdf0e10cSrcweir return;
334cdf0e10cSrcweir
335cdf0e10cSrcweir EventObject aModifyEvent( m_rEventSource );
336cdf0e10cSrcweir m_aModifyListeners.notifyEach( &XModifyListener::modified, aModifyEvent );
337cdf0e10cSrcweir }
338cdf0e10cSrcweir
339cdf0e10cSrcweir //============================================================================
340cdf0e10cSrcweir
VBAScriptListenerContainer(::osl::Mutex & rMutex)341cdf0e10cSrcweir VBAScriptListenerContainer::VBAScriptListenerContainer( ::osl::Mutex& rMutex ) :
342cdf0e10cSrcweir VBAScriptListenerContainer_BASE( rMutex )
343cdf0e10cSrcweir {
344cdf0e10cSrcweir }
345cdf0e10cSrcweir
implTypedNotify(const Reference<vba::XVBAScriptListener> & rxListener,const vba::VBAScriptEvent & rEvent)346cdf0e10cSrcweir bool VBAScriptListenerContainer::implTypedNotify( const Reference< vba::XVBAScriptListener >& rxListener, const vba::VBAScriptEvent& rEvent ) throw (Exception)
347cdf0e10cSrcweir {
348cdf0e10cSrcweir rxListener->notifyVBAScriptEvent( rEvent );
349cdf0e10cSrcweir return true; // notify all other listeners too
350cdf0e10cSrcweir }
351cdf0e10cSrcweir
352cdf0e10cSrcweir //============================================================================
353cdf0e10cSrcweir
354cdf0e10cSrcweir // Implementation class SfxLibraryContainer
DBG_NAME(SfxLibraryContainer)355cdf0e10cSrcweir DBG_NAME( SfxLibraryContainer )
356cdf0e10cSrcweir
357cdf0e10cSrcweir // Ctor
358cdf0e10cSrcweir SfxLibraryContainer::SfxLibraryContainer( void )
359cdf0e10cSrcweir : SfxLibraryContainer_BASE( maMutex )
360cdf0e10cSrcweir
361cdf0e10cSrcweir , maVBAScriptListeners( maMutex )
362cdf0e10cSrcweir , mnRunningVBAScripts( 0 )
363cdf0e10cSrcweir , mbVBACompat( sal_False )
364cdf0e10cSrcweir , maModifiable( *this, maMutex )
365cdf0e10cSrcweir , maNameContainer( getCppuType( (Reference< XNameAccess >*) NULL ) )
366cdf0e10cSrcweir , mbOldInfoFormat( sal_False )
367cdf0e10cSrcweir , mbOasis2OOoFormat( sal_False )
368cdf0e10cSrcweir , mpBasMgr( NULL )
369cdf0e10cSrcweir , mbOwnBasMgr( sal_False )
370cdf0e10cSrcweir {
371cdf0e10cSrcweir DBG_CTOR( SfxLibraryContainer, NULL );
372cdf0e10cSrcweir
373cdf0e10cSrcweir mxMSF = comphelper::getProcessServiceFactory();
374cdf0e10cSrcweir if( !mxMSF.is() )
375cdf0e10cSrcweir {
376cdf0e10cSrcweir OSL_ENSURE( 0, "### couln't get ProcessServiceFactory\n" );
377cdf0e10cSrcweir }
378cdf0e10cSrcweir
379cdf0e10cSrcweir mxSFI = Reference< XSimpleFileAccess >( mxMSF->createInstance
380cdf0e10cSrcweir ( OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY );
381cdf0e10cSrcweir if( !mxSFI.is() )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir OSL_ENSURE( 0, "### couln't create SimpleFileAccess component\n" );
384cdf0e10cSrcweir }
385cdf0e10cSrcweir
386cdf0e10cSrcweir mxStringSubstitution = Reference< XStringSubstitution >( mxMSF->createInstance
387cdf0e10cSrcweir ( OUString::createFromAscii( "com.sun.star.util.PathSubstitution" ) ), UNO_QUERY );
388cdf0e10cSrcweir if( !mxStringSubstitution.is() )
389cdf0e10cSrcweir {
390cdf0e10cSrcweir OSL_ENSURE( 0, "### couln't create PathSubstitution component\n" );
391cdf0e10cSrcweir }
392cdf0e10cSrcweir }
393cdf0e10cSrcweir
~SfxLibraryContainer()394cdf0e10cSrcweir SfxLibraryContainer::~SfxLibraryContainer()
395cdf0e10cSrcweir {
396cdf0e10cSrcweir if( mbOwnBasMgr )
397cdf0e10cSrcweir BasicManager::LegacyDeleteBasicManager( mpBasMgr );
398cdf0e10cSrcweir DBG_DTOR( SfxLibraryContainer, NULL );
399cdf0e10cSrcweir }
400cdf0e10cSrcweir
checkDisposed() const401cdf0e10cSrcweir void SfxLibraryContainer::checkDisposed() const
402cdf0e10cSrcweir {
403cdf0e10cSrcweir if ( isDisposed() )
404cdf0e10cSrcweir throw DisposedException( ::rtl::OUString(), *const_cast< SfxLibraryContainer* >( this ) );
405cdf0e10cSrcweir }
406cdf0e10cSrcweir
enterMethod()407cdf0e10cSrcweir void SfxLibraryContainer::enterMethod()
408cdf0e10cSrcweir {
409cdf0e10cSrcweir maMutex.acquire();
410cdf0e10cSrcweir checkDisposed();
411cdf0e10cSrcweir }
412cdf0e10cSrcweir
leaveMethod()413cdf0e10cSrcweir void SfxLibraryContainer::leaveMethod()
414cdf0e10cSrcweir {
415cdf0e10cSrcweir maMutex.release();
416cdf0e10cSrcweir }
417cdf0e10cSrcweir
getBasicManager(void)418cdf0e10cSrcweir BasicManager* SfxLibraryContainer::getBasicManager( void )
419cdf0e10cSrcweir {
420cdf0e10cSrcweir if ( mpBasMgr )
421cdf0e10cSrcweir return mpBasMgr;
422cdf0e10cSrcweir
423cdf0e10cSrcweir Reference< XModel > xDocument( mxOwnerDocument.get(), UNO_QUERY );
424cdf0e10cSrcweir OSL_ENSURE( xDocument.is(), "SfxLibraryContainer::getBasicManager: cannot obtain a BasicManager without document!" );
425cdf0e10cSrcweir if ( xDocument.is() )
426cdf0e10cSrcweir mpBasMgr = BasicManagerRepository::getDocumentBasicManager( xDocument );
427cdf0e10cSrcweir
428cdf0e10cSrcweir return mpBasMgr;
429cdf0e10cSrcweir }
430cdf0e10cSrcweir
431cdf0e10cSrcweir // Methods XStorageBasedLibraryContainer
getRootStorage()432cdf0e10cSrcweir Reference< XStorage > SAL_CALL SfxLibraryContainer::getRootStorage() throw (RuntimeException)
433cdf0e10cSrcweir {
434cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
435cdf0e10cSrcweir return mxStorage;
436cdf0e10cSrcweir }
437cdf0e10cSrcweir
setRootStorage(const Reference<XStorage> & _rxRootStorage)438cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::setRootStorage( const Reference< XStorage >& _rxRootStorage ) throw (IllegalArgumentException, RuntimeException)
439cdf0e10cSrcweir {
440cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
441cdf0e10cSrcweir if ( !_rxRootStorage.is() )
442cdf0e10cSrcweir throw IllegalArgumentException();
443cdf0e10cSrcweir
444cdf0e10cSrcweir mxStorage = _rxRootStorage;
445cdf0e10cSrcweir onNewRootStorage();
446cdf0e10cSrcweir }
447cdf0e10cSrcweir
storeLibrariesToStorage(const Reference<XStorage> & _rxRootStorage)448cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::storeLibrariesToStorage( const Reference< XStorage >& _rxRootStorage ) throw (IllegalArgumentException, WrappedTargetException, RuntimeException)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
451cdf0e10cSrcweir if ( !_rxRootStorage.is() )
452cdf0e10cSrcweir throw IllegalArgumentException();
453cdf0e10cSrcweir
454cdf0e10cSrcweir try
455cdf0e10cSrcweir {
456cdf0e10cSrcweir storeLibraries_Impl( _rxRootStorage, sal_True );
457cdf0e10cSrcweir }
458cdf0e10cSrcweir catch( const Exception& )
459cdf0e10cSrcweir {
460cdf0e10cSrcweir throw WrappedTargetException( ::rtl::OUString(), *this, ::cppu::getCaughtException() );
461cdf0e10cSrcweir }
462cdf0e10cSrcweir }
463cdf0e10cSrcweir
464cdf0e10cSrcweir
465cdf0e10cSrcweir // Methods XModifiable
isModified()466cdf0e10cSrcweir sal_Bool SfxLibraryContainer::isModified() throw (RuntimeException)
467cdf0e10cSrcweir {
468cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
469cdf0e10cSrcweir if ( maModifiable.isModified() )
470cdf0e10cSrcweir return sal_True;
471cdf0e10cSrcweir
472cdf0e10cSrcweir // the library container is not modified, go through the libraries and check whether they are modified
473cdf0e10cSrcweir Sequence< OUString > aNames = maNameContainer.getElementNames();
474cdf0e10cSrcweir const OUString* pNames = aNames.getConstArray();
475cdf0e10cSrcweir sal_Int32 nNameCount = aNames.getLength();
476cdf0e10cSrcweir
477cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
478cdf0e10cSrcweir {
479cdf0e10cSrcweir OUString aName = pNames[ i ];
480cdf0e10cSrcweir SfxLibrary* pImplLib = getImplLib( aName );
481cdf0e10cSrcweir if( pImplLib->isModified() )
482cdf0e10cSrcweir {
483cdf0e10cSrcweir if ( aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") ) ) )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir // this is a workaround that has to be implemented because
486cdf0e10cSrcweir // empty standard library should stay marked as modified
487cdf0e10cSrcweir // but should not be treated as modified while it is empty
488cdf0e10cSrcweir if ( pImplLib->hasElements() )
489cdf0e10cSrcweir return sal_True;
490cdf0e10cSrcweir }
491cdf0e10cSrcweir else
492cdf0e10cSrcweir return sal_True;
493cdf0e10cSrcweir }
494cdf0e10cSrcweir }
495cdf0e10cSrcweir
496cdf0e10cSrcweir return sal_False;
497cdf0e10cSrcweir }
498cdf0e10cSrcweir
setModified(sal_Bool _bModified)499cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::setModified( sal_Bool _bModified ) throw (PropertyVetoException, RuntimeException)
500cdf0e10cSrcweir {
501cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
502cdf0e10cSrcweir maModifiable.setModified( _bModified );
503cdf0e10cSrcweir }
504cdf0e10cSrcweir
addModifyListener(const Reference<XModifyListener> & _rxListener)505cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::addModifyListener( const Reference< XModifyListener >& _rxListener ) throw (RuntimeException)
506cdf0e10cSrcweir {
507cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
508cdf0e10cSrcweir maModifiable.addModifyListener( _rxListener );
509cdf0e10cSrcweir }
510cdf0e10cSrcweir
removeModifyListener(const Reference<XModifyListener> & _rxListener)511cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::removeModifyListener( const Reference< XModifyListener >& _rxListener ) throw (RuntimeException)
512cdf0e10cSrcweir {
513cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
514cdf0e10cSrcweir maModifiable.removeModifyListener( _rxListener );
515cdf0e10cSrcweir }
516cdf0e10cSrcweir
517cdf0e10cSrcweir // Methods XPersistentLibraryContainer
getRootLocation()518cdf0e10cSrcweir Any SAL_CALL SfxLibraryContainer::getRootLocation() throw (RuntimeException)
519cdf0e10cSrcweir {
520cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
521cdf0e10cSrcweir return makeAny( getRootStorage() );
522cdf0e10cSrcweir }
523cdf0e10cSrcweir
getContainerLocationName()524cdf0e10cSrcweir ::rtl::OUString SAL_CALL SfxLibraryContainer::getContainerLocationName() throw (RuntimeException)
525cdf0e10cSrcweir {
526cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
527cdf0e10cSrcweir return maLibrariesDir;
528cdf0e10cSrcweir }
529cdf0e10cSrcweir
storeLibraries()530cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::storeLibraries( ) throw (WrappedTargetException, RuntimeException)
531cdf0e10cSrcweir {
532cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
533cdf0e10cSrcweir try
534cdf0e10cSrcweir {
535cdf0e10cSrcweir storeLibraries_Impl( mxStorage, mxStorage.is() );
536cdf0e10cSrcweir // we need to store *all* libraries if and only if we are based on a storage:
537cdf0e10cSrcweir // in this case, storeLibraries_Impl will remove the source storage, after loading
538cdf0e10cSrcweir // all libraries, so we need to force them to be stored, again
539cdf0e10cSrcweir }
540cdf0e10cSrcweir catch( const Exception& )
541cdf0e10cSrcweir {
542cdf0e10cSrcweir throw WrappedTargetException( ::rtl::OUString(), *this, ::cppu::getCaughtException() );
543cdf0e10cSrcweir }
544cdf0e10cSrcweir }
545cdf0e10cSrcweir
checkAndCopyFileImpl(const INetURLObject & rSourceFolderInetObj,const INetURLObject & rTargetFolderInetObj,const OUString & rCheckFileName,const OUString & rCheckExtension,Reference<XSimpleFileAccess> xSFI)546cdf0e10cSrcweir static void checkAndCopyFileImpl( const INetURLObject& rSourceFolderInetObj,
547cdf0e10cSrcweir const INetURLObject& rTargetFolderInetObj,
548cdf0e10cSrcweir const OUString& rCheckFileName,
549cdf0e10cSrcweir const OUString& rCheckExtension,
550cdf0e10cSrcweir Reference< XSimpleFileAccess > xSFI )
551cdf0e10cSrcweir {
552cdf0e10cSrcweir INetURLObject aTargetFolderInetObj( rTargetFolderInetObj );
553cdf0e10cSrcweir aTargetFolderInetObj.insertName( rCheckFileName, sal_True, INetURLObject::LAST_SEGMENT,
554cdf0e10cSrcweir sal_True, INetURLObject::ENCODE_ALL );
555cdf0e10cSrcweir aTargetFolderInetObj.setExtension( rCheckExtension );
556cdf0e10cSrcweir OUString aTargetFile = aTargetFolderInetObj.GetMainURL( INetURLObject::NO_DECODE );
557cdf0e10cSrcweir if( !xSFI->exists( aTargetFile ) )
558cdf0e10cSrcweir {
559cdf0e10cSrcweir INetURLObject aSourceFolderInetObj( rSourceFolderInetObj );
560cdf0e10cSrcweir aSourceFolderInetObj.insertName( rCheckFileName, sal_True, INetURLObject::LAST_SEGMENT,
561cdf0e10cSrcweir sal_True, INetURLObject::ENCODE_ALL );
562cdf0e10cSrcweir aSourceFolderInetObj.setExtension( rCheckExtension );
563cdf0e10cSrcweir OUString aSourceFile = aSourceFolderInetObj.GetMainURL( INetURLObject::NO_DECODE );
564cdf0e10cSrcweir xSFI->copy( aSourceFile, aTargetFile );
565cdf0e10cSrcweir }
566cdf0e10cSrcweir }
567cdf0e10cSrcweir
createVariableURL(OUString & rStr,const OUString & rLibName,const OUString & rInfoFileName,bool bUser)568cdf0e10cSrcweir static void createVariableURL( OUString& rStr, const OUString& rLibName,
569cdf0e10cSrcweir const OUString& rInfoFileName, bool bUser )
570cdf0e10cSrcweir {
571cdf0e10cSrcweir if( bUser )
572cdf0e10cSrcweir rStr = OUString::createFromAscii( "$(USER)/basic/" );
573cdf0e10cSrcweir else
574cdf0e10cSrcweir rStr = OUString::createFromAscii( "$(INST)/share/basic/" );
575cdf0e10cSrcweir
576cdf0e10cSrcweir rStr += rLibName;
577cdf0e10cSrcweir rStr += OUString::createFromAscii( "/" );
578cdf0e10cSrcweir rStr += rInfoFileName;
579cdf0e10cSrcweir rStr += OUString::createFromAscii( ".xlb/" );
580cdf0e10cSrcweir }
581cdf0e10cSrcweir
init(const OUString & rInitialDocumentURL,const uno::Reference<embed::XStorage> & rxInitialStorage)582cdf0e10cSrcweir sal_Bool SfxLibraryContainer::init( const OUString& rInitialDocumentURL, const uno::Reference< embed::XStorage >& rxInitialStorage )
583cdf0e10cSrcweir {
584cdf0e10cSrcweir // this might be called from within the ctor, and the impl_init might (indirectly) create
585cdf0e10cSrcweir // an UNO reference to ourself.
586cdf0e10cSrcweir // Ensure that we're not destroyed while we're in here
587cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount );
588cdf0e10cSrcweir sal_Bool bSuccess = init_Impl( rInitialDocumentURL, rxInitialStorage );
589cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount );
590cdf0e10cSrcweir
591cdf0e10cSrcweir return bSuccess;
592cdf0e10cSrcweir }
593cdf0e10cSrcweir
init_Impl(const OUString & rInitialDocumentURL,const uno::Reference<embed::XStorage> & rxInitialStorage)594cdf0e10cSrcweir sal_Bool SfxLibraryContainer::init_Impl(
595cdf0e10cSrcweir const OUString& rInitialDocumentURL, const uno::Reference< embed::XStorage >& rxInitialStorage )
596cdf0e10cSrcweir {
597cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage = rxInitialStorage;
598cdf0e10cSrcweir
599cdf0e10cSrcweir maInitialDocumentURL = rInitialDocumentURL;
600cdf0e10cSrcweir maInfoFileName = OUString::createFromAscii( getInfoFileName() );
601cdf0e10cSrcweir maOldInfoFileName = OUString::createFromAscii( getOldInfoFileName() );
602cdf0e10cSrcweir maLibElementFileExtension = OUString::createFromAscii( getLibElementFileExtension() );
603cdf0e10cSrcweir maLibrariesDir = OUString::createFromAscii( getLibrariesDir() );
604cdf0e10cSrcweir
605cdf0e10cSrcweir meInitMode = DEFAULT;
606cdf0e10cSrcweir INetURLObject aInitUrlInetObj( maInitialDocumentURL );
607cdf0e10cSrcweir OUString aInitFileName = aInitUrlInetObj.GetMainURL( INetURLObject::NO_DECODE );
608*0848378bSHerbert Dürr if( !aInitFileName.isEmpty() )
609cdf0e10cSrcweir {
610cdf0e10cSrcweir // We need a BasicManager to avoid problems
611cdf0e10cSrcweir StarBASIC* pBas = new StarBASIC();
612cdf0e10cSrcweir mpBasMgr = new BasicManager( pBas );
613cdf0e10cSrcweir mbOwnBasMgr = sal_True;
614cdf0e10cSrcweir
615cdf0e10cSrcweir OUString aExtension = aInitUrlInetObj.getExtension();
616cdf0e10cSrcweir if( aExtension.compareToAscii( "xlc" ) == COMPARE_EQUAL )
617cdf0e10cSrcweir {
618cdf0e10cSrcweir meInitMode = CONTAINER_INIT_FILE;
619cdf0e10cSrcweir INetURLObject aLibPathInetObj( aInitUrlInetObj );
620cdf0e10cSrcweir aLibPathInetObj.removeSegment();
621cdf0e10cSrcweir maLibraryPath = aLibPathInetObj.GetMainURL( INetURLObject::NO_DECODE );
622cdf0e10cSrcweir }
623cdf0e10cSrcweir else if( aExtension.compareToAscii( "xlb" ) == COMPARE_EQUAL )
624cdf0e10cSrcweir {
625cdf0e10cSrcweir meInitMode = LIBRARY_INIT_FILE;
626cdf0e10cSrcweir uno::Reference< embed::XStorage > xDummyStor;
627cdf0e10cSrcweir ::xmlscript::LibDescriptor aLibDesc;
628cdf0e10cSrcweir sal_Bool bReadIndexFile = implLoadLibraryIndexFile( NULL, aLibDesc, xDummyStor, aInitFileName );
629cdf0e10cSrcweir return bReadIndexFile;
630cdf0e10cSrcweir }
631cdf0e10cSrcweir else
632cdf0e10cSrcweir {
633cdf0e10cSrcweir // Decide between old and new document
634cdf0e10cSrcweir sal_Bool bOldStorage = SotStorage::IsOLEStorage( aInitFileName );
635cdf0e10cSrcweir if ( bOldStorage )
636cdf0e10cSrcweir {
637cdf0e10cSrcweir meInitMode = OLD_BASIC_STORAGE;
638cdf0e10cSrcweir importFromOldStorage( aInitFileName );
639cdf0e10cSrcweir return sal_True;
640cdf0e10cSrcweir }
641cdf0e10cSrcweir else
642cdf0e10cSrcweir {
643cdf0e10cSrcweir meInitMode = OFFICE_DOCUMENT;
644cdf0e10cSrcweir try
645cdf0e10cSrcweir {
646cdf0e10cSrcweir xStorage = ::comphelper::OStorageHelper::GetStorageFromURL( aInitFileName, embed::ElementModes::READ );
647cdf0e10cSrcweir }
648cdf0e10cSrcweir catch ( uno::Exception& )
649cdf0e10cSrcweir {
650cdf0e10cSrcweir // TODO: error handling
651cdf0e10cSrcweir }
652cdf0e10cSrcweir }
653cdf0e10cSrcweir }
654cdf0e10cSrcweir }
655cdf0e10cSrcweir else
656cdf0e10cSrcweir {
657cdf0e10cSrcweir // Default pathes
658cdf0e10cSrcweir maLibraryPath = SvtPathOptions().GetBasicPath();
659cdf0e10cSrcweir }
660cdf0e10cSrcweir
661cdf0e10cSrcweir Reference< XParser > xParser( mxMSF->createInstance(
662cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ) ), UNO_QUERY );
663cdf0e10cSrcweir if( !xParser.is() )
664cdf0e10cSrcweir {
665cdf0e10cSrcweir OSL_ENSURE( 0, "### couln't create sax parser component\n" );
666cdf0e10cSrcweir return sal_False;
667cdf0e10cSrcweir }
668cdf0e10cSrcweir
669cdf0e10cSrcweir uno::Reference< io::XInputStream > xInput;
670cdf0e10cSrcweir
671cdf0e10cSrcweir mxStorage = xStorage;
672cdf0e10cSrcweir sal_Bool bStorage = mxStorage.is();
673cdf0e10cSrcweir
674cdf0e10cSrcweir
675cdf0e10cSrcweir // #110009: Scope to force the StorageRefs to be destructed and
676cdf0e10cSrcweir // so the streams to be closed before the preload operation
677cdf0e10cSrcweir {
678cdf0e10cSrcweir // #110009
679cdf0e10cSrcweir
680cdf0e10cSrcweir uno::Reference< embed::XStorage > xLibrariesStor;
681cdf0e10cSrcweir String aFileName;
682cdf0e10cSrcweir
683cdf0e10cSrcweir int nPassCount = 1;
684cdf0e10cSrcweir if( !bStorage && meInitMode == DEFAULT )
685cdf0e10cSrcweir nPassCount = 2;
686cdf0e10cSrcweir for( int nPass = 0 ; nPass < nPassCount ; nPass++ )
687cdf0e10cSrcweir {
688cdf0e10cSrcweir if( bStorage )
689cdf0e10cSrcweir {
690cdf0e10cSrcweir OSL_ENSURE( meInitMode == DEFAULT || meInitMode == OFFICE_DOCUMENT,
691cdf0e10cSrcweir "### Wrong InitMode for document\n" );
692cdf0e10cSrcweir try
693cdf0e10cSrcweir {
694cdf0e10cSrcweir uno::Reference< io::XStream > xStream;
695cdf0e10cSrcweir xLibrariesStor = xStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READ );
696cdf0e10cSrcweir //if ( !xLibrariesStor.is() )
697cdf0e10cSrcweir // TODO: the method must either return a storage or throw an exception
698cdf0e10cSrcweir //throw uno::RuntimeException();
699cdf0e10cSrcweir
700cdf0e10cSrcweir if ( xLibrariesStor.is() )
701cdf0e10cSrcweir {
702cdf0e10cSrcweir aFileName = maInfoFileName;
703cdf0e10cSrcweir aFileName += String( RTL_CONSTASCII_USTRINGPARAM("-lc.xml") );
704cdf0e10cSrcweir
705cdf0e10cSrcweir try
706cdf0e10cSrcweir {
707cdf0e10cSrcweir xStream = xLibrariesStor->openStreamElement( aFileName, embed::ElementModes::READ );
708cdf0e10cSrcweir }
709cdf0e10cSrcweir catch( uno::Exception& )
710cdf0e10cSrcweir {}
711cdf0e10cSrcweir
712cdf0e10cSrcweir if( !xStream.is() )
713cdf0e10cSrcweir {
714cdf0e10cSrcweir mbOldInfoFormat = true;
715cdf0e10cSrcweir
716cdf0e10cSrcweir // Check old version
717cdf0e10cSrcweir aFileName = maOldInfoFileName;
718cdf0e10cSrcweir aFileName += String( RTL_CONSTASCII_USTRINGPARAM(".xml") );
719cdf0e10cSrcweir
720cdf0e10cSrcweir try
721cdf0e10cSrcweir {
722cdf0e10cSrcweir xStream = xLibrariesStor->openStreamElement( aFileName, embed::ElementModes::READ );
723cdf0e10cSrcweir }
724cdf0e10cSrcweir catch( uno::Exception& )
725cdf0e10cSrcweir {}
726cdf0e10cSrcweir
727cdf0e10cSrcweir if( !xStream.is() )
728cdf0e10cSrcweir {
729cdf0e10cSrcweir // Check for EA2 document version with wrong extensions
730cdf0e10cSrcweir aFileName = maOldInfoFileName;
731cdf0e10cSrcweir aFileName += String( RTL_CONSTASCII_USTRINGPARAM(".xli") );
732cdf0e10cSrcweir xStream = xLibrariesStor->openStreamElement( aFileName, embed::ElementModes::READ );
733cdf0e10cSrcweir }
734cdf0e10cSrcweir }
735cdf0e10cSrcweir }
736cdf0e10cSrcweir
737cdf0e10cSrcweir if ( xStream.is() )
738cdf0e10cSrcweir xInput = xStream->getInputStream();
739cdf0e10cSrcweir }
740cdf0e10cSrcweir catch( uno::Exception& )
741cdf0e10cSrcweir {
742cdf0e10cSrcweir // TODO: error handling?
743cdf0e10cSrcweir }
744cdf0e10cSrcweir }
745cdf0e10cSrcweir else
746cdf0e10cSrcweir {
747cdf0e10cSrcweir INetURLObject* pLibInfoInetObj = NULL;
748cdf0e10cSrcweir if( meInitMode == CONTAINER_INIT_FILE )
749cdf0e10cSrcweir {
750cdf0e10cSrcweir aFileName = aInitFileName;
751cdf0e10cSrcweir }
752cdf0e10cSrcweir else
753cdf0e10cSrcweir {
754cdf0e10cSrcweir if( nPass == 1 )
755cdf0e10cSrcweir pLibInfoInetObj = new INetURLObject( String(maLibraryPath).GetToken(0) );
756cdf0e10cSrcweir else
757cdf0e10cSrcweir pLibInfoInetObj = new INetURLObject( String(maLibraryPath).GetToken(1) );
758cdf0e10cSrcweir pLibInfoInetObj->insertName( maInfoFileName, sal_True, INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
759cdf0e10cSrcweir pLibInfoInetObj->setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xlc") ) );
760cdf0e10cSrcweir aFileName = pLibInfoInetObj->GetMainURL( INetURLObject::NO_DECODE );
761cdf0e10cSrcweir }
762cdf0e10cSrcweir
763cdf0e10cSrcweir try
764cdf0e10cSrcweir {
765cdf0e10cSrcweir xInput = mxSFI->openFileRead( aFileName );
766cdf0e10cSrcweir }
767cdf0e10cSrcweir catch( Exception& )
768cdf0e10cSrcweir {
769cdf0e10cSrcweir xInput.clear();
770cdf0e10cSrcweir if( nPass == 0 )
771cdf0e10cSrcweir {
772cdf0e10cSrcweir SfxErrorContext aEc( ERRCTX_SFX_LOADBASIC, aFileName );
773cdf0e10cSrcweir sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
774cdf0e10cSrcweir ErrorHandler::HandleError( nErrorCode );
775cdf0e10cSrcweir }
776cdf0e10cSrcweir }
777cdf0e10cSrcweir
778cdf0e10cSrcweir // Old variant?
779cdf0e10cSrcweir if( !xInput.is() && nPass == 0 )
780cdf0e10cSrcweir {
781cdf0e10cSrcweir INetURLObject aLibInfoInetObj( String(maLibraryPath).GetToken(1) );
782cdf0e10cSrcweir aLibInfoInetObj.insertName( maOldInfoFileName, sal_True, INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
783cdf0e10cSrcweir aLibInfoInetObj.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xli") ) );
784cdf0e10cSrcweir aFileName = aLibInfoInetObj.GetMainURL( INetURLObject::NO_DECODE );
785cdf0e10cSrcweir
786cdf0e10cSrcweir try
787cdf0e10cSrcweir {
788cdf0e10cSrcweir xInput = mxSFI->openFileRead( aFileName );
789cdf0e10cSrcweir mbOldInfoFormat = true;
790cdf0e10cSrcweir }
791cdf0e10cSrcweir catch( Exception& )
792cdf0e10cSrcweir {
793cdf0e10cSrcweir xInput.clear();
794cdf0e10cSrcweir SfxErrorContext aEc( ERRCTX_SFX_LOADBASIC, aFileName );
795cdf0e10cSrcweir sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
796cdf0e10cSrcweir ErrorHandler::HandleError( nErrorCode );
797cdf0e10cSrcweir }
798cdf0e10cSrcweir }
799cdf0e10cSrcweir
800cdf0e10cSrcweir delete pLibInfoInetObj;
801cdf0e10cSrcweir }
802cdf0e10cSrcweir
803cdf0e10cSrcweir if( xInput.is() )
804cdf0e10cSrcweir {
805cdf0e10cSrcweir InputSource source;
806cdf0e10cSrcweir source.aInputStream = xInput;
807cdf0e10cSrcweir source.sSystemId = aFileName;
808cdf0e10cSrcweir
809cdf0e10cSrcweir // start parsing
810cdf0e10cSrcweir ::xmlscript::LibDescriptorArray* pLibArray = new ::xmlscript::LibDescriptorArray();
811cdf0e10cSrcweir
812cdf0e10cSrcweir try
813cdf0e10cSrcweir {
814cdf0e10cSrcweir xParser->setDocumentHandler( ::xmlscript::importLibraryContainer( pLibArray ) );
815cdf0e10cSrcweir xParser->parseStream( source );
816cdf0e10cSrcweir }
817cdf0e10cSrcweir catch ( xml::sax::SAXException& e )
818cdf0e10cSrcweir {
819cdf0e10cSrcweir (void) e; // avoid warning
820cdf0e10cSrcweir OSL_ENSURE( 0, OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
821cdf0e10cSrcweir return sal_False;
822cdf0e10cSrcweir }
823cdf0e10cSrcweir catch ( io::IOException& e )
824cdf0e10cSrcweir {
825cdf0e10cSrcweir (void) e; // avoid warning
826cdf0e10cSrcweir OSL_ENSURE( 0, OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
827cdf0e10cSrcweir return sal_False;
828cdf0e10cSrcweir }
829cdf0e10cSrcweir
830cdf0e10cSrcweir sal_Int32 nLibCount = pLibArray->mnLibCount;
831cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
832cdf0e10cSrcweir {
833cdf0e10cSrcweir ::xmlscript::LibDescriptor& rLib = pLibArray->mpLibs[i];
834cdf0e10cSrcweir
835cdf0e10cSrcweir // Check storage URL
836cdf0e10cSrcweir OUString aStorageURL = rLib.aStorageURL;
837*0848378bSHerbert Dürr if( !bStorage && aStorageURL.isEmpty() && nPass == 0 )
838cdf0e10cSrcweir {
839cdf0e10cSrcweir String aLibraryPath;
840cdf0e10cSrcweir if( meInitMode == CONTAINER_INIT_FILE )
841cdf0e10cSrcweir aLibraryPath = maLibraryPath;
842cdf0e10cSrcweir else
843cdf0e10cSrcweir aLibraryPath = String(maLibraryPath).GetToken(1);
844cdf0e10cSrcweir INetURLObject aInetObj( aLibraryPath );
845cdf0e10cSrcweir
846cdf0e10cSrcweir aInetObj.insertName( rLib.aName, sal_True, INetURLObject::LAST_SEGMENT,
847cdf0e10cSrcweir sal_True, INetURLObject::ENCODE_ALL );
848cdf0e10cSrcweir OUString aLibDirPath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
849cdf0e10cSrcweir if( mxSFI->isFolder( aLibDirPath ) )
850cdf0e10cSrcweir {
851cdf0e10cSrcweir createVariableURL( rLib.aStorageURL, rLib.aName, maInfoFileName, true );
852cdf0e10cSrcweir maModifiable.setModified( sal_True );
853cdf0e10cSrcweir }
854cdf0e10cSrcweir else if( rLib.bLink )
855cdf0e10cSrcweir {
856cdf0e10cSrcweir // Check "share" path
857cdf0e10cSrcweir INetURLObject aShareInetObj( String(maLibraryPath).GetToken(0) );
858cdf0e10cSrcweir aShareInetObj.insertName( rLib.aName, sal_True, INetURLObject::LAST_SEGMENT,
859cdf0e10cSrcweir sal_True, INetURLObject::ENCODE_ALL );
860cdf0e10cSrcweir OUString aShareLibDirPath = aShareInetObj.GetMainURL( INetURLObject::NO_DECODE );
861cdf0e10cSrcweir if( mxSFI->isFolder( aShareLibDirPath ) )
862cdf0e10cSrcweir {
863cdf0e10cSrcweir createVariableURL( rLib.aStorageURL, rLib.aName, maInfoFileName, false );
864cdf0e10cSrcweir maModifiable.setModified( sal_True );
865cdf0e10cSrcweir }
866cdf0e10cSrcweir else
867cdf0e10cSrcweir {
868cdf0e10cSrcweir // #i25537: Ignore lib if library folder does not really exist
869cdf0e10cSrcweir continue;
870cdf0e10cSrcweir }
871cdf0e10cSrcweir }
872cdf0e10cSrcweir }
873cdf0e10cSrcweir
874cdf0e10cSrcweir OUString aLibName = rLib.aName;
875cdf0e10cSrcweir
876cdf0e10cSrcweir // If the same library name is used by the shared and the
877cdf0e10cSrcweir // user lib container index files the user file wins
878cdf0e10cSrcweir if( nPass == 1 && hasByName( aLibName ) )
879cdf0e10cSrcweir continue;
880cdf0e10cSrcweir
881cdf0e10cSrcweir SfxLibrary* pImplLib;
882cdf0e10cSrcweir if( rLib.bLink )
883cdf0e10cSrcweir {
884cdf0e10cSrcweir Reference< XNameAccess > xLib =
885cdf0e10cSrcweir createLibraryLink( aLibName, rLib.aStorageURL, rLib.bReadOnly );
886cdf0e10cSrcweir pImplLib = static_cast< SfxLibrary* >( xLib.get() );
887cdf0e10cSrcweir }
888cdf0e10cSrcweir else
889cdf0e10cSrcweir {
890cdf0e10cSrcweir Reference< XNameContainer > xLib = createLibrary( aLibName );
891cdf0e10cSrcweir pImplLib = static_cast< SfxLibrary* >( xLib.get() );
892cdf0e10cSrcweir pImplLib->mbLoaded = sal_False;
893cdf0e10cSrcweir pImplLib->mbReadOnly = rLib.bReadOnly;
894cdf0e10cSrcweir if( !bStorage )
895cdf0e10cSrcweir checkStorageURL( rLib.aStorageURL, pImplLib->maLibInfoFileURL,
896cdf0e10cSrcweir pImplLib->maStorageURL, pImplLib->maUnexpandedStorageURL );
897cdf0e10cSrcweir }
898cdf0e10cSrcweir maModifiable.setModified( sal_False );
899cdf0e10cSrcweir
900cdf0e10cSrcweir // Read library info files
901cdf0e10cSrcweir if( !mbOldInfoFormat )
902cdf0e10cSrcweir {
903cdf0e10cSrcweir uno::Reference< embed::XStorage > xLibraryStor;
904cdf0e10cSrcweir if( !pImplLib->mbInitialised && bStorage )
905cdf0e10cSrcweir {
906cdf0e10cSrcweir try {
907cdf0e10cSrcweir xLibraryStor = xLibrariesStor->openStorageElement( rLib.aName,
908cdf0e10cSrcweir embed::ElementModes::READ );
909cdf0e10cSrcweir }
910cdf0e10cSrcweir catch( uno::Exception& )
911cdf0e10cSrcweir {
912cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
913cdf0e10cSrcweir Any aError( ::cppu::getCaughtException() );
914cdf0e10cSrcweir ::rtl::OStringBuffer aMessage;
915cdf0e10cSrcweir aMessage.append( "couln't open sub storage for library '" );
916cdf0e10cSrcweir aMessage.append( ::rtl::OUStringToOString( rLib.aName, osl_getThreadTextEncoding() ) );
917cdf0e10cSrcweir aMessage.append( "'.\n\nException:" );
918cdf0e10cSrcweir aMessage.append( ::rtl::OUStringToOString( ::comphelper::anyToString( aError ), osl_getThreadTextEncoding() ) );
919cdf0e10cSrcweir OSL_ENSURE( false, aMessage.makeStringAndClear().getStr() );
920cdf0e10cSrcweir #endif
921cdf0e10cSrcweir }
922cdf0e10cSrcweir }
923cdf0e10cSrcweir
924cdf0e10cSrcweir // Link is already initialised in createLibraryLink()
925cdf0e10cSrcweir if( !pImplLib->mbInitialised && (!bStorage || xLibraryStor.is()) )
926cdf0e10cSrcweir {
927cdf0e10cSrcweir OUString aIndexFileName;
928cdf0e10cSrcweir sal_Bool bLoaded = implLoadLibraryIndexFile( pImplLib, rLib, xLibraryStor, aIndexFileName );
929cdf0e10cSrcweir if( bLoaded && aLibName != rLib.aName )
930cdf0e10cSrcweir {
931cdf0e10cSrcweir OSL_ENSURE( 0, "Different library names in library"
932cdf0e10cSrcweir " container and library info files!\n" );
933cdf0e10cSrcweir }
934cdf0e10cSrcweir if( GbMigrationSuppressErrors && !bLoaded )
935cdf0e10cSrcweir removeLibrary( aLibName );
936cdf0e10cSrcweir }
937cdf0e10cSrcweir }
938cdf0e10cSrcweir else if( !bStorage )
939cdf0e10cSrcweir {
940cdf0e10cSrcweir // Write new index file immediately because otherwise
941cdf0e10cSrcweir // the library elements will be lost when storing into
942cdf0e10cSrcweir // the new info format
943cdf0e10cSrcweir uno::Reference< embed::XStorage > xTmpStorage;
944cdf0e10cSrcweir implStoreLibraryIndexFile( pImplLib, rLib, xTmpStorage );
945cdf0e10cSrcweir }
946cdf0e10cSrcweir
947cdf0e10cSrcweir implImportLibDescriptor( pImplLib, rLib );
948cdf0e10cSrcweir
949cdf0e10cSrcweir if( nPass == 1 )
950cdf0e10cSrcweir {
951cdf0e10cSrcweir pImplLib->mbSharedIndexFile = sal_True;
952cdf0e10cSrcweir pImplLib->mbReadOnly = sal_True;
953cdf0e10cSrcweir }
954cdf0e10cSrcweir }
955cdf0e10cSrcweir
956cdf0e10cSrcweir // Keep flag for documents to force writing the new index files
957cdf0e10cSrcweir if( !bStorage )
958cdf0e10cSrcweir mbOldInfoFormat = sal_False;
959cdf0e10cSrcweir
960cdf0e10cSrcweir delete pLibArray;
961cdf0e10cSrcweir }
962cdf0e10cSrcweir // Only in the first pass it's an error when no index file is found
963cdf0e10cSrcweir else if( nPass == 0 )
964cdf0e10cSrcweir {
965cdf0e10cSrcweir return sal_False;
966cdf0e10cSrcweir }
967cdf0e10cSrcweir }
968cdf0e10cSrcweir
969cdf0e10cSrcweir // #110009: END Scope to force the StorageRefs to be destructed
970cdf0e10cSrcweir }
971cdf0e10cSrcweir // #110009
972cdf0e10cSrcweir
973cdf0e10cSrcweir if( !bStorage && meInitMode == DEFAULT )
974cdf0e10cSrcweir {
975cdf0e10cSrcweir try
976cdf0e10cSrcweir {
977cdf0e10cSrcweir implScanExtensions();
978cdf0e10cSrcweir }
979cdf0e10cSrcweir catch( uno::Exception& )
980cdf0e10cSrcweir {
981cdf0e10cSrcweir // TODO: error handling?
982cdf0e10cSrcweir OSL_ASSERT( "Cannot access extensions!" );
983cdf0e10cSrcweir }
984cdf0e10cSrcweir }
985cdf0e10cSrcweir
986cdf0e10cSrcweir // #110009 Preload?
987cdf0e10cSrcweir {
988cdf0e10cSrcweir Sequence< OUString > aNames = maNameContainer.getElementNames();
989cdf0e10cSrcweir const OUString* pNames = aNames.getConstArray();
990cdf0e10cSrcweir sal_Int32 nNameCount = aNames.getLength();
991cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
992cdf0e10cSrcweir {
993cdf0e10cSrcweir OUString aName = pNames[ i ];
994cdf0e10cSrcweir SfxLibrary* pImplLib = getImplLib( aName );
995cdf0e10cSrcweir if( pImplLib->mbPreload )
996cdf0e10cSrcweir loadLibrary( aName );
997cdf0e10cSrcweir }
998cdf0e10cSrcweir }
999cdf0e10cSrcweir
1000cdf0e10cSrcweir // #118803# upgrade installation 7.0 -> 8.0
1001cdf0e10cSrcweir if( meInitMode == DEFAULT )
1002cdf0e10cSrcweir {
1003cdf0e10cSrcweir INetURLObject aUserBasicInetObj( String(maLibraryPath).GetToken(1) );
1004cdf0e10cSrcweir OUString aStandardStr( RTL_CONSTASCII_USTRINGPARAM("Standard") );
1005cdf0e10cSrcweir
1006cdf0e10cSrcweir static char strPrevFolderName_1[] = "__basic_80";
1007cdf0e10cSrcweir static char strPrevFolderName_2[] = "__basic_80_2";
1008cdf0e10cSrcweir INetURLObject aPrevUserBasicInetObj_1( aUserBasicInetObj );
1009cdf0e10cSrcweir aPrevUserBasicInetObj_1.removeSegment();
1010cdf0e10cSrcweir INetURLObject aPrevUserBasicInetObj_2 = aPrevUserBasicInetObj_1;
1011cdf0e10cSrcweir aPrevUserBasicInetObj_1.Append( strPrevFolderName_1 );
1012cdf0e10cSrcweir aPrevUserBasicInetObj_2.Append( strPrevFolderName_2 );
1013cdf0e10cSrcweir
1014cdf0e10cSrcweir // #i93163
1015cdf0e10cSrcweir bool bCleanUp = false;
1016cdf0e10cSrcweir try
1017cdf0e10cSrcweir {
1018cdf0e10cSrcweir INetURLObject aPrevUserBasicInetObj = aPrevUserBasicInetObj_1;
1019cdf0e10cSrcweir String aPrevFolder = aPrevUserBasicInetObj.GetMainURL( INetURLObject::NO_DECODE );
1020cdf0e10cSrcweir bool bSecondTime = false;
1021cdf0e10cSrcweir if( mxSFI->isFolder( aPrevFolder ) )
1022cdf0e10cSrcweir {
1023cdf0e10cSrcweir // #110101 Check if Standard folder exists and is complete
1024cdf0e10cSrcweir INetURLObject aUserBasicStandardInetObj( aUserBasicInetObj );
1025cdf0e10cSrcweir aUserBasicStandardInetObj.insertName( aStandardStr, sal_True, INetURLObject::LAST_SEGMENT,
1026cdf0e10cSrcweir sal_True, INetURLObject::ENCODE_ALL );
1027cdf0e10cSrcweir INetURLObject aPrevUserBasicStandardInetObj( aPrevUserBasicInetObj );
1028cdf0e10cSrcweir aPrevUserBasicStandardInetObj.insertName( aStandardStr, sal_True, INetURLObject::LAST_SEGMENT,
1029cdf0e10cSrcweir sal_True, INetURLObject::ENCODE_ALL );
1030cdf0e10cSrcweir OUString aPrevStandardFolder = aPrevUserBasicStandardInetObj.GetMainURL( INetURLObject::NO_DECODE );
1031cdf0e10cSrcweir if( mxSFI->isFolder( aPrevStandardFolder ) )
1032cdf0e10cSrcweir {
1033cdf0e10cSrcweir OUString aXlbExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xlb") ) );
1034cdf0e10cSrcweir OUString aCheckFileName;
1035cdf0e10cSrcweir
1036cdf0e10cSrcweir // Check if script.xlb exists
1037cdf0e10cSrcweir aCheckFileName = OUString( RTL_CONSTASCII_USTRINGPARAM("script") );
1038cdf0e10cSrcweir checkAndCopyFileImpl( aUserBasicStandardInetObj,
1039cdf0e10cSrcweir aPrevUserBasicStandardInetObj,
1040cdf0e10cSrcweir aCheckFileName, aXlbExtension, mxSFI );
1041cdf0e10cSrcweir
1042cdf0e10cSrcweir // Check if dialog.xlb exists
1043cdf0e10cSrcweir aCheckFileName = OUString( RTL_CONSTASCII_USTRINGPARAM("dialog") );
1044cdf0e10cSrcweir checkAndCopyFileImpl( aUserBasicStandardInetObj,
1045cdf0e10cSrcweir aPrevUserBasicStandardInetObj,
1046cdf0e10cSrcweir aCheckFileName, aXlbExtension, mxSFI );
1047cdf0e10cSrcweir
1048cdf0e10cSrcweir // Check if module1.xba exists
1049cdf0e10cSrcweir OUString aXbaExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xba") ) );
1050cdf0e10cSrcweir aCheckFileName = OUString( RTL_CONSTASCII_USTRINGPARAM("Module1") );
1051cdf0e10cSrcweir checkAndCopyFileImpl( aUserBasicStandardInetObj,
1052cdf0e10cSrcweir aPrevUserBasicStandardInetObj,
1053cdf0e10cSrcweir aCheckFileName, aXbaExtension, mxSFI );
1054cdf0e10cSrcweir }
1055cdf0e10cSrcweir else
1056cdf0e10cSrcweir {
1057cdf0e10cSrcweir String aStandardFolder = aUserBasicStandardInetObj.GetMainURL( INetURLObject::NO_DECODE );
1058cdf0e10cSrcweir mxSFI->copy( aStandardFolder, aPrevStandardFolder );
1059cdf0e10cSrcweir }
1060cdf0e10cSrcweir
1061cdf0e10cSrcweir String aPrevCopyToFolder = aPrevUserBasicInetObj_2.GetMainURL( INetURLObject::NO_DECODE );
1062cdf0e10cSrcweir mxSFI->copy( aPrevFolder, aPrevCopyToFolder );
1063cdf0e10cSrcweir }
1064cdf0e10cSrcweir else
1065cdf0e10cSrcweir {
1066cdf0e10cSrcweir bSecondTime = true;
1067cdf0e10cSrcweir aPrevUserBasicInetObj = aPrevUserBasicInetObj_2;
1068cdf0e10cSrcweir aPrevFolder = aPrevUserBasicInetObj.GetMainURL( INetURLObject::NO_DECODE );
1069cdf0e10cSrcweir }
1070cdf0e10cSrcweir if( mxSFI->isFolder( aPrevFolder ) )
1071cdf0e10cSrcweir {
1072cdf0e10cSrcweir SfxLibraryContainer* pPrevCont = createInstanceImpl();
1073cdf0e10cSrcweir Reference< XInterface > xRef = static_cast< XInterface* >( static_cast< OWeakObject* >(pPrevCont) );
1074cdf0e10cSrcweir
1075cdf0e10cSrcweir // Rename previous basic folder to make storage URLs correct during initialisation
1076cdf0e10cSrcweir String aFolderUserBasic = aUserBasicInetObj.GetMainURL( INetURLObject::NO_DECODE );
1077cdf0e10cSrcweir INetURLObject aUserBasicTmpInetObj( aUserBasicInetObj );
1078cdf0e10cSrcweir aUserBasicTmpInetObj.removeSegment();
1079cdf0e10cSrcweir aUserBasicTmpInetObj.Append( "__basic_tmp" );
1080cdf0e10cSrcweir String aFolderTmp = aUserBasicTmpInetObj.GetMainURL( INetURLObject::NO_DECODE );
1081cdf0e10cSrcweir
1082cdf0e10cSrcweir mxSFI->move( aFolderUserBasic, aFolderTmp );
1083cdf0e10cSrcweir try
1084cdf0e10cSrcweir {
1085cdf0e10cSrcweir mxSFI->move( aPrevFolder, aFolderUserBasic );
1086cdf0e10cSrcweir }
1087cdf0e10cSrcweir catch( Exception& )
1088cdf0e10cSrcweir {
1089cdf0e10cSrcweir // Move back user/basic folder
1090cdf0e10cSrcweir try
1091cdf0e10cSrcweir {
1092cdf0e10cSrcweir mxSFI->kill( aFolderUserBasic );
1093cdf0e10cSrcweir }
1094cdf0e10cSrcweir catch( Exception& )
1095cdf0e10cSrcweir {}
1096cdf0e10cSrcweir mxSFI->move( aFolderTmp, aFolderUserBasic );
1097cdf0e10cSrcweir throw;
1098cdf0e10cSrcweir }
1099cdf0e10cSrcweir
1100cdf0e10cSrcweir INetURLObject aPrevUserBasicLibInfoInetObj( aUserBasicInetObj );
1101cdf0e10cSrcweir aPrevUserBasicLibInfoInetObj.insertName( maInfoFileName, sal_True, INetURLObject::LAST_SEGMENT,
1102cdf0e10cSrcweir sal_True, INetURLObject::ENCODE_ALL );
1103cdf0e10cSrcweir aPrevUserBasicLibInfoInetObj.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xlc") ) );
1104cdf0e10cSrcweir OUString aLibInfoFileName = aPrevUserBasicLibInfoInetObj.GetMainURL( INetURLObject::NO_DECODE );
1105cdf0e10cSrcweir Sequence<Any> aInitSeq( 1 );
1106cdf0e10cSrcweir aInitSeq.getArray()[0] <<= aLibInfoFileName;
1107cdf0e10cSrcweir GbMigrationSuppressErrors = true;
1108cdf0e10cSrcweir pPrevCont->initialize( aInitSeq );
1109cdf0e10cSrcweir GbMigrationSuppressErrors = false;
1110cdf0e10cSrcweir
1111cdf0e10cSrcweir // Rename folders back
1112cdf0e10cSrcweir mxSFI->move( aFolderUserBasic, aPrevFolder );
1113cdf0e10cSrcweir mxSFI->move( aFolderTmp, aFolderUserBasic );
1114cdf0e10cSrcweir
1115cdf0e10cSrcweir OUString aUserSearchStr = OUString::createFromAscii( "vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE" );
1116cdf0e10cSrcweir OUString aSharedSearchStr = OUString::createFromAscii( "vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE" );
1117cdf0e10cSrcweir OUString aBundledSearchStr = OUString::createFromAscii( "vnd.sun.star.expand:$BUNDLED_EXTENSIONS" );
1118cdf0e10cSrcweir OUString aInstSearchStr = OUString::createFromAscii( "$(INST)" );
1119cdf0e10cSrcweir
1120cdf0e10cSrcweir Sequence< OUString > aNames = pPrevCont->getElementNames();
1121cdf0e10cSrcweir const OUString* pNames = aNames.getConstArray();
1122cdf0e10cSrcweir sal_Int32 nNameCount = aNames.getLength();
1123cdf0e10cSrcweir
1124cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
1125cdf0e10cSrcweir {
1126cdf0e10cSrcweir OUString aLibName = pNames[ i ];
1127cdf0e10cSrcweir if( hasByName( aLibName ) )
1128cdf0e10cSrcweir {
1129cdf0e10cSrcweir if( aLibName == aStandardStr )
1130cdf0e10cSrcweir {
1131cdf0e10cSrcweir SfxLibrary* pImplLib = getImplLib( aStandardStr );
1132cdf0e10cSrcweir INetURLObject aStandardFolderInetObj( pImplLib->maStorageURL );
1133cdf0e10cSrcweir String aStandardFolder = pImplLib->maStorageURL;
1134cdf0e10cSrcweir mxSFI->kill( aStandardFolder );
1135cdf0e10cSrcweir }
1136cdf0e10cSrcweir else
1137cdf0e10cSrcweir {
1138cdf0e10cSrcweir continue;
1139cdf0e10cSrcweir }
1140cdf0e10cSrcweir }
1141cdf0e10cSrcweir
1142cdf0e10cSrcweir SfxLibrary* pImplLib = pPrevCont->getImplLib( aLibName );
1143cdf0e10cSrcweir if( pImplLib->mbLink )
1144cdf0e10cSrcweir {
1145cdf0e10cSrcweir OUString aStorageURL = pImplLib->maUnexpandedStorageURL;
1146cdf0e10cSrcweir bool bCreateLink = true;
1147cdf0e10cSrcweir if( aStorageURL.indexOf( aUserSearchStr ) != -1 ||
1148cdf0e10cSrcweir aStorageURL.indexOf( aSharedSearchStr ) != -1 ||
1149cdf0e10cSrcweir aStorageURL.indexOf( aBundledSearchStr ) != -1 ||
1150cdf0e10cSrcweir aStorageURL.indexOf( aInstSearchStr ) != -1 )
1151cdf0e10cSrcweir {
1152cdf0e10cSrcweir bCreateLink = false;
1153cdf0e10cSrcweir }
1154cdf0e10cSrcweir if( bCreateLink )
1155cdf0e10cSrcweir createLibraryLink( aLibName, pImplLib->maStorageURL, pImplLib->mbReadOnly );
1156cdf0e10cSrcweir }
1157cdf0e10cSrcweir else
1158cdf0e10cSrcweir {
1159cdf0e10cSrcweir // Move folder if not already done
1160cdf0e10cSrcweir INetURLObject aUserBasicLibFolderInetObj( aUserBasicInetObj );
1161cdf0e10cSrcweir aUserBasicLibFolderInetObj.Append( aLibName );
1162cdf0e10cSrcweir String aLibFolder = aUserBasicLibFolderInetObj.GetMainURL( INetURLObject::NO_DECODE );
1163cdf0e10cSrcweir
1164cdf0e10cSrcweir INetURLObject aPrevUserBasicLibFolderInetObj( aPrevUserBasicInetObj );
1165cdf0e10cSrcweir aPrevUserBasicLibFolderInetObj.Append( aLibName );
1166cdf0e10cSrcweir String aPrevLibFolder = aPrevUserBasicLibFolderInetObj.GetMainURL( INetURLObject::NO_DECODE );
1167cdf0e10cSrcweir
1168cdf0e10cSrcweir if( mxSFI->isFolder( aPrevLibFolder ) && !mxSFI->isFolder( aLibFolder ) )
1169cdf0e10cSrcweir mxSFI->move( aPrevLibFolder, aLibFolder );
1170cdf0e10cSrcweir
1171cdf0e10cSrcweir if( aLibName == aStandardStr )
1172cdf0e10cSrcweir maNameContainer.removeByName( aLibName );
1173cdf0e10cSrcweir
1174cdf0e10cSrcweir // Create library
1175cdf0e10cSrcweir Reference< XNameContainer > xLib = createLibrary( aLibName );
1176cdf0e10cSrcweir SfxLibrary* pNewLib = static_cast< SfxLibrary* >( xLib.get() );
1177cdf0e10cSrcweir pNewLib->mbLoaded = false;
1178cdf0e10cSrcweir pNewLib->implSetModified( sal_False );
1179cdf0e10cSrcweir checkStorageURL( aLibFolder, pNewLib->maLibInfoFileURL,
1180cdf0e10cSrcweir pNewLib->maStorageURL, pNewLib->maUnexpandedStorageURL );
1181cdf0e10cSrcweir
1182cdf0e10cSrcweir uno::Reference< embed::XStorage > xDummyStor;
1183cdf0e10cSrcweir ::xmlscript::LibDescriptor aLibDesc;
1184cdf0e10cSrcweir /*sal_Bool bReadIndexFile =*/ implLoadLibraryIndexFile
1185cdf0e10cSrcweir ( pNewLib, aLibDesc, xDummyStor, pNewLib->maLibInfoFileURL );
1186cdf0e10cSrcweir implImportLibDescriptor( pNewLib, aLibDesc );
1187cdf0e10cSrcweir }
1188cdf0e10cSrcweir }
1189cdf0e10cSrcweir mxSFI->kill( aPrevFolder );
1190cdf0e10cSrcweir }
1191cdf0e10cSrcweir }
1192cdf0e10cSrcweir catch( Exception& )
1193cdf0e10cSrcweir {
1194cdf0e10cSrcweir bCleanUp = true;
1195cdf0e10cSrcweir }
1196cdf0e10cSrcweir
1197cdf0e10cSrcweir // #i93163
1198cdf0e10cSrcweir if( bCleanUp )
1199cdf0e10cSrcweir {
1200cdf0e10cSrcweir DBG_ERROR( "Upgrade of Basic installation failed somehow" );
1201cdf0e10cSrcweir
1202cdf0e10cSrcweir static char strErrorSavFolderName[] = "__basic_80_err";
1203cdf0e10cSrcweir INetURLObject aPrevUserBasicInetObj_Err( aUserBasicInetObj );
1204cdf0e10cSrcweir aPrevUserBasicInetObj_Err.removeSegment();
1205cdf0e10cSrcweir aPrevUserBasicInetObj_Err.Append( strErrorSavFolderName );
1206cdf0e10cSrcweir String aPrevFolder_Err = aPrevUserBasicInetObj_Err.GetMainURL( INetURLObject::NO_DECODE );
1207cdf0e10cSrcweir
1208cdf0e10cSrcweir bool bSaved = false;
1209cdf0e10cSrcweir try
1210cdf0e10cSrcweir {
1211cdf0e10cSrcweir String aPrevFolder_1 = aPrevUserBasicInetObj_1.GetMainURL( INetURLObject::NO_DECODE );
1212cdf0e10cSrcweir if( mxSFI->isFolder( aPrevFolder_1 ) )
1213cdf0e10cSrcweir {
1214cdf0e10cSrcweir mxSFI->move( aPrevFolder_1, aPrevFolder_Err );
1215cdf0e10cSrcweir bSaved = true;
1216cdf0e10cSrcweir }
1217cdf0e10cSrcweir }
1218cdf0e10cSrcweir catch( Exception& )
1219cdf0e10cSrcweir {}
1220cdf0e10cSrcweir try
1221cdf0e10cSrcweir {
1222cdf0e10cSrcweir String aPrevFolder_2 = aPrevUserBasicInetObj_2.GetMainURL( INetURLObject::NO_DECODE );
1223cdf0e10cSrcweir if( !bSaved && mxSFI->isFolder( aPrevFolder_2 ) )
1224cdf0e10cSrcweir mxSFI->move( aPrevFolder_2, aPrevFolder_Err );
1225cdf0e10cSrcweir else
1226cdf0e10cSrcweir mxSFI->kill( aPrevFolder_2 );
1227cdf0e10cSrcweir }
1228cdf0e10cSrcweir catch( Exception& )
1229cdf0e10cSrcweir {}
1230cdf0e10cSrcweir }
1231cdf0e10cSrcweir }
1232cdf0e10cSrcweir
1233cdf0e10cSrcweir return sal_True;
1234cdf0e10cSrcweir }
1235cdf0e10cSrcweir
implScanExtensions(void)1236cdf0e10cSrcweir void SfxLibraryContainer::implScanExtensions( void )
1237cdf0e10cSrcweir {
1238cdf0e10cSrcweir ScriptExtensionIterator aScriptIt;
1239cdf0e10cSrcweir rtl::OUString aLibURL;
1240cdf0e10cSrcweir
1241cdf0e10cSrcweir bool bPureDialogLib = false;
1242*0848378bSHerbert Dürr while( (aLibURL = aScriptIt.nextBasicOrDialogLibrary( bPureDialogLib )).isEmpty() == false )
1243cdf0e10cSrcweir {
1244cdf0e10cSrcweir if( bPureDialogLib && maInfoFileName.equalsAscii( "script" ) )
1245cdf0e10cSrcweir continue;
1246cdf0e10cSrcweir
1247cdf0e10cSrcweir // Extract lib name
1248cdf0e10cSrcweir sal_Int32 nLen = aLibURL.getLength();
1249cdf0e10cSrcweir sal_Int32 indexLastSlash = aLibURL.lastIndexOf( '/' );
1250cdf0e10cSrcweir sal_Int32 nReduceCopy = 0;
1251cdf0e10cSrcweir if( indexLastSlash == nLen - 1 )
1252cdf0e10cSrcweir {
1253cdf0e10cSrcweir nReduceCopy = 1;
1254cdf0e10cSrcweir indexLastSlash = aLibURL.lastIndexOf( '/', nLen - 1 );
1255cdf0e10cSrcweir }
1256cdf0e10cSrcweir
1257cdf0e10cSrcweir OUString aLibName = aLibURL.copy( indexLastSlash + 1, nLen - indexLastSlash - nReduceCopy - 1 );
1258cdf0e10cSrcweir
1259cdf0e10cSrcweir // If a library of the same exists the existing library wins
1260cdf0e10cSrcweir if( hasByName( aLibName ) )
1261cdf0e10cSrcweir continue;
1262cdf0e10cSrcweir
1263cdf0e10cSrcweir // Add index file to URL
1264cdf0e10cSrcweir OUString aIndexFileURL = aLibURL;
1265cdf0e10cSrcweir if( nReduceCopy == 0 )
1266cdf0e10cSrcweir aIndexFileURL += OUString::createFromAscii( "/" );
1267cdf0e10cSrcweir aIndexFileURL += maInfoFileName;
1268cdf0e10cSrcweir aIndexFileURL += OUString::createFromAscii( ".xlb" );
1269cdf0e10cSrcweir
1270cdf0e10cSrcweir // Create link
1271cdf0e10cSrcweir const bool bReadOnly = false;
1272cdf0e10cSrcweir Reference< XNameAccess > xLib =
1273cdf0e10cSrcweir createLibraryLink( aLibName, aIndexFileURL, bReadOnly );
1274cdf0e10cSrcweir }
1275cdf0e10cSrcweir }
1276cdf0e10cSrcweir
1277cdf0e10cSrcweir // Handle maLibInfoFileURL and maStorageURL correctly
checkStorageURL(const OUString & aSourceURL,OUString & aLibInfoFileURL,OUString & aStorageURL,OUString & aUnexpandedStorageURL)1278cdf0e10cSrcweir void SfxLibraryContainer::checkStorageURL( const OUString& aSourceURL,
1279cdf0e10cSrcweir OUString& aLibInfoFileURL, OUString& aStorageURL, OUString& aUnexpandedStorageURL )
1280cdf0e10cSrcweir {
1281cdf0e10cSrcweir OUString aExpandedSourceURL = expand_url( aSourceURL );
1282cdf0e10cSrcweir if( aExpandedSourceURL != aSourceURL )
1283cdf0e10cSrcweir aUnexpandedStorageURL = aSourceURL;
1284cdf0e10cSrcweir
1285cdf0e10cSrcweir INetURLObject aInetObj( aExpandedSourceURL );
1286cdf0e10cSrcweir OUString aExtension = aInetObj.getExtension();
1287cdf0e10cSrcweir if( aExtension.compareToAscii( "xlb" ) == COMPARE_EQUAL )
1288cdf0e10cSrcweir {
1289cdf0e10cSrcweir // URL to xlb file
1290cdf0e10cSrcweir aLibInfoFileURL = aExpandedSourceURL;
1291cdf0e10cSrcweir aInetObj.removeSegment();
1292cdf0e10cSrcweir aStorageURL = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
1293cdf0e10cSrcweir }
1294cdf0e10cSrcweir else
1295cdf0e10cSrcweir {
1296cdf0e10cSrcweir // URL to library folder
1297cdf0e10cSrcweir aStorageURL = aExpandedSourceURL;
1298cdf0e10cSrcweir aInetObj.insertName( maInfoFileName, sal_True, INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
1299cdf0e10cSrcweir aInetObj.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xlb") ) );
1300cdf0e10cSrcweir aLibInfoFileURL = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
1301cdf0e10cSrcweir }
1302cdf0e10cSrcweir }
1303cdf0e10cSrcweir
getImplLib(const String & rLibraryName)1304cdf0e10cSrcweir SfxLibrary* SfxLibraryContainer::getImplLib( const String& rLibraryName )
1305cdf0e10cSrcweir {
1306cdf0e10cSrcweir Any aLibAny = maNameContainer.getByName( rLibraryName ) ;
1307cdf0e10cSrcweir Reference< XNameAccess > xNameAccess;
1308cdf0e10cSrcweir aLibAny >>= xNameAccess;
1309cdf0e10cSrcweir SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
1310cdf0e10cSrcweir return pImplLib;
1311cdf0e10cSrcweir }
1312cdf0e10cSrcweir
1313cdf0e10cSrcweir
1314cdf0e10cSrcweir // Storing with password encryption
1315cdf0e10cSrcweir
1316cdf0e10cSrcweir // Empty implementation, avoids unneccesary implementation in dlgcont.cxx
implStorePasswordLibrary(SfxLibrary *,const OUString &,const uno::Reference<embed::XStorage> &,const uno::Reference<task::XInteractionHandler> &)1317cdf0e10cSrcweir sal_Bool SfxLibraryContainer::implStorePasswordLibrary(
1318cdf0e10cSrcweir SfxLibrary*,
1319cdf0e10cSrcweir const OUString&,
1320cdf0e10cSrcweir const uno::Reference< embed::XStorage >&, const uno::Reference< task::XInteractionHandler >& )
1321cdf0e10cSrcweir {
1322cdf0e10cSrcweir return sal_False;
1323cdf0e10cSrcweir }
1324cdf0e10cSrcweir
implStorePasswordLibrary(SfxLibrary *,const::rtl::OUString &,const::com::sun::star::uno::Reference<::com::sun::star::embed::XStorage> &,const::rtl::OUString &,const Reference<XSimpleFileAccess>,const uno::Reference<task::XInteractionHandler> &)1325cdf0e10cSrcweir sal_Bool SfxLibraryContainer::implStorePasswordLibrary(
1326cdf0e10cSrcweir SfxLibrary* /*pLib*/,
1327cdf0e10cSrcweir const ::rtl::OUString& /*aName*/,
1328cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& /*xStorage*/,
1329cdf0e10cSrcweir const ::rtl::OUString& /*aTargetURL*/,
1330cdf0e10cSrcweir const Reference< XSimpleFileAccess > /*xToUseSFI*/,
1331cdf0e10cSrcweir const uno::Reference< task::XInteractionHandler >& )
1332cdf0e10cSrcweir {
1333cdf0e10cSrcweir return sal_False;
1334cdf0e10cSrcweir }
1335cdf0e10cSrcweir
implLoadPasswordLibrary(SfxLibrary *,const OUString &,sal_Bool)1336cdf0e10cSrcweir sal_Bool SfxLibraryContainer::implLoadPasswordLibrary(
1337cdf0e10cSrcweir SfxLibrary* /*pLib*/,
1338cdf0e10cSrcweir const OUString& /*Name*/,
1339cdf0e10cSrcweir sal_Bool /*bVerifyPasswordOnly*/ )
1340cdf0e10cSrcweir throw(WrappedTargetException, RuntimeException)
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir return sal_True;
1343cdf0e10cSrcweir }
1344cdf0e10cSrcweir
1345cdf0e10cSrcweir
1346cdf0e10cSrcweir
1347cdf0e10cSrcweir #define EXPAND_PROTOCOL "vnd.sun.star.expand"
1348cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
1349cdf0e10cSrcweir
createAppLibraryFolder(SfxLibrary * pLib,const OUString & aName)1350cdf0e10cSrcweir OUString SfxLibraryContainer::createAppLibraryFolder
1351cdf0e10cSrcweir ( SfxLibrary* pLib, const OUString& aName )
1352cdf0e10cSrcweir {
1353cdf0e10cSrcweir OUString aLibDirPath = pLib->maStorageURL;
1354*0848378bSHerbert Dürr if( aLibDirPath.isEmpty() )
1355cdf0e10cSrcweir {
1356cdf0e10cSrcweir INetURLObject aInetObj( String(maLibraryPath).GetToken(1) );
1357cdf0e10cSrcweir aInetObj.insertName( aName, sal_True, INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
1358cdf0e10cSrcweir checkStorageURL( aInetObj.GetMainURL( INetURLObject::NO_DECODE ), pLib->maLibInfoFileURL,
1359cdf0e10cSrcweir pLib->maStorageURL, pLib->maUnexpandedStorageURL );
1360cdf0e10cSrcweir aLibDirPath = pLib->maStorageURL;
1361cdf0e10cSrcweir }
1362cdf0e10cSrcweir
1363cdf0e10cSrcweir if( !mxSFI->isFolder( aLibDirPath ) )
1364cdf0e10cSrcweir {
1365cdf0e10cSrcweir try
1366cdf0e10cSrcweir {
1367cdf0e10cSrcweir mxSFI->createFolder( aLibDirPath );
1368cdf0e10cSrcweir }
1369cdf0e10cSrcweir catch( Exception& )
1370cdf0e10cSrcweir {}
1371cdf0e10cSrcweir }
1372cdf0e10cSrcweir
1373cdf0e10cSrcweir return aLibDirPath;
1374cdf0e10cSrcweir }
1375cdf0e10cSrcweir
1376cdf0e10cSrcweir // Storing
implStoreLibrary(SfxLibrary * pLib,const OUString & aName,const uno::Reference<embed::XStorage> & xStorage)1377cdf0e10cSrcweir void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
1378cdf0e10cSrcweir const OUString& aName, const uno::Reference< embed::XStorage >& xStorage )
1379cdf0e10cSrcweir {
1380cdf0e10cSrcweir OUString aDummyLocation;
1381cdf0e10cSrcweir Reference< XSimpleFileAccess > xDummySFA;
1382cdf0e10cSrcweir Reference< XInteractionHandler > xDummyHandler;
1383cdf0e10cSrcweir implStoreLibrary( pLib, aName, xStorage, aDummyLocation, xDummySFA, xDummyHandler );
1384cdf0e10cSrcweir }
1385cdf0e10cSrcweir
1386cdf0e10cSrcweir // New variant for library export
implStoreLibrary(SfxLibrary * pLib,const OUString & aName,const uno::Reference<embed::XStorage> & xStorage,const::rtl::OUString & aTargetURL,Reference<XSimpleFileAccess> xToUseSFI,const Reference<XInteractionHandler> & xHandler)1387cdf0e10cSrcweir void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
1388cdf0e10cSrcweir const OUString& aName, const uno::Reference< embed::XStorage >& xStorage,
1389cdf0e10cSrcweir const ::rtl::OUString& aTargetURL, Reference< XSimpleFileAccess > xToUseSFI,
1390cdf0e10cSrcweir const Reference< XInteractionHandler >& xHandler )
1391cdf0e10cSrcweir {
1392cdf0e10cSrcweir sal_Bool bLink = pLib->mbLink;
1393cdf0e10cSrcweir sal_Bool bStorage = xStorage.is() && !bLink;
1394cdf0e10cSrcweir
1395cdf0e10cSrcweir Sequence< OUString > aElementNames = pLib->getElementNames();
1396cdf0e10cSrcweir sal_Int32 nNameCount = aElementNames.getLength();
1397cdf0e10cSrcweir const OUString* pNames = aElementNames.getConstArray();
1398cdf0e10cSrcweir
1399cdf0e10cSrcweir if( bStorage )
1400cdf0e10cSrcweir {
1401cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
1402cdf0e10cSrcweir {
1403cdf0e10cSrcweir OUString aElementName = pNames[ i ];
1404cdf0e10cSrcweir
1405cdf0e10cSrcweir OUString aStreamName = aElementName;
1406cdf0e10cSrcweir aStreamName += String( RTL_CONSTASCII_USTRINGPARAM(".xml") );
1407cdf0e10cSrcweir
1408cdf0e10cSrcweir /*Any aElement = pLib->getByName( aElementName );*/
1409cdf0e10cSrcweir if( !isLibraryElementValid( pLib->getByName( aElementName ) ) )
1410cdf0e10cSrcweir {
1411cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1412cdf0e10cSrcweir ::rtl::OStringBuffer aMessage;
1413cdf0e10cSrcweir aMessage.append( "invalid library element '" );
1414cdf0e10cSrcweir aMessage.append( ::rtl::OUStringToOString( aElementName, osl_getThreadTextEncoding() ) );
1415cdf0e10cSrcweir aMessage.append( "'." );
1416cdf0e10cSrcweir OSL_ENSURE( false, aMessage.makeStringAndClear().getStr() );
1417cdf0e10cSrcweir #endif
1418cdf0e10cSrcweir continue;
1419cdf0e10cSrcweir }
1420cdf0e10cSrcweir try {
1421cdf0e10cSrcweir uno::Reference< io::XStream > xElementStream = xStorage->openStreamElement(
1422cdf0e10cSrcweir aStreamName,
1423cdf0e10cSrcweir embed::ElementModes::READWRITE );
1424cdf0e10cSrcweir //if ( !xElementStream.is() )
1425cdf0e10cSrcweir // throw uno::RuntimeException(); // TODO: method must either return the stream or throw an exception
1426cdf0e10cSrcweir
1427cdf0e10cSrcweir String aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) );
1428cdf0e10cSrcweir OUString aMime( RTL_CONSTASCII_USTRINGPARAM("text/xml") );
1429cdf0e10cSrcweir
1430cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( xElementStream, uno::UNO_QUERY );
1431cdf0e10cSrcweir OSL_ENSURE( xProps.is(), "The StorageStream must implement XPropertySet interface!\n" );
1432cdf0e10cSrcweir //if ( !xProps.is() ) //TODO
1433cdf0e10cSrcweir // throw uno::RuntimeException();
1434cdf0e10cSrcweir
1435cdf0e10cSrcweir if ( xProps.is() )
1436cdf0e10cSrcweir {
1437cdf0e10cSrcweir xProps->setPropertyValue( aPropName, uno::makeAny( aMime ) );
1438cdf0e10cSrcweir
1439cdf0e10cSrcweir // #87671 Allow encryption
1440cdf0e10cSrcweir //REMOVE aPropName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("Encrypted") );
1441cdf0e10cSrcweir aPropName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) );
1442cdf0e10cSrcweir xProps->setPropertyValue( aPropName, uno::makeAny( sal_True ) );
1443cdf0e10cSrcweir
1444cdf0e10cSrcweir Reference< XOutputStream > xOutput = xElementStream->getOutputStream();
1445cdf0e10cSrcweir Reference< XNameContainer > xLib( pLib );
1446cdf0e10cSrcweir writeLibraryElement( xLib, aElementName, xOutput );
1447cdf0e10cSrcweir // writeLibraryElement closes the stream
1448cdf0e10cSrcweir // xOutput->closeOutput();
1449cdf0e10cSrcweir }
1450cdf0e10cSrcweir }
1451cdf0e10cSrcweir catch( uno::Exception& )
1452cdf0e10cSrcweir {
1453cdf0e10cSrcweir OSL_ENSURE( sal_False, "Problem during storing of library!\n" );
1454cdf0e10cSrcweir // TODO: error handling?
1455cdf0e10cSrcweir }
1456cdf0e10cSrcweir }
1457cdf0e10cSrcweir
1458cdf0e10cSrcweir pLib->storeResourcesToStorage( xStorage );
1459cdf0e10cSrcweir }
1460cdf0e10cSrcweir else
1461cdf0e10cSrcweir {
1462cdf0e10cSrcweir // Export?
1463cdf0e10cSrcweir bool bExport = aTargetURL.getLength();
1464cdf0e10cSrcweir try
1465cdf0e10cSrcweir {
1466cdf0e10cSrcweir Reference< XSimpleFileAccess > xSFI = mxSFI;
1467cdf0e10cSrcweir if( xToUseSFI.is() )
1468cdf0e10cSrcweir xSFI = xToUseSFI;
1469cdf0e10cSrcweir
1470cdf0e10cSrcweir OUString aLibDirPath;
1471cdf0e10cSrcweir if( bExport )
1472cdf0e10cSrcweir {
1473cdf0e10cSrcweir INetURLObject aInetObj( aTargetURL );
1474cdf0e10cSrcweir aInetObj.insertName( aName, sal_True, INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
1475cdf0e10cSrcweir aLibDirPath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
1476cdf0e10cSrcweir
1477cdf0e10cSrcweir if( !xSFI->isFolder( aLibDirPath ) )
1478cdf0e10cSrcweir xSFI->createFolder( aLibDirPath );
1479cdf0e10cSrcweir
1480cdf0e10cSrcweir pLib->storeResourcesToURL( aLibDirPath, xHandler );
1481cdf0e10cSrcweir }
1482cdf0e10cSrcweir else
1483cdf0e10cSrcweir {
1484cdf0e10cSrcweir aLibDirPath = createAppLibraryFolder( pLib, aName );
1485cdf0e10cSrcweir pLib->storeResources();
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir
1488cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
1489cdf0e10cSrcweir {
1490cdf0e10cSrcweir OUString aElementName = pNames[ i ];
1491cdf0e10cSrcweir
1492cdf0e10cSrcweir INetURLObject aElementInetObj( aLibDirPath );
1493cdf0e10cSrcweir aElementInetObj.insertName( aElementName, sal_False,
1494cdf0e10cSrcweir INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
1495cdf0e10cSrcweir aElementInetObj.setExtension( maLibElementFileExtension );
1496cdf0e10cSrcweir String aElementPath( aElementInetObj.GetMainURL( INetURLObject::NO_DECODE ) );
1497cdf0e10cSrcweir
1498cdf0e10cSrcweir /*Any aElement = pLib->getByName( aElementName );*/
1499cdf0e10cSrcweir if( !isLibraryElementValid( pLib->getByName( aElementName ) ) )
1500cdf0e10cSrcweir {
1501cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1502cdf0e10cSrcweir ::rtl::OStringBuffer aMessage;
1503cdf0e10cSrcweir aMessage.append( "invalid library element '" );
1504cdf0e10cSrcweir aMessage.append( ::rtl::OUStringToOString( aElementName, osl_getThreadTextEncoding() ) );
1505cdf0e10cSrcweir aMessage.append( "'." );
1506cdf0e10cSrcweir OSL_ENSURE( false, aMessage.makeStringAndClear().getStr() );
1507cdf0e10cSrcweir #endif
1508cdf0e10cSrcweir continue;
1509cdf0e10cSrcweir }
1510cdf0e10cSrcweir
1511cdf0e10cSrcweir // TODO: Check modified
1512cdf0e10cSrcweir try
1513cdf0e10cSrcweir {
1514cdf0e10cSrcweir if( xSFI->exists( aElementPath ) )
1515cdf0e10cSrcweir xSFI->kill( aElementPath );
1516cdf0e10cSrcweir Reference< XOutputStream > xOutput = xSFI->openFileWrite( aElementPath );
1517cdf0e10cSrcweir Reference< XNameContainer > xLib( pLib );
1518cdf0e10cSrcweir writeLibraryElement( xLib, aElementName, xOutput );
1519cdf0e10cSrcweir xOutput->closeOutput();
1520cdf0e10cSrcweir }
1521cdf0e10cSrcweir catch( Exception& )
1522cdf0e10cSrcweir {
1523cdf0e10cSrcweir if( bExport )
1524cdf0e10cSrcweir throw;
1525cdf0e10cSrcweir
1526cdf0e10cSrcweir SfxErrorContext aEc( ERRCTX_SFX_SAVEDOC, aElementPath );
1527cdf0e10cSrcweir sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
1528cdf0e10cSrcweir ErrorHandler::HandleError( nErrorCode );
1529cdf0e10cSrcweir }
1530cdf0e10cSrcweir }
1531cdf0e10cSrcweir }
1532cdf0e10cSrcweir catch( Exception& )
1533cdf0e10cSrcweir {
1534cdf0e10cSrcweir if( bExport )
1535cdf0e10cSrcweir throw;
1536cdf0e10cSrcweir }
1537cdf0e10cSrcweir }
1538cdf0e10cSrcweir }
1539cdf0e10cSrcweir
implStoreLibraryIndexFile(SfxLibrary * pLib,const::xmlscript::LibDescriptor & rLib,const uno::Reference<embed::XStorage> & xStorage)1540cdf0e10cSrcweir void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
1541cdf0e10cSrcweir const ::xmlscript::LibDescriptor& rLib, const uno::Reference< embed::XStorage >& xStorage )
1542cdf0e10cSrcweir {
1543cdf0e10cSrcweir OUString aDummyLocation;
1544cdf0e10cSrcweir Reference< XSimpleFileAccess > xDummySFA;
1545cdf0e10cSrcweir implStoreLibraryIndexFile( pLib, rLib, xStorage, aDummyLocation, xDummySFA );
1546cdf0e10cSrcweir }
1547cdf0e10cSrcweir
1548cdf0e10cSrcweir // New variant for library export
implStoreLibraryIndexFile(SfxLibrary * pLib,const::xmlscript::LibDescriptor & rLib,const uno::Reference<embed::XStorage> & xStorage,const::rtl::OUString & aTargetURL,Reference<XSimpleFileAccess> xToUseSFI)1549cdf0e10cSrcweir void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
1550cdf0e10cSrcweir const ::xmlscript::LibDescriptor& rLib, const uno::Reference< embed::XStorage >& xStorage,
1551cdf0e10cSrcweir const ::rtl::OUString& aTargetURL, Reference< XSimpleFileAccess > xToUseSFI )
1552cdf0e10cSrcweir {
1553cdf0e10cSrcweir // Create sax writer
1554cdf0e10cSrcweir Reference< XExtendedDocumentHandler > xHandler(
1555cdf0e10cSrcweir mxMSF->createInstance(
1556cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer") ) ), UNO_QUERY );
1557cdf0e10cSrcweir if( !xHandler.is() )
1558cdf0e10cSrcweir {
1559cdf0e10cSrcweir OSL_ENSURE( 0, "### couln't create sax-writer component\n" );
1560cdf0e10cSrcweir return;
1561cdf0e10cSrcweir }
1562cdf0e10cSrcweir
1563cdf0e10cSrcweir sal_Bool bLink = pLib->mbLink;
1564cdf0e10cSrcweir sal_Bool bStorage = xStorage.is() && !bLink;
1565cdf0e10cSrcweir
1566cdf0e10cSrcweir // Write info file
1567cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOut;
1568cdf0e10cSrcweir uno::Reference< io::XStream > xInfoStream;
1569cdf0e10cSrcweir if( bStorage )
1570cdf0e10cSrcweir {
1571cdf0e10cSrcweir OUString aStreamName( maInfoFileName );
1572cdf0e10cSrcweir aStreamName += String( RTL_CONSTASCII_USTRINGPARAM("-lb.xml") );
1573cdf0e10cSrcweir
1574cdf0e10cSrcweir try {
1575cdf0e10cSrcweir xInfoStream = xStorage->openStreamElement( aStreamName, embed::ElementModes::READWRITE );
1576cdf0e10cSrcweir OSL_ENSURE( xInfoStream.is(), "No stream!\n" );
1577cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( xInfoStream, uno::UNO_QUERY );
1578cdf0e10cSrcweir //if ( !xProps.is() )
1579cdf0e10cSrcweir // throw uno::RuntimeException(); // TODO
1580cdf0e10cSrcweir
1581cdf0e10cSrcweir if ( xProps.is() )
1582cdf0e10cSrcweir {
1583cdf0e10cSrcweir String aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) );
1584cdf0e10cSrcweir OUString aMime( RTL_CONSTASCII_USTRINGPARAM("text/xml") );
1585cdf0e10cSrcweir xProps->setPropertyValue( aPropName, uno::makeAny( aMime ) );
1586cdf0e10cSrcweir
1587cdf0e10cSrcweir // #87671 Allow encryption
1588cdf0e10cSrcweir //REMOVE aPropName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("Encrypted") );
1589cdf0e10cSrcweir aPropName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) );
1590cdf0e10cSrcweir xProps->setPropertyValue( aPropName, uno::makeAny( sal_True ) );
1591cdf0e10cSrcweir
1592cdf0e10cSrcweir xOut = xInfoStream->getOutputStream();
1593cdf0e10cSrcweir }
1594cdf0e10cSrcweir }
1595cdf0e10cSrcweir catch( uno::Exception& )
1596cdf0e10cSrcweir {
1597cdf0e10cSrcweir OSL_ENSURE( sal_False, "Problem during storing of library index file!\n" );
1598cdf0e10cSrcweir // TODO: error handling?
1599cdf0e10cSrcweir }
1600cdf0e10cSrcweir }
1601cdf0e10cSrcweir else
1602cdf0e10cSrcweir {
1603cdf0e10cSrcweir // Export?
1604cdf0e10cSrcweir bool bExport = aTargetURL.getLength();
1605cdf0e10cSrcweir Reference< XSimpleFileAccess > xSFI = mxSFI;
1606cdf0e10cSrcweir if( xToUseSFI.is() )
1607cdf0e10cSrcweir xSFI = xToUseSFI;
1608cdf0e10cSrcweir
1609cdf0e10cSrcweir OUString aLibInfoPath;
1610cdf0e10cSrcweir if( bExport )
1611cdf0e10cSrcweir {
1612cdf0e10cSrcweir INetURLObject aInetObj( aTargetURL );
1613cdf0e10cSrcweir aInetObj.insertName( rLib.aName, sal_True, INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
1614cdf0e10cSrcweir OUString aLibDirPath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
1615cdf0e10cSrcweir if( !xSFI->isFolder( aLibDirPath ) )
1616cdf0e10cSrcweir xSFI->createFolder( aLibDirPath );
1617cdf0e10cSrcweir
1618cdf0e10cSrcweir aInetObj.insertName( maInfoFileName, sal_True, INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
1619cdf0e10cSrcweir aInetObj.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xlb") ) );
1620cdf0e10cSrcweir aLibInfoPath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
1621cdf0e10cSrcweir }
1622cdf0e10cSrcweir else
1623cdf0e10cSrcweir {
1624cdf0e10cSrcweir createAppLibraryFolder( pLib, rLib.aName );
1625cdf0e10cSrcweir aLibInfoPath = pLib->maLibInfoFileURL;
1626cdf0e10cSrcweir }
1627cdf0e10cSrcweir
1628cdf0e10cSrcweir try
1629cdf0e10cSrcweir {
1630cdf0e10cSrcweir if( xSFI->exists( aLibInfoPath ) )
1631cdf0e10cSrcweir xSFI->kill( aLibInfoPath );
1632cdf0e10cSrcweir xOut = xSFI->openFileWrite( aLibInfoPath );
1633cdf0e10cSrcweir }
1634cdf0e10cSrcweir catch( Exception& )
1635cdf0e10cSrcweir {
1636cdf0e10cSrcweir if( bExport )
1637cdf0e10cSrcweir throw;
1638cdf0e10cSrcweir
1639cdf0e10cSrcweir SfxErrorContext aEc( ERRCTX_SFX_SAVEDOC, aLibInfoPath );
1640cdf0e10cSrcweir sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
1641cdf0e10cSrcweir ErrorHandler::HandleError( nErrorCode );
1642cdf0e10cSrcweir }
1643cdf0e10cSrcweir }
1644cdf0e10cSrcweir if( !xOut.is() )
1645cdf0e10cSrcweir {
1646cdf0e10cSrcweir OSL_ENSURE( 0, "### couln't open output stream\n" );
1647cdf0e10cSrcweir return;
1648cdf0e10cSrcweir }
1649cdf0e10cSrcweir
1650cdf0e10cSrcweir Reference< XActiveDataSource > xSource( xHandler, UNO_QUERY );
1651cdf0e10cSrcweir xSource->setOutputStream( xOut );
1652cdf0e10cSrcweir
1653cdf0e10cSrcweir xmlscript::exportLibrary( xHandler, rLib );
1654cdf0e10cSrcweir }
1655cdf0e10cSrcweir
1656cdf0e10cSrcweir
implLoadLibraryIndexFile(SfxLibrary * pLib,::xmlscript::LibDescriptor & rLib,const uno::Reference<embed::XStorage> & xStorage,const OUString & aIndexFileName)1657cdf0e10cSrcweir sal_Bool SfxLibraryContainer::implLoadLibraryIndexFile( SfxLibrary* pLib,
1658cdf0e10cSrcweir ::xmlscript::LibDescriptor& rLib, const uno::Reference< embed::XStorage >& xStorage, const OUString& aIndexFileName )
1659cdf0e10cSrcweir {
1660cdf0e10cSrcweir Reference< XParser > xParser( mxMSF->createInstance(
1661cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ) ), UNO_QUERY );
1662cdf0e10cSrcweir if( !xParser.is() )
1663cdf0e10cSrcweir {
1664cdf0e10cSrcweir OSL_ENSURE( 0, "### couln't create sax parser component\n" );
1665cdf0e10cSrcweir return sal_False;
1666cdf0e10cSrcweir }
1667cdf0e10cSrcweir
1668cdf0e10cSrcweir sal_Bool bLink = sal_False;
1669cdf0e10cSrcweir sal_Bool bStorage = sal_False;
1670cdf0e10cSrcweir if( pLib )
1671cdf0e10cSrcweir {
1672cdf0e10cSrcweir bLink = pLib->mbLink;
1673cdf0e10cSrcweir bStorage = xStorage.is() && !bLink;
1674cdf0e10cSrcweir }
1675cdf0e10cSrcweir
1676cdf0e10cSrcweir // Read info file
1677cdf0e10cSrcweir uno::Reference< io::XInputStream > xInput;
1678cdf0e10cSrcweir String aLibInfoPath;
1679cdf0e10cSrcweir if( bStorage )
1680cdf0e10cSrcweir {
1681cdf0e10cSrcweir aLibInfoPath = maInfoFileName;
1682cdf0e10cSrcweir aLibInfoPath += String( RTL_CONSTASCII_USTRINGPARAM("-lb.xml") );
1683cdf0e10cSrcweir
1684cdf0e10cSrcweir try {
1685cdf0e10cSrcweir uno::Reference< io::XStream > xInfoStream =
1686cdf0e10cSrcweir xStorage->openStreamElement( aLibInfoPath, embed::ElementModes::READ );
1687cdf0e10cSrcweir xInput = xInfoStream->getInputStream();
1688cdf0e10cSrcweir }
1689cdf0e10cSrcweir catch( uno::Exception& )
1690cdf0e10cSrcweir {}
1691cdf0e10cSrcweir }
1692cdf0e10cSrcweir else
1693cdf0e10cSrcweir {
1694cdf0e10cSrcweir // Create Input stream
1695cdf0e10cSrcweir //String aLibInfoPath; // attention: THIS PROBLEM MUST BE REVIEWED BY SCRIPTING OWNER!!!
1696cdf0e10cSrcweir
1697cdf0e10cSrcweir if( pLib )
1698cdf0e10cSrcweir {
1699cdf0e10cSrcweir createAppLibraryFolder( pLib, rLib.aName );
1700cdf0e10cSrcweir aLibInfoPath = pLib->maLibInfoFileURL;
1701cdf0e10cSrcweir }
1702cdf0e10cSrcweir else
1703cdf0e10cSrcweir aLibInfoPath = aIndexFileName;
1704cdf0e10cSrcweir
1705cdf0e10cSrcweir try
1706cdf0e10cSrcweir {
1707cdf0e10cSrcweir xInput = mxSFI->openFileRead( aLibInfoPath );
1708cdf0e10cSrcweir }
1709cdf0e10cSrcweir catch( Exception& )
1710cdf0e10cSrcweir {
1711cdf0e10cSrcweir xInput.clear();
1712cdf0e10cSrcweir if( !GbMigrationSuppressErrors )
1713cdf0e10cSrcweir {
1714cdf0e10cSrcweir SfxErrorContext aEc( ERRCTX_SFX_LOADBASIC, aLibInfoPath );
1715cdf0e10cSrcweir sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
1716cdf0e10cSrcweir ErrorHandler::HandleError( nErrorCode );
1717cdf0e10cSrcweir }
1718cdf0e10cSrcweir }
1719cdf0e10cSrcweir }
1720cdf0e10cSrcweir if( !xInput.is() )
1721cdf0e10cSrcweir {
1722cdf0e10cSrcweir // OSL_ENSURE( 0, "### couln't open input stream\n" );
1723cdf0e10cSrcweir return sal_False;
1724cdf0e10cSrcweir }
1725cdf0e10cSrcweir
1726cdf0e10cSrcweir InputSource source;
1727cdf0e10cSrcweir source.aInputStream = xInput;
1728cdf0e10cSrcweir source.sSystemId = aLibInfoPath;
1729cdf0e10cSrcweir
1730cdf0e10cSrcweir // start parsing
1731cdf0e10cSrcweir try {
1732cdf0e10cSrcweir xParser->setDocumentHandler( ::xmlscript::importLibrary( rLib ) );
1733cdf0e10cSrcweir xParser->parseStream( source );
1734cdf0e10cSrcweir }
1735cdf0e10cSrcweir catch( Exception& )
1736cdf0e10cSrcweir {
1737cdf0e10cSrcweir // throw WrappedTargetException( OUString::createFromAscii( "parsing error!\n" ),
1738cdf0e10cSrcweir // Reference< XInterface >(),
1739cdf0e10cSrcweir // makeAny( e ) );
1740cdf0e10cSrcweir OSL_ENSURE( 0, "Parsing error\n" );
1741cdf0e10cSrcweir SfxErrorContext aEc( ERRCTX_SFX_LOADBASIC, aLibInfoPath );
1742cdf0e10cSrcweir sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
1743cdf0e10cSrcweir ErrorHandler::HandleError( nErrorCode );
1744cdf0e10cSrcweir return sal_False;
1745cdf0e10cSrcweir }
1746cdf0e10cSrcweir
1747cdf0e10cSrcweir if( !pLib )
1748cdf0e10cSrcweir {
1749cdf0e10cSrcweir Reference< XNameContainer > xLib = createLibrary( rLib.aName );
1750cdf0e10cSrcweir pLib = static_cast< SfxLibrary* >( xLib.get() );
1751cdf0e10cSrcweir pLib->mbLoaded = sal_False;
1752cdf0e10cSrcweir rLib.aStorageURL = aIndexFileName;
1753cdf0e10cSrcweir checkStorageURL( rLib.aStorageURL, pLib->maLibInfoFileURL, pLib->maStorageURL,
1754cdf0e10cSrcweir pLib->maUnexpandedStorageURL );
1755cdf0e10cSrcweir
1756cdf0e10cSrcweir implImportLibDescriptor( pLib, rLib );
1757cdf0e10cSrcweir }
1758cdf0e10cSrcweir
1759cdf0e10cSrcweir return sal_True;
1760cdf0e10cSrcweir }
1761cdf0e10cSrcweir
implImportLibDescriptor(SfxLibrary * pLib,::xmlscript::LibDescriptor & rLib)1762cdf0e10cSrcweir void SfxLibraryContainer::implImportLibDescriptor
1763cdf0e10cSrcweir ( SfxLibrary* pLib, ::xmlscript::LibDescriptor& rLib )
1764cdf0e10cSrcweir {
1765cdf0e10cSrcweir if( !pLib->mbInitialised )
1766cdf0e10cSrcweir {
1767cdf0e10cSrcweir sal_Int32 nElementCount = rLib.aElementNames.getLength();
1768cdf0e10cSrcweir const OUString* pElementNames = rLib.aElementNames.getConstArray();
1769cdf0e10cSrcweir Any aDummyElement = createEmptyLibraryElement();
1770cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
1771cdf0e10cSrcweir {
1772cdf0e10cSrcweir pLib->maNameContainer.insertByName( pElementNames[i], aDummyElement );
1773cdf0e10cSrcweir }
1774cdf0e10cSrcweir pLib->mbPasswordProtected = rLib.bPasswordProtected;
1775cdf0e10cSrcweir pLib->mbReadOnly = rLib.bReadOnly;
1776cdf0e10cSrcweir pLib->mbPreload = rLib.bPreload;
1777cdf0e10cSrcweir pLib->implSetModified( sal_False );
1778cdf0e10cSrcweir
1779cdf0e10cSrcweir pLib->mbInitialised = sal_True;
1780cdf0e10cSrcweir }
1781cdf0e10cSrcweir }
1782cdf0e10cSrcweir
1783cdf0e10cSrcweir
1784cdf0e10cSrcweir // Methods of new XLibraryStorage interface?
storeLibraries_Impl(const uno::Reference<embed::XStorage> & i_rStorage,sal_Bool bComplete)1785cdf0e10cSrcweir void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XStorage >& i_rStorage, sal_Bool bComplete )
1786cdf0e10cSrcweir {
1787cdf0e10cSrcweir const Sequence< OUString > aNames = maNameContainer.getElementNames();
1788cdf0e10cSrcweir sal_Int32 nNameCount = aNames.getLength();
1789cdf0e10cSrcweir const OUString* pName = aNames.getConstArray();
1790cdf0e10cSrcweir const OUString* pNamesEnd = aNames.getConstArray() + nNameCount;
1791cdf0e10cSrcweir
1792cdf0e10cSrcweir // Don't count libs from shared index file
1793cdf0e10cSrcweir sal_Int32 nLibsToSave = nNameCount;
1794cdf0e10cSrcweir for( ; pName != pNamesEnd; ++pName )
1795cdf0e10cSrcweir {
1796cdf0e10cSrcweir SfxLibrary* pImplLib = getImplLib( *pName );
1797cdf0e10cSrcweir if( pImplLib->mbSharedIndexFile || pImplLib->mbExtension )
1798cdf0e10cSrcweir nLibsToSave--;
1799cdf0e10cSrcweir }
1800cdf0e10cSrcweir if( !nLibsToSave )
1801cdf0e10cSrcweir return;
1802cdf0e10cSrcweir
1803cdf0e10cSrcweir ::xmlscript::LibDescriptorArray* pLibArray = new ::xmlscript::LibDescriptorArray( nLibsToSave );
1804cdf0e10cSrcweir
1805cdf0e10cSrcweir // Write to storage?
1806cdf0e10cSrcweir sal_Bool bStorage = i_rStorage.is();
1807cdf0e10cSrcweir uno::Reference< embed::XStorage > xSourceLibrariesStor;
1808cdf0e10cSrcweir uno::Reference< embed::XStorage > xTargetLibrariesStor;
1809cdf0e10cSrcweir ::rtl::OUString sTempTargetStorName;
1810cdf0e10cSrcweir const bool bInplaceStorage = bStorage && ( i_rStorage == mxStorage );
1811cdf0e10cSrcweir if ( bStorage )
1812cdf0e10cSrcweir {
1813cdf0e10cSrcweir // Don't write if only empty standard lib exists
1814cdf0e10cSrcweir if ( ( nNameCount == 1 ) && ( aNames[0].equalsAscii( "Standard" ) ) )
1815cdf0e10cSrcweir {
1816cdf0e10cSrcweir Any aLibAny = maNameContainer.getByName( aNames[0] );
1817cdf0e10cSrcweir Reference< XNameAccess > xNameAccess;
1818cdf0e10cSrcweir aLibAny >>= xNameAccess;
1819c887325fSJian Fang Zhang if ( !xNameAccess->hasElements() ){
1820c887325fSJian Fang Zhang delete pLibArray;
1821cdf0e10cSrcweir return;
1822cdf0e10cSrcweir }
1823c887325fSJian Fang Zhang }
1824cdf0e10cSrcweir
1825cdf0e10cSrcweir // create the empty target storage
1826cdf0e10cSrcweir try
1827cdf0e10cSrcweir {
1828cdf0e10cSrcweir ::rtl::OUString sTargetLibrariesStoreName;
1829cdf0e10cSrcweir if ( bInplaceStorage )
1830cdf0e10cSrcweir {
1831cdf0e10cSrcweir // create a temporary target storage
1832cdf0e10cSrcweir const ::rtl::OUStringBuffer aTempTargetNameBase = maLibrariesDir + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_temp_" ) );
1833cdf0e10cSrcweir sal_Int32 index = 0;
1834cdf0e10cSrcweir do
1835cdf0e10cSrcweir {
1836cdf0e10cSrcweir ::rtl::OUStringBuffer aTempTargetName( aTempTargetNameBase );
1837cdf0e10cSrcweir aTempTargetName.append( index++ );
1838cdf0e10cSrcweir
1839cdf0e10cSrcweir sTargetLibrariesStoreName = aTempTargetName.makeStringAndClear();
1840cdf0e10cSrcweir if ( !i_rStorage->hasByName( sTargetLibrariesStoreName ) )
1841cdf0e10cSrcweir break;
1842cdf0e10cSrcweir }
1843cdf0e10cSrcweir while ( true );
1844cdf0e10cSrcweir sTempTargetStorName = sTargetLibrariesStoreName;
1845cdf0e10cSrcweir }
1846cdf0e10cSrcweir else
1847cdf0e10cSrcweir {
1848cdf0e10cSrcweir sTargetLibrariesStoreName = maLibrariesDir;
1849cdf0e10cSrcweir if ( i_rStorage->hasByName( sTargetLibrariesStoreName ) )
1850cdf0e10cSrcweir i_rStorage->removeElement( sTargetLibrariesStoreName );
1851cdf0e10cSrcweir }
1852cdf0e10cSrcweir
1853cdf0e10cSrcweir xTargetLibrariesStor.set( i_rStorage->openStorageElement( sTargetLibrariesStoreName, embed::ElementModes::READWRITE ), UNO_QUERY_THROW );
1854cdf0e10cSrcweir }
1855cdf0e10cSrcweir catch( const uno::Exception& )
1856cdf0e10cSrcweir {
1857cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
1858cdf0e10cSrcweir return;
1859cdf0e10cSrcweir }
1860cdf0e10cSrcweir
1861cdf0e10cSrcweir // open the source storage which might be used to copy yet-unmodified libraries
1862cdf0e10cSrcweir try
1863cdf0e10cSrcweir {
1864cdf0e10cSrcweir if ( mxStorage->hasByName( maLibrariesDir ) )
1865cdf0e10cSrcweir xSourceLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, bInplaceStorage ? embed::ElementModes::READWRITE : embed::ElementModes::READ );
1866cdf0e10cSrcweir else if ( bInplaceStorage )
1867cdf0e10cSrcweir xSourceLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READWRITE );
1868cdf0e10cSrcweir }
1869cdf0e10cSrcweir catch( const uno::Exception& )
1870cdf0e10cSrcweir {
1871cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
1872cdf0e10cSrcweir return;
1873cdf0e10cSrcweir }
1874cdf0e10cSrcweir }
1875cdf0e10cSrcweir
1876cdf0e10cSrcweir int iArray = 0;
1877cdf0e10cSrcweir pName = aNames.getConstArray();
1878cdf0e10cSrcweir ::xmlscript::LibDescriptor aLibDescriptorForExtensionLibs;
1879cdf0e10cSrcweir for( ; pName != pNamesEnd; ++pName )
1880cdf0e10cSrcweir {
1881cdf0e10cSrcweir SfxLibrary* pImplLib = getImplLib( *pName );
1882cdf0e10cSrcweir if( pImplLib->mbSharedIndexFile )
1883cdf0e10cSrcweir continue;
1884cdf0e10cSrcweir const bool bExtensionLib = pImplLib->mbExtension;
1885cdf0e10cSrcweir ::xmlscript::LibDescriptor& rLib = bExtensionLib ?
1886cdf0e10cSrcweir aLibDescriptorForExtensionLibs : pLibArray->mpLibs[iArray];
1887cdf0e10cSrcweir if( !bExtensionLib )
1888cdf0e10cSrcweir iArray++;
1889cdf0e10cSrcweir rLib.aName = *pName;
1890cdf0e10cSrcweir
1891cdf0e10cSrcweir rLib.bLink = pImplLib->mbLink;
1892cdf0e10cSrcweir if( !bStorage || pImplLib->mbLink )
1893cdf0e10cSrcweir {
1894cdf0e10cSrcweir rLib.aStorageURL = ( pImplLib->maUnexpandedStorageURL.getLength() ) ?
1895cdf0e10cSrcweir pImplLib->maUnexpandedStorageURL : pImplLib->maLibInfoFileURL;
1896cdf0e10cSrcweir }
1897cdf0e10cSrcweir rLib.bReadOnly = pImplLib->mbReadOnly;
1898cdf0e10cSrcweir rLib.bPreload = pImplLib->mbPreload;
1899cdf0e10cSrcweir rLib.bPasswordProtected = pImplLib->mbPasswordProtected;
1900cdf0e10cSrcweir rLib.aElementNames = pImplLib->getElementNames();
1901cdf0e10cSrcweir
1902cdf0e10cSrcweir if( pImplLib->implIsModified() || bComplete )
1903cdf0e10cSrcweir {
1904cdf0e10cSrcweir // Can we simply copy the storage?
1905cdf0e10cSrcweir if( !mbOldInfoFormat && !pImplLib->implIsModified() && !mbOasis2OOoFormat && xSourceLibrariesStor.is() )
1906cdf0e10cSrcweir {
1907cdf0e10cSrcweir try
1908cdf0e10cSrcweir {
1909cdf0e10cSrcweir xSourceLibrariesStor->copyElementTo( rLib.aName, xTargetLibrariesStor, rLib.aName );
1910cdf0e10cSrcweir }
1911cdf0e10cSrcweir catch( const uno::Exception& )
1912cdf0e10cSrcweir {
1913cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
1914cdf0e10cSrcweir // TODO: error handling?
1915cdf0e10cSrcweir }
1916cdf0e10cSrcweir }
1917cdf0e10cSrcweir else
1918cdf0e10cSrcweir {
1919cdf0e10cSrcweir uno::Reference< embed::XStorage > xLibraryStor;
1920cdf0e10cSrcweir if( bStorage )
1921cdf0e10cSrcweir {
1922cdf0e10cSrcweir try
1923cdf0e10cSrcweir {
1924cdf0e10cSrcweir xLibraryStor = xTargetLibrariesStor->openStorageElement(
1925cdf0e10cSrcweir rLib.aName,
1926cdf0e10cSrcweir embed::ElementModes::READWRITE );
1927cdf0e10cSrcweir }
1928cdf0e10cSrcweir catch( uno::Exception& )
1929cdf0e10cSrcweir {
1930cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1931cdf0e10cSrcweir Any aError( ::cppu::getCaughtException() );
1932cdf0e10cSrcweir ::rtl::OStringBuffer aMessage;
1933cdf0e10cSrcweir aMessage.append( "couln't create sub storage for library '" );
1934cdf0e10cSrcweir aMessage.append( ::rtl::OUStringToOString( rLib.aName, osl_getThreadTextEncoding() ) );
1935cdf0e10cSrcweir aMessage.append( "'.\n\nException:" );
1936cdf0e10cSrcweir aMessage.append( ::rtl::OUStringToOString( ::comphelper::anyToString( aError ), osl_getThreadTextEncoding() ) );
1937cdf0e10cSrcweir OSL_ENSURE( false, aMessage.makeStringAndClear().getStr() );
1938cdf0e10cSrcweir #endif
1939cdf0e10cSrcweir return;
1940cdf0e10cSrcweir }
1941cdf0e10cSrcweir }
1942cdf0e10cSrcweir
1943cdf0e10cSrcweir // Maybe lib is not loaded?!
1944cdf0e10cSrcweir if( bComplete )
1945cdf0e10cSrcweir loadLibrary( rLib.aName );
1946cdf0e10cSrcweir
1947cdf0e10cSrcweir if( pImplLib->mbPasswordProtected )
1948cdf0e10cSrcweir implStorePasswordLibrary( pImplLib, rLib.aName, xLibraryStor, uno::Reference< task::XInteractionHandler >() );
1949cdf0e10cSrcweir // TODO: Check return value
1950cdf0e10cSrcweir else
1951cdf0e10cSrcweir implStoreLibrary( pImplLib, rLib.aName, xLibraryStor );
1952cdf0e10cSrcweir
1953cdf0e10cSrcweir implStoreLibraryIndexFile( pImplLib, rLib, xLibraryStor );
1954cdf0e10cSrcweir if( bStorage )
1955cdf0e10cSrcweir {
1956cdf0e10cSrcweir try
1957cdf0e10cSrcweir {
1958cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xTransact( xLibraryStor, uno::UNO_QUERY_THROW );
1959cdf0e10cSrcweir xTransact->commit();
1960cdf0e10cSrcweir }
1961cdf0e10cSrcweir catch( uno::Exception& )
1962cdf0e10cSrcweir {
1963cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
1964cdf0e10cSrcweir // TODO: error handling
1965cdf0e10cSrcweir }
1966cdf0e10cSrcweir }
1967cdf0e10cSrcweir }
1968cdf0e10cSrcweir
1969cdf0e10cSrcweir maModifiable.setModified( sal_True );
1970cdf0e10cSrcweir pImplLib->implSetModified( sal_False );
1971cdf0e10cSrcweir }
1972cdf0e10cSrcweir
1973cdf0e10cSrcweir // For container info ReadOnly refers to mbReadOnlyLink
1974cdf0e10cSrcweir rLib.bReadOnly = pImplLib->mbReadOnlyLink;
1975cdf0e10cSrcweir }
1976cdf0e10cSrcweir
1977cdf0e10cSrcweir // if we did an in-place save into a storage (i.e. a save into the storage we were already based on),
1978cdf0e10cSrcweir // then we need to clean up the temporary storage we used for this
1979*0848378bSHerbert Dürr if ( bInplaceStorage && !sTempTargetStorName.isEmpty() )
1980cdf0e10cSrcweir {
1981cdf0e10cSrcweir OSL_ENSURE( xSourceLibrariesStor.is(), "SfxLibrariesContainer::storeLibraries_impl: unexpected: we should have a source storage here!" );
1982cdf0e10cSrcweir try
1983cdf0e10cSrcweir {
1984cdf0e10cSrcweir // for this, we first remove everything from the source storage, then copy the complete content
1985cdf0e10cSrcweir // from the temporary target storage. From then on, what used to be the "source storage" becomes
1986cdf0e10cSrcweir // the "targt storage" for all subsequent operations.
1987cdf0e10cSrcweir
1988cdf0e10cSrcweir // (We cannot simply remove the storage, denoted by maLibrariesDir, from i_rStorage - there might be
1989cdf0e10cSrcweir // open references to it.)
1990cdf0e10cSrcweir
1991cdf0e10cSrcweir if ( xSourceLibrariesStor.is() )
1992cdf0e10cSrcweir {
1993cdf0e10cSrcweir // remove
1994cdf0e10cSrcweir const Sequence< ::rtl::OUString > aRemoveNames( xSourceLibrariesStor->getElementNames() );
1995cdf0e10cSrcweir for ( const ::rtl::OUString* pRemoveName = aRemoveNames.getConstArray();
1996cdf0e10cSrcweir pRemoveName != aRemoveNames.getConstArray() + aRemoveNames.getLength();
1997cdf0e10cSrcweir ++pRemoveName
1998cdf0e10cSrcweir )
1999cdf0e10cSrcweir {
2000cdf0e10cSrcweir xSourceLibrariesStor->removeElement( *pRemoveName );
2001cdf0e10cSrcweir }
2002cdf0e10cSrcweir
2003cdf0e10cSrcweir // copy
2004cdf0e10cSrcweir const Sequence< ::rtl::OUString > aCopyNames( xTargetLibrariesStor->getElementNames() );
2005cdf0e10cSrcweir for ( const ::rtl::OUString* pCopyName = aCopyNames.getConstArray();
2006cdf0e10cSrcweir pCopyName != aCopyNames.getConstArray() + aCopyNames.getLength();
2007cdf0e10cSrcweir ++pCopyName
2008cdf0e10cSrcweir )
2009cdf0e10cSrcweir {
2010cdf0e10cSrcweir xTargetLibrariesStor->copyElementTo( *pCopyName, xSourceLibrariesStor, *pCopyName );
2011cdf0e10cSrcweir }
2012cdf0e10cSrcweir }
2013cdf0e10cSrcweir
2014cdf0e10cSrcweir // close and remove temp target
2015cdf0e10cSrcweir xTargetLibrariesStor->dispose();
2016cdf0e10cSrcweir i_rStorage->removeElement( sTempTargetStorName );
2017cdf0e10cSrcweir xTargetLibrariesStor.clear();
2018cdf0e10cSrcweir sTempTargetStorName = ::rtl::OUString();
2019cdf0e10cSrcweir
2020cdf0e10cSrcweir // adjust target
2021cdf0e10cSrcweir xTargetLibrariesStor = xSourceLibrariesStor;
2022cdf0e10cSrcweir xSourceLibrariesStor.clear();
2023cdf0e10cSrcweir }
2024cdf0e10cSrcweir catch( const Exception& )
2025cdf0e10cSrcweir {
2026cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
2027cdf0e10cSrcweir }
2028cdf0e10cSrcweir }
2029cdf0e10cSrcweir
2030cdf0e10cSrcweir if( !mbOldInfoFormat && !maModifiable.isModified() )
2031cdf0e10cSrcweir return;
2032cdf0e10cSrcweir maModifiable.setModified( sal_False );
2033cdf0e10cSrcweir mbOldInfoFormat = sal_False;
2034cdf0e10cSrcweir
2035cdf0e10cSrcweir // Write library container info
2036cdf0e10cSrcweir // Create sax writer
2037cdf0e10cSrcweir Reference< XExtendedDocumentHandler > xHandler(
2038cdf0e10cSrcweir mxMSF->createInstance(
2039cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer") ) ), UNO_QUERY );
2040cdf0e10cSrcweir if( !xHandler.is() )
2041cdf0e10cSrcweir {
2042cdf0e10cSrcweir OSL_ENSURE( 0, "### couln't create sax-writer component\n" );
2043cdf0e10cSrcweir return;
2044cdf0e10cSrcweir }
2045cdf0e10cSrcweir
2046cdf0e10cSrcweir // Write info file
2047cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOut;
2048cdf0e10cSrcweir uno::Reference< io::XStream > xInfoStream;
2049cdf0e10cSrcweir if( bStorage )
2050cdf0e10cSrcweir {
2051cdf0e10cSrcweir OUString aStreamName( maInfoFileName );
2052cdf0e10cSrcweir aStreamName += String( RTL_CONSTASCII_USTRINGPARAM("-lc.xml") );
2053cdf0e10cSrcweir
2054cdf0e10cSrcweir try {
2055cdf0e10cSrcweir xInfoStream = xTargetLibrariesStor->openStreamElement( aStreamName, embed::ElementModes::READWRITE );
2056cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( xInfoStream, uno::UNO_QUERY );
2057cdf0e10cSrcweir OSL_ENSURE ( xProps.is(), "The stream must implement XPropertySet!\n" );
2058cdf0e10cSrcweir if ( !xProps.is() )
2059cdf0e10cSrcweir throw uno::RuntimeException();
2060cdf0e10cSrcweir
2061cdf0e10cSrcweir String aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) );
2062cdf0e10cSrcweir OUString aMime( RTL_CONSTASCII_USTRINGPARAM("text/xml") );
2063cdf0e10cSrcweir xProps->setPropertyValue( aPropName, uno::makeAny( aMime ) );
2064cdf0e10cSrcweir
2065cdf0e10cSrcweir // #87671 Allow encryption
2066cdf0e10cSrcweir aPropName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("UseCommonStoragePasswordEncryption") );
2067cdf0e10cSrcweir xProps->setPropertyValue( aPropName, uno::makeAny( sal_True ) );
2068cdf0e10cSrcweir
2069cdf0e10cSrcweir xOut = xInfoStream->getOutputStream();
2070cdf0e10cSrcweir }
2071cdf0e10cSrcweir catch( uno::Exception& )
2072cdf0e10cSrcweir {
2073cdf0e10cSrcweir sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
2074cdf0e10cSrcweir ErrorHandler::HandleError( nErrorCode );
2075cdf0e10cSrcweir }
2076cdf0e10cSrcweir }
2077cdf0e10cSrcweir else
2078cdf0e10cSrcweir {
2079cdf0e10cSrcweir // Create Output stream
2080cdf0e10cSrcweir INetURLObject aLibInfoInetObj( String(maLibraryPath).GetToken(1) );
2081cdf0e10cSrcweir aLibInfoInetObj.insertName( maInfoFileName, sal_True, INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
2082cdf0e10cSrcweir aLibInfoInetObj.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xlc") ) );
2083cdf0e10cSrcweir String aLibInfoPath( aLibInfoInetObj.GetMainURL( INetURLObject::NO_DECODE ) );
2084cdf0e10cSrcweir
2085cdf0e10cSrcweir try
2086cdf0e10cSrcweir {
2087cdf0e10cSrcweir if( mxSFI->exists( aLibInfoPath ) )
2088cdf0e10cSrcweir mxSFI->kill( aLibInfoPath );
2089cdf0e10cSrcweir xOut = mxSFI->openFileWrite( aLibInfoPath );
2090cdf0e10cSrcweir }
2091cdf0e10cSrcweir catch( Exception& )
2092cdf0e10cSrcweir {
2093cdf0e10cSrcweir xOut.clear();
2094cdf0e10cSrcweir SfxErrorContext aEc( ERRCTX_SFX_SAVEDOC, aLibInfoPath );
2095cdf0e10cSrcweir sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
2096cdf0e10cSrcweir ErrorHandler::HandleError( nErrorCode );
2097cdf0e10cSrcweir }
2098cdf0e10cSrcweir
2099cdf0e10cSrcweir }
2100cdf0e10cSrcweir if( !xOut.is() )
2101cdf0e10cSrcweir {
2102cdf0e10cSrcweir OSL_ENSURE( 0, "### couln't open output stream\n" );
2103cdf0e10cSrcweir return;
2104cdf0e10cSrcweir }
2105cdf0e10cSrcweir
2106cdf0e10cSrcweir Reference< XActiveDataSource > xSource( xHandler, UNO_QUERY );
2107cdf0e10cSrcweir xSource->setOutputStream( xOut );
2108cdf0e10cSrcweir
2109cdf0e10cSrcweir try
2110cdf0e10cSrcweir {
2111cdf0e10cSrcweir xmlscript::exportLibraryContainer( xHandler, pLibArray );
2112cdf0e10cSrcweir if ( bStorage )
2113cdf0e10cSrcweir {
2114cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xTransact( xTargetLibrariesStor, uno::UNO_QUERY );
2115cdf0e10cSrcweir OSL_ENSURE( xTransact.is(), "The storage must implement XTransactedObject!\n" );
2116cdf0e10cSrcweir if ( !xTransact.is() )
2117cdf0e10cSrcweir throw uno::RuntimeException();
2118cdf0e10cSrcweir
2119cdf0e10cSrcweir xTransact->commit();
2120cdf0e10cSrcweir }
2121cdf0e10cSrcweir }
2122cdf0e10cSrcweir catch( uno::Exception& )
2123cdf0e10cSrcweir {
2124cdf0e10cSrcweir OSL_ENSURE( sal_False, "Problem during storing of libraries!\n" );
2125cdf0e10cSrcweir sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
2126cdf0e10cSrcweir ErrorHandler::HandleError( nErrorCode );
2127cdf0e10cSrcweir }
2128cdf0e10cSrcweir
2129cdf0e10cSrcweir delete pLibArray;
2130cdf0e10cSrcweir }
2131cdf0e10cSrcweir
2132cdf0e10cSrcweir
2133cdf0e10cSrcweir // Methods XElementAccess
getElementType()2134cdf0e10cSrcweir Type SAL_CALL SfxLibraryContainer::getElementType()
2135cdf0e10cSrcweir throw(RuntimeException)
2136cdf0e10cSrcweir {
2137cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2138cdf0e10cSrcweir return maNameContainer.getElementType();
2139cdf0e10cSrcweir }
2140cdf0e10cSrcweir
hasElements()2141cdf0e10cSrcweir sal_Bool SfxLibraryContainer::hasElements()
2142cdf0e10cSrcweir throw(RuntimeException)
2143cdf0e10cSrcweir {
2144cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2145cdf0e10cSrcweir sal_Bool bRet = maNameContainer.hasElements();
2146cdf0e10cSrcweir return bRet;
2147cdf0e10cSrcweir }
2148cdf0e10cSrcweir
2149cdf0e10cSrcweir // Methods XNameAccess
getByName(const OUString & aName)2150cdf0e10cSrcweir Any SfxLibraryContainer::getByName( const OUString& aName )
2151cdf0e10cSrcweir throw(NoSuchElementException, WrappedTargetException, RuntimeException)
2152cdf0e10cSrcweir {
2153cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2154cdf0e10cSrcweir Any aRetAny = maNameContainer.getByName( aName ) ;
2155cdf0e10cSrcweir return aRetAny;
2156cdf0e10cSrcweir }
2157cdf0e10cSrcweir
getElementNames()2158cdf0e10cSrcweir Sequence< OUString > SfxLibraryContainer::getElementNames()
2159cdf0e10cSrcweir throw(RuntimeException)
2160cdf0e10cSrcweir {
2161cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2162cdf0e10cSrcweir return maNameContainer.getElementNames();
2163cdf0e10cSrcweir }
2164cdf0e10cSrcweir
hasByName(const OUString & aName)2165cdf0e10cSrcweir sal_Bool SfxLibraryContainer::hasByName( const OUString& aName )
2166cdf0e10cSrcweir throw(RuntimeException)
2167cdf0e10cSrcweir {
2168cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2169cdf0e10cSrcweir return maNameContainer.hasByName( aName ) ;
2170cdf0e10cSrcweir }
2171cdf0e10cSrcweir
2172cdf0e10cSrcweir // Methods XLibraryContainer
createLibrary(const OUString & Name)2173cdf0e10cSrcweir Reference< XNameContainer > SAL_CALL SfxLibraryContainer::createLibrary( const OUString& Name )
2174cdf0e10cSrcweir throw(IllegalArgumentException, ElementExistException, RuntimeException)
2175cdf0e10cSrcweir {
2176cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2177cdf0e10cSrcweir SfxLibrary* pNewLib = implCreateLibrary( Name );
2178cdf0e10cSrcweir pNewLib->maLibElementFileExtension = maLibElementFileExtension;
2179cdf0e10cSrcweir
2180cdf0e10cSrcweir createVariableURL( pNewLib->maUnexpandedStorageURL, Name, maInfoFileName, true );
2181cdf0e10cSrcweir
2182cdf0e10cSrcweir Reference< XNameAccess > xNameAccess = static_cast< XNameAccess* >( pNewLib );
2183cdf0e10cSrcweir Any aElement;
2184cdf0e10cSrcweir aElement <<= xNameAccess;
2185cdf0e10cSrcweir maNameContainer.insertByName( Name, aElement );
2186cdf0e10cSrcweir maModifiable.setModified( sal_True );
2187cdf0e10cSrcweir Reference< XNameContainer > xRet( xNameAccess, UNO_QUERY );
2188cdf0e10cSrcweir return xRet;
2189cdf0e10cSrcweir }
2190cdf0e10cSrcweir
createLibraryLink(const OUString & Name,const OUString & StorageURL,sal_Bool ReadOnly)2191cdf0e10cSrcweir Reference< XNameAccess > SAL_CALL SfxLibraryContainer::createLibraryLink
2192cdf0e10cSrcweir ( const OUString& Name, const OUString& StorageURL, sal_Bool ReadOnly )
2193cdf0e10cSrcweir throw(IllegalArgumentException, ElementExistException, RuntimeException)
2194cdf0e10cSrcweir {
2195cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2196cdf0e10cSrcweir // TODO: Check other reasons to force ReadOnly status
2197cdf0e10cSrcweir //if( !ReadOnly )
2198cdf0e10cSrcweir //{
2199cdf0e10cSrcweir //}
2200cdf0e10cSrcweir
2201cdf0e10cSrcweir OUString aLibInfoFileURL;
2202cdf0e10cSrcweir OUString aLibDirURL;
2203cdf0e10cSrcweir OUString aUnexpandedStorageURL;
2204cdf0e10cSrcweir checkStorageURL( StorageURL, aLibInfoFileURL, aLibDirURL, aUnexpandedStorageURL );
2205cdf0e10cSrcweir
2206cdf0e10cSrcweir
2207cdf0e10cSrcweir SfxLibrary* pNewLib = implCreateLibraryLink( Name, aLibInfoFileURL, aLibDirURL, ReadOnly );
2208cdf0e10cSrcweir pNewLib->maLibElementFileExtension = maLibElementFileExtension;
2209cdf0e10cSrcweir pNewLib->maUnexpandedStorageURL = aUnexpandedStorageURL;
2210cdf0e10cSrcweir pNewLib->maOrignialStorageURL = StorageURL;
2211cdf0e10cSrcweir
2212cdf0e10cSrcweir OUString aInitFileName;
2213cdf0e10cSrcweir uno::Reference< embed::XStorage > xDummyStor;
2214cdf0e10cSrcweir ::xmlscript::LibDescriptor aLibDesc;
2215cdf0e10cSrcweir /*sal_Bool bReadIndexFile = */implLoadLibraryIndexFile( pNewLib, aLibDesc, xDummyStor, aInitFileName );
2216cdf0e10cSrcweir implImportLibDescriptor( pNewLib, aLibDesc );
2217cdf0e10cSrcweir
2218cdf0e10cSrcweir Reference< XNameAccess > xRet = static_cast< XNameAccess* >( pNewLib );
2219cdf0e10cSrcweir Any aElement;
2220cdf0e10cSrcweir aElement <<= xRet;
2221cdf0e10cSrcweir maNameContainer.insertByName( Name, aElement );
2222cdf0e10cSrcweir maModifiable.setModified( sal_True );
2223cdf0e10cSrcweir
2224cdf0e10cSrcweir OUString aUserSearchStr = OUString::createFromAscii( "vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE" );
2225cdf0e10cSrcweir OUString aSharedSearchStr = OUString::createFromAscii( "vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE" );
2226cdf0e10cSrcweir OUString aBundledSearchStr = OUString::createFromAscii( "vnd.sun.star.expand:$BUNDLED_EXTENSIONS" );
2227cdf0e10cSrcweir if( StorageURL.indexOf( aUserSearchStr ) != -1 )
2228cdf0e10cSrcweir {
2229cdf0e10cSrcweir pNewLib->mbExtension = sal_True;
2230cdf0e10cSrcweir }
2231cdf0e10cSrcweir else if( StorageURL.indexOf( aSharedSearchStr ) != -1 || StorageURL.indexOf( aBundledSearchStr ) != -1 )
2232cdf0e10cSrcweir {
2233cdf0e10cSrcweir pNewLib->mbExtension = sal_True;
2234cdf0e10cSrcweir pNewLib->mbReadOnly = sal_True;
2235cdf0e10cSrcweir }
2236cdf0e10cSrcweir
2237cdf0e10cSrcweir return xRet;
2238cdf0e10cSrcweir }
2239cdf0e10cSrcweir
removeLibrary(const OUString & Name)2240cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::removeLibrary( const OUString& Name )
2241cdf0e10cSrcweir throw(NoSuchElementException, WrappedTargetException, RuntimeException)
2242cdf0e10cSrcweir {
2243cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2244cdf0e10cSrcweir // Get and hold library before removing
2245cdf0e10cSrcweir Any aLibAny = maNameContainer.getByName( Name ) ;
2246cdf0e10cSrcweir Reference< XNameAccess > xNameAccess;
2247cdf0e10cSrcweir aLibAny >>= xNameAccess;
2248cdf0e10cSrcweir SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
2249cdf0e10cSrcweir if( pImplLib->mbReadOnly && !pImplLib->mbLink )
2250cdf0e10cSrcweir throw IllegalArgumentException();
2251cdf0e10cSrcweir
2252cdf0e10cSrcweir // Remove from container
2253cdf0e10cSrcweir maNameContainer.removeByName( Name );
2254cdf0e10cSrcweir maModifiable.setModified( sal_True );
2255cdf0e10cSrcweir
2256cdf0e10cSrcweir // Delete library files, but not for linked libraries
2257cdf0e10cSrcweir if( !pImplLib->mbLink )
2258cdf0e10cSrcweir {
2259cdf0e10cSrcweir if( mxStorage.is() )
2260cdf0e10cSrcweir return;
2261cdf0e10cSrcweir if( xNameAccess->hasElements() )
2262cdf0e10cSrcweir {
2263cdf0e10cSrcweir Sequence< OUString > aNames = pImplLib->getElementNames();
2264cdf0e10cSrcweir sal_Int32 nNameCount = aNames.getLength();
2265cdf0e10cSrcweir const OUString* pNames = aNames.getConstArray();
2266cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nNameCount ; ++i, ++pNames )
2267cdf0e10cSrcweir {
2268cdf0e10cSrcweir pImplLib->removeElementWithoutChecks( *pNames, SfxLibrary::LibraryContainerAccess() );
2269cdf0e10cSrcweir }
2270cdf0e10cSrcweir }
2271cdf0e10cSrcweir
2272cdf0e10cSrcweir // Delete index file
2273cdf0e10cSrcweir createAppLibraryFolder( pImplLib, Name );
2274cdf0e10cSrcweir String aLibInfoPath = pImplLib->maLibInfoFileURL;
2275cdf0e10cSrcweir try
2276cdf0e10cSrcweir {
2277cdf0e10cSrcweir if( mxSFI->exists( aLibInfoPath ) )
2278cdf0e10cSrcweir mxSFI->kill( aLibInfoPath );
2279cdf0e10cSrcweir }
2280cdf0e10cSrcweir catch( Exception& ) {}
2281cdf0e10cSrcweir
2282cdf0e10cSrcweir // Delete folder if empty
2283cdf0e10cSrcweir INetURLObject aInetObj( String(maLibraryPath).GetToken(1) );
2284cdf0e10cSrcweir aInetObj.insertName( Name, sal_True, INetURLObject::LAST_SEGMENT,
2285cdf0e10cSrcweir sal_True, INetURLObject::ENCODE_ALL );
2286cdf0e10cSrcweir OUString aLibDirPath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
2287cdf0e10cSrcweir
2288cdf0e10cSrcweir try
2289cdf0e10cSrcweir {
2290cdf0e10cSrcweir if( mxSFI->isFolder( aLibDirPath ) )
2291cdf0e10cSrcweir {
2292cdf0e10cSrcweir Sequence< OUString > aContentSeq = mxSFI->getFolderContents( aLibDirPath, true );
2293cdf0e10cSrcweir sal_Int32 nCount = aContentSeq.getLength();
2294cdf0e10cSrcweir if( !nCount )
2295cdf0e10cSrcweir mxSFI->kill( aLibDirPath );
2296cdf0e10cSrcweir }
2297cdf0e10cSrcweir }
2298cdf0e10cSrcweir catch( Exception& )
2299cdf0e10cSrcweir {
2300cdf0e10cSrcweir }
2301cdf0e10cSrcweir }
2302cdf0e10cSrcweir }
2303cdf0e10cSrcweir
isLibraryLoaded(const OUString & Name)2304cdf0e10cSrcweir sal_Bool SAL_CALL SfxLibraryContainer::isLibraryLoaded( const OUString& Name )
2305cdf0e10cSrcweir throw(NoSuchElementException, RuntimeException)
2306cdf0e10cSrcweir {
2307cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2308cdf0e10cSrcweir SfxLibrary* pImplLib = getImplLib( Name );
2309cdf0e10cSrcweir sal_Bool bRet = pImplLib->mbLoaded;
2310cdf0e10cSrcweir return bRet;
2311cdf0e10cSrcweir }
2312cdf0e10cSrcweir
2313cdf0e10cSrcweir
loadLibrary(const OUString & Name)2314cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
2315cdf0e10cSrcweir throw(NoSuchElementException, WrappedTargetException, RuntimeException)
2316cdf0e10cSrcweir {
2317cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2318cdf0e10cSrcweir Any aLibAny = maNameContainer.getByName( Name ) ;
2319cdf0e10cSrcweir Reference< XNameAccess > xNameAccess;
2320cdf0e10cSrcweir aLibAny >>= xNameAccess;
2321cdf0e10cSrcweir SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
2322cdf0e10cSrcweir
2323cdf0e10cSrcweir sal_Bool bLoaded = pImplLib->mbLoaded;
2324cdf0e10cSrcweir pImplLib->mbLoaded = sal_True;
2325cdf0e10cSrcweir if( !bLoaded && xNameAccess->hasElements() )
2326cdf0e10cSrcweir {
2327cdf0e10cSrcweir if( pImplLib->mbPasswordProtected )
2328cdf0e10cSrcweir {
2329cdf0e10cSrcweir implLoadPasswordLibrary( pImplLib, Name );
2330cdf0e10cSrcweir return;
2331cdf0e10cSrcweir }
2332cdf0e10cSrcweir
2333cdf0e10cSrcweir sal_Bool bLink = pImplLib->mbLink;
2334cdf0e10cSrcweir sal_Bool bStorage = mxStorage.is() && !bLink;
2335cdf0e10cSrcweir
2336cdf0e10cSrcweir uno::Reference< embed::XStorage > xLibrariesStor;
2337cdf0e10cSrcweir uno::Reference< embed::XStorage > xLibraryStor;
2338cdf0e10cSrcweir if( bStorage )
2339cdf0e10cSrcweir {
2340cdf0e10cSrcweir try {
2341cdf0e10cSrcweir xLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READ );
2342cdf0e10cSrcweir OSL_ENSURE( xLibrariesStor.is(), "The method must either throw exception or return a storage!\n" );
2343cdf0e10cSrcweir if ( !xLibrariesStor.is() )
2344cdf0e10cSrcweir throw uno::RuntimeException();
2345cdf0e10cSrcweir
2346cdf0e10cSrcweir xLibraryStor = xLibrariesStor->openStorageElement( Name, embed::ElementModes::READ );
2347cdf0e10cSrcweir OSL_ENSURE( xLibraryStor.is(), "The method must either throw exception or return a storage!\n" );
2348cdf0e10cSrcweir if ( !xLibrariesStor.is() )
2349cdf0e10cSrcweir throw uno::RuntimeException();
2350cdf0e10cSrcweir }
2351cdf0e10cSrcweir catch( uno::Exception& )
2352cdf0e10cSrcweir {
2353cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
2354cdf0e10cSrcweir Any aError( ::cppu::getCaughtException() );
2355cdf0e10cSrcweir ::rtl::OStringBuffer aMessage;
2356cdf0e10cSrcweir aMessage.append( "couln't open sub storage for library '" );
2357cdf0e10cSrcweir aMessage.append( ::rtl::OUStringToOString( Name, osl_getThreadTextEncoding() ) );
2358cdf0e10cSrcweir aMessage.append( "'.\n\nException:" );
2359cdf0e10cSrcweir aMessage.append( ::rtl::OUStringToOString( ::comphelper::anyToString( aError ), osl_getThreadTextEncoding() ) );
2360cdf0e10cSrcweir OSL_ENSURE( false, aMessage.makeStringAndClear().getStr() );
2361cdf0e10cSrcweir #endif
2362cdf0e10cSrcweir return;
2363cdf0e10cSrcweir }
2364cdf0e10cSrcweir }
2365cdf0e10cSrcweir
2366cdf0e10cSrcweir Sequence< OUString > aNames = pImplLib->getElementNames();
2367cdf0e10cSrcweir sal_Int32 nNameCount = aNames.getLength();
2368cdf0e10cSrcweir const OUString* pNames = aNames.getConstArray();
2369cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
2370cdf0e10cSrcweir {
2371cdf0e10cSrcweir OUString aElementName = pNames[ i ];
2372cdf0e10cSrcweir
2373cdf0e10cSrcweir OUString aFile;
2374cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream;
2375cdf0e10cSrcweir
2376cdf0e10cSrcweir if( bStorage )
2377cdf0e10cSrcweir {
2378cdf0e10cSrcweir uno::Reference< io::XStream > xElementStream;
2379cdf0e10cSrcweir
2380cdf0e10cSrcweir aFile = aElementName;
2381cdf0e10cSrcweir aFile += String( RTL_CONSTASCII_USTRINGPARAM(".xml") );
2382cdf0e10cSrcweir
2383cdf0e10cSrcweir try {
2384cdf0e10cSrcweir xElementStream = xLibraryStor->openStreamElement( aFile, embed::ElementModes::READ );
2385cdf0e10cSrcweir } catch( uno::Exception& )
2386cdf0e10cSrcweir {}
2387cdf0e10cSrcweir
2388cdf0e10cSrcweir if( !xElementStream.is() )
2389cdf0e10cSrcweir {
2390cdf0e10cSrcweir // Check for EA2 document version with wrong extensions
2391cdf0e10cSrcweir aFile = aElementName;
2392cdf0e10cSrcweir aFile += String( RTL_CONSTASCII_USTRINGPARAM(".") );
2393cdf0e10cSrcweir aFile += maLibElementFileExtension;
2394cdf0e10cSrcweir try {
2395cdf0e10cSrcweir xElementStream = xLibraryStor->openStreamElement( aFile, embed::ElementModes::READ );
2396cdf0e10cSrcweir } catch( uno::Exception& )
2397cdf0e10cSrcweir {}
2398cdf0e10cSrcweir }
2399cdf0e10cSrcweir
2400cdf0e10cSrcweir if ( xElementStream.is() )
2401cdf0e10cSrcweir xInStream = xElementStream->getInputStream();
2402cdf0e10cSrcweir
2403cdf0e10cSrcweir if ( !xInStream.is() )
2404cdf0e10cSrcweir {
2405cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
2406cdf0e10cSrcweir ::rtl::OStringBuffer aMessage;
2407cdf0e10cSrcweir aMessage.append( "couln't open library element stream - attempted to open library '" );
2408cdf0e10cSrcweir aMessage.append( ::rtl::OUStringToOString( Name, osl_getThreadTextEncoding() ) );
2409cdf0e10cSrcweir aMessage.append( "'." );
2410cdf0e10cSrcweir OSL_ENSURE( false, aMessage.makeStringAndClear().getStr() );
2411cdf0e10cSrcweir #endif
2412cdf0e10cSrcweir return;
2413cdf0e10cSrcweir }
2414cdf0e10cSrcweir }
2415cdf0e10cSrcweir else
2416cdf0e10cSrcweir {
2417cdf0e10cSrcweir String aLibDirPath = pImplLib->maStorageURL;
2418cdf0e10cSrcweir INetURLObject aElementInetObj( aLibDirPath );
2419cdf0e10cSrcweir aElementInetObj.insertName( aElementName, sal_False,
2420cdf0e10cSrcweir INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
2421cdf0e10cSrcweir aElementInetObj.setExtension( maLibElementFileExtension );
2422cdf0e10cSrcweir aFile = aElementInetObj.GetMainURL( INetURLObject::NO_DECODE );
2423cdf0e10cSrcweir }
2424cdf0e10cSrcweir
2425cdf0e10cSrcweir Reference< XNameContainer > xLib( pImplLib );
2426cdf0e10cSrcweir Any aAny = importLibraryElement( xLib, aElementName,
2427cdf0e10cSrcweir aFile, xInStream );
2428cdf0e10cSrcweir if( pImplLib->hasByName( aElementName ) )
2429cdf0e10cSrcweir {
2430cdf0e10cSrcweir if( aAny.hasValue() )
2431cdf0e10cSrcweir pImplLib->maNameContainer.replaceByName( aElementName, aAny );
2432cdf0e10cSrcweir }
2433cdf0e10cSrcweir else
2434cdf0e10cSrcweir {
2435cdf0e10cSrcweir pImplLib->maNameContainer.insertByName( aElementName, aAny );
2436cdf0e10cSrcweir }
2437cdf0e10cSrcweir }
2438cdf0e10cSrcweir
2439cdf0e10cSrcweir pImplLib->implSetModified( sal_False );
2440cdf0e10cSrcweir }
2441cdf0e10cSrcweir }
2442cdf0e10cSrcweir
2443cdf0e10cSrcweir // Methods XLibraryContainer2
isLibraryLink(const OUString & Name)2444cdf0e10cSrcweir sal_Bool SAL_CALL SfxLibraryContainer::isLibraryLink( const OUString& Name )
2445cdf0e10cSrcweir throw (NoSuchElementException, RuntimeException)
2446cdf0e10cSrcweir {
2447cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2448cdf0e10cSrcweir SfxLibrary* pImplLib = getImplLib( Name );
2449cdf0e10cSrcweir sal_Bool bRet = pImplLib->mbLink;
2450cdf0e10cSrcweir return bRet;
2451cdf0e10cSrcweir }
2452cdf0e10cSrcweir
getLibraryLinkURL(const OUString & Name)2453cdf0e10cSrcweir OUString SAL_CALL SfxLibraryContainer::getLibraryLinkURL( const OUString& Name )
2454cdf0e10cSrcweir throw (IllegalArgumentException, NoSuchElementException, RuntimeException)
2455cdf0e10cSrcweir {
2456cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2457cdf0e10cSrcweir SfxLibrary* pImplLib = getImplLib( Name );
2458cdf0e10cSrcweir sal_Bool bLink = pImplLib->mbLink;
2459cdf0e10cSrcweir if( !bLink )
2460cdf0e10cSrcweir throw IllegalArgumentException();
2461cdf0e10cSrcweir OUString aRetStr = pImplLib->maLibInfoFileURL;
2462cdf0e10cSrcweir return aRetStr;
2463cdf0e10cSrcweir }
2464cdf0e10cSrcweir
isLibraryReadOnly(const OUString & Name)2465cdf0e10cSrcweir sal_Bool SAL_CALL SfxLibraryContainer::isLibraryReadOnly( const OUString& Name )
2466cdf0e10cSrcweir throw (NoSuchElementException, RuntimeException)
2467cdf0e10cSrcweir {
2468cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2469cdf0e10cSrcweir SfxLibrary* pImplLib = getImplLib( Name );
2470cdf0e10cSrcweir sal_Bool bRet = pImplLib->mbReadOnly || (pImplLib->mbLink && pImplLib->mbReadOnlyLink);
2471cdf0e10cSrcweir return bRet;
2472cdf0e10cSrcweir }
2473cdf0e10cSrcweir
setLibraryReadOnly(const OUString & Name,sal_Bool bReadOnly)2474cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::setLibraryReadOnly( const OUString& Name, sal_Bool bReadOnly )
2475cdf0e10cSrcweir throw (NoSuchElementException, RuntimeException)
2476cdf0e10cSrcweir {
2477cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2478cdf0e10cSrcweir SfxLibrary* pImplLib = getImplLib( Name );
2479cdf0e10cSrcweir if( pImplLib->mbLink )
2480cdf0e10cSrcweir {
2481cdf0e10cSrcweir if( pImplLib->mbReadOnlyLink != bReadOnly )
2482cdf0e10cSrcweir {
2483cdf0e10cSrcweir pImplLib->mbReadOnlyLink = bReadOnly;
2484cdf0e10cSrcweir pImplLib->implSetModified( sal_True );
2485cdf0e10cSrcweir maModifiable.setModified( sal_True );
2486cdf0e10cSrcweir }
2487cdf0e10cSrcweir }
2488cdf0e10cSrcweir else
2489cdf0e10cSrcweir {
2490cdf0e10cSrcweir if( pImplLib->mbReadOnly != bReadOnly )
2491cdf0e10cSrcweir {
2492cdf0e10cSrcweir pImplLib->mbReadOnly = bReadOnly;
2493cdf0e10cSrcweir pImplLib->implSetModified( sal_True );
2494cdf0e10cSrcweir }
2495cdf0e10cSrcweir }
2496cdf0e10cSrcweir }
2497cdf0e10cSrcweir
renameLibrary(const OUString & Name,const OUString & NewName)2498cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OUString& NewName )
2499cdf0e10cSrcweir throw (NoSuchElementException, ElementExistException, RuntimeException)
2500cdf0e10cSrcweir {
2501cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2502cdf0e10cSrcweir if( maNameContainer.hasByName( NewName ) )
2503cdf0e10cSrcweir throw ElementExistException();
2504cdf0e10cSrcweir
2505cdf0e10cSrcweir // Get and hold library before removing
2506cdf0e10cSrcweir Any aLibAny = maNameContainer.getByName( Name ) ;
2507cdf0e10cSrcweir
2508cdf0e10cSrcweir // #i24094 Maybe lib is not loaded!
2509cdf0e10cSrcweir Reference< XNameAccess > xNameAccess;
2510cdf0e10cSrcweir aLibAny >>= xNameAccess;
2511cdf0e10cSrcweir SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
2512cdf0e10cSrcweir if( pImplLib->mbPasswordProtected && !pImplLib->mbPasswordVerified )
2513cdf0e10cSrcweir return; // Lib with unverified password cannot be renamed
2514cdf0e10cSrcweir loadLibrary( Name );
2515cdf0e10cSrcweir
2516cdf0e10cSrcweir // Remove from container
2517cdf0e10cSrcweir maNameContainer.removeByName( Name );
2518cdf0e10cSrcweir maModifiable.setModified( sal_True );
2519cdf0e10cSrcweir
2520cdf0e10cSrcweir // Rename library folder, but not for linked libraries
2521cdf0e10cSrcweir bool bMovedSuccessful = true;
2522cdf0e10cSrcweir
2523cdf0e10cSrcweir // Rename files
2524cdf0e10cSrcweir sal_Bool bStorage = mxStorage.is();
2525cdf0e10cSrcweir if( !bStorage && !pImplLib->mbLink )
2526cdf0e10cSrcweir {
2527cdf0e10cSrcweir bMovedSuccessful = false;
2528cdf0e10cSrcweir
2529cdf0e10cSrcweir OUString aLibDirPath = pImplLib->maStorageURL;
2530cdf0e10cSrcweir
2531cdf0e10cSrcweir INetURLObject aDestInetObj( String(maLibraryPath).GetToken(1) );
2532cdf0e10cSrcweir aDestInetObj.insertName( NewName, sal_True, INetURLObject::LAST_SEGMENT,
2533cdf0e10cSrcweir sal_True, INetURLObject::ENCODE_ALL );
2534cdf0e10cSrcweir OUString aDestDirPath = aDestInetObj.GetMainURL( INetURLObject::NO_DECODE );
2535cdf0e10cSrcweir
2536cdf0e10cSrcweir // Store new URL
2537cdf0e10cSrcweir OUString aLibInfoFileURL = pImplLib->maLibInfoFileURL;
2538cdf0e10cSrcweir checkStorageURL( aDestDirPath, pImplLib->maLibInfoFileURL, pImplLib->maStorageURL,
2539cdf0e10cSrcweir pImplLib->maUnexpandedStorageURL );
2540cdf0e10cSrcweir
2541cdf0e10cSrcweir try
2542cdf0e10cSrcweir {
2543cdf0e10cSrcweir if( mxSFI->isFolder( aLibDirPath ) )
2544cdf0e10cSrcweir {
2545cdf0e10cSrcweir if( !mxSFI->isFolder( aDestDirPath ) )
2546cdf0e10cSrcweir mxSFI->createFolder( aDestDirPath );
2547cdf0e10cSrcweir
2548cdf0e10cSrcweir // Move index file
2549cdf0e10cSrcweir try
2550cdf0e10cSrcweir {
2551cdf0e10cSrcweir if( mxSFI->exists( pImplLib->maLibInfoFileURL ) )
2552cdf0e10cSrcweir mxSFI->kill( pImplLib->maLibInfoFileURL );
2553cdf0e10cSrcweir mxSFI->move( aLibInfoFileURL, pImplLib->maLibInfoFileURL );
2554cdf0e10cSrcweir }
2555cdf0e10cSrcweir catch( Exception& )
2556cdf0e10cSrcweir {
2557cdf0e10cSrcweir }
2558cdf0e10cSrcweir
2559cdf0e10cSrcweir Sequence< OUString > aElementNames = xNameAccess->getElementNames();
2560cdf0e10cSrcweir sal_Int32 nNameCount = aElementNames.getLength();
2561cdf0e10cSrcweir const OUString* pNames = aElementNames.getConstArray();
2562cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
2563cdf0e10cSrcweir {
2564cdf0e10cSrcweir OUString aElementName = pNames[ i ];
2565cdf0e10cSrcweir
2566cdf0e10cSrcweir INetURLObject aElementInetObj( aLibDirPath );
2567cdf0e10cSrcweir aElementInetObj.insertName( aElementName, sal_False,
2568cdf0e10cSrcweir INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
2569cdf0e10cSrcweir aElementInetObj.setExtension( maLibElementFileExtension );
2570cdf0e10cSrcweir String aElementPath( aElementInetObj.GetMainURL( INetURLObject::NO_DECODE ) );
2571cdf0e10cSrcweir
2572cdf0e10cSrcweir INetURLObject aElementDestInetObj( aDestDirPath );
2573cdf0e10cSrcweir aElementDestInetObj.insertName( aElementName, sal_False,
2574cdf0e10cSrcweir INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
2575cdf0e10cSrcweir aElementDestInetObj.setExtension( maLibElementFileExtension );
2576cdf0e10cSrcweir String aDestElementPath( aElementDestInetObj.GetMainURL( INetURLObject::NO_DECODE ) );
2577cdf0e10cSrcweir
2578cdf0e10cSrcweir try
2579cdf0e10cSrcweir {
2580cdf0e10cSrcweir if( mxSFI->exists( aDestElementPath ) )
2581cdf0e10cSrcweir mxSFI->kill( aDestElementPath );
2582cdf0e10cSrcweir mxSFI->move( aElementPath, aDestElementPath );
2583cdf0e10cSrcweir }
2584cdf0e10cSrcweir catch( Exception& )
2585cdf0e10cSrcweir {
2586cdf0e10cSrcweir }
2587cdf0e10cSrcweir }
2588cdf0e10cSrcweir pImplLib->storeResourcesAsURL( aDestDirPath, NewName );
2589cdf0e10cSrcweir
2590cdf0e10cSrcweir // Delete folder if empty
2591cdf0e10cSrcweir Sequence< OUString > aContentSeq = mxSFI->getFolderContents( aLibDirPath, true );
2592cdf0e10cSrcweir sal_Int32 nCount = aContentSeq.getLength();
2593cdf0e10cSrcweir if( !nCount )
2594cdf0e10cSrcweir {
2595cdf0e10cSrcweir mxSFI->kill( aLibDirPath );
2596cdf0e10cSrcweir }
2597cdf0e10cSrcweir
2598cdf0e10cSrcweir bMovedSuccessful = true;
2599cdf0e10cSrcweir pImplLib->implSetModified( sal_True );
2600cdf0e10cSrcweir }
2601cdf0e10cSrcweir }
2602cdf0e10cSrcweir catch( Exception& )
2603cdf0e10cSrcweir {
2604cdf0e10cSrcweir // Restore old library
2605cdf0e10cSrcweir maNameContainer.insertByName( Name, aLibAny ) ;
2606cdf0e10cSrcweir }
2607cdf0e10cSrcweir }
2608cdf0e10cSrcweir
2609cdf0e10cSrcweir if( bStorage && !pImplLib->mbLink )
2610cdf0e10cSrcweir pImplLib->implSetModified( sal_True );
2611cdf0e10cSrcweir
2612cdf0e10cSrcweir if( bMovedSuccessful )
2613cdf0e10cSrcweir maNameContainer.insertByName( NewName, aLibAny ) ;
2614cdf0e10cSrcweir
2615cdf0e10cSrcweir }
2616cdf0e10cSrcweir
2617cdf0e10cSrcweir
2618cdf0e10cSrcweir // Methods XInitialization
initialize(const Sequence<Any> & _rArguments)2619cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::initialize( const Sequence< Any >& _rArguments )
2620cdf0e10cSrcweir throw (Exception, RuntimeException)
2621cdf0e10cSrcweir {
2622cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2623cdf0e10cSrcweir sal_Int32 nArgCount = _rArguments.getLength();
2624cdf0e10cSrcweir if ( nArgCount == 1 )
2625cdf0e10cSrcweir {
2626cdf0e10cSrcweir OUString sInitialDocumentURL;
2627cdf0e10cSrcweir Reference< XStorageBasedDocument > xDocument;
2628cdf0e10cSrcweir if ( _rArguments[0] >>= sInitialDocumentURL )
2629cdf0e10cSrcweir {
2630cdf0e10cSrcweir initializeFromDocumentURL( sInitialDocumentURL );
2631cdf0e10cSrcweir return;
2632cdf0e10cSrcweir }
2633cdf0e10cSrcweir
2634cdf0e10cSrcweir if ( _rArguments[0] >>= xDocument )
2635cdf0e10cSrcweir {
2636cdf0e10cSrcweir initializeFromDocument( xDocument );
2637cdf0e10cSrcweir return;
2638cdf0e10cSrcweir }
2639cdf0e10cSrcweir }
2640cdf0e10cSrcweir
2641cdf0e10cSrcweir throw IllegalArgumentException();
2642cdf0e10cSrcweir }
2643cdf0e10cSrcweir
initializeFromDocumentURL(const::rtl::OUString & _rInitialDocumentURL)2644cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::initializeFromDocumentURL( const ::rtl::OUString& _rInitialDocumentURL )
2645cdf0e10cSrcweir {
2646cdf0e10cSrcweir init( _rInitialDocumentURL, NULL );
2647cdf0e10cSrcweir }
2648cdf0e10cSrcweir
initializeFromDocument(const Reference<XStorageBasedDocument> & _rxDocument)2649cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::initializeFromDocument( const Reference< XStorageBasedDocument >& _rxDocument )
2650cdf0e10cSrcweir {
2651cdf0e10cSrcweir // check whether this is a valid OfficeDocument, and obtain the document's root storage
2652cdf0e10cSrcweir Reference< XStorage > xDocStorage;
2653cdf0e10cSrcweir try
2654cdf0e10cSrcweir {
2655cdf0e10cSrcweir Reference< XServiceInfo > xSI( _rxDocument, UNO_QUERY_THROW );
2656cdf0e10cSrcweir if ( xSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.OfficeDocument" ) ) ) )
2657cdf0e10cSrcweir xDocStorage.set( _rxDocument->getDocumentStorage(), UNO_QUERY_THROW );
2658cdf0e10cSrcweir
2659cdf0e10cSrcweir Reference< XModel > xDocument( _rxDocument, UNO_QUERY_THROW );
2660cdf0e10cSrcweir Reference< XComponent > xDocComponent( _rxDocument, UNO_QUERY_THROW );
2661cdf0e10cSrcweir
2662cdf0e10cSrcweir mxOwnerDocument = xDocument;
2663cdf0e10cSrcweir startComponentListening( xDocComponent );
2664cdf0e10cSrcweir }
2665cdf0e10cSrcweir catch( const Exception& ) { }
2666cdf0e10cSrcweir
2667cdf0e10cSrcweir if ( !xDocStorage.is() )
2668cdf0e10cSrcweir throw IllegalArgumentException();
2669cdf0e10cSrcweir
2670cdf0e10cSrcweir init( OUString(), xDocStorage );
2671cdf0e10cSrcweir }
2672cdf0e10cSrcweir
2673cdf0e10cSrcweir // OEventListenerAdapter
_disposing(const EventObject & _rSource)2674cdf0e10cSrcweir void SfxLibraryContainer::_disposing( const EventObject& _rSource )
2675cdf0e10cSrcweir {
2676cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
2677cdf0e10cSrcweir Reference< XModel > xDocument( mxOwnerDocument.get(), UNO_QUERY );
2678cdf0e10cSrcweir OSL_ENSURE( ( xDocument == _rSource.Source ) && xDocument.is(), "SfxLibraryContainer::_disposing: where does this come from?" );
2679cdf0e10cSrcweir #else
2680cdf0e10cSrcweir (void)_rSource;
2681cdf0e10cSrcweir #endif
2682cdf0e10cSrcweir dispose();
2683cdf0e10cSrcweir }
2684cdf0e10cSrcweir
2685cdf0e10cSrcweir // OComponentHelper
disposing()2686cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::disposing()
2687cdf0e10cSrcweir {
2688cdf0e10cSrcweir Reference< XModel > xModel = mxOwnerDocument;
2689cdf0e10cSrcweir EventObject aEvent( xModel.get() );
2690cdf0e10cSrcweir maVBAScriptListeners.disposing( aEvent );
2691cdf0e10cSrcweir stopAllComponentListening();
2692cdf0e10cSrcweir mxOwnerDocument = WeakReference< XModel >();
2693cdf0e10cSrcweir }
2694cdf0e10cSrcweir
2695cdf0e10cSrcweir // Methods XLibraryContainerPassword
isLibraryPasswordProtected(const OUString &)2696cdf0e10cSrcweir sal_Bool SAL_CALL SfxLibraryContainer::isLibraryPasswordProtected( const OUString& )
2697cdf0e10cSrcweir throw (NoSuchElementException, RuntimeException)
2698cdf0e10cSrcweir {
2699cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2700cdf0e10cSrcweir return sal_False;
2701cdf0e10cSrcweir }
2702cdf0e10cSrcweir
isLibraryPasswordVerified(const OUString &)2703cdf0e10cSrcweir sal_Bool SAL_CALL SfxLibraryContainer::isLibraryPasswordVerified( const OUString& )
2704cdf0e10cSrcweir throw (IllegalArgumentException, NoSuchElementException, RuntimeException)
2705cdf0e10cSrcweir {
2706cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2707cdf0e10cSrcweir throw IllegalArgumentException();
2708cdf0e10cSrcweir }
2709cdf0e10cSrcweir
verifyLibraryPassword(const OUString &,const OUString &)2710cdf0e10cSrcweir sal_Bool SAL_CALL SfxLibraryContainer::verifyLibraryPassword
2711cdf0e10cSrcweir ( const OUString&, const OUString& )
2712cdf0e10cSrcweir throw (IllegalArgumentException, NoSuchElementException, RuntimeException)
2713cdf0e10cSrcweir {
2714cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2715cdf0e10cSrcweir throw IllegalArgumentException();
2716cdf0e10cSrcweir }
2717cdf0e10cSrcweir
changeLibraryPassword(const OUString &,const OUString &,const OUString &)2718cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::changeLibraryPassword(
2719cdf0e10cSrcweir const OUString&, const OUString&, const OUString& )
2720cdf0e10cSrcweir throw (IllegalArgumentException, NoSuchElementException, RuntimeException)
2721cdf0e10cSrcweir {
2722cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2723cdf0e10cSrcweir throw IllegalArgumentException();
2724cdf0e10cSrcweir }
2725cdf0e10cSrcweir
2726cdf0e10cSrcweir // Methods XContainer
addContainerListener(const Reference<XContainerListener> & xListener)2727cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::addContainerListener( const Reference< XContainerListener >& xListener )
2728cdf0e10cSrcweir throw (RuntimeException)
2729cdf0e10cSrcweir {
2730cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2731cdf0e10cSrcweir maNameContainer.setEventSource( static_cast< XInterface* >( (OWeakObject*)this ) );
2732cdf0e10cSrcweir maNameContainer.addContainerListener( xListener );
2733cdf0e10cSrcweir }
2734cdf0e10cSrcweir
removeContainerListener(const Reference<XContainerListener> & xListener)2735cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::removeContainerListener( const Reference< XContainerListener >& xListener )
2736cdf0e10cSrcweir throw (RuntimeException)
2737cdf0e10cSrcweir {
2738cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2739cdf0e10cSrcweir maNameContainer.removeContainerListener( xListener );
2740cdf0e10cSrcweir }
2741cdf0e10cSrcweir
2742cdf0e10cSrcweir // Methods XLibraryContainerExport
exportLibrary(const OUString & Name,const OUString & URL,const Reference<XInteractionHandler> & Handler)2743cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::exportLibrary( const OUString& Name, const OUString& URL,
2744cdf0e10cSrcweir const Reference< XInteractionHandler >& Handler )
2745cdf0e10cSrcweir throw ( uno::Exception, NoSuchElementException, RuntimeException)
2746cdf0e10cSrcweir {
2747cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2748cdf0e10cSrcweir SfxLibrary* pImplLib = getImplLib( Name );
2749cdf0e10cSrcweir
2750cdf0e10cSrcweir Reference< XSimpleFileAccess > xToUseSFI;
2751cdf0e10cSrcweir if( Handler.is() )
2752cdf0e10cSrcweir {
2753cdf0e10cSrcweir xToUseSFI = Reference< XSimpleFileAccess >( mxMSF->createInstance
2754cdf0e10cSrcweir ( OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY );
2755cdf0e10cSrcweir if( xToUseSFI.is() )
2756cdf0e10cSrcweir xToUseSFI->setInteractionHandler( Handler );
2757cdf0e10cSrcweir }
2758cdf0e10cSrcweir
2759cdf0e10cSrcweir // Maybe lib is not loaded?!
2760cdf0e10cSrcweir loadLibrary( Name );
2761cdf0e10cSrcweir
2762cdf0e10cSrcweir uno::Reference< ::com::sun::star::embed::XStorage > xDummyStor;
2763cdf0e10cSrcweir if( pImplLib->mbPasswordProtected )
2764cdf0e10cSrcweir implStorePasswordLibrary( pImplLib, Name, xDummyStor, URL, xToUseSFI, Handler );
2765cdf0e10cSrcweir else
2766cdf0e10cSrcweir implStoreLibrary( pImplLib, Name, xDummyStor, URL, xToUseSFI, Handler );
2767cdf0e10cSrcweir
2768cdf0e10cSrcweir ::xmlscript::LibDescriptor aLibDesc;
2769cdf0e10cSrcweir aLibDesc.aName = Name;
2770cdf0e10cSrcweir aLibDesc.bLink = false; // Link status gets lost?
2771cdf0e10cSrcweir aLibDesc.bReadOnly = pImplLib->mbReadOnly;
2772cdf0e10cSrcweir aLibDesc.bPreload = false; // Preload status gets lost?
2773cdf0e10cSrcweir aLibDesc.bPasswordProtected = pImplLib->mbPasswordProtected;
2774cdf0e10cSrcweir aLibDesc.aElementNames = pImplLib->getElementNames();
2775cdf0e10cSrcweir
2776cdf0e10cSrcweir implStoreLibraryIndexFile( pImplLib, aLibDesc, xDummyStor, URL, xToUseSFI );
2777cdf0e10cSrcweir }
2778cdf0e10cSrcweir
expand_url(const OUString & url)2779cdf0e10cSrcweir OUString SfxLibraryContainer::expand_url( const OUString& url )
2780cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
2781cdf0e10cSrcweir {
2782cdf0e10cSrcweir if (0 == url.compareToAscii( RTL_CONSTASCII_STRINGPARAM(EXPAND_PROTOCOL ":") ))
2783cdf0e10cSrcweir {
2784cdf0e10cSrcweir if( !mxMacroExpander.is() )
2785cdf0e10cSrcweir {
2786cdf0e10cSrcweir Reference< XPropertySet > xProps( mxMSF, UNO_QUERY );
2787cdf0e10cSrcweir OSL_ASSERT( xProps.is() );
2788cdf0e10cSrcweir if( xProps.is() )
2789cdf0e10cSrcweir {
2790cdf0e10cSrcweir Reference< XComponentContext > xContext;
2791cdf0e10cSrcweir xProps->getPropertyValue(
2792cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xContext;
2793cdf0e10cSrcweir OSL_ASSERT( xContext.is() );
2794cdf0e10cSrcweir if( xContext.is() )
2795cdf0e10cSrcweir {
2796cdf0e10cSrcweir Reference< util::XMacroExpander > xExpander;
2797cdf0e10cSrcweir xContext->getValueByName(
2798cdf0e10cSrcweir OUSTR("/singletons/com.sun.star.util.theMacroExpander") ) >>= xExpander;
2799cdf0e10cSrcweir if(! xExpander.is())
2800cdf0e10cSrcweir {
2801cdf0e10cSrcweir throw uno::DeploymentException(
2802cdf0e10cSrcweir OUSTR("no macro expander singleton available!"), Reference< XInterface >() );
2803cdf0e10cSrcweir }
2804cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() );
2805cdf0e10cSrcweir if( !mxMacroExpander.is() )
2806cdf0e10cSrcweir {
2807cdf0e10cSrcweir mxMacroExpander = xExpander;
2808cdf0e10cSrcweir }
2809cdf0e10cSrcweir }
2810cdf0e10cSrcweir }
2811cdf0e10cSrcweir }
2812cdf0e10cSrcweir
2813cdf0e10cSrcweir if( !mxMacroExpander.is() )
2814cdf0e10cSrcweir return url;
2815cdf0e10cSrcweir
2816cdf0e10cSrcweir // cut protocol
2817cdf0e10cSrcweir OUString macro( url.copy( sizeof (EXPAND_PROTOCOL ":") -1 ) );
2818cdf0e10cSrcweir // decode uric class chars
2819cdf0e10cSrcweir macro = Uri::decode( macro, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
2820cdf0e10cSrcweir // expand macro string
2821cdf0e10cSrcweir OUString ret( mxMacroExpander->expandMacros( macro ) );
2822cdf0e10cSrcweir return ret;
2823cdf0e10cSrcweir }
2824cdf0e10cSrcweir else if( mxStringSubstitution.is() )
2825cdf0e10cSrcweir {
2826cdf0e10cSrcweir OUString ret( mxStringSubstitution->substituteVariables( url, false ) );
2827cdf0e10cSrcweir return ret;
2828cdf0e10cSrcweir }
2829cdf0e10cSrcweir else
2830cdf0e10cSrcweir {
2831cdf0e10cSrcweir return url;
2832cdf0e10cSrcweir }
2833cdf0e10cSrcweir }
2834cdf0e10cSrcweir
2835cdf0e10cSrcweir //XLibraryContainer3
getOriginalLibraryLinkURL(const OUString & Name)2836cdf0e10cSrcweir OUString SAL_CALL SfxLibraryContainer::getOriginalLibraryLinkURL( const OUString& Name )
2837cdf0e10cSrcweir throw (IllegalArgumentException, NoSuchElementException, RuntimeException)
2838cdf0e10cSrcweir {
2839cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2840cdf0e10cSrcweir SfxLibrary* pImplLib = getImplLib( Name );
2841cdf0e10cSrcweir sal_Bool bLink = pImplLib->mbLink;
2842cdf0e10cSrcweir if( !bLink )
2843cdf0e10cSrcweir throw IllegalArgumentException();
2844cdf0e10cSrcweir OUString aRetStr = pImplLib->maOrignialStorageURL;
2845cdf0e10cSrcweir return aRetStr;
2846cdf0e10cSrcweir }
2847cdf0e10cSrcweir
2848cdf0e10cSrcweir
2849cdf0e10cSrcweir // XVBACompatibility
getVBACompatibilityMode()2850cdf0e10cSrcweir ::sal_Bool SAL_CALL SfxLibraryContainer::getVBACompatibilityMode() throw (RuntimeException)
2851cdf0e10cSrcweir {
2852cdf0e10cSrcweir return mbVBACompat;
2853cdf0e10cSrcweir }
2854cdf0e10cSrcweir
setVBACompatibilityMode(::sal_Bool _vbacompatmodeon)2855cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::setVBACompatibilityMode( ::sal_Bool _vbacompatmodeon ) throw (RuntimeException)
2856cdf0e10cSrcweir {
2857cdf0e10cSrcweir /* The member variable mbVBACompat must be set first, the following call
2858cdf0e10cSrcweir to getBasicManager() may call getVBACompatibilityMode() which returns
2859cdf0e10cSrcweir this value. */
2860cdf0e10cSrcweir mbVBACompat = _vbacompatmodeon;
2861cdf0e10cSrcweir if( BasicManager* pBasMgr = getBasicManager() )
2862cdf0e10cSrcweir {
2863cdf0e10cSrcweir // get the standard library
2864cdf0e10cSrcweir String aLibName = pBasMgr->GetName();
2865cdf0e10cSrcweir if ( aLibName.Len() == 0 )
2866cdf0e10cSrcweir aLibName = String( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
2867cdf0e10cSrcweir
2868cdf0e10cSrcweir if( StarBASIC* pBasic = pBasMgr->GetLib( aLibName ) )
2869cdf0e10cSrcweir pBasic->SetVBAEnabled( _vbacompatmodeon );
2870cdf0e10cSrcweir
2871cdf0e10cSrcweir /* If in VBA compatibility mode, force creation of the VBA Globals
2872cdf0e10cSrcweir object. Each application will create an instance of its own
2873cdf0e10cSrcweir implementation and store it in its Basic manager. Implementations
2874cdf0e10cSrcweir will do all necessary additional initialization, such as
2875cdf0e10cSrcweir registering the global "This***Doc" UNO constant, starting the
2876cdf0e10cSrcweir document events processor etc.
2877cdf0e10cSrcweir */
2878cdf0e10cSrcweir if( mbVBACompat ) try
2879cdf0e10cSrcweir {
2880cdf0e10cSrcweir Reference< XModel > xModel( mxOwnerDocument ); // weak-ref -> ref
2881cdf0e10cSrcweir Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW );
2882cdf0e10cSrcweir xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAGlobals" ) ) );
2883cdf0e10cSrcweir }
2884cdf0e10cSrcweir catch( Exception& )
2885cdf0e10cSrcweir {
2886cdf0e10cSrcweir }
2887cdf0e10cSrcweir }
2888cdf0e10cSrcweir }
2889cdf0e10cSrcweir
getRunningVBAScripts()2890cdf0e10cSrcweir sal_Int32 SAL_CALL SfxLibraryContainer::getRunningVBAScripts() throw (RuntimeException)
2891cdf0e10cSrcweir {
2892cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2893cdf0e10cSrcweir return mnRunningVBAScripts;
2894cdf0e10cSrcweir }
2895cdf0e10cSrcweir
addVBAScriptListener(const Reference<vba::XVBAScriptListener> & rxListener)2896cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::addVBAScriptListener( const Reference< vba::XVBAScriptListener >& rxListener ) throw (RuntimeException)
2897cdf0e10cSrcweir {
2898cdf0e10cSrcweir maVBAScriptListeners.addTypedListener( rxListener );
2899cdf0e10cSrcweir }
2900cdf0e10cSrcweir
removeVBAScriptListener(const Reference<vba::XVBAScriptListener> & rxListener)2901cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::removeVBAScriptListener( const Reference< vba::XVBAScriptListener >& rxListener ) throw (RuntimeException)
2902cdf0e10cSrcweir {
2903cdf0e10cSrcweir maVBAScriptListeners.removeTypedListener( rxListener );
2904cdf0e10cSrcweir }
2905cdf0e10cSrcweir
broadcastVBAScriptEvent(sal_Int32 nIdentifier,const::rtl::OUString & rModuleName)2906cdf0e10cSrcweir void SAL_CALL SfxLibraryContainer::broadcastVBAScriptEvent( sal_Int32 nIdentifier, const ::rtl::OUString& rModuleName ) throw (RuntimeException)
2907cdf0e10cSrcweir {
2908cdf0e10cSrcweir // own lock for accessing the number of running scripts
2909cdf0e10cSrcweir enterMethod();
2910cdf0e10cSrcweir switch( nIdentifier )
2911cdf0e10cSrcweir {
2912cdf0e10cSrcweir case vba::VBAScriptEventId::SCRIPT_STARTED:
2913cdf0e10cSrcweir ++mnRunningVBAScripts;
2914cdf0e10cSrcweir break;
2915cdf0e10cSrcweir case vba::VBAScriptEventId::SCRIPT_STOPPED:
2916cdf0e10cSrcweir --mnRunningVBAScripts;
2917cdf0e10cSrcweir break;
2918cdf0e10cSrcweir }
2919cdf0e10cSrcweir leaveMethod();
2920cdf0e10cSrcweir
2921cdf0e10cSrcweir Reference< XModel > xModel = mxOwnerDocument; // weak-ref -> ref
2922cdf0e10cSrcweir Reference< XInterface > xSender( xModel, UNO_QUERY_THROW );
2923cdf0e10cSrcweir vba::VBAScriptEvent aEvent( xSender, nIdentifier, rModuleName );
2924cdf0e10cSrcweir maVBAScriptListeners.notify( aEvent );
2925cdf0e10cSrcweir }
2926cdf0e10cSrcweir
2927cdf0e10cSrcweir // Methods XServiceInfo
supportsService(const::rtl::OUString & _rServiceName)2928cdf0e10cSrcweir ::sal_Bool SAL_CALL SfxLibraryContainer::supportsService( const ::rtl::OUString& _rServiceName )
2929cdf0e10cSrcweir throw (RuntimeException)
2930cdf0e10cSrcweir {
2931cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
2932cdf0e10cSrcweir Sequence< OUString > aSupportedServices( getSupportedServiceNames() );
2933cdf0e10cSrcweir const OUString* pSupportedServices = aSupportedServices.getConstArray();
2934cdf0e10cSrcweir for ( sal_Int32 i=0; i<aSupportedServices.getLength(); ++i, ++pSupportedServices )
2935cdf0e10cSrcweir if ( *pSupportedServices == _rServiceName )
2936cdf0e10cSrcweir return sal_True;
2937cdf0e10cSrcweir return sal_False;
2938cdf0e10cSrcweir }
2939cdf0e10cSrcweir
2940cdf0e10cSrcweir //============================================================================
2941cdf0e10cSrcweir
2942cdf0e10cSrcweir // Implementation class SfxLibrary
2943cdf0e10cSrcweir
2944cdf0e10cSrcweir // Ctor
SfxLibrary(ModifiableHelper & _rModifiable,const Type & aType,const Reference<XMultiServiceFactory> & xMSF,const Reference<XSimpleFileAccess> & xSFI)2945cdf0e10cSrcweir SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
2946cdf0e10cSrcweir const Reference< XMultiServiceFactory >& xMSF, const Reference< XSimpleFileAccess >& xSFI )
2947cdf0e10cSrcweir : OComponentHelper( m_aMutex )
2948cdf0e10cSrcweir , mxMSF( xMSF )
2949cdf0e10cSrcweir , mxSFI( xSFI )
2950cdf0e10cSrcweir , mrModifiable( _rModifiable )
2951cdf0e10cSrcweir , maNameContainer( aType )
2952cdf0e10cSrcweir , mbLoaded( sal_True )
2953cdf0e10cSrcweir , mbIsModified( sal_True )
2954cdf0e10cSrcweir , mbInitialised( sal_False )
2955cdf0e10cSrcweir , mbLink( sal_False )
2956cdf0e10cSrcweir , mbReadOnly( sal_False )
2957cdf0e10cSrcweir , mbReadOnlyLink( sal_False )
2958cdf0e10cSrcweir , mbPreload( sal_False )
2959cdf0e10cSrcweir , mbPasswordProtected( sal_False )
2960cdf0e10cSrcweir , mbPasswordVerified( sal_False )
2961cdf0e10cSrcweir , mbDoc50Password( sal_False )
2962cdf0e10cSrcweir , mbSharedIndexFile( sal_False )
2963cdf0e10cSrcweir , mbExtension( sal_False )
2964cdf0e10cSrcweir {
2965cdf0e10cSrcweir }
2966cdf0e10cSrcweir
SfxLibrary(ModifiableHelper & _rModifiable,const Type & aType,const Reference<XMultiServiceFactory> & xMSF,const Reference<XSimpleFileAccess> & xSFI,const OUString & aLibInfoFileURL,const OUString & aStorageURL,sal_Bool ReadOnly)2967cdf0e10cSrcweir SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
2968cdf0e10cSrcweir const Reference< XMultiServiceFactory >& xMSF, const Reference< XSimpleFileAccess >& xSFI,
2969cdf0e10cSrcweir const OUString& aLibInfoFileURL, const OUString& aStorageURL, sal_Bool ReadOnly )
2970cdf0e10cSrcweir : OComponentHelper( m_aMutex )
2971cdf0e10cSrcweir , mxMSF( xMSF )
2972cdf0e10cSrcweir , mxSFI( xSFI )
2973cdf0e10cSrcweir , mrModifiable( _rModifiable )
2974cdf0e10cSrcweir , maNameContainer( aType )
2975cdf0e10cSrcweir , mbLoaded( sal_False )
2976cdf0e10cSrcweir , mbIsModified( sal_True )
2977cdf0e10cSrcweir , mbInitialised( sal_False )
2978cdf0e10cSrcweir , maLibInfoFileURL( aLibInfoFileURL )
2979cdf0e10cSrcweir , maStorageURL( aStorageURL )
2980cdf0e10cSrcweir , mbLink( sal_True )
2981cdf0e10cSrcweir , mbReadOnly( sal_False )
2982cdf0e10cSrcweir , mbReadOnlyLink( ReadOnly )
2983cdf0e10cSrcweir , mbPreload( sal_False )
2984cdf0e10cSrcweir , mbPasswordProtected( sal_False )
2985cdf0e10cSrcweir , mbPasswordVerified( sal_False )
2986cdf0e10cSrcweir , mbDoc50Password( sal_False )
2987cdf0e10cSrcweir , mbSharedIndexFile( sal_False )
2988cdf0e10cSrcweir , mbExtension( sal_False )
2989cdf0e10cSrcweir {
2990cdf0e10cSrcweir }
2991cdf0e10cSrcweir
implSetModified(sal_Bool _bIsModified)2992cdf0e10cSrcweir void SfxLibrary::implSetModified( sal_Bool _bIsModified )
2993cdf0e10cSrcweir {
2994cdf0e10cSrcweir if ( mbIsModified == _bIsModified )
2995cdf0e10cSrcweir return;
2996cdf0e10cSrcweir mbIsModified = _bIsModified;
2997cdf0e10cSrcweir if ( mbIsModified )
2998cdf0e10cSrcweir mrModifiable.setModified( sal_True );
2999cdf0e10cSrcweir }
3000cdf0e10cSrcweir
3001cdf0e10cSrcweir // Methods XInterface
queryInterface(const Type & rType)3002cdf0e10cSrcweir Any SAL_CALL SfxLibrary::queryInterface( const Type& rType )
3003cdf0e10cSrcweir throw( RuntimeException )
3004cdf0e10cSrcweir {
3005cdf0e10cSrcweir Any aRet;
3006cdf0e10cSrcweir
3007cdf0e10cSrcweir /*
3008cdf0e10cSrcweir if( mbReadOnly )
3009cdf0e10cSrcweir {
3010cdf0e10cSrcweir aRet = Any( ::cppu::queryInterface( rType,
3011cdf0e10cSrcweir static_cast< XContainer * >( this ),
3012cdf0e10cSrcweir static_cast< XNameAccess * >( this ) ) );
3013cdf0e10cSrcweir }
3014cdf0e10cSrcweir else
3015cdf0e10cSrcweir {
3016cdf0e10cSrcweir */
3017cdf0e10cSrcweir aRet = Any( ::cppu::queryInterface( rType,
3018cdf0e10cSrcweir static_cast< XContainer * >( this ),
3019cdf0e10cSrcweir static_cast< XNameContainer * >( this ),
3020cdf0e10cSrcweir static_cast< XNameAccess * >( this ),
3021cdf0e10cSrcweir static_cast< XElementAccess * >( this ),
3022cdf0e10cSrcweir static_cast< XChangesNotifier * >( this ) ) );
3023cdf0e10cSrcweir //}
3024cdf0e10cSrcweir if( !aRet.hasValue() )
3025cdf0e10cSrcweir aRet = OComponentHelper::queryInterface( rType );
3026cdf0e10cSrcweir return aRet;
3027cdf0e10cSrcweir }
3028cdf0e10cSrcweir
3029cdf0e10cSrcweir // Methods XElementAccess
getElementType()3030cdf0e10cSrcweir Type SfxLibrary::getElementType()
3031cdf0e10cSrcweir throw(RuntimeException)
3032cdf0e10cSrcweir {
3033cdf0e10cSrcweir return maNameContainer.getElementType();
3034cdf0e10cSrcweir }
3035cdf0e10cSrcweir
hasElements()3036cdf0e10cSrcweir sal_Bool SfxLibrary::hasElements()
3037cdf0e10cSrcweir throw(RuntimeException)
3038cdf0e10cSrcweir {
3039cdf0e10cSrcweir sal_Bool bRet = maNameContainer.hasElements();
3040cdf0e10cSrcweir return bRet;
3041cdf0e10cSrcweir }
3042cdf0e10cSrcweir
3043cdf0e10cSrcweir // Methods XNameAccess
getByName(const OUString & aName)3044cdf0e10cSrcweir Any SfxLibrary::getByName( const OUString& aName )
3045cdf0e10cSrcweir throw(NoSuchElementException, WrappedTargetException, RuntimeException)
3046cdf0e10cSrcweir {
3047cdf0e10cSrcweir impl_checkLoaded();
3048cdf0e10cSrcweir
3049cdf0e10cSrcweir Any aRetAny = maNameContainer.getByName( aName ) ;
3050cdf0e10cSrcweir return aRetAny;
3051cdf0e10cSrcweir }
3052cdf0e10cSrcweir
getElementNames()3053cdf0e10cSrcweir Sequence< OUString > SfxLibrary::getElementNames()
3054cdf0e10cSrcweir throw(RuntimeException)
3055cdf0e10cSrcweir {
3056cdf0e10cSrcweir return maNameContainer.getElementNames();
3057cdf0e10cSrcweir }
3058cdf0e10cSrcweir
hasByName(const OUString & aName)3059cdf0e10cSrcweir sal_Bool SfxLibrary::hasByName( const OUString& aName )
3060cdf0e10cSrcweir throw(RuntimeException)
3061cdf0e10cSrcweir {
3062cdf0e10cSrcweir sal_Bool bRet = maNameContainer.hasByName( aName );
3063cdf0e10cSrcweir return bRet;
3064cdf0e10cSrcweir }
3065cdf0e10cSrcweir
impl_checkReadOnly()3066cdf0e10cSrcweir void SfxLibrary::impl_checkReadOnly()
3067cdf0e10cSrcweir {
3068cdf0e10cSrcweir if( mbReadOnly || (mbLink && mbReadOnlyLink) )
3069cdf0e10cSrcweir throw IllegalArgumentException(
3070cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Library is readonly." ) ),
3071cdf0e10cSrcweir // TODO: resource
3072cdf0e10cSrcweir *this, 0
3073cdf0e10cSrcweir );
3074cdf0e10cSrcweir }
3075cdf0e10cSrcweir
impl_checkLoaded()3076cdf0e10cSrcweir void SfxLibrary::impl_checkLoaded()
3077cdf0e10cSrcweir {
3078cdf0e10cSrcweir if ( !mbLoaded )
3079cdf0e10cSrcweir throw WrappedTargetException(
3080cdf0e10cSrcweir ::rtl::OUString(),
3081cdf0e10cSrcweir *this,
3082cdf0e10cSrcweir makeAny( LibraryNotLoadedException(
3083cdf0e10cSrcweir ::rtl::OUString(),
3084cdf0e10cSrcweir *this
3085cdf0e10cSrcweir ) )
3086cdf0e10cSrcweir );
3087cdf0e10cSrcweir }
3088cdf0e10cSrcweir
3089cdf0e10cSrcweir // Methods XNameReplace
replaceByName(const OUString & aName,const Any & aElement)3090cdf0e10cSrcweir void SfxLibrary::replaceByName( const OUString& aName, const Any& aElement )
3091cdf0e10cSrcweir throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
3092cdf0e10cSrcweir {
3093cdf0e10cSrcweir impl_checkReadOnly();
3094cdf0e10cSrcweir impl_checkLoaded();
3095cdf0e10cSrcweir
3096cdf0e10cSrcweir OSL_ENSURE( isLibraryElementValid( aElement ), "SfxLibrary::replaceByName: replacing element is invalid!" );
3097cdf0e10cSrcweir
3098cdf0e10cSrcweir maNameContainer.replaceByName( aName, aElement );
3099cdf0e10cSrcweir implSetModified( sal_True );
3100cdf0e10cSrcweir }
3101cdf0e10cSrcweir
3102cdf0e10cSrcweir
3103cdf0e10cSrcweir // Methods XNameContainer
insertByName(const OUString & aName,const Any & aElement)3104cdf0e10cSrcweir void SfxLibrary::insertByName( const OUString& aName, const Any& aElement )
3105cdf0e10cSrcweir throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
3106cdf0e10cSrcweir {
3107cdf0e10cSrcweir impl_checkReadOnly();
3108cdf0e10cSrcweir impl_checkLoaded();
3109cdf0e10cSrcweir
3110cdf0e10cSrcweir OSL_ENSURE( isLibraryElementValid( aElement ), "SfxLibrary::insertByName: to-be-inserted element is invalid!" );
3111cdf0e10cSrcweir
3112cdf0e10cSrcweir maNameContainer.insertByName( aName, aElement );
3113cdf0e10cSrcweir implSetModified( sal_True );
3114cdf0e10cSrcweir }
3115cdf0e10cSrcweir
impl_removeWithoutChecks(const::rtl::OUString & _rElementName)3116cdf0e10cSrcweir void SfxLibrary::impl_removeWithoutChecks( const ::rtl::OUString& _rElementName )
3117cdf0e10cSrcweir {
3118cdf0e10cSrcweir maNameContainer.removeByName( _rElementName );
3119cdf0e10cSrcweir implSetModified( sal_True );
3120cdf0e10cSrcweir
3121cdf0e10cSrcweir // Remove element file
3122*0848378bSHerbert Dürr if( !maStorageURL.isEmpty() )
3123cdf0e10cSrcweir {
3124cdf0e10cSrcweir INetURLObject aElementInetObj( maStorageURL );
3125cdf0e10cSrcweir aElementInetObj.insertName( _rElementName, sal_False,
3126cdf0e10cSrcweir INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL );
3127cdf0e10cSrcweir aElementInetObj.setExtension( maLibElementFileExtension );
3128cdf0e10cSrcweir OUString aFile = aElementInetObj.GetMainURL( INetURLObject::NO_DECODE );
3129cdf0e10cSrcweir
3130cdf0e10cSrcweir try
3131cdf0e10cSrcweir {
3132cdf0e10cSrcweir if( mxSFI->exists( aFile ) )
3133cdf0e10cSrcweir mxSFI->kill( aFile );
3134cdf0e10cSrcweir }
3135cdf0e10cSrcweir catch( Exception& )
3136cdf0e10cSrcweir {
3137cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
3138cdf0e10cSrcweir }
3139cdf0e10cSrcweir }
3140cdf0e10cSrcweir }
3141cdf0e10cSrcweir
removeByName(const OUString & Name)3142cdf0e10cSrcweir void SfxLibrary::removeByName( const OUString& Name )
3143cdf0e10cSrcweir throw(NoSuchElementException, WrappedTargetException, RuntimeException)
3144cdf0e10cSrcweir {
3145cdf0e10cSrcweir impl_checkReadOnly();
3146cdf0e10cSrcweir impl_checkLoaded();
3147cdf0e10cSrcweir impl_removeWithoutChecks( Name );
3148cdf0e10cSrcweir }
3149cdf0e10cSrcweir
3150cdf0e10cSrcweir // XTypeProvider
getTypes()3151cdf0e10cSrcweir Sequence< Type > SfxLibrary::getTypes()
3152cdf0e10cSrcweir throw( RuntimeException )
3153cdf0e10cSrcweir {
3154cdf0e10cSrcweir static OTypeCollection * s_pTypes_NameContainer = 0;
3155cdf0e10cSrcweir {
3156cdf0e10cSrcweir if( !s_pTypes_NameContainer )
3157cdf0e10cSrcweir {
3158cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() );
3159cdf0e10cSrcweir if( !s_pTypes_NameContainer )
3160cdf0e10cSrcweir {
3161cdf0e10cSrcweir static OTypeCollection s_aTypes_NameContainer(
3162cdf0e10cSrcweir ::getCppuType( (const Reference< XNameContainer > *)0 ),
3163cdf0e10cSrcweir ::getCppuType( (const Reference< XContainer > *)0 ),
3164cdf0e10cSrcweir ::getCppuType( (const Reference< XChangesNotifier > *)0 ),
3165cdf0e10cSrcweir OComponentHelper::getTypes() );
3166cdf0e10cSrcweir s_pTypes_NameContainer = &s_aTypes_NameContainer;
3167cdf0e10cSrcweir }
3168cdf0e10cSrcweir }
3169cdf0e10cSrcweir return s_pTypes_NameContainer->getTypes();
3170cdf0e10cSrcweir }
3171cdf0e10cSrcweir }
3172cdf0e10cSrcweir
3173cdf0e10cSrcweir
getImplementationId()3174cdf0e10cSrcweir Sequence< sal_Int8 > SfxLibrary::getImplementationId()
3175cdf0e10cSrcweir throw( RuntimeException )
3176cdf0e10cSrcweir {
3177cdf0e10cSrcweir static OImplementationId * s_pId_NameContainer = 0;
3178cdf0e10cSrcweir {
3179cdf0e10cSrcweir if( !s_pId_NameContainer )
3180cdf0e10cSrcweir {
3181cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() );
3182cdf0e10cSrcweir if( !s_pId_NameContainer )
3183cdf0e10cSrcweir {
3184cdf0e10cSrcweir static OImplementationId s_aId_NameContainer;
3185cdf0e10cSrcweir s_pId_NameContainer = &s_aId_NameContainer;
3186cdf0e10cSrcweir }
3187cdf0e10cSrcweir }
3188cdf0e10cSrcweir return s_pId_NameContainer->getImplementationId();
3189cdf0e10cSrcweir }
3190cdf0e10cSrcweir }
3191cdf0e10cSrcweir
3192cdf0e10cSrcweir // Methods XContainer
addContainerListener(const Reference<XContainerListener> & xListener)3193cdf0e10cSrcweir void SAL_CALL SfxLibrary::addContainerListener( const Reference< XContainerListener >& xListener )
3194cdf0e10cSrcweir throw (RuntimeException)
3195cdf0e10cSrcweir {
3196cdf0e10cSrcweir maNameContainer.setEventSource( static_cast< XInterface* >( (OWeakObject*)this ) );
3197cdf0e10cSrcweir maNameContainer.addContainerListener( xListener );
3198cdf0e10cSrcweir }
3199cdf0e10cSrcweir
removeContainerListener(const Reference<XContainerListener> & xListener)3200cdf0e10cSrcweir void SAL_CALL SfxLibrary::removeContainerListener( const Reference< XContainerListener >& xListener )
3201cdf0e10cSrcweir throw (RuntimeException)
3202cdf0e10cSrcweir {
3203cdf0e10cSrcweir maNameContainer.removeContainerListener( xListener );
3204cdf0e10cSrcweir }
3205cdf0e10cSrcweir
3206cdf0e10cSrcweir // Methods XChangesNotifier
addChangesListener(const Reference<XChangesListener> & xListener)3207cdf0e10cSrcweir void SAL_CALL SfxLibrary::addChangesListener( const Reference< XChangesListener >& xListener )
3208cdf0e10cSrcweir throw (RuntimeException)
3209cdf0e10cSrcweir {
3210cdf0e10cSrcweir maNameContainer.setEventSource( static_cast< XInterface* >( (OWeakObject*)this ) );
3211cdf0e10cSrcweir maNameContainer.addChangesListener( xListener );
3212cdf0e10cSrcweir }
3213cdf0e10cSrcweir
removeChangesListener(const Reference<XChangesListener> & xListener)3214cdf0e10cSrcweir void SAL_CALL SfxLibrary::removeChangesListener( const Reference< XChangesListener >& xListener )
3215cdf0e10cSrcweir throw (RuntimeException)
3216cdf0e10cSrcweir {
3217cdf0e10cSrcweir maNameContainer.removeChangesListener( xListener );
3218cdf0e10cSrcweir }
3219cdf0e10cSrcweir
3220cdf0e10cSrcweir //============================================================================
3221cdf0e10cSrcweir // Implementation class ScriptExtensionIterator
3222cdf0e10cSrcweir
3223cdf0e10cSrcweir static rtl::OUString aBasicLibMediaType( rtl::OUString::createFromAscii( "application/vnd.sun.star.basic-library" ) );
3224cdf0e10cSrcweir static rtl::OUString aDialogLibMediaType( rtl::OUString::createFromAscii( "application/vnd.sun.star.dialog-library" ) );
3225cdf0e10cSrcweir
ScriptExtensionIterator(void)3226cdf0e10cSrcweir ScriptExtensionIterator::ScriptExtensionIterator( void )
3227cdf0e10cSrcweir : m_eState( USER_EXTENSIONS )
3228cdf0e10cSrcweir , m_bUserPackagesLoaded( false )
3229cdf0e10cSrcweir , m_bSharedPackagesLoaded( false )
3230cdf0e10cSrcweir , m_bBundledPackagesLoaded( false )
3231cdf0e10cSrcweir , m_iUserPackage( 0 )
3232cdf0e10cSrcweir , m_iSharedPackage( 0 )
3233cdf0e10cSrcweir , m_iBundledPackage( 0 )
3234cdf0e10cSrcweir , m_pScriptSubPackageIterator( NULL )
3235cdf0e10cSrcweir {
3236cdf0e10cSrcweir Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
3237cdf0e10cSrcweir Reference< XPropertySet > xProps( xFactory, UNO_QUERY );
3238cdf0e10cSrcweir OSL_ASSERT( xProps.is() );
3239cdf0e10cSrcweir if (xProps.is())
3240cdf0e10cSrcweir {
3241cdf0e10cSrcweir xProps->getPropertyValue(
3242cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= m_xContext;
3243cdf0e10cSrcweir OSL_ASSERT( m_xContext.is() );
3244cdf0e10cSrcweir }
3245cdf0e10cSrcweir if( !m_xContext.is() )
3246cdf0e10cSrcweir {
3247cdf0e10cSrcweir throw RuntimeException(
3248cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "ScriptExtensionIterator::init(), no XComponentContext" ),
3249cdf0e10cSrcweir Reference< XInterface >() );
3250cdf0e10cSrcweir }
3251cdf0e10cSrcweir }
3252cdf0e10cSrcweir
nextBasicOrDialogLibrary(bool & rbPureDialogLib)3253cdf0e10cSrcweir rtl::OUString ScriptExtensionIterator::nextBasicOrDialogLibrary( bool& rbPureDialogLib )
3254cdf0e10cSrcweir {
3255cdf0e10cSrcweir rtl::OUString aRetLib;
3256cdf0e10cSrcweir
3257*0848378bSHerbert Dürr while( aRetLib.isEmpty() && m_eState != END_REACHED )
3258cdf0e10cSrcweir {
3259cdf0e10cSrcweir switch( m_eState )
3260cdf0e10cSrcweir {
3261cdf0e10cSrcweir case USER_EXTENSIONS:
3262cdf0e10cSrcweir {
3263cdf0e10cSrcweir Reference< deployment::XPackage > xScriptPackage =
3264cdf0e10cSrcweir implGetNextUserScriptPackage( rbPureDialogLib );
3265cdf0e10cSrcweir if( !xScriptPackage.is() )
3266cdf0e10cSrcweir break;
3267cdf0e10cSrcweir
3268cdf0e10cSrcweir aRetLib = xScriptPackage->getURL();
3269cdf0e10cSrcweir break;
3270cdf0e10cSrcweir }
3271cdf0e10cSrcweir
3272cdf0e10cSrcweir case SHARED_EXTENSIONS:
3273cdf0e10cSrcweir {
3274cdf0e10cSrcweir Reference< deployment::XPackage > xScriptPackage =
3275cdf0e10cSrcweir implGetNextSharedScriptPackage( rbPureDialogLib );
3276cdf0e10cSrcweir if( !xScriptPackage.is() )
3277cdf0e10cSrcweir break;
3278cdf0e10cSrcweir
3279cdf0e10cSrcweir aRetLib = xScriptPackage->getURL();
3280cdf0e10cSrcweir break;
3281cdf0e10cSrcweir }
3282cdf0e10cSrcweir case BUNDLED_EXTENSIONS:
3283cdf0e10cSrcweir {
3284cdf0e10cSrcweir Reference< deployment::XPackage > xScriptPackage =
3285cdf0e10cSrcweir implGetNextBundledScriptPackage( rbPureDialogLib );
3286cdf0e10cSrcweir if( !xScriptPackage.is() )
3287cdf0e10cSrcweir break;
3288cdf0e10cSrcweir
3289cdf0e10cSrcweir aRetLib = xScriptPackage->getURL();
3290cdf0e10cSrcweir break;
3291cdf0e10cSrcweir }
3292cdf0e10cSrcweir case END_REACHED:
3293cdf0e10cSrcweir VOS_ENSURE( false, "ScriptExtensionIterator::nextBasicOrDialogLibrary(): Invalid case END_REACHED" );
3294cdf0e10cSrcweir break;
3295cdf0e10cSrcweir }
3296cdf0e10cSrcweir }
3297cdf0e10cSrcweir
3298cdf0e10cSrcweir return aRetLib;
3299cdf0e10cSrcweir }
3300cdf0e10cSrcweir
ScriptSubPackageIterator(Reference<deployment::XPackage> xMainPackage)3301cdf0e10cSrcweir ScriptSubPackageIterator::ScriptSubPackageIterator( Reference< deployment::XPackage > xMainPackage )
3302cdf0e10cSrcweir : m_xMainPackage( xMainPackage )
3303cdf0e10cSrcweir , m_bIsValid( false )
3304cdf0e10cSrcweir , m_bIsBundle( false )
3305cdf0e10cSrcweir , m_nSubPkgCount( 0 )
3306cdf0e10cSrcweir , m_iNextSubPkg( 0 )
3307cdf0e10cSrcweir {
3308cdf0e10cSrcweir Reference< deployment::XPackage > xScriptPackage;
3309cdf0e10cSrcweir if( !m_xMainPackage.is() )
3310cdf0e10cSrcweir return;
3311cdf0e10cSrcweir
3312cdf0e10cSrcweir // Check if parent package is registered
3313cdf0e10cSrcweir beans::Optional< beans::Ambiguous<sal_Bool> > option( m_xMainPackage->isRegistered
3314cdf0e10cSrcweir ( Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>() ) );
3315cdf0e10cSrcweir bool bRegistered = false;
3316cdf0e10cSrcweir if( option.IsPresent )
3317cdf0e10cSrcweir {
3318cdf0e10cSrcweir beans::Ambiguous<sal_Bool> const & reg = option.Value;
3319cdf0e10cSrcweir if( !reg.IsAmbiguous && reg.Value )
3320cdf0e10cSrcweir bRegistered = true;
3321cdf0e10cSrcweir }
3322cdf0e10cSrcweir if( bRegistered )
3323cdf0e10cSrcweir {
3324cdf0e10cSrcweir m_bIsValid = true;
3325cdf0e10cSrcweir if( m_xMainPackage->isBundle() )
3326cdf0e10cSrcweir {
3327cdf0e10cSrcweir m_bIsBundle = true;
3328cdf0e10cSrcweir m_aSubPkgSeq = m_xMainPackage->getBundle
3329cdf0e10cSrcweir ( Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>() );
3330cdf0e10cSrcweir m_nSubPkgCount = m_aSubPkgSeq.getLength();
3331cdf0e10cSrcweir }
3332cdf0e10cSrcweir }
3333cdf0e10cSrcweir }
3334cdf0e10cSrcweir
getNextScriptSubPackage(bool & rbPureDialogLib)3335cdf0e10cSrcweir Reference< deployment::XPackage > ScriptSubPackageIterator::getNextScriptSubPackage
3336cdf0e10cSrcweir ( bool& rbPureDialogLib )
3337cdf0e10cSrcweir {
3338cdf0e10cSrcweir rbPureDialogLib = false;
3339cdf0e10cSrcweir
3340cdf0e10cSrcweir Reference< deployment::XPackage > xScriptPackage;
3341cdf0e10cSrcweir if( !m_bIsValid )
3342cdf0e10cSrcweir return xScriptPackage;
3343cdf0e10cSrcweir
3344cdf0e10cSrcweir if( m_bIsBundle )
3345cdf0e10cSrcweir {
3346cdf0e10cSrcweir const Reference< deployment::XPackage >* pSeq = m_aSubPkgSeq.getConstArray();
3347cdf0e10cSrcweir sal_Int32 iPkg;
3348cdf0e10cSrcweir for( iPkg = m_iNextSubPkg ; iPkg < m_nSubPkgCount ; ++iPkg )
3349cdf0e10cSrcweir {
3350cdf0e10cSrcweir const Reference< deployment::XPackage > xSubPkg = pSeq[ iPkg ];
3351cdf0e10cSrcweir xScriptPackage = implDetectScriptPackage( xSubPkg, rbPureDialogLib );
3352cdf0e10cSrcweir if( xScriptPackage.is() )
3353cdf0e10cSrcweir break;
3354cdf0e10cSrcweir }
3355cdf0e10cSrcweir m_iNextSubPkg = iPkg + 1;
3356cdf0e10cSrcweir }
3357cdf0e10cSrcweir else
3358cdf0e10cSrcweir {
3359cdf0e10cSrcweir xScriptPackage = implDetectScriptPackage( m_xMainPackage, rbPureDialogLib );
3360cdf0e10cSrcweir m_bIsValid = false; // No more script packages
3361cdf0e10cSrcweir }
3362cdf0e10cSrcweir
3363cdf0e10cSrcweir return xScriptPackage;
3364cdf0e10cSrcweir }
3365cdf0e10cSrcweir
implDetectScriptPackage(const Reference<deployment::XPackage> xPackage,bool & rbPureDialogLib)3366cdf0e10cSrcweir Reference< deployment::XPackage > ScriptSubPackageIterator::implDetectScriptPackage
3367cdf0e10cSrcweir ( const Reference< deployment::XPackage > xPackage, bool& rbPureDialogLib )
3368cdf0e10cSrcweir {
3369cdf0e10cSrcweir Reference< deployment::XPackage > xScriptPackage;
3370cdf0e10cSrcweir
3371cdf0e10cSrcweir if( xPackage.is() )
3372cdf0e10cSrcweir {
3373cdf0e10cSrcweir const Reference< deployment::XPackageTypeInfo > xPackageTypeInfo = xPackage->getPackageType();
3374cdf0e10cSrcweir rtl::OUString aMediaType = xPackageTypeInfo->getMediaType();
3375cdf0e10cSrcweir if( aMediaType.equals( aBasicLibMediaType ) )
3376cdf0e10cSrcweir {
3377cdf0e10cSrcweir xScriptPackage = xPackage;
3378cdf0e10cSrcweir }
3379cdf0e10cSrcweir else if( aMediaType.equals( aDialogLibMediaType ) )
3380cdf0e10cSrcweir {
3381cdf0e10cSrcweir rbPureDialogLib = true;
3382cdf0e10cSrcweir xScriptPackage = xPackage;
3383cdf0e10cSrcweir }
3384cdf0e10cSrcweir }
3385cdf0e10cSrcweir
3386cdf0e10cSrcweir return xScriptPackage;
3387cdf0e10cSrcweir }
3388cdf0e10cSrcweir
implGetScriptPackageFromPackage(const Reference<deployment::XPackage> xPackage,bool & rbPureDialogLib)3389cdf0e10cSrcweir Reference< deployment::XPackage > ScriptExtensionIterator::implGetScriptPackageFromPackage
3390cdf0e10cSrcweir ( const Reference< deployment::XPackage > xPackage, bool& rbPureDialogLib )
3391cdf0e10cSrcweir {
3392cdf0e10cSrcweir rbPureDialogLib = false;
3393cdf0e10cSrcweir
3394cdf0e10cSrcweir Reference< deployment::XPackage > xScriptPackage;
3395cdf0e10cSrcweir if( !xPackage.is() )
3396cdf0e10cSrcweir return xScriptPackage;
3397cdf0e10cSrcweir
3398cdf0e10cSrcweir // Check if parent package is registered
3399cdf0e10cSrcweir beans::Optional< beans::Ambiguous<sal_Bool> > option( xPackage->isRegistered
3400cdf0e10cSrcweir ( Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>() ) );
3401cdf0e10cSrcweir bool bRegistered = false;
3402cdf0e10cSrcweir if( option.IsPresent )
3403cdf0e10cSrcweir {
3404cdf0e10cSrcweir beans::Ambiguous<sal_Bool> const & reg = option.Value;
3405cdf0e10cSrcweir if( !reg.IsAmbiguous && reg.Value )
3406cdf0e10cSrcweir bRegistered = true;
3407cdf0e10cSrcweir }
3408cdf0e10cSrcweir if( bRegistered )
3409cdf0e10cSrcweir {
3410cdf0e10cSrcweir if( xPackage->isBundle() )
3411cdf0e10cSrcweir {
3412cdf0e10cSrcweir Sequence< Reference< deployment::XPackage > > aPkgSeq = xPackage->getBundle
3413cdf0e10cSrcweir ( Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>() );
3414cdf0e10cSrcweir sal_Int32 nPkgCount = aPkgSeq.getLength();
3415cdf0e10cSrcweir const Reference< deployment::XPackage >* pSeq = aPkgSeq.getConstArray();
3416cdf0e10cSrcweir for( sal_Int32 iPkg = 0 ; iPkg < nPkgCount ; ++iPkg )
3417cdf0e10cSrcweir {
3418cdf0e10cSrcweir const Reference< deployment::XPackage > xSubPkg = pSeq[ iPkg ];
3419cdf0e10cSrcweir const Reference< deployment::XPackageTypeInfo > xPackageTypeInfo = xSubPkg->getPackageType();
3420cdf0e10cSrcweir rtl::OUString aMediaType = xPackageTypeInfo->getMediaType();
3421cdf0e10cSrcweir if( aMediaType.equals( aBasicLibMediaType ) )
3422cdf0e10cSrcweir {
3423cdf0e10cSrcweir xScriptPackage = xSubPkg;
3424cdf0e10cSrcweir break;
3425cdf0e10cSrcweir }
3426cdf0e10cSrcweir else if( aMediaType.equals( aDialogLibMediaType ) )
3427cdf0e10cSrcweir {
3428cdf0e10cSrcweir rbPureDialogLib = true;
3429cdf0e10cSrcweir xScriptPackage = xSubPkg;
3430cdf0e10cSrcweir break;
3431cdf0e10cSrcweir }
3432cdf0e10cSrcweir }
3433cdf0e10cSrcweir }
3434cdf0e10cSrcweir else
3435cdf0e10cSrcweir {
3436cdf0e10cSrcweir const Reference< deployment::XPackageTypeInfo > xPackageTypeInfo = xPackage->getPackageType();
3437cdf0e10cSrcweir rtl::OUString aMediaType = xPackageTypeInfo->getMediaType();
3438cdf0e10cSrcweir if( aMediaType.equals( aBasicLibMediaType ) )
3439cdf0e10cSrcweir {
3440cdf0e10cSrcweir xScriptPackage = xPackage;
3441cdf0e10cSrcweir }
3442cdf0e10cSrcweir else if( aMediaType.equals( aDialogLibMediaType ) )
3443cdf0e10cSrcweir {
3444cdf0e10cSrcweir rbPureDialogLib = true;
3445cdf0e10cSrcweir xScriptPackage = xPackage;
3446cdf0e10cSrcweir }
3447cdf0e10cSrcweir }
3448cdf0e10cSrcweir }
3449cdf0e10cSrcweir
3450cdf0e10cSrcweir return xScriptPackage;
3451cdf0e10cSrcweir }
3452cdf0e10cSrcweir
implGetNextUserScriptPackage(bool & rbPureDialogLib)3453cdf0e10cSrcweir Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextUserScriptPackage
3454cdf0e10cSrcweir ( bool& rbPureDialogLib )
3455cdf0e10cSrcweir {
3456cdf0e10cSrcweir Reference< deployment::XPackage > xScriptPackage;
3457cdf0e10cSrcweir
3458cdf0e10cSrcweir if( !m_bUserPackagesLoaded )
3459cdf0e10cSrcweir {
3460cdf0e10cSrcweir try
3461cdf0e10cSrcweir {
3462cdf0e10cSrcweir Reference< XExtensionManager > xManager =
3463cdf0e10cSrcweir ExtensionManager::get( m_xContext );
3464cdf0e10cSrcweir m_aUserPackagesSeq = xManager->getDeployedExtensions
3465cdf0e10cSrcweir (rtl::OUString::createFromAscii("user"),
3466cdf0e10cSrcweir Reference< task::XAbortChannel >(), Reference< ucb::XCommandEnvironment >() );
3467cdf0e10cSrcweir }
3468cdf0e10cSrcweir catch( com::sun::star::uno::DeploymentException& )
3469cdf0e10cSrcweir {
3470cdf0e10cSrcweir // Special Office installations may not contain deployment code
3471cdf0e10cSrcweir m_eState = END_REACHED;
3472cdf0e10cSrcweir return xScriptPackage;
3473cdf0e10cSrcweir }
3474cdf0e10cSrcweir
3475cdf0e10cSrcweir m_bUserPackagesLoaded = true;
3476cdf0e10cSrcweir }
3477cdf0e10cSrcweir
3478cdf0e10cSrcweir if( m_iUserPackage == m_aUserPackagesSeq.getLength() )
3479cdf0e10cSrcweir {
3480cdf0e10cSrcweir m_eState = SHARED_EXTENSIONS; // Later: SHARED_MODULE
3481cdf0e10cSrcweir }
3482cdf0e10cSrcweir else
3483cdf0e10cSrcweir {
3484cdf0e10cSrcweir if( m_pScriptSubPackageIterator == NULL )
3485cdf0e10cSrcweir {
3486cdf0e10cSrcweir const Reference< deployment::XPackage >* pUserPackages = m_aUserPackagesSeq.getConstArray();
3487cdf0e10cSrcweir Reference< deployment::XPackage > xPackage = pUserPackages[ m_iUserPackage ];
3488cdf0e10cSrcweir VOS_ENSURE( xPackage.is(), "ScriptExtensionIterator::implGetNextUserScriptPackage(): Invalid package" );
3489cdf0e10cSrcweir m_pScriptSubPackageIterator = new ScriptSubPackageIterator( xPackage );
3490cdf0e10cSrcweir }
3491cdf0e10cSrcweir
3492cdf0e10cSrcweir if( m_pScriptSubPackageIterator != NULL )
3493cdf0e10cSrcweir {
3494cdf0e10cSrcweir xScriptPackage = m_pScriptSubPackageIterator->getNextScriptSubPackage( rbPureDialogLib );
3495cdf0e10cSrcweir if( !xScriptPackage.is() )
3496cdf0e10cSrcweir {
3497cdf0e10cSrcweir delete m_pScriptSubPackageIterator;
3498cdf0e10cSrcweir m_pScriptSubPackageIterator = NULL;
3499cdf0e10cSrcweir m_iUserPackage++;
3500cdf0e10cSrcweir }
3501cdf0e10cSrcweir }
3502cdf0e10cSrcweir }
3503cdf0e10cSrcweir
3504cdf0e10cSrcweir return xScriptPackage;
3505cdf0e10cSrcweir }
3506cdf0e10cSrcweir
implGetNextSharedScriptPackage(bool & rbPureDialogLib)3507cdf0e10cSrcweir Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextSharedScriptPackage
3508cdf0e10cSrcweir ( bool& rbPureDialogLib )
3509cdf0e10cSrcweir {
3510cdf0e10cSrcweir Reference< deployment::XPackage > xScriptPackage;
3511cdf0e10cSrcweir
3512cdf0e10cSrcweir if( !m_bSharedPackagesLoaded )
3513cdf0e10cSrcweir {
3514cdf0e10cSrcweir try
3515cdf0e10cSrcweir {
3516cdf0e10cSrcweir Reference< XExtensionManager > xSharedManager =
3517cdf0e10cSrcweir ExtensionManager::get( m_xContext );
3518cdf0e10cSrcweir m_aSharedPackagesSeq = xSharedManager->getDeployedExtensions
3519cdf0e10cSrcweir (rtl::OUString::createFromAscii("shared"),
3520cdf0e10cSrcweir Reference< task::XAbortChannel >(), Reference< ucb::XCommandEnvironment >() );
3521cdf0e10cSrcweir }
3522cdf0e10cSrcweir catch( com::sun::star::uno::DeploymentException& )
3523cdf0e10cSrcweir {
3524cdf0e10cSrcweir // Special Office installations may not contain deployment code
3525cdf0e10cSrcweir return xScriptPackage;
3526cdf0e10cSrcweir }
3527cdf0e10cSrcweir
3528cdf0e10cSrcweir m_bSharedPackagesLoaded = true;
3529cdf0e10cSrcweir }
3530cdf0e10cSrcweir
3531cdf0e10cSrcweir if( m_iSharedPackage == m_aSharedPackagesSeq.getLength() )
3532cdf0e10cSrcweir {
3533cdf0e10cSrcweir m_eState = BUNDLED_EXTENSIONS;
3534cdf0e10cSrcweir }
3535cdf0e10cSrcweir else
3536cdf0e10cSrcweir {
3537cdf0e10cSrcweir if( m_pScriptSubPackageIterator == NULL )
3538cdf0e10cSrcweir {
3539cdf0e10cSrcweir const Reference< deployment::XPackage >* pSharedPackages = m_aSharedPackagesSeq.getConstArray();
3540cdf0e10cSrcweir Reference< deployment::XPackage > xPackage = pSharedPackages[ m_iSharedPackage ];
3541cdf0e10cSrcweir VOS_ENSURE( xPackage.is(), "ScriptExtensionIterator::implGetNextSharedScriptPackage(): Invalid package" );
3542cdf0e10cSrcweir m_pScriptSubPackageIterator = new ScriptSubPackageIterator( xPackage );
3543cdf0e10cSrcweir }
3544cdf0e10cSrcweir
3545cdf0e10cSrcweir if( m_pScriptSubPackageIterator != NULL )
3546cdf0e10cSrcweir {
3547cdf0e10cSrcweir xScriptPackage = m_pScriptSubPackageIterator->getNextScriptSubPackage( rbPureDialogLib );
3548cdf0e10cSrcweir if( !xScriptPackage.is() )
3549cdf0e10cSrcweir {
3550cdf0e10cSrcweir delete m_pScriptSubPackageIterator;
3551cdf0e10cSrcweir m_pScriptSubPackageIterator = NULL;
3552cdf0e10cSrcweir m_iSharedPackage++;
3553cdf0e10cSrcweir }
3554cdf0e10cSrcweir }
3555cdf0e10cSrcweir }
3556cdf0e10cSrcweir
3557cdf0e10cSrcweir return xScriptPackage;
3558cdf0e10cSrcweir }
3559cdf0e10cSrcweir
implGetNextBundledScriptPackage(bool & rbPureDialogLib)3560cdf0e10cSrcweir Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextBundledScriptPackage
3561cdf0e10cSrcweir ( bool& rbPureDialogLib )
3562cdf0e10cSrcweir {
3563cdf0e10cSrcweir Reference< deployment::XPackage > xScriptPackage;
3564cdf0e10cSrcweir
3565cdf0e10cSrcweir if( !m_bBundledPackagesLoaded )
3566cdf0e10cSrcweir {
3567cdf0e10cSrcweir try
3568cdf0e10cSrcweir {
3569cdf0e10cSrcweir Reference< XExtensionManager > xManager =
3570cdf0e10cSrcweir ExtensionManager::get( m_xContext );
3571cdf0e10cSrcweir m_aBundledPackagesSeq = xManager->getDeployedExtensions
3572cdf0e10cSrcweir (rtl::OUString::createFromAscii("bundled"),
3573cdf0e10cSrcweir Reference< task::XAbortChannel >(), Reference< ucb::XCommandEnvironment >() );
3574cdf0e10cSrcweir }
3575cdf0e10cSrcweir catch( com::sun::star::uno::DeploymentException& )
3576cdf0e10cSrcweir {
3577cdf0e10cSrcweir // Special Office installations may not contain deployment code
3578cdf0e10cSrcweir return xScriptPackage;
3579cdf0e10cSrcweir }
3580cdf0e10cSrcweir
3581cdf0e10cSrcweir m_bBundledPackagesLoaded = true;
3582cdf0e10cSrcweir }
3583cdf0e10cSrcweir
3584cdf0e10cSrcweir if( m_iBundledPackage == m_aBundledPackagesSeq.getLength() )
3585cdf0e10cSrcweir {
3586cdf0e10cSrcweir m_eState = END_REACHED;
3587cdf0e10cSrcweir }
3588cdf0e10cSrcweir else
3589cdf0e10cSrcweir {
3590cdf0e10cSrcweir if( m_pScriptSubPackageIterator == NULL )
3591cdf0e10cSrcweir {
3592cdf0e10cSrcweir const Reference< deployment::XPackage >* pBundledPackages = m_aBundledPackagesSeq.getConstArray();
3593cdf0e10cSrcweir Reference< deployment::XPackage > xPackage = pBundledPackages[ m_iBundledPackage ];
3594cdf0e10cSrcweir VOS_ENSURE( xPackage.is(), "ScriptExtensionIterator::implGetNextBundledScriptPackage(): Invalid package" );
3595cdf0e10cSrcweir m_pScriptSubPackageIterator = new ScriptSubPackageIterator( xPackage );
3596cdf0e10cSrcweir }
3597cdf0e10cSrcweir
3598cdf0e10cSrcweir if( m_pScriptSubPackageIterator != NULL )
3599cdf0e10cSrcweir {
3600cdf0e10cSrcweir xScriptPackage = m_pScriptSubPackageIterator->getNextScriptSubPackage( rbPureDialogLib );
3601cdf0e10cSrcweir if( !xScriptPackage.is() )
3602cdf0e10cSrcweir {
3603cdf0e10cSrcweir delete m_pScriptSubPackageIterator;
3604cdf0e10cSrcweir m_pScriptSubPackageIterator = NULL;
3605cdf0e10cSrcweir m_iBundledPackage++;
3606cdf0e10cSrcweir }
3607cdf0e10cSrcweir }
3608cdf0e10cSrcweir }
3609cdf0e10cSrcweir
3610cdf0e10cSrcweir return xScriptPackage;
3611cdf0e10cSrcweir }
3612cdf0e10cSrcweir
3613cdf0e10cSrcweir } // namespace basic
3614