Example usage for org.jdom2 Element getName

List of usage examples for org.jdom2 Element getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the (local) name of the element (without any namespace prefix).

Usage

From source file:neon.server.entity.EntitySaver.java

License:Open Source License

Entity load(long uid, Element root) throws ResourceException {
    String id = root.getAttributeValue("id");

    if (root.getName().equals("item")) {
        RItem item = resources.getResource("items", id);
        return itemBuilder.build(uid, item);
    } else if (root.getName().equals("creature")) {
        RCreature species = resources.getResource("creatures", id);
        Entity creature = creatureBuilder.build(PLAYER_UID, species);
        Shape shape = creature.getComponent(Shape.class);
        shape.setX(Integer.parseInt(root.getAttributeValue("x")));
        shape.setY(Integer.parseInt(root.getAttributeValue("y")));
        return creature;
    } else if (root.getName().equals("player")) {
        RCreature species = resources.getResource("creatures", id);
        Entity player = creatureBuilder.build(PLAYER_UID, species);
        player.setComponent(new PlayerInfo(0, root.getAttributeValue("name"), "gender"));
        Shape shape = player.getComponent(Shape.class);
        shape.setX(Integer.parseInt(root.getAttributeValue("x")));
        shape.setY(Integer.parseInt(root.getAttributeValue("y")));
        loadInventory(root.getChild("items"), player.getComponent(Inventory.class));
        return player;
    } else {// ww w .ja  v  a  2 s.c o  m
        throw new IllegalArgumentException("Entity <" + uid + "> does not exist");
    }
}

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

License:Open Source License

@Override
public Resource load(String id) throws IOException {
    Element root = files.loadFile(translator, namespace, id + ".xml").getRootElement();
    switch (root.getName()) {
    case "client":
        return loadClient(root);
    case "game":
        return loadGame(root);
    case "server":
        return loadServer(root);
    default://from   www. j  ava  2s  .  c om
        throw new IllegalArgumentException("Argument is not a configuration resource");
    }
}

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

License:Open Source License

public CServer loadServer(Element root) {
    // LinkedHashSet to preserve module load order and to prevent doubles
    LinkedHashSet<String> modules = new LinkedHashSet<String>();
    for (Element module : root.getChild("modules").getChildren()) {
        modules.add(module.getText());/* ww  w .  jav  a  2  s .  c om*/
    }

    // set the correct module uid's in the entity manager
    if (root.getName().equals("server")) {
        // in case this was a saved configuration file
        for (Element module : root.getChild("modules").getChildren()) {
            entities.setModuleUID(module.getText(), Short.parseShort(module.getAttributeValue("uid")));
        }
    } else {
        // in case configuration was loaded from neon.ini
        short index = 1;
        for (String module : modules) {
            entities.setModuleUID(module, index++);
        }
    }

    String level = root.getChildText("log").toUpperCase();
    return new CServer(modules, level);
}

From source file:neon.ui.graphics.svg.SVGLoader.java

License:Open Source License

public static JVShape loadShape(Element shape) {
    Color color = ColorFactory.getColor(shape.getAttributeValue("fill"));
    if (shape.getAttribute("opacity") != null) {
        int opacity = (int) (Float.parseFloat(shape.getAttributeValue("opacity")) * 255);
        color = new Color(color.getRed(), color.getGreen(), color.getBlue(), opacity);
    }//from  ww  w.j  av a  2  s . c  o  m
    //      DitherPaint paint = new DitherPaint(color, Float.parseFloat(shape.getAttributeValue("opacity")));

    if (shape.getName().equals("circle")) {
        int radius = Integer.parseInt(shape.getAttributeValue("r"));
        return new JVEllipse(radius, color);
    } else {
        return new JVRectangle(null, null);
    }
}

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

License:Open Source License

private Element getProfileRoot(String profileName) {
    Element profilesElem = this.root.getChild(XmlConstants.PROFILES);
    for (Element elem : profilesElem.getChildren())
        if (elem.getName().equals(XmlConstants.PROFILE)) {
            String xmlname = elem.getAttributeValue(FieldManager.NAME_FIELD);
            if (xmlname != null && xmlname.equals(profileName))
                return elem;
        }//from  w ww  . jav a  2 s  .  c  o m
    return null;
}

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

License:Open Source License

@Override
public Profile loadProfile(String profileName, String password) {
    Element xmlprofile = this.getProfileRoot(profileName);
    if (xmlprofile != null) {
        Profile profile = new Profile(profileName);
        for (Element xmlfield : xmlprofile.getChildren())
            if (this.isValidField(xmlfield)) {
                EncryptionOutput encOutput = new CryptoManager.EncryptionOutput(xmlfield);
                String xmlhmac = xmlfield.getChild(XmlConstants.HMAC).getTextNormalize();

                String genhmac = CryptoManager.getInstance().generateHmac(encOutput, password);
                if (xmlhmac != genhmac)
                    return null;

                String plaintext = CryptoManager.getInstance().decrypt(encOutput, password);
                profile.setValue(xmlfield.getName(), plaintext);
            }//from  ww  w.  j  a  v  a 2 s  .c  o  m
        return profile;
    }
    return null;
}

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

License:Open Source License

@Override
public List<String> listProfiles() {
    List<String> profiles = new ArrayList<String>();
    Element profilesElem = this.root.getChild(XmlConstants.PROFILES);
    if (profilesElem != null)
        for (Element elem : profilesElem.getChildren())
            if (elem.getName() == XmlConstants.PROFILE) {
                String name = elem.getAttributeValue(FieldManager.NAME_FIELD);
                if (name != null)
                    profiles.add(name);//from   w w  w . j ava2s .c  o m
            }
    return profiles;
}

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

License:Open Source License

private void parseResponse(FriendPacket response, PrintWriter out) {
    log.debug("{}", response);
    ByteConverter responseBc = new ByteConverter(response.getPayload());
    byte type = responseBc.getByte();
    log.debug("Response Type : {}", type);
    switch (type) {
    case FileServer.FAILURE:
        String errorMsg = responseBc.getString();
        if (true == "OK".equals(errorMsg)) {
            out.println("OK");
        } else {//from w  w w. j av  a 2s  .c  o m
            out.println("ERROR in Response Packet:" + errorMsg);
        }
        break;

    case FileServer.DIRECTORY_LISTING:
        out.println("Listing  of " + RemoteServer + " : " + RemotePath);
        String xmlData = responseBc.getString();
        log.info("Response String : {}", xmlData);
        final SAXBuilder builder = new SAXBuilder();
        Document doc;
        try {
            doc = builder.build(new StringReader(xmlData));
            Element root = null;
            root = doc.getRootElement();
            List<Element> le = root.getChildren();
            for (int i = 0; i < le.size(); i++) {
                Element curentElement = le.get(i);
                String date = curentElement.getChildText("lastModified");
                long ms = Long.parseLong(date);
                Date d = new Date(ms);
                out.printf("%29s", d);
                out.print("|");
                String size = curentElement.getChildText("Size");
                if (null == size) {
                    size = "";
                }
                out.printf("%12s", size);
                out.print("|");
                if (true == "File".equals(curentElement.getName())) {
                    out.print("F");
                } else if (true == "Directory".equals(curentElement.getName())) {
                    out.print("D");
                } else {
                    out.print("X");
                }
                out.print("|");
                out.println(curentElement.getText()); // File Name
            }
        } catch (JDOMException e) {
            log.error(Tool.fromExceptionToString(e));
        } catch (IOException e) {
            log.error(Tool.fromExceptionToString(e));
        }
        break;

    default:
        out.println("ERROR: Receive Response of invalid Type ! "
                + Tool.fromByteBufferToHexString(response.getPayload()));
        break;
    }
}

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

License:Open Source License

@Override
public void load(Element e) {
    {/*from   w ww . j a  v  a  2 s  .  co  m*/
        String value = e.getAttributeValue("displayOnly", e.getNamespace());
        String valueNoNS = e.getAttributeValue("displayOnly");
        if (value != null) {
            displayOnly = Boolean.parseBoolean(value);
        } else if (valueNoNS != null) {
            displayOnly = Boolean.parseBoolean(valueNoNS);
        }
    }
    {
        String value = e.getAttributeValue("addressCoding", e.getNamespace());
        if (value != null) {
            addressCoding = AddressCoding.map.get(value);
        }
    }
    addressType = AddressType.map.get(e.getName());
    id = e.getAttributeValue("id");
    address = e.getText();
}

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

License:Open Source License

@Override
public void load(Element element) {

    Element body = element.getChild("Body", MM7Message.ENVELOPE);
    Element e = (Element) body.getChildren().get(0);

    this.faultCode = e.getChildTextTrim("faultcode");
    this.faultMessage = e.getChildTextTrim("faultstring");
    try {//from ww  w .j av  a  2 s .co m
        Element detail;
        if (element.getNamespace("") != null) {
            detail = (Element) e.getChild("detail", element.getNamespace("")).getChildren().get(0);
        } else {
            detail = (Element) e.getChild("detail").getChildren().get(0);
        }
        String message = detail.getName();
        // Instantiate correct status type

        Class<?> clazz = Class.forName("net.instantcom.mm7." + message);
        this.response = (MM7Response) clazz.newInstance();
        this.response.load(element);
    } catch (Throwable t) {
        // Ignored
        XMLOutputter outp = new XMLOutputter();
        String s = outp.outputString(element);
        System.err.println("Failed to instantiate a correct response type" + s);
        t.printStackTrace();
    }
}