Example usage for com.google.gwt.xml.client Document createTextNode

List of usage examples for com.google.gwt.xml.client Document createTextNode

Introduction

In this page you can find the example usage for com.google.gwt.xml.client Document createTextNode.

Prototype

Text createTextNode(String data);

Source Link

Document

This method creates a new Text.

Usage

From source file:client.serializers.XMLSeriesSerializer.java

License:Open Source License

/**
 * Serialize to XML.// ww  w. ja  va  2 s  .  c o m
 */
@Override
public String serialize(SortedSet<Integer> years, List<SeriesManager.Row> rows) {

    Document document = XMLParser.createDocument();

    Element documentElement = document.createElement(ROOT);
    document.appendChild(documentElement);

    for (SeriesManager.Row row : rows) {
        Element rowElement = document.createElement(COUNTRY);

        Series series = row.getSeries();

        Country country = series.getCountry();
        if (country != null) {
            rowElement.setAttribute(COUNTRY_NAME, country.getName());
            rowElement.setAttribute(COUNTRY_ISO, country.getISO());
        }

        List<Point> points = series.getPoints();
        if (points != null) {
            for (Point point : points) {
                Element pointElement = document.createElement(POINT);

                pointElement.setAttribute(POINT_YEAR, point.getYear() + "");
                pointElement.appendChild(
                        document.createTextNode((Double) (((int) (point.getValue() * RES)) / RES) + ""));

                rowElement.appendChild(pointElement);
            }
        }

        documentElement.appendChild(rowElement);
    }

    return document.toString();
}

From source file:com.fredhat.gwt.xmlrpc.client.XmlRpcClient.java

License:Open Source License

private Document buildRequest(String methodName, Object[] params) {
    Document request = XMLParser.createDocument();
    Element methodCall = request.createElement("methodCall");
    {//from  w  ww.  j  a v  a  2  s  . com
        Element methodNameElem = request.createElement("methodName");
        methodNameElem.appendChild(request.createTextNode(methodName));
        methodCall.appendChild(methodNameElem);
    }
    {
        Element paramsElem = request.createElement("params");
        for (int i = 0; i < params.length; i++) {
            Element paramElem = request.createElement("param");
            paramElem.appendChild(buildValue(params[i]));
            paramsElem.appendChild(paramElem);

        }
        methodCall.appendChild(paramsElem);
    }
    request.appendChild(methodCall);

    return request;
}

From source file:com.fredhat.gwt.xmlrpc.client.XmlRpcClient.java

License:Open Source License

private Element buildValue(Object param) {
    Document doc = XMLParser.createDocument();
    Element valueElem = doc.createElement("value");

    if (param == null) {
        Element nilElem = doc.createElement("nil");
        valueElem.appendChild(nilElem);//  ww w .  j  a  v  a 2s .  c om
    } else if (param instanceof Integer) {
        Element intElem = doc.createElement("int");
        intElem.appendChild(doc.createTextNode(param.toString()));
        valueElem.appendChild(intElem);
    } else if (param instanceof Boolean) {
        Element boolElem = doc.createElement("boolean");
        boolean b = ((Boolean) param).booleanValue();
        if (b)
            boolElem.appendChild(doc.createTextNode("1"));
        else
            boolElem.appendChild(doc.createTextNode("0"));
        valueElem.appendChild(boolElem);
    } else if (param instanceof String) {
        Element stringElem = doc.createElement("string");
        stringElem.appendChild(doc.createTextNode(param.toString()));
        valueElem.appendChild(stringElem);
    } else if (param instanceof Double) {
        Element doubleElem = doc.createElement("double");
        doubleElem.appendChild(doc.createTextNode(param.toString()));
        valueElem.appendChild(doubleElem);
    } else if (param instanceof com.fredhat.gwt.xmlrpc.client.Date) {
        com.fredhat.gwt.xmlrpc.client.Date date = (com.fredhat.gwt.xmlrpc.client.Date) param;
        Element dateElem = doc.createElement("dateTime.iso8601");
        dateElem.appendChild(doc.createTextNode(dateToISO8601(date)));
        valueElem.appendChild(dateElem);
    } else if (param instanceof Base64) {
        Element base64Elem = doc.createElement("base64");
        base64Elem.appendChild(doc.createTextNode(param.toString()));
        valueElem.appendChild(base64Elem);
    } else if (param instanceof Map) {
        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>) param;
        Element mapElem = doc.createElement("struct");

        for (Iterator<String> iter = map.keySet().iterator(); iter.hasNext();) {
            Object key = iter.next();
            Element memberElem = doc.createElement("member");
            {
                Element nameElem = doc.createElement("name");
                nameElem.appendChild(doc.createTextNode(key.toString()));
                memberElem.appendChild(nameElem);
            }
            {
                Element innerValueElem = buildValue(map.get(key));
                memberElem.appendChild(innerValueElem);
            }

            mapElem.appendChild(memberElem);
        }

        valueElem.appendChild(mapElem);
    } else if (param instanceof List) {
        @SuppressWarnings("unchecked")
        List<Object> list = (List<Object>) param;
        Element listElem = doc.createElement("array");
        {
            Element dataElem = doc.createElement("data");
            for (Iterator<Object> iter = list.iterator(); iter.hasNext();) {
                Element innerValueElem = buildValue(iter.next());
                dataElem.appendChild(innerValueElem);
            }
            listElem.appendChild(dataElem);
        }

        valueElem.appendChild(listElem);
    }

    return valueElem;
}

From source file:com.sensia.gwt.relaxNG.RNGInstanceWriter.java

License:Open Source License

protected String writeRNGTag(RNGTag tag, Document dom, Node parentNode) {
    String text = null;/*w  w w .  j  a  v a 2s  .c  o  m*/
    String error = null;

    if (tag instanceof RNGElement) {
        RNGElement elt = (RNGElement) tag;
        Element newElt = dom.createElement(getFullName(elt.getNamespace(), elt.getName()));
        parentNode.appendChild(newElt);
        ensureNamespaceDecl(elt.getNamespace());
        for (RNGTag child : elt.getChildren())
            writeRNGTag(child, dom, newElt);
    }

    else if (tag instanceof RNGAttribute) {
        RNGAttribute att = (RNGAttribute) tag;
        String name = getFullName(att.getNamespace(), att.getName());
        String value = writeRNGTag(att.getChildren().get(0), dom, null);
        ((Element) parentNode).setAttribute(name, value);
        ensureNamespaceDecl(att.getNamespace());
    }

    else if (tag instanceof RNGGroup) {
        RNGGroup grp = (RNGGroup) tag;
        for (RNGTag child : grp.getChildren())
            writeRNGTag(child, dom, parentNode);
    }

    else if (tag instanceof RNGOptional) {
        RNGOptional opt = (RNGOptional) tag;
        if (opt.isSelected())
            for (RNGTag child : opt.getChildren())
                writeRNGTag(child, dom, parentNode);
    }

    else if (tag instanceof RNGChoice) {
        RNGChoice choice = (RNGChoice) tag;
        if (choice.isSelected())
            text = writeRNGTag(choice.getSelectedPattern(), dom, parentNode);
        else
            error = NO_CHOICE;
    }

    else if (tag instanceof RNGZeroOrMore) {
        RNGZeroOrMore multiple = (RNGZeroOrMore) tag;
        for (List<RNGTag> tagList : multiple.getPatternInstances()) {
            for (RNGTag item : tagList)
                text = writeRNGTag(item, dom, parentNode);
        }
    }

    else if (tag instanceof RNGList) {
        RNGList list = (RNGList) tag;
        StringBuilder buf = new StringBuilder();

        for (RNGTag child : list.getChildren()) {
            String val = writeRNGTag(child, dom, null);
            if (val != null) {
                buf.append(val);
                buf.append(' ');
            }
        }

        if (buf.length() > 0)
            text = buf.toString();
    }

    else if (tag instanceof RNGRef) {
        RNGRef ref = (RNGRef) tag;
        if (ref.getPattern() != null) {
            for (RNGTag child : ref.getPattern().getChildren())
                writeRNGTag(child, dom, parentNode);
        } else
            error = NO_REF;
    }

    else if (tag instanceof RNGValue) {
        text = ((RNGValue) tag).getText();
        if (text == null)
            error = NO_VALUE;
    }

    else if (tag instanceof RNGText) {
        text = ((RNGText) tag).getText();
        if (text == null)
            error = NO_VALUE;
    }

    else if (tag instanceof RNGData<?>) {
        Object val = ((RNGData<?>) tag).getValue();
        if (val != null)
            text = val.toString();
        else
            error = NO_VALUE;
    }

    // deal with text nodes or attribute values
    if (text != null && text.length() > 0) {
        if (parentNode != null) {
            Text node = dom.createTextNode(text);
            parentNode.appendChild(node);
        } else
            return text;
    }

    // deal with error text
    if (error != null) {
        if (parentNode != null) {
            Comment c = dom.createComment(error);
            parentNode.appendChild(c);
        } else
            return error;
    }

    return null;
}

From source file:com.sensia.gwt.relaxNG.RNGWriter.java

License:Open Source License

protected void writeRNGTag(RNGTag tag, Document dom, Node parentNode) {
    if (tag instanceof RNGGrammar) {
        RNGGrammar grammar = (RNGGrammar) tag;
        Element grammarElt = dom.createElement("grammar");
        parentNode.appendChild(grammarElt);

        // insert namespace attributes
        grammarElt.setAttribute("xmlns", RNGParser.RNG_NS_URI);
        grammarElt.setAttribute("xmlns:a", RNGParser.ANNOT_NS_URI);
        for (Entry<String, String> ns : grammar.getNsPrefixToUri().entrySet())
            grammarElt.setAttribute("xmlns:" + ns.getKey(), ns.getValue());

        // includes
        for (Entry<String, RNGGrammar> include : grammar.getIncludedGrammars().entrySet()) {
            Element incElt = dom.createElement("include");
            grammarElt.appendChild(incElt);
            String href = include.getKey();
            href = href.substring(grammar.getId().length() + 1);
            // TODO generate correct relative url
        }//from   w  w  w .  j  av  a  2  s  .  c om

        // start pattern
        Element startElt = dom.createElement("start");
        grammarElt.appendChild(startElt);
        for (RNGTag child : grammar.getStartPattern().getChildren())
            writeRNGTag(child, dom, startElt);

        // defines
        for (RNGDefine def : grammar.getPatterns().values())
            writeRNGTag(def, dom, grammarElt);
    }

    else if (tag instanceof RNGDefine) {
        RNGDefine def = (RNGDefine) tag;
        Element newElt = dom.createElement("define");
        newElt.setAttribute("name", def.getId());
        parentNode.appendChild(newElt);

        for (RNGTag child : def.getChildren())
            writeRNGTag(child, dom, newElt);
    }

    else if (tag instanceof RNGElement) {
        RNGElement elt = (RNGElement) tag;
        Element newElt = dom.createElement("element");
        newElt.setAttribute("name", getFullName(elt.getNamespace(), elt.getName()));
        parentNode.appendChild(newElt);

        for (RNGTag child : elt.getChildren())
            writeRNGTag(child, dom, newElt);
    }

    else if (tag instanceof RNGAttribute) {
        RNGAttribute att = (RNGAttribute) tag;
        Element newElt = dom.createElement("attribute");
        newElt.setAttribute("name", getFullName(att.getNamespace(), att.getName()));
        parentNode.appendChild(newElt);

        for (RNGTag child : att.getChildren())
            writeRNGTag(child, dom, newElt);
    }

    else if (tag instanceof RNGGroup) {
        RNGGroup grp = (RNGGroup) tag;
        Element newElt = dom.createElement("group");
        parentNode.appendChild(newElt);

        for (RNGTag child : grp.getChildren())
            writeRNGTag(child, dom, newElt);
    }

    else if (tag instanceof RNGOptional) {
        RNGOptional opt = (RNGOptional) tag;

        if (!opt.isDisabled()) {
            Element newElt = dom.createElement("optional");
            parentNode.appendChild(newElt);

            if (keepUserInput)
                newElt.setAttribute("selected", Boolean.toString(opt.isSelected()));

            for (RNGTag child : opt.getChildren())
                writeRNGTag(child, dom, newElt);
        }
    }

    else if (tag instanceof RNGChoice) {
        RNGChoice choice = (RNGChoice) tag;
        Element newElt = dom.createElement("choice");
        parentNode.appendChild(newElt);

        // TODO handle degenerated choice (all items disabled except one)
        // in this case, don't even write choice envelope

        int selectedIndex = choice.getSelectedIndex();
        for (int i = 0; i < choice.getItems().size(); i++) {
            RNGTag item = choice.getItems().get(i);
            if (!item.isDisabled()) {
                writeRNGTag(item, dom, newElt);
                if (keepUserInput && i == selectedIndex)
                    ((Element) newElt.getLastChild()).setAttribute("selected", "true");
            }
        }
    }

    else if (tag instanceof RNGZeroOrMore) {
        RNGZeroOrMore zeroOrMore = (RNGZeroOrMore) tag;

        // TODO handle case where a different multiplicity is set
        // examples are 1..*, 1..3, 2..2, etc...)
        // need info in RNG object
        // repalce by oneOrMore or the exact number of patterns using ref and optional

        if (!zeroOrMore.isDisabled()) {
            Element newElt = (zeroOrMore instanceof RNGOneOrMore) ? dom.createElement("oneOrMore")
                    : dom.createElement("zeroOrMore");
            parentNode.appendChild(newElt);

            if (keepUserInput) {
                for (List<RNGTag> tagList : zeroOrMore.getPatternInstances()) {
                    Element occElt = dom.createElement("occurence");
                    for (RNGTag item : tagList)
                        writeRNGTag(item, dom, occElt);
                    newElt.appendChild(newElt);
                }
            }

            for (RNGTag child : zeroOrMore.getChildren())
                writeRNGTag(child, dom, newElt);
        }
    }

    else if (tag instanceof RNGList) {
        RNGList list = (RNGList) tag;
        Element newElt = dom.createElement("list");
        parentNode.appendChild(newElt);

        for (RNGTag child : list.getChildren())
            writeRNGTag(child, dom, newElt);
    }

    else if (tag instanceof RNGRef) {
        RNGRef ref = (RNGRef) tag;
        Element newElt = dom.createElement("ref");
        newElt.setAttribute("name", ref.getId());
        parentNode.appendChild(newElt);
    }

    else if (tag instanceof RNGValue) {
        RNGValue val = ((RNGValue) tag);
        Element newElt = dom.createElement("value");
        newElt.appendChild(dom.createTextNode(val.getText()));
        parentNode.appendChild(newElt);
    }

    else if (tag instanceof RNGText) {
        RNGText text = ((RNGText) tag);

        if (keepUserInput || text.getText() == null) {
            Element newElt = dom.createElement("text");
            parentNode.appendChild(newElt);

            if (text.getText() != null) {
                Element valElt = dom.createElement("value");
                valElt.appendChild(dom.createTextNode(text.getText()));
                newElt.appendChild(valElt);
            }
        } else {
            Element newElt = dom.createElement("value");
            newElt.appendChild(dom.createTextNode(text.getText()));
            parentNode.appendChild(newElt);
        }
    }

    else if (tag instanceof RNGData<?>) {
        RNGData<?> data = ((RNGData<?>) tag);

        // TODO write data type parameters

        if (keepUserInput || data.getStringValue() == null) {
            Element newElt = dom.createElement("data");
            newElt.setAttribute("type", data.getType());
            parentNode.appendChild(newElt);

            if (data.getStringValue() != null) {
                Element valElt = dom.createElement("value");
                valElt.appendChild(dom.createTextNode(data.getStringValue()));
                newElt.appendChild(valElt);
            }
        } else {
            Element newElt = dom.createElement("value");
            newElt.appendChild(dom.createTextNode(data.getStringValue()));
            parentNode.appendChild(newElt);
        }
    }
}

From source file:edu.umb.jsPedigrees.client.Pelican.Pelican.java

License:Open Source License

public String getGrade() {
    Document d = XMLParser.createDocument();
    Element root = d.createElement("Grade");

    // first, some specifications of the pedigree
    int numMales = 0;
    int numFemales = 0;
    int numAffectedMales = 0;
    int numAffectedFemales = 0;
    PelicanPerson[] people = getAllPeople();
    for (int i = 0; i < people.length; i++) {
        PelicanPerson p = people[i];/*from  w  w w  . ja v a2s.  c  o m*/
        if (p.sex == PelicanPerson.male) {
            numMales++;
            if (p.affection == PelicanPerson.affected) {
                numAffectedMales++;
            }
        } else {
            numFemales++;
            if (p.affection == PelicanPerson.affected) {
                numAffectedFemales++;
            }
        }
    }
    Element e = d.createElement("Counts");

    Element M = d.createElement("M");
    M.appendChild(d.createTextNode(String.valueOf(numMales)));
    e.appendChild(M);

    Element F = d.createElement("F");
    F.appendChild(d.createTextNode(String.valueOf(numFemales)));
    e.appendChild(F);

    Element aM = d.createElement("aM");
    aM.appendChild(d.createTextNode(String.valueOf(numAffectedMales)));
    e.appendChild(aM);

    Element aF = d.createElement("aF");
    aF.appendChild(d.createTextNode(String.valueOf(numAffectedFemales)));
    e.appendChild(aF);

    root.appendChild(e);

    // now, the analysis results
    renumberAll();
    updateDisplay();

    String integrity = checkIntegrity(history.lastElement());
    if (integrity.equals("")) {
        PedigreeSolver ps = new PedigreeSolver(getAllPeople(), getMatingList());
        PedigreeSolution sol = ps.solve();
        e = d.createElement("Analysis");

        GenotypeSet[] results = sol.getResults();

        Element AR = d.createElement("AR");
        if (results[0].getAll().size() > 0) {
            AR.appendChild(d.createTextNode("Y"));
        } else {
            AR.appendChild(d.createTextNode("N"));
        }
        e.appendChild(AR);

        Element AD = d.createElement("AD");
        if (results[1].getAll().size() > 0) {
            AD.appendChild(d.createTextNode("Y"));
        } else {
            AD.appendChild(d.createTextNode("N"));
        }
        e.appendChild(AD);

        Element SR = d.createElement("SR");
        if (results[2].getAll().size() > 0) {
            SR.appendChild(d.createTextNode("Y"));
        } else {
            SR.appendChild(d.createTextNode("N"));
        }
        e.appendChild(SR);

        Element SD = d.createElement("SD");
        if (results[3].getAll().size() > 0) {
            SD.appendChild(d.createTextNode("Y"));
        } else {
            SD.appendChild(d.createTextNode("N"));
        }
        e.appendChild(SD);
    }
    root.appendChild(e);

    return root.toString();
}

From source file:edu.umb.jsVGL.client.GeneticModels.ProblemTypeSpecification.java

License:Open Source License

public Element save() throws Exception {
    Document d = XMLParser.createDocument();
    Element ptse = d.createElement("ProblemTypeSpecification");
    Element e = null;/*from  ww  w  .j a v a2s .c o  m*/

    e = d.createElement("FieldPopTrueBreeding");
    e.appendChild(d.createTextNode(String.valueOf(fieldPopTrueBreeding)));
    ptse.appendChild(e);

    e = d.createElement("BeginnerMode");
    e.appendChild(d.createTextNode(String.valueOf(beginnerMode)));
    ptse.appendChild(e);

    e = d.createElement("MinOffspring");
    e.appendChild(d.createTextNode(String.valueOf(minOffspring)));
    ptse.appendChild(e);

    e = d.createElement("MaxOffspring");
    e.appendChild(d.createTextNode(String.valueOf(maxOffspring)));
    ptse.appendChild(e);

    e = d.createElement("ZZ_ZW");
    e.appendChild(d.createTextNode(String.valueOf(chZZ_ZW)));
    ptse.appendChild(e);

    e = d.createElement("Gene1_SexLinked");
    e.appendChild(d.createTextNode(String.valueOf(gene1_chSexLinked)));
    ptse.appendChild(e);

    e = d.createElement("Gene1_3Alleles");
    e.appendChild(d.createTextNode(String.valueOf(gene1_ch3Alleles)));
    ptse.appendChild(e);

    e = d.createElement("Gene1_IncDom");
    e.appendChild(d.createTextNode(String.valueOf(gene1_chIncDom)));
    ptse.appendChild(e);

    e = d.createElement("Gene1_CircDom");
    e.appendChild(d.createTextNode(String.valueOf(gene1_chCircDom)));
    ptse.appendChild(e);

    e = d.createElement("Gene2_Present");
    e.appendChild(d.createTextNode(String.valueOf(gene2_chPresent)));
    ptse.appendChild(e);

    e = d.createElement("Gene2_SameChrAsGene1");
    e.appendChild(d.createTextNode(String.valueOf(gene2_chSameChrAsGene1)));
    ptse.appendChild(e);

    e = d.createElement("Gene2_MinRfToGene1");
    e.appendChild(d.createTextNode(String.valueOf(gene2_minRfToGene1)));
    ptse.appendChild(e);

    e = d.createElement("Gene2_MaxRfToGene1");
    e.appendChild(d.createTextNode(String.valueOf(gene2_maxRfToGene1)));
    ptse.appendChild(e);

    e = d.createElement("Gene2_3Alleles");
    e.appendChild(d.createTextNode(String.valueOf(gene2_ch3Alleles)));
    ptse.appendChild(e);

    e = d.createElement("Gene2_IncDom");
    e.appendChild(d.createTextNode(String.valueOf(gene2_chIncDom)));
    ptse.appendChild(e);

    e = d.createElement("Gene2_CircDom");
    e.appendChild(d.createTextNode(String.valueOf(gene2_chCircDom)));
    ptse.appendChild(e);

    e = d.createElement("Gene3_Present");
    e.appendChild(d.createTextNode(String.valueOf(gene3_chPresent)));
    ptse.appendChild(e);

    e = d.createElement("Gene3_SameChrAsGene1");
    e.appendChild(d.createTextNode(String.valueOf(gene3_chSameChrAsGene1)));
    ptse.appendChild(e);

    e = d.createElement("Gene3_MinRfToPrevGene");
    e.appendChild(d.createTextNode(String.valueOf(gene3_minRfToPrevGene)));
    ptse.appendChild(e);

    e = d.createElement("Gene3_MaxRfToPrevGene");
    e.appendChild(d.createTextNode(String.valueOf(gene3_maxRfToPrevGene)));
    ptse.appendChild(e);

    e = d.createElement("Gene3_3Alleles");
    e.appendChild(d.createTextNode(String.valueOf(gene3_ch3Alleles)));
    ptse.appendChild(e);

    e = d.createElement("Gene3_IncDom");
    e.appendChild(d.createTextNode(String.valueOf(gene3_chIncDom)));
    ptse.appendChild(e);

    e = d.createElement("Gene3_CircDom");
    e.appendChild(d.createTextNode(String.valueOf(gene3_chCircDom)));
    ptse.appendChild(e);

    e = d.createElement("PhenotypeInteraction");
    e.appendChild(d.createTextNode(String.valueOf(phenotypeInteraction)));
    ptse.appendChild(e);

    e = d.createElement("Epistasis");
    e.appendChild(d.createTextNode(String.valueOf(epistasis)));
    ptse.appendChild(e);

    return ptse;
}

From source file:org.apache.oozie.tools.workflowgenerator.client.property.action.PipesPropertyTable.java

License:Apache License

/**
 * Create xml element of specified tag name
 *
 * @param list list of properties/*  w w w  . j a  va 2s  . c o  m*/
 * @param root xml element under which new elements are added
 * @param pipes pipes element
 * @param doc xml doc
 * @param key tag name
 * @return
 */
protected Element filterListToXML(List<Property> list, Element root, Element pipes, Document doc, String key) {

    for (Property prop : list) {
        if (prop.getName() != null && !prop.getName().matches("\\s*") && prop.getValue() != null
                && !prop.getValue().matches("\\s*")) {
            if (prop.getName().equals(key)) {
                if (pipes == null) {
                    pipes = doc.createElement("pipes");
                    root.appendChild(pipes);
                }
                // create key element
                Element nameele = doc.createElement(key);
                pipes.appendChild(nameele);

                // create text node under created element
                Text valele = doc.createTextNode(prop.getValue());
                nameele.appendChild(valele);
            }
        }
    }
    return pipes;
}

From source file:org.apache.oozie.tools.workflowgenerator.client.property.action.SSHPropertyTable.java

License:Apache License

/**
 * Generate xml elements of ssh action and attach them to xml doc
 *//* w  ww.  j a va  2s .  c  o m*/
public void generateXML(Document doc, Element root, NodeWidget next) {

    Element action = doc.createElement("action");
    action.setAttribute("name", current.getName());

    // create <ssh>
    Element sshEle = doc.createElement("ssh");
    action.appendChild(sshEle);

    // create <host>
    sshEle.appendChild(generateElement(doc, "host", host));

    // create <command>
    sshEle.appendChild(generateElement(doc, "command", command));

    // create <args>
    for (String arg : args) {
        Element argsEle = doc.createElement("args");
        Text n = doc.createTextNode(arg);
        argsEle.appendChild(n);
        sshEle.appendChild(argsEle);

    }

    // create <capture-output>
    if (rby.getValue()) {
        Element outputele = doc.createElement("capture-output");
        sshEle.appendChild(outputele);
    }

    // create <ok>
    action.appendChild(generateOKElement(doc, next));

    // create <error>
    action.appendChild(generateErrorElement(doc));

    root.appendChild(action);
}

From source file:org.apache.oozie.tools.workflowgenerator.client.property.action.StreamingPropertyTable.java

License:Apache License

/**
 * Create xml element of specified tag name
 *
 * @param list list of properties//from w w w.j av a 2  s.  c o m
 * @param root xml element under which new elements are added
 * @param streaming streaming element
 * @param doc xml doc
 * @param key tag name
 * @return
 */
protected Element filterListToXML(List<Property> list, Element root, Element streaming, Document doc,
        String key) {

    for (Property prop : list) {
        if (prop.getName() != null && !prop.getName().matches("\\s*") && prop.getValue() != null
                && !prop.getValue().matches("\\s*")) {
            if (prop.getName().equals(key)) {
                if (streaming == null) {
                    streaming = doc.createElement("streaming");
                    root.appendChild(streaming);
                }
                // create key element
                Element nameele = doc.createElement(key);
                streaming.appendChild(nameele);

                // create text node under created element
                Text valele = doc.createTextNode(prop.getValue());
                nameele.appendChild(valele);
            }
        }
    }
    return streaming;
}