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