Example usage for org.dom4j.tree DefaultElement setText

List of usage examples for org.dom4j.tree DefaultElement setText

Introduction

In this page you can find the example usage for org.dom4j.tree DefaultElement setText.

Prototype

public void setText(String text) 

Source Link

Usage

From source file:com.thoughtworks.cruise.ConfigureCruiseUsingApi.java

License:Apache License

private void user(String username, Element admins) {
    DefaultElement user = new DefaultElement("user");
    user.setText(username);
    admins.add(user);//from   ww  w  .  j a  va 2  s  . co m
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

private DefaultElement resourceElement(String resource) {
    DefaultElement resourceElement = new DefaultElement("resource");
    resourceElement.setText(resource);
    return resourceElement;
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

private DefaultElement paramElement(String parameterName, String value) {
    DefaultElement elem = new DefaultElement("param");
    elem.addAttribute("name", parameterName);
    elem.setText(value);
    return elem;/*from   w  w  w.j  ava2s .c  o m*/
}

From source file:de.codecentric.multitool.xml.XmlLibrary.java

License:Apache License

/**
 * Ersetzt das Textinhalt eines Elements.
 * /*from   www  . j a  v a2  s.  c om*/
 * @param element
 *            {@link Element}
 * @param value
 *            value
 */
private void replaceElementValue(DefaultElement element, String value) {
    element.setText(value);

}

From source file:delphsim.model.Resultado.java

License:Open Source License

/**
 * Mtodo esttico que exporta los valores obtenidos tras la simulacin al
 * formato XML./*from  ww  w  .  j  av  a 2  s  .c  om*/
 * @param destino El archivo de destino.
 * @param nombres Los nombres de las distintas columnas/funciones.
 * @param definiciones La definicin de cada columna/funcin.
 * @param temps Array con los archivos temporales de los cuales obtener los
 *              datos a exportar.
 * @param numPuntosTotal El nmero de puntos total que contienen los
 *                       archivos temporales.
 * @param numPuntosExportar El nmero de puntos que quiere obtener el usuario.
 * @throws java.io.IOException Si hubiera algn problema al crear el archivo en disco.
 */
public static void exportarComoXML(File destino, String[] nombres, String[] definiciones, File[] temps,
        long numPuntosTotal, long numPuntosExportar) throws IOException {
    // Crear el documento, el elemento 'raiz' y asignarlo
    org.dom4j.Document documento = DocumentHelper.createDocument();
    DefaultElement elementoResultado = new DefaultElement("resultado");
    documento.setRootElement(elementoResultado);

    // Creamos los bfers de lectura para leer los temporales
    BufferedReader[] buffers = new BufferedReader[temps.length];
    for (int i = 0; i < temps.length; i++) {
        buffers[i] = new BufferedReader(new FileReader(temps[i]));
    }
    // Calculamos cada cuanto tenemos que guardar un punto
    double cadaCuanto;
    if (numPuntosTotal == numPuntosExportar) {
        cadaCuanto = 1.0d;
    } else {
        cadaCuanto = new Double(numPuntosTotal) / new Double(numPuntosExportar - 1);
    }
    long siguientePuntoExportar = 0;
    long contadorNumPuntoLeido = 0;
    long contadorNumPuntosExportados = 0;
    // Comenzamos a leer los temporales aadiendo elementos al documento
    String[] valores = new String[buffers.length];
    for (int i = 0; i < buffers.length; i++) {
        valores[i] = buffers[i].readLine();
    }
    // En el momento en que se lee un null, se termina
    while (valores[0] != null) {
        // Para cada punto que haya que exportar
        if (siguientePuntoExportar == contadorNumPuntoLeido) {
            DefaultElement nuevaFila = new DefaultElement("fila");
            // Para el tiempo, nuevo elemento, su valor y aadirlo a la fila
            DefaultElement elementoTiempo = new DefaultElement("Tiempo");
            elementoTiempo.setText(valores[0]);
            nuevaFila.add(elementoTiempo);
            // Lo mismo para cada linea, pero ademas con nombre y definicin
            for (int i = 1; i < valores.length; i++) {
                DefaultElement elementoLinea = new DefaultElement("Lnea" + i);
                elementoLinea.add(new DefaultAttribute("nombre", nombres[i]));
                elementoLinea.add(new DefaultAttribute("definicion", definiciones[i]));
                elementoLinea.setText(valores[i]);
                nuevaFila.add(elementoLinea);
            }
            // Y aadimos la nueva fila
            elementoResultado.add(nuevaFila);
            // Calculamos el siguiente punto a exportar
            contadorNumPuntosExportados++;
            siguientePuntoExportar = Math.round(cadaCuanto * contadorNumPuntosExportados);
            if (siguientePuntoExportar >= numPuntosTotal) {
                siguientePuntoExportar = numPuntosTotal - 1;
            }
        }
        // Leemos la siguiente lnea de los ficheros
        for (int i = 0; i < buffers.length; i++) {
            valores[i] = buffers[i].readLine();
        }
        contadorNumPuntoLeido++;
    }
    // Cerramos los bfers y el archivo de salida
    for (int i = 0; i < buffers.length; i++) {
        buffers[i].close();
    }
    // Imprimimos el documento como XML
    OutputFormat formato = OutputFormat.createPrettyPrint();
    formato.setEncoding("UTF-16");
    formato.setIndent("\t");
    formato.setNewLineAfterDeclaration(false);
    formato.setPadText(false);
    formato.setTrimText(true);
    formato.setXHTML(true);
    OutputStreamWriter salida = new OutputStreamWriter(new FileOutputStream(destino), "UTF-16");
    XMLWriter escritor = new XMLWriter(salida, formato);
    escritor.write(documento);
    escritor.flush();
    escritor.close();
}

From source file:gjset.data.Card.java

License:Open Source License

/**
 * //from www .j  a  v a2s.c o m
 * Creates an element with the indicated tag and value.
 *
 * @param tag
 * @param value
 * @return
 */
private Element createElement(String tag, int value) {
    DefaultElement element = new DefaultElement(tag);
    element.setText("" + value);

    return element;
}

From source file:gjset.data.CardTableData.java

License:Open Source License

public Element getRepresentation() {
    DefaultElement root = new DefaultElement("cardtable");

    DefaultElement sizeElement = new DefaultElement("size");
    root.add(sizeElement);//from  w  w  w .  ja v  a  2 s . com

    //Define the table.
    DefaultElement rowsElement = new DefaultElement("rows");
    rowsElement.setText("" + gridRows);
    sizeElement.add(rowsElement);

    DefaultElement colsElement = new DefaultElement("cols");
    colsElement.setText("" + gridCols);
    sizeElement.add(colsElement);

    DefaultElement cardsElement = new DefaultElement("cards");
    root.add(cardsElement);

    //Describe each card on the table.
    for (int r = 0; r < gridRows; r++) {
        for (int c = 0; c < gridCols; c++) {
            Card card = grid[r][c];
            Element cardElement = card.getXMLRepresentation();

            if (isHighlighted(card)) {
                cardElement.addAttribute("highlighted", "true");
            }

            cardsElement.add(cardElement);
        }
    }

    return root;
}

From source file:org.jivesoftware.smack.sasl.SASLMechanism.java

License:Open Source License

private static Element createAuthEl(String name, String authenticationText) {
    if (name == null) {
        throw new NullPointerException("SASL mechanism name shouldn't be null.");
    }/*w w w.  ja va2 s  . c  o m*/
    DefaultElement authEl = new DefaultElement("auth", Namespace.get("urn:ietf:params:xml:ns:xmpp-sasl"));
    authEl.addAttribute("mechanism", name);
    if (authenticationText != null) {
        authEl.setText(authenticationText);
    }
    return authEl;
}

From source file:org.jivesoftware.smack.sasl.SASLMechanism.java

License:Open Source License

private static Element createChallengeEl(String data) {
    DefaultElement authEl = new DefaultElement("challenge", Namespace.get("urn:ietf:params:xml:ns:xmpp-sasl"));
    if (data != null) {
        authEl.setText(data);
    }/*from   w w w  . j ava2  s  .  com*/
    return authEl;
}

From source file:org.jivesoftware.smack.sasl.SASLMechanism.java

License:Open Source License

private static Element createResponseEl(String authenticationText) {
    DefaultElement authEl = new DefaultElement("response", Namespace.get("urn:ietf:params:xml:ns:xmpp-sasl"));
    if (authenticationText != null && !authenticationText.isEmpty()) {
        authEl.setText(authenticationText);
    }/*w  w w  . ja  va2s . c  o  m*/
    return authEl;
}