Example usage for org.dom4j Element add

List of usage examples for org.dom4j Element add

Introduction

In this page you can find the example usage for org.dom4j Element add.

Prototype

void add(Namespace namespace);

Source Link

Document

Adds the given Namespace to this element.

Usage

From source file:de.ailis.wlandsuite.game.parts.Items.java

License:Open Source License

/**
 * Returns the monsters as XML./*from   w  ww .ja  va2  s  .c om*/
 *
 * @return The monsters as XML
 */

public Element toXml() {
    Element element;

    // Create the root XML element
    element = XmlUtils.createElement("items");

    // Add all the items
    for (final Item item : this) {
        element.add(item.toXml());
    }

    // Return the XML element
    return element;
}

From source file:de.ailis.wlandsuite.game.parts.LibraryAction.java

License:Open Source License

/**
 * Returns the library data as XML.//from  ww w .j  a  v  a  2 s  .  com
 *
 * @param id
 *            The action id
 * @return The library data as XML
 */

@Override
public Element toXml(final int id) {
    Element element;

    element = XmlUtils.createElement("library");

    element.addAttribute("id", StringUtils.toHex(id));
    if (this.name != null && this.name.length() > 0) {
        element.addAttribute("name", this.name);
    }
    if (this.message != 0) {
        element.addAttribute("message", Integer.toString(this.message));
    }
    if (this.newActionClass != 255) {
        element.addAttribute("newActionClass", StringUtils.toHex(this.newActionClass));
    }
    if (this.newAction != 255) {
        element.addAttribute("newAction", StringUtils.toHex(this.newAction));
    }

    for (final int skill : this.skills) {
        Element subElement;

        subElement = XmlUtils.createElement("skill");
        subElement.addText(Integer.toString(skill));

        element.add(subElement);
    }
    return element;
}

From source file:de.ailis.wlandsuite.game.parts.LootAction.java

License:Open Source License

/**
 * @see de.ailis.wlandsuite.game.parts.Action#toXml(int)
 */// ww  w.java2  s. com

@Override
public Element toXml(final int id) {
    Element element;

    element = XmlUtils.createElement("loot");
    element.addAttribute("id", StringUtils.toHex(id));
    element.addAttribute("newActionClass", StringUtils.toHex(this.newActionClass));
    element.addAttribute("newAction", StringUtils.toHex(this.newAction));

    for (final LootItem item : this.items) {
        element.add(item.toXml());
    }

    return element;
}

From source file:de.ailis.wlandsuite.game.parts.Monsters.java

License:Open Source License

/**
 * Returns the monsters as XML./*from w  ww.  j  av  a  2s.c o m*/
 *
 * @return The monsters as XML
 */

public Element toXml() {
    Element element, subElement;
    int monsterNo;

    // Create the root XML element
    element = XmlUtils.createElement("monsters");

    // Add all the monsters
    monsterNo = 0;
    for (final Monster monster : this) {
        // Create and append string element
        subElement = monster.toXml(monsterNo);
        element.add(subElement);
        monsterNo++;
    }

    // Return the XML element
    return element;
}

From source file:de.ailis.wlandsuite.game.parts.NPCs.java

License:Open Source License

/**
 * Returns the NPCs as XML./*www .  j av  a2s. com*/
 *
 * @return The NPCs as XML
 */

public Element toXml() {
    Element element, subElement;
    int npcNo;

    // Create the root XML element
    element = XmlUtils.createElement("npcs");

    // Add all the npcs
    npcNo = 1;
    for (final Char character : this) {
        // Create and append string element
        subElement = character.toXml(npcNo);
        element.add(subElement);
        npcNo++;
    }

    // Return the XML element
    return element;
}

From source file:de.ailis.wlandsuite.game.parts.Parties.java

License:Open Source License

/**
 * Returns the XML representation of the parties.
 *
 * @return The XML element/*w  w  w  .j  a v  a  2 s .co  m*/
 */

public Element toXml() {
    int id;
    Element element;

    if (size() > 4) {
        throw new GameException("There can be only 4 parties in the save game but here we have " + size());
    }

    element = XmlUtils.createElement("parties");
    element.addAttribute("currentParty", Integer.toString(this.currentParty));
    id = 0;
    for (final Party party : this) {
        element.add(party.toXml(id));
        id++;
    }
    return element;
}

From source file:de.ailis.wlandsuite.game.parts.Party.java

License:Open Source License

/**
 * Returns the XML representation of the party.
 *
 * @param id/*from   w w w  .j  a va  2  s.  co  m*/
 *            The party id
 * @return The XML element
 */

public Element toXml(final int id) {
    Element element;

    if (size() > 7) {
        throw new GameException("Party cannot have more than 7 members but this party has " + size());
    }

    element = XmlUtils.createElement("party");
    element.addAttribute("id", Integer.toString(id));
    element.addAttribute("x", Integer.toString(this.x));
    element.addAttribute("y", Integer.toString(this.y));
    element.addAttribute("map", Integer.toString(this.map));
    element.addAttribute("prevX", Integer.toString(this.prevX));
    element.addAttribute("prevY", Integer.toString(this.prevY));
    element.addAttribute("prevMap", Integer.toString(this.prevMap));
    for (final int member : this) {
        Element subElement;

        subElement = XmlUtils.createElement("member");
        subElement.addText(Integer.toString(member));
        element.add(subElement);
    }
    return element;
}

From source file:de.ailis.wlandsuite.game.parts.PrintAction.java

License:Open Source License

/**
 * @see de.ailis.wlandsuite.game.parts.Action#toXml(int)
 *///w  w w .  j  ava2 s  . c  o  m

@Override
public Element toXml(final int id) {
    Element element, subElement;

    element = XmlUtils.createElement("print");
    element.addAttribute("id", StringUtils.toHex(id));
    for (final int message : this.messages) {
        subElement = XmlUtils.createElement("message");
        subElement.setText(Integer.toString(message));
        element.add(subElement);
    }
    if (this.newActionClass != 255) {
        element.addAttribute("newActionClass", StringUtils.toHex(this.newActionClass));
    }
    if (this.newAction != 255) {
        element.addAttribute("newAction", StringUtils.toHex(this.newAction));
    }

    return element;
}

From source file:de.ailis.wlandsuite.game.parts.Skills.java

License:Open Source License

/**
 * Returns the monsters as XML./*  www . jav  a2  s.c o m*/
 *
 * @return The monsters as XML
 */

public Element toXml() {
    Element element;

    // Create the root XML element
    element = XmlUtils.createElement("skills");

    // Add all the skills
    for (final Skill skill : this) {
        element.add(skill.toXml());
    }

    // Return the XML element
    return element;
}

From source file:de.ailis.wlandsuite.game.parts.StoreAction.java

License:Open Source License

/**
 * Returns the store data as XML.//from  w ww.j  ava2s .  c o m
 *
 * @param id
 *            The action id
 * @return The store data as XML
 */

@Override
public Element toXml(final int id) {
    Element element;

    element = XmlUtils.createElement("store");

    element.addAttribute("id", StringUtils.toHex(id));
    if (this.name != null && this.name.length() > 0) {
        element.addAttribute("name", this.name);
    }
    if (this.message != 0) {
        element.addAttribute("message", Integer.toString(this.message));
    }
    if (this.buyFactor != 0) {
        element.addAttribute("buyFactor", Integer.toString(this.buyFactor));
    }
    if (this.sellFactor != 0) {
        element.addAttribute("sellFactor", Integer.toString(this.sellFactor));
    }
    if (this.itemList != 0) {
        element.addAttribute("itemList", Integer.toString(this.itemList));
    }
    if (this.newActionClass != 255) {
        element.addAttribute("newActionClass", StringUtils.toHex(this.newActionClass));
    }
    if (this.newActionClass != 255) {
        element.addAttribute("newAction", StringUtils.toHex(this.newAction));
    }

    for (final int itemType : this.itemTypes) {
        Element subElement;

        subElement = XmlUtils.createElement("itemType");
        subElement.addText(Integer.toString(itemType));

        element.add(subElement);
    }
    return element;
}