Example usage for org.w3c.dom Document createTextNode

List of usage examples for org.w3c.dom Document createTextNode

Introduction

In this page you can find the example usage for org.w3c.dom Document createTextNode.

Prototype

public Text createTextNode(String data);

Source Link

Document

Creates a Text node given the specified string.

Usage

From source file:de.crowdcode.movmvn.plugin.general.GeneralPlugin.java

private void createPomProperties(Document doc, Element rootElement) {
    Element properties = doc.createElement("properties");
    rootElement.appendChild(properties);

    Element projectBuildSourceEncoding = doc.createElement("project.build.sourceEncoding");
    projectBuildSourceEncoding.appendChild(doc.createTextNode("UTF-8"));
    properties.appendChild(projectBuildSourceEncoding);
}

From source file:edu.ur.ir.ir_export.service.DefaultCollectionExportService.java

/**
 * Add the id element./*  w  w w.java2 s.com*/
 * 
 * @param parent - parent element
 * @param id - id value
 * @param doc - document element
 */
private void addIdElement(Element parent, String id, Document doc) {
    Element idVal = doc.createElement("id");
    Text data = doc.createTextNode(id);
    idVal.appendChild(data);
    parent.appendChild(idVal);
}

From source file:it.greenvulcano.gvesb.virtual.http.HTTPCallOperation.java

private void dumpPart(Part p, Element msg, Document doc) throws Exception {
    Element content = null;/* w w w  .j av  a  2s.  com*/
    if (p.isMimeType("text/plain")) {
        content = doc.createElement("PlainMessage");
        Text body = doc.createTextNode((String) p.getContent());
        content.appendChild(body);
    } else if (p.isMimeType("text/html")) {
        content = doc.createElement("HTMLMessage");
        CDATASection body = doc.createCDATASection((String) p.getContent());
        content.appendChild(body);
    } else if (p.isMimeType("multipart/*")) {
        Multipart mp = (Multipart) p.getContent();
        int count = mp.getCount();
        content = doc.createElement("Multipart");
        for (int i = 0; i < count; i++) {
            dumpPart(mp.getBodyPart(i), content, doc);
        }
    } else if (p.isMimeType("message/rfc822")) {
        content = doc.createElement("NestedMessage");
        dumpPart((Part) p.getContent(), content, doc);
    } else {
        content = doc.createElement("EncodedContent");
        DataHandler dh = p.getDataHandler();
        OutputStream os = new ByteArrayOutputStream();
        Base64EncodingOutputStream b64os = new Base64EncodingOutputStream(os);
        dh.writeTo(b64os);
        b64os.flush();
        b64os.close();
        content.appendChild(doc.createTextNode(os.toString()));
    }
    msg.appendChild(content);
    String filename = p.getFileName();
    if (filename != null) {
        content.setAttribute("file-name", filename);
    }
    String ct = p.getContentType();
    if (ct != null) {
        content.setAttribute("content-type", ct);
    }
    String desc = p.getDescription();
    if (desc != null) {
        content.setAttribute("description", desc);
    }
}

From source file:Main.java

/**
 * Convenience method to copy the contents of the old {@link Node} into the
 * new one./* ww  w  . j  a va 2s.c  om*/
 * 
 * @param newDoc
 * @param newNode
 * @param oldParent
 */
public static void copyContents(Document newDoc, Node newNode, Node oldNode) {
    // FIXME we should be able to achieve this with much less code (e.g.
    // the code commented out) but for some reason there are
    // incompatibility issues being spat out by the tests.
    //      final NodeList childNodes = oldNode.getChildNodes();
    //        for (int i = 0; i < childNodes.getLength(); i++) {
    //           final Node child = newDoc.importNode(childNodes.item(i), true);
    //           newNode.appendChild(child);
    //        }

    final NodeList childs = oldNode.getChildNodes();

    for (int i = 0; i < childs.getLength(); i++) {
        final Node child = childs.item(i);
        Element newElem = null;
        switch (child.getNodeType()) {
        case Node.ELEMENT_NODE:
            //Get all the attributes of an element in a map
            final NamedNodeMap attrs = child.getAttributes();

            // Process each attribute
            newElem = newDoc.createElement(child.getNodeName());
            for (int j = 0; j < attrs.getLength(); j++) {
                final Attr attr = (Attr) attrs.item(j);
                // add attribute name and value to the new element
                newElem.setAttribute(attr.getNodeName(), attr.getNodeValue());
            }
            newNode.appendChild(newElem);
            break;

        case Node.TEXT_NODE:
            newNode.appendChild(newDoc.createTextNode(getString(child)));
        }
        copyContents(newDoc, newElem, child);
    }
}

From source file:edu.ur.ir.ir_export.service.DefaultCollectionExportService.java

/**
 * Add the name element.//  w w w  .  j av a2 s .  c  om
 * 
 * @param parent - parent element to add the name to
 * @param name - name value to add
 * @param doc - document element
 */
private void addNameElement(Element parent, String name, Document doc) {
    Element nameVal = doc.createElement("name");
    Text data = doc.createTextNode(name);
    nameVal.appendChild(data);
    parent.appendChild(nameVal);
}

From source file:org.getwheat.harvest.library.dom.DomHelper.java

/**
 * Adds an {@link Element} to the parent if the value is not null.
 * //from w w  w.  j a v  a2s.  com
 * @param document
 * @param parent
 * @param tag
 * @param value
 * @return the created {@link Element}
 */
public Element addElement(final Document document, final Element parent, final XmlTag tag, final String value) {
    Element element = null;
    if (value != null) {
        element = document.createElement(tag.getElementName());
        element.appendChild(document.createTextNode(value));
        parent.appendChild(element);
    }
    return element;
}

From source file:edu.ur.ir.ir_export.service.DefaultCollectionExportService.java

/**
 * Add the image.//from   w  ww  .j a  v  a  2 s  . com
 * 
 * @param parent
 * @param imageName
 * @param doc
 */
private void addImage(Element parent, String imageName, Document doc) {
    Element picture = doc.createElement("picture");
    Text data = doc.createTextNode(imageName);
    picture.appendChild(data);
    parent.appendChild(picture);
}

From source file:edu.ur.ir.ir_export.service.DefaultCollectionExportService.java

/**
 * Add the copyright value.//w  ww  . jav  a 2  s.co m
 * 
 * @param parent
 * @param copyrightVal
 * @param doc
 */
private void addCopyright(Element parent, String copyrightVal, Document doc) {
    Element copyright = doc.createElement("copyright");
    Text data = doc.createTextNode(copyrightVal);
    copyright.appendChild(data);
    parent.appendChild(copyright);
}

From source file:edu.ur.ir.ir_export.service.DefaultCollectionExportService.java

/**
 * Add the description//  w  w w. ja  v a  2  s. c  om
 * 
 * @param parent
 * @param introText
 * @param doc
 */
private void addDescription(Element parent, String introText, Document doc) {
    Element introductoryText = doc.createElement("description");
    Text data = doc.createTextNode(introText);
    introductoryText.appendChild(data);
    parent.appendChild(introductoryText);
}

From source file:org.callimachusproject.xproc.Pipeline.java

private void appendBase64(InputStream source, Document doc, Element data) throws IOException {
    byte bytes[] = new byte[bufSize];
    int pos = 0;/*from  w  ww . ja va  2  s  .c om*/
    int readLen = bufSize;
    int len = source.read(bytes, 0, bufSize);
    while (len >= 0) {
        pos += len;
        readLen -= len;
        if (readLen == 0) {
            data.appendChild(doc.createTextNode(Base64.encodeBytes(bytes)));
            pos = 0;
            readLen = bufSize;
        }

        len = source.read(bytes, pos, readLen);
    }

    if (pos > 0) {
        byte lastBytes[] = new byte[pos];
        System.arraycopy(bytes, 0, lastBytes, 0, pos);
        data.appendChild(doc.createTextNode(Base64.encodeBytes(lastBytes)));
    }
}