org.restlet.service
Class MetadataService

java.lang.Object
  extended by org.restlet.service.Service
      extended by org.restlet.service.MetadataService

public class MetadataService
extends Service

Application service providing access to metadata and their associated extension names. The list of default mappings is documented in the addCommonExtensions() method.

Internally, the mappings are stored as a list of "extension, metadata" pairs.

Author:
Jerome Louvel

Constructor Summary
MetadataService()
          Constructor.
 
Method Summary
 void addCommonExtensions()
          Adds a common list of associations from extensions to metadata.
The list of languages extensions:
en: English es: Spanish fr: French
The list of character set extensions:
ascii: US-ASCII
The list of media type extensions:
ai: PostScript document atom: Atom syndication document au: AU audio file bin: Binary file bmp: Bitmap graphics class: Java bytecode css: CSS stylesheet csv: Comma-separated Values dat: Fixed-width Values dib: Device-Independent Bitmap Graphics doc: Microsoft Word document docx: Microsoft Office Word 2007 document docm: Office Word 2007 macro-enabled document dotx: Office Word 2007 template dotm: Office Word 2007 macro-enabled document template dtd: XML Document Type Definition eps: Encapsulated PostScript exe: Executable File (Microsoft Corporation) fmt: FreeMarker encoding form: Web forms (URL encoded) ftl: FreeMarker encoding gif: GIF image gwt: Java serialized object (using GWT-RPC encoder) hqx: BinHex 4 Compressed Archive (Macintosh) htm, html: HTML document ico: Windows icon (Favicon) jad: Java Application Descriptor file jar: Java Archive java: Java source code jnlp: Java Web start launch file jpe, jpeg, jpg: JPEG image js: JavaScript document jsf: Java Server Faces file json: JavaScript Object Notation document kar: Karaoke MIDI file latex: LaTeX document man: Manual file mathml: Mathml XML document mid, midi: MIDI Audio mov, qt: QuickTime video clip (Apple Computer, Inc.) mp2, mp3: MPEG Audio Stream file mp4: MPEG-4 video file mpe, mpeg, mpg: MPEG video clip n3: RDF N3 document nt: RDF N-Triples document odb: OpenDocument Database odc: OpenDocument Chart odf: OpenDocument Formula odg: OpenDocument Drawing odi: OpenDocument Image odm: OpenDocument Master Document odp: OpenDocument Presentation ods: OpenDocument Spreadsheet odt: OpenDocument Text onetoc: Microsoft Office OneNote 2007 TOC onetoc2: Office OneNote 2007 TOC otg: OpenDocument Drawing Template oth: HTML Document Template otp: OpenDocument Presentation Template ots: OpenDocument Spreadsheet Template ott: OpenDocument Text Template oxt: OpenOffice.org extension pdf: Adobe PDF document png: PNG image potm: Office PowerPoint 2007 macro-enabled presentation template potx: Office PowerPoint 2007 template ppam: Office PowerPoint 2007 add-in pps, ppt: Microsoft Powerpoint document ppsm: Office PowerPoint 2007 macro-enabled slide show ppsx: Office PowerPoint 2007 slide show pptm: Office PowerPoint 2007 macro-enabled presentation pptx: Microsoft Office PowerPoint 2007 presentation ps: PostScript document rdf: Description Framework document rnc: Relax NG Schema document, Compact syntax rng: Relax NG Schema document, XML syntax rss: RSS file rtf: Rich Text Format document sav: SPSS Data sit: StuffIt compressed archive file sldm: Office PowerPoint 2007 macro-enabled slide sldx: Office PowerPoint 2007 slide snd: Amiga sound sps: SPSS Script Syntax sta: Stata data file svg: Scalable Vector Graphics file swf: Adobe Flash file tar: Tape Archive file tex: Tex file tif, tiff: Tagged Image Format File tsv: Tab-separated Values txt: Plain text ulw: MU-LAW (US telephony format) vm: Velocity encoding vrml: Virtual Reality Modeling Language file vxml: VoiceXML source file wadl: Web Application Description Language document wav: Waveform audio wrl: Plain text VRML file xht, xhtml: XHTML document xlam: Office Excel 2007 add-in xls: Microsoft Excel document xlsb: Office Excel 2007 binary workbook xlsm: Office Excel 2007 macro-enabled workbook xlsx: Microsoft Office Excel 2007 workbook xltm: Office Excel 2007 macro-enabled workbook template xltx: Office Excel 2007 template xmi: XMI document xml: XML document xsd: W3C XML Schema document xsl, xslt: XSL Transform file xul: XML User Interface Language file z: UNIX compressed archive file zip: Zip archive
 void addExtension(String extension, Metadata metadata)
          Maps an extension to some metadata (media type, language or character set) to an extension.
 void addExtension(String extension, Metadata metadata, boolean preferred)
          Maps an extension to some metadata (media type, language or character set) to an extension.
 void clearExtensions()
          clears the mappings for all extensions.
 List<String> getAllCharacterSetExtensionNames()
          Return the ordered list of extension names mapped to character set.
 List<CharacterSet> getAllCharacterSets(String extension)
          Returns all the character sets associated to this extension.
 List<String> getAllEncodingExtensionNames()
          Return the ordered list of extension names mapped to encodings.
 List<String> getAllExtensionNames()
          Return the ordered list of extension names.
 List<String> getAllLanguageExtensionNames()
          Return the ordered list of extension names mapped to languages.
 List<Language> getAllLanguages(String extension)
          Returns all the languages associated to this extension.
 List<String> getAllMediaTypeExtensionNames()
          Return the ordered list of extension names mapped to media types.
 List<MediaType> getAllMediaTypes(String extension)
          Returns all the media types associated to this extension.
 List<Metadata> getAllMetadata(String extension)
          Returns all the metadata associated to this extension.
 CharacterSet getCharacterSet(String extension)
          Returns the character set associated to this extension.
 CharacterSet getDefaultCharacterSet()
          Returns the default character set for textual representations.
 Encoding getDefaultEncoding()
          Returns the default encoding for representations.
 Language getDefaultLanguage()
          Returns the default language for representations.
 MediaType getDefaultMediaType()
          Returns the default media type for representations.
 Encoding getEncoding(String extension)
          Returns the encoding associated to this extension.
 String getExtension(Metadata metadata)
          Returns the first extension mapping to this metadata.
 Language getLanguage(String extension)
          Returns the language associated to this extension.
 MediaType getMediaType(String extension)
          Returns the mediatype associated to this extension.
 Metadata getMetadata(String extension)
          Returns the metadata associated to this extension.
<T extends Metadata>
T
getMetadata(String extension, Class<T> metadataType)
          Returns the metadata associated to this extension.
 void setDefaultCharacterSet(CharacterSet defaultCharacterSet)
          Sets the default character set for local representations.
 void setDefaultEncoding(Encoding defaultEncoding)
          Sets the default encoding for local representations.
 void setDefaultLanguage(Language defaultLanguage)
          Sets the default language for local representations.
 void setDefaultMediaType(MediaType defaultMediaType)
          Sets the default media type for local representations.
 
Methods inherited from class org.restlet.service.Service
createInboundFilter, createOutboundFilter, getContext, isEnabled, isStarted, isStopped, setContext, setEnabled, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MetadataService

public MetadataService()
Constructor. Sets the default language to Language.ENGLISH_US, the default encoding to Encoding.IDENTITY (no encoding) and the default media type to MediaType.APPLICATION_OCTET_STREAM. It also calls the addCommonExtensions() method.

Method Detail

addCommonExtensions

public void addCommonExtensions()
Adds a common list of associations from extensions to metadata.
The list of languages extensions:

The list of character set extensions:

The list of media type extensions:


addExtension

public void addExtension(String extension,
                         Metadata metadata)
Maps an extension to some metadata (media type, language or character set) to an extension.

Parameters:
extension - The extension name.
metadata - The metadata to map.

addExtension

public void addExtension(String extension,
                         Metadata metadata,
                         boolean preferred)
Maps an extension to some metadata (media type, language or character set) to an extension.

Parameters:
extension - The extension name.
metadata - The metadata to map.
preferred - indicates if this mapping is the preferred one.

clearExtensions

public void clearExtensions()
clears the mappings for all extensions.


getAllCharacterSetExtensionNames

public List<String> getAllCharacterSetExtensionNames()
Return the ordered list of extension names mapped to character set.

Returns:
The ordered list of extension names mapped to character set.

getAllCharacterSets

public List<CharacterSet> getAllCharacterSets(String extension)
Returns all the character sets associated to this extension. It returns null if the extension was not declared.

Parameters:
extension - The extension name without any delimiter.
Returns:
The list of character sets associated to this extension.

getAllEncodingExtensionNames

public List<String> getAllEncodingExtensionNames()
Return the ordered list of extension names mapped to encodings.

Returns:
The ordered list of extension names mapped to encodings.

getAllExtensionNames

public List<String> getAllExtensionNames()
Return the ordered list of extension names.

Returns:
The ordered list of extension names.

getAllLanguageExtensionNames

public List<String> getAllLanguageExtensionNames()
Return the ordered list of extension names mapped to languages.

Returns:
The ordered list of extension names mapped to languages.

getAllLanguages

public List<Language> getAllLanguages(String extension)
Returns all the languages associated to this extension. It returns null if the extension was not declared.

Parameters:
extension - The extension name without any delimiter.
Returns:
The list of languages associated to this extension.

getAllMediaTypeExtensionNames

public List<String> getAllMediaTypeExtensionNames()
Return the ordered list of extension names mapped to media types.

Returns:
The ordered list of extension names mapped to media types.

getAllMediaTypes

public List<MediaType> getAllMediaTypes(String extension)
Returns all the media types associated to this extension. It returns null if the extension was not declared.

Parameters:
extension - The extension name without any delimiter.
Returns:
The list of media type associated to this extension.

getAllMetadata

public List<Metadata> getAllMetadata(String extension)
Returns all the metadata associated to this extension. It returns null if the extension was not declared.

Parameters:
extension - The extension name without any delimiter.
Returns:
The list of metadata associated to this extension.

getCharacterSet

public CharacterSet getCharacterSet(String extension)
Returns the character set associated to this extension. It returns null if the extension was not declared of it is corresponds to another type of medatata such as a media type. If several metadata are associated to the same extension then only the first matching metadata is returned.

Parameters:
extension - The extension name without any delimiter.
Returns:
The character set associated to this extension.

getDefaultCharacterSet

public CharacterSet getDefaultCharacterSet()
Returns the default character set for textual representations.

Returns:
The default character set for textual representations.

getDefaultEncoding

public Encoding getDefaultEncoding()
Returns the default encoding for representations.

Returns:
The default encoding for representations.

getDefaultLanguage

public Language getDefaultLanguage()
Returns the default language for representations.

Returns:
The default language for representations.

getDefaultMediaType

public MediaType getDefaultMediaType()
Returns the default media type for representations.

Returns:
The default media type for representations.

getEncoding

public Encoding getEncoding(String extension)
Returns the encoding associated to this extension. It returns null if the extension was not declared of it is corresponds to another type of medatata such as a media type. If several metadata are associated to the same extension then only the first matching metadata is returned.

Parameters:
extension - The extension name without any delimiter.
Returns:
The encoding associated to this extension.

getExtension

public String getExtension(Metadata metadata)
Returns the first extension mapping to this metadata.

Parameters:
metadata - The metadata to find.
Returns:
The first extension mapping to this metadata.

getLanguage

public Language getLanguage(String extension)
Returns the language associated to this extension. It returns null if the extension was not declared of it is corresponds to another type of medatata such as a media type. If several metadata are associated to the same extension then only the first matching metadata is returned.

Parameters:
extension - The extension name without any delimiter.
Returns:
The language associated to this extension.

getMediaType

public MediaType getMediaType(String extension)
Returns the mediatype associated to this extension. It returns null if the extension was not declared of it is corresponds to another type of medatata such as a language. If several metadata are associated to the same extension (ex: 'xml' for both 'text/xml' and 'application/xml') then only the first matching metadata is returned.

Parameters:
extension - The extension name without any delimiter.
Returns:
The media type associated to this extension.

getMetadata

public Metadata getMetadata(String extension)
Returns the metadata associated to this extension. It returns null if the extension was not declared. If several metadata are associated to the same extension (ex: 'xml' for both 'text/xml' and 'application/xml') then only the first matching metadata is returned.

Parameters:
extension - The extension name without any delimiter.
Returns:
The metadata associated to this extension.

getMetadata

public <T extends Metadata> T getMetadata(String extension,
                                          Class<T> metadataType)
Returns the metadata associated to this extension. It returns null if the extension was not declared or is not of the target metadata type.

Type Parameters:
T -
Parameters:
extension - The extension name without any delimiter.
metadataType - The target metadata type.
Returns:
The metadata associated to this extension.

setDefaultCharacterSet

public void setDefaultCharacterSet(CharacterSet defaultCharacterSet)
Sets the default character set for local representations.

Parameters:
defaultCharacterSet - The default character set for local representations.

setDefaultEncoding

public void setDefaultEncoding(Encoding defaultEncoding)
Sets the default encoding for local representations.

Parameters:
defaultEncoding - The default encoding for local representations.

setDefaultLanguage

public void setDefaultLanguage(Language defaultLanguage)
Sets the default language for local representations.

Parameters:
defaultLanguage - The default language for local representations.

setDefaultMediaType

public void setDefaultMediaType(MediaType defaultMediaType)
Sets the default media type for local representations.

Parameters:
defaultMediaType - The default media type for local representations.


Copyright © 2005-2013 Restlet.