xref: /trunk/main/shell/source/win32/shlxthandler/util/fileextensions.cxx (revision 0ba0bc4aae3d6774eb9ed9cba4036e1ea29e2025)
1f8e2c85aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
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
10cdf0e10cSrcweir  *
11f8e2c85aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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";
34cdf0e10cSrcweir 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";
40cdf0e10cSrcweir 
41cdf0e10cSrcweir FileExtensionEntry OOFileExtensionTable[] = {
42cdf0e10cSrcweir     { ".sxw", L".sxw", "soffice.StarWriterDocument.6"        },
43cdf0e10cSrcweir     { ".sxc", L".sxc", "soffice.StarCalcDocument.6"          },
44cdf0e10cSrcweir     { ".sxi", L".sxi", "soffice.StarImpressDocument.6"       },
45cdf0e10cSrcweir     { ".sxd", L".sxd", "soffice.StarDrawDocument.6"          },
46cdf0e10cSrcweir     { ".sxm", L".sxm", "soffice.StarMathDocument.6"          },
47cdf0e10cSrcweir     { ".stw", L".stw", "soffice.StarWriterTemplate.6"        },
48cdf0e10cSrcweir     { ".sxg", L".sxg", "soffice.StarWriterGlobalDocument.6"  },
49cdf0e10cSrcweir     { ".std", L".std", "soffice.StarDrawTemplate.6"          },
50cdf0e10cSrcweir     { ".sti", L".sti", "soffice.StarImpressTemplate.6"       },
51cdf0e10cSrcweir     { ".stc", L".stc", "soffice.StarCalcTemplate.6"          },
52cdf0e10cSrcweir     { ".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"    },
56cdf0e10cSrcweir     { ".ods", L".ods", "opendocument.CalcDocument.1"         },
57cdf0e10cSrcweir     { ".ots", L".ots", "opendocument.CalcTemplate.1"         },
58cdf0e10cSrcweir     { ".odg", L".odg", "opendocument.DrawDocument.1"         },
59cdf0e10cSrcweir     { ".otg", L".otg", "opendocument.DrawTemplate.1"         },
60cdf0e10cSrcweir     { ".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"     }
64cdf0e10cSrcweir     };
65cdf0e10cSrcweir 
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 {
89cdf0e10cSrcweir     if( in<='Z' && in>='A' )
90cdf0e10cSrcweir         return in-('Z'-'z');
91cdf0e10cSrcweir     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 {
96cdf0e10cSrcweir     std::string fext = get_file_name_extension(file_name);
97cdf0e10cSrcweir     std::transform(fext.begin(), fext.end(), fext.begin(), easytolower);
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     if (std::string::npos != WRITER_FILE_EXTENSIONS.find(fext))
100cdf0e10cSrcweir         return WRITER;
101cdf0e10cSrcweir     else if (std::string::npos != CALC_FILE_EXTENSIONS.find(fext))
102cdf0e10cSrcweir         return CALC;
103cdf0e10cSrcweir     else if (std::string::npos != DRAW_FILE_EXTENSIONS.find(fext))
104cdf0e10cSrcweir         return DRAW;
105cdf0e10cSrcweir     else if (std::string::npos != IMPRESS_FILE_EXTENSIONS.find(fext))
106cdf0e10cSrcweir         return IMPRESS;
107cdf0e10cSrcweir     else if (std::string::npos != MATH_FILE_EXTENSIONS.find(fext))
108cdf0e10cSrcweir         return MATH;
109cdf0e10cSrcweir     else if (std::string::npos != WEB_FILE_EXTENSIONS.find(fext))
110cdf0e10cSrcweir         return WEB;
111cdf0e10cSrcweir     else if (std::string::npos != DATABASE_FILE_EXTENSIONS.find(fext))
112cdf0e10cSrcweir         return DATABASE;
113cdf0e10cSrcweir     else
114cdf0e10cSrcweir         return UNKNOWN;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117*0ba0bc4aSmseidel /* vim: set noet sw=4 ts=4: */
118