Class DOMResource

java.lang.Object
de.wwu.scdh.annotation.selection.resource.DOMResource
All Implemented Interfaces:
Resource<net.sf.saxon.s9api.XdmNode>, S9ApiResource<net.sf.saxon.s9api.XdmNode>
Direct Known Subclasses:
MappedDOMResource

public class DOMResource extends Object implements S9ApiResource<net.sf.saxon.s9api.XdmNode>
A DOMResource is a web Resource that can be parsed to a DOM representation, e.g., an HTML or an XML document.
  • Constructor Details

    • DOMResource

      public DOMResource(URI uri, net.sf.saxon.s9api.XdmNode document, net.sf.saxon.s9api.Processor processor)
      Create a new DOMResource.
      Parameters:
      uri - a URI identifying the resource
      document - the document node (root node)
      processor - a saxon Processor that was used by the document builder
    • DOMResource

      public DOMResource(URI uri, Source source, net.sf.saxon.s9api.Processor processor) throws net.sf.saxon.s9api.SaxonApiException
      Create a new DOMResource from a parsed JAXP Source. The source is fed to Saxon's DocumentBuilder. Please notice the information on JAXP source types in the Saxon documentation.

      The uri is not systemId: The systemId is related to the physical location of the source and may be important for processing XIncludes or the like and determines the Base URI of the resulting nodes of the document. It should be set to the source, if required. In contrast, the uri must be seen as the IRI of the resource in a linked open data context. It is used to filter out selectors into the resource.

      Parameters:
      uri - a URI identifying the resource
      source - the document as a JAXP Source
      processor - a Saxon Processor to be used by the document builder
      Throws:
      net.sf.saxon.s9api.SaxonApiException - when the document builder fails
  • Method Details

    • fromHTML

      public static DOMResource fromHTML(URI uri, InputStream inputStream, String systemId, net.sf.saxon.s9api.Processor processor) throws net.sf.saxon.s9api.SaxonApiException
      Make a DOMResource from HTML input given as an InputStream. This uses the Cowan's Parser for parsing the HTML input, which may be tag soup.
      Parameters:
      uri - - a URI identifying the resource in a linked open data context
      inputStream - - InputStream with the HTML document
      systemId - - the physical location of the input stream, may be used for processing XIncludes
      processor - a Saxon Processor to be used by the document builder
      Throws:
      net.sf.saxon.s9api.SaxonApiException - when the document builder fails
    • fromHTML

      public static DOMResource fromHTML(URI uri, net.sf.saxon.s9api.Processor processor) throws IOException, net.sf.saxon.s9api.SaxonApiException
      Same as fromHTML(URI, InputStream, String, Processor), but gets the input from the URI.
      Parameters:
      uri - - a URI identifying the resource
      processor - - a Saxon Processor to be used by the document builder
      Throws:
      net.sf.saxon.s9api.SaxonApiException - when the document builder fails
      IOException
    • fromXML

      public static DOMResource fromXML(URI uri, InputStream inputStream, String systemId, net.sf.saxon.s9api.Processor processor) throws net.sf.saxon.s9api.SaxonApiException
      Make a DOMResource from XML input given as an InputStream.
      Parameters:
      uri - - a URI identifying the resource
      inputStream - - InputStream with the XML document
      systemId - - the systemId of the input stream, may be used to process XIncludes
      processor - - a Saxon Processor to be used by the document builder
      Throws:
      net.sf.saxon.s9api.SaxonApiException - when the document builder fails
    • fromXML

      public static DOMResource fromXML(URI uri, net.sf.saxon.s9api.Processor processor) throws IOException, net.sf.saxon.s9api.SaxonApiException
      Same as fromXML(URI, InputStream, String, Processor), but gets the input from the URI.
      Parameters:
      uri - - a URI identifying the resource
      processor - - a Saxon Processor to be used by the document builder
      Throws:
      net.sf.saxon.s9api.SaxonApiException - when the document builder fails
      IOException
    • fromXMLwithXerces

      public static DOMResource fromXMLwithXerces(URI uri, InputStream inputStream, String systemId, net.sf.saxon.s9api.Processor processor) throws ResourceException
      Make a MappedDOMResource from XML input given as an InputStream using the Xerces DOM parser. The parsed document is wrapped in XDM nodes, but the underlying nodes are w3c.xml.dom nodes.
      Parameters:
      uri - - a URI identifying the resource
      inputStream - - InputStream with the XML document
      systemId - - the systemId of the input stream, may be used to process XIncludes
      processor - - a Saxon Processor to be used by the document builder
      Throws:
      ResourceException - when the document builder fails
    • fromXMLwithXerces

      public static DOMResource fromXMLwithXerces(URI uri, net.sf.saxon.s9api.Processor processor) throws ResourceException
      Same as fromXMLwithXerces(URI, InputStream, String, Processor), but gets the input from the URI.
      Parameters:
      uri - a URI identifying the resource
      processor - - a sSaxon Processor to be used by the document builder
      Throws:
      ResourceException - when the document builder fails
    • getUri

      public URI getUri()
      Returns the URI identifying this resource.
      Specified by:
      getUri in interface Resource<net.sf.saxon.s9api.XdmNode>
    • getContents

      public net.sf.saxon.s9api.XdmNode getContents()
      Returns the document node of the DOM resource.
      Specified by:
      getContents in interface Resource<net.sf.saxon.s9api.XdmNode>
      Returns:
      an XdmNode
    • getProcessor

      public net.sf.saxon.s9api.Processor getProcessor()
      Returns the Saxon Processor the resource was parsed with.
      Specified by:
      getProcessor in interface S9ApiResource<net.sf.saxon.s9api.XdmNode>
      Returns:
      a Saxon Processor