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: fileextensions.cxx,v $
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_shell.hxx"
33 #include "internal/fileextensions.hxx"
35 //------------------------------------
37 //------------------------------------
39 const std::string WRITER_FILE_EXTENSIONS
= "sxwstwsxgodtottodm";
40 const std::string CALC_FILE_EXTENSIONS
= "sxcstcodsots";
41 const std::string DRAW_FILE_EXTENSIONS
= "sxdstdodgotg";
42 const std::string IMPRESS_FILE_EXTENSIONS
= "sxistiodpotp";
43 const std::string MATH_FILE_EXTENSIONS
= "sxmodf";
44 const std::string WEB_FILE_EXTENSIONS
= "oth";
45 const std::string DATABASE_FILE_EXTENSIONS
= "odb";
47 FileExtensionEntry OOFileExtensionTable
[] = {
48 { ".sxw", L
".sxw", "soffice.StarWriterDocument.6" },
49 { ".sxc", L
".sxc", "soffice.StarCalcDocument.6" },
50 { ".sxi", L
".sxi", "soffice.StarImpressDocument.6" },
51 { ".sxd", L
".sxd", "soffice.StarDrawDocument.6" },
52 { ".sxm", L
".sxm", "soffice.StarMathDocument.6" },
53 { ".stw", L
".stw", "soffice.StarWriterTemplate.6" },
54 { ".sxg", L
".sxg", "soffice.StarWriterGlobalDocument.6"},
55 { ".std", L
".std", "soffice.StarDrawTemplate.6" },
56 { ".sti", L
".sti", "soffice.StarImpressTemplate.6" },
57 { ".stc", L
".stc", "soffice.StarCalcTemplate.6" },
58 { ".odt", L
".odt", "opendocument.WriterDocument.1" },
59 { ".ott", L
".ott", "opendocument.WriterTemplate.1" },
60 { ".odm", L
".odm", "opendocument.WriterGlobalDocument.1" },
61 { ".oth", L
".oth", "opendocument.WriterWebTemplate.1" },
62 { ".ods", L
".ods", "opendocument.CalcDocument.1" },
63 { ".ots", L
".ots", "opendocument.CalcTemplate.1" },
64 { ".odg", L
".odg", "opendocument.DrawDocument.1" },
65 { ".otg", L
".otg", "opendocument.DrawTemplate.1" },
66 { ".odp", L
".odp", "opendocument.ImpressDocument.1" },
67 { ".otp", L
".otp", "opendocument.ImpressTemplate.1" },
68 { ".odf", L
".odf", "opendocument.MathDocument.1" },
69 { ".odb", L
".odb", "opendocument.DatabaseDocument.1" }
73 size_t OOFileExtensionTableSize
= sizeof(OOFileExtensionTable
)/sizeof(OOFileExtensionTable
[0]);
75 //---------------------------------
76 /** Return the extension of a file
79 std::string
get_file_name_extension(const std::string
& file_name
)
81 std::string::size_type idx
= file_name
.find_last_of(".");
83 if (std::string::npos
!= idx
++)
84 return std::string(file_name
.begin() + idx
, file_name
.end());
89 //---------------------------------
90 /** Return the type of a file
93 File_Type_t
get_file_type(const std::string
& file_name
)
95 std::string fext
= get_file_name_extension(file_name
);
97 if (std::string::npos
!= WRITER_FILE_EXTENSIONS
.find(fext
))
99 else if (std::string::npos
!= CALC_FILE_EXTENSIONS
.find(fext
))
101 else if (std::string::npos
!= DRAW_FILE_EXTENSIONS
.find(fext
))
103 else if (std::string::npos
!= IMPRESS_FILE_EXTENSIONS
.find(fext
))
105 else if (std::string::npos
!= MATH_FILE_EXTENSIONS
.find(fext
))
107 else if (std::string::npos
!= WEB_FILE_EXTENSIONS
.find(fext
))
109 else if (std::string::npos
!= DATABASE_FILE_EXTENSIONS
.find(fext
))