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

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

Introduction

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

Prototype

Element createElement(String tagName);

Source Link

Document

This method creates a new Element.

Usage

From source file:carteirainveste.client.DateUtil.java

License:Creative Commons License

static Element appendChildNode(Document doc, Node parent) {
    Element elem = doc.createElement(Constant.XML_TAG_PREFERENCES);
    parent.appendChild(elem);//from   w w  w.j  a va2  s  .  com

    elem.setAttribute("stock_sell_spread", String.valueOf(sellSpread));
    elem.setAttribute("stock_broker_fee", String.valueOf(brokerFeeCents));
    elem.setAttribute("stock_tax_exemption_limit", String.valueOf(stockTaxExemptionCents));
    elem.setAttribute("stock_tax_fee", String.valueOf(stockTaxFee));
    elem.setAttribute("stock_daytrade_tax_fee", String.valueOf(stockDayTradeTaxFee));
    elem.setAttribute("stock_daytrade_affect_exemption_limit",
            String.valueOf(stockDayTradeAffectExemptionLimit.getValue()));
    elem.setAttribute("stock_exempt_gains_reduce_carried_loss",
            String.valueOf(stockExemptGainsReduceCarriedLoss.getValue()));
    elem.setAttribute("stock_tax_ratio_over_pretax_earnings",
            String.valueOf(stockTaxRatioOverPretaxEarnings.getValue()));

    /*
    Carteira curr = CarteiraInveste.carteiraAtual;
    String strCarryLoss = curr.startTaxCarryLoss.getText();
    if (strCarryLoss == null)
       strCarryLoss = CurrencyUtil.format(0);
    String strDayTradeCarryLoss = curr.startTaxDayTradeCarryLoss.getText();
    if (strDayTradeCarryLoss == null)
       strDayTradeCarryLoss = CurrencyUtil.format(0);
    */

    elem.setAttribute("stock_tax_start_carry_loss", startTaxCarryLoss.getText());
    elem.setAttribute("stock_tax_daytrade_start_carry_loss", startTaxDayTradeCarryLoss.getText());

    return elem;
}

From source file:carteirainveste.client.DateUtil.java

License:Creative Commons License

Element appendChildNode(Document doc, Node parent) {
    Element elem = doc.createElement(Constant.XML_TAG_QUOTE);
    parent.appendChild(elem);//  ww  w .j  a  v a  2s .c o m

    elem.setAttribute("date", Preference.dateFormat.format(quoteDate));
    elem.setAttribute("asset_name", quoteAssetName);
    elem.setAttribute("asset_amount", String.valueOf(quoteAssetAmount));
    elem.setAttribute("value", String.valueOf(quoteValue));

    return elem;
}

From source file:carteirainveste.client.DateUtil.java

License:Creative Commons License

Element appendChildNode(Document doc, Node parent) {
    Element elem = doc.createElement(Constant.XML_TAG_OPERATION);
    parent.appendChild(elem);
    return elem;
}

From source file:carteirainveste.client.DateUtil.java

License:Creative Commons License

void updateXmlDb() {
    Document doc = XMLParser.createDocument();
    Element parent = doc.getDocumentElement();

    if (parent == null) {
        parent = doc.createElement("database");
        doc.appendChild(parent);//from ww w. j a  v a 2s  .  c o m
    }

    // Add preferences to DOM
    Preference.appendChildNode(doc, parent);

    // Add quotes to DOM
    for (Object element : quoteTable.values()) {
        Quote quote = (Quote) element;
        quote.appendChildNode(doc, parent);
    }

    // Add operations to DOM
    for (int i = 0; i < operationList.size(); ++i) {
        Operation op = (Operation) operationList.get(i);
        op.appendChildNode(doc, parent);
    }

    // Convert DOM to XML
    currXmlTextDb = Constant.XML_HEADER + doc.toString();

    // Display XML
    dbText.setText(currXmlTextDb);
}

From source file:client.serializers.XMLSeriesSerializer.java

License:Open Source License

/**
 * Serialize to XML.//from w w  w .j  a v  a2  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");
    {/*  w  w w.j  a  v  a2 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);//from  w  ww.j  a v a  2s . c  o  m
    } 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  ww.  jav  a2s.co  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 ww  .  j  a va 2 s. c  o m*/

        // 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   ww w .ja  v  a 2s  .  c om*/
        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();
}