Class XMP.Value
- java.lang.Object
-
- org.faceless.pdf2.XMP.Value
-
- Enclosing class:
- XMP
public static class XMP.Value extends java.lang.Object
A Value is a typed-value which is stored in the XMP against aXMP.Property
. Values may be simple (eg a Text value, which is a String), aList
of other values, or aMap
of [XMP.Property
, Value] pairs.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description XMP.Value
clone(XMP xmp)
Make a new deep copy of this Value which is tied to the specified XMP.XMP.Value
get(int i)
If the Value is aList
, return the indexed Value from that List, or null if the value is out of range.XMP.Value
get(java.lang.String key)
If the Value is aMap
, return the Value that matches the specified Property in the underlying map, or null if it doesn't exist.XMP.Value
get(XMP.Property key)
If the Value is aMap
, return the Value that matches the specified Property in the underlying map, or null if it doesn't exist.java.lang.Object
getData()
Return a copy of the data-value of this Value.java.lang.Object
getData(int i)
A convenience method that returns the data from the specified Value.java.lang.Object
getData(java.lang.String key)
A convenience method that returns the data from the specified Value.java.lang.Object
getData(XMP.Property key)
A convenience method that returns the data from the specified Value.java.util.Set<XMP.Property>
getFields()
If this Value is aMap
, return a read-only collection of the Fields that are set on this Value.java.lang.String
getLanguage()
A convenience method to return the"xml:lang"
qualifier set on this value, or null if not set.XMP.Value
getQualifier(XMP.Property p)
Return the Value associated with the specified qualifier property on this Value, if set, or null otherwise.java.util.Set<XMP.Property>
getQualifiers()
Return the set of "qualifier" Properties set on this value.java.lang.String
getRDFType()
Structured values in RDF can be stored using a particular element rather than rdf:Description, a format known as "Typed Nodes".XMP.Type
getType()
Return the Type of this Value.boolean
isList()
Return true if this Value is a list of other Valuesboolean
isMap()
Return true if this Value is a Map of other Values (also called a "Complex" or "Structured" type)boolean
isSimple()
Return true if this Value is neither a List or Map.XMP.Value
putQualifier(java.lang.String name, java.lang.Object data)
Set a Qualifier on this Value.void
putQualifier(XMP.Property p, XMP.Value value)
Set a Qualifier on this Value.void
set(int i, XMP.Value v)
Set the value in the underlying Collection, which must be aList
.void
set(XMP.Property p, XMP.Value v)
Set the value in the underlying Collection, which must be aMap
.int
size()
java.lang.String
toString()
-
-
-
Method Detail
-
getType
public XMP.Type getType()
Return the Type of this Value. Typically this will match the Type of theXMP.Property
that value is stored against, but not always - for example, if an XMP stream is read in where the expected value is a "Seq Text", and the value found is a "Text", thenProperty.getType()
will be "Seq Text" butValue.getType()
will be a type that isundefined
.
-
getRDFType
public java.lang.String getRDFType()
Structured values in RDF can be stored using a particular element rather than rdf:Description, a format known as "Typed Nodes". This was explicitly disallowed in XMP until 2008, but is allowable as of ISO16684 (XMP 2012). If a structured element is stored as a Typed Node, this method will return the URL of that node, which is defined as the concatenation of the namespace of the element and the localname. For any other type of Value, this returns null.
Typed nodes are stored as an
rdf:type
qualifier on the element. So this method is a convenience method forValue v = getQualifier(Property.TYPE); return v == null ? null : (String)v.getData();
-
getData
public java.lang.Object getData()
Return a copy of the data-value of this Value. The returned value will be a simple type - perhaps aString
,Boolean
,Number
,Calendar
or some other simple type, or aList
of those values (ifisList()
is true), or aMap
where the keys areString
representing the name and the values are a type returned by this method. Put another way, if this Value contain other Values, thegetData()
method will be called on those values recursively, to build up a structure.- Returns:
- the extracted data value, which is an independent copy of the content of this Value.
-
getQualifiers
public java.util.Set<XMP.Property> getQualifiers()
Return the set of "qualifier" Properties set on this value. Usually this will be an empty Set, as qualifiers are not common in XMP. The one qualifier that is commonly set is the "xml:lang" property, which is a qualifier commonly set on text data.- See Also:
XMP.Property.LANG
-
getQualifier
public XMP.Value getQualifier(XMP.Property p)
Return the Value associated with the specified qualifier property on this Value, if set, or null otherwise. For example, to identify the language set on this Value:Value langValue = value.getQualifier(Property.LANG); String lang = langValue == null ? null : (String)langValue.getData();
- See Also:
getLanguage()
,XMP.Property.LANG
-
putQualifier
public void putQualifier(XMP.Property p, XMP.Value value)
Set a Qualifier on this Value.- Parameters:
p
- the propertyvalue
- the value, which must be a new Value and not used elsewhere in this (or any other) XMP
-
putQualifier
public XMP.Value putQualifier(java.lang.String name, java.lang.Object data)
Set a Qualifier on this Value. If the specified property is known, this method is identical to the following code:
Property property = xmp.getProperty(name); value.putQualifier(property, property.getType().create(xmp, data));
If the property is not known, it will be created with an undefined type. This allows values to be quickly set on the XMP, although the resulting XMP would not validate against PDF/A-1, 2 or 3, or against a PDF/A-4 Schema.
- Parameters:
name
- the name of the propertydata
- the value
-
getLanguage
public java.lang.String getLanguage()
A convenience method to return the"xml:lang"
qualifier set on this value, or null if not set. Simply callsValue langValue = value.getQualifier(Property.LANG); return langValue == null ? null : (String)langValue.getData();
-
isList
public boolean isList()
Return true if this Value is a list of other Values
-
isMap
public boolean isMap()
Return true if this Value is a Map of other Values (also called a "Complex" or "Structured" type)
-
isSimple
public boolean isSimple()
Return true if this Value is neither a List or Map.
-
getFields
public java.util.Set<XMP.Property> getFields()
If this Value is aMap
, return a read-only collection of the Fields that are set on this Value. In a completely valid Value, the Fields will be a subset of theXMP.Type.getFields()
on this Type, but other Values may have been read in. For non-Map Values, returns an empty set.
-
size
public int size()
-
getData
public java.lang.Object getData(int i)
A convenience method that returns the data from the specified Value. Simply calls:Value v = get(i); return v == null ? null : v.getData();
- Parameters:
i
- the index into the underlying collection
-
getData
public java.lang.Object getData(java.lang.String key)
A convenience method that returns the data from the specified Value. Simply calls:Value v = get(key); return v == null ? null : v.getData();
- Parameters:
key
- the key in underlying collection
-
getData
public java.lang.Object getData(XMP.Property key)
A convenience method that returns the data from the specified Value. Simply calls:Value v = get(key); return v == null ? null : v.getData();
- Parameters:
key
- the key in underlying collection
-
get
public XMP.Value get(int i)
If the Value is aList
, return the indexed Value from that List, or null if the value is out of range. If the value is aMap
, return the ith entry in the list of keys, otherwise return null. If the Value is asimple
Value, return null.- Parameters:
i
- the index into the underlying collection
-
get
public XMP.Value get(XMP.Property key)
If the Value is aMap
, return the Value that matches the specified Property in the underlying map, or null if it doesn't exist. Otherwise, return null.- Parameters:
key
- the key into the underlying collection
-
get
public XMP.Value get(java.lang.String key)
If the Value is aMap
, return the Value that matches the specified Property in the underlying map, or null if it doesn't exist. As a special case, if the Value is aList
then this will return the value that has the specifiedgetLanguage()
qualifier set - for example:Value value = xmp.get(xmp.getProperty("dc:title")); if (value != null) { Value defaultTitle = value.get("x-default"); Value frenchTitle = value.get("fr"); }
It a List value has no matching language qualifier, or the Type is asimple
type, return null.- Parameters:
key
- the key into the underlying collection
-
set
public void set(int i, XMP.Value v)
Set the value in the underlying Collection, which must be aList
.- Parameters:
i
- the index into the list - set tosize()
to add an entry to the end of the listv
- the value to set, which must not be used elsewhere in the XMP. If null, that index is removed from the list
-
set
public void set(XMP.Property p, XMP.Value v)
Set the value in the underlying Collection, which must be aMap
. The property should ideally be taken fromgetType().getFields()
, but this is not enforced.- Parameters:
p
- the Property to use as a key in this Map.v
- the value to set. If it's null, the value is removed.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
clone
public XMP.Value clone(XMP xmp)
Make a new deep copy of this Value which is tied to the specified XMP. object. Repairs may be made to the value if the target XMP belongs to PDF that has specific requirements; for example, if the target XMP is on a PDF/A document, undefined fields will be removed.- Since:
- 2.25
-
-