Пример #1
0
  /* Read the main XML elements and call appropriate private functions to handle
   * reading child elements.
   */
  private void readXML(String filename) {
    Document xml = util.fileToXML(filename);

    Node root = xml.getDocumentElement();
    if ("gte".equals(root.getNodeName())) {
      for (Node child = root.getFirstChild(); child != null; child = child.getNextSibling()) {
        if ("gameDescription".equals(child.getNodeName())) {
          // this.gameDescription = "\"" + child.getTextContent() + "\"";
        }
        if ("players".equals(child.getNodeName())) {
          this.playerNames = util.readPlayersXML(child);
        }
        if ("strategicForm".equals(child.getNodeName())) {
          this.readStrategicForm(child);
          this.numRows = Integer.parseInt(this.numPlayerStrategies.get(0));
          this.numCols = Integer.parseInt(this.numPlayerStrategies.get(1));
        }
        if ("display".equals(child.getNodeName())) {
          this.readDisplayXML(child);
        }
      }
    } else {
      System.out.println("XMLToLaTeX error: first XML element not recognized.");
    }
  }
Пример #2
0
  /* Parse the data from a strategy node */
  private void processStrategy(Node node) {
    NodeList nl = node.getChildNodes();
    String value = nl.item(0).getNodeValue();
    String playerName = util.getAttribute(node, "player");

    this.addPlayerName(playerName);

    value = value.replace("}", "");
    value = value.replace("{", "");

    value = value.trim();
    ArrayList<String> strategies = util.extractTokens(value);

    this.playerStrategies.put(playerName, strategies);
  }
Пример #3
0
  /* Process the data from a payoff node */
  private void processPayoff(Node node) {
    NodeList nl = node.getChildNodes();
    String value = nl.item(0).getNodeValue();
    String playerName = util.getAttribute(node, "player");

    // this call is superfluous if <players> present, but keeping to ensure players populated
    this.addPlayerName(playerName);

    this.playerPayoffs.put(playerName, value.trim());
  }
Пример #4
0
  /* read and process the XML data from the strategicForm XML node */
  private void readStrategicForm(Node stratForm) {
    String gameSize = util.getAttribute(stratForm, "size");
    gameSize = gameSize.replace("}", "");
    gameSize = gameSize.replace("{", "").trim();

    String[] strategies = gameSize.split("\\s+");

    for (int i = 0; i < strategies.length; i++) {
      this.numPlayerStrategies.add(strategies[i].trim());
    }

    for (Node child = stratForm.getFirstChild(); child != null; child = child.getNextSibling()) {
      if ("strategy".equals(child.getNodeName())) {
        processStrategy((Element) child);
      } else if ("payoffs".equals(child.getNodeName())) {
        processPayoff((Element) child);
      }
    }
  }
Пример #5
0
 /* create the output file leveraging the utilities class */
 private void createLaTeXFile(String filename) {
   String outFile = this.filename.substring(0, filename.length() - 4) + this.fileSuffix;
   util.createFile(outFile, this.getLaTeXString());
 }