Class SimpleXMLResource

java.lang.Object
org.xmldb.api.sdk.modules.BaseResource
org.xmldb.api.sdk.modules.SimpleXMLResource
All Implemented Interfaces:
Resource, XMLResource
Direct Known Subclasses:
XMLResourceImpl

public abstract class SimpleXMLResource extends BaseResource implements XMLResource
Provides access to XML resources stored in the database. An XMLResource can be accessed either as text XML or via the DOM or SAX APIs.

The default behavior for getContent and setContent is to work with XML data as text so these methods work on String content.

  • Constructor Details

    • SimpleXMLResource

      public SimpleXMLResource(Collection parent, String id, String documentID)
      Create a new XMLResource without any content.
    • SimpleXMLResource

      public SimpleXMLResource(Collection parent, String id, String documentID, String content)
      Create a fully initialized XMLResource
  • Method Details

    • getDocumentId

      public String getDocumentId() throws XMLDBException
      Returns the ID for the parent document of this resource.
      Specified by:
      getDocumentId in interface XMLResource
      Returns:
      the id for the parent document of this Resource or null if there is no parent document for this Resource.
      Throws:
      XMLDBException - with expected error codes.
      ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
    • getResourceType

      public String getResourceType() throws XMLDBException
      Returns the resource type for this Resource.
      Specified by:
      getResourceType in interface Resource
      Returns:
      the resource type for the Resource.
      Throws:
      XMLDBException - with expected error codes.
      ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
    • getContent

      public Object getContent() throws XMLDBException
      Retrieves the content from the resource. The type of the content varies depending what type of resource is being used.
      Specified by:
      getContent in interface Resource
      Returns:
      the content of the resource.
      Throws:
      XMLDBException - with expected error codes.
      ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
    • setContent

      public void setContent(Object value) throws XMLDBException
      Sets the content for this resource. The type of content that can be set depends on the type of resource being used.
      Specified by:
      setContent in interface Resource
      Parameters:
      value - the content value to set for the resource.
      Throws:
      XMLDBException - with expected error codes.
      ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
    • getContentAsDOM

      public Node getContentAsDOM() throws XMLDBException
      Returns the content of the Resource as a DOM Node.
      Specified by:
      getContentAsDOM in interface XMLResource
      Returns:
      The XML content as a DOM Node
      Throws:
      XMLDBException - with expected error codes.
      ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
    • setContentAsDOM

      public void setContentAsDOM(Node content) throws XMLDBException
      Sets the content of the Resource using a DOM Node as the source.
      Specified by:
      setContentAsDOM in interface XMLResource
      Parameters:
      content - The new content value
      Throws:
      XMLDBException - with expected error codes.
      ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
      ErrorCodes.INVALID_RESOURCE if the content value provided is null.
      ErrorCodes.WRONG_CONTENT_TYPE if the content provided in not a valid DOM Node.
    • getContentAsSAX

      public void getContentAsSAX(ContentHandler handler) throws XMLDBException
      Allows you to use a ContentHandler to parse the XML data from the database for use in an application.
      Specified by:
      getContentAsSAX in interface XMLResource
      Parameters:
      handler - the SAX ContentHandler to use to handle the Resource content.
      Throws:
      XMLDBException - with expected error codes.
      ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
      ErrorCodes.INVALID_RESOURCE if the ContentHandler provided is null.
    • setContentAsSAX

      public ContentHandler setContentAsSAX() throws XMLDBException
      Sets the content of the Resource using a SAX ContentHandler.
      Specified by:
      setContentAsSAX in interface XMLResource
      Returns:
      a SAX ContentHandler that can be used to add content into the Resource.
      Throws:
      XMLDBException - with expected error codes.
      ErrorCodes.VENDOR_ERROR for any vendor specific errors that occur.
    • setSAXFeature

      public void setSAXFeature(String feature, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException
      Sets a SAX feature that will be used when this XMLResource is used to produce SAX events (through the getContentAsSAX() method)
      Specified by:
      setSAXFeature in interface XMLResource
      Parameters:
      feature - Feature name. Standard SAX feature names are documented at http://sax.sourceforge.net/.
      value - Set or unset feature
      Throws:
      SAXNotRecognizedException
      SAXNotSupportedException
    • getSAXFeature

      public boolean getSAXFeature(String feature) throws SAXNotRecognizedException, SAXNotSupportedException
      Returns current setting of a SAX feature that will be used when this XMLResource is used to produce SAX events (through the getContentAsSAX() method)
      Specified by:
      getSAXFeature in interface XMLResource
      Parameters:
      feature - Feature name. Standard SAX feature names are documented at http://sax.sourceforge.net/.
      Returns:
      whether the feature is set
      Throws:
      SAXNotRecognizedException
      SAXNotSupportedException