Example usage for org.jdom2 Element getValue

List of usage examples for org.jdom2 Element getValue

Introduction

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

Prototype

@Override
public String getValue() 

Source Link

Document

Returns the XPath 1.0 string value of this element, which is the complete, ordered content of all text node descendants of this element (i.e. the text that's left after all references are resolved and all other markup is stripped out.)

Usage

From source file:com.thoughtworks.go.server.service.lookups.CommandSnippetXmlParser.java

License:Apache License

public CommandSnippet parse(String xmlContent, String fileName, String relativeFilePath) {
    try {//  w  w w  .  j a  v a 2 s  .c  o  m
        Document document = buildXmlDocument(xmlContent,
                CommandSnippet.class.getResource("command-snippet.xsd"));
        CommandSnippetComment comment = getComment(document);

        Element execTag = document.getRootElement();
        String commandName = execTag.getAttributeValue("command");
        List<String> arguments = new ArrayList<>();
        for (Object child : execTag.getChildren()) {
            Element element = (Element) child;
            arguments.add(element.getValue());
        }
        return new CommandSnippet(commandName, arguments, comment, fileName, relativeFilePath);
    } catch (Exception e) {
        String errorMessage = String.format("Reason: %s", e.getMessage());
        LOGGER.info("Could not load command '{}'. {}", fileName, errorMessage);
        return CommandSnippet.invalid(fileName, errorMessage, new EmptySnippetComment());
    }
}

From source file:cz.lbenda.dbapp.rc.db.JDBCConfiguration.java

License:Apache License

public final void loadFromElement(Element element) {
    setPassword(subElementText(element, "password", ""));
    setUsername(subElementText(element, "user", "SA"));
    setUrl(subElementText(element, "url", ""));
    setDriverClass(subElementText(element, "driverClass", ""));
    Element libraries = element.getChild("libraries");
    if (libraries != null) {
        for (Element librarie : (List<Element>) libraries.getChildren("librarie")) {
            getImportedLibreries().add(librarie.getValue());
        }//w  w  w  .j av  a  2 s .  c  om
    }
}

From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.UnaryOperatorRemover.java

License:Apache License

private void removeUnaryOperator(final Element rootElem) {

    assert rootElem != null;

    /* Presentation MathML */
    final Set<String> pmCharsToRemove = getPropertySet(PM_UNARY_OPERATORS_TO_REMOVE);

    if (!pmCharsToRemove.isEmpty()) {

        // Unary operators
        List<Element> pmElemsToRemove = xpPMUnaryOperators.evaluate(rootElem);
        for (Element toRemove : pmElemsToRemove) {
            if (pmCharsToRemove.contains(toRemove.getValue())) {
                LOGGER.finest("Removing element '" + toRemove.getQualifiedName() + "' with value '"
                        + toRemove.getValue() + "'.");
                toRemove.detach();/*from www . j a v  a2  s . c om*/
            } else {
                LOGGER.finest("Skipping element '" + toRemove.getQualifiedName() + "' with value '"
                        + toRemove.getValue() + "'.");
            }
        }

        // Second of the double operators
        pmElemsToRemove = xpPMSecondOperatorInDoubleOperators.evaluate(rootElem);
        for (Element toRemove : pmElemsToRemove) {
            if (pmCharsToRemove.contains(toRemove.getValue())) {
                LOGGER.finest("Removing the second element out of double elements '"
                        + toRemove.getQualifiedName() + "' with value '" + toRemove.getValue() + "'.");
                toRemove.detach();
            } else {
                LOGGER.finest("Skipping the second element out of double elements '"
                        + toRemove.getQualifiedName() + "' with value '" + toRemove.getValue() + "'.");
            }
        }

    }

    LOGGER.finer("RemoveUnaryOperator Presentation MathML finished");

    /* Content MathML */
    List<Element> applyWithTwoChildrens = xpCMApplyWithTwoChildrens.evaluate(rootElem);
    final Set<String> cmOperatorsToRemove = getPropertySet(CM_UNARY_OPERATORS_TO_REMOVE);

    for (Element applyElem : applyWithTwoChildrens) {
        Element operator = applyElem.getChildren().get(0);
        if (cmOperatorsToRemove.contains(operator.getName())) {
            Element operand = applyElem.getChildren().get(1);
            LOGGER.finest("Removing operator '" + operator.getQualifiedName() + "' for operand '"
                    + operand.getQualifiedName() + "'.");
            operand.detach();
            Element parent = applyElem.getParentElement();
            int applyElemIndex = parent.indexOf(applyElem);
            parent.setContent(applyElemIndex, operand);
            applyElem.detach();
        }
    }

    LOGGER.finer("RemoveUnaryOperator Content MathML finished");

}

From source file:de.nava.informa.parsers.Atom_0_3_Parser.java

License:Open Source License

/**
 * Returns the title from title element.
 *//*  ww w .  ja  v  a 2  s  . c o  m*/
static String getTitle(Element elt) {
    if (elt == null) {
        return "";
    }

    String type = getContentType(elt);
    String value;

    if ("application/xhtml+xml".equals(type)) {
        value = elt.getValue();
    } else {
        value = AtomParserUtils.getValue(elt, elt.getAttributeValue("mode"));

        if (!"text/plain".equals(type)) {
            value = ParserUtils.unEscape(value);
        }
    }

    return value;
}

From source file:de.sub.goobi.helper.HelperSchritte.java

License:Open Source License

private static void addMetadata(List<Element> elements, Map<String, List<String>> metadataPairs) {
    for (Element goobimetadata : elements) {
        String metadataType = goobimetadata.getAttributeValue("name");
        String metadataValue = "";
        if (goobimetadata.getAttributeValue("type") != null
                && goobimetadata.getAttributeValue("type").equals("person")) {
            Element displayName = goobimetadata.getChild("displayName", goobiNamespace);
            if (displayName != null && !displayName.getValue().equals(",")) {
                metadataValue = displayName.getValue();
            }//from   w w w.j a  va 2s . c o  m
        } else if (goobimetadata.getAttributeValue("type") != null
                && goobimetadata.getAttributeValue("type").equals("group")) {
            List<Element> groupMetadataList = goobimetadata.getChildren();
            addMetadata(groupMetadataList, metadataPairs);
        } else {
            metadataValue = goobimetadata.getValue();
        }
        if (!metadataValue.equals("")) {

            if (metadataPairs.containsKey(metadataType)) {
                List<String> oldValue = metadataPairs.get(metadataType);
                if (!oldValue.contains(metadataValue)) {
                    oldValue.add(metadataValue);
                    metadataPairs.put(metadataType, oldValue);
                }
            } else {
                List<String> list = new ArrayList<>();
                list.add(metadataValue);
                metadataPairs.put(metadataType, list);
            }
        }

    }
    return;
}

From source file:eddpractica1_201503692.CargaXML.java

public void cargarXml(File xml) {
    //Parseo Arhchivo

    SAXBuilder builder = new SAXBuilder();

    try {/*from  w w  w .  j a v a2s  .c  o m*/
        //Se crea el documento a traves del archivo
        Document document = (Document) builder.build(xml);
        List elemento = document.getContent();

        //Se obtiene la raiz 'tables'
        Element rootNode = document.getRootElement();

        //Se obtiene la lista de hijos de la raiz 'tables'
        List list = rootNode.getChildren("diccionario");
        List list1 = rootNode.getChildren("dobles");

        //Se recorre la lista de hijos de 'tables'
        for (int i = 0; i < list.size(); i++) {
            //Se obtiene el elemento 'tabla'
            Element tabla = (Element) list.get(i);

            //Se obtiene el atributo 'nombre' que esta en el tag 'tabla'
            String nombreTabla = tabla.getValue();

            System.out.println("Dimension: " + nombreTabla);

            //Se obtiene la lista de hijos del tag 'tabla'
            List lista_campos = tabla.getChildren();

            //YA SE INSERTAN VALORES A LA LISTA SIMPLE PARA EL DICCIONARIO
            //Se recorre la lista de campos
            for (int j = 0; j < lista_campos.size(); j++) {
                //Se obtiene el elemento 'campo'
                Element campo = (Element) lista_campos.get(j);

                //Se obtienen los valores que estan entre los tags '<campo></campo>'
                //Se obtiene el valor que esta entre los tags '<nombre></nombre>'
                String nombre = campo.getValue();
                lista.insertarAlFrente(nombre);
                //Se obtiene el valor que esta entre los tags '<tipo></tipo>'
                String tipo = campo.getChildTextTrim("y");

                //Se obtiene el valor que esta entre los tags '<valor></valor>'
                //                String valor = campo.getChildTextTrim("valor");
                System.out.println("\t" + "x" + "\t\t" + "y");
                System.out.println("\t" + nombre + "\t\t" + tipo + "\t\t");
                System.out.println(lista.mostrarlista());
            }

        }

        Palabras();
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }
}

From source file:edu.byu.ece.rapidSmith.design.subsite.CellLibrary.java

License:Open Source License

/**
 * Reads the "family" tag from the cellLibrary.xml file and stores its value.
 * This tag is necessary to get handles to the proper site type later on in the parsing
 * process./*  w w w  .j a  v a2  s  . c  o  m*/
 * @param familyEl family element in the cellLibray.xml
 */
private void readFamilyType(Element familyEl) {

    if (familyEl == null) {
        // TODO: replace this exception with the proper exception. 
        throw new Exceptions.FileFormatException("<family> tag not found in cellLibrary.xml file");
    }

    this.familyType = FamilyType.valueOf(familyEl.getValue());
}

From source file:edu.kit.iks.CryptographicsLib.Configuration.java

License:MIT License

/**
 * Parses the values of the configuration XML.
 * @param child the current child element
 *//*  ww w  . ja va  2s  . c  o m*/
private void parseConfigElement(Element child) {
    String value = child.getValue();
    String name = child.getName();

    switch (name) {
    case "idleTimeout":
        this.idleTimeout = Integer.parseInt(value);
        break;

    case "resetTimeout":
        this.resetTimeout = Integer.parseInt(value);
        break;

    case "debugMode":
        this.debugMode = Boolean.parseBoolean(value);
        break;

    case "fullscreenMode":
        this.fullscreenMode = Boolean.parseBoolean(value);
        break;

    case "lookAndFeel":
        this.lookAndFeel = Boolean.parseBoolean(value);
        break;

    case "mouseCursor":
        this.mouseCursor = Boolean.parseBoolean(value);
        break;

    case "languageCode":
        this.languageCode = value;
        break;

    default:
        // Do not use the logger here since this happens very early
        // and the logger might not be configured yet.
        System.out.println("Unknown configuration element " + child.getName() + ". Skipping.");
        break;
    }
}

From source file:edu.ucla.loni.server.ServerUtils.java

License:Open Source License

public static String readAccessFileGroup(Element parentEle) {
    String rs = "";
    String sep = ",";

    for (Element agent : parentEle.getChildren()) {
        String agentName = agent.getValue();
        String groupAttr = agent.getAttributeValue("group");

        boolean isGroup = groupAttr.equals("true");

        if (isGroup) {
            agentName = GroupSyntax.groupnameToAgent(agentName);
        }/* w w w  .ja  v a  2 s.c  o  m*/

        rs += agentName + sep;
    }

    if (!rs.equals("")) {
        // Get rid of final separator 
        rs = rs.substring(0, rs.length() - sep.length());
    }

    return rs;
}

From source file:egovframework.rte.fdl.xml.AbstractXMLUtility.java

License:Apache License

/**
 * TextNode Update//ww  w .  j  a  v a  2s. co m
 * 
 * @param element - ? Element
 * @param list - update TextNode 
 */
public void updTextNode(Element element, List<?> list) {
    List<?> childList = element.getChildren();

    if (childList.size() != 0) {
        for (int yy = 0; yy < childList.size(); yy++) {
            Element tmp = (Element) childList.get(yy);
            for (int tt = 0; tt < list.size(); tt++) {
                SharedObject sobj = (SharedObject) list.get(tt);
                if (tmp.getValue().equals((String) sobj.getKey())) {
                    tmp.setText((String) sobj.getValue());
                    break;
                }
            }
            updTextNode(tmp, list);
        }
    } else {
        for (int tt = 0; tt < list.size(); tt++) {
            SharedObject sobj = (SharedObject) list.get(tt);
            if (element.getValue().equals((String) sobj.getKey())) {
                element.setText((String) sobj.getValue());
                break;
            }
        }
    }
}