Class XMPPathParser


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

      Constructors 
      Modifier Constructor Description
      private XMPPathParser()
      Private constructor
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static XMPPath expandXPath​(java.lang.String schemaNS, java.lang.String path)
      Split an XMPPath expression apart at the conceptual steps, adding the root namespace prefix to the first property component.
      private static XMPPathSegment parseIndexSegment​(PathPosition pos)
      Parses an array index segment.
      private static void parseRootNode​(java.lang.String schemaNS, PathPosition pos, XMPPath expandedXPath)
      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.
      private static XMPPathSegment parseStructSegment​(PathPosition pos)
      Parses a struct segment
      private static void skipPathDelimiter​(java.lang.String path, PathPosition pos)  
      private static void verifyQualName​(java.lang.String qualName)
      Verifies whether the qualifier name is not XML conformant or the namespace prefix has not been registered.
      private static void verifySimpleXMLName​(java.lang.String name)
      Verify if an XML name is conformant.
      private static java.lang.String verifyXPathRoot​(java.lang.String schemaNS, java.lang.String rootProp)
      Set up the first 2 components of the expanded XMPPath.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XMPPathParser

        private XMPPathParser()
        Private constructor
    • Method Detail

      • expandXPath

        public static XMPPath expandXPath​(java.lang.String schemaNS,
                                          java.lang.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.
      • 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​(java.lang.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​(java.lang.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​(java.lang.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 java.lang.String verifyXPathRoot​(java.lang.String schemaNS,
                                                        java.lang.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.