Example usage for org.jdom2 Element getChildren

List of usage examples for org.jdom2 Element getChildren

Introduction

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

Prototype

public List<Element> getChildren() 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element, as Element objects.

Usage

From source file:delfos.io.xml.dataset.DatasetLoaderXML.java

License:Open Source License

public static Object getDatasetLoader(ParameterOwner parameterOwner, Element element) {
    String datasetLoaderName = element.getAttributeValue("name");

    DatasetLoader<? extends Rating> datasetLoader = DatasetLoadersFactory.getInstance()
            .getClassByName(datasetLoaderName);

    for (Object o : element.getChildren()) {
        Element parameterElement = (Element) o;
        ParameterXML.getParameterValue(datasetLoader, parameterElement);
    }//www  .j a v a  2  s.  c  o  m
    return datasetLoader;
}

From source file:delfos.main.managers.experiment.join.xml.AggregateResultsXML.java

License:Open Source License

public Map<String, Object> extractCaseParametersMapFromElement(Element element) {
    Map<String, Object> valuesByColumnName = new TreeMap<>();

    String elementName = element.getName();
    if (element.getAttribute("name") != null) {
        elementName = elementName + "." + element.getAttributeValue("name");
    }//from  w  w  w .ja v a 2  s.c  o m

    if (elementName.equals(CASE_ROOT_ELEMENT_NAME)) {
        for (Attribute attribute : element.getAttributes()) {
            String name = CaseStudyXML.CASE_ROOT_ELEMENT_NAME + "." + attribute.getName();
            String value = attribute.getValue();
            valuesByColumnName.put(name, value);
        }
    }

    if (elementName.equals(RelevanceCriteriaXML.ELEMENT_NAME)) {

        double threshold = RelevanceCriteriaXML.getRelevanceCriteria(element).getThreshold().doubleValue();
        valuesByColumnName.put(RelevanceCriteriaXML.ELEMENT_NAME, threshold);

    } else if (element.getChildren().isEmpty()) {
        String columnName;
        String value;

        if (!element.hasAttributes()) {
            throw new IllegalArgumentException("arg");
        }

        if (element.getAttribute("name") != null) {
            columnName = elementName;
            value = element.getAttributeValue("name");
        } else if (element.getAttribute("parameterName") != null) {
            columnName = element.getAttributeValue("parameterName");
            value = element.getAttributeValue("parameterValue");
        } else {
            throw new IllegalStateException("arg");
        }

        valuesByColumnName.put(columnName, value);

    } else {
        for (Element child : element.getChildren()) {

            if (child.getName().equals(AGGREGATE_VALUES_ELEMENT_NAME)) {
                continue;
            }

            if (child.getName().equals(EXECUTIONS_RESULTS_ELEMENT_NAME)) {
                throw new IllegalArgumentException("The file is a full results file!");
            }

            Map<String, Object> extractCaseParametersMapFromElement = extractCaseParametersMapFromElement(
                    child);

            for (Map.Entry<String, Object> entry : extractCaseParametersMapFromElement.entrySet()) {
                String columnNameWithPrefix = elementName + "." + entry.getKey();

                Object value = entry.getValue();

                valuesByColumnName.put(columnNameWithPrefix, value);
            }

        }
    }
    return valuesByColumnName;

}

From source file:delfos.main.managers.experiment.join.xml.AggregateResultsXML.java

License:Open Source License

private Map<String, Object> extractCaseResultsMapFromElement(Element caseStudy) {

    Map<String, Object> ret = new TreeMap<>();

    Element aggregateValues = caseStudy.getChild(AGGREGATE_VALUES_ELEMENT_NAME);

    for (Element measureResult : aggregateValues.getChildren()) {

        if (measureResult.getName().equals(AreaUnderROC.class.getSimpleName())
                || measureResult.getName().equals(AreaUnderRoc.class.getSimpleName())) {

            Element curveElement = measureResult
                    .getChild(ConfusionMatricesCurveXML.CONFUSION_MATRIX_CURVE_ELEMENT_NAME);

            try {
                ConfusionMatricesCurve curve = ConfusionMatricesCurveXML
                        .getConfusionMatricesCurve(curveElement);

                for (int index = 1; index < curve.size(); index++) {
                    double precisionAt = curve.getPrecisionAt(index);

                    DecimalFormat format = new DecimalFormat("000");

                    ret.put("Precision@" + format.format(index), precisionAt);

                    if (index == 20) {
                        break;
                    }/*from w w w.j  a va 2 s .co  m*/
                }

            } catch (UnrecognizedElementException ex) {
                Logger.getLogger(AggregateResultsXML.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        if (measureResult.getName().equals(ParameterOwnerXML.PARAMETER_OWNER_ELEMENT_NAME)) {
            String measureName = measureResult.getAttributeValue("name");
            String measureValue = measureResult.getAttributeValue("value");
            ret.put(measureName, measureValue);
        } else {
            String measureName = measureResult.getName();
            String measureValue = measureResult.getAttributeValue("value");
            ret.put(measureName, measureValue);
        }
    }

    return ret;
}

From source file:devicemodel.conversions.XmlConversions.java

public static Element nodeToXml(DeviceNode node) {
    Element elem = new Element(node.getName());
    if (node.getAttributes().size() > 0) {
        for (String key : node.getAttributes().keySet()) {
            elem.getAttributes().add(new Attribute(key, node.getAttribute(key)));
        }//from w w  w  .j  a va  2s  .  c  om
    }
    if (node.getValue() != null) {
        elem.setText(node.getValue());
    }

    if (node.getChildren().size() > 0) {
        List<String> children = node.getChildrenNamesSorted();
        for (String child : children) {
            elem.getChildren().add(nodeToXml(node.getChild(child)));
        }
    }

    return elem;
}

From source file:devicemodel.conversions.XmlConversions.java

public static DeviceNode xmlToNode(Element e, String id) {

    String[] ids = new String[] { "" };

    if (e.getAttribute("ids") != null) {
        ids = e.getAttributeValue("ids").split(",");
        e.removeAttribute("ids");
    }//  w  ww.  j  ava2s.  c o m

    DeviceNode node = new DeviceNode(e.getName() + id);

    node.setValue(e.getTextTrim());

    for (Attribute a : e.getAttributes()) {
        node.getAttributes().put(a.getName(), a.getValue());
    }

    for (String cid : ids) {
        for (Element c : e.getChildren()) {
            try {
                node.addChild(xmlToNode(c, cid));
            } catch (Exception ex) {
            }
        }
    }

    return node;
}

From source file:devicerestmodel.representations.DevicePropertyNode.java

/**
 * Set the current value in the device. This can set a virtual value or the
 * value in the actual hardware.//from   w  w  w . j ava2  s .  com
 *
 * @param element
 * @return
 * @throws Exception
 */
public synchronized final boolean setXml(Element element) throws Exception {
    if (isXmlValid(element)) {
        setElement(element);
        for (Element child : element.getChildren()) {
            for (DevicePropertyNode node : children) {
                if (node.setXml(child)) {
                    break;
                }
            }
        }
        return true;
    }
    return false;
}

From source file:devicerestmodel.representations.DevicePropertyNode.java

/**
 * Used by hardware polling to update a virtual property value.
 *
 * @param element/*from   ww w . j  a  v  a 2  s  .  c o m*/
 * @return
 * @throws Exception
 */
public synchronized final boolean updateXml(Element element) throws Exception {
    if (isXmlValid(element)) {
        updateElement(element);
        for (Element child : element.getChildren()) {
            for (DevicePropertyNode node : children) {
                if (node.updateXml(child)) {
                    break;
                }
            }
        }
        return true;
    }
    return false;
}

From source file:diuf.diva.dia.ms.script.command.CreateStackedAE.java

License:Open Source License

@Override
public String execute(Element element) throws Exception {
    String id = readId(element);//from www . j  ava 2  s  . co m

    /* If the <fromClassifier> tag is present, skip
     *
     */
    if (element.getChild("fromClassifier") != null) {
        script.scae.put(id, convertFromClassifier(getAE(id), readElement(element, "fromClassifier")));
        return "";
    }

    Element unitEl = element.getChild("unit");
    if (unitEl == null) {
        error("require unit tag");
    }
    if (unitEl.getChildren().size() != 1) {
        error("unit requires one child tag");
    }
    unitEl = unitEl.getChildren().get(0);

    String type = unitEl.getName();
    if (type == null) {
        error("unit requires a type");
    }

    SCAE scae = getAE(id);
    int inputDepth = (scae == null) ? script.colorspace.depth : scae.getOutputDepth();

    AutoEncoder unit = null;
    int width = Integer.parseInt(readElement(element, "width"));
    int height = Integer.parseInt(readElement(element, "height"));
    int ox = Integer.parseInt(readElement(element, "offset-x"));
    int oy = Integer.parseInt(readElement(element, "offset-y"));

    if (type.equalsIgnoreCase("STANDARD")) {
        // Parse the 'dimensions' text
        int hidden = Integer.parseInt(readElement(unitEl, "hidden"));

        // Parse the 'layer' text

        String encoderClassName = null;
        String decoderClassName = null;
        if (unitEl.getChild("layer") != null) {
            encoderClassName = readElement(unitEl, "layer");
            decoderClassName = encoderClassName;
        } else {
            encoderClassName = readElement(unitEl, "encoder");
            decoderClassName = readElement(unitEl, "decoder");
        }

        // Create the unit with specified parameters
        unit = new StandardAutoEncoder(width, height, inputDepth, hidden, encoderClassName, decoderClassName);
    }

    if (type.equalsIgnoreCase("MAX-POOLER")) {
        unit = new MaxPooler(width, height, inputDepth);
    }

    if (type.equalsIgnoreCase("BasicBBRBM")) {
        int hidden = Integer.parseInt(readElement(unitEl, "hidden"));
        unit = new BBRBMUnit(width, height, inputDepth, hidden);
    }

    if (type.equalsIgnoreCase("BasicGBRBM")) {
        int hidden = Integer.parseInt(readElement(unitEl, "hidden"));
        unit = new GBRBMUnit(width, height, inputDepth, hidden);
    }

    if (type.equalsIgnoreCase("PCA")) {
        // Parse the 'dimensions' text
        String s = readElement(unitEl, "dimensions");
        int dim;
        if (s.equalsIgnoreCase("FULL")) {
            // With 'FULL' we keep all dimensions
            dim = width * height * inputDepth;
        } else {
            // We keep the specified number of dimensions
            dim = Integer.parseInt(readElement(unitEl, "dimensions"));
        }

        // Parse the 'layer' text
        String layerClassName = readElement(unitEl, "layer");

        // Create the unit with specified parameters
        unit = new PCAAutoEncoder(width, height, inputDepth, dim, layerClassName);
    }

    if (type.equalsIgnoreCase("LDA")) {
        // Parse the 'dimensions' text
        int dim = Integer.parseInt(readElement(unitEl, "dimensions"));

        // Parse the 'layer' text
        String layerClassName = readElement(unitEl, "layer");

        // Create the unit with specified parameters
        unit = new LDAAutoEncoder(width, height, inputDepth, dim, layerClassName);
    }

    if (type.equalsIgnoreCase("KMeans")) {
        error("KMeans unit no longer supported after refactor");
    }

    if (unit == null) {
        error("unknown unit type: " + type);
    }

    scae = process(scae, unit, ox, oy);

    script.scae.put(id, scae);
    return "";
}

From source file:docubricks.data.Brick.java

public static Brick fromXML(File basepath, DocubricksProject proj, Element root) {
    Brick u = new Brick();
    u.id = root.getAttributeValue("id");

    u.name = root.getChildText("name");
    u.vabstract = root.getChildText("abstract");
    u.longdesc = root.getChildText("long_description");
    u.notes = root.getChildText("notes");
    u.license = root.getChildText("license");

    for (Element child : root.getChildren())
        if (child.getName().equals("author")) {
            String id = child.getAttributeValue("id");
            u.authors.add(proj.getAuthor(id));
        }/*from   w ww  .  j  a  v  a  2  s. c  om*/
    for (Element child : root.getChildren())
        if (child.getName().equals("logical_part") || child.getName().equals("function"))
            u.functions.add(Function.fromXML(basepath, proj, child));
    for (Element child : root.getChildren())
        if (child.getName().equals("instruction")) {
            StepByStepInstruction i = StepByStepInstruction.fromXML(u, basepath, child);
            i.name = child.getAttributeValue("name");
            u.instructions.add(i);
        }

    u.asmInstruction = StepByStepInstruction.fromXML(u, basepath, root.getChild("assembly_instruction"));

    u.media = MediaSet.fromXML(basepath, root.getChild("media"));

    return u;
}