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