OSDN Git Service

git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core@2953 ae02f08e...
[xerial/xerial-core.git] / src / main / java / org / xerial / util / FileType.java
1 /*--------------------------------------------------------------------------
2  *  Copyright 2009 Taro L. Saito
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *--------------------------------------------------------------------------*/
16 //--------------------------------------
17 // XerialJ
18 //
19 // FileType.java
20 // Since: Feb 10, 2009 10:38:10 AM
21 //
22 // $URL$
23 // $Author$
24 //--------------------------------------
25 package org.xerial.util;
26
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
30
31 /**
32  * File type notation
33  * 
34  * @author leo
35  * 
36  */
37 public enum FileType {
38
39     // image formats
40     JPEG("jpeg,jpg"),
41     PNG("png"),
42     GIF("gif"),
43     BMP("bmp"),
44     TIFF("tiff"),
45
46     // text formats
47     XML("xml"),
48     JSON("json"),
49     SILK("silk"),
50     TAB("tab"),
51     CSV("csv"),
52     FASTA("fasta"),
53     TEX("tex"),
54     TEXT("txt"),
55
56     // HTML formats
57     HTML("html,htm"),
58
59     // binary format
60     PDF("pdf"),
61     WORD("doc,docx"),
62     EXCEL("xls,xlsx"),
63     POWER_POINT("ppt,pptx"),
64
65     // compressed format
66     ZIP("zip"),
67     GZIP("gz"),
68     TAR("tar"),
69     TAR_GZ("tar.gz"),
70     BZIP2("bz2")
71
72     ;
73
74     private static HashMap<String, FileType> fileTypeTable = new HashMap<String, FileType>();
75     static
76     {
77         for (FileType eachType : FileType.values())
78         {
79             for (String eachExt : eachType.getFileExtList())
80                 fileTypeTable.put(eachExt, eachType);
81         }
82     }
83
84     private ArrayList<String> fileExtList;
85
86     private FileType(String fileExtCSV)
87     {
88         String[] fileExt = fileExtCSV.split(",\\s*");
89         assert (fileExt != null);
90         fileExtList = new ArrayList<String>(fileExt.length);
91         for (String each : fileExt)
92         {
93             fileExtList.add(each);
94         }
95     }
96
97     public List<String> getFileExtList()
98     {
99         return fileExtList;
100     }
101
102     /**
103      * Retrieve file type
104      * 
105      * @param fileExt
106      * @return
107      */
108     public static FileType getFileType(String fileExt)
109     {
110         return fileTypeTable.get(fileExt.toLowerCase());
111     }
112 }