Example usage for org.jdom2 Attribute getValue

List of usage examples for org.jdom2 Attribute getValue

Introduction

In this page you can find the example usage for org.jdom2 Attribute getValue.

Prototype

public String getValue() 

Source Link

Document

This will return the actual textual value of this Attribute.

Usage

From source file:recparser.idmef.IdmefParser.java

License:Open Source License

private void addAttribute(Element current, Attribute attribute, Object o) {

    String elemento = current.getName();
    String attributeName = attribute.getName();
    String attributeValue = attribute.getValue();

    if (elemento.equals("Target")) {
        if (attributeName.equals("ident")) {
            if (o instanceof IntrusionTarget) {
                IntrusionTarget target = (IntrusionTarget) o;
                target.setTargetID(attributeValue);
            }/*from  w w w  . j  a v a  2  s.c o m*/
        }
    } else if (elemento.equals("Source")) {
        if (o instanceof IntrusionSource) {
            IntrusionSource source = (IntrusionSource) o;
            if (attributeName.equals("spoofed")) {
                source.setSpoofed(attributeValue);

            } else if (attributeName.equals("ident")) {
                source.setIdent(attributeValue);

            } else if (attributeName.equals("interface")) {
                source.setInterfaceSource(attributeValue);
            }
        }
    } else if (elemento.equals("Address")) {
        if (o instanceof Address) {
            Address a = (Address) o;
            if (attributeName.equals("category")) {
                a.setCategory(attributeValue);

            } else if (attributeName.equals("vlan-name")) {
                a.setVlan_name(attributeValue);

            } else if (attributeName.equals("vlan-num")) {
                a.setVlan_num(attributeValue);

            } else if (attributeName.equals("ident")) {
                a.setIdent(attributeValue);
            }
        }
    } else if (elemento.equals("Service")) {
        if (o instanceof IntrusionTarget) {
            IntrusionTarget target = (IntrusionTarget) o;
            if (attributeName.equals("ident")) {
                target.setServiceID(attributeValue);
            }
        }
    }

}

From source file:Reference.SearchThroughXML.XML_Query_SAX_1.java

public static void querySAX(String inputFileName) {
    try {/*from   w  ww.j a  v a2s. c o  m*/

        //File inputFile = new File(inputFileName);
        File inputFile = new File("data/input_car_xml.xml");

        SAXBuilder saxBuilder = new SAXBuilder();
        Document document = saxBuilder.build(inputFile);

        System.out.println("Root element :" + document.getRootElement().getName());

        Element rootElement = document.getRootElement();

        System.out.println("---------------------------------------------");

        List<Element> supercarList = rootElement.getChildren("supercars");

        System.out.println("size of supercarList is " + supercarList.size());
        System.out.println("");

        for (int i = 0; i < supercarList.size(); i++) {
            Element supercarElement = supercarList.get(i);
            System.out.println("Current Element :" + supercarElement.getName());
            Attribute attribute = supercarElement.getAttribute("company");
            System.out.println("company : " + attribute.getValue());
            List<Element> carNameList = supercarElement.getChildren("carname");
            for (int j = 0; j < carNameList.size(); j++) {
                Element carElement = carNameList.get(j);
                String carName = carElement.getText();
                Attribute typeAttribute = carElement.getAttribute("type");
                String carType = (typeAttribute != null ? typeAttribute.getValue() : "null");
                System.out.println("car name : " + carName + ", " + "car type : " + carType);
            }
            //deck
            Element deckElement = supercarElement.getChild("deck");
            //Attribute nullAttribute = deckElement.getAttribute("null");
            //System.out.println("* " + nullAttribute.toString());
            //String deckString = (nullAttribute != null ? "null" : deckElement.getText());
            System.out.println("deck : " + deckElement.getText());

            Element aliasesElement = supercarElement.getChild("aliases");
            Attribute nullAttribute = aliasesElement.getAttribute("null");
            //String aliasText = (nullAttribute.getValue().equals("true") ? "null" : aliasesElement.getText());
            String aliasText = (nullAttribute == null ? aliasesElement.getText() : "null");
            System.out.println("aliasesElement : " + aliasText);

            System.out.println("");
        }

        List<Element> luxurycarList = rootElement.getChildren("luxurycars");

        System.out.println("size of luxurycarList is " + luxurycarList.size());
        System.out.println("");

        for (int i = 0; i < luxurycarList.size(); i++) {
            Element luxurycarElement = luxurycarList.get(i);
            System.out.println("Current Element :" + luxurycarElement.getName());
            List<Element> carNameList = luxurycarElement.getChildren("carname");
            for (int j = 0; j < carNameList.size(); j++) {
                Element carElement = carNameList.get(j);
                String carName = carElement.getText();
                System.out.println("car name : " + carName);

            }
        }

    } catch (JDOMException e) {
        e.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}

From source file:ru.iteco.xmldoc.ConfigEx.java

License:Open Source License

public Map<String, String> getElementMap(Element el) {
    Map<String, String> result = new LinkedHashMap<String, String>();
    for (Attribute attr : el.getAttributes()) {
        if (attr.getName().equals("class"))
            //     ?  
            result.put("_class", attr.getValue());
        result.put(attr.getName(), attr.getValue());
    }/*from  ww  w  .  java2  s  .c o  m*/

    result.put("description", getPreviousComment(el));
    result.put("source", new XMLOutputter().outputString(el).trim());
    result.put("elementname", el.getName());

    return result;
}

From source file:ru.iteco.xmldoc.Scope.java

License:Open Source License

public Scope(Element element) {
    Element scopeEl = element.getParentElement();
    if (scopeEl.getName() != "scope")
        System.out.println("Where is scope ? Parent el :" + scopeEl.getName());
    else {/*from w ww. ja  v  a 2s . c  om*/
        List<Attribute> scopes = scopeEl.getAttributes();
        for (Attribute sc : scopes) {
            String tmp_val = sc.getValue();
            String[] tmp_vals = tmp_val.split(",");
            for (String v : tmp_vals) {
                add(sc.getName(), v.trim());
            }
        }
    }
}

From source file:se.miun.itm.input.model.element.Value.java

License:Open Source License

@SuppressWarnings("unchecked")
public boolean same(Object obj) {
    if (!(obj instanceof Value))
        return false;

    Value<? extends Param<?>> foreigner = (Value<?>) obj;
    Attribute forAttr;
    for (Attribute attr : getAttributes()) {
        forAttr = foreigner.getAttribute(attr.getName());
        if (forAttr == null || !forAttr.getValue().equals(attr.getValue()))
            return false;
    }//  w  w  w . j  a v a2  s. c om

    List<Value<?>> myChildren = (List<Value<?>>) (List<?>) getChildren();
    List<Value<?>> foreignerChildren = (List<Value<?>>) (List<?>) foreigner.getChildren();
    if (myChildren.size() != foreignerChildren.size())
        return false;

    Value<?> foreignerValue;
    for (Value<?> value : myChildren) {
        foreignerValue = getSame(value, foreignerChildren);
        if (foreignerValue == null || !value.same(foreignerValue))
            return false;
    }

    return true;
}

From source file:se.miun.itm.input.model.param.Param.java

License:Open Source License

private void initFromOriginal(Element original) {
    // init attributes
    setNamespace(original.getNamespace());
    setName(original.getName());//  w w  w.j a v a2  s  . co  m
    Attribute attr;
    for (Object content : original.getAttributes()) {
        attr = (Attribute) content;
        setAttribute(attr.getName(), attr.getValue());
    }

    // move children
    Element childE;
    Object[] children = original.getChildren().toArray();
    for (Object child : children) {
        childE = (Element) child;
        original.removeContent(childE);
        addContent(childE);
    }

    // attach to parent
    Element parent = original.getParentElement();
    parent.removeContent(original);
    parent.addContent(this);
}

From source file:se.miun.itm.input.model.param.Param.java

License:Open Source License

public boolean isOptional() {
    Attribute optionalAttribute = getAttribute(Q.OPTIONAL);
    return optionalAttribute == null ? false : Boolean.parseBoolean(optionalAttribute.getValue());
}

From source file:site.util.EvXmlUtil.java

License:BSD License

/**
 * Checks if name and attributes equal, not content
 *//*from www  .  j  a  v  a2  s . c  om*/
public static boolean elementsEqual(Element a, Element b) {
    if (a.getName().equals(b.getName())) {
        for (Object o : a.getAttributes()) {
            Attribute attra = (Attribute) o;
            Attribute attrb = b.getAttribute(attra.getName());
            if (attrb == null)
                return false;
            if (!attra.getValue().equals(attrb.getValue()))
                return false;
        }
        for (Object o : b.getAttributes()) {
            Attribute attrb = (Attribute) o;
            Attribute attra = a.getAttribute(attrb.getName());
            if (attra == null)
                return false;
            if (!attrb.getValue().equals(attra.getValue()))
                return false;
        }
        return true;
    } else
        return false;
}

From source file:strategies.HeldStock.java

public void LoadFromXml(Element heldElement) {
    Attribute attribute = heldElement.getAttribute("ticker");
    tickerSymbol = attribute.getValue();

    List<Element> purchaseElements = heldElement.getChildren();
    for (Element purchaseElement : purchaseElements) {
        StockPurchase purchase = new StockPurchase();
        purchase.LoadFromXml(purchaseElement);
        purchases.add(purchase);/*w  ww  .j  a v a  2 s .  com*/
    }
}

From source file:strategies.StockPurchase.java

void LoadFromXml(Element purchaseElement) {
    try {/*from w  ww  .  j av  a  2s.  co m*/
        Attribute attribute = purchaseElement.getAttribute("priceForOne");
        priceForOne = attribute.getDoubleValue();

        attribute = purchaseElement.getAttribute("position");
        position = attribute.getIntValue();

        attribute = purchaseElement.getAttribute("portions");
        portions = attribute.getIntValue();

        attribute = purchaseElement.getAttribute("date");
        date = LocalDate.parse(attribute.getValue());

    } catch (DataConversionException ex) {
        logger.severe("Error in loading from XML: Failed to convert values in purchases. " + ex.getMessage());
    }
}