Class XMPPathParser

java.lang.Object
com.itextpdf.xmp.impl.xpath.XMPPathParser

public final class XMPPathParser extends Object
Parser for XMP XPaths.
Since:
01.03.2006
  • Constructor Details

    • XMPPathParser

      private XMPPathParser()
      Private constructor
  • Method Details

    • expandXPath

      public static XMPPath expandXPath(String schemaNS, String path) throws XMPException
      Split an XMPPath expression apart at the conceptual steps, adding the root namespace prefix to the first property component. The schema URI is put in the first (0th) slot in the expanded XMPPath. Check if the top level component is an alias, but don't resolve it.

      In the most verbose case steps are separated by '/', and each step can be of these forms:

      prefix:name
      A top level property or struct field.
      [index]
      An element of an array.
      [last()]
      The last element of an array.
      [fieldName="value"]
      An element in an array of structs, chosen by a field value.
      [@xml:lang="value"]
      An element in an alt-text array, chosen by the xml:lang qualifier.
      [?qualName="value"]
      An element in an array, chosen by a qualifier value.
      @xml:lang
      An xml:lang qualifier.
      ?qualName
      A general qualifier.

      The logic is complicated though by shorthand for arrays, the separating '/' and leading '*' are optional. These are all equivalent: array/*[2] array/[2] array*[2] array[2] All of these are broken into the 2 steps "array" and "[2]".

      The value portion in the array selector forms is a string quoted by ''' or '"'. The value may contain any character including a doubled quoting character. The value may be empty.

      The syntax isn't checked, but an XML name begins with a letter or '_', and contains letters, digits, '.', '-', '_', and a bunch of special non-ASCII Unicode characters. An XML qualified name is a pair of names separated by a colon.

      Parameters:
      schemaNS - schema namespace
      path - property name
      Returns:
      Returns the expandet XMPPath.
      Throws:
      XMPException - Thrown if the format is not correct somehow.
    • skipPathDelimiter

      private static void skipPathDelimiter(String path, PathPosition pos) throws XMPException
      Parameters:
      path -
      pos -
      Throws:
      XMPException
    • parseStructSegment

      private static XMPPathSegment parseStructSegment(PathPosition pos) throws XMPException
      Parses a struct segment
      Parameters:
      pos - the current position in the path
      Returns:
      Retusn the segment or an errror
      Throws:
      XMPException - If the sement is empty
    • parseIndexSegment

      private static XMPPathSegment parseIndexSegment(PathPosition pos) throws XMPException
      Parses an array index segment.
      Parameters:
      pos - the xmp path
      Returns:
      Returns the segment or an error
      Throws:
      XMPException - thrown on xmp path errors
    • parseRootNode

      private static void parseRootNode(String schemaNS, PathPosition pos, XMPPath expandedXPath) throws XMPException
      Parses the root node of an XMP Path, checks if namespace and prefix fit together and resolve the property to the base property if it is an alias.
      Parameters:
      schemaNS - the root namespace
      pos - the parsing position helper
      expandedXPath - the path to contribute to
      Throws:
      XMPException - If the path is not valid.
    • verifyQualName

      private static void verifyQualName(String qualName) throws XMPException
      Verifies whether the qualifier name is not XML conformant or the namespace prefix has not been registered.
      Parameters:
      qualName - a qualifier name
      Throws:
      XMPException - If the name is not conformant
    • verifySimpleXMLName

      private static void verifySimpleXMLName(String name) throws XMPException
      Verify if an XML name is conformant.
      Parameters:
      name - an XML name
      Throws:
      XMPException - When the name is not XML conformant
    • verifyXPathRoot

      private static String verifyXPathRoot(String schemaNS, String rootProp) throws XMPException
      Set up the first 2 components of the expanded XMPPath. Normalizes the various cases of using the full schema URI and/or a qualified root property name. Returns true for normal processing. If allowUnknownSchemaNS is true and the schema namespace is not registered, false is returned. If allowUnknownSchemaNS is false and the schema namespace is not registered, an exception is thrown

      (Should someday check the full syntax:)

      Parameters:
      schemaNS - schema namespace
      rootProp - the root xpath segment
      Returns:
      Returns root QName.
      Throws:
      XMPException - Thrown if the format is not correct somehow.