public final class MimePath extends Object
In order to fully understand the scale of the problem the mime path is trying to describe you should consider two things. First a document can contain several different embedded fragments each of a different mime type. Second, each embeded fragment itself can possibly contain one or more other embedded fragments and this nesting can in theory go indefinitely deep.
In reality the nesting probably will not be very deep. As an example of a document containing an embedded fragment of another document of the different mime type you could imagine a JSP page containing a Java scriplet. The main document is the JSP page of the 'text/x-jsp' mime type, which includes a fragment of Java source code of the 'text/x-java' mime type.
The mime path comes handy when we want to distinguish between the ordinary 'text/x-java' mime type and the 'text/x-java' mime type embedded in the JSP page, because both of those 'text/x-java' mime types will have a different mime path. The ordinary 'text/x-java' mime type has a mime path consisting of just one mime type - 'text/x-java'. The 'text/x-java' mime type embeded in the JSP page, however, has a mime path comprised from two mime types 'text/x-jsp' and 'text/x-java'. The order of mime types in a mime path is obviously very important, because it describes how the mime types are embedded.
The mime path can be represented as a
String simply by
concatenating all its mime types separated by the '/' character. Since
mime types always contain one and only one '/' character it is clear which
'/' character belongs to a mime type and which is the mime path separator.
In the above example the mime path of the 'text/x-java' mime type embedded in the 'text/x-jsp' mime type can be represented as 'text/x-jsp/text/x-java'.
For some languages it is not uncommon to allow embedding of itself. For example
in Ruby it is allowed to use Ruby code within strings and Ruby will
evaluate this code when evaluating the value of the strings. Depending on the
implementation of a lexer there can be tokens with
contains several consecutive mime types that are the same.
The format of a valid mime type string is described in
MimePath performs internall checks according to this specification.
Identity: By definition two
MimePath instances are equal
if they represent the same string mime path. The implementation guarantees
that by caching and reusing instances of the
MimePath that it
MimePath instances can be used as keys in maps.
Lifecycle: Although the instances of
internally cached and should survive for certain time without being referenced
from outside of the MimePath API, clients are strongly encouraged to hold
a reference to the
MimePath they obtained throughout the whole
lifecycle of their component. For example an opened java editor with a document
should keep its instance of the 'text/x-java'
MimePath for the
whole time the editor is open.
|Modifier and Type||Field and Description|
The root of all mime paths.
|Modifier and Type||Method and Description|
Gets the mime path corresponding to a mime type embedded in another mime type.
Gets the mime path for the given mime type.
Returns the included Mime paths.
Returns the inherited Mime type.
Get mime type of this mime-path at the given index.
Get string path represented by this mime-path.
Return prefix mime-path with the given number of mime-type components ranging from zero till the size of this mime-path.
Parses a mime path string and returns its
Get total number of mime-types in the mime-path.
Validates a path to check if it's a valid mime path.
Validates components of a mime type.
public static final MimePath EMPTY
MimePathwill contain exactly one element and it will be the mime type passed in as the parameter.
mimeType- The mime type to get the mime path for. If
nullor empty string is passed in the
EMPTYmime path will be returned.
MimePathfor the given mime type or
MimePath.EMPTYif the mime type is
nullor empty string.
For example for a java scriplet embedded in a jsp page the
be the mime path 'text/x-jsp' and
mimeType would be 'text/x-java'.
The method will return the 'text/x-jsp/text/x-java' mime path.
prefix- The mime path determining the mime type that embedds the mime type passed in in the second parameter. It can be
EMPTYin which case the call will be equivalent to calling
mimeType- The mime type that is embedded in the mime type determined by the
The format of a mime path string representation is a string of mime type components comprising the mime path separated by the '/' character. For example a mime path representing the 'text/x-java' mime type embedded in the 'text/x-jsp' mime type can be represented as the following string - 'text/x-jsp/text/x-java'.
The mime path string can be an empty string, which represents the
EMPTY mime path. By definition all valid mime paths except of
the empty one have to contain odd number of '/' characters.
path- The mime path string representation.
public static boolean validate(CharSequence type, CharSequence subtype)
type- The type component of a mime type to validate. If
nullthe type component will not be validated.
subtype- The subtype component of a mime type to validate. If
nullthe subtype component will not be validated.
trueif non-null components passed in are valid mime type components, otherwise
public static boolean validate(CharSequence path)
truethe path is a valid mime path string and can be used in the
path- The path string to validate.
trueif the path string is a valid mime path.
public String getPath()
public int size()
EMPTYmime-path has zero size.
"text/x-jsp/text/x-java"has size 2.
public String getMimeType(int index)
public MimePath getPrefix(int size)
public String getInheritedType()
null. For most other mime types, returns
"". If the mime type derives from another one, such as text/ant+xml derives from xml, the return value will be the base mime type (text/xml in the example case). For MimePaths that identified embedded content (more components on the MimePath), the method returns the parent MIME of the last MIME type on the path
null, if no parent exists (for
EMPTYMimePaths, the list contains at least one entry, and the last entry is the
EMPTY. Note also, that the complete MimePath is always returned as the 1st member of the list. The returned sequence of MimePaths is suitable for searching settings or services for the (embedded) content whose type is described by MimePath as it is ordered from the most specific to the least specific paths (including generalization) and always contains the mime type of the identified contents. The last component ("") represents default settings (services). Note that for MimePaths created from a mime type (not empty!) string, the
getInheritedPaths().get(1)is a parent mime type. Either empty, or the generalized MIME. The caller should not modify the returned List.
Built on March 17 2018. | Portions Copyright 1997-2018 Oracle. All rights reserved.