Changing the implementation of StAX to Woodstox. Fixed some XML related bugs as well.

This commit is contained in:
Stian Grenborgen 2006-10-19 13:12:27 +00:00
parent ba9d4dd1ae
commit 6f9897f179
14 changed files with 40 additions and 25 deletions

View File

@ -47,7 +47,7 @@
/>
<javac srcdir="${freecol.src.dir}"
destdir="${freecol.build.dir}"
classpath="${basedir}/jars/higlayout.jar:${basedir}/jars/jsr173_1.0_api.jar:${basedir}/jars/sjsxp.jar"
classpath="${basedir}/jars/higlayout.jar:${basedir}/jars/jsr173_1.0_api.jar:${basedir}/jars/wstx-lgpl-3.0.2.jar"
debug="on"
optimize="on"
deprecation="off"
@ -217,7 +217,7 @@
overview="${freecol.overview.file}"
destdir="${freecol.javadoc.dir}"
packagenames="net.sf.freecol.*"
classpath="${basedir}/jars/higlayout.jar:${basedir}/jars/jsr173_1.0_api.jar:${basedir}/jars/sjsxp.jar"
classpath="${basedir}/jars/higlayout.jar:${basedir}/jars/jsr173_1.0_api.jar:${basedir}/jars/wstx-lgpl-3.0.2.jar"
Author="true"
Windowtitle="FreeCol Code Documentation"
/>

Binary file not shown.

BIN
jars/wstx-lgpl-3.0.2.jar Normal file

Binary file not shown.

View File

@ -1,4 +1,4 @@
Manifest-Version: 1.0
Created-By: FreeCol Team
Main-Class: net.sf.freecol.FreeCol
Class-Path: jars/higlayout.jar jars/jsr173_1.0_api.jar jars/sjsxp.jar
Class-Path: jars/higlayout.jar jars/jsr173_1.0_api.jar jars/wstx-lgpl-3.0.2.jar

View File

@ -198,8 +198,7 @@ public final class ConnectController {
try {
XMLStreamWriter out = c.ask();
out.writeStartElement("login");
// Don't send " in username
out.writeAttribute("username", username.replace("\"", "&quot;"));
out.writeAttribute("username", username);
out.writeAttribute("freeColVersion", FreeCol.getVersion());
out.writeEndElement();
in = c.getReply();

View File

@ -307,7 +307,8 @@ public abstract class FreeColAction extends AbstractAction implements Option {
StringWriter sw = new StringWriter();
XMLOutputFactory xif = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = xif.createXMLStreamWriter(sw);
toXML(xsw);
toXML(xsw);
xsw.close();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document tempDocument = null;

View File

@ -309,8 +309,9 @@ abstract public class FreeColGameObject {
StringWriter sw = new StringWriter();
XMLOutputFactory xif = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = xif.createXMLStreamWriter(sw);
toXML(xsw, player, showAll, toSavedGame);
toXML(xsw, player, showAll, toSavedGame);
xsw.close();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document tempDocument = null;
try {

View File

@ -436,7 +436,8 @@ public class Goods implements Locatable, Ownable {
StringWriter sw = new StringWriter();
XMLOutputFactory xif = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = xif.createXMLStreamWriter(sw);
toXML(xsw, player);
toXML(xsw, player);
xsw.close();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document tempDocument = null;

View File

@ -2081,7 +2081,7 @@ public class Player extends FreeColGameObject {
out.writeStartElement(getXMLElementTagName());
out.writeAttribute("ID", getID());
out.writeAttribute("username", name.replace("\"", "&quot;"));
out.writeAttribute("username", name);
out.writeAttribute("nation", Integer.toString(nation));
out.writeAttribute("color", Integer.toString(color.getRGB()));
out.writeAttribute("admin", Boolean.toString(admin));
@ -2164,8 +2164,6 @@ public class Player extends FreeColGameObject {
setID(in.getAttributeValue(null, "ID"));
name = in.getAttributeValue(null, "username");
if (name != null)
name = name.replace("&quot;", "\"");
nation = Integer.parseInt(in.getAttributeValue(null, "nation"));
color = new Color(Integer.parseInt(in.getAttributeValue(null, "color")));
admin = (new Boolean(in.getAttributeValue(null, "admin"))).booleanValue();

View File

@ -48,6 +48,7 @@ public class Connection {
private final Socket socket;
private final Transformer xmlTransformer;
private final ReceivingThread thread;
private final XMLOutputFactory xof = XMLOutputFactory.newInstance();
private MessageHandler messageHandler;
private XMLStreamWriter xmlOut = null;
@ -245,7 +246,6 @@ public class Connection {
currentQuestionID = thread.getNextNetworkReplyId();
}
try {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
xmlOut = xof.createXMLStreamWriter(out);
} catch (XMLStreamException e) {
throw new IOException(e.toString());
@ -269,8 +269,7 @@ public class Connection {
}
currentQuestionID = thread.getNextNetworkReplyId();
}
try {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
try {
xmlOut = xof.createXMLStreamWriter(out);
} catch (XMLStreamException e) {
throw new IOException(e.toString());
@ -295,6 +294,8 @@ public class Connection {
xmlOut.writeEndElement();
xmlOut.writeCharacters("\n");
xmlOut.flush();
xmlOut.close();
xmlOut = null;
XMLStreamReader in = (XMLStreamReader) nro.getResponse();
in.nextTag();
@ -312,9 +313,12 @@ public class Connection {
in.next();
}
thread.unlock();
in.close();
} else {
xmlOut.writeCharacters("\n");
xmlOut.flush();
xmlOut.close();
xmlOut = null;
}
synchronized (out) {
@ -322,7 +326,12 @@ public class Connection {
out.notifyAll();
}
} catch (XMLStreamException e) {
throw new IOException(e.toString());
IOException ie = new IOException(e.toString());
ie.initCause(e);
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
logger.warning(sw.toString());
throw ie;
}
}
@ -386,19 +395,17 @@ public class Connection {
xmlIn.nextTag();
}
if (smh.accepts(xmlIn.getLocalName())) {
XMLStreamWriter xmlOut = send();
XMLStreamWriter xmlOut = null;
if (question) {
xmlOut = send();
xmlOut.writeStartElement("reply");
xmlOut.writeAttribute("networkReplyId", networkReplyId);
}
smh.handle(this, xmlIn, xmlOut);
if (question) {
xmlOut.writeEndElement();
}
endTransmission(null);
while (xmlIn.hasNext()) {
xmlIn.next();
}
endTransmission(null);
}
thread.unlock();
messagedConsumed = true;
}

View File

@ -222,9 +222,16 @@ final class ReceivingThread extends Thread {
}
if (!foundNetworkReplyObject) {
while (xmlIn.hasNext()) {
xmlIn.next();
}
xmlIn.close();
xmlIn = null;
logger.warning("Could not find networkReplyId=" + networkReplyID);
}
} else {
xmlIn.close();
xmlIn = null;
bis.reset();
connection.handleAndSendReply(bis);
}

View File

@ -156,7 +156,8 @@ abstract public class AbstractOption implements Option {
StringWriter sw = new StringWriter();
XMLOutputFactory xif = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = xif.createXMLStreamWriter(sw);
toXML(xsw);
toXML(xsw);
xsw.close();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document tempDocument = null;

View File

@ -111,7 +111,8 @@ public abstract class AIObject {
StringWriter sw = new StringWriter();
XMLOutputFactory xif = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = xif.createXMLStreamWriter(sw);
toXML(xsw);
toXML(xsw);
xsw.close();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document tempDocument = null;

View File

@ -148,7 +148,6 @@ public final class UserConnectionHandler implements MessageHandler, StreamedMess
if (username == null) {
throw new IllegalArgumentException("The attribute 'username' is missing.");
}
username = username.replace("&quot;", "\"");
final String freeColVersion = in.getAttributeValue(null, "freeColVersion");
if (freeColVersion == null) {