xref: /AOO41X/main/sfx2/source/doc/docfac.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/registry/MergeConflictException.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/document/XTypeDetection.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/frame/XLoadable.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
37*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
38*cdf0e10cSrcweir #include <tools/config.hxx>
39*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
40*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
41*cdf0e10cSrcweir #include <tools/urlobj.hxx>
42*cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
43*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
44*cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
45*cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include <sfx2/sfx.hrc>
48*cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
49*cdf0e10cSrcweir #include <sfx2/docfac.hxx>
50*cdf0e10cSrcweir #include "sfx2/viewfac.hxx"
51*cdf0e10cSrcweir #include "fltfnc.hxx"
52*cdf0e10cSrcweir #include "arrdecl.hxx"
53*cdf0e10cSrcweir #include <sfx2/app.hxx>
54*cdf0e10cSrcweir #include <sfx2/module.hxx>
55*cdf0e10cSrcweir #include <sfx2/mnumgr.hxx>
56*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
57*cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
58*cdf0e10cSrcweir #include "syspath.hxx"
59*cdf0e10cSrcweir #include <osl/file.hxx>
60*cdf0e10cSrcweir #include <osl/security.hxx>
61*cdf0e10cSrcweir #include "doc.hrc"
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir #include <assert.h>
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir namespace css = ::com::sun::star;
66*cdf0e10cSrcweir using namespace ::com::sun::star;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir //========================================================================
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir DECL_PTRARRAY( SfxViewFactoryArr_Impl, SfxViewFactory*, 2, 2 )
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir //========================================================================
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir DBG_NAME(SfxObjectFactory)
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir //static SfxObjectFactoryArr_Impl* pObjFac = 0;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir //========================================================================
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir struct SfxObjectFactory_Impl
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir 	SfxViewFactoryArr_Impl		aViewFactoryArr;// Liste von <SfxViewFactory>s
83*cdf0e10cSrcweir 	SfxFilterArr_Impl			aFilterArr;     // Liste von <SFxFilter>n
84*cdf0e10cSrcweir 	ResId*						pNameResId;
85*cdf0e10cSrcweir 	::rtl::OUString				aServiceName;
86*cdf0e10cSrcweir 	SfxFilterContainer*			pFilterContainer;
87*cdf0e10cSrcweir 	SfxModule*					pModule;
88*cdf0e10cSrcweir 	sal_uInt16					nImageId;
89*cdf0e10cSrcweir 	String						aStandardTemplate;
90*cdf0e10cSrcweir 	sal_Bool					bTemplateInitialized;
91*cdf0e10cSrcweir 	SvGlobalName				aClassName;
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	SfxObjectFactory_Impl() :
94*cdf0e10cSrcweir 		pNameResId			( NULL ),
95*cdf0e10cSrcweir 		pFilterContainer	( NULL ),
96*cdf0e10cSrcweir 		pModule				( NULL ),
97*cdf0e10cSrcweir 		nImageId			( 0 ),
98*cdf0e10cSrcweir 		bTemplateInitialized( sal_False )
99*cdf0e10cSrcweir 		{}
100*cdf0e10cSrcweir };
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir //========================================================================
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir SfxFilterContainer* SfxObjectFactory::GetFilterContainer( sal_Bool /*bForceLoad*/ ) const
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir 	return pImpl->pFilterContainer;
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir //--------------------------------------------------------------------
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir SfxObjectFactory::SfxObjectFactory
112*cdf0e10cSrcweir (
113*cdf0e10cSrcweir 	const SvGlobalName& 	rName,
114*cdf0e10cSrcweir 	SfxObjectShellFlags 	nFlagsP,
115*cdf0e10cSrcweir 	const char*				pName
116*cdf0e10cSrcweir ) :    pShortName( pName ),
117*cdf0e10cSrcweir        pImpl( new SfxObjectFactory_Impl ),
118*cdf0e10cSrcweir        nFlags( nFlagsP )
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir 	DBG_CTOR(SfxObjectFactory, 0);
121*cdf0e10cSrcweir 	pImpl->pFilterContainer = new SfxFilterContainer( String::CreateFromAscii( pName ) );
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 	String aShortName( String::CreateFromAscii( pShortName ) );
124*cdf0e10cSrcweir 	aShortName.ToLowerAscii();
125*cdf0e10cSrcweir 	pImpl->aClassName = rName;
126*cdf0e10cSrcweir 	if ( aShortName.EqualsAscii( "swriter" ) )
127*cdf0e10cSrcweir 		pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_SW );
128*cdf0e10cSrcweir 	else if ( aShortName.EqualsAscii( "swriter/web" ) )
129*cdf0e10cSrcweir 		pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_SWWEB );
130*cdf0e10cSrcweir 	else if ( aShortName.EqualsAscii( "swriter/globaldocument" ) )
131*cdf0e10cSrcweir 		pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_SWGLOB );
132*cdf0e10cSrcweir 	else if ( aShortName.EqualsAscii( "scalc" ) )
133*cdf0e10cSrcweir 		pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_SC );
134*cdf0e10cSrcweir 	else if ( aShortName.EqualsAscii( "simpress" ) )
135*cdf0e10cSrcweir 		pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_SI );
136*cdf0e10cSrcweir 	else if ( aShortName.EqualsAscii( "sdraw" ) )
137*cdf0e10cSrcweir 		pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_SD );
138*cdf0e10cSrcweir 	else if ( aShortName.EqualsAscii( "message" ) )
139*cdf0e10cSrcweir 		pImpl->pNameResId = new SfxResId( STR_DOCTYPENAME_MESSAGE );
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir //--------------------------------------------------------------------
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir SfxObjectFactory::~SfxObjectFactory()
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir 	DBG_DTOR(SfxObjectFactory, 0);
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 	const sal_uInt16 nCount = pImpl->aFilterArr.Count();
149*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < nCount; ++i )
150*cdf0e10cSrcweir 		delete pImpl->aFilterArr[i];
151*cdf0e10cSrcweir 	delete pImpl->pNameResId;
152*cdf0e10cSrcweir 	delete pImpl;
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir //--------------------------------------------------------------------
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir void SfxObjectFactory::RegisterViewFactory
158*cdf0e10cSrcweir (
159*cdf0e10cSrcweir 	SfxViewFactory &rFactory
160*cdf0e10cSrcweir )
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
163*cdf0e10cSrcweir     {
164*cdf0e10cSrcweir         const String sViewName( rFactory.GetAPIViewName() );
165*cdf0e10cSrcweir 	    for ( sal_uInt16 i = 0; i < pImpl->aViewFactoryArr.Count(); ++i )
166*cdf0e10cSrcweir         {
167*cdf0e10cSrcweir             if ( !pImpl->aViewFactoryArr[i]->GetAPIViewName().Equals( sViewName ) )
168*cdf0e10cSrcweir                 continue;
169*cdf0e10cSrcweir             ByteString sMessage( "SfxObjectFactory::RegisterViewFactory: duplicate view name '" );
170*cdf0e10cSrcweir             sMessage += ByteString( sViewName, RTL_TEXTENCODING_ASCII_US );
171*cdf0e10cSrcweir             sMessage += "'!";
172*cdf0e10cSrcweir             OSL_ENSURE( false, sMessage.GetBuffer() );
173*cdf0e10cSrcweir             break;
174*cdf0e10cSrcweir         }
175*cdf0e10cSrcweir     }
176*cdf0e10cSrcweir #endif
177*cdf0e10cSrcweir 	sal_uInt16 nPos;
178*cdf0e10cSrcweir 	for ( nPos = 0;
179*cdf0e10cSrcweir 		  nPos < pImpl->aViewFactoryArr.Count() &&
180*cdf0e10cSrcweir 		  pImpl->aViewFactoryArr[nPos]->GetOrdinal() <= rFactory.GetOrdinal();
181*cdf0e10cSrcweir 		  ++nPos )
182*cdf0e10cSrcweir 	/* empty loop */;
183*cdf0e10cSrcweir 	pImpl->aViewFactoryArr.Insert(nPos, &rFactory);
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir //--------------------------------------------------------------------
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir sal_uInt16 SfxObjectFactory::GetViewFactoryCount() const
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir 	return pImpl->aViewFactoryArr.Count();
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir //--------------------------------------------------------------------
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir SfxViewFactory& SfxObjectFactory::GetViewFactory(sal_uInt16 i) const
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir 	return *pImpl->aViewFactoryArr[i];
198*cdf0e10cSrcweir }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir //--------------------------------------------------------------------
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir SfxModule* SfxObjectFactory::GetModule() const
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir 	return pImpl->pModule;
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir void SfxObjectFactory::SetModule_Impl( SfxModule *pMod )
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir 	pImpl->pModule = pMod;
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir void SfxObjectFactory::SetSystemTemplate( const String& rServiceName, const String& rTemplateName )
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir     static const int nMaxPathSize = 16000;
215*cdf0e10cSrcweir 	static ::rtl::OUString SERVICE_FILTER_FACTORY = ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" );
216*cdf0e10cSrcweir 	static ::rtl::OUString SERVICE_TYPE_DECTECTION = ::rtl::OUString::createFromAscii( "com.sun.star.document.TypeDetection" );
217*cdf0e10cSrcweir 	static ::rtl::OUString SERVICE_SIMPLE_ACCESS = ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" );
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 	static ::rtl::OUString CONF_ROOT  = ::rtl::OUString::createFromAscii( "/org.openoffice.Setup");
220*cdf0e10cSrcweir 	static ::rtl::OUString CONF_PATH  = ::rtl::OUString::createFromAscii( "Office/Factories/" ) + ::rtl::OUString( rServiceName );
221*cdf0e10cSrcweir 	static ::rtl::OUString PROP_DEF_TEMPL_CHANGED  = ::rtl::OUString::createFromAscii( "ooSetupFactorySystemDefaultTemplateChanged" );
222*cdf0e10cSrcweir 	static ::rtl::OUString PROP_ACTUAL_FILTER  = ::rtl::OUString::createFromAscii( "ooSetupFactoryActualFilter" );
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 	static ::rtl::OUString DEF_TPL_STR = ::rtl::OUString::createFromAscii("/soffice.");
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 	String      sURL;
227*cdf0e10cSrcweir     String      sPath;
228*cdf0e10cSrcweir     sal_Unicode aPathBuffer[nMaxPathSize];
229*cdf0e10cSrcweir     if ( SystemPath::GetUserTemplateLocation( aPathBuffer, nMaxPathSize ))
230*cdf0e10cSrcweir         sPath = String( aPathBuffer );
231*cdf0e10cSrcweir 	::utl::LocalFileHelper::ConvertPhysicalNameToURL( sPath, sURL );
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 	::rtl::OUString aUserTemplateURL( sURL );
234*cdf0e10cSrcweir 	if ( aUserTemplateURL.getLength() != 0)
235*cdf0e10cSrcweir 	{
236*cdf0e10cSrcweir 		try
237*cdf0e10cSrcweir 		{
238*cdf0e10cSrcweir 			uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
239*cdf0e10cSrcweir 			uno::Reference< uno::XInterface > xConfig = ::comphelper::ConfigurationHelper::openConfig(
240*cdf0e10cSrcweir 				xFactory, CONF_ROOT, ::comphelper::ConfigurationHelper::E_STANDARD );
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 			::rtl::OUString aActualFilter;
243*cdf0e10cSrcweir 			::comphelper::ConfigurationHelper::readRelativeKey( xConfig, CONF_PATH, PROP_ACTUAL_FILTER ) >>= aActualFilter;
244*cdf0e10cSrcweir 			sal_Bool bChanged(sal_False);
245*cdf0e10cSrcweir 			::comphelper::ConfigurationHelper::readRelativeKey( xConfig, CONF_PATH, PROP_DEF_TEMPL_CHANGED ) >>= bChanged;
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 			uno::Reference< container::XNameAccess > xFilterFactory(
248*cdf0e10cSrcweir 				xFactory->createInstance( SERVICE_FILTER_FACTORY ), uno::UNO_QUERY_THROW );
249*cdf0e10cSrcweir 			uno::Reference< container::XNameAccess > xTypeDetection(
250*cdf0e10cSrcweir 				xFactory->createInstance( SERVICE_TYPE_DECTECTION ), uno::UNO_QUERY_THROW );
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 			::rtl::OUString aActualFilterTypeName;
253*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue > aActuralFilterData;
254*cdf0e10cSrcweir 			xFilterFactory->getByName( aActualFilter ) >>= aActuralFilterData;
255*cdf0e10cSrcweir 			for ( sal_Int32 nInd = 0; nInd < aActuralFilterData.getLength(); nInd++ )
256*cdf0e10cSrcweir 				if ( aActuralFilterData[nInd].Name.equalsAscii( "Type" ) )
257*cdf0e10cSrcweir 					aActuralFilterData[nInd].Value >>= aActualFilterTypeName;
258*cdf0e10cSrcweir 			::comphelper::SequenceAsHashMap aProps1( xTypeDetection->getByName( aActualFilterTypeName ) );
259*cdf0e10cSrcweir 			uno::Sequence< ::rtl::OUString > aAllExt =
260*cdf0e10cSrcweir 				aProps1.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Extensions" ), uno::Sequence< ::rtl::OUString >() );
261*cdf0e10cSrcweir 			//To-do: check if aAllExt is empty first
262*cdf0e10cSrcweir 			::rtl::OUString aExt = aAllExt[0];
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 			aUserTemplateURL += DEF_TPL_STR;
265*cdf0e10cSrcweir 			aUserTemplateURL += aExt;
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 			uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess(
268*cdf0e10cSrcweir 				xFactory->createInstance( SERVICE_SIMPLE_ACCESS ), uno::UNO_QUERY_THROW );
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 			::rtl::OUString aBackupURL;
271*cdf0e10cSrcweir 			::osl::Security().getConfigDir(aBackupURL);
272*cdf0e10cSrcweir 			aBackupURL += ::rtl::OUString::createFromAscii( "/temp" );
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 			if ( !xSimpleFileAccess->exists( aBackupURL ) )
275*cdf0e10cSrcweir 				xSimpleFileAccess->createFolder( aBackupURL );
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 			aBackupURL += DEF_TPL_STR;
278*cdf0e10cSrcweir 			aBackupURL += aExt;
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 			if ( rTemplateName.Len() != 0 )
281*cdf0e10cSrcweir 			{
282*cdf0e10cSrcweir 				if ( xSimpleFileAccess->exists( aUserTemplateURL ) && !bChanged )
283*cdf0e10cSrcweir 					xSimpleFileAccess->copy( aUserTemplateURL, aBackupURL );
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir 				uno::Reference< document::XTypeDetection > xTypeDetector( xTypeDetection, uno::UNO_QUERY );
286*cdf0e10cSrcweir 				::comphelper::SequenceAsHashMap aProps2( xTypeDetection->getByName( xTypeDetector->queryTypeByURL( rTemplateName ) ) );
287*cdf0e10cSrcweir 				::rtl::OUString aFilterName =
288*cdf0e10cSrcweir 					aProps2.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii("PreferredFilter"), ::rtl::OUString() );
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 				uno::Sequence< beans::PropertyValue > aArgs( 3 );
291*cdf0e10cSrcweir 				aArgs[0].Name = ::rtl::OUString::createFromAscii( "FilterName" );
292*cdf0e10cSrcweir 				aArgs[0].Value <<= aFilterName;
293*cdf0e10cSrcweir 				aArgs[1].Name = ::rtl::OUString::createFromAscii( "AsTemplate" );
294*cdf0e10cSrcweir 				aArgs[1].Value <<= sal_True;
295*cdf0e10cSrcweir 				aArgs[2].Name = ::rtl::OUString::createFromAscii( "URL" );
296*cdf0e10cSrcweir 				aArgs[2].Value <<= ::rtl::OUString( rTemplateName );
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 				uno::Reference< frame::XLoadable > xLoadable( xFactory->createInstance( ::rtl::OUString( rServiceName ) ), uno::UNO_QUERY );
299*cdf0e10cSrcweir 				xLoadable->load( aArgs );
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 				aArgs.realloc( 2 );
302*cdf0e10cSrcweir 				aArgs[1].Name = ::rtl::OUString::createFromAscii( "Overwrite" );
303*cdf0e10cSrcweir 				aArgs[1].Value <<= sal_True;
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 				uno::Reference< frame::XStorable > xStorable( xLoadable, uno::UNO_QUERY );
306*cdf0e10cSrcweir 				xStorable->storeToURL( aUserTemplateURL, aArgs );
307*cdf0e10cSrcweir 				::comphelper::ConfigurationHelper::writeRelativeKey( xConfig, CONF_PATH, PROP_DEF_TEMPL_CHANGED, uno::makeAny( sal_True ));
308*cdf0e10cSrcweir 				::comphelper::ConfigurationHelper::flush( xConfig );
309*cdf0e10cSrcweir 			}
310*cdf0e10cSrcweir 			else
311*cdf0e10cSrcweir 			{
312*cdf0e10cSrcweir 				DBG_ASSERT( bChanged, "invalid ooSetupFactorySystemDefaultTemplateChanged value!" );
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 				xSimpleFileAccess->copy( aBackupURL, aUserTemplateURL );
315*cdf0e10cSrcweir 				xSimpleFileAccess->kill( aBackupURL );
316*cdf0e10cSrcweir 				::comphelper::ConfigurationHelper::writeRelativeKey( xConfig, CONF_PATH, PROP_DEF_TEMPL_CHANGED, uno::makeAny( sal_False ));
317*cdf0e10cSrcweir 				::comphelper::ConfigurationHelper::flush( xConfig );
318*cdf0e10cSrcweir 			}
319*cdf0e10cSrcweir 		}
320*cdf0e10cSrcweir 		catch( uno::Exception& )
321*cdf0e10cSrcweir 		{
322*cdf0e10cSrcweir 		}
323*cdf0e10cSrcweir 	}
324*cdf0e10cSrcweir }
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir void SfxObjectFactory::SetStandardTemplate( const String& rServiceName, const String& rTemplate )
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir 	SvtModuleOptions::EFactory eFac = SvtModuleOptions::ClassifyFactoryByServiceName(rServiceName);
329*cdf0e10cSrcweir     if (eFac == SvtModuleOptions::E_UNKNOWN_FACTORY)
330*cdf0e10cSrcweir         eFac = SvtModuleOptions::ClassifyFactoryByShortName(rServiceName);
331*cdf0e10cSrcweir     if (eFac != SvtModuleOptions::E_UNKNOWN_FACTORY)
332*cdf0e10cSrcweir 	{
333*cdf0e10cSrcweir 		SetSystemTemplate( rServiceName, rTemplate );
334*cdf0e10cSrcweir 		SvtModuleOptions().SetFactoryStandardTemplate(eFac, rTemplate);
335*cdf0e10cSrcweir 	}
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir String SfxObjectFactory::GetStandardTemplate( const String& rServiceName )
339*cdf0e10cSrcweir {
340*cdf0e10cSrcweir 	SvtModuleOptions::EFactory eFac = SvtModuleOptions::ClassifyFactoryByServiceName(rServiceName);
341*cdf0e10cSrcweir     if (eFac == SvtModuleOptions::E_UNKNOWN_FACTORY)
342*cdf0e10cSrcweir         eFac = SvtModuleOptions::ClassifyFactoryByShortName(rServiceName);
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir     String sTemplate;
345*cdf0e10cSrcweir     if (eFac != SvtModuleOptions::E_UNKNOWN_FACTORY)
346*cdf0e10cSrcweir         sTemplate = SvtModuleOptions().GetFactoryStandardTemplate(eFac);
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir 	return sTemplate;
349*cdf0e10cSrcweir }
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir /*
352*cdf0e10cSrcweir const SfxObjectFactory* SfxObjectFactory::GetFactory( const String& rFactoryURL )
353*cdf0e10cSrcweir {
354*cdf0e10cSrcweir 	const SfxObjectFactory* pFactory = 0;
355*cdf0e10cSrcweir 	String aFact( rFactoryURL );
356*cdf0e10cSrcweir 	String aPrefix( DEFINE_CONST_UNICODE( "private:factory/" ) );
357*cdf0e10cSrcweir 	if ( aPrefix.Len() == aFact.Match( aPrefix ) )
358*cdf0e10cSrcweir 		// Aufruf m"oglich mit z.B. "swriter" oder "private:factory/swriter"
359*cdf0e10cSrcweir 		aFact.Erase( 0, aPrefix.Len() );
360*cdf0e10cSrcweir 	sal_uInt16 nPos = aFact.Search( '?' );
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir 	// Etwaige Parameter abschneiden
363*cdf0e10cSrcweir 	aFact.Erase( nPos, aFact.Len() );
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 	SfxApplication *pApp = SFX_APP();
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 	// "swriter4" durch "swriter" ersetzen, zum Vergleichen uppercase verwenden
368*cdf0e10cSrcweir 	WildCard aSearchedFac( aFact.EraseAllChars('4').ToUpperAscii() );
369*cdf0e10cSrcweir     for( sal_uInt16 n = GetObjectFactoryCount_Impl(); !pFactory && n--; )
370*cdf0e10cSrcweir 	{
371*cdf0e10cSrcweir         pFactory = &GetObjectFactory_Impl( n );
372*cdf0e10cSrcweir 		String aCompareTo = String::CreateFromAscii( pFactory->GetShortName() );
373*cdf0e10cSrcweir 		aCompareTo.ToUpperAscii();
374*cdf0e10cSrcweir 		if( !aSearchedFac.Matches( aCompareTo ) )
375*cdf0e10cSrcweir 			pFactory = 0;
376*cdf0e10cSrcweir 	}
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir 	return pFactory;
379*cdf0e10cSrcweir }
380*cdf0e10cSrcweir */
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir const SfxFilter* SfxObjectFactory::GetTemplateFilter() const
383*cdf0e10cSrcweir {
384*cdf0e10cSrcweir 	sal_uInt16 nVersion=0;
385*cdf0e10cSrcweir 	SfxFilterMatcher aMatcher ( String::CreateFromAscii( pShortName ) );
386*cdf0e10cSrcweir 	SfxFilterMatcherIter aIter( &aMatcher );
387*cdf0e10cSrcweir 	const SfxFilter *pFilter = 0;
388*cdf0e10cSrcweir 	const SfxFilter *pTemp = aIter.First();
389*cdf0e10cSrcweir 	while ( pTemp )
390*cdf0e10cSrcweir 	{
391*cdf0e10cSrcweir 		if( pTemp->IsOwnFormat() && pTemp->IsOwnTemplateFormat() && ( pTemp->GetVersion() > nVersion ) )
392*cdf0e10cSrcweir 		{
393*cdf0e10cSrcweir 			pFilter = pTemp;
394*cdf0e10cSrcweir 			nVersion = (sal_uInt16) pTemp->GetVersion();
395*cdf0e10cSrcweir 		}
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir 		pTemp = aIter.Next();
398*cdf0e10cSrcweir 	}
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir 	return pFilter;
401*cdf0e10cSrcweir }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir void SfxObjectFactory::SetDocumentTypeNameResource( const ResId& rId )
404*cdf0e10cSrcweir {
405*cdf0e10cSrcweir 	DBG_ASSERT( !pImpl->pNameResId, "UI-Namensresource mehrfach gesetzt!" );
406*cdf0e10cSrcweir 	pImpl->pNameResId = new ResId( rId );
407*cdf0e10cSrcweir }
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir String SfxObjectFactory::GetDocumentTypeName() const
410*cdf0e10cSrcweir {
411*cdf0e10cSrcweir 	if ( pImpl->pNameResId )
412*cdf0e10cSrcweir 		return String( *pImpl->pNameResId );
413*cdf0e10cSrcweir 	return String();
414*cdf0e10cSrcweir }
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir void SfxObjectFactory::SetDocumentServiceName( const ::rtl::OUString& rServiceName )
417*cdf0e10cSrcweir {
418*cdf0e10cSrcweir 	pImpl->aServiceName = rServiceName;
419*cdf0e10cSrcweir }
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir const ::rtl::OUString& SfxObjectFactory::GetDocumentServiceName() const
422*cdf0e10cSrcweir {
423*cdf0e10cSrcweir 	return pImpl->aServiceName;
424*cdf0e10cSrcweir }
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir const SvGlobalName& SfxObjectFactory::GetClassId() const
427*cdf0e10cSrcweir {
428*cdf0e10cSrcweir 	return pImpl->aClassName;
429*cdf0e10cSrcweir }
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir String SfxObjectFactory::GetFactoryURL() const
432*cdf0e10cSrcweir {
433*cdf0e10cSrcweir     ::rtl::OUStringBuffer aURLComposer;
434*cdf0e10cSrcweir     aURLComposer.appendAscii( "private:factory/" );
435*cdf0e10cSrcweir     aURLComposer.appendAscii( GetShortName() );
436*cdf0e10cSrcweir     return aURLComposer.makeStringAndClear();
437*cdf0e10cSrcweir }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir String SfxObjectFactory::GetModuleName() const
440*cdf0e10cSrcweir {
441*cdf0e10cSrcweir     static ::rtl::OUString SERVICENAME_MODULEMANAGER = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
442*cdf0e10cSrcweir     static ::rtl::OUString PROP_MODULEUINAME         = ::rtl::OUString::createFromAscii("ooSetupFactoryUIName");
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir     try
445*cdf0e10cSrcweir     {
446*cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess > xModuleManager(
449*cdf0e10cSrcweir             xSMGR->createInstance(SERVICENAME_MODULEMANAGER),
450*cdf0e10cSrcweir             css::uno::UNO_QUERY_THROW);
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir         ::rtl::OUString sDocService(GetDocumentServiceName());
453*cdf0e10cSrcweir         ::comphelper::SequenceAsHashMap aPropSet( xModuleManager->getByName(sDocService) );
454*cdf0e10cSrcweir         ::rtl::OUString sModuleName = aPropSet.getUnpackedValueOrDefault(PROP_MODULEUINAME, ::rtl::OUString());
455*cdf0e10cSrcweir         return String(sModuleName);
456*cdf0e10cSrcweir     }
457*cdf0e10cSrcweir     catch(const css::uno::RuntimeException&)
458*cdf0e10cSrcweir         { throw; }
459*cdf0e10cSrcweir     catch(const css::uno::Exception&)
460*cdf0e10cSrcweir         {}
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir     return String();
463*cdf0e10cSrcweir }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir sal_uInt16 SfxObjectFactory::GetViewNo_Impl( const sal_uInt16 i_nViewId, const sal_uInt16 i_nFallback ) const
467*cdf0e10cSrcweir {
468*cdf0e10cSrcweir     for ( sal_uInt16 curViewNo = 0; curViewNo < GetViewFactoryCount(); ++curViewNo )
469*cdf0e10cSrcweir     {
470*cdf0e10cSrcweir         const sal_uInt16 curViewId = GetViewFactory( curViewNo ).GetOrdinal();
471*cdf0e10cSrcweir         if ( i_nViewId == curViewId )
472*cdf0e10cSrcweir            return curViewNo;
473*cdf0e10cSrcweir     }
474*cdf0e10cSrcweir     return i_nFallback;
475*cdf0e10cSrcweir }
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir SfxViewFactory* SfxObjectFactory::GetViewFactoryByViewName( const String& i_rViewName ) const
478*cdf0e10cSrcweir {
479*cdf0e10cSrcweir     for (   sal_uInt16 nViewNo = 0;
480*cdf0e10cSrcweir             nViewNo < GetViewFactoryCount();
481*cdf0e10cSrcweir             ++nViewNo
482*cdf0e10cSrcweir         )
483*cdf0e10cSrcweir     {
484*cdf0e10cSrcweir         SfxViewFactory& rViewFac( GetViewFactory( nViewNo ) );
485*cdf0e10cSrcweir         if  (   ( rViewFac.GetAPIViewName() == i_rViewName )
486*cdf0e10cSrcweir             ||  ( rViewFac.GetLegacyViewName() == i_rViewName )
487*cdf0e10cSrcweir             )
488*cdf0e10cSrcweir             return &rViewFac;
489*cdf0e10cSrcweir     }
490*cdf0e10cSrcweir     return NULL;
491*cdf0e10cSrcweir }
492