Class ParseRDF

  • All Implemented Interfaces:
    XMPConst, XMPError

    public class ParseRDF
    extends java.lang.Object
    implements XMPError, XMPConst
    Parser for "normal" XML serialisation of RDF.
    Since:
    14.07.2006
    • Constructor Detail

      • ParseRDF

        public ParseRDF()
    • Method Detail

      • parse

        static XMPMetaImpl parse​(org.w3c.dom.Node xmlRoot)
                          throws XMPException
        The main parsing method. The XML tree is walked through from the root node and and XMP tree is created. This is a raw parse, the normalisation of the XMP tree happens outside.
        Parameters:
        xmlRoot - the XML root node
        Returns:
        Returns an XMP metadata object (not normalized)
        Throws:
        XMPException - Occurs if the parsing fails for any reason.
      • rdf_RDF

        static void rdf_RDF​(XMPMetaImpl xmp,
                            org.w3c.dom.Node rdfRdfNode)
                     throws XMPException
        Each of these parsing methods is responsible for recognizing an RDF syntax production and adding the appropriate structure to the XMP tree. They simply return for success, failures will throw an exception.
        Parameters:
        xmp - the xmp metadata object that is generated
        rdfRdfNode - the top-level xml node
        Throws:
        XMPException - thown on parsing errors
      • rdf_NodeElementList

        private static void rdf_NodeElementList​(XMPMetaImpl xmp,
                                                XMPNode xmpParent,
                                                org.w3c.dom.Node rdfRdfNode)
                                         throws XMPException
        7.2.10 nodeElementList
        ws* ( nodeElement ws* )* Note: this method is only called from the rdf:RDF-node (top level)
        Parameters:
        xmp - the xmp metadata object that is generated
        xmpParent - the parent xmp node
        rdfRdfNode - the top-level xml node
        Throws:
        XMPException - thown on parsing errors
      • rdf_NodeElement

        private static void rdf_NodeElement​(XMPMetaImpl xmp,
                                            XMPNode xmpParent,
                                            org.w3c.dom.Node xmlNode,
                                            boolean isTopLevel)
                                     throws XMPException
        7.2.5 nodeElementURIs anyURI - ( coreSyntaxTerms | rdf:li | oldTerms ) 7.2.11 nodeElement start-element ( URI == nodeElementURIs, attributes == set ( ( idAttr | nodeIdAttr | aboutAttr )?, propertyAttr* ) ) propertyEltList end-element() A node element URI is rdf:Description or anything else that is not an RDF term.
        Parameters:
        xmp - the xmp metadata object that is generated
        xmpParent - the parent xmp node
        xmlNode - the currently processed XML node
        isTopLevel - Flag if the node is a top-level node
        Throws:
        XMPException - thown on parsing errors
      • rdf_NodeElementAttrs

        private static void rdf_NodeElementAttrs​(XMPMetaImpl xmp,
                                                 XMPNode xmpParent,
                                                 org.w3c.dom.Node xmlNode,
                                                 boolean isTopLevel)
                                          throws XMPException
        7.2.7 propertyAttributeURIs anyURI - ( coreSyntaxTerms | rdf:Description | rdf:li | oldTerms ) 7.2.11 nodeElement start-element ( URI == nodeElementURIs, attributes == set ( ( idAttr | nodeIdAttr | aboutAttr )?, propertyAttr* ) ) propertyEltList end-element() Process the attribute list for an RDF node element. A property attribute URI is anything other than an RDF term. The rdf:ID and rdf:nodeID attributes are simply ignored, as are rdf:about attributes on inner nodes.
        Parameters:
        xmp - the xmp metadata object that is generated
        xmpParent - the parent xmp node
        xmlNode - the currently processed XML node
        isTopLevel - Flag if the node is a top-level node
        Throws:
        XMPException - thown on parsing errors
      • rdf_PropertyElementList

        private static void rdf_PropertyElementList​(XMPMetaImpl xmp,
                                                    XMPNode xmpParent,
                                                    org.w3c.dom.Node xmlParent,
                                                    boolean isTopLevel)
                                             throws XMPException
        7.2.13 propertyEltList ws* ( propertyElt ws* )*
        Parameters:
        xmp - the xmp metadata object that is generated
        xmpParent - the parent xmp node
        xmlParent - the currently processed XML node
        isTopLevel - Flag if the node is a top-level node
        Throws:
        XMPException - thown on parsing errors
      • rdf_PropertyElement

        private static void rdf_PropertyElement​(XMPMetaImpl xmp,
                                                XMPNode xmpParent,
                                                org.w3c.dom.Node xmlNode,
                                                boolean isTopLevel)
                                         throws XMPException
        7.2.14 propertyElt resourcePropertyElt | literalPropertyElt | parseTypeLiteralPropertyElt | parseTypeResourcePropertyElt | parseTypeCollectionPropertyElt | parseTypeOtherPropertyElt | emptyPropertyElt 7.2.15 resourcePropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr? ) ) ws* nodeElement ws* end-element() 7.2.16 literalPropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, datatypeAttr?) ) text() end-element() 7.2.17 parseTypeLiteralPropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, parseLiteral ) ) literal end-element() 7.2.18 parseTypeResourcePropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, parseResource ) ) propertyEltList end-element() 7.2.19 parseTypeCollectionPropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, parseCollection ) ) nodeElementList end-element() 7.2.20 parseTypeOtherPropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, parseOther ) ) propertyEltList end-element() 7.2.21 emptyPropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, ( resourceAttr | nodeIdAttr )?, propertyAttr* ) ) end-element() The various property element forms are not distinguished by the XML element name, but by their attributes for the most part. The exceptions are resourcePropertyElt and literalPropertyElt. They are distinguished by their XML element content. NOTE: The RDF syntax does not explicitly include the xml:lang attribute although it can appear in many of these. We have to allow for it in the attibute counts below.
        Parameters:
        xmp - the xmp metadata object that is generated
        xmpParent - the parent xmp node
        xmlNode - the currently processed XML node
        isTopLevel - Flag if the node is a top-level node
        Throws:
        XMPException - thown on parsing errors
      • rdf_ResourcePropertyElement

        private static void rdf_ResourcePropertyElement​(XMPMetaImpl xmp,
                                                        XMPNode xmpParent,
                                                        org.w3c.dom.Node xmlNode,
                                                        boolean isTopLevel)
                                                 throws XMPException
        7.2.15 resourcePropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr? ) ) ws* nodeElement ws* end-element() This handles structs using an rdf:Description node, arrays using rdf:Bag/Seq/Alt, and typedNodes. It also catches and cleans up qualified properties written with rdf:Description and rdf:value.
        Parameters:
        xmp - the xmp metadata object that is generated
        xmpParent - the parent xmp node
        xmlNode - the currently processed XML node
        isTopLevel - Flag if the node is a top-level node
        Throws:
        XMPException - thown on parsing errors
      • rdf_LiteralPropertyElement

        private static void rdf_LiteralPropertyElement​(XMPMetaImpl xmp,
                                                       XMPNode xmpParent,
                                                       org.w3c.dom.Node xmlNode,
                                                       boolean isTopLevel)
                                                throws XMPException
        7.2.16 literalPropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, datatypeAttr?) ) text() end-element() Add a leaf node with the text value and qualifiers for the attributes.
        Parameters:
        xmp - the xmp metadata object that is generated
        xmpParent - the parent xmp node
        xmlNode - the currently processed XML node
        isTopLevel - Flag if the node is a top-level node
        Throws:
        XMPException - thown on parsing errors
      • rdf_ParseTypeLiteralPropertyElement

        private static void rdf_ParseTypeLiteralPropertyElement()
                                                         throws XMPException
        7.2.17 parseTypeLiteralPropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, parseLiteral ) ) literal end-element()
        Throws:
        XMPException - thown on parsing errors
      • rdf_ParseTypeResourcePropertyElement

        private static void rdf_ParseTypeResourcePropertyElement​(XMPMetaImpl xmp,
                                                                 XMPNode xmpParent,
                                                                 org.w3c.dom.Node xmlNode,
                                                                 boolean isTopLevel)
                                                          throws XMPException
        7.2.18 parseTypeResourcePropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, parseResource ) ) propertyEltList end-element() Add a new struct node with a qualifier for the possible rdf:ID attribute. Then process the XML child nodes to get the struct fields.
        Parameters:
        xmp - the xmp metadata object that is generated
        xmpParent - the parent xmp node
        xmlNode - the currently processed XML node
        isTopLevel - Flag if the node is a top-level node
        Throws:
        XMPException - thown on parsing errors
      • rdf_ParseTypeCollectionPropertyElement

        private static void rdf_ParseTypeCollectionPropertyElement()
                                                            throws XMPException
        7.2.19 parseTypeCollectionPropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, parseCollection ) ) nodeElementList end-element()
        Throws:
        XMPException - thown on parsing errors
      • rdf_ParseTypeOtherPropertyElement

        private static void rdf_ParseTypeOtherPropertyElement()
                                                       throws XMPException
        7.2.20 parseTypeOtherPropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, parseOther ) ) propertyEltList end-element()
        Throws:
        XMPException - thown on parsing errors
      • rdf_EmptyPropertyElement

        private static void rdf_EmptyPropertyElement​(XMPMetaImpl xmp,
                                                     XMPNode xmpParent,
                                                     org.w3c.dom.Node xmlNode,
                                                     boolean isTopLevel)
                                              throws XMPException
        7.2.21 emptyPropertyElt start-element ( URI == propertyElementURIs, attributes == set ( idAttr?, ( resourceAttr | nodeIdAttr )?, propertyAttr* ) ) end-element() An emptyPropertyElt is an element with no contained content, just a possibly empty set of attributes. An emptyPropertyElt can represent three special cases of simple XMP properties: a simple property with an empty value (ns:Prop1), a simple property whose value is a URI (ns:Prop2), or a simple property with simple qualifiers (ns:Prop3). An emptyPropertyElt can also represent an XMP struct whose fields are all simple and unqualified (ns:Prop4). It is an error to use both rdf:value and rdf:resource - that can lead to invalid RDF in the verbose form written using a literalPropertyElt. The XMP mapping for an emptyPropertyElt is a bit different from generic RDF, partly for design reasons and partly for historical reasons. The XMP mapping rules are:
        1. If there is an rdf:value attribute then this is a simple property with a text value. All other attributes are qualifiers.
        2. If there is an rdf:resource attribute then this is a simple property with a URI value. All other attributes are qualifiers.
        3. If there are no attributes other than xml:lang, rdf:ID, or rdf:nodeID then this is a simple property with an empty value.
        4. Otherwise this is a struct, the attributes other than xml:lang, rdf:ID, or rdf:nodeID are fields.
        Parameters:
        xmp - the xmp metadata object that is generated
        xmpParent - the parent xmp node
        xmlNode - the currently processed XML node
        isTopLevel - Flag if the node is a top-level node
        Throws:
        XMPException - thown on parsing errors
      • addChildNode

        private static XMPNode addChildNode​(XMPMetaImpl xmp,
                                            XMPNode xmpParent,
                                            org.w3c.dom.Node xmlNode,
                                            java.lang.String value,
                                            boolean isTopLevel)
                                     throws XMPException
        Adds a child node.
        Parameters:
        xmp - the xmp metadata object that is generated
        xmpParent - the parent xmp node
        xmlNode - the currently processed XML node
        value - Node value
        isTopLevel - Flag if the node is a top-level node
        Returns:
        Returns the newly created child node.
        Throws:
        XMPException - thown on parsing errors
      • addQualifierNode

        private static XMPNode addQualifierNode​(XMPNode xmpParent,
                                                java.lang.String name,
                                                java.lang.String value)
                                         throws XMPException
        Adds a qualifier node.
        Parameters:
        xmpParent - the parent xmp node
        name - the name of the qualifier which has to be QName including the default prefix
        value - the value of the qualifier
        Returns:
        Returns the newly created child node.
        Throws:
        XMPException - thown on parsing errors
      • fixupQualifiedNode

        private static void fixupQualifiedNode​(XMPNode xmpParent)
                                        throws XMPException
        The parent is an RDF pseudo-struct containing an rdf:value field. Fix the XMP data model. The rdf:value node must be the first child, the other children are qualifiers. The form, value, and children of the rdf:value node are the real ones. The rdf:value node's qualifiers must be added to the others.
        Parameters:
        xmpParent - the parent xmp node
        Throws:
        XMPException - thown on parsing errors
      • isWhitespaceNode

        private static boolean isWhitespaceNode​(org.w3c.dom.Node node)
        Checks if the node is a white space.
        Parameters:
        node - an XML-node
        Returns:
        Returns whether the node is a whitespace node, i.e. a text node that contains only whitespaces.
      • isPropertyElementName

        private static boolean isPropertyElementName​(int term)
        7.2.6 propertyElementURIs anyURI - ( coreSyntaxTerms | rdf:Description | oldTerms )
        Parameters:
        term - the term id
        Returns:
        Return true if the term is a property element name.
      • isOldTerm

        private static boolean isOldTerm​(int term)
        7.2.4 oldTerms
        rdf:aboutEach | rdf:aboutEachPrefix | rdf:bagID
        Parameters:
        term - the term id
        Returns:
        Returns true if the term is an old term.
      • isCoreSyntaxTerm

        private static boolean isCoreSyntaxTerm​(int term)
        7.2.2 coreSyntaxTerms
        rdf:RDF | rdf:ID | rdf:about | rdf:parseType | rdf:resource | rdf:nodeID | rdf:datatype
        Parameters:
        term - the term id
        Returns:
        Return true if the term is a core syntax term
      • getRDFTermKind

        private static int getRDFTermKind​(org.w3c.dom.Node node)
        Determines the ID for a certain RDF Term. Arranged to hopefully minimize the parse time for large XMP.
        Parameters:
        node - an XML node
        Returns:
        Returns the term ID.