1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_shell.hxx"
26 #include "algorithm"
27 #include "internal/fileextensions.hxx"
28 
29 //------------------------------------
30 //
31 //------------------------------------
32 
33 const std::string WRITER_FILE_EXTENSIONS   = "sxwstwsxgodtottodm";
34 const std::string CALC_FILE_EXTENSIONS     = "sxcstcodsots";
35 const std::string DRAW_FILE_EXTENSIONS     = "sxdstdodgotg";
36 const std::string IMPRESS_FILE_EXTENSIONS  = "sxistiodpotp";
37 const std::string MATH_FILE_EXTENSIONS     = "sxmodf";
38 const std::string WEB_FILE_EXTENSIONS      = "oth";
39 const std::string DATABASE_FILE_EXTENSIONS = "odb";
40 
41 FileExtensionEntry OOFileExtensionTable[] = {
42 	{ ".sxw", L".sxw", "soffice.StarWriterDocument.6"        },
43 	{ ".sxc", L".sxc", "soffice.StarCalcDocument.6"          },
44 	{ ".sxi", L".sxi", "soffice.StarImpressDocument.6"       },
45 	{ ".sxd", L".sxd", "soffice.StarDrawDocument.6"          },
46 	{ ".sxm", L".sxm", "soffice.StarMathDocument.6"          },
47 	{ ".stw", L".stw", "soffice.StarWriterTemplate.6"        },
48 	{ ".sxg", L".sxg", "soffice.StarWriterGlobalDocument.6"  },
49 	{ ".std", L".std", "soffice.StarDrawTemplate.6"          },
50 	{ ".sti", L".sti", "soffice.StarImpressTemplate.6"       },
51 	{ ".stc", L".stc", "soffice.StarCalcTemplate.6"          },
52 	{ ".odt", L".odt", "opendocument.WriterDocument.1"       },
53 	{ ".ott", L".ott", "opendocument.WriterTemplate.1"       },
54 	{ ".odm", L".odm", "opendocument.WriterGlobalDocument.1" },
55 	{ ".oth", L".oth", "opendocument.WriterWebTemplate.1"    },
56 	{ ".ods", L".ods", "opendocument.CalcDocument.1"         },
57 	{ ".ots", L".ots", "opendocument.CalcTemplate.1"         },
58 	{ ".odg", L".odg", "opendocument.DrawDocument.1"         },
59 	{ ".otg", L".otg", "opendocument.DrawTemplate.1"         },
60 	{ ".odp", L".odp", "opendocument.ImpressDocument.1"      },
61 	{ ".otp", L".otp", "opendocument.ImpressTemplate.1"      },
62 	{ ".odf", L".odf", "opendocument.MathDocument.1"         },
63 	{ ".odb", L".odb", "opendocument.DatabaseDocument.1"     }
64 	};
65 
66 
67 size_t OOFileExtensionTableSize = sizeof(OOFileExtensionTable)/sizeof(OOFileExtensionTable[0]);
68 
69 //---------------------------------
70 /** Return the extension of a file
71 	name without the '.'
72 */
get_file_name_extension(const std::string & file_name)73 std::string get_file_name_extension(const std::string& file_name)
74 {
75 	std::string::size_type idx = file_name.find_last_of(".");
76 
77 	if (std::string::npos != idx++)
78 		return std::string(file_name.begin() + idx, file_name.end());
79 
80 	return std::string();
81 }
82 
83 //---------------------------------
84 /** Return the type of a file
85 */
86 
easytolower(char in)87 char easytolower( char in )
88 {
89 	if( in<='Z' && in>='A' )
90 		return in-('Z'-'z');
91 	return in;
92 }
93 
get_file_type(const std::string & file_name)94 File_Type_t get_file_type(const std::string& file_name)
95 {
96 	std::string fext = get_file_name_extension(file_name);
97 	std::transform(fext.begin(), fext.end(), fext.begin(), easytolower);
98 
99 	if (std::string::npos != WRITER_FILE_EXTENSIONS.find(fext))
100 		return WRITER;
101 	else if (std::string::npos != CALC_FILE_EXTENSIONS.find(fext))
102 		return CALC;
103 	else if (std::string::npos != DRAW_FILE_EXTENSIONS.find(fext))
104 		return DRAW;
105 	else if (std::string::npos != IMPRESS_FILE_EXTENSIONS.find(fext))
106 		return IMPRESS;
107 	else if (std::string::npos != MATH_FILE_EXTENSIONS.find(fext))
108 		return MATH;
109 	else if (std::string::npos != WEB_FILE_EXTENSIONS.find(fext))
110 		return WEB;
111 	else if (std::string::npos != DATABASE_FILE_EXTENSIONS.find(fext))
112 		return DATABASE;
113 	else
114 		return UNKNOWN;
115 }
116 
117 /* vim: set noet sw=4 ts=4: */
118