Class XMLMetadata

java.lang.Object
org.apache.sis.storage.geotiff.XMLMetadata
All Implemented Interfaces:
Filter

final class XMLMetadata extends Object implements Filter
Supports for metadata encoded in XML inside a GeoTIFF tags. This is a temporary object used only at parsing time. Two TIFF tags are associated to XML data:
  • GDAL_METADATA (A480) stored as ASCII characters.
  • GEO_METADATA (C6DD) stored as bytes with UTF-8 encoding.
GEO_METADATA is defined by the Defense Geospatial Information Working Group (DGIWG) in the GeoTIFF Profile for Georeferenced Imagery standard.
Since:
1.2
Version:
1.2
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
    Parser of GDAL metadata.
    (package private) static final class 
    A tree-table representation of the XML document contained in the enclosing XMLMetadata.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private byte[]
    The bytes to decode as an XML document.
    private String
    Name of the XML element being processed.
    private final boolean
    true if the XML is GDAL metadata.
    private static final String
    The "Item" string, used in GDAL metadata.
    private final StoreListeners
    Where to report non-fatal warnings.
    private static final String
    The "name" string, used in GDAL metadata.
    private XMLMetadata
    The next metadata in a list of linked metadata.
    private String
    The XML document as string.
  • Constructor Summary

    Constructors
    Constructor
    Description
    XMLMetadata(String xml, boolean isGDAL)
    Creates a new instance with the given XML.
    XMLMetadata(Reader reader, Type type, long count, short tag)
    Creates new metadata which will decode the given vector of bytes.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Converts an XML element and its children to a tree table node.
    Appends the content of this object to the given metadata builder.
    (package private) final void
    Appends this metadata at the end of a linked list starting with the given element.
    boolean
    Returns true if the XML document could not be read.
    boolean
    Invoked when a non-fatal warning occurs during the parsing of XML document.
    (package private) String
    tag()
    Returns the name of the tag from which the XML has been read.
    Returns the XML document as a character string, or null if the document could not be read.
    Returns a reader for the XML document, or null if the document could not be read.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • ITEM

      private static final String ITEM
      The "Item" string, used in GDAL metadata.
      See Also:
    • NAME

      private static final String NAME
      The "name" string, used in GDAL metadata.
      See Also:
    • bytes

      private byte[] bytes
      The bytes to decode as an XML document. DGIWG specification mandates UTF-8 encoding.
    • string

      private String string
      The XML document as string.
    • currentElement

      private String currentElement
      Name of the XML element being processed. Used for error message only: this field is left to a non-null value if an exception occurred during XML parsing.
    • listeners

      private final StoreListeners listeners
      Where to report non-fatal warnings.
    • isGDAL

      private final boolean isGDAL
      true if the XML is GDAL metadata. Example:
    • next

      private XMLMetadata next
      The next metadata in a list of linked metadata. Should always be null, but we nevertheless define this field in case a file defines more than one GEO_METADATA or GDAL_METADATA tags.
  • Constructor Details

    • XMLMetadata

      XMLMetadata(String xml, boolean isGDAL)
      Creates a new instance with the given XML. Used for testing purposes.
    • XMLMetadata

      XMLMetadata(Reader reader, Type type, long count, short tag) throws IOException
      Creates new metadata which will decode the given vector of bytes.
      Parameters:
      reader - the TIFF reader.
      type - type of the metadata tag to read.
      count - number of bytes or characters in the value to read.
      tag - the tag where the metadata was stored.
      Throws:
      IOException
  • Method Details

    • appendTo

      final void appendTo(XMLMetadata head)
      Appends this metadata at the end of a linked list starting with the given element. This method is inefficient because it iterates over all elements for reaching the tail, but it should not be an issue because this method is invoked only in the unlikely case where a file would define more than one *_METADATA tag.
      Parameters:
      head - first element of the linked list where to append this metadata.
    • tag

      String tag()
      Returns the name of the tag from which the XML has been read. This is used for error messages.
    • isEmpty

      public boolean isEmpty()
      Returns true if the XML document could not be read.
    • toString

      public String toString()
      Returns the XML document as a character string, or null if the document could not be read.
      Overrides:
      toString in class Object
    • toXML

      private XMLEventReader toXML() throws XMLStreamException
      Returns a reader for the XML document, or null if the document could not be read.
      Throws:
      XMLStreamException
    • append

      private void append(XMLEventReader reader, StartElement element, TreeTable.Node node) throws XMLStreamException
      Converts an XML element and its children to a tree table node. This is used for NativeMetadata representation.
      Parameters:
      reader - the XML reader with its cursor set after the XML element.
      element - the XML element to append.
      node - an initially empty node which is added to the tree.
      Throws:
      XMLStreamException
    • appendTo

      public XMLMetadata appendTo(MetadataBuilder metadata) throws XMLStreamException, JAXBException
      Appends the content of this object to the given metadata builder.
      Parameters:
      metadata - the builder where to append the content of this XMLMetadata.
      Returns:
      the next metadata in a linked list of metadata, or null if none.
      Throws:
      XMLStreamException - if an error occurred while parsing the XML.
      JAXBException - if an error occurred while parsing the XML.
    • isLoggable

      public boolean isLoggable(LogRecord warning)
      Invoked when a non-fatal warning occurs during the parsing of XML document.
      Specified by:
      isLoggable in interface Filter