1*efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*efeef26fSAndrew Rist * distributed with this work for additional information 6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*efeef26fSAndrew Rist * software distributed under the License is distributed on an 15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17*efeef26fSAndrew Rist * specific language governing permissions and limitations 18*efeef26fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*efeef26fSAndrew Rist *************************************************************/ 21*efeef26fSAndrew Rist 22*efeef26fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sw.hxx" 26cdf0e10cSrcweir #include "swdetect.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <framework/interaction.hxx> 29cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 30cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 31cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp> 32cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX 33cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 36cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 37cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 38cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> 39cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp> 40cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveAppException.hpp> 41cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 42cdf0e10cSrcweir #include <com/sun/star/packages/zip/ZipIOException.hpp> 43cdf0e10cSrcweir #ifndef _TOOLKIT_UNOHLP_HXX 44cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 45cdf0e10cSrcweir #endif 46cdf0e10cSrcweir #include <ucbhelper/simpleinteractionrequest.hxx> 47cdf0e10cSrcweir #include <rtl/ustring.h> 48cdf0e10cSrcweir #include <rtl/logfile.hxx> 49cdf0e10cSrcweir #include <svl/itemset.hxx> 50cdf0e10cSrcweir #include <vcl/window.hxx> 51cdf0e10cSrcweir #include <svl/eitem.hxx> 52cdf0e10cSrcweir #include <svl/stritem.hxx> 53cdf0e10cSrcweir #include <tools/urlobj.hxx> 54cdf0e10cSrcweir #include <vos/mutex.hxx> 55cdf0e10cSrcweir #include <svtools/sfxecode.hxx> 56cdf0e10cSrcweir #include <svtools/ehdl.hxx> 57cdf0e10cSrcweir #include <sot/storinfo.hxx> 58cdf0e10cSrcweir #include <vcl/svapp.hxx> 59cdf0e10cSrcweir #include <sfx2/app.hxx> 60cdf0e10cSrcweir #include <sfx2/sfxsids.hrc> 61cdf0e10cSrcweir #include <sfx2/request.hxx> 62cdf0e10cSrcweir #include <sfx2/docfile.hxx> 63cdf0e10cSrcweir #include <sfx2/docfilt.hxx> 64cdf0e10cSrcweir #include <sfx2/fcontnr.hxx> 65cdf0e10cSrcweir #include <sfx2/brokenpackageint.hxx> 66cdf0e10cSrcweir #include <svtools/FilterConfigItem.hxx> 67cdf0e10cSrcweir #include <unotools/moduleoptions.hxx> 68cdf0e10cSrcweir #include <com/sun/star/util/XArchiver.hpp> 69cdf0e10cSrcweir #include <comphelper/ihwrapnofilter.hxx> 70cdf0e10cSrcweir 71cdf0e10cSrcweir #include <swdll.hxx> 72cdf0e10cSrcweir 73cdf0e10cSrcweir using namespace ::com::sun::star; 74cdf0e10cSrcweir using namespace ::com::sun::star::uno; 75cdf0e10cSrcweir using namespace ::com::sun::star::io; 76cdf0e10cSrcweir using namespace ::com::sun::star::frame; 77cdf0e10cSrcweir using namespace ::com::sun::star::task; 78cdf0e10cSrcweir using namespace ::com::sun::star::beans; 79cdf0e10cSrcweir using namespace ::com::sun::star::lang; 80cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 81cdf0e10cSrcweir using ::rtl::OUString; 82cdf0e10cSrcweir 83cdf0e10cSrcweir SwFilterDetect::SwFilterDetect( const REFERENCE < lang::XMultiServiceFactory >& /*xFactory*/ ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir SwFilterDetect::~SwFilterDetect() 88cdf0e10cSrcweir { 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir ::rtl::OUString SAL_CALL SwFilterDetect::detect( uno::Sequence< beans::PropertyValue >& lDescriptor ) throw( uno::RuntimeException ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir REFERENCE< XInputStream > xStream; 94cdf0e10cSrcweir REFERENCE< XContent > xContent; 95cdf0e10cSrcweir REFERENCE< XInteractionHandler > xInteraction; 96cdf0e10cSrcweir String aURL; 97cdf0e10cSrcweir ::rtl::OUString sTemp; 98cdf0e10cSrcweir String aTypeName; // a name describing the type (from MediaDescriptor, usually from flat detection) 99cdf0e10cSrcweir String aPreselectedFilterName; // a name describing the filter to use (from MediaDescriptor, usually from UI action) 100cdf0e10cSrcweir 101cdf0e10cSrcweir ::rtl::OUString aDocumentTitle; // interesting only if set in this method 102cdf0e10cSrcweir 103cdf0e10cSrcweir // opening as template is done when a parameter tells to do so and a template filter can be detected 104cdf0e10cSrcweir // (otherwise no valid filter would be found) or if the detected filter is a template filter and 105cdf0e10cSrcweir // there is no parameter that forbids to open as template 106cdf0e10cSrcweir sal_Bool bOpenAsTemplate = sal_False; 107cdf0e10cSrcweir sal_Bool bWasReadOnly = sal_False, bReadOnly = sal_False; 108cdf0e10cSrcweir 109cdf0e10cSrcweir sal_Bool bRepairPackage = sal_False; 110cdf0e10cSrcweir sal_Bool bRepairAllowed = sal_False; 111cdf0e10cSrcweir 112cdf0e10cSrcweir // now some parameters that can already be in the array, but may be overwritten or new inserted here 113cdf0e10cSrcweir // remember their indices in the case new values must be added to the array 114cdf0e10cSrcweir sal_Int32 nPropertyCount = lDescriptor.getLength(); 115cdf0e10cSrcweir sal_Int32 nIndexOfFilterName = -1; 116cdf0e10cSrcweir sal_Int32 nIndexOfInputStream = -1; 117cdf0e10cSrcweir sal_Int32 nIndexOfContent = -1; 118cdf0e10cSrcweir sal_Int32 nIndexOfReadOnlyFlag = -1; 119cdf0e10cSrcweir sal_Int32 nIndexOfTemplateFlag = -1; 120cdf0e10cSrcweir sal_Int32 nIndexOfDocumentTitle = -1; 121cdf0e10cSrcweir sal_Int32 nIndexOfInteractionHandler = -1; 122cdf0e10cSrcweir 123cdf0e10cSrcweir for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir // extract properties 126cdf0e10cSrcweir if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("URL")) ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir lDescriptor[nProperty].Value >>= sTemp; 129cdf0e10cSrcweir aURL = sTemp; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir else if( !aURL.Len() && lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("FileName")) ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir lDescriptor[nProperty].Value >>= sTemp; 134cdf0e10cSrcweir aURL = sTemp; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("TypeName")) ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir lDescriptor[nProperty].Value >>= sTemp; 139cdf0e10cSrcweir aTypeName = sTemp; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("FilterName")) ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir lDescriptor[nProperty].Value >>= sTemp; 144cdf0e10cSrcweir aPreselectedFilterName = sTemp; 145cdf0e10cSrcweir 146cdf0e10cSrcweir // if the preselected filter name is not correct, it must be erased after detection 147cdf0e10cSrcweir // remember index of property to get access to it later 148cdf0e10cSrcweir nIndexOfFilterName = nProperty; 149cdf0e10cSrcweir } 150cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("InputStream")) ) 151cdf0e10cSrcweir nIndexOfInputStream = nProperty; 152cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")) ) 153cdf0e10cSrcweir nIndexOfReadOnlyFlag = nProperty; 154cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("UCBContent")) ) 155cdf0e10cSrcweir nIndexOfContent = nProperty; 156cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("AsTemplate")) ) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir lDescriptor[nProperty].Value >>= bOpenAsTemplate; 159cdf0e10cSrcweir nIndexOfTemplateFlag = nProperty; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("InteractionHandler")) ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir lDescriptor[nProperty].Value >>= xInteraction; 164cdf0e10cSrcweir nIndexOfInteractionHandler = nProperty; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("RepairPackage")) ) 167cdf0e10cSrcweir lDescriptor[nProperty].Value >>= bRepairPackage; 168cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("DocumentTitle")) ) 169cdf0e10cSrcweir nIndexOfDocumentTitle = nProperty; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir // can't check the type for external filters, so set the "dont" flag accordingly 173cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 174cdf0e10cSrcweir //SfxFilterFlags nMust = SFX_FILTER_IMPORT, nDont = SFX_FILTER_NOTINSTALLED; 175cdf0e10cSrcweir 176cdf0e10cSrcweir SfxApplication* pApp = SFX_APP(); 177cdf0e10cSrcweir SfxAllItemSet *pSet = new SfxAllItemSet( pApp->GetPool() ); 178cdf0e10cSrcweir TransformParameters( SID_OPENDOC, lDescriptor, *pSet ); 179cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pItem, SfxBoolItem, SID_DOC_READONLY, sal_False ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir bWasReadOnly = pItem && pItem->GetValue(); 182cdf0e10cSrcweir 183cdf0e10cSrcweir const SfxFilter* pFilter = 0; 184cdf0e10cSrcweir String aPrefix = String::CreateFromAscii( "private:factory/" ); 185cdf0e10cSrcweir if( aURL.Match( aPrefix ) == aPrefix.Len() ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir if( SvtModuleOptions().IsWriter() ) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir String aPattern( aPrefix ); 190cdf0e10cSrcweir aPattern += String::CreateFromAscii("swriter"); 191cdf0e10cSrcweir if ( aURL.Match( aPattern ) >= aPattern.Len() ) 192cdf0e10cSrcweir //pFilter = SfxFilter::GetDefaultFilterFromFactory( aURL ); 193cdf0e10cSrcweir return aTypeName; 194cdf0e10cSrcweir } 195cdf0e10cSrcweir } 196cdf0e10cSrcweir else 197cdf0e10cSrcweir { 198cdf0e10cSrcweir // ctor of SfxMedium uses owner transition of ItemSet 199cdf0e10cSrcweir SfxMedium aMedium( aURL, bWasReadOnly ? STREAM_STD_READ : STREAM_STD_READWRITE, sal_False, NULL, pSet ); 200cdf0e10cSrcweir aMedium.UseInteractionHandler( sal_True ); 201cdf0e10cSrcweir if ( aMedium.GetErrorCode() == ERRCODE_NONE ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir // remember input stream and content and put them into the descriptor later 204cdf0e10cSrcweir // should be done here since later the medium can switch to a version 205cdf0e10cSrcweir xStream = aMedium.GetInputStream(); 206cdf0e10cSrcweir xContent = aMedium.GetContent(); 207cdf0e10cSrcweir bReadOnly = aMedium.IsReadOnly(); 208cdf0e10cSrcweir 209cdf0e10cSrcweir sal_Bool bIsStorage = aMedium.IsStorage(); 210cdf0e10cSrcweir if ( bIsStorage ) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage = aMedium.GetStorage( sal_False ); 213cdf0e10cSrcweir if ( aMedium.GetLastStorageCreationState() != ERRCODE_NONE ) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir // error during storage creation means _here_ that the medium 216cdf0e10cSrcweir // is broken, but we can not handle it in medium since impossibility 217cdf0e10cSrcweir // to create a storage does not _always_ means that the medium is broken 218cdf0e10cSrcweir aMedium.SetError( aMedium.GetLastStorageCreationState(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 219cdf0e10cSrcweir if ( xInteraction.is() ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir OUString empty; 222cdf0e10cSrcweir try 223cdf0e10cSrcweir { 224cdf0e10cSrcweir InteractiveAppException xException( empty, 225cdf0e10cSrcweir REFERENCE< XInterface >(), 226cdf0e10cSrcweir InteractionClassification_ERROR, 227cdf0e10cSrcweir aMedium.GetError() ); 228cdf0e10cSrcweir 229cdf0e10cSrcweir REFERENCE< XInteractionRequest > xRequest( 230cdf0e10cSrcweir new ucbhelper::SimpleInteractionRequest( makeAny( xException ), 231cdf0e10cSrcweir ucbhelper::CONTINUATION_APPROVE ) ); 232cdf0e10cSrcweir xInteraction->handle( xRequest ); 233cdf0e10cSrcweir } 234cdf0e10cSrcweir catch ( Exception & ) {}; 235cdf0e10cSrcweir } 236cdf0e10cSrcweir } 237cdf0e10cSrcweir else 238cdf0e10cSrcweir { 239cdf0e10cSrcweir DBG_ASSERT( xStorage.is(), "At this point storage must exist!" ); 240cdf0e10cSrcweir 241cdf0e10cSrcweir try 242cdf0e10cSrcweir { 243cdf0e10cSrcweir const SfxFilter* pPreFilter = aPreselectedFilterName.Len() ? 244cdf0e10cSrcweir SfxFilterMatcher().GetFilter4FilterName( aPreselectedFilterName ) : aTypeName.Len() ? 245cdf0e10cSrcweir SfxFilterMatcher(String::CreateFromAscii("swriter")).GetFilter4EA( aTypeName ) : 0; 246cdf0e10cSrcweir if (!pPreFilter) 247cdf0e10cSrcweir pPreFilter = SfxFilterMatcher(String::CreateFromAscii("sweb")).GetFilter4EA( aTypeName ); 248cdf0e10cSrcweir String aFilterName; 249cdf0e10cSrcweir if ( pPreFilter ) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir aFilterName = pPreFilter->GetName(); 252cdf0e10cSrcweir aTypeName = pPreFilter->GetTypeName(); 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255cdf0e10cSrcweir aTypeName = SfxFilter::GetTypeFromStorage( xStorage, pPreFilter ? pPreFilter->IsOwnTemplateFormat() : sal_False, &aFilterName ); 256cdf0e10cSrcweir } 257cdf0e10cSrcweir catch( lang::WrappedTargetException& aWrap ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir packages::zip::ZipIOException aZipException; 260cdf0e10cSrcweir 261cdf0e10cSrcweir // repairing is done only if this type is requested from outside 262cdf0e10cSrcweir // we don't do any type detection on broken packages (f.e. because it might be impossible), so any requested 263cdf0e10cSrcweir // type will be accepted if the user allows to repair the file 264cdf0e10cSrcweir if ( ( aWrap.TargetException >>= aZipException ) && ( aTypeName.Len() || aPreselectedFilterName.Len() ) ) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir if ( xInteraction.is() ) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir // the package is a broken one 269cdf0e10cSrcweir aDocumentTitle = aMedium.GetURLObject().getName( 270cdf0e10cSrcweir INetURLObject::LAST_SEGMENT, 271cdf0e10cSrcweir true, 272cdf0e10cSrcweir INetURLObject::DECODE_WITH_CHARSET ); 273cdf0e10cSrcweir 274cdf0e10cSrcweir if ( !bRepairPackage ) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir // ask the user whether he wants to try to repair 277cdf0e10cSrcweir RequestPackageReparation aRequest( aDocumentTitle ); 278cdf0e10cSrcweir xInteraction->handle( aRequest.GetRequest() ); 279cdf0e10cSrcweir bRepairAllowed = aRequest.isApproved(); 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir if ( !bRepairAllowed ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir // repair either not allowed or not successful 285cdf0e10cSrcweir // repair either not allowed or not successful 286cdf0e10cSrcweir NotifyBrokenPackage aNotifyRequest( aDocumentTitle ); 287cdf0e10cSrcweir xInteraction->handle( aNotifyRequest.GetRequest() ); 288cdf0e10cSrcweir 289cdf0e10cSrcweir rtl::Reference< ::comphelper::OIHWrapNoFilterDialog > xHandler = new ::comphelper::OIHWrapNoFilterDialog( xInteraction ); 290cdf0e10cSrcweir if ( nIndexOfInteractionHandler != -1 ) 291cdf0e10cSrcweir lDescriptor[nIndexOfInteractionHandler].Value <<= uno::Reference< XInteractionHandler >( static_cast< task::XInteractionHandler* >( xHandler.get() ) ); 292cdf0e10cSrcweir 293cdf0e10cSrcweir aMedium.SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 294cdf0e10cSrcweir } 295cdf0e10cSrcweir } 296cdf0e10cSrcweir else 297cdf0e10cSrcweir // no interaction, error handling as usual 298cdf0e10cSrcweir aMedium.SetError( ERRCODE_IO_BROKENPACKAGE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 299cdf0e10cSrcweir 300cdf0e10cSrcweir if ( !bRepairAllowed ) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir aTypeName.Erase(); 303cdf0e10cSrcweir aPreselectedFilterName.Erase(); 304cdf0e10cSrcweir } 305cdf0e10cSrcweir } 306cdf0e10cSrcweir } 307cdf0e10cSrcweir catch( uno::RuntimeException& ) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir throw; 310cdf0e10cSrcweir } 311cdf0e10cSrcweir catch( uno::Exception& ) 312cdf0e10cSrcweir { 313cdf0e10cSrcweir aTypeName.Erase(); 314cdf0e10cSrcweir aPreselectedFilterName.Erase(); 315cdf0e10cSrcweir } 316cdf0e10cSrcweir } 317cdf0e10cSrcweir } 318cdf0e10cSrcweir else 319cdf0e10cSrcweir { 320cdf0e10cSrcweir aMedium.GetInStream(); 321cdf0e10cSrcweir if ( aMedium.GetErrorCode() == ERRCODE_NONE ) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir if ( aPreselectedFilterName.Len() ) 324cdf0e10cSrcweir pFilter = SfxFilter::GetFilterByName( aPreselectedFilterName ); 325cdf0e10cSrcweir else 326cdf0e10cSrcweir pFilter = SfxFilterMatcher().GetFilter4EA( aTypeName ); 327cdf0e10cSrcweir 328cdf0e10cSrcweir sal_Bool bTestWriter = !pFilter || pFilter->GetServiceName().EqualsAscii("com.sun.star.text.TextDocument") || 329cdf0e10cSrcweir pFilter->GetServiceName().EqualsAscii("com.sun.star.text.WebDocument"); 330cdf0e10cSrcweir sal_Bool bTestGlobal = !pFilter || pFilter->GetServiceName().EqualsAscii("com.sun.star.text.GlobalDocument"); 331cdf0e10cSrcweir 332cdf0e10cSrcweir const SfxFilter* pOrigFilter = NULL; 333cdf0e10cSrcweir if ( !bTestWriter && !bTestGlobal && pFilter ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir // cross filter; now this should be a type detection only, not a filter detection 336cdf0e10cSrcweir // we can simulate it by preserving the preselected filter if the type matches 337cdf0e10cSrcweir // example: HTML filter for Calc 338cdf0e10cSrcweir pOrigFilter = pFilter; 339cdf0e10cSrcweir pFilter = SfxFilterMatcher().GetFilter4EA( pFilter->GetTypeName() ); 340cdf0e10cSrcweir bTestWriter = sal_True; 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir sal_uLong nErr = ERRCODE_NONE; 344cdf0e10cSrcweir if ( pFilter || bTestWriter ) 345cdf0e10cSrcweir nErr = DetectFilter( aMedium, &pFilter ); 346cdf0e10cSrcweir if ( nErr != ERRCODE_NONE ) 347cdf0e10cSrcweir pFilter = NULL; 348cdf0e10cSrcweir else if ( pOrigFilter && pFilter && pFilter->GetTypeName() == pOrigFilter->GetTypeName() ) 349cdf0e10cSrcweir // cross filter, see above 350cdf0e10cSrcweir pFilter = pOrigFilter; 351cdf0e10cSrcweir } 352cdf0e10cSrcweir 353cdf0e10cSrcweir if ( pFilter ) 354cdf0e10cSrcweir aTypeName = pFilter->GetTypeName(); 355cdf0e10cSrcweir else 356cdf0e10cSrcweir aTypeName.Erase(); 357cdf0e10cSrcweir } 358cdf0e10cSrcweir } 359cdf0e10cSrcweir } 360cdf0e10cSrcweir 361cdf0e10cSrcweir if ( nIndexOfInputStream == -1 && xStream.is() ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir // if input stream wasn't part of the descriptor, now it should be, otherwise the content would be opend twice 364cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 365cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("InputStream"); 366cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= xStream; 367cdf0e10cSrcweir nPropertyCount++; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir if ( nIndexOfContent == -1 && xContent.is() ) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir // if input stream wasn't part of the descriptor, now it should be, otherwise the content would be opend twice 373cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 374cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("UCBContent"); 375cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= xContent; 376cdf0e10cSrcweir nPropertyCount++; 377cdf0e10cSrcweir } 378cdf0e10cSrcweir 379cdf0e10cSrcweir if ( bReadOnly != bWasReadOnly ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir if ( nIndexOfReadOnlyFlag == -1 ) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 384cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("ReadOnly"); 385cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= bReadOnly; 386cdf0e10cSrcweir nPropertyCount++; 387cdf0e10cSrcweir } 388cdf0e10cSrcweir else 389cdf0e10cSrcweir lDescriptor[nIndexOfReadOnlyFlag].Value <<= bReadOnly; 390cdf0e10cSrcweir } 391cdf0e10cSrcweir 392cdf0e10cSrcweir if ( !bRepairPackage && bRepairAllowed ) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 395cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("RepairPackage"); 396cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= bRepairAllowed; 397cdf0e10cSrcweir nPropertyCount++; 398cdf0e10cSrcweir bOpenAsTemplate = sal_True; 399cdf0e10cSrcweir // TODO/LATER: set progress bar that should be used 400cdf0e10cSrcweir } 401cdf0e10cSrcweir 402cdf0e10cSrcweir if ( bOpenAsTemplate ) 403cdf0e10cSrcweir { 404cdf0e10cSrcweir if ( nIndexOfTemplateFlag == -1 ) 405cdf0e10cSrcweir { 406cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 407cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("AsTemplate"); 408cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= bOpenAsTemplate; 409cdf0e10cSrcweir nPropertyCount++; 410cdf0e10cSrcweir } 411cdf0e10cSrcweir else 412cdf0e10cSrcweir lDescriptor[nIndexOfTemplateFlag].Value <<= bOpenAsTemplate; 413cdf0e10cSrcweir } 414cdf0e10cSrcweir 415cdf0e10cSrcweir if ( aDocumentTitle.getLength() ) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir // the title was set here 418cdf0e10cSrcweir if ( nIndexOfDocumentTitle == -1 ) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 421cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("DocumentTitle"); 422cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= aDocumentTitle; 423cdf0e10cSrcweir nPropertyCount++; 424cdf0e10cSrcweir } 425cdf0e10cSrcweir else 426cdf0e10cSrcweir lDescriptor[nIndexOfDocumentTitle].Value <<= aDocumentTitle; 427cdf0e10cSrcweir } 428cdf0e10cSrcweir 429cdf0e10cSrcweir 430cdf0e10cSrcweir return aTypeName; 431cdf0e10cSrcweir } 432cdf0e10cSrcweir 433cdf0e10cSrcweir SFX_IMPL_SINGLEFACTORY( SwFilterDetect ) 434cdf0e10cSrcweir 435cdf0e10cSrcweir /* XServiceInfo */ 436cdf0e10cSrcweir UNOOUSTRING SAL_CALL SwFilterDetect::getImplementationName() throw( UNORUNTIMEEXCEPTION ) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir return impl_getStaticImplementationName(); 439cdf0e10cSrcweir } 440cdf0e10cSrcweir \ 441cdf0e10cSrcweir /* XServiceInfo */ 442cdf0e10cSrcweir sal_Bool SAL_CALL SwFilterDetect::supportsService( const UNOOUSTRING& sServiceName ) throw( UNORUNTIMEEXCEPTION ) 443cdf0e10cSrcweir { 444cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > seqServiceNames = getSupportedServiceNames(); 445cdf0e10cSrcweir const UNOOUSTRING* pArray = seqServiceNames.getConstArray(); 446cdf0e10cSrcweir for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ ) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir if ( pArray[nCounter] == sServiceName ) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir return sal_True ; 451cdf0e10cSrcweir } 452cdf0e10cSrcweir } 453cdf0e10cSrcweir return sal_False ; 454cdf0e10cSrcweir } 455cdf0e10cSrcweir 456cdf0e10cSrcweir /* XServiceInfo */ 457cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > SAL_CALL SwFilterDetect::getSupportedServiceNames() throw( UNORUNTIMEEXCEPTION ) 458cdf0e10cSrcweir { 459cdf0e10cSrcweir return impl_getStaticSupportedServiceNames(); 460cdf0e10cSrcweir } 461cdf0e10cSrcweir 462cdf0e10cSrcweir /* Helper for XServiceInfo */ 463cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > SwFilterDetect::impl_getStaticSupportedServiceNames() 464cdf0e10cSrcweir { 465cdf0e10cSrcweir UNOMUTEXGUARD aGuard( UNOMUTEX::getGlobalMutex() ); 466cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > seqServiceNames( 3 ); 467cdf0e10cSrcweir seqServiceNames.getArray() [0] = UNOOUSTRING::createFromAscii( "com.sun.star.frame.ExtendedTypeDetection" ); 468cdf0e10cSrcweir seqServiceNames.getArray() [1] = UNOOUSTRING::createFromAscii( "com.sun.star.text.FormatDetector" ); 469cdf0e10cSrcweir seqServiceNames.getArray() [2] = UNOOUSTRING::createFromAscii( "com.sun.star.text.W4WFormatDetector" ); 470cdf0e10cSrcweir return seqServiceNames ; 471cdf0e10cSrcweir } 472cdf0e10cSrcweir 473cdf0e10cSrcweir /* Helper for XServiceInfo */ 474cdf0e10cSrcweir UNOOUSTRING SwFilterDetect::impl_getStaticImplementationName() 475cdf0e10cSrcweir { 476cdf0e10cSrcweir return UNOOUSTRING::createFromAscii( "com.sun.star.comp.writer.FormatDetector" ); 477cdf0e10cSrcweir } 478cdf0e10cSrcweir 479cdf0e10cSrcweir /* Helper for registry */ 480cdf0e10cSrcweir UNOREFERENCE< UNOXINTERFACE > SAL_CALL SwFilterDetect::impl_createInstance( const UNOREFERENCE< UNOXMULTISERVICEFACTORY >& xServiceManager ) throw( UNOEXCEPTION ) 481cdf0e10cSrcweir { 482cdf0e10cSrcweir return UNOREFERENCE< UNOXINTERFACE >( *new SwFilterDetect( xServiceManager ) ); 483cdf0e10cSrcweir } 484cdf0e10cSrcweir 485