Exemplo n.º 1
0
  public Document makeDocument() {
    Element fightNode = doc.createElement(fightTag);
    fightNode.setAttribute(nameTag, fight.getName());
    fightNode.setAttribute(guidTag, fight.getGuid());
    addFightInfo(fightNode);

    Element victimNode = doc.createElement(victimTag);
    FightParticipant victim = fight.getVictim();
    XMLFightParticipant victimXP = new XMLFightParticipant(doc, victim, fight);
    Node victimParticipantNode = victimXP.makeNode();
    fightNode.appendChild(victimNode);
    victimNode.appendChild(victimParticipantNode);

    List<FightParticipant> parts = fight.getParticipants();
    for (FightParticipant p : parts) {
      XMLFightParticipant xp = new XMLFightParticipant(doc, p, fight);
      Node n = xp.makeNode();
      fightNode.appendChild(n);
    }
    doc.appendChild(fightNode);
    return doc;
  }
Exemplo n.º 2
0
  public void parseXML(Node rootNode) {
    try {
      NumberFormat nf = WLPNumberFormat.getInstance();
      NamedNodeMap attrs = rootNode.getAttributes();
      if (attrs != null) {
        Node nameNode = attrs.getNamedItem(nameTag);
        if (nameNode != null) {
          name = nameNode.getTextContent().trim();
        }
        Node guidNode = attrs.getNamedItem(guidTag);
        if (guidNode != null) {
          guid = guidNode.getTextContent().trim();
        }
      }

      Node mergedNode = XmlHelper.getChildNode(rootNode, mergedTag);
      if (mergedNode != null) {
        merged = Boolean.parseBoolean(mergedNode.getTextContent().trim());
      }

      Node durationNode = XmlHelper.getChildNode(rootNode, durationTag);
      if (durationNode != null) {
        duration = nf.parse(durationNode.getTextContent().trim()).doubleValue();
      }

      Node activeDurationNode = XmlHelper.getChildNode(rootNode, activeDurationTag);
      if (activeDurationNode != null) {
        activeDuration = nf.parse(activeDurationNode.getTextContent().trim()).doubleValue();
      }

      Node numMobsNode = XmlHelper.getChildNode(rootNode, numMobsTag);
      if (numMobsNode != null) {
        numMobs = Integer.parseInt(numMobsNode.getTextContent().trim());
      }

      Node totalDamageNode = XmlHelper.getChildNode(rootNode, totalDamageTag);
      if (totalDamageNode != null) {
        totalDamage = Long.parseLong(totalDamageNode.getTextContent().trim());
      }

      Node victimNode = XmlHelper.getChildNode(rootNode, victimTag);
      if (victimNode != null) {
        Node victimFightparticipantNode =
            XmlHelper.getChildNode(victimNode, XMLFightParticipant.fightParticipantTag);
        if (victimFightparticipantNode != null) {
          xmlVictim = new XMLFightParticipant();
          xmlVictim.parseXML(victimFightparticipantNode);
        }
      }
      List<Node> fightParticipantNodes =
          XmlHelper.getChildNodes(rootNode, XMLFightParticipant.fightParticipantTag);
      fightParticipants = new ArrayList<XMLFightParticipant>();
      for (Node partNode : fightParticipantNodes) {
        if (partNode != null) {
          XMLFightParticipant xmlPart = new XMLFightParticipant();
          xmlPart.parseXML(partNode);
          fightParticipants.add(xmlPart);
        }
      }
    } catch (ParseException ex) {
      throw new NumberFormatException();
    }
  }