|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.freecol.common.networking.DOMMessage
public class DOMMessage
Class for parsing raw message data into an XML-tree and for creating new XML-trees.
| Field Summary | |
|---|---|
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
|
| Constructor Summary | |
|---|---|
protected |
DOMMessage()
|
|
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. |
|
DOMMessage(java.lang.String msg)
Constructs a new DOMMessage with data from the given String. |
| Method Summary | |
|---|---|
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 org.w3c.dom.Element |
createError(java.lang.String messageID,
java.lang.String message)
Creates an error message. |
static void |
createError(javax.xml.stream.XMLStreamWriter out,
java.lang.String messageID,
java.lang.String message)
Creates an error message. |
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: returns 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 newRoot as the new root element and appends the
old root element. |
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()
Returns the String representation of the message. |
org.w3c.dom.Element |
toXMLElement()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
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
| Constructor Detail |
|---|
protected DOMMessage()
public DOMMessage(java.lang.String msg)
throws org.xml.sax.SAXException,
java.io.IOException
msg - The raw message data.
java.io.IOException - should not be thrown.
org.xml.sax.SAXException - if thrown during parsing.
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.| Method Detail |
|---|
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 collapseElements(java.util.List<org.w3c.dom.Element> elements)
elements - A list of Elements 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(javax.xml.stream.XMLStreamWriter out,
java.lang.String messageID,
java.lang.String message)
out - The output stream for the 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.public static org.w3c.dom.Element clientError(java.lang.String message)
message - The error in plain text.
Element of the error message.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 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 java.lang.String getAttribute(java.lang.String key)
key - The key 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 as the new root element and appends the
old root element.
newRoot - The new root element.
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.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.
public org.w3c.dom.Element toXMLElement()
public java.lang.String toString()
String representation of the message. This is
what actually gets transmitted to the other peer.
toString in class java.lang.ObjectString representation of the message.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||