Source Code Cross Referenced for MediaType.java in  » Web-Services » restlet-1.0.8 » org » restlet » data » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services » restlet 1.0.8 » org.restlet.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2007 Noelios Consulting.
003:         *
004:         * The contents of this file are subject to the terms of the Common Development
005:         * and Distribution License (the "License"). You may not use this file except in
006:         * compliance with the License.
007:         *
008:         * You can obtain a copy of the license at
009:         * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
010:         * language governing permissions and limitations under the License.
011:         *
012:         * When distributing Covered Code, include this CDDL HEADER in each file and
013:         * include the License file at http://www.opensource.org/licenses/cddl1.txt If
014:         * applicable, add the following below this CDDL HEADER, with the fields
015:         * enclosed by brackets "[]" replaced with your own identifying information:
016:         * Portions Copyright [yyyy] [name of copyright owner]
017:         */
018:
019:        package org.restlet.data;
020:
021:        import org.restlet.util.Engine;
022:        import org.restlet.util.Series;
023:
024:        /**
025:         * Media type used in representations and preferences.
026:         *
027:         * @see <a href="http://en.wikipedia.org/wiki/MIME">MIME types on Wikipedia</a>
028:         * @author Jerome Louvel (contact@noelios.com)
029:         */
030:        public final class MediaType extends Metadata {
031:            public static final MediaType ALL = new MediaType("*/*",
032:                    "All media");
033:
034:            public static final MediaType APPLICATION_ALL = new MediaType(
035:                    "application/*", "All application documents");
036:
037:            public static final MediaType APPLICATION_ATOM_XML = new MediaType(
038:                    "application/atom+xml", "Atom syndication documents");
039:
040:            public static final MediaType APPLICATION_CAB = new MediaType(
041:                    "application/vnd.ms-cab-compressed",
042:                    "Microsoft Cabinet archive");
043:
044:            public static final MediaType APPLICATION_EXCEL = new MediaType(
045:                    "application/vnd.ms-excel", "Microsoft Excel document");
046:
047:            public static final MediaType APPLICATION_FLASH = new MediaType(
048:                    "application/x-shockwave-flash", "Shockwave Flash object");
049:
050:            public static final MediaType APPLICATION_GNU_TAR = new MediaType(
051:                    "application/x-gtar", "GNU Tar archive");
052:
053:            public static final MediaType APPLICATION_GNU_ZIP = new MediaType(
054:                    "application/x-gzip", "GNU Zip archive");
055:
056:            public static final MediaType APPLICATION_HTTP_COOKIES = new MediaType(
057:                    "application/x-http-cookies", "HTTP cookies");
058:
059:            public static final MediaType APPLICATION_JAVA_ARCHIVE = new MediaType(
060:                    "application/java-archive", "Java archive");
061:
062:            public static final MediaType APPLICATION_JAVA_OBJECT = new MediaType(
063:                    "application/x-java-serialized-object",
064:                    "Java serialized object");
065:
066:            public static final MediaType APPLICATION_JAVASCRIPT = new MediaType(
067:                    "application/x-javascript", "Javascript document");
068:
069:            public static final MediaType APPLICATION_JSON = new MediaType(
070:                    "application/json", "JavaScript Object Notation document");
071:
072:            public static final MediaType APPLICATION_OCTET_STREAM = new MediaType(
073:                    "application/octet-stream", "Raw octet stream");
074:
075:            public static final MediaType APPLICATION_PDF = new MediaType(
076:                    "application/pdf", "Adobe PDF document");
077:
078:            public static final MediaType APPLICATION_POSTSCRIPT = new MediaType(
079:                    "application/postscript", "Postscript document");
080:
081:            public static final MediaType APPLICATION_POWERPOINT = new MediaType(
082:                    "application/vnd.ms-powerpoint",
083:                    "Microsoft Powerpoint document");
084:
085:            public static final MediaType APPLICATION_PROJECT = new MediaType(
086:                    "application/vnd.ms-project", "Microsoft Project document");
087:
088:            public static final MediaType APPLICATION_RDF_XML = new MediaType(
089:                    "application/rdf+xml",
090:                    "XML serialized Resource Description Framework document");
091:
092:            public static final MediaType APPLICATION_RTF = new MediaType(
093:                    "application/rtf", "Rich Text Format document");
094:
095:            public static final MediaType APPLICATION_STUFFIT = new MediaType(
096:                    "application/x-stuffit", "Stuffit archive");
097:
098:            public static final MediaType APPLICATION_TAR = new MediaType(
099:                    "application/x-tar", "Tar archive");
100:
101:            public static final MediaType APPLICATION_WORD = new MediaType(
102:                    "application/msword", "Microsoft Word document");
103:
104:            public static final MediaType APPLICATION_WWW_FORM = new MediaType(
105:                    "application/x-www-form-urlencoded",
106:                    "Web form (URL encoded)");
107:
108:            public static final MediaType APPLICATION_XHTML_XML = new MediaType(
109:                    "application/xhtml+xml", "XHTML document");
110:
111:            public static final MediaType APPLICATION_XML = new MediaType(
112:                    "application/xml", "XML document");
113:
114:            public static final MediaType APPLICATION_ZIP = new MediaType(
115:                    "application/zip", "Zip archive");
116:
117:            public static final MediaType AUDIO_ALL = new MediaType("audio/*",
118:                    "All audios");
119:
120:            public static final MediaType AUDIO_MPEG = new MediaType(
121:                    "audio/mpeg", "MPEG audio (MP3)");
122:
123:            public static final MediaType AUDIO_REAL = new MediaType(
124:                    "audio/x-pn-realaudio", "Real audio");
125:
126:            public static final MediaType AUDIO_WAV = new MediaType(
127:                    "audio/x-wav", "Waveform audio");
128:
129:            public static final MediaType IMAGE_ALL = new MediaType("image/*",
130:                    "All images");
131:
132:            public static final MediaType IMAGE_BMP = new MediaType(
133:                    "image/bmp", "Windows bitmap");
134:
135:            public static final MediaType IMAGE_GIF = new MediaType(
136:                    "image/gif", "GIF image");
137:
138:            public static final MediaType IMAGE_ICON = new MediaType(
139:                    "image/x-icon", "Windows icon (Favicon)");
140:
141:            public static final MediaType IMAGE_JPEG = new MediaType(
142:                    "image/jpeg", "JPEG image");
143:
144:            public static final MediaType IMAGE_PNG = new MediaType(
145:                    "image/png", "PNG image");
146:
147:            public static final MediaType IMAGE_SVG = new MediaType(
148:                    "image/svg+xml", "Scalable Vector Graphics");
149:
150:            public static final MediaType MESSAGE_ALL = new MediaType(
151:                    "message/*", "All messages");
152:
153:            public static final MediaType MODEL_ALL = new MediaType("model/*",
154:                    "All models");
155:
156:            public static final MediaType MULTIPART_ALL = new MediaType(
157:                    "multipart/*", "All multipart data");
158:
159:            public static final MediaType MULTIPART_FORM_DATA = new MediaType(
160:                    "multipart/form-data", "Multipart form data");
161:
162:            public static final MediaType TEXT_ALL = new MediaType("text/*",
163:                    "All texts");
164:
165:            public static final MediaType TEXT_CALENDAR = new MediaType(
166:                    "text/calendar", "iCalendar event");
167:
168:            public static final MediaType TEXT_CSS = new MediaType("text/css",
169:                    "CSS stylesheet");
170:
171:            public static final MediaType TEXT_HTML = new MediaType(
172:                    "text/html", "HTML document");
173:
174:            public static final MediaType TEXT_PLAIN = new MediaType(
175:                    "text/plain", "Plain text");
176:
177:            public static final MediaType TEXT_RDF_N3 = new MediaType(
178:                    "text/rdf+n3",
179:                    "N3 serialized Resource Description Framework document");
180:
181:            public static final MediaType TEXT_URI_LIST = new MediaType(
182:                    "text/uri-list", "List of URIs");
183:
184:            public static final MediaType TEXT_VCARD = new MediaType(
185:                    "text/x-vcard", "vCard");
186:
187:            public static final MediaType TEXT_XML = new MediaType("text/xml",
188:                    "XML text");
189:
190:            public static final MediaType VIDEO_ALL = new MediaType("video/*",
191:                    "All videos");
192:
193:            public static final MediaType VIDEO_AVI = new MediaType(
194:                    "video/x-msvideo", "AVI video");
195:
196:            public static final MediaType VIDEO_MPEG = new MediaType(
197:                    "video/mpeg", "MPEG video");
198:
199:            public static final MediaType VIDEO_QUICKTIME = new MediaType(
200:                    "video/quicktime", "Quicktime video");
201:
202:            public static final MediaType VIDEO_WMV = new MediaType(
203:                    "video/x-ms-wmv", "Windows movie");
204:
205:            /**
206:             * Returns the media type associated to a name. If an existing constant
207:             * exists then it is returned, otherwise a new instance is created.
208:             *
209:             * @param name
210:             *            The name.
211:             * @return The associated media type.
212:             */
213:            public static MediaType valueOf(String name) {
214:                MediaType result = null;
215:
216:                if (name != null) {
217:                    if (name.equals(ALL.getName()))
218:                        result = ALL;
219:                    else if (name.equals(APPLICATION_ALL.getName()))
220:                        result = APPLICATION_ALL;
221:                    else if (name.equals(APPLICATION_ATOM_XML.getName()))
222:                        result = APPLICATION_ATOM_XML;
223:                    else if (name.equals(APPLICATION_CAB.getName()))
224:                        result = APPLICATION_CAB;
225:                    else if (name.equals(APPLICATION_EXCEL.getName()))
226:                        result = APPLICATION_EXCEL;
227:                    else if (name.equals(APPLICATION_FLASH.getName()))
228:                        result = APPLICATION_FLASH;
229:                    else if (name.equals(APPLICATION_GNU_TAR.getName()))
230:                        result = APPLICATION_GNU_TAR;
231:                    else if (name.equals(APPLICATION_GNU_ZIP.getName()))
232:                        result = APPLICATION_GNU_ZIP;
233:                    else if (name.equals(APPLICATION_JAVA_ARCHIVE.getName()))
234:                        result = APPLICATION_JAVA_ARCHIVE;
235:                    else if (name.equals(APPLICATION_JAVA_OBJECT.getName()))
236:                        result = APPLICATION_JAVA_OBJECT;
237:                    else if (name.equals(APPLICATION_JAVASCRIPT.getName()))
238:                        result = APPLICATION_JAVASCRIPT;
239:                    else if (name.equals(APPLICATION_JSON.getName()))
240:                        result = APPLICATION_JSON;
241:                    else if (name.equals(APPLICATION_OCTET_STREAM.getName()))
242:                        result = APPLICATION_OCTET_STREAM;
243:                    else if (name.equals(APPLICATION_PDF.getName()))
244:                        result = APPLICATION_PDF;
245:                    else if (name.equals(APPLICATION_POSTSCRIPT.getName()))
246:                        result = APPLICATION_POSTSCRIPT;
247:                    else if (name.equals(APPLICATION_POWERPOINT.getName()))
248:                        result = APPLICATION_POWERPOINT;
249:                    else if (name.equals(APPLICATION_PROJECT.getName()))
250:                        result = APPLICATION_PROJECT;
251:                    else if (name.equals(APPLICATION_RTF.getName()))
252:                        result = APPLICATION_RTF;
253:                    else if (name.equals(APPLICATION_STUFFIT.getName()))
254:                        result = APPLICATION_STUFFIT;
255:                    else if (name.equals(APPLICATION_TAR.getName()))
256:                        result = APPLICATION_TAR;
257:                    else if (name.equals(APPLICATION_WORD.getName()))
258:                        result = APPLICATION_WORD;
259:                    else if (name.equals(APPLICATION_WWW_FORM.getName()))
260:                        result = APPLICATION_WWW_FORM;
261:                    else if (name.equals(APPLICATION_XHTML_XML.getName()))
262:                        result = APPLICATION_XHTML_XML;
263:                    else if (name.equals(APPLICATION_XML.getName()))
264:                        result = APPLICATION_XML;
265:                    else if (name.equals(APPLICATION_ZIP.getName()))
266:                        result = APPLICATION_ZIP;
267:                    else if (name.equals(AUDIO_ALL.getName()))
268:                        result = AUDIO_ALL;
269:                    else if (name.equals(AUDIO_MPEG.getName()))
270:                        result = AUDIO_MPEG;
271:                    else if (name.equals(AUDIO_REAL.getName()))
272:                        result = AUDIO_REAL;
273:                    else if (name.equals(AUDIO_WAV.getName()))
274:                        result = AUDIO_WAV;
275:                    else if (name.equals(IMAGE_ALL.getName()))
276:                        result = IMAGE_ALL;
277:                    else if (name.equals(IMAGE_BMP.getName()))
278:                        result = IMAGE_BMP;
279:                    else if (name.equals(IMAGE_GIF.getName()))
280:                        result = IMAGE_GIF;
281:                    else if (name.equals(IMAGE_ICON.getName()))
282:                        result = IMAGE_ICON;
283:                    else if (name.equals(IMAGE_JPEG.getName()))
284:                        result = IMAGE_JPEG;
285:                    else if (name.equals(IMAGE_PNG.getName()))
286:                        result = IMAGE_PNG;
287:                    else if (name.equals(IMAGE_SVG.getName()))
288:                        result = IMAGE_SVG;
289:                    else if (name.equals(MESSAGE_ALL.getName()))
290:                        result = MESSAGE_ALL;
291:                    else if (name.equals(MODEL_ALL.getName()))
292:                        result = MODEL_ALL;
293:                    else if (name.equals(MESSAGE_ALL.getName()))
294:                        result = MESSAGE_ALL;
295:                    else if (name.equals(MULTIPART_ALL.getName()))
296:                        result = MULTIPART_ALL;
297:                    else if (name.equals(MULTIPART_FORM_DATA.getName()))
298:                        result = MULTIPART_FORM_DATA;
299:                    else if (name.equals(TEXT_ALL.getName()))
300:                        result = TEXT_ALL;
301:                    else if (name.equals(TEXT_CALENDAR.getName()))
302:                        result = TEXT_CALENDAR;
303:                    else if (name.equals(TEXT_CSS.getName()))
304:                        result = TEXT_CSS;
305:                    else if (name.equals(TEXT_HTML.getName()))
306:                        result = TEXT_HTML;
307:                    else if (name.equals(TEXT_PLAIN.getName()))
308:                        result = TEXT_PLAIN;
309:                    else if (name.equals(TEXT_URI_LIST.getName()))
310:                        result = TEXT_URI_LIST;
311:                    else if (name.equals(TEXT_VCARD.getName()))
312:                        result = TEXT_VCARD;
313:                    else if (name.equals(TEXT_XML.getName()))
314:                        result = TEXT_XML;
315:                    else if (name.equals(VIDEO_ALL.getName()))
316:                        result = VIDEO_ALL;
317:                    else if (name.equals(VIDEO_AVI.getName()))
318:                        result = VIDEO_AVI;
319:                    else if (name.equals(VIDEO_MPEG.getName()))
320:                        result = VIDEO_MPEG;
321:                    else if (name.equals(VIDEO_QUICKTIME.getName()))
322:                        result = VIDEO_QUICKTIME;
323:                    else if (name.equals(VIDEO_WMV.getName()))
324:                        result = VIDEO_WMV;
325:                    else
326:                        result = new MediaType(name);
327:                }
328:
329:                return result;
330:            }
331:
332:            /** The list of parameters. */
333:            private Series<Parameter> parameters;
334:
335:            /**
336:             * Constructor.
337:             *
338:             * @param name
339:             *            The name.
340:             */
341:            public MediaType(String name) {
342:                this (name, null, "Media type or range of media types");
343:            }
344:
345:            /**
346:             * Constructor.
347:             *
348:             * @param name
349:             *            The name.
350:             * @param parameters
351:             *            The list of parameters.
352:             */
353:            public MediaType(String name, Series<Parameter> parameters) {
354:                this (name, parameters, "Media type or range of media types");
355:            }
356:
357:            /**
358:             * Constructor.
359:             *
360:             * @param name
361:             *            The name.
362:             * @param parameters
363:             *            The list of parameters.
364:             * @param description
365:             *            The description.
366:             */
367:            public MediaType(String name, Series<Parameter> parameters,
368:                    String description) {
369:                super ((name == null) ? null : name, description);
370:                this .parameters = parameters;
371:            }
372:
373:            /**
374:             * Constructor.
375:             *
376:             * @param name
377:             *            The name.
378:             * @param description
379:             *            The description.
380:             */
381:            public MediaType(String name, String description) {
382:                this (name, null, description);
383:            }
384:
385:            /** {@inheritDoc} */
386:            @Override
387:            public boolean equals(Object obj) {
388:                return equals(obj, false);
389:            }
390:
391:            /**
392:             * Test the equality of two media types, with the possibility to ignore the
393:             * parameters.
394:             *
395:             * @param obj
396:             *            The object to compare to.
397:             * @param ignoreParameters
398:             *            Indicates if parameters should be ignored during comparison.
399:             * @return True if both media types are equal.
400:             */
401:            public boolean equals(Object obj, boolean ignoreParameters) {
402:                boolean result = (obj == this );
403:
404:                // if obj == this no need to go further
405:                if (!result) {
406:                    // test for equality at Metadata level i.e. name and value.
407:                    if (super .equals(obj)) {
408:                        // if obj isn't a mediatype or is null don't evaluate further
409:                        if ((obj instanceof  MediaType) && obj != null) {
410:                            MediaType that = (MediaType) obj;
411:                            result = ignoreParameters
412:                                    || this .getParameters().equals(
413:                                            that.getParameters());
414:                        }
415:                    }
416:                }
417:
418:                return result;
419:            }
420:
421:            /**
422:             * Returns the main type.
423:             *
424:             * @return The main type.
425:             */
426:            public String getMainType() {
427:                String result = null;
428:
429:                if (getName() != null) {
430:                    int index = getName().indexOf('/');
431:
432:                    // Some clients appear to use name types without subtypes
433:                    if (index == -1) {
434:                        index = getName().indexOf(';');
435:                    }
436:
437:                    if (index == -1) {
438:                        result = getName();
439:                    } else {
440:                        result = getName().substring(0, index);
441:                    }
442:                }
443:
444:                return result;
445:            }
446:
447:            /**
448:             * Returns the list of parameters.
449:             *
450:             * @return The list of parameters.
451:             */
452:            public Series<Parameter> getParameters() {
453:                if (this .parameters == null)
454:                    this .parameters = new Form();
455:                return this .parameters;
456:            }
457:
458:            /**
459:             * Returns the sub-type.
460:             *
461:             * @return The sub-type.
462:             */
463:            public String getSubType() {
464:                String result = null;
465:
466:                if (getName() != null) {
467:                    int slash = getName().indexOf('/');
468:
469:                    if (slash == -1) {
470:                        // No subtype found, assume that all subtypes are accepted
471:                        result = "*";
472:                    } else {
473:                        int separator = getName().indexOf(';');
474:                        if (separator == -1) {
475:                            result = getName().substring(slash + 1);
476:                        } else {
477:                            result = getName().substring(slash + 1, separator);
478:                        }
479:                    }
480:                }
481:
482:                return result;
483:            }
484:
485:            /** {@inheritDoc} */
486:            @Override
487:            public int hashCode() {
488:                return Engine.hashCode(super .hashCode(), getParameters());
489:            }
490:
491:            /**
492:             * Indicates if a given media type is included in the current one. The test
493:             * is true if both types are equal or if the given media type is within the
494:             * range of the current one. For example, ALL includes all media types.
495:             * Parameters are ignored for this comparison. A null media type is
496:             * considered as included into the current one.
497:             *
498:             * @param included
499:             *            The media type to test for inclusion.
500:             * @return True if the given media type is included in the current one.
501:             */
502:            public boolean includes(MediaType included) {
503:                boolean result = equals(ALL) || included == null
504:                        || equals(included);
505:
506:                if (!result) {
507:                    // Both media types are different
508:                    result = getMainType().equals(included.getMainType())
509:                            && (getSubType().equals(included.getSubType()) || getSubType()
510:                                    .equals("*"));
511:                }
512:
513:                return result;
514:            }
515:
516:            @Override
517:            public String toString() {
518:                StringBuilder sb = new StringBuilder();
519:
520:                if (getName() != null) {
521:                    sb.append(getName());
522:
523:                    for (Parameter param : getParameters()) {
524:                        sb.append("; ").append(param.getName()).append('=')
525:                                .append(param.getValue());
526:                    }
527:                }
528:
529:                return sb.toString();
530:            }
531:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.