Class Metadata
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
XMPMetadata
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMetadata()Constructs a new, empty metadata.Metadata(MetadataWriteLimiter writeLimiter) Constructs a new, empty metadata with the specified write limiter. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a metadata name/value mapping.protected voidAdd a metadata name/value mapping.voidAppends a value under a document- or tool-derived name, keyed asprefix + name.voidadd(KeyPrefix, String, String)for a source-typed date value (e.g. an OLE VT_DATE / OOXMLvt:filetimecustom property): the value is stored in Tika's canonical ISO-8601 form, identical to how curated datePropertyconstants serialize.voidAdds the integer value of the identified metadata property.voidAdd a metadata property/value mapping.voidAdds the date value of the identified metadata property.voidaddTrusted(String name, String value) Trusted add, bypassing the reserved-key guard: writes reach reserved Tika-native (tk:) keys directly.booleanGet the value associated to a metadata name.Returns the value (if any) of the identified metadata property.getBoolean(Property property) Returns the value of the identified Boolean based metadata property.Returns the value of the identified Date based metadata property.Returns the value of the identified Double based metadata property (REAL or RATIONAL value type, mirroringset(Property, double)).Returns the value of the identified Integer based metadata property.int[]getIntValues(Property property) Gets the array of ints of the identified "seq" integer metadata property.Returns the value of the identified Long based metadata property (INTEGER or REAL value type, mirroringset(Property, long)).long[]getLongValues(Property property) Gets the array of longs of the identified "seq" metadata property.String[]Get the values associated to a metadata name.String[]Get the values associated to a metadata name.inthashCode()booleanisMultiValued(String name) Returns true if named value is multivalued.booleanisMultiValued(Property property) Returns true if named value is multivalued.String[]names()Returns an array of the names contained in the metadata.static MetadatanewInstance(ParseContext context) Creates a new Metadata instance configured from the ParseContext.voidCopies every key fromotherinto this Metadata: for each name inother, this Metadata's values for that name are replaced wholesale withother's values, in order (multi-values preserved); names absent fromotherare left untouched.voidreconstruct(String name, String value, boolean append) Trusted write for clone/merge/deserialize; reserved keys go via their Property.voidRemove a metadata and all its associated values.voidRemove a metadata property and all its associated values.voidSet metadata name/value.protected voidvoidSets the integer value of the identified metadata property.voidSets the real or rational value of the identified metadata property.voidSets the integer value of the identified metadata property.voidSets the long value of the identified metadata property.voidSets the value of the identified metadata property.voidSets the values of the identified metadata property.voidSets the date value of the identified metadata property.voidSets the date value of the identified metadata property.voidsetTrusted(String name, String value) Trusted set, bypassing the reserved-key guard: writes reach reserved Tika-native (tk:) keys directly.intsize()Returns the number of metadata names in this metadata.toString()
-
Constructor Details
-
Metadata
public Metadata()Constructs a new, empty metadata. -
Metadata
Constructs a new, empty metadata with the specified write limiter. The limiter will be applied to all subsequent writes.- Parameters:
writeLimiter- the limiter to apply to metadata writes, or null for no limits- Since:
- Apache Tika 4.0.0
-
-
Method Details
-
newInstance
Creates a new Metadata instance configured from the ParseContext.If a
MetadataWriteLimiterFactoryis present in the context, the returned Metadata will have a write limiter that enforces those limits. Otherwise, returns a plain Metadata object with no limits.Parsers should use this method instead of
new Metadata()when creating metadata for embedded documents, to ensure limits are applied at creation time.- Parameters:
context- the ParseContext (may be null)- Returns:
- a new Metadata instance configured from the context
- Since:
- Apache Tika 4.0.0
-
isMultiValued
Returns true if named value is multivalued.- Parameters:
property- metadata property- Returns:
- true is named value is multivalued, false if single value or null
-
isMultiValued
Returns true if named value is multivalued.- Parameters:
name- name of metadata- Returns:
- true is named value is multivalued, false if single value or null
-
names
Returns an array of the names contained in the metadata.- Returns:
- Metadata names
-
get
Get the value associated to a metadata name. If many values are associated to the specified name, then the first one is returned.- Parameters:
name- of the metadata.- Returns:
- the value associated to the specified metadata name.
-
get
Returns the value (if any) of the identified metadata property. If many values are associated to the specified property, then the first one is returned.- Parameters:
property- property definition- Returns:
- property value, or
nullif the property is not set - Since:
- Apache Tika 0.7
-
getInt
Returns the value of the identified Integer based metadata property. If many values are associated to the specified property, then the first one is returned.- Parameters:
property- simple integer property definition- Returns:
- property value as a Integer, or
nullif the property is not set, or not a valid Integer - Since:
- Apache Tika 0.8
-
getDate
Returns the value of the identified Date based metadata property. If many values are associated to the specified property, then the first one is returned.- Parameters:
property- simple date property definition- Returns:
- property value as a Date, or
nullif the property is not set, or not a valid Date - Since:
- Apache Tika 0.8
-
getLong
Returns the value of the identified Long based metadata property (INTEGER or REAL value type, mirroringset(Property, long)). If many values are associated to the specified property, then the first one is returned.- Parameters:
property- simple integer or real property definition- Returns:
- property value as a Long, or
nullif the property is not set, or not a valid Long - Since:
- Apache Tika 4.0.0
-
getBoolean
Returns the value of the identified Boolean based metadata property. If many values are associated to the specified property, then the first one is returned.- Parameters:
property- simple boolean property definition- Returns:
- property value as a Boolean, or
nullif the property is not set, or not a valid Boolean - Since:
- Apache Tika 4.0.0
-
getDouble
Returns the value of the identified Double based metadata property (REAL or RATIONAL value type, mirroringset(Property, double)). If many values are associated to the specified property, then the first one is returned.- Parameters:
property- simple real or rational property definition- Returns:
- property value as a Double, or
nullif the property is not set, or not a valid Double - Since:
- Apache Tika 4.0.0
-
getValues
Get the values associated to a metadata name.- Parameters:
property- of the metadata.- Returns:
- the values associated to a metadata name.
-
getValues
Get the values associated to a metadata name.- Parameters:
name- of the metadata.- Returns:
- the values associated to a metadata name.
-
add
Add a metadata name/value mapping. Add the specified value to the list of values associated to the specified metadata name.This route rejects reserved Tika-native (
tk:) keys. It is for names the caller owns. Document-controlled names -- custom OOXML/MSG properties, NetCDF and GRIB attribute names -- must not come through here, because a crafted file could then assert Tika's own computed keys by naming one; route those throughadd(KeyPrefix, String, String), which namespaces them and applies skip-and-WARN bounds instead of throwing.If you are writing a key Tika owns, use its
Propertyoverload, oraddTrusted(java.lang.String, java.lang.String)when only the name is available.- Parameters:
name- the metadata name.value- the metadata value.- Throws:
IllegalArgumentException- ifnameis a reserved Tika-native (tk:) key; use itsPropertyoraddTrusted(java.lang.String, java.lang.String).- See Also:
-
addTrusted
Trusted add, bypassing the reserved-key guard: writes reach reserved Tika-native (tk:) keys directly. For internal/known-trusted writers (metadata filters, clone/merge/deserialize, emit-time enrichment) that legitimately need to assert a reserved key by name rather than by itsProperty. -
add
Appends a value under a document- or tool-derived name, keyed asprefix + name. This is the write route for names Tika does not control (custom document properties, format-specific attribute names, tool output): append-only (a repeated name accumulates values, losslessly transcribing the source), with a built-in safety net for hostile or malformed input — a null/blank name, a name longer thanMAX_PREFIX_ROUTE_NAME_LENGTH, or a new name arriving afterMAX_PREFIX_ROUTE_NAMESdistinct prefix-route names is skipped with a WARN, never an exception. Known, bounded vocabularies belong in curatedPropertyconstants instead; deployment-tunable limits belong in aStandardMetadataLimiter, which applies on top of this route.- Parameters:
prefix- the declared prefix for this source (never from document text)name- the source-derived name; skipped if null, blank, or over-lengthvalue- the value; a null value is skipped- Throws:
NullPointerException- if prefix is null- Since:
- Apache Tika 4.0.0
-
add
add(KeyPrefix, String, String)for a source-typed date value (e.g. an OLE VT_DATE / OOXMLvt:filetimecustom property): the value is stored in Tika's canonical ISO-8601 form, identical to how curated datePropertyconstants serialize. The date-typing travels with the value, not the key. An Instant too extreme to represent is skipped with a WARN. If the source's date field fails to parse in the first place, keep the raw text via the String overload instead.- Since:
- Apache Tika 4.0.0
-
reconstruct
Trusted write for clone/merge/deserialize; reserved keys go via their Property.- Parameters:
append- add rather than set- See Also:
-
putAll
Copies every key fromotherinto this Metadata: for each name inother, this Metadata's values for that name are replaced wholesale withother's values, in order (multi-values preserved); names absent fromotherare left untouched. Each value is written viareconstruct(String, String, boolean), so reservedtk:keys copy through their trusted route rather than the String-guarded route.Use this instead of a manual
for (String n : src.names()) dest.set(n, src.get(n))copy loop, which collapses multi-valued keys and throws ontk:-prefixed keys.- Parameters:
other- the Metadata to copy from;other == thisis a no-op- Throws:
NullPointerException- if other is null- Since:
- Apache Tika 4.0.0
-
add
Add a metadata name/value mapping. Add the specified value to the list of values associated to the specified metadata name.- Parameters:
name- the metadata name.newValues- the metadata values
-
add
Add a metadata property/value mapping. Add the specified value to the list of values associated to the specified metadata property.- Parameters:
property- the metadata property.value- the metadata value.
-
set
Set metadata name/value. Associate the specified value to the specified metadata name. If some previous values were associated to this name, they are removed. If the given value isnull, then the metadata entry is removed.This route rejects reserved Tika-native (
tk:) keys -- seeadd(String, String)for why, and use thePropertyoverload orsetTrusted(java.lang.String, java.lang.String)for keys Tika owns.- Parameters:
name- the metadata name.value- the metadata value, ornull- Throws:
IllegalArgumentException- ifnameis a reserved Tika-native (tk:) key andvalueis non-null; use itsPropertyorsetTrusted(java.lang.String, java.lang.String). A null value (removal) is always allowed, matchingremove(String).- See Also:
-
setTrusted
Trusted set, bypassing the reserved-key guard: writes reach reserved Tika-native (tk:) keys directly. SeeaddTrusted(java.lang.String, java.lang.String). -
set
-
set
Sets the value of the identified metadata property.- Parameters:
property- property definitionvalue- property value- Since:
- Apache Tika 0.7
-
set
Sets the values of the identified metadata property.- Parameters:
property- property definitionvalues- property values- Since:
- Apache Tika 1.2
-
set
Sets the integer value of the identified metadata property.- Parameters:
property- simple integer property definitionvalue- property value- Since:
- Apache Tika 0.8
-
set
Sets the long value of the identified metadata property.- Parameters:
property- simple integer or real property definitionvalue- property value- Since:
- Apache Tika 0.8
-
set
Sets the integer value of the identified metadata property.- Parameters:
property- simple integer property definitionvalue- property value- Since:
- Apache Tika 2.1.1
-
add
Adds the integer value of the identified metadata property.- Parameters:
property- seq integer property definitionvalue- property value- Since:
- Apache Tika 1.21
-
getIntValues
Gets the array of ints of the identified "seq" integer metadata property.- Parameters:
property- seq integer property definition- Returns:
- array of ints
- Since:
- Apache Tika 1.21
-
getLongValues
Gets the array of longs of the identified "seq" metadata property. INTEGER or REAL valued (mirroringgetLong(org.apache.tika.metadata.Property)).- Parameters:
property- seq integer or real property definition- Returns:
- array of longs
- Since:
- Apache Tika 1.21
-
set
Sets the real or rational value of the identified metadata property.- Parameters:
property- simple real or simple rational property definitionvalue- property value- Since:
- Apache Tika 0.8
-
set
Sets the date value of the identified metadata property.- Parameters:
property- simple integer property definitiondate- property value- Since:
- Apache Tika 0.8
-
set
Sets the date value of the identified metadata property.- Parameters:
property- simple integer property definitiondate- property value- Since:
- Apache Tika 0.8
-
add
Adds the date value of the identified metadata property.- Parameters:
property- simple calendar property definitiondate- property value- Since:
- Apache Tika 2.5.0
-
remove
Remove a metadata and all its associated values.- Parameters:
name- metadata name to remove
-
remove
Remove a metadata property and all its associated values.- Parameters:
property- metadata property to remove
-
size
public int size()Returns the number of metadata names in this metadata.- Returns:
- number of metadata names
-
hashCode
public int hashCode() -
equals
-
toString
-