1717
1818import org .apache .commons .lang3 .StringUtils ;
1919
20+ import java .util .HashMap ;
21+ import java .util .Map ;
22+
2023public enum FileType
2124{
2225 JAVA_PROPERTIES ("text/plain" , true ), // Java resources
@@ -44,13 +47,29 @@ public enum FileType
4447 STRINGSDICT ("application/xml" , true ), // iOS/OSX resources in dictionary format
4548 MADCAP ("application/octet-stream" , false ), // MADCAP file
4649 SRT ("text/plain" , false ), // SubRip Text Format
47- MARKDOWN ("text/markdown" , true ); // Markdown Text Format
50+ MARKDOWN ("text/markdown" , true ), // Markdown Text Format
51+ PHP_RESOURCE ("text/plain" , false ), // PHP resources
52+ TMX ("application/xml" , false ), // TMX translation memory file format
53+ XLIFF_CAT ("application/xml" , false ), // XLIFF for offline CAT integration
54+ DITA ("application/xml" , false ); // DITA file format
4855
4956 private final String identifier ;
5057 private final String mimeType ;
5158 private final boolean isTextFormat ;
5259
53- private static String createIdentifier (String s )
60+ // Lookup map
61+ public final static Map <String , FileType > BY_NAME_LOOKUP = new HashMap <>();
62+
63+ static
64+ {
65+ for (final FileType value : FileType .values ())
66+ {
67+ BY_NAME_LOOKUP .put (value .identifier .toLowerCase (), value );
68+ BY_NAME_LOOKUP .put (value .name ().toLowerCase (), value );
69+ }
70+ }
71+
72+ private static String toLowerCamel (String s )
5473 {
5574 StringBuilder buf = new StringBuilder ();
5675 String [] parts = s .split ("_" );
@@ -61,9 +80,9 @@ private static String createIdentifier(String s)
6180 return buf .toString ();
6281 }
6382
64- private FileType (final String mimeType , final boolean isTextFormat )
83+ FileType (final String mimeType , final boolean isTextFormat )
6584 {
66- this .identifier = createIdentifier (name ());
85+ this .identifier = toLowerCamel (name ());
6786 this .mimeType = mimeType ;
6887 this .isTextFormat = isTextFormat ;
6988 }
@@ -85,12 +104,6 @@ public boolean isTextFormat()
85104
86105 public static FileType lookup (final String fileTypeString )
87106 {
88- for (final FileType fileType : FileType .values ())
89- {
90- if (fileType .identifier .equalsIgnoreCase (fileTypeString ))
91- return fileType ;
92- }
93-
94- return null ;
107+ return BY_NAME_LOOKUP .get (StringUtils .lowerCase (fileTypeString ));
95108 }
96109}
0 commit comments