Example usage for org.dom4j Element addText

List of usage examples for org.dom4j Element addText

Introduction

In this page you can find the example usage for org.dom4j Element addText.

Prototype

Element addText(String text);

Source Link

Document

Adds a new Text node with the given text to this element.

Usage

From source file:tokyo.northside.jrst.JRSTLexer.java

License:Open Source License

/**
 * .. comment/* w w w.  ja  v  a  2 s  .  co m*/
 * 
 * @return Element
 * @throws IOException
 */
private Element peekComment() throws IOException {
    beginPeek();
    Element result = null;
    String line = in.readLine();
    if (line != null) {
        if (line.matches("^\\.\\.\\s+.*$")) {
            result = DocumentHelper.createElement(COMMENT);
            result.addAttribute(LEVEL, "0");
            result.addAttribute(XMLSPACE, "preserve");

            // first line is part of comment
            result.setText(line.substring(2).trim());
            line = in.readLine();
            if (line != null) {
                int level = level(line);
                if (level > 0) {
                    String[] lines = readBlock(level);
                    String text = line.substring(level);
                    for (String l : lines) {
                        text += "\n" + l.substring(level);
                    }
                    result.addText(text);
                }
            }
        }
    }

    endPeek();
    return result;
}

From source file:us.wthr.jdem846.kml.LinearRing.java

License:Apache License

protected void loadKmlChildren(Element element) {
    super.loadKmlChildren(element);

    StringBuffer coordsBuffer = new StringBuffer();
    for (Coordinate coordinate : coordinates) {
        coordsBuffer.append(coordinate.toString() + "\r\n");
    }/* ww w .ja  v  a 2  s  .  co  m*/

    Element coordsElement = element.addElement("coordinates");
    coordsElement.addText(coordsBuffer.toString());
}

From source file:us.wthr.jdem846.project.XmlProjectFileWriter.java

License:Apache License

public static Document createDocument(ProjectModel projectModel) {
    Document document = DocumentHelper.createDocument();
    Element jdem846 = document.addElement("jdem846");
    jdem846.addAttribute("spec-version", DemConstants.APPLICATION_SPEC_VERSION);
    jdem846.addAttribute("generated", "" + (new Date(System.currentTimeMillis())));

    Element project = jdem846.addElement("project");

    if (projectModel.getProjectType() != null) {
        Element projectType = project.addElement("type");
        projectType.addText(projectModel.getProjectType().identifier());
    }// w  w w .  ja  v a  2  s .  c om

    Element options = project.addElement("options");

    for (String key : projectModel.getOptionKeys()) {
        String value = projectModel.getOption(key);
        if (value != null) {

            Element element = options.addElement("option");
            element.addAttribute("key", key);
            element.addCDATA(value);

        }
    }

    Element scripting = project.addElement("scripting");
    if (projectModel.getScriptLanguage() != null) {
        scripting.addElement("language").addText(projectModel.getScriptLanguage().text());
    }

    if (projectModel.getUserScript() != null) {
        Element script = scripting.addElement("script");
        script.addCDATA(projectModel.getUserScript());
    }

    Element inputFiles = project.addElement("input-files");
    for (String inputFile : projectModel.getInputFiles()) {
        inputFiles.addElement("input").addText(inputFile);
    }

    for (ShapeFileReference shapeFileRequest : projectModel.getShapeFiles()) {

        Element shapeFileElement = inputFiles.addElement("shapefile");
        shapeFileElement.addElement("path").addText(shapeFileRequest.getPath());
        if (shapeFileRequest.getShapeDataDefinitionId() != null) {
            shapeFileElement.addElement("data-definition-id")
                    .addText(shapeFileRequest.getShapeDataDefinitionId());
        }

    }

    return document;

}

From source file:zutil.net.ws.soap.SOAPHttpPage.java

License:Open Source License

/**
 * Generates a XML Element for a given Object. This method can
 * handle return values as XML Elements, WSReturnObject and
 * Java basic data types./* ww w.ja va  2  s .  c o m*/
 * 
 * @param      root       is the parent Element
 * @param       obj       is the object that is the return value
 * @param       elementName       is the name of the parent Element
 */
protected static void generateSOAPXMLForObj(Element root, Object obj, String elementName)
        throws IllegalArgumentException, IllegalAccessException {
    if (obj == null)
        return;
    if (byte[].class.isAssignableFrom(obj.getClass())) {
        Element valueE = root.addElement(elementName);
        valueE.addAttribute("type", "xsd:" + getSOAPClassName(obj.getClass()));
        String tmp = Base64Encoder.encode((byte[]) obj);
        tmp = tmp.replaceAll("\\s", "");
        valueE.setText(tmp);
    }
    // return an array
    else if (obj.getClass().isArray()) {
        Element array = root.addElement((elementName.equals("element") ? "Array" : elementName));
        String arrayType = "xsd:" + getSOAPClassName(obj.getClass());
        arrayType = arrayType.replaceFirst("\\[\\]", "[" + Array.getLength(obj) + "]");

        array.addAttribute("type", "soap:Array");
        array.addAttribute("soap:arrayType", arrayType);
        for (int i = 0; i < Array.getLength(obj); i++) {
            generateSOAPXMLForObj(array, Array.get(obj, i), "element");
        }
    } else {
        Element objectE = root.addElement(elementName);
        if (obj instanceof Element)
            objectE.add((Element) obj);
        else if (obj instanceof WSReturnObject) {
            Field[] fields = obj.getClass().getFields();
            for (int i = 0; i < fields.length; i++) {
                WSValueName tmp = fields[i].getAnnotation(WSValueName.class);
                String name;
                if (tmp != null)
                    name = tmp.value();
                else
                    name = "field" + i;
                generateSOAPXMLForObj(objectE, fields[i].get(obj), name);
            }
        } else {
            objectE.addAttribute("type", "xsd:" + getSOAPClassName(obj.getClass()));
            objectE.addText("" + obj);
        }
    }
}