tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / svl / source / misc / inettype.cxx
blob7487214bc071807339fee5b0810274c209b6a3f6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <array>
24 #include <tools/debug.hxx>
25 #include <tools/wldcrd.hxx>
26 #include <tools/inetmime.hxx>
27 #include <o3tl/string_view.hxx>
28 #include <osl/diagnose.h>
29 #include <svl/inettype.hxx>
31 namespace
34 struct MediaTypeEntry
36 OUString m_pTypeName;
37 INetContentType m_eTypeID;
41 MediaTypeEntry const * seekEntry(OUString const & rTypeName,
42 MediaTypeEntry const * pMap, std::size_t nSize);
44 /** A mapping from type names to type ids and extensions. Sorted by type
45 name.
47 MediaTypeEntry const aStaticTypeNameMap[CONTENT_TYPE_LAST + 1]
48 = { { u" "_ustr, CONTENT_TYPE_UNKNOWN },
49 { CONTENT_TYPE_STR_X_CNT_FSYSBOX, CONTENT_TYPE_X_CNT_FSYSBOX },
50 { CONTENT_TYPE_STR_X_CNT_FSYSFOLDER, CONTENT_TYPE_X_CNT_FSYSFOLDER },
51 { CONTENT_TYPE_STR_X_CNT_FSYSSPECIALFOLDER, CONTENT_TYPE_X_CNT_FSYSSPECIALFOLDER },
52 { CONTENT_TYPE_STR_APP_OCTSTREAM, CONTENT_TYPE_APP_OCTSTREAM },
53 { CONTENT_TYPE_STR_APP_PDF, CONTENT_TYPE_APP_PDF },
54 { CONTENT_TYPE_STR_APP_RTF, CONTENT_TYPE_APP_RTF },
55 { CONTENT_TYPE_STR_APP_VND_CALC, CONTENT_TYPE_APP_VND_CALC },
56 { CONTENT_TYPE_STR_APP_VND_CHART, CONTENT_TYPE_APP_VND_CHART },
57 { CONTENT_TYPE_STR_APP_VND_DRAW, CONTENT_TYPE_APP_VND_DRAW },
58 { CONTENT_TYPE_STR_APP_VND_IMAGE, CONTENT_TYPE_APP_VND_IMAGE },
59 { CONTENT_TYPE_STR_APP_VND_IMPRESS, CONTENT_TYPE_APP_VND_IMPRESS },
60 { CONTENT_TYPE_STR_APP_VND_IMPRESSPACKED, CONTENT_TYPE_APP_VND_IMPRESSPACKED },
61 { CONTENT_TYPE_STR_APP_VND_MAIL, CONTENT_TYPE_APP_VND_MAIL },
62 { CONTENT_TYPE_STR_APP_VND_MATH, CONTENT_TYPE_APP_VND_MATH },
63 { CONTENT_TYPE_STR_APP_VND_NEWS, CONTENT_TYPE_APP_VND_NEWS },
64 { CONTENT_TYPE_STR_APP_VND_OUTTRAY, CONTENT_TYPE_APP_VND_OUTTRAY },
65 { CONTENT_TYPE_STR_APP_VND_TEMPLATE, CONTENT_TYPE_APP_VND_TEMPLATE },
66 { CONTENT_TYPE_STR_APP_VND_WRITER, CONTENT_TYPE_APP_VND_WRITER },
67 { CONTENT_TYPE_STR_APP_VND_WRITER_GLOBAL, CONTENT_TYPE_APP_VND_WRITER_GLOBAL },
68 { CONTENT_TYPE_STR_APP_VND_WRITER_WEB, CONTENT_TYPE_APP_VND_WRITER_WEB },
69 { CONTENT_TYPE_STR_APP_VND_SUN_XML_CALC, CONTENT_TYPE_APP_VND_SUN_XML_CALC },
70 { CONTENT_TYPE_STR_APP_VND_SUN_XML_CHART, CONTENT_TYPE_APP_VND_SUN_XML_CHART },
71 { CONTENT_TYPE_STR_APP_VND_SUN_XML_DRAW, CONTENT_TYPE_APP_VND_SUN_XML_DRAW },
72 { CONTENT_TYPE_STR_APP_VND_SUN_XML_IMPRESS, CONTENT_TYPE_APP_VND_SUN_XML_IMPRESS },
73 { CONTENT_TYPE_STR_APP_VND_SUN_XML_IMPRESSPACKED, CONTENT_TYPE_APP_VND_SUN_XML_IMPRESSPACKED },
74 { CONTENT_TYPE_STR_APP_VND_SUN_XML_MATH, CONTENT_TYPE_APP_VND_SUN_XML_MATH },
75 { CONTENT_TYPE_STR_APP_VND_SUN_XML_WRITER, CONTENT_TYPE_APP_VND_SUN_XML_WRITER },
76 { CONTENT_TYPE_STR_APP_VND_SUN_XML_WRITER_GLOBAL, CONTENT_TYPE_APP_VND_SUN_XML_WRITER_GLOBAL },
77 { CONTENT_TYPE_STR_APP_FRAMESET, CONTENT_TYPE_APP_FRAMESET },
78 { CONTENT_TYPE_STR_APP_GALLERY, CONTENT_TYPE_APP_GALLERY },
79 { CONTENT_TYPE_STR_APP_GALLERY_THEME, CONTENT_TYPE_APP_GALLERY_THEME },
80 { CONTENT_TYPE_STR_APP_JAR, CONTENT_TYPE_APP_JAR },
81 { CONTENT_TYPE_STR_APP_MACRO, CONTENT_TYPE_APP_MACRO },
82 { CONTENT_TYPE_STR_APP_MSEXCEL, CONTENT_TYPE_APP_MSEXCEL },
83 { CONTENT_TYPE_STR_APP_MSEXCEL_TEMPL, CONTENT_TYPE_APP_MSEXCEL_TEMPL },
84 { CONTENT_TYPE_STR_APP_MSPPOINT, CONTENT_TYPE_APP_MSPPOINT },
85 { CONTENT_TYPE_STR_APP_MSPPOINT_TEMPL, CONTENT_TYPE_APP_MSPPOINT_TEMPL },
86 { CONTENT_TYPE_STR_APP_MSWORD, CONTENT_TYPE_APP_MSWORD },
87 { CONTENT_TYPE_STR_APP_MSWORD_TEMPL, CONTENT_TYPE_APP_MSWORD_TEMPL },
88 { CONTENT_TYPE_STR_APP_STARCALC, CONTENT_TYPE_APP_STARCALC },
89 { CONTENT_TYPE_STR_APP_STARCHART, CONTENT_TYPE_APP_STARCHART },
90 { CONTENT_TYPE_STR_APP_STARDRAW, CONTENT_TYPE_APP_STARDRAW },
91 { CONTENT_TYPE_STR_APP_STARHELP, CONTENT_TYPE_APP_STARHELP },
92 { CONTENT_TYPE_STR_APP_STARIMAGE, CONTENT_TYPE_APP_STARIMAGE },
93 { CONTENT_TYPE_STR_APP_STARIMPRESS, CONTENT_TYPE_APP_STARIMPRESS },
94 { CONTENT_TYPE_STR_APP_STARMAIL_SDM, CONTENT_TYPE_APP_STARMAIL_SDM },
95 { CONTENT_TYPE_STR_APP_STARMAIL_SMD, CONTENT_TYPE_APP_STARMAIL_SMD },
96 { CONTENT_TYPE_STR_APP_STARMATH, CONTENT_TYPE_APP_STARMATH },
97 { CONTENT_TYPE_STR_APP_STARWRITER, CONTENT_TYPE_APP_STARWRITER },
98 { CONTENT_TYPE_STR_APP_STARWRITER_GLOB, CONTENT_TYPE_APP_STARWRITER_GLOB },
99 { CONTENT_TYPE_STR_APP_CDE_CALENDAR_APP, CONTENT_TYPE_APP_CDE_CALENDAR_APP },
100 { CONTENT_TYPE_STR_APP_ZIP, CONTENT_TYPE_APP_ZIP },
101 { CONTENT_TYPE_STR_AUDIO_AIFF, CONTENT_TYPE_AUDIO_AIFF },
102 { CONTENT_TYPE_STR_AUDIO_BASIC, CONTENT_TYPE_AUDIO_BASIC },
103 { CONTENT_TYPE_STR_AUDIO_MIDI, CONTENT_TYPE_AUDIO_MIDI },
104 { CONTENT_TYPE_STR_AUDIO_VORBIS, CONTENT_TYPE_AUDIO_VORBIS },
105 { CONTENT_TYPE_STR_AUDIO_WAV, CONTENT_TYPE_AUDIO_WAV },
106 { CONTENT_TYPE_STR_AUDIO_WEBM, CONTENT_TYPE_AUDIO_WEBM },
107 { CONTENT_TYPE_STR_IMAGE_GENERIC, CONTENT_TYPE_IMAGE_GENERIC },
108 { CONTENT_TYPE_STR_IMAGE_GIF, CONTENT_TYPE_IMAGE_GIF },
109 { CONTENT_TYPE_STR_IMAGE_JPEG, CONTENT_TYPE_IMAGE_JPEG },
110 { CONTENT_TYPE_STR_IMAGE_PCX, CONTENT_TYPE_IMAGE_PCX },
111 { CONTENT_TYPE_STR_IMAGE_PNG, CONTENT_TYPE_IMAGE_PNG },
112 { CONTENT_TYPE_STR_IMAGE_TIFF, CONTENT_TYPE_IMAGE_TIFF },
113 { CONTENT_TYPE_STR_IMAGE_BMP, CONTENT_TYPE_IMAGE_BMP },
114 { CONTENT_TYPE_STR_INET_MSG_RFC822, CONTENT_TYPE_INET_MESSAGE_RFC822 },
115 { CONTENT_TYPE_STR_INET_MULTI_ALTERNATIVE, CONTENT_TYPE_INET_MULTIPART_ALTERNATIVE },
116 { CONTENT_TYPE_STR_INET_MULTI_DIGEST, CONTENT_TYPE_INET_MULTIPART_DIGEST },
117 { CONTENT_TYPE_STR_INET_MULTI_MIXED, CONTENT_TYPE_INET_MULTIPART_MIXED },
118 { CONTENT_TYPE_STR_INET_MULTI_PARALLEL, CONTENT_TYPE_INET_MULTIPART_PARALLEL },
119 { CONTENT_TYPE_STR_INET_MULTI_RELATED, CONTENT_TYPE_INET_MULTIPART_RELATED },
120 { CONTENT_TYPE_STR_TEXT_ICALENDAR, CONTENT_TYPE_TEXT_ICALENDAR },
121 { CONTENT_TYPE_STR_TEXT_HTML, CONTENT_TYPE_TEXT_HTML },
122 { CONTENT_TYPE_STR_TEXT_PLAIN, CONTENT_TYPE_TEXT_PLAIN },
123 { CONTENT_TYPE_STR_TEXT_XMLICALENDAR, CONTENT_TYPE_TEXT_XMLICALENDAR },
124 { CONTENT_TYPE_STR_TEXT_URL, CONTENT_TYPE_TEXT_URL },
125 { CONTENT_TYPE_STR_TEXT_VCALENDAR, CONTENT_TYPE_TEXT_VCALENDAR },
126 { CONTENT_TYPE_STR_TEXT_VCARD, CONTENT_TYPE_TEXT_VCARD },
127 { CONTENT_TYPE_STR_VIDEO_MSVIDEO, CONTENT_TYPE_VIDEO_MSVIDEO },
128 { CONTENT_TYPE_STR_VIDEO_THEORA, CONTENT_TYPE_VIDEO_THEORA },
129 { CONTENT_TYPE_STR_VIDEO_VDO, CONTENT_TYPE_VIDEO_VDO },
130 { CONTENT_TYPE_STR_VIDEO_WEBM, CONTENT_TYPE_VIDEO_WEBM },
131 { CONTENT_TYPE_STR_X_STARMAIL, CONTENT_TYPE_X_STARMAIL },
132 { CONTENT_TYPE_STR_X_VRML, CONTENT_TYPE_X_VRML }
136 /** A mapping from extensions to type IDs. Sorted by extension.
138 MediaTypeEntry const aStaticExtensionMap[]
139 = { { u"aif"_ustr, CONTENT_TYPE_AUDIO_AIFF },
140 { u"aiff"_ustr, CONTENT_TYPE_AUDIO_AIFF },
141 { u"appt"_ustr, CONTENT_TYPE_APP_CDE_CALENDAR_APP },
142 { u"au"_ustr, CONTENT_TYPE_AUDIO_BASIC },
143 { u"avi"_ustr, CONTENT_TYPE_VIDEO_MSVIDEO },
144 { u"bmp"_ustr, CONTENT_TYPE_IMAGE_BMP },
145 { u"cgm"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
146 { u"doc"_ustr, CONTENT_TYPE_APP_MSWORD },
147 { u"dot"_ustr, CONTENT_TYPE_APP_MSWORD_TEMPL },
148 { u"dxf"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
149 { u"eps"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
150 { u"gal"_ustr, CONTENT_TYPE_APP_GALLERY },
151 { u"gif"_ustr, CONTENT_TYPE_IMAGE_GIF },
152 { u"htm"_ustr, CONTENT_TYPE_TEXT_HTML },
153 { u"html"_ustr, CONTENT_TYPE_TEXT_HTML },
154 { u"ics"_ustr, CONTENT_TYPE_TEXT_ICALENDAR },
155 { u"jar"_ustr, CONTENT_TYPE_APP_JAR },
156 { u"jpeg"_ustr, CONTENT_TYPE_IMAGE_JPEG },
157 { u"jpg"_ustr, CONTENT_TYPE_IMAGE_JPEG },
158 { u"met"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
159 { u"mid"_ustr, CONTENT_TYPE_AUDIO_MIDI },
160 { u"midi"_ustr, CONTENT_TYPE_AUDIO_MIDI },
161 { u"ogg"_ustr, CONTENT_TYPE_AUDIO_VORBIS },
162 { u"pbm"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
163 { u"pcd"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
164 { u"pct"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
165 { u"pcx"_ustr, CONTENT_TYPE_IMAGE_PCX },
166 { u"pdf"_ustr, CONTENT_TYPE_APP_PDF },
167 { u"pgm"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
168 { u"png"_ustr, CONTENT_TYPE_IMAGE_PNG },
169 { u"pot"_ustr, CONTENT_TYPE_APP_MSPPOINT_TEMPL },
170 { u"ppm"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
171 { u"ppt"_ustr, CONTENT_TYPE_APP_MSPPOINT },
172 { u"psd"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
173 { u"ras"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
174 { u"rtf"_ustr, CONTENT_TYPE_APP_RTF },
175 { u"sda"_ustr, CONTENT_TYPE_APP_VND_DRAW },
176 { u"sdc"_ustr, CONTENT_TYPE_APP_VND_CALC },
177 { u"sdd"_ustr, CONTENT_TYPE_APP_VND_IMPRESS },
178 { u"sdm"_ustr, CONTENT_TYPE_APP_VND_MAIL },
179 { u"sdp"_ustr, CONTENT_TYPE_APP_VND_IMPRESSPACKED },
180 { u"sds"_ustr, CONTENT_TYPE_APP_VND_CHART },
181 { u"sdw"_ustr, CONTENT_TYPE_APP_VND_WRITER },
182 { u"sd~"_ustr, CONTENT_TYPE_X_STARMAIL },
183 { u"sfs"_ustr, CONTENT_TYPE_APP_FRAMESET },
184 { u"sgl"_ustr, CONTENT_TYPE_APP_VND_WRITER_GLOBAL },
185 { u"sim"_ustr, CONTENT_TYPE_APP_VND_IMAGE },
186 { u"smd"_ustr, CONTENT_TYPE_APP_STARMAIL_SMD }, //CONTENT_TYPE_X_STARMAIL
187 { u"smf"_ustr, CONTENT_TYPE_APP_VND_MATH },
188 { u"svh"_ustr, CONTENT_TYPE_APP_STARHELP },
189 { u"svm"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
190 { u"sxc"_ustr, CONTENT_TYPE_APP_VND_SUN_XML_CALC },
191 { u"sxd"_ustr, CONTENT_TYPE_APP_VND_SUN_XML_DRAW },
192 { u"sxg"_ustr, CONTENT_TYPE_APP_VND_SUN_XML_WRITER_GLOBAL },
193 { u"sxi"_ustr, CONTENT_TYPE_APP_VND_SUN_XML_IMPRESS },
194 { u"sxm"_ustr, CONTENT_TYPE_APP_VND_SUN_XML_MATH },
195 { u"sxp"_ustr, CONTENT_TYPE_APP_VND_SUN_XML_IMPRESSPACKED },
196 { u"sxs"_ustr, CONTENT_TYPE_APP_VND_SUN_XML_CHART },
197 { u"sxw"_ustr, CONTENT_TYPE_APP_VND_SUN_XML_WRITER },
198 { u"tga"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
199 { u"thm"_ustr, CONTENT_TYPE_APP_GALLERY_THEME },
200 { u"tif"_ustr, CONTENT_TYPE_IMAGE_TIFF },
201 { u"tiff"_ustr, CONTENT_TYPE_IMAGE_TIFF },
202 { u"txt"_ustr, CONTENT_TYPE_TEXT_PLAIN },
203 { u"url"_ustr, CONTENT_TYPE_TEXT_URL },
204 { u"vcf"_ustr, CONTENT_TYPE_TEXT_VCARD },
205 { u"vcs"_ustr, CONTENT_TYPE_TEXT_VCALENDAR },
206 { u"vdo"_ustr, CONTENT_TYPE_VIDEO_VDO },
207 { u"vor"_ustr, CONTENT_TYPE_APP_VND_TEMPLATE },
208 { u"wav"_ustr, CONTENT_TYPE_AUDIO_WAV },
209 { u"webm"_ustr, CONTENT_TYPE_VIDEO_WEBM },
210 { u"wmf"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
211 { u"wrl"_ustr, CONTENT_TYPE_X_VRML },
212 { u"xbm"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
213 { u"xcs"_ustr, CONTENT_TYPE_TEXT_XMLICALENDAR },
214 { u"xls"_ustr, CONTENT_TYPE_APP_MSEXCEL },
215 { u"xlt"_ustr, CONTENT_TYPE_APP_MSEXCEL_TEMPL },
216 { u"xlw"_ustr, CONTENT_TYPE_APP_MSEXCEL },
217 { u"xpm"_ustr, CONTENT_TYPE_IMAGE_GENERIC },
218 { u"zip"_ustr, CONTENT_TYPE_APP_ZIP } };
223 // seekEntry
226 namespace
229 MediaTypeEntry const * seekEntry(OUString const & rTypeName,
230 MediaTypeEntry const * pMap, std::size_t nSize)
232 #if defined DBG_UTIL
233 for (std::size_t i = 0; i < nSize - 1; ++i)
234 DBG_ASSERT(
235 pMap[i].m_pTypeName < pMap[i + 1].m_pTypeName,
236 "seekEntry(): Bad map");
237 #endif
239 std::size_t nLow = 0;
240 std::size_t nHigh = nSize;
241 while (nLow != nHigh)
243 std::size_t nMiddle = (nLow + nHigh) / 2;
244 MediaTypeEntry const * pEntry = pMap + nMiddle;
245 sal_Int32 nCmp = rTypeName.compareToIgnoreAsciiCase(pEntry->m_pTypeName);
246 if (nCmp < 0)
247 nHigh = nMiddle;
248 else if (nCmp == 0)
249 return pEntry;
251 else
252 nLow = nMiddle + 1;
254 return nullptr;
259 // static
260 INetContentType INetContentTypes::GetContentType(OUString const & rTypeName)
262 OUString aType;
263 OUString aSubType;
264 if (parse(rTypeName, aType, aSubType))
266 aType += "/" + aSubType;
267 MediaTypeEntry const * pEntry = seekEntry(aType, aStaticTypeNameMap,
268 CONTENT_TYPE_LAST + 1);
269 return pEntry ? pEntry->m_eTypeID : CONTENT_TYPE_UNKNOWN;
271 else
272 return rTypeName.equalsIgnoreAsciiCase(CONTENT_TYPE_STR_X_STARMAIL) ?
273 CONTENT_TYPE_X_STARMAIL : CONTENT_TYPE_UNKNOWN;
274 // the content type "x-starmail" has no sub type
277 //static
278 OUString INetContentTypes::GetContentType(INetContentType eTypeID)
280 static std::array<OUString, CONTENT_TYPE_LAST + 1> aMap = []()
282 std::array<OUString, CONTENT_TYPE_LAST + 1> tmp;
283 for (std::size_t i = 0; i <= CONTENT_TYPE_LAST; ++i)
284 tmp[aStaticTypeNameMap[i].m_eTypeID] = aStaticTypeNameMap[i].m_pTypeName;
285 tmp[CONTENT_TYPE_UNKNOWN] = CONTENT_TYPE_STR_APP_OCTSTREAM;
286 tmp[CONTENT_TYPE_TEXT_PLAIN] = CONTENT_TYPE_STR_TEXT_PLAIN +
287 "; charset=iso-8859-1";
288 return tmp;
289 }();
291 OUString aTypeName = eTypeID <= CONTENT_TYPE_LAST ? aMap[eTypeID]
292 : OUString();
293 if (aTypeName.isEmpty())
295 OSL_FAIL("INetContentTypes::GetContentType(): Bad ID");
296 return CONTENT_TYPE_STR_APP_OCTSTREAM;
298 return aTypeName;
301 //static
302 INetContentType INetContentTypes::GetContentType4Extension(OUString const & rExtension)
304 MediaTypeEntry const * pEntry = seekEntry(rExtension, aStaticExtensionMap,
305 SAL_N_ELEMENTS(aStaticExtensionMap));
306 if (pEntry)
307 return pEntry->m_eTypeID;
308 return CONTENT_TYPE_APP_OCTSTREAM;
311 //static
312 INetContentType INetContentTypes::GetContentTypeFromURL(std::u16string_view rURL)
314 INetContentType eTypeID = CONTENT_TYPE_UNKNOWN;
315 std::size_t nIdx{ 0 };
316 OUString aToken( o3tl::getToken(rURL, u':', nIdx) );
317 if (!aToken.isEmpty())
319 if (aToken.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_FILE))
320 if (rURL[ rURL.size() - 1 ] == '/') // folder
321 if (rURL.size() > RTL_CONSTASCII_LENGTH("file:///"))
322 if (WildCard(u"*/{*}/").Matches(rURL)) // special folder
323 eTypeID = CONTENT_TYPE_X_CNT_FSYSSPECIALFOLDER;
324 else
325 // drive? -> "file:///?|/"
326 if (rURL.size() == 11
327 && rURL[ rURL.size() - 2 ] == '|')
329 // Drives need further processing, because of
330 // dynamic type according to underlying volume,
331 // which cannot be determined here.
333 else // normal folder
334 eTypeID = CONTENT_TYPE_X_CNT_FSYSFOLDER;
335 else // file system root
336 eTypeID = CONTENT_TYPE_X_CNT_FSYSBOX;
337 else // file
339 //@@@
341 else if (aToken.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_HTTP)
342 || aToken.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_HTTPS))
343 eTypeID = CONTENT_TYPE_TEXT_HTML;
344 else if (aToken.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_PRIVATE))
346 aToken = o3tl::getToken(rURL, u'/', nIdx);
347 if (aToken == "factory")
349 aToken = o3tl::getToken(rURL, u'/', nIdx);
350 if (aToken == "swriter")
352 aToken = o3tl::getToken(rURL, u'/', nIdx);
353 eTypeID = aToken == "web" ?
354 CONTENT_TYPE_APP_VND_WRITER_WEB :
355 aToken == "GlobalDocument" ?
356 CONTENT_TYPE_APP_VND_WRITER_GLOBAL :
357 CONTENT_TYPE_APP_VND_WRITER;
359 else if (aToken == "scalc")
360 eTypeID = CONTENT_TYPE_APP_VND_CALC;
361 else if (aToken == "sdraw")
362 eTypeID = CONTENT_TYPE_APP_VND_DRAW;
363 else if (aToken == "simpress")
364 eTypeID = CONTENT_TYPE_APP_VND_IMPRESS;
365 else if (aToken == "schart")
366 eTypeID = CONTENT_TYPE_APP_VND_CHART;
367 else if (aToken == "simage")
368 eTypeID = CONTENT_TYPE_APP_VND_IMAGE;
369 else if (aToken == "smath")
370 eTypeID = CONTENT_TYPE_APP_VND_MATH;
371 else if (aToken == "frameset")
372 eTypeID = CONTENT_TYPE_APP_FRAMESET;
374 else if (aToken == "helpid")
375 eTypeID = CONTENT_TYPE_APP_STARHELP;
377 else if (aToken.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_MAILTO))
378 eTypeID = CONTENT_TYPE_APP_VND_OUTTRAY;
379 else if (aToken.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_MACRO))
380 eTypeID = CONTENT_TYPE_APP_MACRO;
381 else if (aToken.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_DATA))
383 aToken = o3tl::getToken(rURL, u',', nIdx);
384 eTypeID = GetContentType(aToken);
387 if (eTypeID == CONTENT_TYPE_UNKNOWN)
389 OUString aExtension;
390 if (GetExtensionFromURL(rURL, aExtension))
391 eTypeID = GetContentType4Extension(aExtension);
393 return eTypeID;
396 //static
397 bool INetContentTypes::GetExtensionFromURL(std::u16string_view rURL,
398 OUString & rExtension)
400 size_t nSlashPos = 0;
401 size_t i = 0;
402 while (i != std::u16string_view::npos)
404 nSlashPos = i;
405 i = rURL.find('/', i + 1);
407 if (nSlashPos != 0)
409 size_t nLastDotPos = i = rURL.find('.', nSlashPos);
410 while (i != std::u16string_view::npos)
412 nLastDotPos = i;
413 i = rURL.find('.', i + 1);
415 if (nLastDotPos >- 0)
416 rExtension = rURL.substr(nLastDotPos + 1);
417 return true;
419 return false;
422 bool INetContentTypes::parse(
423 OUString const & rMediaType, OUString & rType, OUString & rSubType,
424 INetContentTypeParameterList * pParameters)
426 sal_Unicode const * b = rMediaType.getStr();
427 sal_Unicode const * e = b + rMediaType.getLength();
428 OUString t;
429 OUString s;
430 INetContentTypeParameterList p;
431 if (INetMIME::scanContentType(rMediaType, &t, &s, pParameters == nullptr ? nullptr : &p) == e) {
432 rType = t;
433 rSubType = s;
434 if (pParameters != nullptr) {
435 *pParameters = std::move(p);
437 return true;
438 } else {
439 return false;
443 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */