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_sd.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "sddetect.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <framework/interaction.hxx> 34*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp> 40*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 41*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveAppException.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/packages/zip/ZipIOException.hpp> 50*cdf0e10cSrcweir #include <framework/interaction.hxx> 51*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 52*cdf0e10cSrcweir #include <ucbhelper/simpleinteractionrequest.hxx> 53*cdf0e10cSrcweir #include <svtools/filter.hxx> 54*cdf0e10cSrcweir #include <rtl/ustring.h> 55*cdf0e10cSrcweir #include <rtl/logfile.hxx> 56*cdf0e10cSrcweir #include <svl/itemset.hxx> 57*cdf0e10cSrcweir #include <vcl/window.hxx> 58*cdf0e10cSrcweir #include <svl/eitem.hxx> 59*cdf0e10cSrcweir #include <svl/stritem.hxx> 60*cdf0e10cSrcweir #include <tools/urlobj.hxx> 61*cdf0e10cSrcweir #include <vos/mutex.hxx> 62*cdf0e10cSrcweir #include <svtools/sfxecode.hxx> 63*cdf0e10cSrcweir #include <svtools/ehdl.hxx> 64*cdf0e10cSrcweir #include <sot/storinfo.hxx> 65*cdf0e10cSrcweir #include <vcl/svapp.hxx> 66*cdf0e10cSrcweir #include <sfx2/app.hxx> 67*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc> 68*cdf0e10cSrcweir #include <sfx2/request.hxx> 69*cdf0e10cSrcweir #include <sfx2/docfile.hxx> 70*cdf0e10cSrcweir #include <sfx2/docfilt.hxx> 71*cdf0e10cSrcweir #include <sfx2/fcontnr.hxx> 72*cdf0e10cSrcweir #include <sfx2/brokenpackageint.hxx> 73*cdf0e10cSrcweir #include <svtools/FilterConfigItem.hxx> 74*cdf0e10cSrcweir #include <sot/storage.hxx> 75*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx> 76*cdf0e10cSrcweir #include <com/sun/star/util/XArchiver.hpp> 77*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir #include "strmname.h" 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir using namespace ::com::sun::star; 82*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 83*cdf0e10cSrcweir using namespace ::com::sun::star::io; 84*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 85*cdf0e10cSrcweir using namespace ::com::sun::star::task; 86*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 87*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 88*cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 89*cdf0e10cSrcweir using namespace ::rtl; 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir SdFilterDetect::SdFilterDetect( const REFERENCE < ::com::sun::star::lang::XMultiServiceFactory >& ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir SdFilterDetect::~SdFilterDetect() 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir ::rtl::OUString SAL_CALL SdFilterDetect::detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lDescriptor ) throw( ::com::sun::star::uno::RuntimeException ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir REFERENCE< XInputStream > xStream; 102*cdf0e10cSrcweir REFERENCE< XContent > xContent; 103*cdf0e10cSrcweir REFERENCE< XInteractionHandler > xInteraction; 104*cdf0e10cSrcweir String aURL; 105*cdf0e10cSrcweir ::rtl::OUString sTemp; 106*cdf0e10cSrcweir String aTypeName; // a name describing the type (from MediaDescriptor, usually from flat detection) 107*cdf0e10cSrcweir String aPreselectedFilterName; // a name describing the filter to use (from MediaDescriptor, usually from UI action) 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir ::rtl::OUString aDocumentTitle; // interesting only if set in this method 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // opening as template is done when a parameter tells to do so and a template filter can be detected 112*cdf0e10cSrcweir // (otherwise no valid filter would be found) or if the detected filter is a template filter and 113*cdf0e10cSrcweir // there is no parameter that forbids to open as template 114*cdf0e10cSrcweir sal_Bool bOpenAsTemplate = sal_False; 115*cdf0e10cSrcweir sal_Bool bWasReadOnly = sal_False, bReadOnly = sal_False; 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir sal_Bool bRepairPackage = sal_False; 118*cdf0e10cSrcweir sal_Bool bRepairAllowed = sal_False; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // now some parameters that can already be in the array, but may be overwritten or new inserted here 121*cdf0e10cSrcweir // remember their indices in the case new values must be added to the array 122*cdf0e10cSrcweir sal_Int32 nPropertyCount = lDescriptor.getLength(); 123*cdf0e10cSrcweir sal_Int32 nIndexOfFilterName = -1; 124*cdf0e10cSrcweir sal_Int32 nIndexOfInputStream = -1; 125*cdf0e10cSrcweir sal_Int32 nIndexOfContent = -1; 126*cdf0e10cSrcweir sal_Int32 nIndexOfReadOnlyFlag = -1; 127*cdf0e10cSrcweir sal_Int32 nIndexOfTemplateFlag = -1; 128*cdf0e10cSrcweir sal_Int32 nIndexOfDocumentTitle = -1; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir // extract properties 133*cdf0e10cSrcweir if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("URL")) ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= sTemp; 136*cdf0e10cSrcweir aURL = sTemp; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir else if( !aURL.Len() && lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("FileName")) ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= sTemp; 141*cdf0e10cSrcweir aURL = sTemp; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("TypeName")) ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= sTemp; 146*cdf0e10cSrcweir aTypeName = sTemp; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("FilterName")) ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= sTemp; 151*cdf0e10cSrcweir aPreselectedFilterName = sTemp; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // if the preselected filter name is not correct, it must be erased after detection 154*cdf0e10cSrcweir // remember index of property to get access to it later 155*cdf0e10cSrcweir nIndexOfFilterName = nProperty; 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("InputStream")) ) 158*cdf0e10cSrcweir nIndexOfInputStream = nProperty; 159*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")) ) 160*cdf0e10cSrcweir nIndexOfReadOnlyFlag = nProperty; 161*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("UCBContent")) ) 162*cdf0e10cSrcweir nIndexOfContent = nProperty; 163*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("AsTemplate")) ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= bOpenAsTemplate; 166*cdf0e10cSrcweir nIndexOfTemplateFlag = nProperty; 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("InteractionHandler")) ) 169*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= xInteraction; 170*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("RepairPackage")) ) 171*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= bRepairPackage; 172*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("DocumentTitle")) ) 173*cdf0e10cSrcweir nIndexOfDocumentTitle = nProperty; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir // can't check the type for external filters, so set the "dont" flag accordingly 177*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 178*cdf0e10cSrcweir //SfxFilterFlags nMust = SFX_FILTER_IMPORT, nDont = SFX_FILTER_NOTINSTALLED; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir SfxApplication* pApp = SFX_APP(); 181*cdf0e10cSrcweir SfxAllItemSet *pSet = new SfxAllItemSet( pApp->GetPool() ); 182*cdf0e10cSrcweir TransformParameters( SID_OPENDOC, lDescriptor, *pSet ); 183*cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pItem, SfxBoolItem, SID_DOC_READONLY, sal_False ); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir bWasReadOnly = pItem && pItem->GetValue(); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir const SfxFilter* pFilter = 0; 188*cdf0e10cSrcweir String aFilterName; 189*cdf0e10cSrcweir String aPrefix = String::CreateFromAscii( "private:factory/" ); 190*cdf0e10cSrcweir if( aURL.Match( aPrefix ) == aPrefix.Len() ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir if( SvtModuleOptions().IsImpress() ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir String aPattern( aPrefix ); 195*cdf0e10cSrcweir aPattern += String::CreateFromAscii("simpress"); 196*cdf0e10cSrcweir if ( aURL.Match( aPattern ) >= aPattern.Len() ) 197*cdf0e10cSrcweir pFilter = SfxFilter::GetDefaultFilterFromFactory( aURL ); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir if( !pFilter && SvtModuleOptions().IsDraw() ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir String aPattern( aPrefix ); 203*cdf0e10cSrcweir aPattern += String::CreateFromAscii("sdraw"); 204*cdf0e10cSrcweir if ( aURL.Match( aPattern ) >= aPattern.Len() ) 205*cdf0e10cSrcweir pFilter = SfxFilter::GetDefaultFilterFromFactory( aURL ); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir else 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir // ctor of SfxMedium uses owner transition of ItemSet 211*cdf0e10cSrcweir SfxMedium aMedium( aURL, bWasReadOnly ? STREAM_STD_READ : STREAM_STD_READWRITE, sal_False, NULL, pSet ); 212*cdf0e10cSrcweir aMedium.UseInteractionHandler( sal_True ); 213*cdf0e10cSrcweir if ( aPreselectedFilterName.Len() ) 214*cdf0e10cSrcweir pFilter = SfxFilter::GetFilterByName( aPreselectedFilterName ); 215*cdf0e10cSrcweir else if( aTypeName.Len() ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir SfxFilterMatcher aMatch; 218*cdf0e10cSrcweir pFilter = aMatch.GetFilter4EA( aTypeName ); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir if ( aMedium.GetErrorCode() == ERRCODE_NONE ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir // remember input stream and content and put them into the descriptor later 224*cdf0e10cSrcweir // should be done here since later the medium can switch to a version 225*cdf0e10cSrcweir xStream = aMedium.GetInputStream(); 226*cdf0e10cSrcweir xContent = aMedium.GetContent(); 227*cdf0e10cSrcweir bReadOnly = aMedium.IsReadOnly(); 228*cdf0e10cSrcweir sal_Bool bIsStorage = aMedium.IsStorage(); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir if (aMedium.GetError() == SVSTREAM_OK) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir if ( bIsStorage ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir // PowerPoint needs to be detected via StreamName, all other storage based formats are our own and can 235*cdf0e10cSrcweir // be detected by the ClipboardId, so except for the PPT filter all filters must have a ClipboardId set 236*cdf0e10cSrcweir uno::Reference < embed::XStorage > xStorage = aMedium.GetStorage( sal_False ); 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir //TODO/LATER: move error handling to central place! (maybe even complete own filters) 239*cdf0e10cSrcweir if ( aMedium.GetLastStorageCreationState() != ERRCODE_NONE ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir // error during storage creation means _here_ that the medium 242*cdf0e10cSrcweir // is broken, but we can not handle it in medium since unpossibility 243*cdf0e10cSrcweir // to create a storage does not _always_ means that the medium is broken 244*cdf0e10cSrcweir aMedium.SetError( aMedium.GetLastStorageCreationState(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 245*cdf0e10cSrcweir if ( xInteraction.is() ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir OUString empty; 248*cdf0e10cSrcweir try 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir InteractiveAppException xException( empty, 251*cdf0e10cSrcweir REFERENCE< XInterface >(), 252*cdf0e10cSrcweir InteractionClassification_ERROR, 253*cdf0e10cSrcweir aMedium.GetError() ); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir REFERENCE< XInteractionRequest > xRequest( 256*cdf0e10cSrcweir new ucbhelper::SimpleInteractionRequest( makeAny( xException ), 257*cdf0e10cSrcweir ucbhelper::CONTINUATION_APPROVE ) ); 258*cdf0e10cSrcweir xInteraction->handle( xRequest ); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir catch ( Exception & ) {}; 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir else 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir if ( pFilter && !pFilter->GetFormat() ) 266*cdf0e10cSrcweir // preselected Filter has no ClipboardId -> doesn't match (see comment above) 267*cdf0e10cSrcweir pFilter = 0; 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir // the storage must be checked even if filter is already found, since it is deep type detection 270*cdf0e10cSrcweir // the storage can be corrupted and it will be detected here 271*cdf0e10cSrcweir try 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir String sFilterName; 274*cdf0e10cSrcweir if ( pFilter ) 275*cdf0e10cSrcweir sFilterName = pFilter->GetName(); 276*cdf0e10cSrcweir aTypeName = SfxFilter::GetTypeFromStorage( xStorage, pFilter ? pFilter->IsOwnTemplateFormat() : sal_False, &sFilterName ); 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir catch( lang::WrappedTargetException& aWrap ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir packages::zip::ZipIOException aZipException; 281*cdf0e10cSrcweir if ( ( aWrap.TargetException >>= aZipException ) && aTypeName.Len() ) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir if ( xInteraction.is() ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir // the package is broken one 286*cdf0e10cSrcweir aDocumentTitle = aMedium.GetURLObject().getName( 287*cdf0e10cSrcweir INetURLObject::LAST_SEGMENT, 288*cdf0e10cSrcweir true, 289*cdf0e10cSrcweir INetURLObject::DECODE_WITH_CHARSET ); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir if ( !bRepairPackage ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir // ask the user whether he wants to try to repair 294*cdf0e10cSrcweir RequestPackageReparation aRequest( aDocumentTitle ); 295*cdf0e10cSrcweir xInteraction->handle( aRequest.GetRequest() ); 296*cdf0e10cSrcweir bRepairAllowed = aRequest.isApproved(); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir if ( !bRepairAllowed ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir // repair either not allowed or not successful 302*cdf0e10cSrcweir NotifyBrokenPackage aNotifyRequest( aDocumentTitle ); 303*cdf0e10cSrcweir xInteraction->handle( aNotifyRequest.GetRequest() ); 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir if ( !bRepairAllowed ) 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir aTypeName.Erase(); 310*cdf0e10cSrcweir pFilter = 0; 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir catch( uno::RuntimeException& ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir throw; 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir catch( uno::Exception& ) 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir aTypeName.Erase(); 321*cdf0e10cSrcweir pFilter = 0; 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir if ( !pFilter && aTypeName.Len() ) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir //TODO/LATER: using this method impress is always preferred if no flat detecion has been made 327*cdf0e10cSrcweir // this should been discussed! 328*cdf0e10cSrcweir if ( SvtModuleOptions().IsImpress() ) 329*cdf0e10cSrcweir pFilter = SfxFilterMatcher( String::CreateFromAscii("simpress") ).GetFilter4EA( aTypeName ); 330*cdf0e10cSrcweir else if ( SvtModuleOptions().IsDraw() ) 331*cdf0e10cSrcweir pFilter = SfxFilterMatcher( String::CreateFromAscii("sdraw") ).GetFilter4EA( aTypeName ); 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir else 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir SvStream* pStm = aMedium.GetInStream(); 338*cdf0e10cSrcweir if ( !pStm ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir pFilter = 0; 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir else 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir SotStorageRef aStorage = new SotStorage ( pStm, sal_False ); 345*cdf0e10cSrcweir if ( !aStorage->GetError() ) 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir String aStreamName = UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "PowerPoint Document" ) ); 348*cdf0e10cSrcweir if ( aStorage->IsStream( aStreamName ) && SvtModuleOptions().IsImpress() ) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir String aFileName(aMedium.GetName()); 351*cdf0e10cSrcweir aFileName.ToUpperAscii(); 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir if( aFileName.SearchAscii( ".POT" ) == STRING_NOTFOUND ) 354*cdf0e10cSrcweir pFilter = SfxFilter::GetFilterByName( pFilterPowerPoint97); 355*cdf0e10cSrcweir else 356*cdf0e10cSrcweir pFilter = SfxFilter::GetFilterByName( pFilterPowerPoint97Template ); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir else 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir // Vektorgraphik? 362*cdf0e10cSrcweir pStm->Seek( STREAM_SEEK_TO_BEGIN ); 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir const String aFileName( aMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ); 365*cdf0e10cSrcweir GraphicDescriptor aDesc( *pStm, &aFileName ); 366*cdf0e10cSrcweir GraphicFilter* pGrfFilter = GraphicFilter::GetGraphicFilter(); 367*cdf0e10cSrcweir if( !aDesc.Detect( sal_False ) ) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir pFilter = 0; 370*cdf0e10cSrcweir if( SvtModuleOptions().IsImpress() ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir INetURLObject aCheckURL( aFileName ); 373*cdf0e10cSrcweir if( aCheckURL.getExtension().equalsIgnoreAsciiCaseAscii( "cgm" ) ) 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir sal_uInt8 n8; 376*cdf0e10cSrcweir pStm->Seek( STREAM_SEEK_TO_BEGIN ); 377*cdf0e10cSrcweir *pStm >> n8; 378*cdf0e10cSrcweir if ( ( n8 & 0xf0 ) == 0 ) // we are supporting binary cgm format only, so 379*cdf0e10cSrcweir { // this is a small test to exclude cgm text 380*cdf0e10cSrcweir const String aName = UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "CGM - Computer Graphics Metafile" ) ); 381*cdf0e10cSrcweir SfxFilterMatcher aMatch( String::CreateFromAscii("simpress") ); 382*cdf0e10cSrcweir pFilter = aMatch.GetFilter4FilterName( aName ); 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir else 388*cdf0e10cSrcweir { 389*cdf0e10cSrcweir String aShortName( aDesc.GetImportFormatShortName( aDesc.GetFileFormat() ) ); 390*cdf0e10cSrcweir const String aName( pGrfFilter->GetImportFormatTypeName( pGrfFilter->GetImportFormatNumberForShortName( aShortName ) ) ); 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir if ( pFilter && aShortName.EqualsIgnoreCaseAscii( "PCD" ) ) // there is a multiple pcd selection possible 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir sal_Int32 nBase = 2; // default Base0 395*cdf0e10cSrcweir String aFilterTypeName( pFilter->GetRealTypeName() ); 396*cdf0e10cSrcweir if ( aFilterTypeName.CompareToAscii( "pcd_Photo_CD_Base4" ) == COMPARE_EQUAL ) 397*cdf0e10cSrcweir nBase = 1; 398*cdf0e10cSrcweir else if ( aFilterTypeName.CompareToAscii( "pcd_Photo_CD_Base16" ) == COMPARE_EQUAL ) 399*cdf0e10cSrcweir nBase = 0; 400*cdf0e10cSrcweir String aFilterConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/Graphic/Import/PCD" ) ); 401*cdf0e10cSrcweir FilterConfigItem aFilterConfigItem( aFilterConfigPath ); 402*cdf0e10cSrcweir aFilterConfigItem.WriteInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Resolution" ) ), nBase ); 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir SfxFilterMatcher aMatch( String::CreateFromAscii("sdraw") ); 406*cdf0e10cSrcweir pFilter = aMatch.GetFilter4FilterName( aName ); 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir if ( nIndexOfInputStream == -1 && xStream.is() ) 416*cdf0e10cSrcweir { 417*cdf0e10cSrcweir // if input stream wasn't part of the descriptor, now it should be, otherwise the content would be opend twice 418*cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 419*cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("InputStream"); 420*cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= xStream; 421*cdf0e10cSrcweir nPropertyCount++; 422*cdf0e10cSrcweir } 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir if ( nIndexOfContent == -1 && xContent.is() ) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir // if input stream wasn't part of the descriptor, now it should be, otherwise the content would be opend twice 427*cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 428*cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("UCBContent"); 429*cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= xContent; 430*cdf0e10cSrcweir nPropertyCount++; 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir if ( bReadOnly != bWasReadOnly ) 434*cdf0e10cSrcweir { 435*cdf0e10cSrcweir if ( nIndexOfReadOnlyFlag == -1 ) 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 438*cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("ReadOnly"); 439*cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= bReadOnly; 440*cdf0e10cSrcweir nPropertyCount++; 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir else 443*cdf0e10cSrcweir lDescriptor[nIndexOfReadOnlyFlag].Value <<= bReadOnly; 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir if ( !bRepairPackage && bRepairAllowed ) 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 449*cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("RepairPackage"); 450*cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= bRepairAllowed; 451*cdf0e10cSrcweir nPropertyCount++; 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir bOpenAsTemplate = sal_True; 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir // TODO/LATER: set progress bar that should be used 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir if ( bOpenAsTemplate ) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir if ( nIndexOfTemplateFlag == -1 ) 461*cdf0e10cSrcweir { 462*cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 463*cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("AsTemplate"); 464*cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= bOpenAsTemplate; 465*cdf0e10cSrcweir nPropertyCount++; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir else 468*cdf0e10cSrcweir lDescriptor[nIndexOfTemplateFlag].Value <<= bOpenAsTemplate; 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir if ( aDocumentTitle.getLength() ) 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir // the title was set here 474*cdf0e10cSrcweir if ( nIndexOfDocumentTitle == -1 ) 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 477*cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("DocumentTitle"); 478*cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= aDocumentTitle; 479*cdf0e10cSrcweir nPropertyCount++; 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir else 482*cdf0e10cSrcweir lDescriptor[nIndexOfDocumentTitle].Value <<= aDocumentTitle; 483*cdf0e10cSrcweir } 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir if ( pFilter ) 486*cdf0e10cSrcweir aTypeName = pFilter->GetTypeName(); 487*cdf0e10cSrcweir else 488*cdf0e10cSrcweir aTypeName.Erase(); 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir return aTypeName; 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir SFX_IMPL_SINGLEFACTORY( SdFilterDetect ) 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir /* XServiceInfo */ 496*cdf0e10cSrcweir UNOOUSTRING SAL_CALL SdFilterDetect::getImplementationName() throw( UNORUNTIMEEXCEPTION ) 497*cdf0e10cSrcweir { 498*cdf0e10cSrcweir return impl_getStaticImplementationName(); 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir \ 501*cdf0e10cSrcweir /* XServiceInfo */ 502*cdf0e10cSrcweir sal_Bool SAL_CALL SdFilterDetect::supportsService( const UNOOUSTRING& sServiceName ) throw( UNORUNTIMEEXCEPTION ) 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > seqServiceNames = getSupportedServiceNames(); 505*cdf0e10cSrcweir const UNOOUSTRING* pArray = seqServiceNames.getConstArray(); 506*cdf0e10cSrcweir for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ ) 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir if ( pArray[nCounter] == sServiceName ) 509*cdf0e10cSrcweir { 510*cdf0e10cSrcweir return sal_True ; 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir return sal_False ; 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir /* XServiceInfo */ 517*cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > SAL_CALL SdFilterDetect::getSupportedServiceNames() throw( UNORUNTIMEEXCEPTION ) 518*cdf0e10cSrcweir { 519*cdf0e10cSrcweir return impl_getStaticSupportedServiceNames(); 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir /* Helper for XServiceInfo */ 523*cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > SdFilterDetect::impl_getStaticSupportedServiceNames() 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir UNOMUTEXGUARD aGuard( UNOMUTEX::getGlobalMutex() ); 526*cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > seqServiceNames( 1 ); 527*cdf0e10cSrcweir seqServiceNames.getArray() [0] = UNOOUSTRING::createFromAscii( "com.sun.star.frame.ExtendedTypeDetection" ); 528*cdf0e10cSrcweir return seqServiceNames ; 529*cdf0e10cSrcweir } 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir /* Helper for XServiceInfo */ 532*cdf0e10cSrcweir UNOOUSTRING SdFilterDetect::impl_getStaticImplementationName() 533*cdf0e10cSrcweir { 534*cdf0e10cSrcweir return UNOOUSTRING::createFromAscii( "com.sun.star.comp.draw.FormatDetector" ); 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir /* Helper for registry */ 538*cdf0e10cSrcweir UNOREFERENCE< UNOXINTERFACE > SAL_CALL SdFilterDetect::impl_createInstance( const UNOREFERENCE< UNOXMULTISERVICEFACTORY >& xServiceManager ) throw( UNOEXCEPTION ) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir return UNOREFERENCE< UNOXINTERFACE >( *new SdFilterDetect( xServiceManager ) ); 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir 543