Example usage for org.dom4j Element addComment

List of usage examples for org.dom4j Element addComment

Introduction

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

Prototype

Element addComment(String comment);

Source Link

Document

Adds a new Comment node with the given text to this element.

Usage

From source file:packet_readers.lineage2.listeners.L2NpcSayListener.java

License:Open Source License

@Override
public void closeImpl() throws IOException {
    Document document = DocumentHelper.createDocument();
    Element listElement = document.addElement("list");

    for (L2NpcInfo info : _world.valuesNpc()) {
        if (info.getSays().isEmpty())
            continue;

        Element npcElement = listElement.addElement("npc");
        npcElement.addAttribute("id", String.valueOf(info.getNpcId()));
        npcElement.addComment(NpcNameHolder.getInstance().name(info.getNpcId()));

        for (L2NpcSayInfo npcSay : info.getSays()) {
            Element element = npcElement.addElement("npc_say");
            element.addAttribute("string_id", String.valueOf(npcSay.getId()));
            element.addAttribute("type", String.valueOf(npcSay.getChatType()));

            for (String val : npcSay.getParams()) {
                if (val.isEmpty())
                    continue;

                Element valElement = element.addElement("arg");
                valElement.setText(val);
            }//from w w  w. j a v  a  2 s . c om
        }
    }

    if (listElement.elements().isEmpty())
        return;

    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setIndent("\t");
    XMLWriter writer = new XMLWriter(new FileWriter(getLogFile("./npc_say ", "xml")), format);
    writer.write(document);
    writer.close();
}

From source file:packet_readers.lineage2.listeners.L2NpcStateListener.java

License:Open Source License

@Override
public void closeImpl() throws IOException {
    Document document = DocumentHelper.createDocument();
    Element listElement = document.addElement("list");

    for (L2NpcInfo info : _world.valuesNpc()) {
        if (info.getStates().isEmpty())
            continue;

        Element npcElement = listElement.addElement("npc");
        npcElement.addAttribute("id", String.valueOf(info.getNpcId()));
        npcElement.addComment(NpcNameHolder.getInstance().name(info.getNpcId()));

        for (int i : info.getStates().toArray()) {
            Element element = npcElement.addElement("state");
            element.setText(String.valueOf(i));
        }//from  ww w.  j  a va 2s . c om
    }

    if (listElement.elements().isEmpty())
        return;

    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setIndent("\t");
    XMLWriter writer = new XMLWriter(new FileWriter(getLogFile("./npc_states ", "xml")), format);
    writer.write(document);
    writer.close();
}