gov.lanl.archive.resource
Class MIMEParse
java.lang.Object
gov.lanl.archive.resource.MIMEParse
public final class MIMEParse
- extends Object
MIME-Type Parser
This class provides basic functions for handling mime-types. It can handle
matching mime-types against a list of media-ranges. See section 14.1 of the
HTTP specification [RFC 2616] for a complete explanation.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
A port to Java of Joe Gregorio's MIME-Type Parser:
http://code.google.com/p/mimeparse/
Ported by Tom Zellman .
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
parseMimeType
protected static MIMEParse.ParseResults parseMimeType(String mimeType)
- Carves up a mime-type and returns a ParseResults object
For example, the media range 'application/xhtml;q=0.5' would get parsed
into:
('application', 'xhtml', {'q', '0.5'})
parseMediaRange
protected static MIMEParse.ParseResults parseMediaRange(String range)
- Carves up a media range and returns a ParseResults.
For example, the media range 'application/*;q=0.5' would get parsed into:
('application', '*', {'q', '0.5'})
In addition this function also guarantees that there is a value for 'q'
in the params dictionary, filling it in with a proper default if
necessary.
- Parameters:
range
-
fitnessAndQualityParsed
protected static MIMEParse.FitnessAndQuality fitnessAndQualityParsed(String mimeType,
Collection<MIMEParse.ParseResults> parsedRanges)
- Find the best match for a given mimeType against a list of media_ranges
that have already been parsed by MimeParse.parseMediaRange(). Returns a
tuple of the fitness value and the value of the 'q' quality parameter of
the best match, or (-1, 0) if no match was found. Just as for
quality_parsed(), 'parsed_ranges' must be a list of parsed media ranges.
- Parameters:
mimeType
- parsedRanges
-
qualityParsed
protected static float qualityParsed(String mimeType,
Collection<MIMEParse.ParseResults> parsedRanges)
- Find the best match for a given mime-type against a list of ranges that
have already been parsed by parseMediaRange(). Returns the 'q' quality
parameter of the best match, 0 if no match was found. This function
bahaves the same as quality() except that 'parsed_ranges' must be a list
of parsed media ranges.
- Parameters:
mimeType
- parsedRanges
-
- Returns:
quality
public static float quality(String mimeType,
String ranges)
- Returns the quality 'q' of a mime-type when compared against the
mediaRanges in ranges. For example:
- Parameters:
mimeType
- parsedRanges
-
bestMatch
public static String bestMatch(Collection<String> supported,
String header)
- Takes a list of supported mime-types and finds the best match for all the
media-ranges listed in header. The value of header must be a string that
conforms to the format of the HTTP Accept: header. The value of
'supported' is a list of mime-types.
MimeParse.bestMatch(Arrays.asList(new String[]{"application/xbel+xml",
"text/xml"}), "text/*;q=0.5,*; q=0.1") 'text/xml'
- Parameters:
supported
- header
-
- Returns:
Copyright © 2013. All Rights Reserved.