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 oftext/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
-
-
Constructor Summary
Constructors Constructor Description AbstractXMLDepictContext(GuiseSession session, Destination destination)
Guise session constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected <A extends java.lang.Appendable>
AappendAttribute(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>
AappendAttributeName(A appendable, com.globalmentor.xml.spec.NsQualifiedName attributeQualifiedName)
Appends an attribute name to the given appendable.protected <A extends java.lang.Appendable>
AappendAttributeValue(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 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 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.
-
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
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 interfaceTextDepictContext
- Overrides:
getDepictStringBuilder
in classAbstractTextDepictContext
- 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 classAbstractTextDepictContext
- 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 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, 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 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:
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 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:
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 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:
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 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:
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 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:
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 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:
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 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:
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 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:
java.io.IOException
- if there is an error writing the information.
-
writeCommentOpen
public void writeCommentOpen() throws java.io.IOException
Description copied from interface:XMLDepictContext
Writes the beginning part of an XML comment.- Specified by:
writeCommentOpen
in interfaceXMLDepictContext
- Throws:
java.io.IOException
- if there is an error writing the information.- See Also:
XMLDepictContext.writeCommentClose()
-
writeCommentClose
public void writeCommentClose() throws java.io.IOException
Description copied from interface:XMLDepictContext
Writes the ending part of an XML comment.- Specified by:
writeCommentClose
in interfaceXMLDepictContext
- Throws:
java.io.IOException
- if there is an error writing the information.- See Also:
XMLDepictContext.writeCommentOpen()
-
writeComment
public void writeComment(java.lang.String comment) throws java.io.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 interfaceXMLDepictContext
- Parameters:
comment
- The comment to write.- Throws:
java.io.IOException
- if there is an error writing the information.- See Also:
XMLDepictContext.writeCommentOpen()
,XMLDepictContext.writeCommentClose()
-
-