Class AbstractXMLDepictContext

java.lang.Object
com.globalmentor.beans.BoundPropertyObject
All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, DepictContext, TextDepictContext, XMLDepictContext
Direct Known Subclasses:
AbstractXHTMLDepictContext

public abstract class AbstractXMLDepictContext extends AbstractTextDepictContext implements XMLDepictContext
Abstract encapsulation of text/xml information related to the current depiction.
Author:
Garret Wilson
  • Constructor Details

    • AbstractXMLDepictContext

      public AbstractXMLDepictContext(GuiseSession session, Destination destination) throws IOException
      Guise session constructor.
      Parameters:
      session - The Guise user session of which this context is a part.
      destination - The destination with which this context is associated.
      Throws:
      NullPointerException - if the given session and/or destination is null.
      IOException - If there was an I/O error loading a needed resource.
  • Method Details

    • getMessageDigest

      protected MessageDigest getMessageDigest()
      Returns:
      The message digest for creating hashes on the platform.
    • getXMLNamespacePrefixManager

      protected com.globalmentor.xml.XMLNamespacePrefixManager getXMLNamespacePrefixManager()
      Returns:
      The manager of prefixes paired with XML namespaces.
    • isHashAttributesGenerated

      protected boolean isHashAttributesGenerated()
      Returns:
      Whether attributes should be generated representing the hash of XML attributes and content.
    • setHashAttributesGenerated

      protected void setHashAttributesGenerated(boolean generateHashAttributes)
      Sets whether attributes should be generated representing the hash of XML attributes and content.
      Parameters:
      generateHashAttributes - Whether hash attributes should be generated.
    • getAttributeHashAttributeQualifiedName

      protected abstract com.globalmentor.xml.spec.NsQualifiedName getAttributeHashAttributeQualifiedName()
      Returns:
      The qualified name to use for the attribute hash attribute.
    • getContentHashAttributeQualifiedName

      protected abstract com.globalmentor.xml.spec.NsQualifiedName getContentHashAttributeQualifiedName()
      Returns:
      The qualified name to use for the content hash attribute.
    • clearDepictText

      public void clearDepictText()
      Description copied from interface: TextDepictContext
      Clears all data collected for depiction.
      Specified by:
      clearDepictText in interface TextDepictContext
      Overrides:
      clearDepictText in class AbstractTextDepictContext
    • getDepictStringBuilder

      public StringBuilder getDepictStringBuilder()
      The string builder that holds the current content being collected, though not necessarily all the content collected. The string builder returned is appropriate for adding content, but may not be a complete representation of all the text collected.

      This version returns the string builder of the current element state, if there is an element state available.

      Specified by:
      getDepictStringBuilder in interface TextDepictContext
      Overrides:
      getDepictStringBuilder in class AbstractTextDepictContext
      Returns:
      The string builder that holds the current content being collected for depiction.
    • encode

      protected String encode(String string)
      Encodes text information for writing. This version encodes XML characters.
      Overrides:
      encode in class AbstractTextDepictContext
      Parameters:
      string - The text information to encode.
      Returns:
      The encoded text.
    • appendAttribute

      protected <A extends Appendable> A appendAttribute(A appendable, com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName, String attributeValue) throws IOException
      Appends an attribute and its value to the given appendable.
      Type Parameters:
      A - The type of the appendable.
      Parameters:
      appendable - The appendable to which the attribute should be appended.
      attributeQualifiedName - The qualified name of the attribute.
      attributeValue - The value of the attribute.
      Returns:
      The given appendable.
      Throws:
      IOException - if there is a problem appending the attribute information.
    • appendAttributeName

      protected <A extends Appendable> A appendAttributeName(A appendable, com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName) throws IOException
      Appends an attribute name to the given appendable.

      This implementation appends the attribute qname.

      Type Parameters:
      A - The type of the appendable.
      Parameters:
      appendable - The appendable to which the attribute should be appended.
      attributeQualifiedName - The qualified name of the attribute.
      Returns:
      The given appendable.
      Throws:
      IOException - if there is a problem appending the attribute information.
      See Also:
      • NsQualifiedName.getQualifiedName()
    • appendAttributeValue

      protected <A extends Appendable> A appendAttributeValue(A appendable, String attributeValue) throws IOException
      Appends an attribute value to the given appendable.

      This implementation first encodes and then appends appends the given value.

      Type Parameters:
      A - The type of the appendable.
      Parameters:
      appendable - The appendable to which the attribute should be appended.
      attributeValue - The value of the attribute.
      Returns:
      The given appendable.
      Throws:
      IOException - if there is a problem appending the attribute information.
      See Also:
    • getAttributeValue

      protected String getAttributeValue(com.globalmentor.xml.spec.NsQualifiedName elementQualifiedName, com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName, String attributeValue)
      Retrieves the value of a given attribute. This method is provided so that the platform may manipulate an attribute if needed. This version returns the given attribute value unmodified.
      Parameters:
      elementQualifiedName - The qualified name of the element.
      attributeQualifiedName - The qualified name of the attribute.
      attributeValue - The default value of the attribute.
      Returns:
      The value of the attribute.
    • getQualifiedName

      public String getQualifiedName(URI namespaceURI, String localName)
      Description copied from interface: XMLDepictContext
      Retrieves the qualified name of the given namespace and local name. If the namespace URI is not recognized, a new prefix will be generated for that namespace This method therefore works for attributes in the null namespace, but cannot work for elements in the null namespace because this would be ambiguous with elements in the the XHTML namespace.
      Specified by:
      getQualifiedName in interface XMLDepictContext
      Parameters:
      namespaceURI - The URI of the XML namespace, or null if there is no namespace and there should be no prefix.
      localName - The local name of the element or attribute with no prefix.
      Returns:
      The XML qualified name.
    • writeDocType

      public void writeDocType(boolean writeXMLDeclaration, URI namespaceURI, String localName) throws IOException
      Description copied from interface: XMLDepictContext
      Writes a doctype along with an optional XML declaration to the string builder and sets the output content type. No system ID or public ID will be written.
      Specified by:
      writeDocType in interface XMLDepictContext
      Parameters:
      writeXMLDeclaration - Whether an XML declaration should be included before the doctype.
      namespaceURI - The URI of the XML namespace of document element, or null if there is no namespace.
      localName - The local name of the document element with no prefix.
      Throws:
      IOException - if there is an error writing the information.
    • writeDocType

      public void writeDocType(boolean writeXMLDeclaration, URI namespaceURI, String localName, com.globalmentor.net.MediaType contentType) throws IOException
      Description copied from interface: XMLDepictContext
      Writes a doctype along with an optional XML declaration to the string builder and sets the output content type. No system ID or public ID will be written.
      Specified by:
      writeDocType in interface XMLDepictContext
      Parameters:
      writeXMLDeclaration - Whether an XML declaration should be included before the doctype.
      namespaceURI - The URI of the XML namespace of document element, or null if there is no namespace.
      localName - The local name of the document element with no prefix.
      contentType - The specific XML content type.
      Throws:
      IOException - if there is an error writing the information.
    • writeDocType

      public void writeDocType(boolean writeXMLDeclaration, URI namespaceURI, String localName, String publicID) throws IOException
      Description copied from interface: XMLDepictContext
      Writes a doctype along with an optional XML declaration to the string builder and sets the output content type. The system ID and content type will be determined from the given public ID.
      Specified by:
      writeDocType in interface XMLDepictContext
      Parameters:
      writeXMLDeclaration - Whether an XML declaration should be included before the doctype.
      namespaceURI - The URI of the XML namespace of document element, or null if there is no namespace.
      localName - The local name of the document element with no prefix.
      publicID - The XML declaration public ID.
      Throws:
      IOException - if there is an error writing the information.
    • writeDocType

      public void writeDocType(boolean writeXMLDeclaration, URI namespaceURI, String localName, String publicID, String systemID, com.globalmentor.net.MediaType contentType) throws IOException
      Description copied from interface: XMLDepictContext
      Writes a doctype along with an optional XML declaration to the string builder and sets the output content type.
      Specified by:
      writeDocType in interface XMLDepictContext
      Parameters:
      writeXMLDeclaration - Whether an XML declaration should be included before the doctype.
      namespaceURI - The URI of the XML namespace of document element, or null if there is no namespace.
      localName - The local name of the document element with no prefix.
      publicID - The XML declaration public ID, or null if none is used.
      systemID - The XML declaration system ID, or null if one can be determined from the given public ID.
      contentType - The specific XML content type, or null if a content type should be determined from the public ID; otherwise will default to "text/xml".
      Throws:
      IOException - if there is an error writing the information.
    • writeElementBegin

      public XMLDepictContext.ElementState writeElementBegin(URI namespaceURI, String localName) throws IOException
      Description copied from interface: XMLDepictContext
      Begins an XML element that will not be an empty element, even if it has no content.
      Specified by:
      writeElementBegin in interface XMLDepictContext
      Parameters:
      namespaceURI - The URI of the XML namespace of the element, or null if there is no namespace.
      localName - The local name of the element with no prefix.
      Returns:
      The state of the element being written.
      Throws:
      IOException - if there is an error writing the information.
    • writeElementBegin

      public XMLDepictContext.ElementState writeElementBegin(URI namespaceURI, String localName, boolean isEmptyElementAllowed) throws IOException
      Description copied from interface: XMLDepictContext
      Begins an XML element, specifying whether an empty element is allowed.
      Specified by:
      writeElementBegin in interface XMLDepictContext
      Parameters:
      namespaceURI - The URI of the XML namespace of the element, or null if there is no namespace.
      localName - The local name of the element with no prefix.
      isEmptyElementAllowed - Whether an empty element can be created if there is no content.
      Returns:
      The state of the element being written.
      Throws:
      IOException - if there is an error writing the information.
    • writeElementEnd

      public XMLDepictContext.ElementState writeElementEnd(URI namespaceURI, String localName) throws IOException
      Description copied from interface: XMLDepictContext
      Ends an XML element.
      Specified by:
      writeElementEnd in interface XMLDepictContext
      Parameters:
      namespaceURI - The URI of the XML namespace of the element, or null if there is no namespace.
      localName - The local name of the element with no prefix.
      Returns:
      The state of the element being written.
      Throws:
      IOException - if there is an error writing the information.
    • writeAttribute

      public void writeAttribute(URI namespaceURI, String localName, String value) throws IOException
      Writes an attribute of an XML element. The attribute value will be properly encoded for XML.

      This implementation only recognizes the null namespace and the XML namespace, which is assumed to require a prefix of "xml".

      Specified by:
      writeAttribute in interface XMLDepictContext
      Parameters:
      namespaceURI - The URI of the XML namespace of the attribute, or null if there is no namespace.
      localName - The local name of the attribute with no prefix.
      value - The unencoded value of the attribute.
      Throws:
      IOException - if there is an error writing the information.
    • writeCommentOpen

      public void writeCommentOpen() throws IOException
      Description copied from interface: XMLDepictContext
      Writes the beginning part of an XML comment.
      Specified by:
      writeCommentOpen in interface XMLDepictContext
      Throws:
      IOException - if there is an error writing the information.
      See Also:
    • writeCommentClose

      public void writeCommentClose() throws IOException
      Description copied from interface: XMLDepictContext
      Writes the ending part of an XML comment.
      Specified by:
      writeCommentClose in interface XMLDepictContext
      Throws:
      IOException - if there is an error writing the information.
      See Also:
    • writeComment

      public void writeComment(String comment) throws IOException
      Description copied from interface: XMLDepictContext
      Writes an XML comment. This method ensures that any open beginning tag has been closed.
      Specified by:
      writeComment in interface XMLDepictContext
      Parameters:
      comment - The comment to write.
      Throws:
      IOException - if there is an error writing the information.
      See Also: