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