d62d077a6a9443378d4754d17cfbfa385c671e80
[jalview.git] / src / jalview / ws / io / mime / MimeTypes.java
1 package jalview.ws.io.mime;
2
3 import jalview.io.packed.DataProvider.JvDataType;
4
5 /**
6  * static functions for resolving Jalview datatypes from mime types 
7  * @author JimP
8  * TODO: consider making get(Mime)TypeOf functions throw exceptions rather than returning null
9  */
10 public class MimeTypes
11 {
12   /**
13    * pair list {String,JvDataType} giving a mime-type followed by its associated JvDataType enumeration.
14    */
15   final public static Object[] typemap = new Object[] {
16     "application/x-align",JvDataType.ALIGNMENT,
17     "application/x-jalview-annotation",JvDataType.ANNOTATION,
18     "application/x-newick",JvDataType.TREE,
19     "application/x-new-hampshire",JvDataType.TREE,
20     "application/x-new-hampshire-extended",JvDataType.TREE,
21     "application/x-nh",JvDataType.TREE,
22     "application/x-nhx",JvDataType.TREE,
23     "application/x-gff",JvDataType.FEATURES,
24     "application/x-gff3",JvDataType.FEATURES,
25     "application/x-jalview-feature-file",JvDataType.FEATURES,
26     "application/x-pdb",JvDataType.SEQASSOCATED};
27   /**
28    * 
29    * @param mimeType
30    * @return the associated jalview datatype or null if no mapping is available
31    */
32   public static JvDataType getTypeOf(String mimeType)
33   {
34     String mt = mimeType.toLowerCase();
35     for (int i=0;i<typemap.length;i+=2)
36     {
37       if (typemap[i].equals(mt))
38       {
39         return (JvDataType) typemap[i+1];
40       }
41     }
42     return null;
43   }
44   
45   /**
46    * 
47    * @param type
48    * @return the primary mimetype associated with this type.
49    */
50   public static String getMimeTypeOf(JvDataType type)
51   {
52     for (int i=1;i<typemap.length;i+=2)
53     {
54       if (typemap[i].equals(type))
55       {
56         return (String) typemap[i-1];
57       }
58     }
59     return null;
60   }
61 }