1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 #include <o3tl/ptr_container.hxx>
25 #include <tools/wldcrd.hxx>
26 #include <tools/inetmime.hxx>
27 #include <rtl/instance.hxx>
28 #include <osl/diagnose.h>
29 #include <svl/inettype.hxx>
30 #include <svl/svl.hrc>
32 #include <boost/ptr_container/ptr_map.hpp>
34 #include "getstringresource.hxx"
41 sal_Char
const * m_pTypeName
;
42 INetContentType m_eTypeID
;
43 sal_Char
const * m_pExtension
;
49 OUString m_aPresentation
;
50 OUString m_aSystemFileType
;
53 struct TypeNameMapEntry
55 OUString m_aExtension
;
56 INetContentType m_eTypeID
;
59 m_eTypeID(CONTENT_TYPE_UNKNOWN
) {}
62 struct ExtensionMapEntry
64 INetContentType m_eTypeID
;
67 m_eTypeID(CONTENT_TYPE_UNKNOWN
) {}
72 typedef boost::ptr_map
<OUString
, TypeNameMapEntry
> TypeNameMap
;
73 typedef boost::ptr_map
<OUString
, ExtensionMapEntry
> ExtensionMap
;
74 typedef std::map
<INetContentType
, TypeIDMapEntry
*> TypeIDMap
;
76 TypeIDMap m_aTypeIDMap
; // map ContentType to TypeID
77 TypeNameMap m_aTypeNameMap
; // map TypeName to TypeID, Extension
78 ExtensionMap m_aExtensionMap
; // map Extension to TypeID
79 sal_uInt32 m_nNextDynamicID
;
82 Registration(): m_nNextDynamicID(CONTENT_TYPE_LAST
+ 1) {}
86 static inline TypeIDMapEntry
* getEntry(INetContentType eTypeID
);
88 static TypeNameMapEntry
* getExtensionEntry(OUString
const & rTypeName
);
90 static INetContentType
RegisterContentType(OUString
const & rTypeName
,
91 OUString
const & rPresentation
,
92 OUString
const * pExtension
,
93 OUString
const * pSystemFileType
);
95 static INetContentType
GetContentType(OUString
const & rTypeName
);
97 static OUString
GetContentType(INetContentType eTypeID
);
99 static OUString
GetPresentation(INetContentType eTypeID
);
101 static INetContentType
GetContentType4Extension(OUString
const & rExtension
);
107 struct theRegistration
108 : public rtl::Static
< Registration
, theRegistration
> {};
112 inline TypeIDMapEntry
* Registration::getEntry(INetContentType eTypeID
)
114 Registration
&rRegistration
= theRegistration::get();
116 TypeIDMap::iterator it
= rRegistration
.m_aTypeIDMap
.find( eTypeID
);
117 if( it
!= rRegistration
.m_aTypeIDMap
.end() )
123 MediaTypeEntry
const * seekEntry(OUString
const & rTypeName
,
124 MediaTypeEntry
const * pMap
, sal_Size nSize
);
126 /** A mapping from type names to type ids and extensions. Sorted by type
129 MediaTypeEntry
const aStaticTypeNameMap
[CONTENT_TYPE_LAST
+ 1]
130 = { { " ", CONTENT_TYPE_UNKNOWN
, "" },
131 { CONTENT_TYPE_STR_X_CNT_FSYSBOX
, CONTENT_TYPE_X_CNT_FSYSBOX
, "tmp" },
132 { CONTENT_TYPE_STR_X_CNT_FSYSFOLDER
, CONTENT_TYPE_X_CNT_FSYSFOLDER
,
134 { CONTENT_TYPE_STR_X_CNT_FSYSSPECIALFOLDER
,
135 CONTENT_TYPE_X_CNT_FSYSSPECIALFOLDER
, "tmp" },
136 { CONTENT_TYPE_STR_APP_OCTSTREAM
, CONTENT_TYPE_APP_OCTSTREAM
, "tmp" },
137 { CONTENT_TYPE_STR_APP_PDF
, CONTENT_TYPE_APP_PDF
, "pdf" },
138 { CONTENT_TYPE_STR_APP_RTF
, CONTENT_TYPE_APP_RTF
, "rtf" },
139 { CONTENT_TYPE_STR_APP_VND_CALC
, CONTENT_TYPE_APP_VND_CALC
, "sdc" },
140 { CONTENT_TYPE_STR_APP_VND_CHART
, CONTENT_TYPE_APP_VND_CHART
, "sds" },
141 { CONTENT_TYPE_STR_APP_VND_DRAW
, CONTENT_TYPE_APP_VND_DRAW
, "sda" },
142 { CONTENT_TYPE_STR_APP_VND_IMAGE
, CONTENT_TYPE_APP_VND_IMAGE
, "sim" },
143 { CONTENT_TYPE_STR_APP_VND_IMPRESS
, CONTENT_TYPE_APP_VND_IMPRESS
,
145 { CONTENT_TYPE_STR_APP_VND_IMPRESSPACKED
,
146 CONTENT_TYPE_APP_VND_IMPRESSPACKED
, "sdp" },
147 { CONTENT_TYPE_STR_APP_VND_MAIL
, CONTENT_TYPE_APP_VND_MAIL
, "sdm" },
148 { CONTENT_TYPE_STR_APP_VND_MATH
, CONTENT_TYPE_APP_VND_MATH
, "smf" },
149 { CONTENT_TYPE_STR_APP_VND_NEWS
, CONTENT_TYPE_APP_VND_NEWS
, "sdm" },
150 { CONTENT_TYPE_STR_APP_VND_OUTTRAY
, CONTENT_TYPE_APP_VND_OUTTRAY
,
152 { CONTENT_TYPE_STR_APP_VND_TEMPLATE
, CONTENT_TYPE_APP_VND_TEMPLATE
,
154 { CONTENT_TYPE_STR_APP_VND_WRITER
, CONTENT_TYPE_APP_VND_WRITER
,
156 { CONTENT_TYPE_STR_APP_VND_WRITER_GLOBAL
,
157 CONTENT_TYPE_APP_VND_WRITER_GLOBAL
, "sgl" },
158 { CONTENT_TYPE_STR_APP_VND_WRITER_WEB
,
159 CONTENT_TYPE_APP_VND_WRITER_WEB
, "htm" },
160 { CONTENT_TYPE_STR_APP_VND_SUN_XML_CALC
, CONTENT_TYPE_APP_VND_SUN_XML_CALC
, "sxc" },
161 { CONTENT_TYPE_STR_APP_VND_SUN_XML_CHART
, CONTENT_TYPE_APP_VND_SUN_XML_CHART
, "sxs" },
162 { CONTENT_TYPE_STR_APP_VND_SUN_XML_DRAW
, CONTENT_TYPE_APP_VND_SUN_XML_DRAW
, "sxd" },
163 { CONTENT_TYPE_STR_APP_VND_SUN_XML_IMPRESS
, CONTENT_TYPE_APP_VND_SUN_XML_IMPRESS
, "sxi" },
164 { CONTENT_TYPE_STR_APP_VND_SUN_XML_IMPRESSPACKED
, CONTENT_TYPE_APP_VND_SUN_XML_IMPRESSPACKED
, "sxp" },
165 { CONTENT_TYPE_STR_APP_VND_SUN_XML_MATH
, CONTENT_TYPE_APP_VND_SUN_XML_MATH
, "sxm" },
166 { CONTENT_TYPE_STR_APP_VND_SUN_XML_WRITER
, CONTENT_TYPE_APP_VND_SUN_XML_WRITER
, "sxw" },
167 { CONTENT_TYPE_STR_APP_VND_SUN_XML_WRITER_GLOBAL
, CONTENT_TYPE_APP_VND_SUN_XML_WRITER_GLOBAL
, "sxg" },
168 { CONTENT_TYPE_STR_APP_FRAMESET
, CONTENT_TYPE_APP_FRAMESET
, "sfs" },
169 { CONTENT_TYPE_STR_APP_GALLERY
, CONTENT_TYPE_APP_GALLERY
, "gal" },
170 { CONTENT_TYPE_STR_APP_GALLERY_THEME
, CONTENT_TYPE_APP_GALLERY_THEME
,
172 { CONTENT_TYPE_STR_APP_JAR
, CONTENT_TYPE_APP_JAR
, "jar" },
173 { CONTENT_TYPE_STR_APP_MACRO
, CONTENT_TYPE_APP_MACRO
, "tmp" },
174 { CONTENT_TYPE_STR_APP_MSEXCEL
, CONTENT_TYPE_APP_MSEXCEL
, "xls" },
175 { CONTENT_TYPE_STR_APP_MSEXCEL_TEMPL
, CONTENT_TYPE_APP_MSEXCEL_TEMPL
,
177 { CONTENT_TYPE_STR_APP_MSPPOINT
, CONTENT_TYPE_APP_MSPPOINT
, "ppt" },
178 { CONTENT_TYPE_STR_APP_MSPPOINT_TEMPL
,
179 CONTENT_TYPE_APP_MSPPOINT_TEMPL
, "pot" },
180 { CONTENT_TYPE_STR_APP_MSWORD
, CONTENT_TYPE_APP_MSWORD
, "doc" },
181 { CONTENT_TYPE_STR_APP_MSWORD_TEMPL
, CONTENT_TYPE_APP_MSWORD_TEMPL
,
183 { CONTENT_TYPE_STR_APP_STARCALC
, CONTENT_TYPE_APP_STARCALC
, "sdc" },
184 { CONTENT_TYPE_STR_APP_STARCHART
, CONTENT_TYPE_APP_STARCHART
, "sds" },
185 { CONTENT_TYPE_STR_APP_STARDRAW
, CONTENT_TYPE_APP_STARDRAW
, "sda" },
186 { CONTENT_TYPE_STR_APP_STARHELP
, CONTENT_TYPE_APP_STARHELP
, "svh" },
187 { CONTENT_TYPE_STR_APP_STARIMAGE
, CONTENT_TYPE_APP_STARIMAGE
, "sim" },
188 { CONTENT_TYPE_STR_APP_STARIMPRESS
, CONTENT_TYPE_APP_STARIMPRESS
,
190 { CONTENT_TYPE_STR_APP_STARMAIL_SDM
, CONTENT_TYPE_APP_STARMAIL_SDM
,
192 { CONTENT_TYPE_STR_APP_STARMAIL_SMD
, CONTENT_TYPE_APP_STARMAIL_SMD
,
194 { CONTENT_TYPE_STR_APP_STARMATH
, CONTENT_TYPE_APP_STARMATH
, "smf" },
195 { CONTENT_TYPE_STR_APP_STARWRITER
, CONTENT_TYPE_APP_STARWRITER
,
197 { CONTENT_TYPE_STR_APP_STARWRITER_GLOB
,
198 CONTENT_TYPE_APP_STARWRITER_GLOB
, "sgl" },
199 { CONTENT_TYPE_STR_APP_CDE_CALENDAR_APP
,
200 CONTENT_TYPE_APP_CDE_CALENDAR_APP
, "appt" },
201 { CONTENT_TYPE_STR_APP_ZIP
, CONTENT_TYPE_APP_ZIP
, "zip" },
202 { CONTENT_TYPE_STR_AUDIO_AIFF
, CONTENT_TYPE_AUDIO_AIFF
, "aif" },
203 { CONTENT_TYPE_STR_AUDIO_BASIC
, CONTENT_TYPE_AUDIO_BASIC
, "au" },
204 { CONTENT_TYPE_STR_AUDIO_MIDI
, CONTENT_TYPE_AUDIO_MIDI
, "mid" },
205 { CONTENT_TYPE_STR_AUDIO_VORBIS
, CONTENT_TYPE_AUDIO_VORBIS
, "ogg" },
206 { CONTENT_TYPE_STR_AUDIO_WAV
, CONTENT_TYPE_AUDIO_WAV
, "wav" },
207 { CONTENT_TYPE_STR_AUDIO_WEBM
, CONTENT_TYPE_AUDIO_WEBM
, "webm" },
208 { CONTENT_TYPE_STR_IMAGE_GENERIC
, CONTENT_TYPE_IMAGE_GENERIC
, "tmp" },
209 { CONTENT_TYPE_STR_IMAGE_GIF
, CONTENT_TYPE_IMAGE_GIF
, "gif" },
210 { CONTENT_TYPE_STR_IMAGE_JPEG
, CONTENT_TYPE_IMAGE_JPEG
, "jpg" },
211 { CONTENT_TYPE_STR_IMAGE_PCX
, CONTENT_TYPE_IMAGE_PCX
, "pcx" },
212 { CONTENT_TYPE_STR_IMAGE_PNG
, CONTENT_TYPE_IMAGE_PNG
, "png" },
213 { CONTENT_TYPE_STR_IMAGE_TIFF
, CONTENT_TYPE_IMAGE_TIFF
, "tif" },
214 { CONTENT_TYPE_STR_IMAGE_BMP
, CONTENT_TYPE_IMAGE_BMP
, "bmp" },
215 { CONTENT_TYPE_STR_INET_MSG_RFC822
, CONTENT_TYPE_INET_MESSAGE_RFC822
,
217 { CONTENT_TYPE_STR_INET_MULTI_ALTERNATIVE
,
218 CONTENT_TYPE_INET_MULTIPART_ALTERNATIVE
, "tmp" },
219 { CONTENT_TYPE_STR_INET_MULTI_DIGEST
,
220 CONTENT_TYPE_INET_MULTIPART_DIGEST
, "tmp" },
221 { CONTENT_TYPE_STR_INET_MULTI_MIXED
,
222 CONTENT_TYPE_INET_MULTIPART_MIXED
, "tmp" },
223 { CONTENT_TYPE_STR_INET_MULTI_PARALLEL
,
224 CONTENT_TYPE_INET_MULTIPART_PARALLEL
, "tmp" },
225 { CONTENT_TYPE_STR_INET_MULTI_RELATED
,
226 CONTENT_TYPE_INET_MULTIPART_RELATED
, "tmp" },
227 { CONTENT_TYPE_STR_TEXT_ICALENDAR
, CONTENT_TYPE_TEXT_ICALENDAR
,
229 { CONTENT_TYPE_STR_TEXT_HTML
, CONTENT_TYPE_TEXT_HTML
, "htm" },
230 { CONTENT_TYPE_STR_TEXT_PLAIN
, CONTENT_TYPE_TEXT_PLAIN
, "txt" },
231 { CONTENT_TYPE_STR_TEXT_XMLICALENDAR
, CONTENT_TYPE_TEXT_XMLICALENDAR
,
233 { CONTENT_TYPE_STR_TEXT_URL
, CONTENT_TYPE_TEXT_URL
, "url" },
234 { CONTENT_TYPE_STR_TEXT_VCALENDAR
, CONTENT_TYPE_TEXT_VCALENDAR
,
236 { CONTENT_TYPE_STR_TEXT_VCARD
, CONTENT_TYPE_TEXT_VCARD
, "vcf" },
237 { CONTENT_TYPE_STR_VIDEO_MSVIDEO
, CONTENT_TYPE_VIDEO_MSVIDEO
, "avi" },
238 { CONTENT_TYPE_STR_VIDEO_THEORA
, CONTENT_TYPE_VIDEO_THEORA
, "ogg" },
239 { CONTENT_TYPE_STR_VIDEO_VDO
, CONTENT_TYPE_VIDEO_VDO
, "vdo" },
240 { CONTENT_TYPE_STR_VIDEO_WEBM
, CONTENT_TYPE_VIDEO_WEBM
, "webm" },
241 { CONTENT_TYPE_STR_X_STARMAIL
, CONTENT_TYPE_X_STARMAIL
, "smd" },
242 { CONTENT_TYPE_STR_X_VRML
, CONTENT_TYPE_X_VRML
, "wrl" }
245 /** A mapping from type IDs to presentation resource IDs. Sorted by type ID.
247 sal_uInt16
const aStaticResourceIDMap
[CONTENT_TYPE_LAST
+ 1]
248 = { STR_SVT_MIMETYPE_APP_OCTSTREAM
, // CONTENT_TYPE_UNKNOWN
249 STR_SVT_MIMETYPE_APP_OCTSTREAM
, // CONTENT_TYPE_APP_OCTSTREAM
250 STR_SVT_MIMETYPE_APP_PDF
, // CONTENT_TYPE_APP_PDF
251 STR_SVT_MIMETYPE_APP_RTF
, // CONTENT_TYPE_APP_RTF
252 STR_SVT_MIMETYPE_APP_MSWORD
, // CONTENT_TYPE_APP_MSWORD
253 STR_SVT_MIMETYPE_APP_MSWORD
, // CONTENT_TYPE_APP_MSWORD_TEMPL //TODO: new presentation string?
254 STR_SVT_MIMETYPE_APP_STARCALC
, // CONTENT_TYPE_APP_STARCALC
255 STR_SVT_MIMETYPE_APP_STARCHART
, // CONTENT_TYPE_APP_STARCHART
256 STR_SVT_MIMETYPE_APP_STARDRAW
, // CONTENT_TYPE_APP_STARDRAW
257 STR_SVT_MIMETYPE_APP_STARHELP
, // CONTENT_TYPE_APP_STARHELP
258 STR_SVT_MIMETYPE_APP_STARIMAGE
, // CONTENT_TYPE_APP_STARIMAGE
259 STR_SVT_MIMETYPE_APP_STARIMPRESS
, // CONTENT_TYPE_APP_STARIMPRESS
260 STR_SVT_MIMETYPE_APP_STARMATH
, // CONTENT_TYPE_APP_STARMATH
261 STR_SVT_MIMETYPE_APP_STARWRITER
, // CONTENT_TYPE_APP_STARWRITER
262 STR_SVT_MIMETYPE_APP_ZIP
, // CONTENT_TYPE_APP_ZIP
263 STR_SVT_MIMETYPE_AUDIO_AIFF
, // CONTENT_TYPE_AUDIO_AIFF
264 STR_SVT_MIMETYPE_AUDIO_BASIC
, // CONTENT_TYPE_AUDIO_BASIC
265 STR_SVT_MIMETYPE_AUDIO_MIDI
, // CONTENT_TYPE_AUDIO_MIDI
266 STR_SVT_MIMETYPE_AUDIO_VORBIS
, // CONTENT_TYPE_AUDIO_VORBIS
267 STR_SVT_MIMETYPE_AUDIO_WAV
, // CONTENT_TYPE_AUDIO_WAV
268 STR_SVT_MIMETYPE_AUDIO_WEBM
, // CONTENT_TYPE_AUDIO_WEBM
269 STR_SVT_MIMETYPE_IMAGE_GIF
, // CONTENT_TYPE_IMAGE_GIF
270 STR_SVT_MIMETYPE_IMAGE_JPEG
, // CONTENT_TYPE_IMAGE_JPEG
271 STR_SVT_MIMETYPE_IMAGE_PCX
, // CONTENT_TYPE_IMAGE_PCX
272 STR_SVT_MIMETYPE_IMAGE_PNG
, // CONTENT_TYPE_IMAGE_PNG
273 STR_SVT_MIMETYPE_IMAGE_TIFF
, // CONTENT_TYPE_IMAGE_TIFF
274 STR_SVT_MIMETYPE_IMAGE_BMP
, // CONTENT_TYPE_IMAGE_BMP
275 STR_SVT_MIMETYPE_TEXT_HTML
, // CONTENT_TYPE_TEXT_HTML
276 STR_SVT_MIMETYPE_TEXT_PLAIN
, // CONTENT_TYPE_TEXT_PLAIN
277 STR_SVT_MIMETYPE_TEXT_URL
, // CONTENT_TYPE_TEXT_URL
278 STR_SVT_MIMETYPE_TEXT_VCARD
, // CONTENT_TYPE_TEXT_VCARD
279 STR_SVT_MIMETYPE_VIDEO_MSVIDEO
, // CONTENT_TYPE_VIDEO_MSVIDEO
280 STR_SVT_MIMETYPE_VIDEO_THEORA
, // CONTENT_TYPE_VIDEO_THEORA
281 STR_SVT_MIMETYPE_VIDEO_VDO
, // CONTENT_TYPE_VIDEO_VDO
282 STR_SVT_MIMETYPE_VIDEO_WEBM
, // CONTENT_TYPE_VIDEO_WEBM
283 STR_SVT_MIMETYPE_CNT_FSYSBOX
, // CONTENT_TYPE_X_CNT_FSYSBOX
284 STR_SVT_MIMETYPE_CNT_FSYSFLD
, // CONTENT_TYPE_X_CNT_FSYSFOLDER
285 STR_SVT_MIMETYPE_X_STARMAIL
, // CONTENT_TYPE_X_STARMAIL
286 STR_SVT_MIMETYPE_X_VRML
, // CONTENT_TYPE_X_VRML
287 STR_SVT_MIMETYPE_APP_GAL
, // CONTENT_TYPE_APP_GALLERY
288 STR_SVT_MIMETYPE_APP_GAL_THEME
, // CONTENT_TYPE_APP_GALLERY_THEME
289 STR_SVT_MIMETYPE_APP_STARW_GLOB
, // CONTENT_TYPE_APP_STARWRITER_GLOB
290 STR_SVT_MIMETYPE_APP_SDM
, // CONTENT_TYPE_APP_STARMAIL_SDM
291 STR_SVT_MIMETYPE_APP_SMD
, // CONTENT_TYPE_APP_STARMAIL_SMD
292 STR_SVT_MIMETYPE_APP_STARCALC
, // CONTENT_TYPE_APP_VND_CALC
293 STR_SVT_MIMETYPE_APP_STARCHART
, // CONTENT_TYPE_APP_VND_CHART
294 STR_SVT_MIMETYPE_APP_STARDRAW
, // CONTENT_TYPE_APP_VND_DRAW
295 STR_SVT_MIMETYPE_APP_STARIMAGE
, // CONTENT_TYPE_APP_VND_IMAGE
296 STR_SVT_MIMETYPE_APP_STARIMPRESS
, // CONTENT_TYPE_APP_VND_IMPRESS
297 STR_SVT_MIMETYPE_X_STARMAIL
, // CONTENT_TYPE_APP_VND_MAIL
298 STR_SVT_MIMETYPE_APP_STARMATH
, // CONTENT_TYPE_APP_VND_MATH
299 STR_SVT_MIMETYPE_APP_STARWRITER
, // CONTENT_TYPE_APP_VND_WRITER
300 STR_SVT_MIMETYPE_APP_STARW_GLOB
, // CONTENT_TYPE_APP_VND_WRITER_GLOBAL
301 STR_SVT_MIMETYPE_APP_STARW_WEB
, // CONTENT_TYPE_APP_VND_WRITER_WEB
302 STR_SVT_MIMETYPE_FRAMESET
, // CONTENT_TYPE_APP_FRAMESET
303 STR_SVT_MIMETYPE_MACRO
, // CONTENT_TYPE_APP_MACRO
304 STR_SVT_MIMETYPE_CNT_SFSYSFOLDER
,
305 // CONTENT_TYPE_X_CNT_FSYSSPECIALFOLDER
306 STR_SVT_MIMETYPE_APP_TEMPLATE
, // CONTENT_TYPE_APP_VND_TEMPLATE
307 STR_SVT_MIMETYPE_IMAGE_GENERIC
, // CONTENT_TYPE_IMAGE_GENERIC
308 STR_SVT_MIMETYPE_X_STARMAIL
, // CONTENT_TYPE_APP_VND_NEWS
309 STR_SVT_MIMETYPE_X_STARMAIL
, // CONTENT_TYPE_APP_VND_OUTTRAY
310 STR_SVT_MIMETYPE_APP_MSEXCEL
, // CONTENT_TYPE_APP_MSEXCEL
311 STR_SVT_MIMETYPE_APP_MSEXCEL_TEMPL
, // CONTENT_TYPE_APP_MSEXCEL_TEMPL
312 STR_SVT_MIMETYPE_APP_MSPPOINT
, // CONTENT_TYPE_APP_MSPPOINT
313 STR_SVT_MIMETYPE_APP_MSPPOINT
, // CONTENT_TYPE_APP_MSPPOINT_TEMPL //@todo new presentation string?
314 STR_SVT_MIMETYPE_TEXT_VCALENDAR
, // CONTENT_TYPE_TEXT_VCALENDAR
315 STR_SVT_MIMETYPE_TEXT_ICALENDAR
, // CONTENT_TYPE_TEXT_ICALENDAR
316 STR_SVT_MIMETYPE_TEXT_XMLICALENDAR
, // CONTENT_TYPE_TEXT_XMLICALENDAR
317 STR_SVT_MIMETYPE_TEXT_CDE_CALENDAR_APP
,
318 // CONTENT_TYPE_APP_CDE_CALENDAR_APP
319 STR_SVT_MIMETYPE_INET_MSG_RFC822
, // CONTENT_TYPE_INET_MESSAGE_RFC822
320 STR_SVT_MIMETYPE_INET_MULTI_ALTERNATIVE
,
321 // CONTENT_TYPE_INET_MULTIPART_ALTERNATIVE
322 STR_SVT_MIMETYPE_INET_MULTI_DIGEST
,
323 // CONTENT_TYPE_INET_MULTIPART_DIGEST
324 STR_SVT_MIMETYPE_INET_MULTI_PARALLEL
,
325 // CONTENT_TYPE_INET_MULTIPART_PARALLEL
326 STR_SVT_MIMETYPE_INET_MULTI_RELATED
,
327 // CONTENT_TYPE_INET_MULTIPART_RELATED
328 STR_SVT_MIMETYPE_INET_MULTI_MIXED
,
329 // CONTENT_TYPE_INET_MULTIPART_MIXED
330 STR_SVT_MIMETYPE_APP_IMPRESSPACKED
,
331 // CONTENT_TYPE_APP_VND_IMPRESSPACKED
332 STR_SVT_MIMETYPE_APP_JAR
, // CONTENT_TYPE_APP_JAR
333 STR_SVT_MIMETYPE_APP_SXWRITER
, // CONTENT_TYPE_APP_VND_SUN_XML_WRITER
334 STR_SVT_MIMETYPE_APP_SXCALC
, // CONTENT_TYPE_APP_VND_SUN_XML_CALC
335 STR_SVT_MIMETYPE_APP_SXIMPRESS
, // CONTENT_TYPE_APP_VND_SUN_XML_IMPRESS
336 STR_SVT_MIMETYPE_APP_SXDRAW
, // CONTENT_TYPE_APP_VND_SUN_XML_DRAW
337 STR_SVT_MIMETYPE_APP_SXCHART
, // CONTENT_TYPE_APP_VND_SUN_XML_CHART
338 STR_SVT_MIMETYPE_APP_SXMATH
, // CONTENT_TYPE_APP_VND_SUN_XML_MATH
339 STR_SVT_MIMETYPE_APP_SXGLOBAL
, // CONTENT_TYPE_APP_VND_SUN_XML_WRITER_GLOBAL
340 STR_SVT_MIMETYPE_APP_SXIPACKED
, // CONTENT_TYPE_APP_VND_SUN_XML_IMPRESSPACKED
343 /** A mapping from extensions to type IDs. Sorted by extension.
345 MediaTypeEntry
const aStaticExtensionMap
[]
346 = { { "aif", CONTENT_TYPE_AUDIO_AIFF
, "" },
347 { "aiff", CONTENT_TYPE_AUDIO_AIFF
, "" },
348 { "appt", CONTENT_TYPE_APP_CDE_CALENDAR_APP
, "" },
349 { "au", CONTENT_TYPE_AUDIO_BASIC
, "" },
350 { "avi", CONTENT_TYPE_VIDEO_MSVIDEO
, "" },
351 { "bmp", CONTENT_TYPE_IMAGE_BMP
, "" },
352 { "cgm", CONTENT_TYPE_IMAGE_GENERIC
, "" },
353 { "doc", CONTENT_TYPE_APP_MSWORD
, "" },
354 { "dot", CONTENT_TYPE_APP_MSWORD_TEMPL
, "" },
355 { "dxf", CONTENT_TYPE_IMAGE_GENERIC
, "" },
356 { "eps", CONTENT_TYPE_IMAGE_GENERIC
, "" },
357 { "gal", CONTENT_TYPE_APP_GALLERY
, "" },
358 { "gif", CONTENT_TYPE_IMAGE_GIF
, "" },
359 { "htm", CONTENT_TYPE_TEXT_HTML
, "" },
360 { "html", CONTENT_TYPE_TEXT_HTML
, "" },
361 { "ics", CONTENT_TYPE_TEXT_ICALENDAR
, "" },
362 { "jar", CONTENT_TYPE_APP_JAR
, "" },
363 { "jpeg", CONTENT_TYPE_IMAGE_JPEG
, "" },
364 { "jpg", CONTENT_TYPE_IMAGE_JPEG
, "" },
365 { "met", CONTENT_TYPE_IMAGE_GENERIC
, "" },
366 { "mid", CONTENT_TYPE_AUDIO_MIDI
, "" },
367 { "midi", CONTENT_TYPE_AUDIO_MIDI
, "" },
368 { "ogg", CONTENT_TYPE_AUDIO_VORBIS
, "" },
369 { "pbm", CONTENT_TYPE_IMAGE_GENERIC
, "" },
370 { "pcd", CONTENT_TYPE_IMAGE_GENERIC
, "" },
371 { "pct", CONTENT_TYPE_IMAGE_GENERIC
, "" },
372 { "pcx", CONTENT_TYPE_IMAGE_PCX
, "" },
373 { "pdf", CONTENT_TYPE_APP_PDF
, "" },
374 { "pgm", CONTENT_TYPE_IMAGE_GENERIC
, "" },
375 { "png", CONTENT_TYPE_IMAGE_PNG
, "" },
376 { "pot", CONTENT_TYPE_APP_MSPPOINT_TEMPL
, "" },
377 { "ppm", CONTENT_TYPE_IMAGE_GENERIC
, "" },
378 { "ppt", CONTENT_TYPE_APP_MSPPOINT
, "" },
379 { "psd", CONTENT_TYPE_IMAGE_GENERIC
, "" },
380 { "ras", CONTENT_TYPE_IMAGE_GENERIC
, "" },
381 { "rtf", CONTENT_TYPE_APP_RTF
, "" },
382 { "sda", CONTENT_TYPE_APP_VND_DRAW
, "" },
383 { "sdc", CONTENT_TYPE_APP_VND_CALC
, "" },
384 { "sdd", CONTENT_TYPE_APP_VND_IMPRESS
, "" },
385 { "sdm", CONTENT_TYPE_APP_VND_MAIL
, "" },
386 { "sdp", CONTENT_TYPE_APP_VND_IMPRESSPACKED
, "" },
387 { "sds", CONTENT_TYPE_APP_VND_CHART
, "" },
388 { "sdw", CONTENT_TYPE_APP_VND_WRITER
, "" },
389 { "sd~", CONTENT_TYPE_X_STARMAIL
, "" },
390 { "sfs", CONTENT_TYPE_APP_FRAMESET
, "" },
391 { "sgl", CONTENT_TYPE_APP_VND_WRITER_GLOBAL
, "" },
392 { "sim", CONTENT_TYPE_APP_VND_IMAGE
, "" },
393 { "smd", CONTENT_TYPE_APP_STARMAIL_SMD
, "" }, //CONTENT_TYPE_X_STARMAIL
394 { "smf", CONTENT_TYPE_APP_VND_MATH
, "" },
395 { "svh", CONTENT_TYPE_APP_STARHELP
, "" },
396 { "svm", CONTENT_TYPE_IMAGE_GENERIC
, "" },
397 { "sxc", CONTENT_TYPE_APP_VND_SUN_XML_CALC
, "" },
398 { "sxd", CONTENT_TYPE_APP_VND_SUN_XML_DRAW
, "" },
399 { "sxg", CONTENT_TYPE_APP_VND_SUN_XML_WRITER_GLOBAL
, "" },
400 { "sxi", CONTENT_TYPE_APP_VND_SUN_XML_IMPRESS
, "" },
401 { "sxm", CONTENT_TYPE_APP_VND_SUN_XML_MATH
, "" },
402 { "sxp", CONTENT_TYPE_APP_VND_SUN_XML_IMPRESSPACKED
, "" },
403 { "sxs", CONTENT_TYPE_APP_VND_SUN_XML_CHART
, "" },
404 { "sxw", CONTENT_TYPE_APP_VND_SUN_XML_WRITER
, "" },
405 { "tga", CONTENT_TYPE_IMAGE_GENERIC
, "" },
406 { "thm", CONTENT_TYPE_APP_GALLERY_THEME
, "" },
407 { "tif", CONTENT_TYPE_IMAGE_TIFF
, "" },
408 { "tiff", CONTENT_TYPE_IMAGE_TIFF
, "" },
409 { "txt", CONTENT_TYPE_TEXT_PLAIN
, "" },
410 { "url", CONTENT_TYPE_TEXT_URL
, "" },
411 { "vcf", CONTENT_TYPE_TEXT_VCARD
, "" },
412 { "vcs", CONTENT_TYPE_TEXT_VCALENDAR
, "" },
413 { "vdo", CONTENT_TYPE_VIDEO_VDO
, "" },
414 { "vor", CONTENT_TYPE_APP_VND_TEMPLATE
, "" },
415 { "wav", CONTENT_TYPE_AUDIO_WAV
, "" },
416 { "webm", CONTENT_TYPE_VIDEO_WEBM
, "" },
417 { "wmf", CONTENT_TYPE_IMAGE_GENERIC
, "" },
418 { "wrl", CONTENT_TYPE_X_VRML
, "" },
419 { "xbm", CONTENT_TYPE_IMAGE_GENERIC
, "" },
420 { "xcs", CONTENT_TYPE_TEXT_XMLICALENDAR
, "" },
421 { "xls", CONTENT_TYPE_APP_MSEXCEL
, "" },
422 { "xlt", CONTENT_TYPE_APP_MSEXCEL_TEMPL
, "" },
423 { "xlw", CONTENT_TYPE_APP_MSEXCEL
, "" },
424 { "xpm", CONTENT_TYPE_IMAGE_GENERIC
, "" },
425 { "zip", CONTENT_TYPE_APP_ZIP
, "" } };
433 Registration::~Registration()
435 for ( TypeIDMap::iterator it
= m_aTypeIDMap
.begin(); it
!= m_aTypeIDMap
.end(); ++it
)
440 TypeNameMapEntry
* Registration::getExtensionEntry(OUString
const & rTypeName
)
442 OUString aTheTypeName
= rTypeName
.toAsciiLowerCase();;
443 Registration
&rRegistration
= theRegistration::get();
444 TypeNameMap::iterator it
= rRegistration
.m_aTypeNameMap
.find(aTheTypeName
);
445 if (it
!= rRegistration
.m_aTypeNameMap
.end())
451 INetContentType
Registration::RegisterContentType(OUString
const & rTypeName
,
452 OUString
const & rPresentation
,
453 OUString
const * pExtension
,
454 OUString
const * pSystemFileType
)
456 Registration
&rRegistration
= theRegistration::get();
458 DBG_ASSERT(GetContentType(rTypeName
) == CONTENT_TYPE_UNKNOWN
,
459 "Registration::RegisterContentType(): Already registered");
461 INetContentType eTypeID
= INetContentType(rRegistration
.m_nNextDynamicID
++);
462 OUString aTheTypeName
= rTypeName
.toAsciiLowerCase();
464 TypeIDMapEntry
* pTypeIDMapEntry
= new TypeIDMapEntry
;
465 pTypeIDMapEntry
->m_aTypeName
= aTheTypeName
;
466 pTypeIDMapEntry
->m_aPresentation
= rPresentation
;
468 pTypeIDMapEntry
->m_aSystemFileType
= *pSystemFileType
;
469 rRegistration
.m_aTypeIDMap
.insert( ::std::make_pair( eTypeID
, pTypeIDMapEntry
) );
471 std::unique_ptr
<TypeNameMapEntry
> pTypeNameMapEntry(new TypeNameMapEntry());
473 pTypeNameMapEntry
->m_aExtension
= *pExtension
;
474 pTypeNameMapEntry
->m_eTypeID
= eTypeID
;
475 o3tl::ptr_container::insert(
476 rRegistration
.m_aTypeNameMap
, aTheTypeName
,
477 std::move(pTypeNameMapEntry
));
481 std::unique_ptr
<ExtensionMapEntry
> pExtensionMapEntry(new ExtensionMapEntry());
482 pExtensionMapEntry
->m_eTypeID
= eTypeID
;
483 o3tl::ptr_container::insert(
484 rRegistration
.m_aExtensionMap
, *pExtension
,
485 std::move(pExtensionMapEntry
));
492 INetContentType
Registration::GetContentType(OUString
const & rTypeName
)
494 Registration
&rRegistration
= theRegistration::get();
496 OUString aTheTypeName
= rTypeName
.toAsciiLowerCase();
497 TypeNameMap::iterator it
= rRegistration
.m_aTypeNameMap
.find(aTheTypeName
);
498 return it
!= rRegistration
.m_aTypeNameMap
.end()
499 ? it
->second
->m_eTypeID
500 : CONTENT_TYPE_UNKNOWN
;
504 OUString
Registration::GetContentType(INetContentType eTypeID
)
506 Registration
&rRegistration
= theRegistration::get();
508 TypeIDMap::iterator pEntry
= rRegistration
.m_aTypeIDMap
.find( eTypeID
);
509 if( pEntry
!= rRegistration
.m_aTypeIDMap
.end() )
510 return pEntry
->second
->m_aTypeName
;
515 OUString
Registration::GetPresentation(INetContentType eTypeID
)
517 Registration
&rRegistration
= theRegistration::get();
519 TypeIDMap::iterator pEntry
= rRegistration
.m_aTypeIDMap
.find( eTypeID
);
520 if( pEntry
!= rRegistration
.m_aTypeIDMap
.end() )
521 return pEntry
->second
->m_aPresentation
;
527 INetContentType
Registration::GetContentType4Extension(OUString
const & rExtension
)
529 Registration
&rRegistration
= theRegistration::get();
531 ExtensionMap::iterator it
= rRegistration
.m_aExtensionMap
.find(rExtension
);
532 return it
!= rRegistration
.m_aExtensionMap
.end()
533 ? it
->second
->m_eTypeID
534 : CONTENT_TYPE_UNKNOWN
;
544 MediaTypeEntry
const * seekEntry(OUString
const & rTypeName
,
545 MediaTypeEntry
const * pMap
, sal_Size nSize
)
548 for (sal_Size i
= 0; i
< nSize
- 1; ++i
)
551 pMap
[i
].m_pTypeName
, pMap
[i
+ 1].m_pTypeName
) < 0,
552 "seekEntry(): Bad map");
556 sal_Size nHigh
= nSize
;
557 while (nLow
!= nHigh
)
559 sal_Size nMiddle
= (nLow
+ nHigh
) / 2;
560 MediaTypeEntry
const * pEntry
= pMap
+ nMiddle
;
561 sal_Int32 nCmp
= rTypeName
.compareToIgnoreAsciiCaseAscii(pEntry
->m_pTypeName
);
576 INetContentType
INetContentTypes::RegisterContentType(OUString
const & rTypeName
,
577 OUString
const & rPresentation
,
578 OUString
const * pExtension
,
579 OUString
const * pSystemFileType
)
581 INetContentType eTypeID
= GetContentType(rTypeName
);
582 if (eTypeID
== CONTENT_TYPE_UNKNOWN
)
583 eTypeID
= Registration::RegisterContentType(rTypeName
, rPresentation
,
586 else if (eTypeID
> CONTENT_TYPE_LAST
)
588 TypeIDMapEntry
* pTypeEntry
= Registration::getEntry(eTypeID
);
591 if (!rPresentation
.isEmpty())
592 pTypeEntry
->m_aPresentation
= rPresentation
;
594 pTypeEntry
->m_aSystemFileType
= *pSystemFileType
;
598 TypeNameMapEntry
* pEntry
= Registration::getExtensionEntry(rTypeName
);
600 pEntry
->m_aExtension
= *pExtension
;
607 INetContentType
INetContentTypes::GetContentType(OUString
const & rTypeName
)
611 if (parse(rTypeName
, aType
, aSubType
))
615 MediaTypeEntry
const * pEntry
= seekEntry(aType
, aStaticTypeNameMap
,
616 CONTENT_TYPE_LAST
+ 1);
617 return pEntry
? pEntry
->m_eTypeID
: Registration::GetContentType(aType
);
620 return rTypeName
.equalsIgnoreAsciiCase(CONTENT_TYPE_STR_X_STARMAIL
) ?
621 CONTENT_TYPE_X_STARMAIL
: CONTENT_TYPE_UNKNOWN
;
622 // the content type "x-starmail" has no sub type
626 OUString
INetContentTypes::GetContentType(INetContentType eTypeID
)
628 static sal_Char
const * aMap
[CONTENT_TYPE_LAST
+ 1];
629 static bool bInitialized
= false;
632 for (sal_Size i
= 0; i
<= CONTENT_TYPE_LAST
; ++i
)
633 aMap
[aStaticTypeNameMap
[i
].m_eTypeID
] = aStaticTypeNameMap
[i
].m_pTypeName
;
634 aMap
[CONTENT_TYPE_UNKNOWN
] = CONTENT_TYPE_STR_APP_OCTSTREAM
;
635 aMap
[CONTENT_TYPE_TEXT_PLAIN
] = CONTENT_TYPE_STR_TEXT_PLAIN
636 "; charset=iso-8859-1";
640 OUString aTypeName
= eTypeID
<= CONTENT_TYPE_LAST
? OUString::createFromAscii(aMap
[eTypeID
])
641 : Registration::GetContentType(eTypeID
);
642 if (aTypeName
.isEmpty())
644 OSL_FAIL("INetContentTypes::GetContentType(): Bad ID");
645 return OUString(CONTENT_TYPE_STR_APP_OCTSTREAM
);
651 OUString
INetContentTypes::GetPresentation(INetContentType eTypeID
,
652 const LanguageTag
& aLocale
)
654 sal_uInt16 nResID
= sal_uInt16();
655 if (eTypeID
<= CONTENT_TYPE_LAST
)
656 nResID
= aStaticResourceIDMap
[eTypeID
];
659 OUString aPresentation
= Registration::GetPresentation(eTypeID
);
660 if (aPresentation
.isEmpty())
661 nResID
= STR_SVT_MIMETYPE_APP_OCTSTREAM
;
663 return aPresentation
;
665 return svl::getStringResource(nResID
, aLocale
);
669 INetContentType
INetContentTypes::GetContentType4Extension(OUString
const & rExtension
)
671 MediaTypeEntry
const * pEntry
= seekEntry(rExtension
, aStaticExtensionMap
,
672 sizeof aStaticExtensionMap
/ sizeof (MediaTypeEntry
));
674 return pEntry
->m_eTypeID
;
675 INetContentType eTypeID
= Registration::GetContentType4Extension(rExtension
);
676 return eTypeID
== CONTENT_TYPE_UNKNOWN
? CONTENT_TYPE_APP_OCTSTREAM
681 INetContentType
INetContentTypes::GetContentTypeFromURL(OUString
const & rURL
)
683 INetContentType eTypeID
= CONTENT_TYPE_UNKNOWN
;
684 OUString aToken
= rURL
.getToken(0, ':');
685 if (!aToken
.isEmpty())
687 if (aToken
.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_FILE
))
688 if (rURL
[ rURL
.getLength() - 1 ] == (sal_Unicode
)'/') // folder
689 if (rURL
.getLength() > RTL_CONSTASCII_LENGTH("file:///"))
690 if (WildCard("*/{*}/").Matches(rURL
)) // special folder
691 eTypeID
= CONTENT_TYPE_X_CNT_FSYSSPECIALFOLDER
;
693 // drive? -> "file:///?|/"
694 if (rURL
.getLength() == 11
695 && rURL
[ rURL
.getLength() - 2 ] == '|')
697 // Drives need further processing, because of
698 // dynamic type according to underlying volume,
699 // which cannot be determined here.
701 else // normal folder
702 eTypeID
= CONTENT_TYPE_X_CNT_FSYSFOLDER
;
703 else // file system root
704 eTypeID
= CONTENT_TYPE_X_CNT_FSYSBOX
;
709 else if (aToken
.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_HTTP
)
710 || aToken
.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_HTTPS
))
711 eTypeID
= CONTENT_TYPE_TEXT_HTML
;
712 else if (aToken
.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_PRIVATE
))
714 OUString aSecondPart
= rURL
.getToken(1, ':');
715 aToken
= aSecondPart
.getToken(0, '/');
716 if (aToken
== "factory")
718 aToken
= aSecondPart
.getToken(1, '/');
719 if (aToken
== "swriter")
721 aToken
= aSecondPart
.getToken(2, '/');
722 eTypeID
= aToken
== "web" ?
723 CONTENT_TYPE_APP_VND_WRITER_WEB
:
724 aToken
== "GlobalDocument" ?
725 CONTENT_TYPE_APP_VND_WRITER_GLOBAL
:
726 CONTENT_TYPE_APP_VND_WRITER
;
728 else if (aToken
== "scalc")
729 eTypeID
= CONTENT_TYPE_APP_VND_CALC
;
730 else if (aToken
== "sdraw")
731 eTypeID
= CONTENT_TYPE_APP_VND_DRAW
;
732 else if (aToken
== "simpress")
733 eTypeID
= CONTENT_TYPE_APP_VND_IMPRESS
;
734 else if (aToken
== "schart")
735 eTypeID
= CONTENT_TYPE_APP_VND_CHART
;
736 else if (aToken
== "simage")
737 eTypeID
= CONTENT_TYPE_APP_VND_IMAGE
;
738 else if (aToken
== "smath")
739 eTypeID
= CONTENT_TYPE_APP_VND_MATH
;
740 else if (aToken
== "frameset")
741 eTypeID
= CONTENT_TYPE_APP_FRAMESET
;
743 else if (aToken
== "helpid")
744 eTypeID
= CONTENT_TYPE_APP_STARHELP
;
746 else if (aToken
.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_MAILTO
))
747 eTypeID
= CONTENT_TYPE_APP_VND_OUTTRAY
;
748 else if (aToken
.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_MACRO
))
749 eTypeID
= CONTENT_TYPE_APP_MACRO
;
750 else if (aToken
.equalsIgnoreAsciiCase(INETTYPE_URL_PROT_DATA
))
752 OUString aSecondPart
= rURL
.getToken(1, ':');
753 aToken
= aSecondPart
.getToken(0, ',');
754 eTypeID
= GetContentType(aToken
);
757 if (eTypeID
== CONTENT_TYPE_UNKNOWN
)
760 if (GetExtensionFromURL(rURL
, aExtension
))
761 eTypeID
= GetContentType4Extension(aExtension
);
767 bool INetContentTypes::GetExtensionFromURL(OUString
const & rURL
,
768 OUString
& rExtension
)
770 sal_Int32 nSlashPos
= 0;
775 i
= rURL
.indexOf((sal_Unicode
)'/', i
+ 1);
779 sal_Int32 nLastDotPos
= i
= rURL
.indexOf((sal_Unicode
)'.', nSlashPos
);
783 i
= rURL
.indexOf((sal_Unicode
)'.', i
+ 1);
785 if (nLastDotPos
>- 0)
786 rExtension
= rURL
.copy(nLastDotPos
+ 1);
792 bool INetContentTypes::parse(
793 OUString
const & rMediaType
, OUString
& rType
, OUString
& rSubType
,
794 INetContentTypeParameterList
* pParameters
)
796 sal_Unicode
const * b
= rMediaType
.getStr();
797 sal_Unicode
const * e
= b
+ rMediaType
.getLength();
800 INetContentTypeParameterList p
;
801 if (INetMIME::scanContentType(b
, e
, &t
, &s
, pParameters
== 0 ? 0 : &p
) == e
) {
804 if (pParameters
!= 0) {
813 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */