Content type detection based on the resource name. An instance of this class contains a set of regular expression patterns that are matched against the resource name potentially given as a part of the input metadata.
If a pattern matches the given name, then the media type associated with that pattern is returned as the likely content type of the input document. Otherwise the returned type is
detect(InputStream, Metadata)method for more details of the matching algorithm.
- Apache Tika 0.3
- See Also:
- Serialized Form
All Methods Instance Methods Concrete Methods Modifier and Type Method Description
detect(InputStream input, Metadata metadata)Detects the content type of an input document based on the document name given in the input metadata.
NameDetectorCreates a new content type detector based on the given name patterns. The given pattern map is not copied, so the caller may update the mappings even after this detector instance has been created. However, the map must not be concurrently modified while this instance is used for type detection.
patterns- map from name patterns to corresponding media types
public MediaType detect(InputStream input, Metadata metadata)Detects the content type of an input document based on the document name given in the input metadata. The RESOURCE_NAME_KEY attribute of the given input metadata is expected to contain the name (normally a file name or a URL) of the input document.
If a resource name is given, then it is first processed as follows.
- Potential URL query (?...) and fragment identifier (#...) parts are removed from the end of the resource name.
- Potential leading path elements (up to the last slash or backslash) are removed from the beginning of the resource name.
- Potential URL encodings (%nn, in UTF-8) are decoded.
- Any leading and trailing whitespace is removed.
The resulting name string (if any) is then matched in sequence against all the configured name patterns. If a match is found, then the (first) matching media type is returned.