update author list in license for (JAL-826)
[jalview.git] / src / jalview / ws / io / mime / MimeTypes.java
1 /*******************************************************************************
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
4  *
5  * This file is part of Jalview.
6  *
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  *******************************************************************************/
18 package jalview.ws.io.mime;
19
20 import jalview.io.packed.DataProvider.JvDataType;
21
22 /**
23  * static functions for resolving Jalview datatypes from mime types 
24  * @author JimP
25  * TODO: consider making get(Mime)TypeOf functions throw exceptions rather than returning null
26  */
27 public class MimeTypes
28 {
29   /**
30    * pair list {String,JvDataType} giving a mime-type followed by its associated JvDataType enumeration.
31    */
32   final public static Object[] typemap = new Object[] {
33     "application/x-align",JvDataType.ALIGNMENT,
34     "application/x-jalview-annotation",JvDataType.ANNOTATION,
35     "application/x-newick",JvDataType.TREE,
36     "application/x-new-hampshire",JvDataType.TREE,
37     "application/x-new-hampshire-extended",JvDataType.TREE,
38     "application/x-nh",JvDataType.TREE,
39     "application/x-nhx",JvDataType.TREE,
40     "application/x-gff",JvDataType.FEATURES,
41     "application/x-gff3",JvDataType.FEATURES,
42     "application/x-jalview-feature-file",JvDataType.FEATURES,
43     "application/x-pdb",JvDataType.SEQASSOCATED};
44   /**
45    * 
46    * @param mimeType
47    * @return the associated jalview datatype or null if no mapping is available
48    */
49   public static JvDataType getTypeOf(String mimeType)
50   {
51     String mt = mimeType.toLowerCase();
52     for (int i=0;i<typemap.length;i+=2)
53     {
54       if (typemap[i].equals(mt))
55       {
56         return (JvDataType) typemap[i+1];
57       }
58     }
59     return null;
60   }
61   
62   /**
63    * 
64    * @param type
65    * @return the primary mimetype associated with this type.
66    */
67   public static String getMimeTypeOf(JvDataType type)
68   {
69     for (int i=1;i<typemap.length;i+=2)
70     {
71       if (typemap[i].equals(type))
72       {
73         return (String) typemap[i-1];
74       }
75     }
76     return null;
77   }
78 }