Class AbstractXMLDepictContext

    • Field Summary

      • Fields inherited from class com.globalmentor.beans.BoundPropertyObject

        NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected <A extends java.lang.Appendable>
      A
      appendAttribute​(A appendable, com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName, java.lang.String attributeValue)
      Appends an attribute and its value to the given appendable.
      protected <A extends java.lang.Appendable>
      A
      appendAttributeName​(A appendable, com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName)
      Appends an attribute name to the given appendable.
      protected <A extends java.lang.Appendable>
      A
      appendAttributeValue​(A appendable, java.lang.String attributeValue)
      Appends an attribute value to the given appendable.
      void clearDepictText()
      Clears all data collected for depiction.
      protected java.lang.String encode​(java.lang.String string)
      Encodes text information for writing.
      protected abstract com.globalmentor.xml.spec.NsQualifiedName getAttributeHashAttributeQualifiedName()  
      protected java.lang.String getAttributeValue​(com.globalmentor.xml.spec.NsQualifiedName elementQualifiedName, com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName, java.lang.String attributeValue)
      Retrieves the value of a given attribute.
      protected abstract com.globalmentor.xml.spec.NsQualifiedName getContentHashAttributeQualifiedName()  
      java.lang.StringBuilder getDepictStringBuilder()
      The string builder that holds the current content being collected, though not necessarily all the content collected.
      protected java.security.MessageDigest getMessageDigest()  
      java.lang.String getQualifiedName​(java.net.URI namespaceURI, java.lang.String localName)
      Retrieves the qualified name of the given namespace and local name.
      protected com.globalmentor.xml.XMLNamespacePrefixManager getXMLNamespacePrefixManager()  
      protected boolean isHashAttributesGenerated()  
      protected void setHashAttributesGenerated​(boolean generateHashAttributes)
      Sets whether attributes should be generated representing the hash of XML attributes and content.
      void writeAttribute​(java.net.URI namespaceURI, java.lang.String localName, java.lang.String value)
      Writes an attribute of an XML element.
      void writeComment​(java.lang.String comment)
      Writes an XML comment.
      void writeCommentClose()
      Writes the ending part of an XML comment.
      void writeCommentOpen()
      Writes the beginning part of an XML comment.
      void writeDocType​(boolean writeXMLDeclaration, java.net.URI namespaceURI, java.lang.String localName)
      Writes a doctype along with an optional XML declaration to the string builder and sets the output content type.
      void writeDocType​(boolean writeXMLDeclaration, java.net.URI namespaceURI, java.lang.String localName, com.globalmentor.net.MediaType contentType)
      Writes a doctype along with an optional XML declaration to the string builder and sets the output content type.
      void writeDocType​(boolean writeXMLDeclaration, java.net.URI namespaceURI, java.lang.String localName, java.lang.String publicID)
      Writes a doctype along with an optional XML declaration to the string builder and sets the output content type.
      void writeDocType​(boolean writeXMLDeclaration, java.net.URI namespaceURI, java.lang.String localName, java.lang.String publicID, java.lang.String systemID, com.globalmentor.net.MediaType contentType)
      Writes a doctype along with an optional XML declaration to the string builder and sets the output content type.
      XMLDepictContext.ElementState writeElementBegin​(java.net.URI namespaceURI, java.lang.String localName)
      Begins an XML element that will not be an empty element, even if it has no content.
      XMLDepictContext.ElementState writeElementBegin​(java.net.URI namespaceURI, java.lang.String localName, boolean isEmptyElementAllowed)
      Begins an XML element, specifying whether an empty element is allowed.
      XMLDepictContext.ElementState writeElementEnd​(java.net.URI namespaceURI, java.lang.String localName)
      Ends an XML element.
      • Methods inherited from class com.globalmentor.beans.BoundPropertyObject

        addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPostponedPropertyChangeEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getForwardPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getRepeatPropertyChangeListener, getRepeatVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, getVetoableChangeSupport, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface com.globalmentor.beans.PropertyBindable

        addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
    • Constructor Detail

      • AbstractXMLDepictContext

        public AbstractXMLDepictContext​(GuiseSession session,
                                        Destination destination)
                                 throws java.io.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:
        java.lang.NullPointerException - if the given session and/or destination is null.
        java.io.IOException - If there was an I/O error loading a needed resource.
    • Method Detail

      • getMessageDigest

        protected java.security.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.
      • getDepictStringBuilder

        public java.lang.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 java.lang.String encode​(java.lang.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 java.lang.Appendable> A appendAttribute​(A appendable,
                                                                     com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName,
                                                                     java.lang.String attributeValue)
                                                              throws java.io.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:
        java.io.IOException - if there is a problem appending the attribute information.
      • appendAttributeName

        protected <A extends java.lang.Appendable> A appendAttributeName​(A appendable,
                                                                         com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName)
                                                                  throws java.io.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:
        java.io.IOException - if there is a problem appending the attribute information.
        See Also:
        NsQualifiedName.getQualifiedName()
      • appendAttributeValue

        protected <A extends java.lang.Appendable> A appendAttributeValue​(A appendable,
                                                                          java.lang.String attributeValue)
                                                                   throws java.io.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:
        java.io.IOException - if there is a problem appending the attribute information.
        See Also:
        encode(String)
      • getAttributeValue

        protected java.lang.String getAttributeValue​(com.globalmentor.xml.spec.NsQualifiedName elementQualifiedName,
                                                     com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName,
                                                     java.lang.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 java.lang.String getQualifiedName​(java.net.URI namespaceURI,
                                                 java.lang.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,
                                 java.net.URI namespaceURI,
                                 java.lang.String localName)
                          throws java.io.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:
        java.io.IOException - if there is an error writing the information.
      • writeDocType

        public void writeDocType​(boolean writeXMLDeclaration,
                                 java.net.URI namespaceURI,
                                 java.lang.String localName,
                                 com.globalmentor.net.MediaType contentType)
                          throws java.io.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:
        java.io.IOException - if there is an error writing the information.
      • writeDocType

        public void writeDocType​(boolean writeXMLDeclaration,
                                 java.net.URI namespaceURI,
                                 java.lang.String localName,
                                 java.lang.String publicID)
                          throws java.io.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:
        java.io.IOException - if there is an error writing the information.
      • writeDocType

        public void writeDocType​(boolean writeXMLDeclaration,
                                 java.net.URI namespaceURI,
                                 java.lang.String localName,
                                 java.lang.String publicID,
                                 java.lang.String systemID,
                                 com.globalmentor.net.MediaType contentType)
                          throws java.io.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:
        java.io.IOException - if there is an error writing the information.
      • writeElementBegin

        public XMLDepictContext.ElementState writeElementBegin​(java.net.URI namespaceURI,
                                                               java.lang.String localName)
                                                        throws java.io.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:
        java.io.IOException - if there is an error writing the information.
      • writeElementBegin

        public XMLDepictContext.ElementState writeElementBegin​(java.net.URI namespaceURI,
                                                               java.lang.String localName,
                                                               boolean isEmptyElementAllowed)
                                                        throws java.io.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:
        java.io.IOException - if there is an error writing the information.
      • writeElementEnd

        public XMLDepictContext.ElementState writeElementEnd​(java.net.URI namespaceURI,
                                                             java.lang.String localName)
                                                      throws java.io.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:
        java.io.IOException - if there is an error writing the information.
      • writeAttribute

        public void writeAttribute​(java.net.URI namespaceURI,
                                   java.lang.String localName,
                                   java.lang.String value)
                            throws java.io.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:
        java.io.IOException - if there is an error writing the information.