1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.astrogrid.store.util ;
23
24 /***
25 * A temp fix to guess the mime type from a file name.
26 * This is only required until the myspace manager API allows the client to set the mime type.
27 * @todo Reseolve the duplicate mime type values in filestore FileProperties.
28 *
29 */
30 public class MimeTypeUtil
31 {
32 /***
33 * Known MIME type values.
34 * Note - these are a duplication of the values in filestore FileProperties.
35 *
36 */
37 public static final String MIME_TYPE_TEXT = "text/raw" ;
38 public static final String MIME_TYPE_XML = "text/xml" ;
39 public static final String MIME_TYPE_HTML = "t" ;
40
41 public static final String MIME_TYPE_VOLIST = "text/xml +org.astrogrid.mime.volist" ;
42 public static final String MIME_TYPE_VOTABLE = "text/xml +org.astrogrid.mime.votable" ;
43
44 public static final String MIME_TYPE_JOB = "text/xml +org.astrogrid.mime.job" ;
45 public static final String MIME_TYPE_WORKFLOW = "text/xml +org.astrogrid.mime.workflow" ;
46
47 public static final String MIME_TYPE_ADQL = "text/xml +org.astrogrid.mime.adql" ;
48
49
50 /***
51 * Public constructor.
52 *
53 */
54 public MimeTypeUtil()
55 {
56 }
57
58 /***
59 * Guess the mime type from a file name.
60 * @param name The target filename.
61 * @return The mime type if the filename has a recognised .extension, otherwise null.
62 *
63 */
64 public String resolve(String name)
65 {
66 String mime = null ;
67
68
69 if (null != name)
70 {
71
72
73 int index = name.lastIndexOf('.') ;
74
75
76 if (index != -1)
77 {
78
79
80 String type = name.substring(
81 index
82 ).toLowerCase() ;
83
84
85 if (".xml".equals(type))
86 {
87 mime = MIME_TYPE_XML ;
88 }
89
90
91 if (".xsl".equals(type))
92 {
93 mime = MIME_TYPE_XML ;
94 }
95
96
97 if (".vot".equals(type))
98 {
99 mime = MIME_TYPE_VOTABLE ;
100 }
101 if (".votable".equals(type))
102 {
103 mime = MIME_TYPE_VOTABLE ;
104 }
105
106
107 if (".vol".equals(type))
108 {
109 mime = MIME_TYPE_VOLIST ;
110 }
111 if (".volist".equals(type))
112 {
113 mime = MIME_TYPE_VOLIST ;
114 }
115
116
117 if (".job".equals(type))
118 {
119 mime = MIME_TYPE_JOB ;
120 }
121
122
123 if (".work".equals(type))
124 {
125 mime = MIME_TYPE_WORKFLOW ;
126 }
127 if (".flow".equals(type))
128 {
129 mime = MIME_TYPE_WORKFLOW ;
130 }
131 if (".workflow".equals(type))
132 {
133 mime = MIME_TYPE_WORKFLOW ;
134 }
135
136
137 if (".adql".equals(type))
138 {
139 mime = MIME_TYPE_ADQL ;
140 }
141 }
142 }
143 return mime ;
144 }
145 }