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