Example usage for org.jdom2 Element setText

List of usage examples for org.jdom2 Element setText

Introduction

In this page you can find the example usage for org.jdom2 Element setText.

Prototype

public Element setText(final String text) 

Source Link

Document

Sets the content of the element to be the text given.

Usage

From source file:neon.resources.RZoneTheme.java

License:Open Source License

public Element toElement() {
    Element theme = new Element("zone");
    theme.setAttribute("id", id);
    theme.setAttribute("min", Integer.toString(min));
    theme.setAttribute("max", Integer.toString(max));
    theme.setAttribute("type", type.toString() + ";" + floor + ";" + walls + ";" + doors);

    for (Map.Entry<String, Integer> entry : creatures.entrySet()) {
        Element creature = new Element("creature");
        creature.setText(entry.getKey());
        creature.setAttribute("n", Integer.toString(entry.getValue()));
        theme.addContent(creature);/*  w  w w .j  a v  a  2 s. com*/
    }
    for (Map.Entry<String, Integer> entry : items.entrySet()) {
        Element item = new Element("item");
        item.setText(entry.getKey());
        item.setAttribute("n", Integer.toString(entry.getValue()));
        theme.addContent(item);
    }
    for (Object[] data : features) {
        Element feature = new Element("feature");
        feature.setAttribute("t", data[0].toString());
        feature.setText(data[1].toString());
        feature.setAttribute("s", data[2].toString());
        feature.setAttribute("n", data[3].toString());
        theme.addContent(feature);
    }

    return theme;
}

From source file:neon.server.resource.ConfigurationLoader.java

License:Open Source License

private Element saveServer(CServer server) {
    Element root = new Element("server");

    Element modules = new Element("modules");
    for (String id : server.getModules()) {
        Element module = new Element("module");
        module.setText(id);
        module.setAttribute("uid", Short.toString(entities.getModuleUID(id)));
        modules.addContent(module);/*  w  ww  .ja v a2  s  .  c o m*/
    }
    root.addContent(modules);

    Element log = new Element("log");
    log.setText(server.getLogLevel().toString());
    root.addContent(log);

    return root;
}

From source file:neon.server.resource.ConfigurationLoader.java

License:Open Source License

private Element saveClient(CClient config) {
    Element client = new Element("client");
    client.setAttribute("title", config.title);
    client.setAttribute("subtitle", config.subtitle);

    Element intro = new Element("intro");
    intro.setText(config.intro);
    client.addContent(intro);//from   w  w  w  .jav  a  2s.c om

    Element playable = new Element("playable");
    client.addContent(playable);
    for (String id : config.getPlayableSpecies()) {
        Element species = new Element("species").setAttribute("id", id);
        playable.addContent(species);
    }

    return client;
}

From source file:net.alegen.datpass.library.configure.XMLConfigurator.java

License:Open Source License

@Override
public boolean saveProfile(Profile profile, String profileKey) {
    String profileName = profile.getValue(FieldManager.NAME_FIELD);
    if (this.profileExists(profileName))
        return false;
    if (!FieldManager.getInstance().verityProfileFields(profile))
        return false;
    Element profilesElem = this.root.getChild(XmlConstants.PROFILES);
    if (profilesElem == null) {
        profilesElem = new Element(XmlConstants.PROFILES);
        this.root.addContent(profilesElem);
    }/*from   www  .j av a  2 s.c  om*/
    Element newProfileElem = new Element(XmlConstants.PROFILE);
    newProfileElem.setAttribute(FieldManager.NAME_FIELD, profile.getValue(FieldManager.NAME_FIELD));
    for (Map.Entry<FieldManager.Field, String> field : profile.getValues().entrySet()) {
        if (!field.getKey().toString().equals(FieldManager.NAME_FIELD)) {
            Element fieldElem = new Element(field.getKey().toString());
            CryptoManager.EncryptionOutput output = CryptoManager.getInstance().encrypt(field.getValue(),
                    profileKey);
            String generatedHmac = CryptoManager.getInstance().generateHmac(output, profileKey);
            Element ciphertextElem = new Element(XmlConstants.CIPHERTEXT);
            ciphertextElem.setText(output.getCypherText());
            fieldElem.addContent(ciphertextElem);
            Element encSaltElem = new Element(XmlConstants.ENC_SALT);
            encSaltElem.setText(output.getSalt());
            fieldElem.addContent(encSaltElem);
            Element encIvElem = new Element(XmlConstants.ENC_IV);
            encIvElem.setText(output.getIV());
            fieldElem.addContent(encIvElem);
            Element hmacElem = new Element(XmlConstants.HMAC);
            hmacElem.setText(generatedHmac);
            fieldElem.addContent(hmacElem);
            newProfileElem.addContent(fieldElem);
        }
    }
    profilesElem.addContent(newProfileElem);
    return true;
}

From source file:net.alegen.datpass.library.configure.XMLConfigurator.java

License:Open Source License

public boolean setValue(String name, String value) {
    if (name == null || name.isEmpty() || value == null || value.isEmpty())
        return false;
    Element appValuesElem = this.root.getChild(XmlConstants.APP_VALUES);
    if (appValuesElem == null) {
        appValuesElem = new Element(XmlConstants.APP_VALUES);
        this.root.addContent(appValuesElem);
    }// w w w. ja v a2 s.  com
    boolean elemExists = false;
    for (Element valueElem : appValuesElem.getChildren()) {
        String nameAttrib = valueElem.getAttributeValue(XmlConstants.NAME);
        if (nameAttrib != null && nameAttrib.equals(name)) {
            elemExists = true;
            valueElem.setText(value);
            break;
        }
    }
    if (!elemExists) {
        Element newElem = new Element(XmlConstants.VALUE);
        newElem.setAttribute(XmlConstants.NAME, name);
        newElem.setText(value);
        appValuesElem.addContent(newElem);
    }
    return true;
}

From source file:net.FriendsUnited.Services.FileServer.java

License:Open Source License

private void sendDirectoryListing(FriendPacket pkt, String path) {
    log.info("Received Request for Listing of {}--{}", SharedFolder, path);
    File dir = new File(SharedFolder + path);
    File[] files = dir.listFiles();
    if (null == files) {
        replyWithFailurePacket(pkt, "Directory " + dir.getPath() + " can not be read");
    } else {//ww w.  j  ava  2s.co m
        Element root = new Element("FolderListing");
        for (int i = 0; i < files.length; i++) {
            File f = files[i];
            Element fe;
            if (true == f.isDirectory()) {
                fe = new Element("Directory");
                fe.setText(f.getName());
            } else {
                fe = new Element("File");
                fe.setText(f.getName());
                Element size = new Element("Size");
                size.addContent("" + f.length());
                fe.addContent(size);
            }
            Element lastModified = new Element("lastModified");
            long time = f.lastModified();
            lastModified.addContent("" + time);
            fe.addContent(lastModified);
            root.addContent(fe);
        }
        Document doc = new Document(root);
        XMLOutputter xout = new XMLOutputter(Format.getCompactFormat());
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        try {
            xout.output(doc, bout);
            ByteConverter bc = new ByteConverter();
            bc.add(DIRECTORY_LISTING);
            bout.flush();
            log.debug("Size of Listing XML : " + bout.size());
            bc.add(bout.size()); // length of String
            bc.add(bout.toByteArray()); // String Data
            FriendPacket replyPacket = new FriendPacket(pkt.getTargetServer(), pkt.getTargetService(), // source
                    pkt.getSourceServer(), pkt.getSourceService(), // target
                    bc.toByteArray()); // payload
            log.debug("sending : " + replyPacket);
            server.sendPacketIntoNetwork(this, replyPacket);
            log.debug("Send reply with Listing !");
        } catch (IOException e) {
            replyWithFailurePacket(pkt, Tool.fromExceptionToString(e));
        }
    }
}

From source file:net.instantcom.mm7.Address.java

License:Open Source License

@Override
public Element save(Element parent) {
    Element e = new Element(addressType.toString(), parent.getNamespace());
    if (displayOnly) {
        e.setAttribute("displayOnly", Boolean.toString(displayOnly), parent.getNamespace());
    }/*from  www.ja  va 2 s. co m*/
    if (addressCoding != null) {
        e.setAttribute("addressCoding", addressCoding.toString(), parent.getNamespace());
    }
    if (id != null) {
        e.setAttribute("id", id, parent.getNamespace());
    }
    e.setText(address);
    return e;
}

From source file:net.osgiliath.helpers.cxf.exception.handling.jaxrs.mapper.ExceptionXmlMapper.java

License:Apache License

/**
 * Create the xml description of an exception.
 * //from   w  w w  .j a v a2  s. c o  m
 * @param arg0
 *          the Throwable
 * @param root
 *          the Xml Element (Jdom)
 */
private void populateXML(Throwable arg0, Element root) {
    final Element clazz = new Element("class");
    clazz.setText(arg0.getClass().getSimpleName());
    root.getChildren().add(clazz);
    final Element message = new Element("message");
    message.setText(arg0.getMessage());
    root.getChildren().add(message);
    final Element localizedMessage = new Element("localizedMessage");
    localizedMessage.setText(arg0.getLocalizedMessage());
    root.getChildren().add(localizedMessage);
    if (arg0.getCause() != null) {
        final Element cause = new Element("Cause");
        root.getChildren().add(cause);
        this.populateXML(arg0.getCause(), cause);
    }
}

From source file:net.visualillusionsent.tellplugin.xml.TellSaveHandler.java

License:Open Source License

public void insertData(Tell tell) {
    Element set = new Element("entry");

    /* Add Element Data */
    Element receiverCol = new Element("receiver");
    receiverCol.setText(tell.getReceiver());
    set.addContent(receiverCol);//from   w ww  .ja  v  a  2 s  . c  o  m

    Element senderCol = new Element("sender");
    senderCol.setText(tell.getSender());
    set.addContent(senderCol);

    Element messageCol = new Element("message");
    messageCol.setText(tell.getMessage());
    set.addContent(messageCol);

    Element dateCol = new Element("date");
    dateCol.setText(tell.getDateString());
    set.addContent(dateCol);

    getDocument().getRootElement().addContent(set);
    try {
        write();
    } catch (IOException e) {
        VIBotX.log.error("Error writng to TellPlugin Xml File", e);
    }
}

From source file:nl.colorize.util.xml.XMLHelper.java

License:Apache License

/**
 * Convenience method that creates an element with the specified name and 
 * text content, but with no attributes or namespace.
 *//*from w w w  . j a  va  2 s. co m*/
public static Element createPropertyElement(String name, String text) {
    Element element = new Element(name);
    element.setText(text);
    return element;
}