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:fourmiz.engine.Engine.java

License:Open Source License

/**
 * Parse entity part of xml//from   w w w.j  av  a  2s .c  om
 * @param elems
 * @throws DataConversionException
 */
private void loadEntity(Collection<Element> elems) throws DataConversionException {
    for (Element elem : elems) {
        Entity entity = null;
        switch (elem.getName()) {
        case "Anthill":
            entity = EntityFactory.createEntity(EntityName.Anthill, this);
            break;
        case "Egg":
            entity = EntityFactory.createEntity(EntityName.Egg, this);
            break;
        case "Larva":
            entity = EntityFactory.createEntity(EntityName.Larva, this);
            break;
        case "Nymph":
            entity = EntityFactory.createEntity(EntityName.Nymph, this);
            break;
        case "FourmizWorker":
            entity = EntityFactory.createEntity(EntityName.FourmizWorker, this);
            break;
        case "FourmizSoldier":
            entity = EntityFactory.createEntity(EntityName.FourmizSoldier, this);
            break;
        case "FourmizSex":
            entity = EntityFactory.createEntity(EntityName.FourmizSex, this);
            break;
        case "Queen":
            entity = EntityFactory.createEntity(EntityName.Queen, this);
            break;
        case "Prey":
            entity = EntityFactory.createEntity(EntityName.Prey, this);
            break;
        case "PopPrey":
            entity = EntityFactory.createEntity(EntityName.PopPrey, this);
            break;
        default:
            log.warn("loadLevel: unknown type entity -> " + elem.getName());
            continue;
        }

        Vector2f position = new Vector2f();
        position.x = elem.getAttribute("x").getIntValue() * SIZE_CASE;
        position.y = elem.getAttribute("y").getIntValue() * SIZE_CASE;
        entity.setPosition(position);

        entity.setDirection(elem.getAttribute("dir").getIntValue());

        addEntity(entity);
    }
}

From source file:fr.d4delta.launcher.Launcher.java

License:Open Source License

private void loadProperties(Element pom, Namespace namespace) {
    List<Element> properties;
    try {/*from   ww w.j a  va 2  s . co  m*/
        properties = pom.getChild("properties").getChildren();

        for (Element e : properties) {
            String[] res = callback.addingPropertyNotification(e.getName(),
                    Utils.substituteMaven(e.getValue()));
            if (res != null && res.length == 2) {
                System.setProperty(res[0], res[1]);
            }
        }
    } catch (NullPointerException ex) {
    }
}

From source file:helpers.XMLParser.java

public static ParsedSingleXML parseSingleDoc(String xml) {
    ParsedSingleXML doc = null;//from   ww  w .  j av  a 2s .co  m
    try {

        SAXBuilder saxBuilder = new SAXBuilder();
        Document document = saxBuilder.build(new StringReader(xml));

        Element root = document.getRootElement();
        List<Attribute> rootAttributes = root.getAttributes();
        doc = new ParsedSingleXML(root.getName());
        for (Attribute attr : rootAttributes) {
            doc.addAttr(attr.getName(), attr.getValue());
        }

        XMLRow row;

        List<Element> rootChildren = root.getChildren();
        List<Element> tempChildren;
        List<Attribute> tempAttributes;

        for (Element child : rootChildren) {

            tempChildren = child.getChildren();
            row = new XMLRow(child.getName());
            tempAttributes = child.getAttributes();
            for (Attribute attr : tempAttributes) {
                row.addRootAttr(attr.getName(), attr.getValue());
            }

            for (Element tChild : tempChildren) {
                row.addRowElement(tChild.getName(), tChild.getValue());
            }

            doc.addRow(row);
        }

    } catch (JDOMException ex) {
        Logger.getLogger(XMLParser.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(XMLParser.class.getName()).log(Level.SEVERE, null, ex);
    }

    return doc;

}

From source file:instanceXMLParser.Instance.java

public void buildINstanceJDom(String path) {
    //creating JDOM SAX parser
    SAXBuilder builder = new SAXBuilder();

    //reading XML document
    Document xml = null;/* w ww  .ja v  a  2s .co m*/
    try {
        xml = builder.build(new File(path));
    } catch (JDOMException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    //getting root element from XML document
    Element root = xml.getRootElement();
    List<Element> list = root.getChildren();
    for (Element element : list) {
        List<Element> list1;
        if (element.getName().equals("board")) {
            list1 = element.getChildren();
            for (Element element2 : list1) {
                if (element2.getName().equals("size_n")) {//size of the space
                    size_n = Integer.parseInt(element2.getText());
                } else if (element2.getName().equals("size_m")) {//size of the space
                    size_m = Integer.parseInt(element2.getText());
                    //inizializzo matrice solo dop aver letto le due dimensioni
                    //NOTA CHE SIZE_M E SIZE_N devono essere i primi elementi e in quell ordine!
                    boardState = new CellLogicalState[size_n][size_m];
                    for (int j = 0; j < size_n; j++) {
                        for (int k = 0; k < size_m; k++) {
                            boardState[j][k] = new CellLogicalState();
                        }
                    }

                } else if (element2.getName().equals("tile_state")) {//tile states
                    int x, y, value;
                    CellLogicalState state = new CellLogicalState();
                    String stateString;
                    x = Integer.parseInt(element2.getAttribute("x").getValue());
                    y = Integer.parseInt(element2.getAttribute("y").getValue());

                    stateString = element2.getText();

                    if (stateString.equals("obstacle")) {
                        state.setLocState(LocationState.Obstacle);
                    } else if (stateString.equals("dirty")) {
                        state.setLocState(LocationState.Dirty);
                        value = 1;
                        if (element2.getAttribute("value").getValue() != null) {
                            value = Integer.parseInt(element2.getAttribute("value").getValue());
                        }
                        state.setDirtyAmount(value);

                    }

                    boardState[x][y] = state;

                }
            }
        } else if (element.getName().equals("agent")) {//agent
            List<Element> list3 = element.getChildren();
            for (Element element3 : list3) {
                if (element3.getName().equals("x")) {
                    agentPos.setX(Integer.parseInt(element3.getValue()));
                } else if (element3.getName().equals("y")) {
                    agentPos.setY(Integer.parseInt(element3.getValue()));
                } else if (element3.getName().equals("energy")) {
                    energy = Double.parseDouble(element3.getValue());
                }
            }
        } else if (element.getName().equals("base")) {//agent
            List<Element> list3 = element.getChildren();
            for (Element element3 : list3) {
                if (element3.getName().equals("x")) {
                    basePos.setX(Integer.parseInt(element3.getValue()));
                } else if (element3.getName().equals("y")) {
                    basePos.setY(Integer.parseInt(element3.getValue()));
                }
            }
        } else if (element.getName().equals("action_costs")) {//agent
            List<Element> list3 = element.getChildren();
            for (Element element3 : list3) {
                if (element3.getName().equals("up") || element3.getName().equals("left")
                        || element3.getName().equals("down") || element3.getName().equals("right")
                        || element3.getName().equals("suck")) {

                    actionCosts.put(element3.getName(), Double.parseDouble(element3.getValue()));

                }
            }
        }

    }
}

From source file:io.macgyver.plugin.elb.a10.A10ClientImpl.java

License:Apache License

void throwExceptionIfNecessary(Element element) {
    if (element.getName().equals("response")) {
        String status = element.getAttributeValue("status");

        if (status.equalsIgnoreCase("ok")) {
            // ok
        } else if (status.equalsIgnoreCase("fail")) {
            String code = "";
            String msg = "";

            Element error = element.getChild("error");
            if (error != null) {
                code = error.getAttributeValue("code");
                msg = error.getAttributeValue("msg");
            }//  ww w .j a v  a 2  s  .  c  om
            if (code != null && INVALID_SESSION_ID_CODE.equals(code)) {
                tokenCache.invalidateAll();
            }
            throw new A10RemoteException(code, msg);
        } else {
            logger.warn("unexpected status: {}", status);
        }

    } else {
        logger.warn("unexpected response element: {}", element.getName());
    }

}

From source file:io.sitespeed.jenkins.xml.impl.XMLToPageJDOM.java

License:Open Source License

private Map<String, Integer> getRules(Document doc) {
    Map<String, Integer> rulesMap = new HashMap<String, Integer>();
    // add all the rules
    Element rules = doc.getRootElement().getChild("g");
    for (Element rule : rules.getChildren()) {
        rulesMap.put(rule.getName(), new Integer(rule.getChild("score").getValue()));
    }/*w  w  w  . j a  va  2  s.  c  o m*/
    return rulesMap;
}

From source file:io.sitespeed.jenkins.xml.impl.XMLToPageJDOM.java

License:Open Source License

private Map<String, String> getAssetsSize(Document doc) {
    Map<String, String> assetsAndSize = new HashMap<String, String>();

    Element assets = doc.getRootElement().getChild("stats");
    for (Element asset : assets.getChildren()) {

        // The sizes in YSlow xml is sometimes wrong, need to calculate?!?!
        assetsAndSize.put(asset.getName(), asset.getChild("w").getValue());
    }/*w  ww . j a  v a2  s  . c  o  m*/
    return assetsAndSize;
}

From source file:io.sitespeed.jenkins.xml.impl.XMLToPageJDOM.java

License:Open Source License

private Map<String, Integer> getNumberOfAssets(Document doc) {
    Map<String, Integer> assetsAndNumber = new HashMap<String, Integer>();

    Element assets = doc.getRootElement().getChild("stats");
    for (Element asset : assets.getChildren()) {
        assetsAndNumber.put(asset.getName(), new Integer(asset.getChild("r").getValue()));
    }//from www.j av  a 2 s  .c  o m
    return assetsAndNumber;
}

From source file:io.sitespeed.jenkins.xml.impl.XMLToPageTimingsJDOM.java

License:Open Source License

private Map<String, HashMap<String, String>> getMeasurements(Document doc) {

    List<Element> stats = doc.getRootElement().getChild("statistics").getChildren("statistic");
    Map<String, HashMap<String, String>> data = new HashMap<String, HashMap<String, String>>();

    for (Element statistic : stats) {
        String name = statistic.getChild("name").getValue();
        HashMap<String, String> values = new HashMap<String, String>();

        for (Element element : statistic.getChildren()) {
            if (!element.getName().equals("name")) {
                values.put(element.getName(), element.getValue());
            }//from ww  w.  j  ava2 s .  c  o m
        }

        data.put(name, values);

    }

    return data;
}

From source file:io.sitespeed.jenkins.xml.impl.XMLToSummaryJDOM.java

License:Open Source License

public SiteSummary get(File summaryXML) throws IOException {

    final SAXBuilder b = new SAXBuilder(new XMLReaderSAX2Factory(false));
    Document doc;/* www. j a va  2s .  c o  m*/
    try {
        doc = b.build(summaryXML);
    } catch (JDOMException e) {
        throw new IOException(e);
    }

    Map<String, HashMap<String, String>> values = new HashMap<String, HashMap<String, String>>();
    // TODO today the cache time is in seconds, probably should be converted to minutes?
    for (Element metric : doc.getRootElement().getChild("metrics").getChildren()) {
        String name = metric.getName();
        name = fixBrowserKey(name);
        HashMap<String, String> the = new HashMap<String, String>();
        for (Element valueType : metric.getChildren()) {
            the.put(valueType.getName(), valueType.getValue());
        }
        values.put(name, the);
    }

    int pages = new Integer(doc.getRootElement().getChild("pages").getValue());

    return new SiteSummary(values, pages);
}