View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/mySpace/client/src/java/org/astrogrid/store/util/MimeTypeUtil.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/10/05 15:39:29 $</cvs:date>
5    * <cvs:version>$Revision: 1.2 $</cvs:version>
6    * <cvs:log>
7    *   $Log: MimeTypeUtil.java,v $
8    *   Revision 1.2  2004/10/05 15:39:29  dave
9    *   Merged changes to AladinAdapter ...
10   *
11   *   Revision 1.1.2.1  2004/10/05 15:30:44  dave
12   *   Moved test base from test to src tree ....
13   *   Added MimeTypeUtil
14   *   Added getMimeType to the adapter API
15   *   Added logout to the adapter API
16   *
17   * </cvs:log>
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  		// If we have a name.
69  		if (null != name)
70  			{
71  			//
72  			// Find the last '.' in the name.
73  			int index = name.lastIndexOf('.') ;
74  			//
75  			// If we found a '.' in the name.
76  			if (index != -1)
77  				{
78  				//
79  				// Check for recognised types.
80  				String type = name.substring(
81  					index
82  					).toLowerCase() ;
83  				//
84  				// Vanilla XML.
85  				if (".xml".equals(type))
86  					{
87  					mime = MIME_TYPE_XML ;
88  					}
89  				//
90  				// Vanilla XSL.
91  				if (".xsl".equals(type))
92  					{
93  					mime = MIME_TYPE_XML ;
94  					}
95  				//
96  				// Astrogrid VoTable.
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 				// Astrogrid VoList.
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 				// Astrogrid Job details.
117 				if (".job".equals(type))
118 					{
119 					mime = MIME_TYPE_JOB ;
120 					}
121 				//
122 				// Astrogrid workflow.
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 				// Astrogrid ADQL.
137 				if (".adql".equals(type))
138 					{
139 					mime = MIME_TYPE_ADQL ;
140 					}
141 				}
142 			}
143 		return mime ;
144 		}
145 	}