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