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:edu.ur.ir.ir_export.service.DefaultCollectionExportService.java

/**
 * Add the primary image element//from   w  w  w  .  j  a va 2s  . c o  m
 * 
 * @param parent
 * @param imageName
 * @param doc
 */
private void addPrimaryImage(Element parent, String imageName, Document doc) {
    Element primaryPicture = doc.createElement("primary_picture");
    Text data = doc.createTextNode(imageName);
    primaryPicture.appendChild(data);
    parent.appendChild(primaryPicture);
}

From source file:com.krawler.esp.utils.ConfigReader.java

/** Writes non-default properties in this configuration. */
public void write(OutputStream out) throws IOException {
    Properties properties = getProps();
    try {//www  . j a v a2 s .  c  o m
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element conf = doc.createElement("krawler-conf");
        doc.appendChild(conf);
        conf.appendChild(doc.createTextNode("\n"));
        for (Enumeration e = properties.keys(); e.hasMoreElements();) {
            String name = (String) e.nextElement();
            String value = (String) properties.get(name);

            Element propNode = doc.createElement("property");
            conf.appendChild(propNode);

            Element nameNode = doc.createElement("name");
            nameNode.appendChild(doc.createTextNode(name));
            propNode.appendChild(nameNode);

            Element valueNode = doc.createElement("value");
            valueNode.appendChild(doc.createTextNode(value));
            propNode.appendChild(valueNode);

            conf.appendChild(doc.createTextNode("\n"));
        }

        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(out);
        TransformerFactory transFactory = TransformerFactory.newInstance();
        Transformer transformer = transFactory.newTransformer();
        transformer.transform(source, result);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:net.sourceforge.eclipsetrader.core.internal.TradingSystemRepository.java

private void saveGroup(TradingSystemGroup group, Document document, Element root) {
    Element element = document.createElement("group"); //$NON-NLS-1$
    element.setAttribute("id", String.valueOf(group.getId())); //$NON-NLS-1$
    root.appendChild(element);//  w  w  w . java  2 s  . co  m

    Element node = document.createElement("description"); //$NON-NLS-1$
    node.appendChild(document.createTextNode(group.getDescription()));
    element.appendChild(node);

    for (Iterator iter = group.getGroups().iterator(); iter.hasNext();) {
        TradingSystemGroup grp = (TradingSystemGroup) iter.next();
        saveGroup(grp, document, element);
    }

    for (Iterator iter = group.getTradingSystems().iterator(); iter.hasNext();) {
        TradingSystem system = (TradingSystem) iter.next();
        saveSystem(system, document, element);
    }
}

From source file:com.marklogic.client.functionaltest.TestBulkSearchEWithQBE.java

public void loadXMLDocuments()
        throws IOException, ParserConfigurationException, SAXException, TransformerException {
    int count = 1;
    XMLDocumentManager docMgr = client.newXMLDocumentManager();
    DocumentWriteSet writeset = docMgr.newWriteSet();
    for (int i = 0; i < 102; i++) {
        Document doc = this.getDocumentContent("This is so foo with a bar " + i);
        Element childElement = doc.createElement("author");
        childElement.appendChild(doc.createTextNode("rhiea"));
        doc.getElementsByTagName("foo").item(0).appendChild(childElement);
        writeset.add(DIRECTORY + "foo" + i + ".xml", new DOMHandle(doc));

        if (count % BATCH_SIZE == 0) {
            docMgr.write(writeset);//ww w  . j  av a  2s.c  om
            writeset = docMgr.newWriteSet();
        }
        count++;
    }
    if (count % BATCH_SIZE > 0) {
        docMgr.write(writeset);
    }
}

From source file:XsltDomServlet.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    Document doc = dom.createDocument("", "parameters", null);
    Element parameters = doc.getDocumentElement();

    parameters.setAttribute("title", "XSLT DOM Servlet");
    Enumeration parameterNames = request.getParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameterName = parameterNames.nextElement().toString();
        Element parameter = doc.createElement("parameter");
        parameters.appendChild(parameter);
        parameter.setAttribute("name", parameterName);
        parameter.appendChild(doc.createTextNode(request.getParameter(parameterName)));
    }//from  w w w.ja  v a 2 s .c o m

    DOMSource domSource = new DOMSource(doc);
    StreamResult streamResult = new StreamResult(response.getWriter());

    try {
        transformer.transform(domSource, streamResult);
    } catch (TransformerException te) {
        throw new ServletException(te);
    }
}

From source file:com.twinsoft.convertigo.engine.util.XMLUtils.java

public static NodeList asNodeList(String... strings) {
    Document doc = getDefaultDocumentBuilder().newDocument();
    Element root = doc.createElement("root");
    for (String string : strings) {
        root.appendChild(doc.createTextNode(string));
    }/*from  ww  w.j  a  va  2s . c o  m*/
    return root.getChildNodes();
}

From source file:me.uni.sushilkumar.geodine.util.YummlyLookup.java

/** 
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 * @param request servlet request/*  ww  w.  j  a  v a  2 s.co  m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, ParseException {
    response.setContentType("text/xml");
    PrintWriter out = response.getWriter();
    DBConnection con = null;
    try {

        String cuisine = request.getParameter("cuisine");
        con = new DBConnection();
        CuisineObject obj = con.getCuisineData(cuisine);
        int id = obj.getId();
        String cuisineId = obj.getCuisineId();
        String country = obj.getCountry();
        String ytid = obj.getYtid();

        ArrayList<String> directions = obj.getDirections();
        ArrayList<String> ingredients = obj.getIngredients();
        HttpSession session = request.getSession(true);
        String email = (String) session.getAttribute("userName");
        boolean isFav = con.isFavourite(cuisineId, email);
        String fav = "";
        if (isFav)
            fav = "true";
        else
            fav = "false";
        DocumentBuilderFactory docFactory = null;
        DocumentBuilder docBuilder = null;
        Document xmlDoc = null;
        Element root = null;
        docFactory = DocumentBuilderFactory.newInstance();
        docBuilder = docFactory.newDocumentBuilder();
        xmlDoc = docBuilder.newDocument();
        root = xmlDoc.createElement("item");
        xmlDoc.appendChild(root);

        Element eid = xmlDoc.createElement("id");
        eid.appendChild(xmlDoc.createTextNode(Integer.toString(id)));
        root.appendChild(eid);

        Element eisfav = xmlDoc.createElement("favourite");
        eisfav.appendChild(xmlDoc.createTextNode(fav));
        root.appendChild(eisfav);

        Element ecuisineId = xmlDoc.createElement("cuisine-id");
        ecuisineId.appendChild(xmlDoc.createTextNode(cuisineId));
        root.appendChild(ecuisineId);

        Element ecountry = xmlDoc.createElement("country");
        ecountry.appendChild(xmlDoc.createTextNode(country));
        root.appendChild(ecountry);

        Element eytid = xmlDoc.createElement("ytid");
        eytid.appendChild(xmlDoc.createTextNode(ytid));
        root.appendChild(eytid);

        Element edirections = xmlDoc.createElement("steps");
        for (int i = 0; i < directions.size(); i++) {
            Element temp = xmlDoc.createElement("step");
            temp.appendChild(xmlDoc.createTextNode(directions.get(i)));
            edirections.appendChild(temp);
        }
        root.appendChild(edirections);

        Element eingredients = xmlDoc.createElement("ingredients");
        for (int i = 0; i < ingredients.size(); i++) {
            Element temp = xmlDoc.createElement("ingredient");
            temp.appendChild(xmlDoc.createTextNode(ingredients.get(i)));
            eingredients.appendChild(temp);
        }
        root.appendChild(eingredients);

        StringWriter sw = new StringWriter();
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        //transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(xmlDoc);
        StreamResult result = new StreamResult(sw);
        transformer.transform(source, result);
        out.println(sw.toString());
        if (email != null) {
            con.addRecentCuisine(cuisineId, email, new Date().toString());
        }

    } catch (TransformerException ex) {
        Logger.getLogger(YummlyLookup.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(YummlyLookup.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        out.close();
        if (con != null) {
            con.close();
        }
    }
}

From source file:com.microsoft.windowsazure.messaging.Registration.java

/**
 * Appends a node with a value to a registration xml
 * @param doc   The document to modify//  w  w w.jav  a 2  s .com
 * @param targetElement   The parent element
 * @param nodeName   The node name
 * @param value   The node value
 */
protected void appendNodeWithValue(Document doc, Element targetElement, String nodeName, String value) {
    if (!isNullOrWhiteSpace(value)) {
        Element newElement = doc.createElement(nodeName);
        newElement.appendChild(doc.createTextNode(value));
        targetElement.appendChild(newElement);
    }
}

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

/**
 * Add the link /*from w  ww . ja  va  2  s.co m*/
 * 
 * @param parent - parent element
 * @param l - link to add
 * @param doc - document 
 */
private void addLink(Element parent, InstitutionalCollectionLink l, Document doc) {
    Element link = doc.createElement("link");

    //name
    Element linkName = doc.createElement("name");
    Text data = doc.createTextNode(l.getName());
    linkName.appendChild(data);
    link.appendChild(linkName);

    // url
    Element linkUrl = doc.createElement("url");
    data = doc.createTextNode(l.getUrl());
    linkUrl.appendChild(data);
    link.appendChild(linkUrl);

    //desc
    Element linkDescription = doc.createElement("description");
    data = doc.createTextNode(l.getDescription());
    linkDescription.appendChild(data);
    link.appendChild(linkDescription);

    Element linkId = doc.createElement("id");
    data = doc.createTextNode(l.getId().toString());
    linkId.appendChild(data);
    link.appendChild(linkId);

    parent.appendChild(link);
}

From source file:com.xinferin.licensing.LicenceGenerator.java

/**
 * Gets an RSA Public key as an xml document
 * //  ww  w  .  ja v a  2s.  c  o  m
 * @param key
 * @return
 * @throws ParserConfigurationException
 * @throws UnsupportedEncodingException
 */
private Document getRSAPublicKeyAsXML(RSAPublicKey key)
        throws ParserConfigurationException, UnsupportedEncodingException {

    Document result = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    Element rsaKeyValue = result.createElement("RSAKeyValue");
    result.appendChild(rsaKeyValue);

    Element modulus = result.createElement("Modulus");
    rsaKeyValue.appendChild(modulus);

    byte[] modulusBytes = key.getModulus().toByteArray();
    modulusBytes = stripLeadingZeros(modulusBytes);
    modulus.appendChild(result.createTextNode(new String(Base64.encodeBase64(modulusBytes))));

    Element exponent = result.createElement("Exponent");
    rsaKeyValue.appendChild(exponent);

    byte[] exponentBytes = key.getPublicExponent().toByteArray();
    exponent.appendChild(result.createTextNode(new String(Base64.encodeBase64(exponentBytes))));

    return result;
}