1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docfilt.cxx,v $
10 * $Revision: 1.23.142.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 // INCLUDE ---------------------------------------------------------------
37 // HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
41 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
42 #include <sot/exchange.hxx>
43 #include <comphelper/processfactory.hxx>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/container/XNameAccess.hpp>
47 #include <sfx2/docfac.hxx>
48 #include <sfx2/docfilt.hxx>
50 #include <sfx2/sfxuno.hxx>
51 #include <sfx2/objsh.hxx>
53 using namespace ::com::sun::star
;
57 // TODO #i105076# this should be in the filter configuration!!!
58 bool CheckMSPasswordCapabilityForExport( const String
& rFilterName
)
61 rFilterName
.EqualsAscii( "MS Word 97" ) ||
62 rFilterName
.EqualsAscii( "MS Word 97 Vorlage" ) ||
63 rFilterName
.EqualsAscii( "MS Excel 97" ) ||
64 rFilterName
.EqualsAscii( "MS Excel 97 Vorlage/Template" );
69 // STATIC DATA -----------------------------------------------------------
73 SfxFilter::SfxFilter( const String
&rName
,
74 const String
&rWildCard
,
79 const String
&rMimeType
,
80 const String
&rUsrDat
,
81 const String
&rServiceName
):
82 aWildCard(rWildCard
, ';'),
88 aServiceName( rServiceName
),
89 aMimeType( rMimeType
),
92 String aExts
= GetWildcard()();
95 sal_uInt16 nMaxLength
= USHRT_MAX
;
98 while( ( aRet
= aExts
.GetToken( nPos
++, ';' ) ).Len() )
101 aTest
.SearchAndReplace( DEFINE_CONST_UNICODE( "*." ), String() );
102 if( aTest
.Len() <= nMaxLength
)
104 if( aShort
.Len() ) aShort
+= ';';
109 if( aLong
.Len() ) aLong
+= ';';
113 if( aShort
.Len() && aLong
.Len() )
120 nVersion
= SOFFICE_FILEFORMAT_50
;
121 aUIName
= aFilterName
;
124 SfxFilter::~SfxFilter()
128 String
SfxFilter::GetDefaultExtension() const
130 return GetWildcard()().GetToken( 0, ';' );
133 String
SfxFilter::GetSuffixes() const
135 String aRet
= GetWildcard()();
136 while( aRet
.SearchAndReplaceAscii( "*.", String() ) != STRING_NOTFOUND
) ;
137 while( aRet
.SearchAndReplace( ';', ',' ) != STRING_NOTFOUND
) ;
141 const SfxFilter
* SfxFilter::GetDefaultFilter( const String
& rName
)
143 return SfxFilterContainer::GetDefaultFilter_Impl( rName
);
146 const SfxFilter
* SfxFilter::GetDefaultFilterFromFactory( const String
& rFact
)
148 return GetDefaultFilter( SfxObjectShell::GetServiceNameFromFactory( rFact
) );
151 const SfxFilter
* SfxFilter::GetFilterByName( const String
& rName
)
153 SfxFilterMatcher aMatch
;
154 return aMatch
.GetFilter4FilterName( rName
, 0, 0 );
157 String
SfxFilter::GetTypeFromStorage( const SotStorage
& rStg
)
160 if ( rStg
.IsStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "WordDocument" ) ) ) )
162 if ( rStg
.IsStream( String::CreateFromAscii("0Table" ) ) || rStg
.IsStream( String::CreateFromAscii("1Table" ) ) )
163 pType
= "writer_MS_Word_97";
165 pType
= "writer_MS_Word_95";
167 else if ( rStg
.IsStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Book" ) ) ) )
169 pType
= "calc_MS_Excel_95";
171 else if ( rStg
.IsStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Workbook" ) ) ) )
173 pType
= "calc_MS_Excel_97";
175 else if ( rStg
.IsStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "PowerPoint Document" ) ) ) )
177 pType
= "impress_MS_PowerPoint_97";
179 else if ( rStg
.IsStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Equation Native" ) ) ) )
181 pType
= "math_MathType_3x";
185 sal_Int32 nClipId
= ((SotStorage
&)rStg
).GetFormat();
188 const SfxFilter
* pFilter
= SfxFilterMatcher().GetFilter4ClipBoardId( nClipId
);
190 return pFilter
->GetTypeName();
194 return pType
? String::CreateFromAscii(pType
) : String();
197 String
SfxFilter::GetTypeFromStorage( const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>& xStorage
, BOOL bTemplate
,
198 String
* pFilterName
)
199 throw ( beans::UnknownPropertyException
,
200 lang::WrappedTargetException
,
201 uno::RuntimeException
)
203 SfxFilterMatcher aMatcher
;
208 aName
= *pFilterName
;
209 pFilterName
->Erase();
212 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySet
> xProps( xStorage
, com::sun::star::uno::UNO_QUERY
);
215 ::rtl::OUString aMediaType
;
216 xProps
->getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) ) >>= aMediaType
;
217 if ( aMediaType
.getLength() )
219 ::com::sun::star::datatransfer::DataFlavor aDataFlavor
;
220 aDataFlavor
.MimeType
= aMediaType
;
221 sal_uInt32 nClipId
= SotExchange::GetFormat( aDataFlavor
);
224 SfxFilterFlags nMust
= SFX_FILTER_IMPORT
, nDont
= SFX_FILTER_NOTINSTALLED
;
226 // template filter was preselected, try to verify
227 nMust
|= SFX_FILTER_TEMPLATEPATH
;
229 // template filters shouldn't be detected if not explicitly asked for
230 nDont
|= SFX_FILTER_TEMPLATEPATH
;
232 const SfxFilter
* pFilter
= 0;
234 // get preselected Filter if it matches the desired filter flags
235 pFilter
= aMatcher
.GetFilter4FilterName( aName
, nMust
, nDont
);
237 if ( !pFilter
|| pFilter
->GetFormat() != nClipId
)
239 // get filter from storage MediaType
240 pFilter
= aMatcher
.GetFilter4ClipBoardId( nClipId
, nMust
, nDont
);
242 // template filter is asked for , but there isn't one; so at least the "normal" format should be detected
243 // or storage *is* a template, but bTemplate is not set
244 pFilter
= aMatcher
.GetFilter4ClipBoardId( nClipId
);
250 *pFilterName
= pFilter
->GetName();
251 return pFilter
->GetTypeName();
257 //TODO: do it without SfxFilter
258 //TODO/LATER: don't yield FilterName, should be done in FWK!
262 aRet
= String::CreateFromAscii(pType
);
264 *pFilterName
= aMatcher
.GetFilter4EA( aRet
)->GetName();