public class DOMMessage
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected org.w3c.dom.Document |
document
The actual message data.
|
private static java.lang.String |
FREECOL_PROTOCOL_VERSION |
private static java.lang.String |
INVALID_MESSAGE |
protected static java.util.logging.Logger |
logger |
Modifier | Constructor and Description |
---|---|
|
DOMMessage(org.w3c.dom.Document document)
Constructs a new DOMMessage with data from the given XML-document.
|
private |
DOMMessage(org.xml.sax.InputSource inputSource)
Constructs a new DOMMessage with data from the given InputSource.
|
|
DOMMessage(java.io.InputStream inputStream)
Constructs a new DOMMessage with data from the given InputStream.
|
protected |
DOMMessage(java.lang.String tag)
Protected constructor for the benefit of the subclasses.
|
Modifier and Type | Method and Description |
---|---|
static org.w3c.dom.Element |
clientError(java.lang.String message)
Creates an error message in response to bad client data.
|
static org.w3c.dom.Element |
collapseElements(java.util.List<org.w3c.dom.Element> elements)
Collapses a list of elements into a "multiple" element
with the original elements added as child nodes.
|
static void |
createError(FreeColXMLWriter xw,
java.lang.String messageID,
java.lang.String message)
Creates an error message.
|
static org.w3c.dom.Element |
createError(java.lang.String messageID,
java.lang.String message)
Creates an error message.
|
static DOMMessage |
createMessage(Game game,
org.w3c.dom.Element element)
Create a DOMMessage from an element.
|
static org.w3c.dom.Element |
createMessage(java.lang.String tagName,
java.lang.String... attributes)
Creates a new element with specified attributes.
|
static org.w3c.dom.Document |
createNewDocument()
Creates and returns a new XML-document.
|
static org.w3c.dom.Element |
createNewRootElement(java.lang.String tagName)
Creates a new root element.
|
static java.lang.String |
elementToString(org.w3c.dom.Element element)
Convert an element to a string.
|
java.lang.String |
getAttribute(java.lang.String key)
Gets an attribute from the root element.
|
static org.w3c.dom.Element |
getChildElement(org.w3c.dom.Element element,
java.lang.String tagName)
Convenience method to find the first child element with the
specified tagname.
|
org.w3c.dom.Document |
getDocument()
Gets the
Document holding the message data. |
static java.lang.String |
getFreeColProtocolVersion()
Gets the current version of the FreeCol protocol.
|
java.lang.String |
getType()
Gets the type of this DOMMessage.
|
boolean |
hasAttribute(java.lang.String attribute)
Checks if an attribute is set on the root element.
|
void |
insertAsRoot(org.w3c.dom.Element newRoot)
Inserts an element as a new root element to the existing
element of this message.
|
boolean |
isType(java.lang.String type)
Checks if this message is of a given type.
|
void |
setAttribute(java.lang.String key,
int value)
Sets an attribute on the root element.
|
void |
setAttribute(java.lang.String key,
java.lang.String value)
Sets an attribute on the root element.
|
java.lang.String |
toString() |
org.w3c.dom.Element |
toXMLElement()
Dummy serialization stub.
|
protected static final java.util.logging.Logger logger
private static final java.lang.String FREECOL_PROTOCOL_VERSION
private static final java.lang.String INVALID_MESSAGE
protected org.w3c.dom.Document document
protected DOMMessage(java.lang.String tag)
public DOMMessage(java.io.InputStream inputStream) throws org.xml.sax.SAXException, java.io.IOException
inputStream
- The InputStream
to get the XML-data
from.java.io.IOException
- if thrown by the InputStream
.org.xml.sax.SAXException
- if thrown during parsing.private DOMMessage(org.xml.sax.InputSource inputSource) throws org.xml.sax.SAXException, java.io.IOException
inputSource
- The InputSource
to get the XML-data
from.java.io.IOException
- if thrown by the InputSource
.org.xml.sax.SAXException
- if thrown during parsing.public DOMMessage(org.w3c.dom.Document document)
document
- The document representing an XML-message.public static DOMMessage createMessage(Game game, org.w3c.dom.Element element)
game
- The Game
to create the message in.element
- The Element
to create the message from.public org.w3c.dom.Document getDocument()
Document
holding the message data.Document
holding the message data.public java.lang.String getType()
public boolean isType(java.lang.String type)
type
- The type you wish to test against.true
if the type of this message equals the given
type and false
otherwise.public java.lang.String getAttribute(java.lang.String key)
key
- The key of the attribute.public void setAttribute(java.lang.String key, java.lang.String value)
key
- The key of the attribute.value
- The value of the attribute.public void setAttribute(java.lang.String key, int value)
key
- The key of the attribute.value
- The value of the attribute.public boolean hasAttribute(java.lang.String attribute)
attribute
- The attribute in which to verify the existence of.true
if the root element has the given attribute.public void insertAsRoot(org.w3c.dom.Element newRoot)
newRoot
- The new root Element
.public org.w3c.dom.Element toXMLElement()
public static java.lang.String getFreeColProtocolVersion()
public static org.w3c.dom.Document createNewDocument()
public static org.w3c.dom.Element createNewRootElement(java.lang.String tagName)
tagName
- The tag name of the root element beeing created,public static org.w3c.dom.Element createMessage(java.lang.String tagName, java.lang.String... attributes)
tagName
- The tag name of the element beeing created,attributes
- Key,value string pairs.Element
.public static org.w3c.dom.Element collapseElements(java.util.List<org.w3c.dom.Element> elements)
elements
- A list of Element
s to collapse.public static org.w3c.dom.Element createError(java.lang.String messageID, java.lang.String message)
messageID
- Identifies the "i18n"-keyname. Not specified in the
message if null.message
- The error in plain text. Not specified in the message if
null.Element
of the error message.public static void createError(FreeColXMLWriter xw, java.lang.String messageID, java.lang.String message)
xw
- The FreeColXMLWriter
to write to.messageID
- Identifies the "i18n"-keyname. Not specified in the
message if null.message
- The error in plain text. Not specified in the message if
null.public static org.w3c.dom.Element clientError(java.lang.String message)
message
- The error in plain text.Element
of the error message.public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element element, java.lang.String tagName)
element
- The Element
to search for the child
element in.tagName
- The tag name of the child element to be found.public static java.lang.String elementToString(org.w3c.dom.Element element)
element
- The Element
to convert.String
representation of an element.public java.lang.String toString()
toString
in class java.lang.Object