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:de.smartics.maven.alias.domain.AliasesProcessor.java

License:Apache License

private Alias createAlias(final Element aliasElement) {
    final Alias.Builder builder = new Alias.Builder();
    final Attribute env = aliasElement.getAttribute("env");
    final Element command = aliasElement.getChild("command", nsAlias);
    final String normalizedCommandText = command.getTextNormalize();
    builder.withName(aliasElement.getChildTextNormalize("name", nsAlias)).withCommand(normalizedCommandText);

    final String comment = readComment(aliasElement);
    builder.withComment(comment);/*  w w  w  . j a v  a 2 s  . c om*/

    if (env != null) {
        builder.withEnv(env.getValue());
    }
    final Attribute args = command.getAttribute("passArgs");
    if (args != null && !Boolean.parseBoolean(args.getValue())) {
        builder.withPassArgs(false);
    }

    return builder.build();
}

From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.graphml.GraphmlParser.java

License:Open Source License

/**
 * Parses Edges/*from   w w  w .  j a v a  2 s. c o  m*/
 */
public void readEdges() {
    if (nodelist.isEmpty()) {
        logger.error("Read in Nodes first!");
        System.exit(-1);
    }
    List<Element> edgeelemlist = this.graph.getChildren("edge", this.ns);
    for (Element e : edgeelemlist) {
        Attribute source_attr = e.getAttribute("source");
        int source = Integer.parseInt(source_attr.getValue());

        Attribute target_attr = e.getAttribute("target");
        int target = Integer.parseInt(target_attr.getValue());

        Element linkspeed_elem = findElementById(e.getChildren(), linklabel_key);
        double linkspeed = 0.0;
        if (linkspeed_elem != null) {
            Scanner scanner = new Scanner(linkspeed_elem.getText());
            while (!scanner.hasNextDouble() && scanner.hasNext()) {
                scanner.next();
            }
            if (scanner.hasNextDouble()) {

                linkspeed = scanner.nextDouble();
            }
            if (linkspeed_elem.getText().contains("Mbps")) {
                linkspeed *= 1E06;
            }
            if (linkspeed_elem.getText().contains("Gbps")) {
                linkspeed *= 1E09;
            }
            scanner.close();
        }
        Node sourcenode = null;
        Node targetnode = null;
        for (Node n : this.nodelist) {
            if (n.getIds().contains(source)) {
                sourcenode = n;
            }
            if (n.getIds().contains(target)) {
                targetnode = n;
            }
        }
        if (sourcenode == null || targetnode == null || sourcenode == targetnode
                || findEdge(edgelist, sourcenode, targetnode) != null) {
            continue;
        }
        Edge edge = new Edge(sourcenode, targetnode, linkspeed);
        this.edgelist.add(edge);
    }
}

From source file:delfos.io.xml.recommendations.RecommendationsToXML.java

License:Open Source License

/**
 * Convierte el elemento XML indicado en un objeto que representa las recomendaciones al usuario.
 *
 * @param element Elemento XML a convertir.
 * @return Recomendaciones.//ww  w . java  2s .  c  o m
 *
 * @throws IllegalArgumentException Si el elemento no contiene la informacin necesaria para recuperar un objeto
 * {@link Recommendations}.
 *
 * @see RecommendationsToXML#getRecommendationsElement(delfos.RS.Recommendation.Recommendations)
 *
 */
public static Recommendations getRecommendations(Element element) {

    if (!element.getName().equals(RECOMMENDATIONS_ELEMENT_NAME)) {
        throw new IllegalArgumentException("Element name doesn't match this reader: found '" + element.getName()
                + "' expected '" + RECOMMENDATIONS_ELEMENT_NAME + "'");
    }

    String idTarget = element.getAttributeValue(ID_TARGET_ATTRIBUTE_NAME);

    Map<DetailField, Object> details = new TreeMap<>();
    for (Attribute attribute : element.getAttributes()) {

        if (ID_TARGET_ATTRIBUTE_NAME.equals(attribute.getName())) {
            continue;
        }

        DetailField detailField = DetailField.valueOfNoCase(attribute.getName());

        String detailFieldValueString = attribute.getValue();
        Object detailFieldValue = detailField.parseValue(detailFieldValueString);

        details.put(detailField, detailFieldValue);

    }

    RecommendationComputationDetails recommendationComputationDetails = new RecommendationComputationDetails(
            details);
    List<Recommendation> recommendations = new LinkedList<>();
    for (Object r : element.getChildren(RECOMMENDATION_ELEMENT_NAME)) {
        Element recommendationElement = (Element) r;

        if (!recommendationElement.getName().equals(RECOMMENDATION_ELEMENT_NAME)) {
            throw new IllegalArgumentException("Element name doesn't match this reader: found '"
                    + recommendationElement.getName() + "' expected '" + RECOMMENDATION_ELEMENT_NAME + "'");
        }
        int idItem = Integer.parseInt(recommendationElement.getAttributeValue(ID_ITEM_ATTRIBUTE_NAME));
        double preference = Double
                .parseDouble(recommendationElement.getAttributeValue(PREFERENCE_ATTRIBUTE_NAME));
        recommendations.add(new Recommendation(idItem, preference));
    }

    return RecommendationsFactory.createRecommendations(idTarget, recommendations,
            recommendationComputationDetails);
}

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 ww w  .j a v  a  2s .  com*/

    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: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 a v  a  2 s  . 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:es.upm.dit.xsdinferencer.extraction.extractorImpl.AttributeListInferencerImpl.java

License:Apache License

/**
 * @see AttributeListInferencer#learnAttributeList(List, int)
 *//*from   w w  w . j  ava  2s  .c o m*/
@Override
public void learnAttributeList(List<Attribute> attrList, int documentIndex) {
    checkNotNull(attrList, "'attrList' must not be null");
    if (!firstTime) {
        //First, we mark as optional any known attribute which does not reoccur
        for (SchemaAttribute schemaAttribute : knownAttributes.keySet()) {
            boolean found = false;
            for (Attribute attribute : attrList) {
                if (attribute.getName().equals(schemaAttribute.getName())
                        && attribute.getNamespace().getURI().equals(schemaAttribute.getNamespace()))
                    found = true;
            }
            if (!found)
                schemaAttribute.setOptional(true);
        }
    }
    //Now, we learn the information given by this list of atttributes
    for (Attribute attribute : attrList) {
        if (attribute.getNamespaceURI().equals(XSI_NAMESPACE_URI))
            continue;//Attributes in the XSI namespace are not extracted.
        SchemaAttribute schemaAttribute = searchSchemaAttribute(attribute.getNamespaceURI(),
                attribute.getName());
        //New attribute
        if (schemaAttribute == null) {
            schemaAttribute = new SchemaAttribute(attribute.getName(), attribute.getNamespaceURI(), true,
                    new SimpleType(""));
            if (firstTime)
                schemaAttribute.setOptional(false);
            SimpleTypeInferencer simpleTypeInferencer = InferencersFactory.getInstance()
                    .getSimpleTypeInferencerInstance(schemaAttribute.getNamespace()
                            + config.getTypeNamesAncestorsSeparator() + schemaAttribute.getName(), config);
            simpleTypeInferencer.learnValue(attribute.getValue(), attribute.getNamespaceURI(),
                    "@" + attribute.getName());
            knownAttributes.put(schemaAttribute, simpleTypeInferencer);
        }
        //Already known attribute
        else {
            knownAttributes.get(schemaAttribute).learnValue(attribute.getValue(), attribute.getNamespaceURI(),
                    "@" + attribute.getName());
        }
        complexTypeStatisticsEntry.registerAttributeOccurrenceInfoCount(schemaAttribute, documentIndex);
        complexTypeStatisticsEntry.registerValueOfNodeCount(attribute.getValue(), schemaAttribute,
                documentIndex);
        String realPathFiltered = TypesExtractorImpl.filterAndJoinRealPath(TypesExtractorImpl
                .getRealPathOfAttributeUnfiltered(attribute, config, solvedNamespaceToPrefixMapping));
        statistics.registerAttributeOccurrenceAtPathCount(realPathFiltered, documentIndex);
        statistics.registerValueAtPathCount(realPathFiltered, attribute.getValue(), documentIndex);
    }
    firstTime = false;
}

From source file:fr.paris.lutece.plugins.dila.service.impl.DilaBatchXMLService.java

License:Open Source License

@Override
public XmlDTO buildDocument(File file, AudienceCategoryEnum typeXML) throws JDOMException, IOException {
    XmlDTO dilaXml = new XmlDTO();
    dilaXml.setIdAudience(typeXML.getId());

    // Convert file to document object
    Document document = _saxBuilder.build(file);

    // Get root/* www  . java2 s.  co m*/
    Element root = document.getRootElement();

    // Get attribute ID
    Attribute rootAttrId = root.getAttribute(ATTRIBUTE_ID);

    if (rootAttrId != null) {
        String strId = rootAttrId.getValue();
        dilaXml.setIdXml(strId);
    }

    // Get title
    Element title = root.getChild(CHILD_TITLE, NAMESPACE_DC);

    if (title != null) {
        String strTitle = title.getTextTrim();
        dilaXml.setTitle(strTitle);
    }

    // Get type
    Element type = root.getChild(CHILD_TYPE, NAMESPACE_DC);

    if (type != null) {
        if (file.getName().startsWith("R")) {
            dilaXml.setResourceType(RESSOURCE_TYPE);
        } else {
            String strType = type.getTextTrim();
            dilaXml.setResourceType(strType);
        }
    }

    // Get breadcrumb
    Element rootBreadcrumb = root.getChild(CHILD_BREADCRUMB);

    if (rootBreadcrumb != null) {
        List<Element> listBreadcrumb = rootBreadcrumb.getChildren();

        if (CollectionUtils.isNotEmpty(listBreadcrumb)) {
            List<String> listBreadcrumbId = new ArrayList<String>(listBreadcrumb.size());

            for (Element elementBreadcrumb : listBreadcrumb) {
                listBreadcrumbId.add(elementBreadcrumb.getAttributeValue(ATTRIBUTE_ID));
            }

            String strBreadcrumb = StringUtils.join(listBreadcrumbId, ";");
            dilaXml.setBreadCrumb(strBreadcrumb);
        }
    }

    return dilaXml;
}

From source file:helpers.XMLParser.java

public static ParsedSingleXML parseSingleDoc(String xml) {
    ParsedSingleXML doc = null;/*  ww w . j a v  a 2s  .c  om*/
    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:io.smartspaces.workbench.project.jdom.JdomProjectGroupTemplateSpecificationReader.java

License:Apache License

/**
 * Get any attributes attached to the project.
 *
 * @param spec/* ww w. j  a va 2s .  c  o m*/
 *          the specification whose data is being read
 * @param rootElement
 *          root element of the XML DOM containing the project data
 */
private void getSpecificationAttributes(GroupProjectTemplateSpecification spec, Element rootElement) {
    @SuppressWarnings("unchecked")
    List<Attribute> attributes = rootElement.getAttributes();
    for (Attribute attribute : attributes) {
        spec.addAttribute(attribute.getName(), attribute.getValue());
    }
}

From source file:io.smartspaces.workbench.project.jdom.JdomProjectReader.java

License:Apache License

/**
 * Get any attributes attached to the project.
 *
 * @param project//from ww w .  ja v a  2s .  c  o m
 *          the project description whose data is being read
 * @param rootElement
 *          root element of the XML DOM containing the project data
 */
private void getProjectAttributes(Project project, Element rootElement) {
    @SuppressWarnings("unchecked")
    List<Attribute> attributes = rootElement.getAttributes();
    for (Attribute attribute : attributes) {
        project.addAttribute(attribute.getName(), attribute.getValue());
    }
}