LibreOffice Module sfx2 (master) 1
docfilt.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifdef __sun
21#include <ctime>
22#endif
23
24#include <sot/exchange.hxx>
25#include <sot/storage.hxx>
27#include <com/sun/star/beans/XPropertySet.hpp>
28#include <com/sun/star/embed/XStorage.hpp>
29#include <sfx2/docfilt.hxx>
30#include <sfx2/fcontnr.hxx>
31#include <sfx2/objsh.hxx>
32#include <utility>
33
34using namespace ::com::sun::star;
35
36SfxFilter::SfxFilter( OUString aProvider, OUString aFilterName ) :
37 maFilterName(std::move(aFilterName)),
38 maProvider(std::move(aProvider)),
39 nFormatType(SfxFilterFlags::NONE),
40 nVersion(0),
41 lFormat(SotClipboardFormatId::NONE),
42 mbEnabled(true)
43{
44}
45
46SfxFilter::SfxFilter( OUString aName,
47 std::u16string_view rWildCard,
48 SfxFilterFlags nType,
50 OUString aTypNm,
51 OUString _aMimeType,
52 OUString aUsrDat,
53 OUString _aServiceName,
54 bool bEnabled ):
55 aWildCard(rWildCard, ';'),
56 aTypeName(std::move(aTypNm)),
57 aUserData(std::move(aUsrDat)),
58 aServiceName(std::move(_aServiceName)),
59 aMimeType(std::move(_aMimeType)),
60 maFilterName(std::move(aName)),
61 aUIName(maFilterName),
62 nFormatType(nType),
64 lFormat(lFmt),
65 mbEnabled(bEnabled)
66{
67 const OUString aExts = GetWildcard().getGlob();
68 sal_Int32 nLen{ aExts.getLength() };
69 if (nLen<=0)
70 return;
71
72 // truncate to first empty extension
73 if (aExts[0]==';')
74 {
76 return;
77 }
78 const sal_Int32 nIdx{ aExts.indexOf(";;") };
79 if (nIdx>0)
80 nLen = nIdx;
81 else if (aExts[nLen-1]==';')
82 --nLen;
83 if (nLen<aExts.getLength())
84 aWildCard.setGlob(aExts.subView(0, nLen));
85}
86
88{
89}
90
92{
93 return GetWildcard().getGlob().getToken(0, ';');
94}
95
96
97OUString SfxFilter::GetSuffixes() const
98{
99 OUString aRet = GetWildcard().getGlob();
100 aRet = aRet.replaceAll( "*.", "" );
101 aRet = aRet.replaceAll( ";", "," );
102 return aRet;
103}
104
105std::shared_ptr<const SfxFilter> SfxFilter::GetDefaultFilter( std::u16string_view rName )
106{
108}
109
110std::shared_ptr<const SfxFilter> SfxFilter::GetDefaultFilterFromFactory( const OUString& rFact )
111{
113}
114
115std::shared_ptr<const SfxFilter> SfxFilter::GetFilterByName( const OUString& rName )
116{
117 SfxFilterMatcher aMatch;
118 return aMatch.GetFilter4FilterName( rName, SfxFilterFlags::NONE, SfxFilterFlags::NONE );
119}
120
122{
123 const char* pType=nullptr;
124 if ( rStg.IsStream( "WordDocument" ) )
125 {
126 if ( rStg.IsStream( "0Table" ) || rStg.IsStream( "1Table" ) )
127 pType = "writer_MS_Word_97";
128 else
129 pType = "writer_MS_Word_95";
130 }
131 else if ( rStg.IsStream( "Book" ) )
132 {
133 pType = "calc_MS_Excel_95";
134 }
135 else if ( rStg.IsStream( "Workbook" ) )
136 {
137 pType = "calc_MS_Excel_97";
138 }
139 else if ( rStg.IsStream( "PowerPoint Document" ) )
140 {
141 pType = "impress_MS_PowerPoint_97";
142 }
143 else if ( rStg.IsStream( "Equation Native" ) )
144 {
145 pType = "math_MathType_3x";
146 }
147 else
148 {
149 SotClipboardFormatId nClipId = const_cast<SotStorage&>(rStg).GetFormat();
150 if ( nClipId != SotClipboardFormatId::NONE )
151 {
152 std::shared_ptr<const SfxFilter> pFilter = SfxFilterMatcher().GetFilter4ClipBoardId( nClipId );
153 if ( pFilter )
154 return pFilter->GetTypeName();
155 }
156 }
157
158 return pType ? OUString::createFromAscii(pType) : OUString();
159}
160
162 const uno::Reference<embed::XStorage>& xStorage )
163{
164 SfxFilterMatcher aMatcher;
165
166 css::uno::Reference< css::beans::XPropertySet > xProps( xStorage, css::uno::UNO_QUERY );
167 if ( xProps.is() )
168 {
169 OUString aMediaType;
170 xProps->getPropertyValue("MediaType") >>= aMediaType;
171 if ( !aMediaType.isEmpty() )
172 {
173 css::datatransfer::DataFlavor aDataFlavor;
174 aDataFlavor.MimeType = aMediaType;
175 SotClipboardFormatId nClipId = SotExchange::GetFormat( aDataFlavor );
176 if ( nClipId != SotClipboardFormatId::NONE )
177 {
178 SfxFilterFlags const nMust = SfxFilterFlags::IMPORT;
179 // template filters shouldn't be detected if not explicitly asked for
180 SfxFilterFlags const nDont = SFX_FILTER_NOTINSTALLED | SfxFilterFlags::TEMPLATEPATH;
181
182 // get filter from storage MediaType
183 std::shared_ptr<const SfxFilter> pFilter = aMatcher.GetFilter4ClipBoardId( nClipId, nMust, nDont );
184 if ( !pFilter )
185 // template filter is asked for , but there isn't one; so at least the "normal" format should be detected
186 // or storage *is* a template, but bTemplate is not set
187 pFilter = aMatcher.GetFilter4ClipBoardId( nClipId );
188
189 if ( pFilter )
190 {
191 return pFilter->GetTypeName();
192 }
193 }
194 }
195 }
196
197 return OUString();
198}
199
200/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_uInt16 nVersion
Definition: childwin.cxx:43
static SAL_DLLPRIVATE std::shared_ptr< const SfxFilter > GetDefaultFilter_Impl(std::u16string_view)
Definition: fltfnc.cxx:141
std::shared_ptr< const SfxFilter > GetFilter4FilterName(const OUString &rName, SfxFilterFlags nMust=SfxFilterFlags::NONE, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
Definition: fltfnc.cxx:728
std::shared_ptr< const SfxFilter > GetFilter4ClipBoardId(SotClipboardFormatId nId, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
Definition: fltfnc.cxx:699
SfxFilter(OUString aProvider, OUString aFilterName)
Definition: docfilt.cxx:36
static std::shared_ptr< const SfxFilter > GetDefaultFilter(std::u16string_view rName)
Definition: docfilt.cxx:105
SotClipboardFormatId GetFormat() const
Definition: docfilt.hxx:95
OUString GetSuffixes() const
Definition: docfilt.cxx:97
static std::shared_ptr< const SfxFilter > GetDefaultFilterFromFactory(const OUString &rServiceName)
Definition: docfilt.cxx:110
static std::shared_ptr< const SfxFilter > GetFilterByName(const OUString &rName)
Definition: docfilt.cxx:115
const WildCard & GetWildcard() const
Definition: docfilt.hxx:93
OUString GetDefaultExtension() const
Definition: docfilt.cxx:91
static OUString GetTypeFromStorage(const SotStorage &rStg)
Definition: docfilt.cxx:121
~SfxFilter()
Definition: docfilt.cxx:87
WildCard aWildCard
Definition: docfilt.hxx:42
static OUString GetServiceNameFromFactory(const OUString &rFact)
Definition: objxtor.cxx:921
static SotClipboardFormatId GetFormat(const css::datatransfer::DataFlavor &rFlavor)
bool IsStream(const OUString &rEleName) const
const OUString & getGlob() const
void setGlob(std::u16string_view rString)
SfxFilterFlags
#define SFX_FILTER_NOTINSTALLED
float u
#define SOFFICE_FILEFORMAT_50
OUString aUIName
SotClipboardFormatId
OUString aName
NONE
QPRO_FUNC_TYPE nType
const sal_Unicode *const aMimeType[]
OUString _aServiceName