Source Code Cross Referenced for MetadataService.java in  » Web-Services » restlet-1.0.8 » org » restlet » service » 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.service 
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.service;
020:
021:        import java.util.Map;
022:        import java.util.TreeMap;
023:
024:        import org.restlet.data.Encoding;
025:        import org.restlet.data.Language;
026:        import org.restlet.data.MediaType;
027:        import org.restlet.data.Metadata;
028:
029:        /**
030:         * Service providing access to metadata and their associated extension names.
031:         * 
032:         * @author Jerome Louvel (contact@noelios.com)
033:         */
034:        public class MetadataService {
035:            /** The default encoding for local representations. */
036:            private Encoding defaultEncoding;
037:
038:            /** The default language for local representations. */
039:            private Language defaultLanguage;
040:
041:            /** The default media type for local representations. */
042:            private MediaType defaultMediaType;
043:
044:            /** The mappings from extension names to metadata. */
045:            private Map<String, Metadata> metadataMappings;
046:
047:            /**
048:             * Constructor.
049:             */
050:            public MetadataService() {
051:                this .defaultEncoding = Encoding.IDENTITY;
052:                this .defaultLanguage = Language.ENGLISH_US;
053:                this .defaultMediaType = MediaType.APPLICATION_OCTET_STREAM;
054:                this .metadataMappings = new TreeMap<String, Metadata>();
055:                addCommonExtensions();
056:            }
057:
058:            /**
059:             * Adds a common list of associations from extensions to metadata. The list
060:             * of languages extensions:<br/>
061:             * <ul>
062:             * <li>en: English</li>
063:             * <li>es: Spanish</li>
064:             * <li>fr: French</li>
065:             * </ul>
066:             * <br/> The list of media type extensions:<br/>
067:             * <ul>
068:             * <li>css: CSS stylesheet</li>
069:             * <li>doc: Microsoft Word document</li>
070:             * <li>gif: GIF image</li>
071:             * <li>html: HTML document</li>
072:             * <li>ico: Windows icon (Favicon)</li>
073:             * <li>jpeg, jpg: JPEG image</li>
074:             * <li>js: JavaScript document</li>
075:             * <li>json: JavaScript Object Notation document</li>
076:             * <li>pdf: Adobe PDF document</li>
077:             * <li>png: PNG image</li>
078:             * <li>ppt: Microsoft Powerpoint document</li>
079:             * <li>rdf: Description Framework document</li>
080:             * <li>txt: Plain text</li>
081:             * <li>swf: Shockwave Flash object</li>
082:             * <li>xhtml: XHTML document</li>
083:             * <li>xml: XML document</li>
084:             * <li>zip: Zip archive</li>
085:             * </ul>
086:             */
087:            public void addCommonExtensions() {
088:                addExtension("en", Language.ENGLISH);
089:                addExtension("es", Language.SPANISH);
090:                addExtension("fr", Language.FRENCH);
091:
092:                addExtension("css", MediaType.TEXT_CSS);
093:                addExtension("doc", MediaType.APPLICATION_WORD);
094:                addExtension("gif", MediaType.IMAGE_GIF);
095:                addExtension("html", MediaType.TEXT_HTML);
096:                addExtension("ico", MediaType.IMAGE_ICON);
097:                addExtension("jpeg", MediaType.IMAGE_JPEG);
098:                addExtension("jpg", MediaType.IMAGE_JPEG);
099:                addExtension("js", MediaType.APPLICATION_JAVASCRIPT);
100:                addExtension("json", MediaType.APPLICATION_JSON);
101:                addExtension("pdf", MediaType.APPLICATION_PDF);
102:                addExtension("png", MediaType.IMAGE_PNG);
103:                addExtension("ppt", MediaType.APPLICATION_POWERPOINT);
104:                addExtension("rdf", MediaType.APPLICATION_RDF_XML);
105:                addExtension("txt", MediaType.TEXT_PLAIN);
106:                addExtension("svg", MediaType.IMAGE_SVG);
107:                addExtension("swf", MediaType.APPLICATION_FLASH);
108:                addExtension("xhtml", MediaType.APPLICATION_XHTML_XML);
109:                addExtension("xml", MediaType.TEXT_XML);
110:                addExtension("zip", MediaType.APPLICATION_ZIP);
111:            }
112:
113:            /**
114:             * Maps an extension to some metadata (media type, language or character
115:             * set) to an extension.
116:             * 
117:             * @param extension
118:             *                The extension name.
119:             * @param metadata
120:             *                The metadata to map.
121:             */
122:            public void addExtension(String extension, Metadata metadata) {
123:                this .metadataMappings.put(extension, metadata);
124:            }
125:
126:            /**
127:             * Returns the default encoding for local representations.
128:             * 
129:             * @return The default encoding for local representations.
130:             */
131:            public Encoding getDefaultEncoding() {
132:                return this .defaultEncoding;
133:            }
134:
135:            /**
136:             * Returns the default language for local representations.
137:             * 
138:             * @return The default language for local representations.
139:             */
140:            public Language getDefaultLanguage() {
141:                return this .defaultLanguage;
142:            }
143:
144:            /**
145:             * Returns the default media type for local representations.
146:             * 
147:             * @return The default media type for local representations.
148:             */
149:            public MediaType getDefaultMediaType() {
150:                return this .defaultMediaType;
151:            }
152:
153:            /**
154:             * Returns the first extension mapping to this metadata.
155:             * 
156:             * @param metadata
157:             *                The metadata to find.
158:             * @return The first extension mapping to this metadata.
159:             */
160:            public String getExtension(Metadata metadata) {
161:                for (String extension : getMappings().keySet()) {
162:                    if (getMetadata(extension).equals(metadata)) {
163:                        return extension;
164:                    }
165:                }
166:
167:                return null;
168:            }
169:
170:            /**
171:             * Returns the mappings from extension names to metadata.
172:             * 
173:             * @return The mappings from extension names to metadata.
174:             */
175:            public Map<String, Metadata> getMappings() {
176:                return this .metadataMappings;
177:            }
178:
179:            /**
180:             * Returns the metadata associated to this extension. It returns null if the
181:             * extension was not declared.
182:             * 
183:             * @param extension
184:             *                The extension name without any delimiter.
185:             * @return The metadata associated to this extension.
186:             */
187:            public Metadata getMetadata(String extension) {
188:                return getMappings().get(extension);
189:            }
190:
191:            /**
192:             * Sets the default encoding for local representations.
193:             * 
194:             * @param defaultEncoding
195:             *                The default encoding for local representations.
196:             */
197:            public void setDefaultEncoding(Encoding defaultEncoding) {
198:                this .defaultEncoding = defaultEncoding;
199:            }
200:
201:            /**
202:             * Sets the default language for local representations.
203:             * 
204:             * @param defaultLanguage
205:             *                The default language for local representations.
206:             */
207:            public void setDefaultLanguage(Language defaultLanguage) {
208:                this .defaultLanguage = defaultLanguage;
209:            }
210:
211:            /**
212:             * Sets the default media type for local representations.
213:             * 
214:             * @param defaultMediaType
215:             *                The default media type for local representations.
216:             */
217:            public void setDefaultMediaType(MediaType defaultMediaType) {
218:                this.defaultMediaType = defaultMediaType;
219:            }
220:
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.