com.guiseframework.platform
Class AbstractXMLDepictContext

java.lang.Object
  extended by com.globalmentor.beans.BoundPropertyObject
      extended by com.guiseframework.platform.AbstractDepictContext
          extended by com.guiseframework.platform.AbstractTextDepictContext
              extended by com.guiseframework.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 com.guiseframework.platform.XMLDepictContext
XMLDepictContext.ElementState
 
Field Summary
 
Fields inherited from class com.globalmentor.beans.BoundPropertyObject
NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS
 
Constructor Summary
AbstractXMLDepictContext(GuiseSession session, Destination destination)
          Guise session constructor.
 
Method Summary
 void clearDepictText()
          Clears all data collected for depiction.
protected  java.lang.String encode(java.lang.String string)
          Encodes text information for writing.
protected abstract  java.lang.String getAttributeHashAttributeQualifiedName()
           
protected  java.lang.String getAttributeValue(com.globalmentor.text.xml.QualifiedName elementQualifiedName, com.globalmentor.text.xml.QualifiedName attributeQualifiedName, java.lang.String attributeValue)
          Retrieves the value of a given attribute.
protected abstract  java.lang.String 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.text.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, java.lang.String publicID)
          Writes a doctype along with an optional an 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.ContentType 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.guiseframework.platform.AbstractTextDepictContext
getDepictText, getIndentLevel, indent, indent, isFormatted, setIndentLevel, unindent, write, write, writeIndent, writeLiteral
 
Methods inherited from class com.guiseframework.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 com.guiseframework.platform.TextDepictContext
getDepictText, getIndentLevel, getOutputCharacterEncoding, getOutputContentType, indent, indent, isFormatted, setIndentLevel, setOutputContentType, unindent, write, write, writeIndent, writeLiteral
 
Methods inherited from interface com.guiseframework.platform.DepictContext
getDepictionURI, getDepictionURI, getDepictionURI, getDestination, getPlatform, getSession, getStyles
 
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.text.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:
generateHashAttribute - Whether hash attributes should be generated.

getAttributeHashAttributeQualifiedName

protected abstract java.lang.String getAttributeHashAttributeQualifiedName()
Returns:
The qualified name to use for the attribute hash attribute.

getContentHashAttributeQualifiedName

protected abstract java.lang.String getContentHashAttributeQualifiedName()
Returns:
The qualified name to use for the content hash attribute.

clearDepictText

public void clearDepictText()
Clears all data collected for depiction. This version also clears the stack of element states.

Specified by:
clearDepictText in interface TextDepictContext
Overrides:
clearDepictText in class AbstractTextDepictContext

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.

getAttributeValue

protected java.lang.String getAttributeValue(com.globalmentor.text.xml.QualifiedName elementQualifiedName,
                                             com.globalmentor.text.xml.QualifiedName 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:
elementQualifedName - 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)
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,
                         java.lang.String publicID)
                  throws java.io.IOException
Writes a doctype along with an optional an 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.lang.NullPointerException - if the given public ID is null.
java.lang.IllegalArgumentException - if a system ID could not be determined from the given public ID.
java.io.IOException

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.ContentType contentType)
                  throws java.io.IOException
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 determiend from the public ID; otherwise will default to "text/xml".
Throws:
java.lang.IllegalArgumentException - if a system ID was not provided or one could not be determined from the given public ID.
java.io.IOException

writeElementBegin

public XMLDepictContext.ElementState writeElementBegin(java.net.URI namespaceURI,
                                                       java.lang.String localName)
                                                throws java.io.IOException
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
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
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.util.NoSuchElementException - if the element state stack is empty.
java.lang.IllegalStateException - if the given namespace URI and/or local name does not match that of the currently open element.
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 implemention 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.util.NoSuchElementException - if the element state stack is empty.
java.io.IOException - if there is an error writing the information.

writeCommentOpen

public void writeCommentOpen()
                      throws java.io.IOException
Writes the beginning part of an XML comment.

Specified by:
writeCommentOpen in interface XMLDepictContext
Throws:
java.lang.IllegalStateException - if the comment has already been opened but not closed.
java.io.IOException - if there is an error writing the information.
See Also:
writeCommentClose()

writeCommentClose

public void writeCommentClose()
                       throws java.io.IOException
Writes the ending part of an XML comment.

Specified by:
writeCommentClose in interface XMLDepictContext
Throws:
java.lang.IllegalStateException - if the comment has not been opened or has already been closed.
java.io.IOException - if there is an error writing the information.
See Also:
writeCommentOpen()

writeComment

public void writeComment(java.lang.String comment)
                  throws java.io.IOException
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:
java.io.IOException - if there is an error writing the information.
See Also:
writeCommentOpen(), writeCommentClose()


Copyright © 2005-2010 GlobalMentor, Inc. All Rights Reserved.