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_starmath.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "smdetect.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 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX 41*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveAppException.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/packages/zip/ZipIOException.hpp> 51*cdf0e10cSrcweir #include <framework/interaction.hxx> 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #ifndef _TOOLKIT_UNOHLP_HXX 54*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 55*cdf0e10cSrcweir #endif 56*cdf0e10cSrcweir #include <ucbhelper/simpleinteractionrequest.hxx> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #include <rtl/ustring.h> 59*cdf0e10cSrcweir #include <rtl/logfile.hxx> 60*cdf0e10cSrcweir #include <svl/itemset.hxx> 61*cdf0e10cSrcweir #include <vcl/window.hxx> 62*cdf0e10cSrcweir #include <svl/eitem.hxx> 63*cdf0e10cSrcweir #include <svl/stritem.hxx> 64*cdf0e10cSrcweir #include <tools/urlobj.hxx> 65*cdf0e10cSrcweir #include <vos/mutex.hxx> 66*cdf0e10cSrcweir #include <svtools/sfxecode.hxx> 67*cdf0e10cSrcweir #include <svtools/ehdl.hxx> 68*cdf0e10cSrcweir #include <sot/storinfo.hxx> 69*cdf0e10cSrcweir #include <vcl/svapp.hxx> 70*cdf0e10cSrcweir #include <sfx2/app.hxx> 71*cdf0e10cSrcweir #include <sfx2/sfxsids.hrc> 72*cdf0e10cSrcweir #include <sfx2/request.hxx> 73*cdf0e10cSrcweir #include <sfx2/docfile.hxx> 74*cdf0e10cSrcweir #include <sfx2/docfilt.hxx> 75*cdf0e10cSrcweir #include <sfx2/fcontnr.hxx> 76*cdf0e10cSrcweir #include <sfx2/brokenpackageint.hxx> 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir #include "document.hxx" 79*cdf0e10cSrcweir #include "eqnolefilehdr.hxx" 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir using namespace ::com::sun::star; 83*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 84*cdf0e10cSrcweir using namespace ::com::sun::star::io; 85*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 86*cdf0e10cSrcweir using namespace ::com::sun::star::task; 87*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 88*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 89*cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 90*cdf0e10cSrcweir using namespace ::rtl; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir SmFilterDetect::SmFilterDetect( const REFERENCE < ::com::sun::star::lang::XMultiServiceFactory >& /*xFactory*/ ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir SmFilterDetect::~SmFilterDetect() 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir ::rtl::OUString SAL_CALL SmFilterDetect::detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lDescriptor ) throw( ::com::sun::star::uno::RuntimeException ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir REFERENCE< XInputStream > xStream; 103*cdf0e10cSrcweir REFERENCE< XContent > xContent; 104*cdf0e10cSrcweir REFERENCE< XInteractionHandler > xInteraction; 105*cdf0e10cSrcweir String aURL; 106*cdf0e10cSrcweir ::rtl::OUString sTemp; 107*cdf0e10cSrcweir String aTypeName; // a name describing the type (from MediaDescriptor, usually from flat detection) 108*cdf0e10cSrcweir String aPreselectedFilterName; // a name describing the filter to use (from MediaDescriptor, usually from UI action) 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir ::rtl::OUString aDocumentTitle; // interesting only if set in this method 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir // opening as template is done when a parameter tells to do so and a template filter can be detected 113*cdf0e10cSrcweir // (otherwise no valid filter would be found) or if the detected filter is a template filter and 114*cdf0e10cSrcweir // there is no parameter that forbids to open as template 115*cdf0e10cSrcweir sal_Bool bOpenAsTemplate = sal_False; 116*cdf0e10cSrcweir sal_Bool bWasReadOnly = sal_False, bReadOnly = sal_False; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir sal_Bool bRepairPackage = sal_False; 119*cdf0e10cSrcweir sal_Bool bRepairAllowed = sal_False; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // now some parameters that can already be in the array, but may be overwritten or new inserted here 122*cdf0e10cSrcweir // remember their indices in the case new values must be added to the array 123*cdf0e10cSrcweir sal_Int32 nPropertyCount = lDescriptor.getLength(); 124*cdf0e10cSrcweir sal_Int32 nIndexOfFilterName = -1; 125*cdf0e10cSrcweir sal_Int32 nIndexOfInputStream = -1; 126*cdf0e10cSrcweir sal_Int32 nIndexOfContent = -1; 127*cdf0e10cSrcweir sal_Int32 nIndexOfReadOnlyFlag = -1; 128*cdf0e10cSrcweir sal_Int32 nIndexOfTemplateFlag = -1; 129*cdf0e10cSrcweir sal_Int32 nIndexOfDocumentTitle = -1; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty ) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir // extract properties 134*cdf0e10cSrcweir if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("URL")) ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= sTemp; 137*cdf0e10cSrcweir aURL = sTemp; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir else if( !aURL.Len() && lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("FileName")) ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= sTemp; 142*cdf0e10cSrcweir aURL = sTemp; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("TypeName")) ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= sTemp; 147*cdf0e10cSrcweir aTypeName = sTemp; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("FilterName")) ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= sTemp; 152*cdf0e10cSrcweir aPreselectedFilterName = sTemp; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // if the preselected filter name is not correct, it must be erased after detection 155*cdf0e10cSrcweir // remember index of property to get access to it later 156*cdf0e10cSrcweir nIndexOfFilterName = nProperty; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("InputStream")) ) 159*cdf0e10cSrcweir nIndexOfInputStream = nProperty; 160*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")) ) 161*cdf0e10cSrcweir nIndexOfReadOnlyFlag = nProperty; 162*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("UCBContent")) ) 163*cdf0e10cSrcweir nIndexOfContent = nProperty; 164*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("AsTemplate")) ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= bOpenAsTemplate; 167*cdf0e10cSrcweir nIndexOfTemplateFlag = nProperty; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("InteractionHandler")) ) 170*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= xInteraction; 171*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("RepairPackage")) ) 172*cdf0e10cSrcweir lDescriptor[nProperty].Value >>= bRepairPackage; 173*cdf0e10cSrcweir else if( lDescriptor[nProperty].Name == OUString(RTL_CONSTASCII_USTRINGPARAM("DocumentTitle")) ) 174*cdf0e10cSrcweir nIndexOfDocumentTitle = nProperty; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir // can't check the type for external filters, so set the "dont" flag accordingly 178*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 179*cdf0e10cSrcweir //SfxFilterFlags nMust = SFX_FILTER_IMPORT, nDont = SFX_FILTER_NOTINSTALLED; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir SfxApplication* pApp = SFX_APP(); 182*cdf0e10cSrcweir SfxAllItemSet *pSet = new SfxAllItemSet( pApp->GetPool() ); 183*cdf0e10cSrcweir TransformParameters( SID_OPENDOC, lDescriptor, *pSet ); 184*cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pItem, SfxBoolItem, SID_DOC_READONLY, sal_False ); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir bWasReadOnly = pItem && pItem->GetValue(); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir String aFilterName; 189*cdf0e10cSrcweir String aPrefix = String::CreateFromAscii( "private:factory/" ); 190*cdf0e10cSrcweir if( aURL.Match( aPrefix ) == aPrefix.Len() ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir const SfxFilter* pFilter = 0; 193*cdf0e10cSrcweir String aPattern( aPrefix ); 194*cdf0e10cSrcweir aPattern += String::CreateFromAscii("smath"); 195*cdf0e10cSrcweir if ( aURL.Match( aPattern ) >= aPattern.Len() ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir pFilter = SfxFilter::GetDefaultFilterFromFactory( aURL ); 198*cdf0e10cSrcweir aTypeName = pFilter->GetTypeName(); 199*cdf0e10cSrcweir aFilterName = pFilter->GetName(); 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir else 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir // ctor of SfxMedium uses owner transition of ItemSet 205*cdf0e10cSrcweir SfxMedium aMedium( aURL, bWasReadOnly ? STREAM_STD_READ : STREAM_STD_READWRITE, sal_False, NULL, pSet ); 206*cdf0e10cSrcweir aMedium.UseInteractionHandler( sal_True ); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir sal_Bool bIsStorage = aMedium.IsStorage(); 209*cdf0e10cSrcweir if ( aMedium.GetErrorCode() == ERRCODE_NONE ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir // remember input stream and content and put them into the descriptor later 212*cdf0e10cSrcweir // should be done here since later the medium can switch to a version 213*cdf0e10cSrcweir xStream = aMedium.GetInputStream(); 214*cdf0e10cSrcweir xContent = aMedium.GetContent(); 215*cdf0e10cSrcweir bReadOnly = aMedium.IsReadOnly(); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir if ( bIsStorage ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir //TODO/LATER: factor this out! 220*cdf0e10cSrcweir uno::Reference < embed::XStorage > xStorage = aMedium.GetStorage( sal_False ); 221*cdf0e10cSrcweir if ( aMedium.GetLastStorageCreationState() != ERRCODE_NONE ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir // error during storage creation means _here_ that the medium 224*cdf0e10cSrcweir // is broken, but we can not handle it in medium since unpossibility 225*cdf0e10cSrcweir // to create a storage does not _always_ means that the medium is broken 226*cdf0e10cSrcweir aMedium.SetError( aMedium.GetLastStorageCreationState(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 227*cdf0e10cSrcweir if ( xInteraction.is() ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir OUString empty; 230*cdf0e10cSrcweir try 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir InteractiveAppException xException( empty, 233*cdf0e10cSrcweir REFERENCE< XInterface >(), 234*cdf0e10cSrcweir InteractionClassification_ERROR, 235*cdf0e10cSrcweir aMedium.GetError() ); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir REFERENCE< XInteractionRequest > xRequest( 238*cdf0e10cSrcweir new ucbhelper::SimpleInteractionRequest( makeAny( xException ), 239*cdf0e10cSrcweir ucbhelper::CONTINUATION_APPROVE ) ); 240*cdf0e10cSrcweir xInteraction->handle( xRequest ); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir catch ( Exception & ) {}; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir else 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir aFilterName.Erase(); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir try 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir const SfxFilter* pFilter = aPreselectedFilterName.Len() ? 252*cdf0e10cSrcweir SfxFilterMatcher().GetFilter4FilterName( aPreselectedFilterName ) : aTypeName.Len() ? 253*cdf0e10cSrcweir SfxFilterMatcher(String::CreateFromAscii("smath")).GetFilter4EA( aTypeName ) : 0; 254*cdf0e10cSrcweir String aTmpFilterName; 255*cdf0e10cSrcweir if ( pFilter ) 256*cdf0e10cSrcweir aTmpFilterName = pFilter->GetName(); 257*cdf0e10cSrcweir aTypeName = SfxFilter::GetTypeFromStorage( xStorage, pFilter ? pFilter->IsAllowedAsTemplate() : sal_False, &aTmpFilterName ); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir catch( lang::WrappedTargetException& aWrap ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir packages::zip::ZipIOException aZipException; 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir // repairing is done only if this type is requested from outside 264*cdf0e10cSrcweir if ( ( aWrap.TargetException >>= aZipException ) && aTypeName.Len() ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir if ( xInteraction.is() ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir // the package is broken one 269*cdf0e10cSrcweir aDocumentTitle = aMedium.GetURLObject().getName( 270*cdf0e10cSrcweir INetURLObject::LAST_SEGMENT, 271*cdf0e10cSrcweir true, 272*cdf0e10cSrcweir INetURLObject::DECODE_WITH_CHARSET ); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir if ( !bRepairPackage ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir // ask the user whether he wants to try to repair 277*cdf0e10cSrcweir RequestPackageReparation aRequest( aDocumentTitle ); 278*cdf0e10cSrcweir xInteraction->handle( aRequest.GetRequest() ); 279*cdf0e10cSrcweir bRepairAllowed = aRequest.isApproved(); 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir if ( !bRepairAllowed ) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir // repair either not allowed or not successful 285*cdf0e10cSrcweir NotifyBrokenPackage aNotifyRequest( aDocumentTitle ); 286*cdf0e10cSrcweir xInteraction->handle( aNotifyRequest.GetRequest() ); 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir if ( !bRepairAllowed ) 291*cdf0e10cSrcweir aTypeName.Erase(); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir catch( uno::RuntimeException& ) 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir throw; 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir catch( uno::Exception& ) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir aTypeName.Erase(); 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir if ( aTypeName.Len() ) 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir const SfxFilter* pFilter = 306*cdf0e10cSrcweir SfxFilterMatcher( String::CreateFromAscii("smath") ).GetFilter4EA( aTypeName ); 307*cdf0e10cSrcweir if ( pFilter ) 308*cdf0e10cSrcweir aFilterName = pFilter->GetName(); 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir else 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir //Test to see if this begins with xml and if so run it through 315*cdf0e10cSrcweir //the MathML filter. There are all sorts of things wrong with 316*cdf0e10cSrcweir //this approach, to be fixed at a better level than here 317*cdf0e10cSrcweir SvStream *pStrm = aMedium.GetInStream(); 318*cdf0e10cSrcweir aTypeName.Erase(); 319*cdf0e10cSrcweir if (pStrm && !pStrm->GetError()) 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir SotStorageRef aStorage = new SotStorage ( pStrm, sal_False ); 322*cdf0e10cSrcweir if ( !aStorage->GetError() ) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir if ( aStorage->IsStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Equation Native" ) ) ) ) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir sal_uInt8 nVersion; 327*cdf0e10cSrcweir if (GetMathTypeVersion( aStorage, nVersion ) && nVersion <=3) 328*cdf0e10cSrcweir aTypeName.AssignAscii( "math_MathType_3x" ); 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir else 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir const sal_uInt16 nSize = 5; 334*cdf0e10cSrcweir sal_Char aBuffer[nSize+1]; 335*cdf0e10cSrcweir aBuffer[nSize] = 0; 336*cdf0e10cSrcweir pStrm->Seek( STREAM_SEEK_TO_BEGIN ); 337*cdf0e10cSrcweir sal_uLong nBytesRead = pStrm->Read( aBuffer, nSize ); 338*cdf0e10cSrcweir if (nBytesRead == nSize) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir if (0 == strncmp( "<?xml",aBuffer,nSize)) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir static const sal_Char sFltrNm_2[] = MATHML_XML; 343*cdf0e10cSrcweir static const sal_Char sTypeNm_2[] = "math_MathML_XML_Math"; 344*cdf0e10cSrcweir aFilterName.AssignAscii( sFltrNm_2 ); 345*cdf0e10cSrcweir aTypeName.AssignAscii( sTypeNm_2 ); 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir if ( aTypeName.Len() ) 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir const SfxFilter* pFilt = SfxFilterMatcher( String::CreateFromAscii("smath") ).GetFilter4EA( aTypeName ); 353*cdf0e10cSrcweir if ( pFilt ) 354*cdf0e10cSrcweir aFilterName = pFilt->GetName(); 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir if ( nIndexOfInputStream == -1 && xStream.is() ) 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir // if input stream wasn't part of the descriptor, now it should be, otherwise the content would be opend twice 364*cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 365*cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("InputStream"); 366*cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= xStream; 367*cdf0e10cSrcweir nPropertyCount++; 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir if ( nIndexOfContent == -1 && xContent.is() ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir // if input stream wasn't part of the descriptor, now it should be, otherwise the content would be opend twice 373*cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 374*cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("UCBContent"); 375*cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= xContent; 376*cdf0e10cSrcweir nPropertyCount++; 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir if ( bReadOnly != bWasReadOnly ) 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir if ( nIndexOfReadOnlyFlag == -1 ) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 384*cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("ReadOnly"); 385*cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= bReadOnly; 386*cdf0e10cSrcweir nPropertyCount++; 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir else 389*cdf0e10cSrcweir lDescriptor[nIndexOfReadOnlyFlag].Value <<= bReadOnly; 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir if ( !bRepairPackage && bRepairAllowed ) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 395*cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("RepairPackage"); 396*cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= bRepairAllowed; 397*cdf0e10cSrcweir nPropertyCount++; 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir bOpenAsTemplate = sal_True; 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir // TODO/LATER: set progress bar that should be used 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir if ( bOpenAsTemplate ) 405*cdf0e10cSrcweir { 406*cdf0e10cSrcweir if ( nIndexOfTemplateFlag == -1 ) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 409*cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("AsTemplate"); 410*cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= bOpenAsTemplate; 411*cdf0e10cSrcweir nPropertyCount++; 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir else 414*cdf0e10cSrcweir lDescriptor[nIndexOfTemplateFlag].Value <<= bOpenAsTemplate; 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir if ( aDocumentTitle.getLength() ) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir // the title was set here 420*cdf0e10cSrcweir if ( nIndexOfDocumentTitle == -1 ) 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir lDescriptor.realloc( nPropertyCount + 1 ); 423*cdf0e10cSrcweir lDescriptor[nPropertyCount].Name = ::rtl::OUString::createFromAscii("DocumentTitle"); 424*cdf0e10cSrcweir lDescriptor[nPropertyCount].Value <<= aDocumentTitle; 425*cdf0e10cSrcweir nPropertyCount++; 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir else 428*cdf0e10cSrcweir lDescriptor[nIndexOfDocumentTitle].Value <<= aDocumentTitle; 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir if ( !aFilterName.Len() ) 432*cdf0e10cSrcweir aTypeName.Erase(); 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir return aTypeName; 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir SFX_IMPL_SINGLEFACTORY( SmFilterDetect ) 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir /* XServiceInfo */ 440*cdf0e10cSrcweir UNOOUSTRING SAL_CALL SmFilterDetect::getImplementationName() throw( UNORUNTIMEEXCEPTION ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir return impl_getStaticImplementationName(); 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir \ 445*cdf0e10cSrcweir /* XServiceInfo */ 446*cdf0e10cSrcweir sal_Bool SAL_CALL SmFilterDetect::supportsService( const UNOOUSTRING& sServiceName ) throw( UNORUNTIMEEXCEPTION ) 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > seqServiceNames = getSupportedServiceNames(); 449*cdf0e10cSrcweir const UNOOUSTRING* pArray = seqServiceNames.getConstArray(); 450*cdf0e10cSrcweir for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ ) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir if ( pArray[nCounter] == sServiceName ) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir return sal_True ; 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir return sal_False ; 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir /* XServiceInfo */ 461*cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > SAL_CALL SmFilterDetect::getSupportedServiceNames() throw( UNORUNTIMEEXCEPTION ) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir return impl_getStaticSupportedServiceNames(); 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir /* Helper for XServiceInfo */ 467*cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > SmFilterDetect::impl_getStaticSupportedServiceNames() 468*cdf0e10cSrcweir { 469*cdf0e10cSrcweir UNOMUTEXGUARD aGuard( UNOMUTEX::getGlobalMutex() ); 470*cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > seqServiceNames( 1 ); 471*cdf0e10cSrcweir seqServiceNames.getArray() [0] = UNOOUSTRING::createFromAscii( "com.sun.star.frame.ExtendedTypeDetection" ); 472*cdf0e10cSrcweir return seqServiceNames ; 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir /* Helper for XServiceInfo */ 476*cdf0e10cSrcweir UNOOUSTRING SmFilterDetect::impl_getStaticImplementationName() 477*cdf0e10cSrcweir { 478*cdf0e10cSrcweir return UNOOUSTRING::createFromAscii( "com.sun.star.comp.math.FormatDetector" ); 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir /* Helper for registry */ 482*cdf0e10cSrcweir UNOREFERENCE< UNOXINTERFACE > SAL_CALL SmFilterDetect::impl_createInstance( const UNOREFERENCE< UNOXMULTISERVICEFACTORY >& xServiceManager ) throw( UNOEXCEPTION ) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir return UNOREFERENCE< UNOXINTERFACE >( *new SmFilterDetect( xServiceManager ) ); 485*cdf0e10cSrcweir } 486*cdf0e10cSrcweir 487