001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/framework/util/MimeTypeMapper.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53115 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042:
043: ---------------------------------------------------------------------------*/
044: package org.deegree.framework.util;
045:
046: /**
047: *
048: * <p>
049: * @author <a href="mailto:schaefer@lat-lon.de">Axel Schaefer</a>
050: ** @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
051: * @version
052: */
053: public class MimeTypeMapper {
054:
055: /**
056: * returns true if the submitted content type is defined by the OGC
057: *
058: * @param contentType
059: *
060: * @return
061: */
062: public static boolean isOGCType(String contentType) {
063: return contentType.startsWith("application/vnd.ogc");
064: }
065:
066: /**
067: * returns true if the submitted content type is an image type
068: *
069: * @param contentType
070: *
071: * @return
072: */
073: public static boolean isImageType(String contentType) {
074: return contentType.startsWith("image");
075: }
076:
077: /**
078: * returns true if the submitted image content type is known by the deegree
079: * implementations
080: *
081: * @param contentType
082: *
083: * @return
084: */
085: public static boolean isKnownImageType(String contentType) {
086: return contentType.equalsIgnoreCase("image/jpeg")
087: || contentType.equalsIgnoreCase("image/jpg")
088: || contentType.equalsIgnoreCase("image/gif")
089: || contentType.equalsIgnoreCase("image/tif")
090: || contentType.equalsIgnoreCase("image/tiff")
091: || contentType.equalsIgnoreCase("image/bmp")
092: || contentType.equalsIgnoreCase("image/svg+xml")
093: || contentType.equalsIgnoreCase("image/png");
094: }
095:
096: /**
097: * returns true if the submitted content type is known by the deegree OWS
098: * implementations
099: *
100: * @param contentType
101: *
102: * @return
103: */
104: public static boolean isKnownMimeType(String contentType) {
105: return contentType.equalsIgnoreCase("image/jpeg")
106: || contentType.equalsIgnoreCase("image/jpg")
107: || contentType.equalsIgnoreCase("image/gif")
108: || contentType.equalsIgnoreCase("image/tif")
109: || contentType.equalsIgnoreCase("image/tiff")
110: || contentType.equalsIgnoreCase("image/png")
111: || contentType.equalsIgnoreCase("text/html")
112: || contentType.equalsIgnoreCase("text/text")
113: || contentType.equalsIgnoreCase("text/plain")
114: || contentType.equalsIgnoreCase("text/xml")
115: || contentType.equalsIgnoreCase("image/bmp")
116: || contentType.equalsIgnoreCase("application/xml")
117: || contentType
118: .equalsIgnoreCase("application/vnd.ogc.se_xml")
119: || contentType
120: .equalsIgnoreCase("application/vnd.ogc.se_inimage")
121: || contentType
122: .equalsIgnoreCase("application/vnd.ogc.se_blank")
123: || contentType
124: .equalsIgnoreCase("application/vnd.ogc.wms_xml")
125: || contentType
126: .equalsIgnoreCase("application/vnd.ogc.gml")
127: || contentType
128: .equalsIgnoreCase("application/vnd.gdinrw.session_xml")
129: || contentType
130: .equalsIgnoreCase("application/vnd.gdinrw.secure_xml")
131: || contentType.equalsIgnoreCase("image/svg+xml");
132: }
133:
134: /**
135: * returns true if the submitted content type is a mime type defined by a
136: * OGC specifiction
137: *
138: * @param contentType
139: *
140: * @return
141: */
142: public static boolean isKnownOGCType(String contentType) {
143: return contentType.equalsIgnoreCase("application/xml")
144: || contentType
145: .equalsIgnoreCase("application/vnd.ogc.se_xml")
146: || contentType
147: .equalsIgnoreCase("application/vnd.ogc.se_inimage")
148: || contentType
149: .equalsIgnoreCase("application/vnd.ogc.se_blank")
150: || contentType
151: .equalsIgnoreCase("application/vnd.ogc.wms_xml")
152: || contentType
153: .equalsIgnoreCase("application/vnd.gdinrw.session_xml")
154: || contentType
155: .equalsIgnoreCase("application/vnd.gdinrw.secure_xml")
156: || contentType
157: .equalsIgnoreCase("application/vnd.ogc.gml");
158: }
159:
160: /**
161: * maps a 'simple' format name like gif, jpg or text to the corresponding
162: * mime type --> e.g. image/gif, image/jpeg or text/plain
163: *
164: * @param contentType
165: *
166: * @return
167: */
168: public static String toMimeType(String contentType) {
169:
170: String mimetype = "";
171:
172: if (isKnownMimeType(contentType)) {
173: mimetype = contentType;
174: } else {
175: if (contentType.equalsIgnoreCase("jpeg")) {
176: mimetype = "image/jpeg";
177: } else if (contentType.equalsIgnoreCase("jpg")) {
178: mimetype = "image/jpeg";
179: } else if (contentType.equalsIgnoreCase("gif")) {
180: mimetype = "image/gif";
181: } else if (contentType.equalsIgnoreCase("png")) {
182: mimetype = "image/png";
183: } else if (contentType.equalsIgnoreCase("bmp")) {
184: mimetype = "image/bmp";
185: } else if (contentType.equalsIgnoreCase("tif")) {
186: mimetype = "image/tiff";
187: } else if (contentType.equalsIgnoreCase("tiff")) {
188: mimetype = "image/tiff";
189: } else if (contentType.equalsIgnoreCase("svg")) {
190: mimetype = "image/svg+xml";
191: } else if (contentType.equalsIgnoreCase("xml")) {
192: mimetype = "text/xml";
193: } else if (contentType.equalsIgnoreCase("gml")) {
194: mimetype = "text/gml";
195: } else if (contentType.equalsIgnoreCase("text")) {
196: mimetype = "text/plain";
197: } else if (contentType.equalsIgnoreCase("inimage")) {
198: mimetype = "application/vnd.ogc.se_inimage";
199: } else if (contentType.equalsIgnoreCase("blank")) {
200: mimetype = "application/vnd.ogc.se_blank";
201: } else if (contentType.equalsIgnoreCase("gml")) {
202: mimetype = "application/vnd.ogc.gml";
203: } else {
204: // unknown mimetype
205: mimetype = "unknown/unknown";
206: }
207: }
208:
209: return mimetype;
210: }
211: }
|