| java.lang.Object it.unimi.dsi.mg4j.document.AbstractDocumentFactory it.unimi.dsi.mg4j.document.PropertyBasedDocumentFactory
All known Subclasses: it.unimi.dsi.mg4j.document.IdentityDocumentFactory, it.unimi.dsi.mg4j.document.DispatchingDocumentFactory, it.unimi.dsi.mg4j.document.PdfDocumentFactory, it.unimi.dsi.mg4j.document.HtmlDocumentFactory, test.it.unimi.dsi.mg4j.document.FirstByteDocumentFactory, test.it.unimi.dsi.mg4j.document.NullDocumentFactory,
PropertyBasedDocumentFactory | abstract public class PropertyBasedDocumentFactory extends AbstractDocumentFactory (Code) | | A document factory initialised by default properties.
Many document factories need a number of default values that are used when
the metadata passed to
it.unimi.dsi.mg4j.document.DocumentFactory.getDocument(java.io.InputStreamReference2ObjectMap) is
not sufficient or lacks some key. This abstract class provides a common base for all such factories.
All concrete implementations of this class should have:
- an empty constructor;
- a constructor taking a
it.unimi.dsi.fastutil.objects.Reference2ObjectMap having
java.lang.Enum keys;
- a constructor taking a
Properties object;
- a constructor taking a string array.
In the third case, the properties will be parsed by the
PropertyBasedDocumentFactory.parseProperties(Properties) method. In the fourth case, by the
PropertyBasedDocumentFactory.parseProperties(String[]) method.
Since all implementations are expected to provide such constructors, corresponding
have been provided to
simplify factory instantiation.
If the implementation needs to read and parse some key, it must override the
PropertyBasedDocumentFactory.parseProperty(String,String[],Reference2ObjectMap) method.
Keys are specified with a dotted notation. The last dot-separated token is the actual key. The prefix is used
to select properties: only properties with a prefix that is a prefix of the current class name are considered.
Moreover, if a property with a completely specified prefix (i.e., a prefix that is a class name) is not parsed
an exception will be thrown.
This class provide helpers methods
PropertyBasedDocumentFactory.resolve(Enum,Reference2ObjectMap) and
PropertyBasedDocumentFactory.resolveNotNull(Enum,Reference2ObjectMap) to help in writing implementations of
it.unimi.dsi.mg4j.document.DocumentFactory.getDocument(java.io.InputStreamReference2ObjectMap) that
handle default metadata correctly.
|
Inner Class :public static enum MetadataKeys | |
Method Summary | |
protected static String | ensureJustOne(String key, String[] values) This method checks that the array of values contains just one element, and returns the element.
Parameters: key - the property name (used to build the exception message). Parameters: values - the array of values. | public static PropertyBasedDocumentFactory | getInstance(Class> klass, String[] property) | public static PropertyBasedDocumentFactory | getInstance(Class> klass, Properties properties) | public static PropertyBasedDocumentFactory | getInstance(Class> klass) | public static PropertyBasedDocumentFactory | getInstance(Class> klass, Reference2ObjectMap<Enum<?>, Object> metadata) | public Reference2ObjectMap<Enum<?>, Object> | parseProperties(Properties properties) Scans the property set, parsing the properties that concern this class.
Parameters: properties - a set of properties. | public Reference2ObjectMap<Enum<?>, Object> | parseProperties(String[] property) Parses the given list of properties either as key=value specs (value may
be a list of comma-separated values), or as filenames.
Parameters: property - an array of strings specifying properties. | protected boolean | parseProperty(String key, String[] valuesUnused, Reference2ObjectMap<Enum<?>, Object> metadataUnused) Parses a property with given key and value, adding it to the given map. | protected Object | resolve(Enum> key, Reference2ObjectMap<Enum<?>, Object> metadata) Resolves the given key against the given metadata, falling back to the default metadata.
Parameters: key - a key. Parameters: metadata - a metadata map. | protected Object | resolve(Enum> key, Reference2ObjectMap<Enum<?>, Object> metadata, Object o) Resolves the given key against the given metadata, falling back to the provided object.
Parameters: key - a key. Parameters: metadata - a metadata map. Parameters: o - a default object. | protected Object | resolveNotNull(Enum> key, Reference2ObjectMap<Enum<?>, Object> metadata) Resolves the given key against the given metadata, falling back to the default metadata
and guaranteeing a non-null result.
Parameters: key - a key. Parameters: metadata - a metadata map. | public static boolean | sameKey(Enum> enumKey, String key) A utility method checking whether the downcased name of an
Enum is equal to a given string.
This class uses an
Enum (
MetadataKeys ) to store valid property keys. |
PropertyBasedDocumentFactory | protected PropertyBasedDocumentFactory(Reference2ObjectMap<Enum<?>, Object> defaultMetadata)(Code) | | |
PropertyBasedDocumentFactory | protected PropertyBasedDocumentFactory(Properties properties) throws ConfigurationException(Code) | | |
PropertyBasedDocumentFactory | protected PropertyBasedDocumentFactory(String[] property) throws ConfigurationException(Code) | | |
PropertyBasedDocumentFactory | protected PropertyBasedDocumentFactory()(Code) | | |
ensureJustOne | protected static String ensureJustOne(String key, String[] values) throws ConfigurationException(Code) | | This method checks that the array of values contains just one element, and returns the element.
Parameters: key - the property name (used to build the exception message). Parameters: values - the array of values. the only value (if the array contains exactly one element). throws: ConfigurationException - iff values does not contain a single element. |
parseProperties | public Reference2ObjectMap<Enum<?>, Object> parseProperties(Properties properties) throws ConfigurationException(Code) | | Scans the property set, parsing the properties that concern this class.
Parameters: properties - a set of properties. a metadata map. |
parseProperties | public Reference2ObjectMap<Enum<?>, Object> parseProperties(String[] property) throws ConfigurationException(Code) | | Parses the given list of properties either as key=value specs (value may
be a list of comma-separated values), or as filenames.
Parameters: property - an array of strings specifying properties. a metadata map. |
parseProperty | protected boolean parseProperty(String key, String[] valuesUnused, Reference2ObjectMap<Enum<?>, Object> metadataUnused) throws ConfigurationException(Code) | | Parses a property with given key and value, adding it to the given map.
Currently this implementation just parses the
MetadataKeys.LOCALE property.
Subclasses should do their own parsing, returing true in case of success and
returning super.parseProperty() otherwise.
Parameters: key - the property key. Parameters: valuesUnused - the property value; this is an array, because properties may have a list of comma-separated values. Parameters: metadataUnused - the metadata map. true if the property was parsed correctly, false if it was ignored. |
resolve | protected Object resolve(Enum> key, Reference2ObjectMap<Enum<?>, Object> metadata)(Code) | | Resolves the given key against the given metadata, falling back to the default metadata.
Parameters: key - a key. Parameters: metadata - a metadata map. the value returned by metadata for key , or the valuereturned by PropertyBasedDocumentFactory.defaultMetadata for key if the former is null (the latter,of course, might be null ). |
resolve | protected Object resolve(Enum> key, Reference2ObjectMap<Enum<?>, Object> metadata, Object o)(Code) | | Resolves the given key against the given metadata, falling back to the provided object.
Parameters: key - a key. Parameters: metadata - a metadata map. Parameters: o - a default object. the value returned by metadata for key , or o if theformer is null . |
resolveNotNull | protected Object resolveNotNull(Enum> key, Reference2ObjectMap<Enum<?>, Object> metadata)(Code) | | Resolves the given key against the given metadata, falling back to the default metadata
and guaranteeing a non-null result.
Parameters: key - a key. Parameters: metadata - a metadata map. the value returned by metadata for key , or the valuereturned by PropertyBasedDocumentFactory.defaultMetadata for key if the former is null ; if thelatter is null , too, a NoSuchElementException will be thrown. |
sameKey | public static boolean sameKey(Enum> enumKey, String key)(Code) | | A utility method checking whether the downcased name of an
Enum is equal to a given string.
This class uses an
Enum (
MetadataKeys ) to store valid property keys. We follow
both the uppercase naming convention for enums and the lowercase naming convention for properties,
and this method encapsulates the method calls that necessary to correctly handle key parsing.
Parameters: enumKey - a key expressed as an Enum. Parameters: key - a key expressed as a string. true if key is equal to the downcased of enumKey . |
|
|