List of usage examples for com.google.gwt.xml.client Node normalize
void normalize();
From source file:javawars.client.ui.MatchViewerFast.java
License:Open Source License
public void show(final String matchReport) { this.matchReport = matchReport; // reinitializing the variables; the method 'show' is reuesable. currentTime = 0;/*from w w w .j a va 2 s .c o m*/ if (showActionProgress.isChecked() == true) showAction = true; else showAction = false; // Creating initial documents, parsers... Document d = XMLParser.parse(matchReport); Node match = d.getFirstChild(); match.normalize(); // Getting the board's node... Node boardNode = getNode(match, "board"); // ...its width and elevation... int boardWidth = Integer.parseInt(boardNode.getAttributes().getNamedItem("width").getNodeValue()); int boardHeight = Integer.parseInt(boardNode.getAttributes().getNamedItem("height").getNodeValue()); // ...and creating a fields table. fields = new Field[boardWidth][boardHeight]; // populating fields table with the exact values from the match_report Node fieldNode = getNode(boardNode, "field"); while (fieldNode != null) { try { NamedNodeMap fieldAttributes = fieldNode.getAttributes(); int x = Integer.parseInt(fieldAttributes.getNamedItem("x").getNodeValue()); int y = Integer.parseInt(fieldAttributes.getNamedItem("y").getNodeValue()); int elevation = Integer.parseInt(fieldAttributes.getNamedItem("elevation").getNodeValue()); int gem = Integer.parseInt(fieldAttributes.getNamedItem("gem").getNodeValue()); int robot = Integer.parseInt(fieldAttributes.getNamedItem("robot").getNodeValue()); fields[x][y] = new Field(elevation, gem, robot); do { fieldNode = fieldNode.getNextSibling(); } while (fieldNode.getNodeName().equals("field") == false && fieldNode != null); } catch (Exception e) { break; } } Node robotsNode = getNode(match, "robots"); int robotsCount = Integer.parseInt(robotsNode.getAttributes().getNamedItem("count").getNodeValue()); robots = new Robot[robotsCount]; Node robotNode = getNode(robotsNode, "robot"); while (robotNode != null) { try { NamedNodeMap robotAttributes = robotNode.getAttributes(); int id = Integer.parseInt(robotAttributes.getNamedItem("id").getNodeValue()); String author = robotAttributes.getNamedItem("author").getNodeValue().toUpperCase(); String name = robotAttributes.getNamedItem("name").getNodeValue().toUpperCase(); robots[id - 1] = new Robot(id, name, author); do { robotNode = robotNode.getNextSibling(); } while (robotNode.getNodeName().equals("robot") == false && robotNode != null); } catch (Exception e) { break; } } table.clear(); for (int a = 0; a < boardWidth; a++) { for (int b = 0; b < boardHeight; b++) { table.setHTML(b, a, renderCell(fields[a][b], a, b)); } } table.setCellPadding(0); table.setCellSpacing(0); table.setStyleName("MatchViewerTable"); tableWidth = table.getOffsetWidth(); robotsDescription.setHTML(renderRobotsDescription(robots, tableWidth)); if (showAction == true) { currentTimeHTML.setHTML(generateCurrentTimeHTML()); } else { currentTimeHTML.setHTML("<div style='font-size: 10px; width: " + tableWidth + "px; background-color: #aaa; color: #fff; text-align: center; '> </div>"); } currentNode = getNode(match, "timestamp"); }