1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_shell.hxx" 30 #include "algorithm" 31 #include "internal/fileextensions.hxx" 32 33 //------------------------------------ 34 // 35 //------------------------------------ 36 37 const std::string WRITER_FILE_EXTENSIONS = "sxwstwsxgodtottodm"; 38 const std::string CALC_FILE_EXTENSIONS = "sxcstcodsots"; 39 const std::string DRAW_FILE_EXTENSIONS = "sxdstdodgotg"; 40 const std::string IMPRESS_FILE_EXTENSIONS = "sxistiodpotp"; 41 const std::string MATH_FILE_EXTENSIONS = "sxmodf"; 42 const std::string WEB_FILE_EXTENSIONS = "oth"; 43 const std::string DATABASE_FILE_EXTENSIONS = "odb"; 44 45 FileExtensionEntry OOFileExtensionTable[] = { 46 { ".sxw", L".sxw", "soffice.StarWriterDocument.6" }, 47 { ".sxc", L".sxc", "soffice.StarCalcDocument.6" }, 48 { ".sxi", L".sxi", "soffice.StarImpressDocument.6" }, 49 { ".sxd", L".sxd", "soffice.StarDrawDocument.6" }, 50 { ".sxm", L".sxm", "soffice.StarMathDocument.6" }, 51 { ".stw", L".stw", "soffice.StarWriterTemplate.6" }, 52 { ".sxg", L".sxg", "soffice.StarWriterGlobalDocument.6"}, 53 { ".std", L".std", "soffice.StarDrawTemplate.6" }, 54 { ".sti", L".sti", "soffice.StarImpressTemplate.6" }, 55 { ".stc", L".stc", "soffice.StarCalcTemplate.6" }, 56 { ".odt", L".odt", "opendocument.WriterDocument.1" }, 57 { ".ott", L".ott", "opendocument.WriterTemplate.1" }, 58 { ".odm", L".odm", "opendocument.WriterGlobalDocument.1" }, 59 { ".oth", L".oth", "opendocument.WriterWebTemplate.1" }, 60 { ".ods", L".ods", "opendocument.CalcDocument.1" }, 61 { ".ots", L".ots", "opendocument.CalcTemplate.1" }, 62 { ".odg", L".odg", "opendocument.DrawDocument.1" }, 63 { ".otg", L".otg", "opendocument.DrawTemplate.1" }, 64 { ".odp", L".odp", "opendocument.ImpressDocument.1" }, 65 { ".otp", L".otp", "opendocument.ImpressTemplate.1" }, 66 { ".odf", L".odf", "opendocument.MathDocument.1" }, 67 { ".odb", L".odb", "opendocument.DatabaseDocument.1" } 68 }; 69 70 71 size_t OOFileExtensionTableSize = sizeof(OOFileExtensionTable)/sizeof(OOFileExtensionTable[0]); 72 73 //--------------------------------- 74 /** Return the extension of a file 75 name without the '.' 76 */ 77 std::string get_file_name_extension(const std::string& file_name) 78 { 79 std::string::size_type idx = file_name.find_last_of("."); 80 81 if (std::string::npos != idx++) 82 return std::string(file_name.begin() + idx, file_name.end()); 83 84 return std::string(); 85 } 86 87 //--------------------------------- 88 /** Return the type of a file 89 */ 90 91 char easytolower( char in ) 92 { 93 if( in<='Z' && in>='A' ) 94 return in-('Z'-'z'); 95 return in; 96 } 97 98 File_Type_t get_file_type(const std::string& file_name) 99 { 100 std::string fext = get_file_name_extension(file_name); 101 std::transform(fext.begin(), fext.end(), fext.begin(), easytolower); 102 103 if (std::string::npos != WRITER_FILE_EXTENSIONS.find(fext)) 104 return WRITER; 105 else if (std::string::npos != CALC_FILE_EXTENSIONS.find(fext)) 106 return CALC; 107 else if (std::string::npos != DRAW_FILE_EXTENSIONS.find(fext)) 108 return DRAW; 109 else if (std::string::npos != IMPRESS_FILE_EXTENSIONS.find(fext)) 110 return IMPRESS; 111 else if (std::string::npos != MATH_FILE_EXTENSIONS.find(fext)) 112 return MATH; 113 else if (std::string::npos != WEB_FILE_EXTENSIONS.find(fext)) 114 return WEB; 115 else if (std::string::npos != DATABASE_FILE_EXTENSIONS.find(fext)) 116 return DATABASE; 117 else 118 return UNKNOWN; 119 } 120 121