1/*
2 * Copyright (C) 2007-2008 Esmertec AG.
3 * Copyright (C) 2007-2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.google.android.mms;
19
20import java.util.ArrayList;
21
22public class ContentType {
23    public static final String MMS_MESSAGE       = "application/vnd.wap.mms-message";
24    // The phony content type for generic PDUs (e.g. ReadOrig.ind,
25    // Notification.ind, Delivery.ind).
26    public static final String MMS_GENERIC       = "application/vnd.wap.mms-generic";
27    public static final String MULTIPART_MIXED   = "application/vnd.wap.multipart.mixed";
28    public static final String MULTIPART_RELATED = "application/vnd.wap.multipart.related";
29    public static final String MULTIPART_ALTERNATIVE = "application/vnd.wap.multipart.alternative";
30
31    public static final String TEXT_PLAIN        = "text/plain";
32    public static final String TEXT_HTML         = "text/html";
33    public static final String TEXT_VCALENDAR    = "text/x-vCalendar";
34    public static final String TEXT_VCARD        = "text/x-vCard";
35
36    public static final String IMAGE_UNSPECIFIED = "image/*";
37    public static final String IMAGE_JPEG        = "image/jpeg";
38    public static final String IMAGE_JPG         = "image/jpg";
39    public static final String IMAGE_GIF         = "image/gif";
40    public static final String IMAGE_WBMP        = "image/vnd.wap.wbmp";
41    public static final String IMAGE_PNG         = "image/png";
42
43    public static final String AUDIO_UNSPECIFIED = "audio/*";
44    public static final String AUDIO_AAC         = "audio/aac";
45    public static final String AUDIO_AMR         = "audio/amr";
46    public static final String AUDIO_IMELODY     = "audio/imelody";
47    public static final String AUDIO_MID         = "audio/mid";
48    public static final String AUDIO_MIDI        = "audio/midi";
49    public static final String AUDIO_MP3         = "audio/mp3";
50    public static final String AUDIO_MPEG3       = "audio/mpeg3";
51    public static final String AUDIO_MPEG        = "audio/mpeg";
52    public static final String AUDIO_MPG         = "audio/mpg";
53    public static final String AUDIO_MP4         = "audio/mp4";
54    public static final String AUDIO_X_MID       = "audio/x-mid";
55    public static final String AUDIO_X_MIDI      = "audio/x-midi";
56    public static final String AUDIO_X_MP3       = "audio/x-mp3";
57    public static final String AUDIO_X_MPEG3     = "audio/x-mpeg3";
58    public static final String AUDIO_X_MPEG      = "audio/x-mpeg";
59    public static final String AUDIO_X_MPG       = "audio/x-mpg";
60    public static final String AUDIO_3GPP        = "audio/3gpp";
61    public static final String AUDIO_OGG         = "application/ogg";
62
63    public static final String VIDEO_UNSPECIFIED = "video/*";
64    public static final String VIDEO_3GPP        = "video/3gpp";
65    public static final String VIDEO_3G2         = "video/3gpp2";
66    public static final String VIDEO_H263        = "video/h263";
67    public static final String VIDEO_MP4         = "video/mp4";
68
69    public static final String APP_SMIL          = "application/smil";
70    public static final String APP_WAP_XHTML     = "application/vnd.wap.xhtml+xml";
71    public static final String APP_XHTML         = "application/xhtml+xml";
72
73    public static final String APP_DRM_CONTENT   = "application/vnd.oma.drm.content";
74    public static final String APP_DRM_MESSAGE   = "application/vnd.oma.drm.message";
75
76    private static final ArrayList<String> sSupportedContentTypes = new ArrayList<String>();
77    private static final ArrayList<String> sSupportedImageTypes = new ArrayList<String>();
78    private static final ArrayList<String> sSupportedAudioTypes = new ArrayList<String>();
79    private static final ArrayList<String> sSupportedVideoTypes = new ArrayList<String>();
80
81    static {
82        sSupportedContentTypes.add(TEXT_PLAIN);
83        sSupportedContentTypes.add(TEXT_HTML);
84        sSupportedContentTypes.add(TEXT_VCALENDAR);
85        sSupportedContentTypes.add(TEXT_VCARD);
86
87        sSupportedContentTypes.add(IMAGE_JPEG);
88        sSupportedContentTypes.add(IMAGE_GIF);
89        sSupportedContentTypes.add(IMAGE_WBMP);
90        sSupportedContentTypes.add(IMAGE_PNG);
91        sSupportedContentTypes.add(IMAGE_JPG);
92        //supportedContentTypes.add(IMAGE_SVG); not yet supported.
93
94        sSupportedContentTypes.add(AUDIO_AAC);
95        sSupportedContentTypes.add(AUDIO_AMR);
96        sSupportedContentTypes.add(AUDIO_IMELODY);
97        sSupportedContentTypes.add(AUDIO_MID);
98        sSupportedContentTypes.add(AUDIO_MIDI);
99        sSupportedContentTypes.add(AUDIO_MP3);
100        sSupportedContentTypes.add(AUDIO_MPEG3);
101        sSupportedContentTypes.add(AUDIO_MPEG);
102        sSupportedContentTypes.add(AUDIO_MPG);
103        sSupportedContentTypes.add(AUDIO_X_MID);
104        sSupportedContentTypes.add(AUDIO_X_MIDI);
105        sSupportedContentTypes.add(AUDIO_X_MP3);
106        sSupportedContentTypes.add(AUDIO_X_MPEG3);
107        sSupportedContentTypes.add(AUDIO_X_MPEG);
108        sSupportedContentTypes.add(AUDIO_X_MPG);
109        sSupportedContentTypes.add(AUDIO_3GPP);
110        sSupportedContentTypes.add(AUDIO_OGG);
111
112        sSupportedContentTypes.add(VIDEO_3GPP);
113        sSupportedContentTypes.add(VIDEO_3G2);
114        sSupportedContentTypes.add(VIDEO_H263);
115        sSupportedContentTypes.add(VIDEO_MP4);
116
117        sSupportedContentTypes.add(APP_SMIL);
118        sSupportedContentTypes.add(APP_WAP_XHTML);
119        sSupportedContentTypes.add(APP_XHTML);
120
121        sSupportedContentTypes.add(APP_DRM_CONTENT);
122        sSupportedContentTypes.add(APP_DRM_MESSAGE);
123
124        // add supported image types
125        sSupportedImageTypes.add(IMAGE_JPEG);
126        sSupportedImageTypes.add(IMAGE_GIF);
127        sSupportedImageTypes.add(IMAGE_WBMP);
128        sSupportedImageTypes.add(IMAGE_PNG);
129        sSupportedImageTypes.add(IMAGE_JPG);
130
131        // add supported audio types
132        sSupportedAudioTypes.add(AUDIO_AAC);
133        sSupportedAudioTypes.add(AUDIO_AMR);
134        sSupportedAudioTypes.add(AUDIO_IMELODY);
135        sSupportedAudioTypes.add(AUDIO_MID);
136        sSupportedAudioTypes.add(AUDIO_MIDI);
137        sSupportedAudioTypes.add(AUDIO_MP3);
138        sSupportedAudioTypes.add(AUDIO_MPEG3);
139        sSupportedAudioTypes.add(AUDIO_MPEG);
140        sSupportedAudioTypes.add(AUDIO_MPG);
141        sSupportedAudioTypes.add(AUDIO_MP4);
142        sSupportedAudioTypes.add(AUDIO_X_MID);
143        sSupportedAudioTypes.add(AUDIO_X_MIDI);
144        sSupportedAudioTypes.add(AUDIO_X_MP3);
145        sSupportedAudioTypes.add(AUDIO_X_MPEG3);
146        sSupportedAudioTypes.add(AUDIO_X_MPEG);
147        sSupportedAudioTypes.add(AUDIO_X_MPG);
148        sSupportedAudioTypes.add(AUDIO_3GPP);
149        sSupportedAudioTypes.add(AUDIO_OGG);
150
151        // add supported video types
152        sSupportedVideoTypes.add(VIDEO_3GPP);
153        sSupportedVideoTypes.add(VIDEO_3G2);
154        sSupportedVideoTypes.add(VIDEO_H263);
155        sSupportedVideoTypes.add(VIDEO_MP4);
156    }
157
158    // This class should never be instantiated.
159    private ContentType() {
160    }
161
162    public static boolean isSupportedType(String contentType) {
163        return (null != contentType) && sSupportedContentTypes.contains(contentType);
164    }
165
166    public static boolean isSupportedImageType(String contentType) {
167        return isImageType(contentType) && isSupportedType(contentType);
168    }
169
170    public static boolean isSupportedAudioType(String contentType) {
171        return isAudioType(contentType) && isSupportedType(contentType);
172    }
173
174    public static boolean isSupportedVideoType(String contentType) {
175        return isVideoType(contentType) && isSupportedType(contentType);
176    }
177
178    public static boolean isTextType(String contentType) {
179        return (null != contentType) && contentType.startsWith("text/");
180    }
181
182    public static boolean isImageType(String contentType) {
183        return (null != contentType) && contentType.startsWith("image/");
184    }
185
186    public static boolean isAudioType(String contentType) {
187        return (null != contentType) && contentType.startsWith("audio/");
188    }
189
190    public static boolean isVideoType(String contentType) {
191        return (null != contentType) && contentType.startsWith("video/");
192    }
193
194    public static boolean isDrmType(String contentType) {
195        return (null != contentType)
196                && (contentType.equals(APP_DRM_CONTENT)
197                        || contentType.equals(APP_DRM_MESSAGE));
198    }
199
200    public static boolean isUnspecified(String contentType) {
201        return (null != contentType) && contentType.endsWith("*");
202    }
203
204    @SuppressWarnings("unchecked")
205    public static ArrayList<String> getImageTypes() {
206        return (ArrayList<String>) sSupportedImageTypes.clone();
207    }
208
209    @SuppressWarnings("unchecked")
210    public static ArrayList<String> getAudioTypes() {
211        return (ArrayList<String>) sSupportedAudioTypes.clone();
212    }
213
214    @SuppressWarnings("unchecked")
215    public static ArrayList<String> getVideoTypes() {
216        return (ArrayList<String>) sSupportedVideoTypes.clone();
217    }
218
219    @SuppressWarnings("unchecked")
220    public static ArrayList<String> getSupportedTypes() {
221        return (ArrayList<String>) sSupportedContentTypes.clone();
222    }
223}
224