Example usage for org.jdom2 Element getAttributeValue

List of usage examples for org.jdom2 Element getAttributeValue

Introduction

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

Prototype

public String getAttributeValue(final String attname) 

Source Link

Document

This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.

Usage

From source file:adruinoSignal.tools.ConfigParser.java

public Matcher getMatcher() {
    Element root = doc.getRootElement();
    Element matcherEle = root.getChild("serial").getChild("matcher");

    String start = matcherEle.getAttributeValue("start");
    String divider = matcherEle.getAttributeValue("divider");

    Matcher matcher = new Matcher(start, divider);

    return matcher;
}

From source file:AIR.Common.xml.XmlReader.java

License:Open Source License

public String getAttribute(String attributeName) throws XmlReaderException {
    Element e = getNodeAsElement();
    if (e != null)
        return e.getAttributeValue(attributeName);
    return null;/*  w ww .  jav a 2 s .c  o  m*/
}

From source file:AIR.ResourceBundler.Xml.Resources.java

License:Open Source License

public void parse() throws JDOMException, IOException, ResourcesException {
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File(_configFile);
    Document document = (Document) builder.build(xmlFile);
    Element rootElement = document.getRootElement();

    String attr = rootElement.getAttributeValue("name");
    name = (attr != null) ? attr : null;
    for (Element childEl : rootElement.getChildren()) {
        String childName = childEl.getName();
        if ("import".equalsIgnoreCase(childName)) {
            parseImport(childEl);// w  w  w .j ava  2  s  .  c om
        } else if ("fileSet".equalsIgnoreCase(childName)) {
            parseFileSet(childEl);
        } else if ("remove".equalsIgnoreCase(childName)) {
            parseRemove(childEl);
        }

    }
}

From source file:amara.applications.ingame.entitysystem.templates.CustomSerializer_Ingame.java

public static void registerClasses() {
    BitstreamClassManager.getInstance().register(ArrayList.class,
            //physics/HitboxComponent
            Circle.class, Rectangle.class, RegularCyclic.class, Shape.class, ConvexShape.class,
            SimpleConvexPolygon.class, PointShape.class, Transform2D.class, Vector2D.class, PolygonShape.class,
            BoundRectangle.class, Polygon.class, SetPolygon.class, HolePolygon.class, SimplePolygon.class,
            //units/DamageHistoryComponent
            DamageHistoryComponent.DamageHistoryEntry.class);
    ComponentsRegistrator.registerComponents();
    try {/*from w w w.  j a v  a2s .  co  m*/
        ComponentSerializer.registerFieldSerializer(
                new Field[] { Vector2f.class.getDeclaredField("x"), Vector2f.class.getDeclaredField("y") },
                new FieldSerializer_Float(20, 8));
        ComponentSerializer.registerFieldSerializer(new Field[] { Vector2D.class.getDeclaredField("x"),
                Vector2D.class.getDeclaredField("y"), Transform2D.class.getDeclaredField("scalecos"),
                Transform2D.class.getDeclaredField("scalesin"), Transform2D.class.getDeclaredField("x"),
                Transform2D.class.getDeclaredField("y"), Circle.class.getDeclaredField("localRadius"), },
                new FieldSerializer_DoubleAsFloat(20, 8));
    } catch (NoSuchFieldException ex) {
        ex.printStackTrace();
    }
    XMLTemplateManager xmlTemplateManager = XMLTemplateManager.getInstance();
    //effects/physics
    xmlTemplateManager
            .registerComponent(new XMLComponentConstructor<AddCollisionGroupsComponent>("addCollisionGroups") {

                @Override
                public AddCollisionGroupsComponent construct(EntityWorld entityWorld, Element element) {
                    long targetOf = getCollisionGroupBitMask(element.getAttributeValue("targetOf"));
                    long targets = getCollisionGroupBitMask(element.getAttributeValue("targets"));
                    return new AddCollisionGroupsComponent(targetOf, targets);
                }
            });
    xmlTemplateManager.registerComponent(
            new XMLComponentConstructor<RemoveCollisionGroupsComponent>("removeCollisionGroups") {

                @Override
                public RemoveCollisionGroupsComponent construct(EntityWorld entityWorld, Element element) {
                    long targetOf = getCollisionGroupBitMask(element.getAttributeValue("targetOf"));
                    long targets = getCollisionGroupBitMask(element.getAttributeValue("targets"));
                    return new RemoveCollisionGroupsComponent(targetOf, targets);
                }
            });
    //physics
    xmlTemplateManager.registerComponent(new XMLComponentConstructor<HitboxComponent>("hitbox") {

        @Override
        public HitboxComponent construct(EntityWorld entityWorld, Element element) {
            Shape shape = null;
            Element childElement = (Element) element.getChildren().get(0);
            String shapeType = childElement.getName();
            double x = 0;
            String xText = childElement.getAttributeValue("x");
            if (xText != null) {
                x = Double.parseDouble(xText);
            }
            double y = 0;
            String yText = childElement.getAttributeValue("y");
            if (yText != null) {
                y = Double.parseDouble(yText);
            }
            if (shapeType.equals("regularCyclic")) {
                int edges = Integer.parseInt(childElement.getAttributeValue("edges"));
                double radius = Double.parseDouble(childElement.getAttributeValue("radius"));
                shape = new RegularCyclic(edges, radius);
            } else if (shapeType.equals("circle")) {
                double radius = Double.parseDouble(childElement.getAttributeValue("radius"));
                shape = new Circle(x, y, radius);
            } else if (shapeType.equals("rectangle")) {
                double width = Double.parseDouble(childElement.getAttributeValue("width"));
                double height = Double.parseDouble(childElement.getAttributeValue("height"));
                shape = new Rectangle(x, y, width, height);
            } else if (shapeType.equals("point")) {
                Vector2D localPoint = new Vector2D();
                String[] positionCoordinates = element.getText().split(",");
                if (positionCoordinates.length > 1) {
                    double localPointX = Double
                            .parseDouble(xmlTemplateManager.parseValue(entityWorld, positionCoordinates[0]));
                    double localPointY = Double
                            .parseDouble(xmlTemplateManager.parseValue(entityWorld, positionCoordinates[1]));
                    localPoint = new Vector2D(localPointX, localPointY);
                }
                shape = new PointShape(localPoint);
            }
            if (shape == null) {
                throw new UnsupportedOperationException("Unsupported shape type '" + shapeType + "'.");
            }
            return new HitboxComponent(shape);
        }
    });
    //spawns
    xmlTemplateManager.registerComponent(new XMLComponentConstructor<SpawnTemplateComponent>("spawnTemplate") {

        @Override
        public SpawnTemplateComponent construct(EntityWorld entityWorld, Element element) {
            String[] templates = element.getText().split("\\|");
            for (int i = 0; i < templates.length; i++) {
                templates[i] = xmlTemplateManager.parseTemplate(entityWorld, templates[i]);
            }
            return new SpawnTemplateComponent(templates);
        }
    });
    //spells
    xmlTemplateManager.registerComponent(new XMLComponentConstructor<CastTypeComponent>("castType") {

        @Override
        public CastTypeComponent construct(EntityWorld entityWorld, Element element) {
            return new CastTypeComponent(CastTypeComponent.CastType.valueOf(element.getText().toUpperCase()));
        }
    });
    //units
    xmlTemplateManager
            .registerComponent(new XMLComponentConstructor<CollisionGroupComponent>("collisionGroup") {

                @Override
                public CollisionGroupComponent construct(EntityWorld entityWorld, Element element) {
                    long targetOf = getCollisionGroupBitMask(element.getAttributeValue("targetOf"));
                    long targets = getCollisionGroupBitMask(element.getAttributeValue("targets"));
                    return new CollisionGroupComponent(targetOf, targets);
                }
            });
    xmlTemplateManager
            .registerComponent(new XMLComponentConstructor<HealthBarStyleComponent>("healthBarStyle") {

                @Override
                public HealthBarStyleComponent construct(EntityWorld entityWorld, Element element) {
                    return new HealthBarStyleComponent(
                            HealthBarStyleComponent.HealthBarStyle.valueOf(element.getText().toUpperCase()));
                }
            });
}

From source file:apps.configurexml.SystemConsoleConfigPanelXml.java

License:Open Source License

/**
 * Update static data from XML file/* ww  w  .  j  a  va  2  s  .com*/
 *
 * @param e Top level Element to unpack.
 * @return true if successful
 */
@Override
public boolean load(Element e) {
    boolean result = true;
    String value;

    try {
        if ((value = e.getAttributeValue("scheme")) != null) {
            SystemConsole.getInstance().setScheme(Integer.parseInt(value));
        }

        if ((value = e.getAttributeValue("fontfamily")) != null) {

            // Check if stored font family exists
            if (!FontComboUtil.getFonts(FontComboUtil.MONOSPACED).contains(value)) {

                // No - reset to default
                log.warn("Stored console font is not compatible (" + value
                        + ") - reset to default (Monospaced)");
                value = "Monospaced";
            }

            // Finally, set the font family
            SystemConsole.getInstance().setFontFamily(value);
        }

        if ((value = e.getAttributeValue("fontsize")) != null) {
            SystemConsole.getInstance().setFontSize(Integer.parseInt(value));
        }

        if ((value = e.getAttributeValue("fontstyle")) != null) {
            SystemConsole.getInstance().setFontStyle(Integer.parseInt(value));
        }

        if ((value = e.getAttributeValue("wrapstyle")) != null) {
            SystemConsole.getInstance().setWrapStyle(Integer.parseInt(value));
        }

    } catch (NumberFormatException ex) {
        log.error("NumberFormatException while setting System Console parameters: " + ex);
        result = false;
    }

    // As we've had a load request, register the system console with the
    // preference manager
    jmri.InstanceManager.configureManagerInstance().registerPref(new SystemConsoleConfigPanel());

    return result;
}

From source file:arquivo.Arquivo.java

protected List buscaInterna(Element root, boolean completa, String nome, String nomeE) {
    List<Element> retorna = new LinkedList<>();
    List<Element> empregados = root.getChildren(nomeE);
    for (Element empregado : empregados) {
        if (completa) {
            if (empregado.getAttributeValue("nome").equals(nome))
                retorna.add(empregado);/*from w w  w  .  j av  a 2  s.  c o  m*/
        } else {
            if (empregado.getAttributeValue("nome").contains(nome))
                retorna.add(empregado);
        }
    }
    return retorna;
}

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.layout.Mfenced.java

License:Open Source License

@Override
public Element render(FormulaElement parent, List<FormulaElement> siblings) {
    Element fencedSpan = new Element("span");
    fencedSpan.setAttribute("class", "mfenced");

    // Opening fence
    Element openFenceSpan = new Element("span");
    openFenceSpan.setAttribute("class", "mfenced-open");
    openFenceSpan.setText(opened);//from   www  .j a  va  2s. c  o  m
    fencedSpan.addContent(openFenceSpan);

    // Content
    if (content.isEmpty() == false) {

        // if this is a fenced table or matrix, just render the content element
        // pass information about the fence via parent reference
        if (content.size() == 1 && content.get(0) instanceof Mtable) {
            Mtable fencedTableOrMatrix = (Mtable) content.get(0);
            return fencedTableOrMatrix.render(this, null);
        }

        String tempSeparators = separators.replaceAll(" ", "");

        for (int i = 0; i < content.size(); i++) {
            FormulaElement element = content.get(i);

            Element contentSpan = new Element("span");
            contentSpan.setAttribute("class", "mfenced-content");
            contentSpan.addContent(element.render(null, null));
            fencedSpan.addContent(contentSpan);

            // Separators
            if (content.size() > 1) {
                Mo separatorElement = new Mo();
                separatorElement.setSeparator(true);

                String separator = SEPARATOR;
                if (tempSeparators.length() == 1) {
                    separator = tempSeparators;
                } else if (i < tempSeparators.length()) {
                    separator = Character.toString(tempSeparators.charAt(i));

                    // Entity lookup
                    if (separator.length() > 1) {
                        String entityName = separator.substring(1, separator.length() - 1);
                        if (MathmlCharacterDictionary.entityMapByName.containsKey(entityName)) {
                            separator = MathmlCharacterDictionary.entityMapByName.get(entityName);
                        }
                    }
                }

                separatorElement.setValue(separator);

                Element mo = separatorElement.render(this, null);
                mo.setAttribute("class", mo.getAttributeValue("class") + " mfenced-separator");
                fencedSpan.addContent(mo);
            }
        }
    }

    // Closing fence
    Element closeFenceSpan = new Element("span");
    closeFenceSpan.setAttribute("class", "mfenced-close");
    closeFenceSpan.setText(closed);
    fencedSpan.addContent(closeFenceSpan);

    return fencedSpan;
}

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.elements.tablesmatrices.Mtable.java

License:Open Source License

@Override
public Element render(FormulaElement parent, List<FormulaElement> siblings) {
    Element mtableDiv = new Element("div");
    mtableDiv.setAttribute("class", "mtable");

    // create Table
    Element table = new Element("table");

    // Matrix / Table parenthesis
    if (parent != null && parent instanceof Mfenced) {
        Mfenced mfenced = (Mfenced) parent;
        if (mfenced.getOpened().equals("(") && mfenced.getClosed().equals(")")) {
            table.setAttribute("class", "pmatrix");
        }/*from w  ww.  ja va 2  s .  c  om*/
        if (mfenced.getOpened().equals("[") && mfenced.getClosed().equals("]")) {
            table.setAttribute("class", "bmatrix");
        }
        if (mfenced.getOpened().equals("{") && mfenced.getClosed().equals("}")) {
            table.setAttribute("class", "pmatrix"); // intentionally pmatrix for curved border corners
            mtableDiv.setAttribute("class", mtableDiv.getAttributeValue("class") + " mtable-Bmatrix");
        }
        if (mfenced.getOpened().equals("|") && mfenced.getClosed().equals("|")) {
            table.setAttribute("class", "vmatrix");
        }
        if (mfenced.getOpened().equals("") && mfenced.getClosed().equals("")) {
            table.setAttribute("class", "Vmatrix");
        }

    }

    // evaluate Rows
    for (int i = 0; i < rows.size(); i++) {
        table.addContent(rows.get(i).render(null, null));
    }

    mtableDiv.addContent(table);

    return mtableDiv;
}

From source file:at.newmedialab.lmf.util.geonames.builder.GeoLookupImpl.java

License:Apache License

/**
 * Query the geonames-api for a place with the provided name.
 * @param name the name of the place to lookup at geonames
 * @return the URI of the resolved place, or null if no such place exists.
 *//*  w  w  w  . j a  v  a 2s . c o m*/
private String queryPlace(String name) {
    if (StringUtils.isBlank(name))
        return null;

    StringBuilder querySB = new StringBuilder();
    queryStringAppend(querySB, "q", name);

    queryStringAppend(querySB, "countryBias", countryBias);
    for (char fc : featureClasses) {
        queryStringAppend(querySB, "featureClass", String.valueOf(fc));
    }
    for (String fc : featureCodes) {
        queryStringAppend(querySB, "featureCode", fc);
    }
    for (String c : countries) {
        queryStringAppend(querySB, "country", c);
    }
    for (String cc : continentCodes) {
        queryStringAppend(querySB, "continentCode", cc);
    }
    if (fuzzy < 1) {
        queryStringAppend(querySB, "fuzzy", String.valueOf(fuzzy));
    }

    queryStringAppend(querySB, "maxRows", "1");
    queryStringAppend(querySB, "type", "xml");
    queryStringAppend(querySB, "isNameRequired", "true");
    queryStringAppend(querySB, "style", "short");

    if (StringUtils.isNotBlank(geoNamesUser))
        queryStringAppend(querySB, "username", geoNamesUser);
    if (StringUtils.isNotBlank(geoNamesPasswd))
        queryStringAppend(querySB, "password", geoNamesPasswd);

    final String url = geoNamesUrl + "search?" + querySB.toString();
    HttpGet get = new HttpGet(url);

    try {
        return http.execute(get, new ResponseHandler<String>() {
            /**
             * Parses the xml-response from the geonames webservice and build the uri for the result
             * @return the URI of the resolved place, or null if no place was found.
             */
            @Override
            public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
                final int statusCode = response.getStatusLine().getStatusCode();
                if (!(statusCode >= 200 && statusCode < 300)) {
                    return null;
                }
                try {
                    SAXBuilder builder = new SAXBuilder();
                    final HttpEntity entity = response.getEntity();
                    if (entity == null)
                        throw new ClientProtocolException("Body Required");
                    final Document doc = builder.build(entity.getContent());

                    final Element root = doc.getRootElement();
                    final Element status = root.getChild("status");
                    if (status != null) {
                        final int errCode = Integer.parseInt(status.getAttributeValue("value"));
                        if (errCode == 15) {
                            // NO RESULT should not be an exception
                            return null;
                        }

                        throw new GeoNamesException(errCode, status.getAttributeValue("message"));
                    }
                    final Element gName = root.getChild("geoname");
                    if (gName == null)
                        return null;

                    final String geoId = gName.getChildTextTrim("geonameId");
                    if (geoId == null)
                        return null;

                    return String.format(GEONAMES_URI_PATTERN, geoId);
                } catch (NumberFormatException e) {
                    throw new ClientProtocolException(e);
                } catch (IllegalStateException e) {
                    throw new ClientProtocolException(e);
                } catch (JDOMException e) {
                    throw new IOException(e);
                }
            }
        });
    } catch (GeoNamesException e) {
        log.debug("Lookup at GeoNames failed: {} ({})", e.getMessage(), e.getErrCode());
    } catch (ClientProtocolException e) {
        log.error("Could not query geoNames: " + e.getLocalizedMessage(), e);
    } catch (IOException e) {
        log.error("Could not query geoNames: " + e.getLocalizedMessage(), e);
    }
    return null;
}

From source file:ataraxis.passwordmanager.XMLHandler.java

License:Open Source License

/**
 * Get a GroupEntry with the given id.//from  w  ww  . j  ava 2  s. com
 *
 * @param id
 * @return the requested GroupEntry
 * @throws EntryDoesNotExistException
 */
public GroupEntry getGroupEntry(String id) throws EntryDoesNotExistException {
    GroupEntry groupEntry = null;

    try {
        Element groupElement = getElement(id);
        if (groupElement != null) {
            if (isGroupElement(id)) {
                String entryId = groupElement.getAttributeValue("id");
                groupEntry = new GroupEntry(entryId);
            }
        }
    } catch (JDOMException e) {
        throw new EntryDoesNotExistException("entry not found");
    }

    return groupEntry;
}