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