Example usage for org.jdom2 Element setText

List of usage examples for org.jdom2 Element setText

Introduction

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

Prototype

public Element setText(final String text) 

Source Link

Document

Sets the content of the element to be the text given.

Usage

From source file:ca.nrc.cadc.vosi.TableSet.java

License:Open Source License

private Element addChild(Element eleParent, String chdName, String chdText) {
    Element ele = null;
    if (chdText != null && !chdText.equals("")) {
        ele = new Element(chdName);
        ele.setText(chdText);
        eleParent.addContent(ele);/*w w w. ja v a 2 s.com*/
    }
    return ele;
}

From source file:ca.nrc.cadc.vosi.util.Util.java

License:Open Source License

public static Element addChild(Element ele0, Namespace ns, String chdName, String chdText) {
    Element ele = null;
    if (chdText != null && !chdText.equals("")) {
        if (ns != null)
            ele = new Element(chdName, ns);
        else//from   www . j  av  a 2 s. c o  m
            ele = new Element(chdName);
        ele.setText(chdText);
        ele0.addContent(ele);
    }
    return ele;
}

From source file:ca.nrc.cadc.xml.JsonInputter.java

License:Open Source License

private void processObject(String key, Object value, Element element, Namespace namespace,
        List<Namespace> namespaces) throws JSONException {
    if (value == null) {
        return;/*from w  w w.j a va2 s.  c  om*/
    }

    if (listElementMap.containsKey(key)) {
        final Object childObject = ((JSONObject) value).get("$");
        //        ((JSONObject) value).get(listElementMap.get(key));

        if (childObject instanceof JSONArray) {
            processJSONArray(key, (JSONArray) childObject, element, namespace, namespaces);
        } else if (childObject instanceof JSONObject) {
            processJSONObject((JSONObject) childObject, element, namespaces);
        }
    } else if (value instanceof JSONObject) {
        processJSONObject((JSONObject) value, element, namespaces);
    } else {
        element.setText(getStringValue(value));
    }
}

From source file:ca.nrc.cadc.xml.JsonInputter.java

License:Open Source License

private void processJSONObject(JSONObject jsonObject, Element element, List<Namespace> namespaces)
        throws JSONException {
    List<String> keys = Arrays.asList(JSONObject.getNames(jsonObject));
    Namespace namespace = getNamespace(namespaces, jsonObject, keys);
    if (namespace == null) {
        namespace = element.getNamespace();
    }//from   w  ww .  ja v  a 2 s. com

    for (String key : keys) {
        if (jsonObject.isNull(key)) {
            continue;
        }

        // attribute
        if (key.startsWith("@")) {
            Object value = jsonObject.get(key);
            element.setAttribute(new Attribute(key.substring(1), getStringValue(value)));
            continue;
        }

        // text content
        Object value = jsonObject.get(key);
        if (key.equals("$")) {
            element.setText(getStringValue(value));
            continue;
        }

        Element child = new Element(key, namespace);
        if (listElementMap.containsKey(key)) {
            final String childKey = listElementMap.get(key);
            final Object childObject = ((JSONObject) value).get("$");
            Element grandChild = new Element(childKey, namespace);

            if (childObject instanceof JSONArray) {
                processJSONArray(key, (JSONArray) childObject, child, namespace, namespaces);
            } else if (childObject instanceof JSONObject) {
                processJSONObject((JSONObject) childObject, grandChild, namespaces);
                child.addContent(grandChild);
            }
        } else if (value instanceof JSONObject) {
            processJSONObject((JSONObject) value, child, namespaces);
        }

        element.addContent(child);
    }
}

From source file:ch.rotscher.maven.plugins.InstallWithVersionOverrideMojo.java

License:Apache License

private void replaceVersion(File originalPomFile, File newPomFile, String newVersion)
        throws IOException, JDOMException {

    //we assume that the version of "internal" dependencies are declared with ${project.version}
    FileWriter writer = new FileWriter(newPomFile);
    SAXBuilder parser = new SAXBuilder();
    XMLOutputter xmlOutput = new XMLOutputter();
    // display nice nice
    xmlOutput.setFormat(Format.getPrettyFormat());

    //parse the document
    Document doc = parser.build(originalPomFile);
    Element versionElem = findVersionElement(doc);
    versionElem.setText(newVersion);
    xmlOutput.output(doc, writer);/* w  w w .j  a  va  2 s  .c  om*/
    writer.flush();
    writer.close();
}

From source file:com.archimatetool.canvas.templates.wizard.SaveCanvasAsTemplateWizard.java

License:Open Source License

private String createManifest() throws IOException {
    Document doc = new Document();
    Element root = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_MANIFEST);
    doc.setRootElement(root);//w w w  .  ja  v  a  2  s  .c o m

    // Type
    root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE,
            CanvasModelTemplate.XML_CANVAS_TEMPLATE_ATTRIBUTE_TYPE_MODEL);

    // Timestamp
    root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TIMESTAMP,
            Long.toString(System.currentTimeMillis()));

    // Name
    Element elementName = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_NAME);
    elementName.setText(fTemplateName);
    root.addContent(elementName);

    // Description
    Element elementDescription = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_DESCRIPTION);
    elementDescription.setText(fTemplateDescription);
    root.addContent(elementDescription);

    // Thumbnail
    if (fIncludeThumbnail) {
        String keyThumb = TemplateManager.ZIP_ENTRY_THUMBNAILS + "1.png"; //$NON-NLS-1$
        Element elementKeyThumb = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_KEY_THUMBNAIL);
        elementKeyThumb.setText(keyThumb);
        root.addContent(elementKeyThumb);
    }

    return JDOMUtils.write2XMLString(doc);
}

From source file:com.archimatetool.templates.impl.wizard.SaveArchimateModelAsTemplateWizard.java

License:Open Source License

private String createManifest() throws IOException {
    Document doc = new Document();
    Element root = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_MANIFEST);
    doc.setRootElement(root);/*from   w  w w. ja v  a  2 s .  c  om*/

    // Type
    root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE,
            ArchimateModelTemplate.XML_TEMPLATE_ATTRIBUTE_TYPE_MODEL);

    // Timestamp
    root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TIMESTAMP,
            Long.toString(System.currentTimeMillis()));

    // Name
    Element elementName = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_NAME);
    elementName.setText(fTemplateName);
    root.addContent(elementName);

    // Description
    Element elementDescription = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_DESCRIPTION);
    elementDescription.setText(fTemplateDescription);
    root.addContent(elementDescription);

    // Thumbnails
    if (fIncludeThumbnails) {
        if (fSelectedDiagramModel != null) {
            int i = 1;
            for (IDiagramModel dm : fModel.getDiagramModels()) {
                if (dm == fSelectedDiagramModel) {
                    String keyThumb = TemplateManager.ZIP_ENTRY_THUMBNAILS + i + ".png"; //$NON-NLS-1$
                    Element elementKeyThumb = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_KEY_THUMBNAIL);
                    elementKeyThumb.setText(keyThumb);
                    root.addContent(elementKeyThumb);
                    break;
                }
                i++;
            }
        }
    }

    return JDOMUtils.write2XMLString(doc);
}

From source file:com.archimatetool.templates.model.AbstractTemplate.java

License:Open Source License

@Override
public void save() throws IOException {
    if (fFile == null || !fFile.exists()) {
        return;// w  w w .  j a  v  a2  s.co m
    }

    // Manifest
    Document doc = new Document();
    Element root = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_MANIFEST);
    doc.setRootElement(root);

    Element elementName = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_NAME);
    elementName.setText(getName());
    root.addContent(elementName);

    Element elementDescription = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_DESCRIPTION);
    elementDescription.setText(getDescription());
    root.addContent(elementDescription);

    if (fKeyThumbnailPath != null) {
        Element elementKeyThumb = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_KEY_THUMBNAIL);
        elementKeyThumb.setText(fKeyThumbnailPath);
        root.addContent(elementKeyThumb);
    }

    String manifest = JDOMUtils.write2XMLString(doc);

    // Model
    String model = ZipUtils.extractZipEntry(fFile, TemplateManager.ZIP_ENTRY_MODEL);

    // Start a zip stream
    File tmpFile = File.createTempFile("architemplate", null); //$NON-NLS-1$
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tmpFile));
    ZipOutputStream zOut = new ZipOutputStream(out);

    ZipUtils.addStringToZip(manifest, TemplateManager.ZIP_ENTRY_MANIFEST, zOut);
    ZipUtils.addStringToZip(model, TemplateManager.ZIP_ENTRY_MODEL, zOut);

    // Thumbnails
    Image[] images = getThumbnails();
    int i = 1;
    for (Image image : images) {
        ZipUtils.addImageToZip(image, TemplateManager.ZIP_ENTRY_THUMBNAILS + i++ + ".png", zOut, SWT.IMAGE_PNG, //$NON-NLS-1$
                null);
    }

    zOut.flush();
    zOut.close();

    // Delete and copy
    fFile.delete();
    FileUtils.copyFile(tmpFile, fFile, false);
    tmpFile.delete();
}

From source file:com.astronomy.project.Declination.java

/**
 * //from w  w w.j  av a 2 s.  co  m
 * @return XML element for declination
 */
public Element getElementoXML() {
    Element raiz = new Element("declinacion");
    raiz.setText(String.format("%.1f", this.getSignedValue()).replace(",", "."));
    return raiz;
}

From source file:com.astronomy.project.Orientation.java

/**
 * //  ww  w.j  a v  a 2  s  . c om
 * @return XML element for orientation
 */
public Element getXMLElement() {
    Element raiz = new Element("direccion");
    Element acimutElemento = new Element("acimut");
    acimutElemento.setText(String.valueOf(getAzimuth().getSignedValue()));
    Element elevacionElemento = new Element("elevacion");
    elevacionElemento.setText(String.valueOf(getAltitude().getSignedValue()));
    raiz.addContent(acimutElemento);
    raiz.addContent(elevacionElemento);
    return raiz;
}