Package io.guise.framework.platform
Class AbstractXMLDepictContext
java.lang.Object
com.globalmentor.beans.BoundPropertyObject
io.guise.framework.platform.AbstractDepictContext
io.guise.framework.platform.AbstractTextDepictContext
io.guise.framework.platform.AbstractXMLDepictContext
- 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
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.guise.framework.platform.XMLDepictContext
XMLDepictContext.ElementState
-
Field Summary
Fields inherited from class com.globalmentor.beans.BoundPropertyObject
NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractXMLDepictContext
(GuiseSession session, Destination destination) Guise session constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected <A extends Appendable>
AappendAttribute
(A appendable, com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName, String attributeValue) Appends an attribute and its value to the given appendable.protected <A extends Appendable>
AappendAttributeName
(A appendable, com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName) Appends an attribute name to the given appendable.protected <A extends Appendable>
AappendAttributeValue
(A appendable, String attributeValue) Appends an attribute value to the given appendable.void
Clears all data collected for depiction.protected String
Encodes text information for writing.protected abstract com.globalmentor.xml.spec.NsQualifiedName
protected String
getAttributeValue
(com.globalmentor.xml.spec.NsQualifiedName elementQualifiedName, com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName, String attributeValue) Retrieves the value of a given attribute.protected abstract com.globalmentor.xml.spec.NsQualifiedName
The string builder that holds the current content being collected, though not necessarily all the content collected.protected MessageDigest
getQualifiedName
(URI namespaceURI, String localName) Retrieves the qualified name of the given namespace and local name.protected com.globalmentor.xml.XMLNamespacePrefixManager
protected boolean
protected void
setHashAttributesGenerated
(boolean generateHashAttributes) Sets whether attributes should be generated representing the hash of XML attributes and content.void
writeAttribute
(URI namespaceURI, String localName, String value) Writes an attribute of an XML element.void
writeComment
(String comment) Writes an XML comment.void
Writes the ending part of an XML comment.void
Writes the beginning part of an XML comment.void
writeDocType
(boolean writeXMLDeclaration, URI namespaceURI, 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, URI namespaceURI, 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, URI namespaceURI, String localName, 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, URI namespaceURI, String localName, String publicID, 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.writeElementBegin
(URI namespaceURI, String localName) Begins an XML element that will not be an empty element, even if it has no content.writeElementBegin
(URI namespaceURI, String localName, boolean isEmptyElementAllowed) Begins an XML element, specifying whether an empty element is allowed.writeElementEnd
(URI namespaceURI, String localName) Ends an XML element.Methods inherited from class io.guise.framework.platform.AbstractTextDepictContext
getDepictText, getIndentLevel, indent, indent, isFormatted, setIndentLevel, unindent, write, write, writeIndent, writeLiteral
Methods inherited from class io.guise.framework.platform.AbstractDepictContext
getDepictionURI, getDepictionURI, getDestination, getPlatform, getSession, getStyles
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 io.guise.framework.platform.DepictContext
getDepictionURI, getDepictionURI, getDepictionURI, getDestination, getPlatform, getSession, getStyles
Methods inherited from interface com.globalmentor.beans.PropertyBindable
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
Methods inherited from interface io.guise.framework.platform.TextDepictContext
getDepictText, getIndentLevel, getOutputCharset, getOutputContentType, indent, indent, isFormatted, setIndentLevel, setOutputContentType, unindent, write, write, writeIndent, writeLiteral
-
Constructor Details
-
AbstractXMLDepictContext
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
- 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 interfaceTextDepictContext
- Overrides:
clearDepictText
in classAbstractTextDepictContext
-
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 interfaceTextDepictContext
- Overrides:
getDepictStringBuilder
in classAbstractTextDepictContext
- Returns:
- The string builder that holds the current content being collected for depiction.
-
encode
Encodes text information for writing. This version encodes XML characters.- Overrides:
encode
in classAbstractTextDepictContext
- 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
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 thenull
namespace, but cannot work for elements in thenull
namespace because this would be ambiguous with elements in the the XHTML namespace.- Specified by:
getQualifiedName
in interfaceXMLDepictContext
- Parameters:
namespaceURI
- The URI of the XML namespace, ornull
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 interfaceXMLDepictContext
- Parameters:
writeXMLDeclaration
- Whether an XML declaration should be included before the doctype.namespaceURI
- The URI of the XML namespace of document element, ornull
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 interfaceXMLDepictContext
- Parameters:
writeXMLDeclaration
- Whether an XML declaration should be included before the doctype.namespaceURI
- The URI of the XML namespace of document element, ornull
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 interfaceXMLDepictContext
- Parameters:
writeXMLDeclaration
- Whether an XML declaration should be included before the doctype.namespaceURI
- The URI of the XML namespace of document element, ornull
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 interfaceXMLDepictContext
- Parameters:
writeXMLDeclaration
- Whether an XML declaration should be included before the doctype.namespaceURI
- The URI of the XML namespace of document element, ornull
if there is no namespace.localName
- The local name of the document element with no prefix.publicID
- The XML declaration public ID, ornull
if none is used.systemID
- The XML declaration system ID, ornull
if one can be determined from the given public ID.contentType
- The specific XML content type, ornull
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 interfaceXMLDepictContext
- Parameters:
namespaceURI
- The URI of the XML namespace of the element, ornull
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 interfaceXMLDepictContext
- Parameters:
namespaceURI
- The URI of the XML namespace of the element, ornull
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 interfaceXMLDepictContext
- Parameters:
namespaceURI
- The URI of the XML namespace of the element, ornull
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
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 interfaceXMLDepictContext
- Parameters:
namespaceURI
- The URI of the XML namespace of the attribute, ornull
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
Description copied from interface:XMLDepictContext
Writes the beginning part of an XML comment.- Specified by:
writeCommentOpen
in interfaceXMLDepictContext
- Throws:
IOException
- if there is an error writing the information.- See Also:
-
writeCommentClose
Description copied from interface:XMLDepictContext
Writes the ending part of an XML comment.- Specified by:
writeCommentClose
in interfaceXMLDepictContext
- Throws:
IOException
- if there is an error writing the information.- See Also:
-
writeComment
Description copied from interface:XMLDepictContext
Writes an XML comment. This method ensures that any open beginning tag has been closed.- Specified by:
writeComment
in interfaceXMLDepictContext
- Parameters:
comment
- The comment to write.- Throws:
IOException
- if there is an error writing the information.- See Also:
-