1*e1f63238SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*e1f63238SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*e1f63238SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*e1f63238SAndrew Rist * distributed with this work for additional information
6*e1f63238SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*e1f63238SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*e1f63238SAndrew Rist * "License"); you may not use this file except in compliance
9*e1f63238SAndrew Rist * with the License. You may obtain a copy of the License at
10*e1f63238SAndrew Rist *
11*e1f63238SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*e1f63238SAndrew Rist *
13*e1f63238SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*e1f63238SAndrew Rist * software distributed under the License is distributed on an
15*e1f63238SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e1f63238SAndrew Rist * KIND, either express or implied. See the License for the
17*e1f63238SAndrew Rist * specific language governing permissions and limitations
18*e1f63238SAndrew Rist * under the License.
19*e1f63238SAndrew Rist *
20*e1f63238SAndrew Rist *************************************************************/
21*e1f63238SAndrew Rist
22*e1f63238SAndrew 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/xml/sax/XParser.hpp>
28cdf0e10cSrcweir #include <com/sun/star/xml/sax/InputSource.hpp>
29cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
30cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
31cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
32cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
33cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
34cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
35cdf0e10cSrcweir #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
36cdf0e10cSrcweir #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
37cdf0e10cSrcweir #include "com/sun/star/resource/XStringResourceWithStorage.hpp"
38cdf0e10cSrcweir #include "com/sun/star/resource/XStringResourceWithLocation.hpp"
39cdf0e10cSrcweir #include "dlgcont.hxx"
40cdf0e10cSrcweir #include "sbmodule.hxx"
41cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
42cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
43cdf0e10cSrcweir #include <osl/mutex.hxx>
44cdf0e10cSrcweir
45cdf0e10cSrcweir #include <vcl/svapp.hxx>
46cdf0e10cSrcweir #include <vcl/settings.hxx>
47cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
48cdf0e10cSrcweir #include <xmlscript/xmldlg_imexp.hxx>
49cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
50cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
51cdf0e10cSrcweir #include <svtools/ehdl.hxx>
52cdf0e10cSrcweir
53cdf0e10cSrcweir
54cdf0e10cSrcweir namespace basic
55cdf0e10cSrcweir {
56cdf0e10cSrcweir
57cdf0e10cSrcweir using namespace com::sun::star::document;
58cdf0e10cSrcweir using namespace com::sun::star::container;
59cdf0e10cSrcweir using namespace com::sun::star::io;
60cdf0e10cSrcweir using namespace com::sun::star::uno;
61cdf0e10cSrcweir using namespace com::sun::star::ucb;
62cdf0e10cSrcweir using namespace com::sun::star::lang;
63cdf0e10cSrcweir using namespace com::sun::star::script;
64cdf0e10cSrcweir using namespace com::sun::star::xml::sax;
65cdf0e10cSrcweir using namespace com::sun::star;
66cdf0e10cSrcweir using namespace cppu;
67cdf0e10cSrcweir using namespace rtl;
68cdf0e10cSrcweir using namespace osl;
69cdf0e10cSrcweir
70cdf0e10cSrcweir using com::sun::star::uno::Reference;
71cdf0e10cSrcweir
72cdf0e10cSrcweir //============================================================================
73cdf0e10cSrcweir // Implementation class SfxDialogLibraryContainer
74cdf0e10cSrcweir
getInfoFileName() const75cdf0e10cSrcweir const sal_Char* SAL_CALL SfxDialogLibraryContainer::getInfoFileName() const { return "dialog"; }
getOldInfoFileName() const76cdf0e10cSrcweir const sal_Char* SAL_CALL SfxDialogLibraryContainer::getOldInfoFileName() const { return "dialogs"; }
getLibElementFileExtension() const77cdf0e10cSrcweir const sal_Char* SAL_CALL SfxDialogLibraryContainer::getLibElementFileExtension() const { return "xdl"; }
getLibrariesDir() const78cdf0e10cSrcweir const sal_Char* SAL_CALL SfxDialogLibraryContainer::getLibrariesDir() const { return "Dialogs"; }
79cdf0e10cSrcweir
80cdf0e10cSrcweir // Ctor for service
SfxDialogLibraryContainer(void)81cdf0e10cSrcweir SfxDialogLibraryContainer::SfxDialogLibraryContainer( void )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir // all initialisation has to be done
84cdf0e10cSrcweir // by calling XInitialization::initialize
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
SfxDialogLibraryContainer(const uno::Reference<embed::XStorage> & xStorage)87cdf0e10cSrcweir SfxDialogLibraryContainer::SfxDialogLibraryContainer( const uno::Reference< embed::XStorage >& xStorage )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir init( OUString(), xStorage );
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir // Methods to get library instances of the correct type
implCreateLibrary(const::rtl::OUString & aName)93cdf0e10cSrcweir SfxLibrary* SfxDialogLibraryContainer::implCreateLibrary( const ::rtl::OUString& aName )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir SfxLibrary* pRet = new SfxDialogLibrary( maModifiable, aName, mxMSF, mxSFI, this );
96cdf0e10cSrcweir return pRet;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
implCreateLibraryLink(const::rtl::OUString & aName,const OUString & aLibInfoFileURL,const OUString & StorageURL,sal_Bool ReadOnly)99cdf0e10cSrcweir SfxLibrary* SfxDialogLibraryContainer::implCreateLibraryLink
100cdf0e10cSrcweir ( const ::rtl::OUString& aName, const OUString& aLibInfoFileURL,
101cdf0e10cSrcweir const OUString& StorageURL, sal_Bool ReadOnly )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir SfxLibrary* pRet = new SfxDialogLibrary
104cdf0e10cSrcweir ( maModifiable, aName, mxMSF, mxSFI, aLibInfoFileURL, StorageURL, ReadOnly, this );
105cdf0e10cSrcweir return pRet;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
createEmptyLibraryElement(void)108cdf0e10cSrcweir Any SAL_CALL SfxDialogLibraryContainer::createEmptyLibraryElement( void )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir Reference< XInputStreamProvider > xISP;
111cdf0e10cSrcweir Any aRetAny;
112cdf0e10cSrcweir aRetAny <<= xISP;
113cdf0e10cSrcweir return aRetAny;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
isLibraryElementValid(Any aElement) const116cdf0e10cSrcweir bool SAL_CALL SfxDialogLibraryContainer::isLibraryElementValid( Any aElement ) const
117cdf0e10cSrcweir {
118cdf0e10cSrcweir return SfxDialogLibrary::containsValidDialog( aElement );
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
writeOasis2OOoLibraryElement(Reference<XInputStream> xInput,Reference<XOutputStream> xOutput)121cdf0e10cSrcweir bool writeOasis2OOoLibraryElement(
122cdf0e10cSrcweir Reference< XInputStream > xInput, Reference< XOutputStream > xOutput )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir Reference< XMultiServiceFactory > xMSF(
125cdf0e10cSrcweir comphelper::getProcessServiceFactory() );
126cdf0e10cSrcweir
127cdf0e10cSrcweir Reference< XComponentContext > xContext;
128cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY );
129cdf0e10cSrcweir OSL_ASSERT( xProps.is() );
130cdf0e10cSrcweir OSL_VERIFY( xProps->getPropertyValue(
131cdf0e10cSrcweir OUString::createFromAscii(("DefaultContext")) ) >>= xContext );
132cdf0e10cSrcweir
133cdf0e10cSrcweir Reference< lang::XMultiComponentFactory > xSMgr(
134cdf0e10cSrcweir xContext->getServiceManager() );
135cdf0e10cSrcweir
136cdf0e10cSrcweir if (! xSMgr.is())
137cdf0e10cSrcweir {
138cdf0e10cSrcweir return sal_False;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir Reference< xml::sax::XParser > xParser(
142cdf0e10cSrcweir xSMgr->createInstanceWithContext(
143cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(
144cdf0e10cSrcweir "com.sun.star.xml.sax.Parser" ) ),
145cdf0e10cSrcweir xContext ),
146cdf0e10cSrcweir UNO_QUERY );
147cdf0e10cSrcweir
148cdf0e10cSrcweir Reference< xml::sax::XExtendedDocumentHandler > xWriter(
149cdf0e10cSrcweir xSMgr->createInstanceWithContext(
150cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(
151cdf0e10cSrcweir "com.sun.star.xml.sax.Writer" ) ),
152cdf0e10cSrcweir xContext ),
153cdf0e10cSrcweir UNO_QUERY );
154cdf0e10cSrcweir
155cdf0e10cSrcweir Reference< io::XActiveDataSource > xSource( xWriter, UNO_QUERY );
156cdf0e10cSrcweir xSource->setOutputStream( xOutput );
157cdf0e10cSrcweir
158cdf0e10cSrcweir if ( !xParser.is() || !xWriter.is() )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir return sal_False;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
163cdf0e10cSrcweir Sequence<Any> aArgs( 1 );
164cdf0e10cSrcweir aArgs[0] <<= xWriter;
165cdf0e10cSrcweir
166cdf0e10cSrcweir Reference< xml::sax::XDocumentHandler > xHandler(
167cdf0e10cSrcweir xSMgr->createInstanceWithArgumentsAndContext(
168cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(
169cdf0e10cSrcweir "com.sun.star.comp.Oasis2OOoTransformer" ) ),
170cdf0e10cSrcweir aArgs, xContext ),
171cdf0e10cSrcweir UNO_QUERY );
172cdf0e10cSrcweir
173cdf0e10cSrcweir xParser->setDocumentHandler( xHandler );
174cdf0e10cSrcweir
175cdf0e10cSrcweir xml::sax::InputSource source;
176cdf0e10cSrcweir source.aInputStream = xInput;
177cdf0e10cSrcweir source.sSystemId = OUString::createFromAscii( "virtual file" );
178cdf0e10cSrcweir
179cdf0e10cSrcweir xParser->parseStream( source );
180cdf0e10cSrcweir
181cdf0e10cSrcweir return sal_True;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir
writeLibraryElement(const Reference<XNameContainer> & xLib,const OUString & aElementName,const Reference<XOutputStream> & xOutput)184cdf0e10cSrcweir void SAL_CALL SfxDialogLibraryContainer::writeLibraryElement
185cdf0e10cSrcweir (
186cdf0e10cSrcweir const Reference < XNameContainer >& xLib,
187cdf0e10cSrcweir const OUString& aElementName,
188cdf0e10cSrcweir const Reference< XOutputStream >& xOutput
189cdf0e10cSrcweir )
190cdf0e10cSrcweir throw(Exception)
191cdf0e10cSrcweir {
192cdf0e10cSrcweir Any aElement = xLib->getByName( aElementName );
193cdf0e10cSrcweir Reference< XInputStreamProvider > xISP;
194cdf0e10cSrcweir aElement >>= xISP;
195cdf0e10cSrcweir if( !xISP.is() )
196cdf0e10cSrcweir return;
197cdf0e10cSrcweir
198cdf0e10cSrcweir Reference< XInputStream > xInput( xISP->createInputStream() );
199cdf0e10cSrcweir
200cdf0e10cSrcweir bool bComplete = sal_False;
201cdf0e10cSrcweir if ( mbOasis2OOoFormat )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir bComplete = writeOasis2OOoLibraryElement( xInput, xOutput );
204cdf0e10cSrcweir }
205cdf0e10cSrcweir
206cdf0e10cSrcweir if ( bComplete == sal_False )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir Sequence< sal_Int8 > bytes;
209cdf0e10cSrcweir sal_Int32 nRead = xInput->readBytes( bytes, xInput->available() );
210cdf0e10cSrcweir for (;;)
211cdf0e10cSrcweir {
212cdf0e10cSrcweir if( nRead )
213cdf0e10cSrcweir xOutput->writeBytes( bytes );
214cdf0e10cSrcweir
215cdf0e10cSrcweir nRead = xInput->readBytes( bytes, 1024 );
216cdf0e10cSrcweir if (! nRead)
217cdf0e10cSrcweir break;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir }
220cdf0e10cSrcweir xInput->closeInput();
221cdf0e10cSrcweir }
222cdf0e10cSrcweir
storeLibrariesToStorage(const uno::Reference<embed::XStorage> & xStorage)223cdf0e10cSrcweir void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< embed::XStorage >& xStorage ) throw ( RuntimeException )
224cdf0e10cSrcweir {
225cdf0e10cSrcweir LibraryContainerMethodGuard aGuard( *this );
226cdf0e10cSrcweir mbOasis2OOoFormat = sal_False;
227cdf0e10cSrcweir
228cdf0e10cSrcweir if ( mxStorage.is() && xStorage.is() )
229cdf0e10cSrcweir {
230cdf0e10cSrcweir try
231cdf0e10cSrcweir {
232cdf0e10cSrcweir long nSource = SotStorage::GetVersion( mxStorage );
233cdf0e10cSrcweir long nTarget = SotStorage::GetVersion( xStorage );
234cdf0e10cSrcweir
235cdf0e10cSrcweir if ( nSource == SOFFICE_FILEFORMAT_CURRENT &&
236cdf0e10cSrcweir nTarget != SOFFICE_FILEFORMAT_CURRENT )
237cdf0e10cSrcweir {
238cdf0e10cSrcweir mbOasis2OOoFormat = sal_True;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir }
241cdf0e10cSrcweir catch ( Exception& )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir // if we cannot get the version then the
244cdf0e10cSrcweir // Oasis2OOoTransformer will not be used
245cdf0e10cSrcweir OSL_ASSERT(sal_False);
246cdf0e10cSrcweir }
247cdf0e10cSrcweir }
248cdf0e10cSrcweir
249cdf0e10cSrcweir SfxLibraryContainer::storeLibrariesToStorage( xStorage );
250cdf0e10cSrcweir
251cdf0e10cSrcweir mbOasis2OOoFormat = sal_False;
252cdf0e10cSrcweir }
253cdf0e10cSrcweir
254cdf0e10cSrcweir
importLibraryElement(const Reference<XNameContainer> &,const OUString &,const OUString & aFile,const uno::Reference<io::XInputStream> & xElementStream)255cdf0e10cSrcweir Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement
256cdf0e10cSrcweir ( const Reference < XNameContainer >& /*xLib*/,
257cdf0e10cSrcweir const OUString& /*aElementName */, const OUString& aFile,
258cdf0e10cSrcweir const uno::Reference< io::XInputStream >& xElementStream )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir Any aRetAny;
261cdf0e10cSrcweir
262cdf0e10cSrcweir // TODO: Member because later it will be a component
263cdf0e10cSrcweir //Reference< XMultiServiceFactory > xMSF( comphelper::getProcessServiceFactory() );
264cdf0e10cSrcweir //if( !xMSF.is() )
265cdf0e10cSrcweir //{
266cdf0e10cSrcweir // OSL_ENSURE( 0, "### couln't get ProcessServiceFactory\n" );
267cdf0e10cSrcweir // return aRetAny;
268cdf0e10cSrcweir //}
269cdf0e10cSrcweir
270cdf0e10cSrcweir Reference< XParser > xParser( mxMSF->createInstance(
271cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ) ), UNO_QUERY );
272cdf0e10cSrcweir if( !xParser.is() )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir OSL_ENSURE( 0, "### couln't create sax parser component\n" );
275cdf0e10cSrcweir return aRetAny;
276cdf0e10cSrcweir }
277cdf0e10cSrcweir
278cdf0e10cSrcweir Reference< XNameContainer > xDialogModel( mxMSF->createInstance
279cdf0e10cSrcweir ( OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY );
280cdf0e10cSrcweir if( !xDialogModel.is() )
281cdf0e10cSrcweir {
282cdf0e10cSrcweir OSL_ENSURE( 0, "### couln't create com.sun.star.awt.UnoControlDialogModel component\n" );
283cdf0e10cSrcweir return aRetAny;
284cdf0e10cSrcweir }
285cdf0e10cSrcweir
286cdf0e10cSrcweir // Read from storage?
287cdf0e10cSrcweir sal_Bool bStorage = xElementStream.is();
288cdf0e10cSrcweir Reference< XInputStream > xInput;
289cdf0e10cSrcweir
290cdf0e10cSrcweir if( bStorage )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir xInput = xElementStream;
293cdf0e10cSrcweir }
294cdf0e10cSrcweir else
295cdf0e10cSrcweir {
296cdf0e10cSrcweir try
297cdf0e10cSrcweir {
298cdf0e10cSrcweir xInput = mxSFI->openFileRead( aFile );
299cdf0e10cSrcweir }
300cdf0e10cSrcweir catch( Exception& )
301cdf0e10cSrcweir //catch( Exception& e )
302cdf0e10cSrcweir {
303cdf0e10cSrcweir // TODO:
304cdf0e10cSrcweir //throw WrappedTargetException( e );
305cdf0e10cSrcweir }
306cdf0e10cSrcweir }
307cdf0e10cSrcweir if( !xInput.is() )
308cdf0e10cSrcweir return aRetAny;
309cdf0e10cSrcweir
310cdf0e10cSrcweir Reference< XComponentContext > xContext;
311cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( mxMSF, UNO_QUERY );
312cdf0e10cSrcweir OSL_ASSERT( xProps.is() );
313cdf0e10cSrcweir OSL_VERIFY( xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
314cdf0e10cSrcweir
315cdf0e10cSrcweir InputSource source;
316cdf0e10cSrcweir source.aInputStream = xInput;
317cdf0e10cSrcweir source.sSystemId = aFile;
318cdf0e10cSrcweir
319cdf0e10cSrcweir try {
320cdf0e10cSrcweir // start parsing
321cdf0e10cSrcweir xParser->setDocumentHandler( ::xmlscript::importDialogModel( xDialogModel, xContext ) );
322cdf0e10cSrcweir xParser->parseStream( source );
323cdf0e10cSrcweir }
324cdf0e10cSrcweir catch( Exception& )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir OSL_ENSURE( 0, "Parsing error\n" );
327cdf0e10cSrcweir SfxErrorContext aEc( ERRCTX_SFX_LOADBASIC, aFile );
328cdf0e10cSrcweir sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
329cdf0e10cSrcweir ErrorHandler::HandleError( nErrorCode );
330cdf0e10cSrcweir return aRetAny;
331cdf0e10cSrcweir }
332cdf0e10cSrcweir
333cdf0e10cSrcweir // Create InputStream, TODO: Implement own InputStreamProvider
334cdf0e10cSrcweir // to avoid creating the DialogModel here!
335cdf0e10cSrcweir Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext );
336cdf0e10cSrcweir aRetAny <<= xISP;
337cdf0e10cSrcweir return aRetAny;
338cdf0e10cSrcweir }
339cdf0e10cSrcweir
importFromOldStorage(const OUString &)340cdf0e10cSrcweir void SAL_CALL SfxDialogLibraryContainer::importFromOldStorage( const OUString& )
341cdf0e10cSrcweir {
342cdf0e10cSrcweir // Nothing to do here, old dialogs cannot be imported
343cdf0e10cSrcweir }
344cdf0e10cSrcweir
createInstanceImpl(void)345cdf0e10cSrcweir SfxLibraryContainer* SfxDialogLibraryContainer::createInstanceImpl( void )
346cdf0e10cSrcweir {
347cdf0e10cSrcweir return new SfxDialogLibraryContainer();
348cdf0e10cSrcweir }
349cdf0e10cSrcweir
350cdf0e10cSrcweir
351cdf0e10cSrcweir static OUString aResourceFileNameBase = OUString::createFromAscii( "DialogStrings" );
352cdf0e10cSrcweir static OUString aResourceFileCommentBase = OUString::createFromAscii( "# Strings for Dialog Library " );
353cdf0e10cSrcweir
354cdf0e10cSrcweir // Resource handling
355cdf0e10cSrcweir Reference< ::com::sun::star::resource::XStringResourcePersistence >
implCreateStringResource(SfxDialogLibrary * pDialogLibrary)356cdf0e10cSrcweir SfxDialogLibraryContainer::implCreateStringResource( SfxDialogLibrary* pDialogLibrary )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir Reference< resource::XStringResourcePersistence > xRet;
359cdf0e10cSrcweir OUString aLibName = pDialogLibrary->getName();
360cdf0e10cSrcweir bool bReadOnly = pDialogLibrary->mbReadOnly;
361cdf0e10cSrcweir
362cdf0e10cSrcweir // get ui locale
363cdf0e10cSrcweir ::com::sun ::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
364cdf0e10cSrcweir
365cdf0e10cSrcweir OUString aComment = aResourceFileCommentBase;
366cdf0e10cSrcweir aComment += aLibName;
367cdf0e10cSrcweir
368cdf0e10cSrcweir sal_Bool bStorage = mxStorage.is();
369cdf0e10cSrcweir if( bStorage )
370cdf0e10cSrcweir {
371cdf0e10cSrcweir Sequence<Any> aArgs( 5 );
372cdf0e10cSrcweir aArgs[1] <<= bReadOnly;
373cdf0e10cSrcweir aArgs[2] <<= aLocale;
374cdf0e10cSrcweir aArgs[3] <<= aResourceFileNameBase;
375cdf0e10cSrcweir aArgs[4] <<= aComment;
376cdf0e10cSrcweir
377cdf0e10cSrcweir // TODO: Ctor
378cdf0e10cSrcweir xRet = Reference< resource::XStringResourcePersistence >( mxMSF->createInstance
379cdf0e10cSrcweir ( OUString::createFromAscii( "com.sun.star.resource.StringResourceWithStorage" ) ), UNO_QUERY );
380cdf0e10cSrcweir
381cdf0e10cSrcweir uno::Reference< embed::XStorage > xLibrariesStor;
382cdf0e10cSrcweir uno::Reference< embed::XStorage > xLibraryStor;
383cdf0e10cSrcweir try {
384cdf0e10cSrcweir xLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READ );
385cdf0e10cSrcweir // TODO: Should be READWRITE with new storage concept using store() instead of storeTo()
386cdf0e10cSrcweir if ( !xLibrariesStor.is() )
387cdf0e10cSrcweir throw uno::RuntimeException();
388cdf0e10cSrcweir
389cdf0e10cSrcweir xLibraryStor = xLibrariesStor->openStorageElement( aLibName, embed::ElementModes::READ );
390cdf0e10cSrcweir // TODO: Should be READWRITE with new storage concept using store() instead of storeTo()
391cdf0e10cSrcweir if ( !xLibraryStor.is() )
392cdf0e10cSrcweir throw uno::RuntimeException();
393cdf0e10cSrcweir
394cdf0e10cSrcweir aArgs[0] <<= xLibraryStor;
395cdf0e10cSrcweir }
396cdf0e10cSrcweir catch( uno::Exception& )
397cdf0e10cSrcweir {
398cdf0e10cSrcweir // TODO: Error handling?
399cdf0e10cSrcweir return xRet;
400cdf0e10cSrcweir }
401cdf0e10cSrcweir
402cdf0e10cSrcweir // TODO: Ctor
403cdf0e10cSrcweir if( xRet.is() )
404cdf0e10cSrcweir {
405cdf0e10cSrcweir Reference< XInitialization > xInit( xRet, UNO_QUERY );
406cdf0e10cSrcweir if( xInit.is() )
407cdf0e10cSrcweir xInit->initialize( aArgs );
408cdf0e10cSrcweir }
409cdf0e10cSrcweir }
410cdf0e10cSrcweir else
411cdf0e10cSrcweir {
412cdf0e10cSrcweir Sequence<Any> aArgs( 6 );
413cdf0e10cSrcweir
414cdf0e10cSrcweir OUString aLocation = createAppLibraryFolder( pDialogLibrary, aLibName );
415cdf0e10cSrcweir aArgs[0] <<= aLocation;
416cdf0e10cSrcweir aArgs[1] <<= bReadOnly;
417cdf0e10cSrcweir aArgs[2] <<= aLocale;
418cdf0e10cSrcweir aArgs[3] <<= aResourceFileNameBase;
419cdf0e10cSrcweir aArgs[4] <<= aComment;
420cdf0e10cSrcweir
421cdf0e10cSrcweir // TODO: Real handler?
422cdf0e10cSrcweir Reference< task::XInteractionHandler > xDummyHandler;
423cdf0e10cSrcweir aArgs[5] <<= xDummyHandler;
424cdf0e10cSrcweir
425cdf0e10cSrcweir // TODO: Ctor
426cdf0e10cSrcweir xRet = Reference< resource::XStringResourcePersistence >( mxMSF->createInstance
427cdf0e10cSrcweir ( OUString::createFromAscii( "com.sun.star.resource.StringResourceWithLocation" ) ), UNO_QUERY );
428cdf0e10cSrcweir
429cdf0e10cSrcweir // TODO: Ctor
430cdf0e10cSrcweir if( xRet.is() )
431cdf0e10cSrcweir {
432cdf0e10cSrcweir Reference< XInitialization > xInit( xRet, UNO_QUERY );
433cdf0e10cSrcweir if( xInit.is() )
434cdf0e10cSrcweir xInit->initialize( aArgs );
435cdf0e10cSrcweir }
436cdf0e10cSrcweir }
437cdf0e10cSrcweir
438cdf0e10cSrcweir return xRet;
439cdf0e10cSrcweir }
440cdf0e10cSrcweir
onNewRootStorage()441cdf0e10cSrcweir void SfxDialogLibraryContainer::onNewRootStorage()
442cdf0e10cSrcweir {
443cdf0e10cSrcweir // the library container is not modified, go through the libraries and check whether they are modified
444cdf0e10cSrcweir Sequence< OUString > aNames = maNameContainer.getElementNames();
445cdf0e10cSrcweir const OUString* pNames = aNames.getConstArray();
446cdf0e10cSrcweir sal_Int32 nNameCount = aNames.getLength();
447cdf0e10cSrcweir
448cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
449cdf0e10cSrcweir {
450cdf0e10cSrcweir OUString aName = pNames[ i ];
451cdf0e10cSrcweir SfxDialogLibrary* pDialogLibrary = static_cast<SfxDialogLibrary*>( getImplLib( aName ) );
452cdf0e10cSrcweir
453cdf0e10cSrcweir Reference< resource::XStringResourcePersistence > xStringResourcePersistence =
454cdf0e10cSrcweir pDialogLibrary->getStringResourcePersistence();
455cdf0e10cSrcweir
456cdf0e10cSrcweir if( xStringResourcePersistence.is() )
457cdf0e10cSrcweir {
458cdf0e10cSrcweir Reference< embed::XStorage > xLibrariesStor;
459cdf0e10cSrcweir Reference< embed::XStorage > xLibraryStor;
460cdf0e10cSrcweir try {
461cdf0e10cSrcweir xLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READWRITE );
462cdf0e10cSrcweir if ( !xLibrariesStor.is() )
463cdf0e10cSrcweir throw uno::RuntimeException();
464cdf0e10cSrcweir
465cdf0e10cSrcweir OUString aLibName = pDialogLibrary->getName();
466cdf0e10cSrcweir xLibraryStor = xLibrariesStor->openStorageElement( aLibName, embed::ElementModes::READWRITE );
467cdf0e10cSrcweir if ( !xLibraryStor.is() )
468cdf0e10cSrcweir throw uno::RuntimeException();
469cdf0e10cSrcweir
470cdf0e10cSrcweir Reference< resource::XStringResourceWithStorage >
471cdf0e10cSrcweir xStringResourceWithStorage( xStringResourcePersistence, UNO_QUERY );
472cdf0e10cSrcweir if( xStringResourceWithStorage.is() )
473cdf0e10cSrcweir xStringResourceWithStorage->setStorage( xLibraryStor );
474cdf0e10cSrcweir }
475cdf0e10cSrcweir catch( uno::Exception& )
476cdf0e10cSrcweir {
477cdf0e10cSrcweir // TODO: Error handling?
478cdf0e10cSrcweir }
479cdf0e10cSrcweir }
480cdf0e10cSrcweir }
481cdf0e10cSrcweir }
482cdf0e10cSrcweir
483cdf0e10cSrcweir
484cdf0e10cSrcweir //============================================================================
485cdf0e10cSrcweir // Service
486cdf0e10cSrcweir
createRegistryInfo_SfxDialogLibraryContainer()487cdf0e10cSrcweir void createRegistryInfo_SfxDialogLibraryContainer()
488cdf0e10cSrcweir {
489cdf0e10cSrcweir static OAutoRegistration< SfxDialogLibraryContainer > aAutoRegistration;
490cdf0e10cSrcweir }
491cdf0e10cSrcweir
getImplementationName()492cdf0e10cSrcweir ::rtl::OUString SAL_CALL SfxDialogLibraryContainer::getImplementationName( ) throw (RuntimeException)
493cdf0e10cSrcweir {
494cdf0e10cSrcweir return getImplementationName_static();
495cdf0e10cSrcweir }
496cdf0e10cSrcweir
getSupportedServiceNames()497cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL SfxDialogLibraryContainer::getSupportedServiceNames( ) throw (RuntimeException)
498cdf0e10cSrcweir {
499cdf0e10cSrcweir return getSupportedServiceNames_static();
500cdf0e10cSrcweir }
501cdf0e10cSrcweir
getSupportedServiceNames_static()502cdf0e10cSrcweir Sequence< OUString > SfxDialogLibraryContainer::getSupportedServiceNames_static()
503cdf0e10cSrcweir {
504cdf0e10cSrcweir Sequence< OUString > aServiceNames( 2 );
505cdf0e10cSrcweir aServiceNames[0] = OUString::createFromAscii( "com.sun.star.script.DocumentDialogLibraryContainer" );
506cdf0e10cSrcweir // plus, for compatibility:
507cdf0e10cSrcweir aServiceNames[1] = OUString::createFromAscii( "com.sun.star.script.DialogLibraryContainer" );
508cdf0e10cSrcweir return aServiceNames;
509cdf0e10cSrcweir }
510cdf0e10cSrcweir
getImplementationName_static()511cdf0e10cSrcweir OUString SfxDialogLibraryContainer::getImplementationName_static()
512cdf0e10cSrcweir {
513cdf0e10cSrcweir static OUString aImplName;
514cdf0e10cSrcweir static sal_Bool bNeedsInit = sal_True;
515cdf0e10cSrcweir
516cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() );
517cdf0e10cSrcweir if( bNeedsInit )
518cdf0e10cSrcweir {
519cdf0e10cSrcweir aImplName = OUString::createFromAscii( "com.sun.star.comp.sfx2.DialogLibraryContainer" );
520cdf0e10cSrcweir bNeedsInit = sal_False;
521cdf0e10cSrcweir }
522cdf0e10cSrcweir return aImplName;
523cdf0e10cSrcweir }
524cdf0e10cSrcweir
Create(const Reference<XComponentContext> &)525cdf0e10cSrcweir Reference< XInterface > SAL_CALL SfxDialogLibraryContainer::Create( const Reference< XComponentContext >& ) throw( Exception )
526cdf0e10cSrcweir {
527cdf0e10cSrcweir Reference< XInterface > xRet =
528cdf0e10cSrcweir static_cast< XInterface* >( static_cast< OWeakObject* >(new SfxDialogLibraryContainer()) );
529cdf0e10cSrcweir return xRet;
530cdf0e10cSrcweir }
531cdf0e10cSrcweir
532cdf0e10cSrcweir
533cdf0e10cSrcweir //============================================================================
534cdf0e10cSrcweir // Implementation class SfxDialogLibrary
535cdf0e10cSrcweir
536cdf0e10cSrcweir // Ctor
SfxDialogLibrary(ModifiableHelper & _rModifiable,const::rtl::OUString & aName,const Reference<XMultiServiceFactory> & xMSF,const Reference<XSimpleFileAccess> & xSFI,SfxDialogLibraryContainer * pParent)537cdf0e10cSrcweir SfxDialogLibrary::SfxDialogLibrary( ModifiableHelper& _rModifiable,
538cdf0e10cSrcweir const ::rtl::OUString& aName,
539cdf0e10cSrcweir const Reference< XMultiServiceFactory >& xMSF,
540cdf0e10cSrcweir const Reference< XSimpleFileAccess >& xSFI,
541cdf0e10cSrcweir SfxDialogLibraryContainer* pParent )
542cdf0e10cSrcweir : SfxLibrary( _rModifiable, getCppuType( (const Reference< XInputStreamProvider > *)0 ), xMSF, xSFI )
543cdf0e10cSrcweir , m_pParent( pParent )
544cdf0e10cSrcweir , m_aName( aName )
545cdf0e10cSrcweir {
546cdf0e10cSrcweir }
547cdf0e10cSrcweir
SfxDialogLibrary(ModifiableHelper & _rModifiable,const::rtl::OUString & aName,const Reference<XMultiServiceFactory> & xMSF,const Reference<XSimpleFileAccess> & xSFI,const OUString & aLibInfoFileURL,const OUString & aStorageURL,sal_Bool ReadOnly,SfxDialogLibraryContainer * pParent)548cdf0e10cSrcweir SfxDialogLibrary::SfxDialogLibrary( ModifiableHelper& _rModifiable,
549cdf0e10cSrcweir const ::rtl::OUString& aName,
550cdf0e10cSrcweir const Reference< XMultiServiceFactory >& xMSF,
551cdf0e10cSrcweir const Reference< XSimpleFileAccess >& xSFI,
552cdf0e10cSrcweir const OUString& aLibInfoFileURL,
553cdf0e10cSrcweir const OUString& aStorageURL,
554cdf0e10cSrcweir sal_Bool ReadOnly,
555cdf0e10cSrcweir SfxDialogLibraryContainer* pParent )
556cdf0e10cSrcweir : SfxLibrary( _rModifiable, getCppuType( (const Reference< XInputStreamProvider > *)0 ),
557cdf0e10cSrcweir xMSF, xSFI, aLibInfoFileURL, aStorageURL, ReadOnly)
558cdf0e10cSrcweir , m_pParent( pParent )
559cdf0e10cSrcweir , m_aName( aName )
560cdf0e10cSrcweir {
561cdf0e10cSrcweir }
562cdf0e10cSrcweir
563cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( SfxDialogLibrary, SfxLibrary, SfxDialogLibrary_BASE );
564cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( SfxDialogLibrary, SfxLibrary, SfxDialogLibrary_BASE );
565cdf0e10cSrcweir
566cdf0e10cSrcweir // Provide modify state including resources
isModified(void)567cdf0e10cSrcweir sal_Bool SfxDialogLibrary::isModified( void )
568cdf0e10cSrcweir {
569cdf0e10cSrcweir sal_Bool bRet = implIsModified();
570cdf0e10cSrcweir
571cdf0e10cSrcweir if( !bRet && m_xStringResourcePersistence.is() )
572cdf0e10cSrcweir bRet = m_xStringResourcePersistence->isModified();
573cdf0e10cSrcweir // else: Resources not accessed so far -> not modified
574cdf0e10cSrcweir
575cdf0e10cSrcweir return bRet;
576cdf0e10cSrcweir }
577cdf0e10cSrcweir
storeResources(void)578cdf0e10cSrcweir void SfxDialogLibrary::storeResources( void )
579cdf0e10cSrcweir {
580cdf0e10cSrcweir if( m_xStringResourcePersistence.is() )
581cdf0e10cSrcweir m_xStringResourcePersistence->store();
582cdf0e10cSrcweir }
583cdf0e10cSrcweir
storeResourcesAsURL(const::rtl::OUString & URL,const::rtl::OUString & NewName)584cdf0e10cSrcweir void SfxDialogLibrary::storeResourcesAsURL
585cdf0e10cSrcweir ( const ::rtl::OUString& URL, const ::rtl::OUString& NewName )
586cdf0e10cSrcweir {
587cdf0e10cSrcweir OUString aComment = aResourceFileCommentBase;
588cdf0e10cSrcweir m_aName = NewName;
589cdf0e10cSrcweir aComment += m_aName;
590cdf0e10cSrcweir
591cdf0e10cSrcweir if( m_xStringResourcePersistence.is() )
592cdf0e10cSrcweir {
593cdf0e10cSrcweir m_xStringResourcePersistence->setComment( aComment );
594cdf0e10cSrcweir
595cdf0e10cSrcweir Reference< resource::XStringResourceWithLocation >
596cdf0e10cSrcweir xStringResourceWithLocation( m_xStringResourcePersistence, UNO_QUERY );
597cdf0e10cSrcweir if( xStringResourceWithLocation.is() )
598cdf0e10cSrcweir xStringResourceWithLocation->storeAsURL( URL );
599cdf0e10cSrcweir }
600cdf0e10cSrcweir }
601cdf0e10cSrcweir
storeResourcesToURL(const OUString & URL,const Reference<task::XInteractionHandler> & xHandler)602cdf0e10cSrcweir void SfxDialogLibrary::storeResourcesToURL( const OUString& URL,
603cdf0e10cSrcweir const Reference< task::XInteractionHandler >& xHandler )
604cdf0e10cSrcweir {
605cdf0e10cSrcweir OUString aComment = aResourceFileCommentBase;
606cdf0e10cSrcweir aComment += m_aName;
607cdf0e10cSrcweir
608cdf0e10cSrcweir if( m_xStringResourcePersistence.is() )
609cdf0e10cSrcweir {
610cdf0e10cSrcweir m_xStringResourcePersistence->storeToURL
611cdf0e10cSrcweir ( URL, aResourceFileNameBase, aComment, xHandler );
612cdf0e10cSrcweir }
613cdf0e10cSrcweir }
614cdf0e10cSrcweir
storeResourcesToStorage(const::com::sun::star::uno::Reference<::com::sun::star::embed::XStorage> & xStorage)615cdf0e10cSrcweir void SfxDialogLibrary::storeResourcesToStorage( const ::com::sun::star::uno::Reference
616cdf0e10cSrcweir < ::com::sun::star::embed::XStorage >& xStorage )
617cdf0e10cSrcweir {
618cdf0e10cSrcweir OUString aComment = aResourceFileCommentBase;
619cdf0e10cSrcweir aComment += m_aName;
620cdf0e10cSrcweir
621cdf0e10cSrcweir if( m_xStringResourcePersistence.is() )
622cdf0e10cSrcweir {
623cdf0e10cSrcweir m_xStringResourcePersistence->storeToStorage
624cdf0e10cSrcweir ( xStorage, aResourceFileNameBase, aComment );
625cdf0e10cSrcweir }
626cdf0e10cSrcweir }
627cdf0e10cSrcweir
628cdf0e10cSrcweir
629cdf0e10cSrcweir // XStringResourceSupplier
630cdf0e10cSrcweir Reference< resource::XStringResourceResolver >
getStringResource()631cdf0e10cSrcweir SAL_CALL SfxDialogLibrary::getStringResource( ) throw (RuntimeException)
632cdf0e10cSrcweir {
633cdf0e10cSrcweir if( !m_xStringResourcePersistence.is() )
634cdf0e10cSrcweir m_xStringResourcePersistence = m_pParent->implCreateStringResource( this );
635cdf0e10cSrcweir
636cdf0e10cSrcweir Reference< resource::XStringResourceResolver > xRet( m_xStringResourcePersistence, UNO_QUERY );
637cdf0e10cSrcweir return xRet;
638cdf0e10cSrcweir }
639cdf0e10cSrcweir
containsValidDialog(const::com::sun::star::uno::Any & aElement)640cdf0e10cSrcweir bool SfxDialogLibrary::containsValidDialog( const ::com::sun::star::uno::Any& aElement )
641cdf0e10cSrcweir {
642cdf0e10cSrcweir Reference< XInputStreamProvider > xISP;
643cdf0e10cSrcweir aElement >>= xISP;
644cdf0e10cSrcweir return xISP.is();
645cdf0e10cSrcweir }
646cdf0e10cSrcweir
isLibraryElementValid(::com::sun::star::uno::Any aElement) const647cdf0e10cSrcweir bool SAL_CALL SfxDialogLibrary::isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const
648cdf0e10cSrcweir {
649cdf0e10cSrcweir return SfxDialogLibrary::containsValidDialog( aElement );
650cdf0e10cSrcweir }
651cdf0e10cSrcweir
652cdf0e10cSrcweir }
653cdf0e10cSrcweir //============================================================================
654cdf0e10cSrcweir
655