Example usage for com.google.gwt.xml.client XMLParser createDocument

List of usage examples for com.google.gwt.xml.client XMLParser createDocument

Introduction

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

Prototype

public static Document createDocument() 

Source Link

Document

This method creates a new document, to be manipulated by the DOM API.

Usage

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 va2 s .  com*/
    }

    // 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 ww  w  .j  av  a2s. c  om
 */
@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.calclab.emite.base.xml.XMLPacketImplGWT.java

License:Open Source License

protected XMLPacketImplGWT(final String name, @Nullable final String namespace) {
    document = XMLParser.createDocument();
    element = document.createElement(name);
    if (namespace != null) {
        element.setAttribute("xmlns", namespace);
    }/* w  w w.ja v a2 s  . c o m*/
    document.appendChild(element);
}

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  ww  .  jav a  2  s. co m*/
        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  . ja  va2  s .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

public Document writeInstance(RNGTag tag, Map<String, String> nsUriToPrefixMap) {
    dom = XMLParser.createDocument();
    this.nsUriToPrefixMap = nsUriToPrefixMap;
    writeRNGTag(tag, dom, dom);//from   w ww. j a v  a  2s  . com
    return dom;
}

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

License:Open Source License

/**
 * Writes out the grammar as a DOM document in RelaxNG 1.0 format
 * @param grammar/*  w  w  w .  j  a va 2 s  .  c o m*/
 * @param keepUserInput if set to true, user inputs will be included in the
 * grammar via additional tags and attributes. If not, selections made in the
 * grammar will be used to further restrict it, thus leading to a more
 * constraining schema.
 * @return
 */
public Document writeSchema(RNGGrammar grammar, boolean keepUserInput) {
    dom = XMLParser.createDocument();
    this.keepUserInput = keepUserInput;
    this.nsUriToPrefixMap = grammar.getNsUriToPrefix();
    writeRNGTag(grammar, dom, dom);
    return dom;
}

From source file:de.decidr.modelingtoolbase.client.io.WorkflowModelMarshaller.java

License:Apache License

/**
 * Converts a workflow model and its variables and child nodes into a DWDL
 * document.//from w w  w . j  a v  a 2  s. com
 * 
 * @param model
 *            The model to be converted into an XML string
 * @return the model as XML string
 */
public String marshal(WorkflowModel workflow) {
    doc = XMLParser.createDocument();

    /* Create workflow root element and set attributes */
    Element workflowElement = doc.createElement(DWDLNames.root);
    workflowElement.setAttribute(DWDLNames.name, workflow.getName());
    workflowElement.setAttribute(DWDLNames.id, workflow.getId().toString());
    workflowElement.setAttribute(DWDLNames.targetNamespace, workflow.getXmlProperties().getTargetNamespace());
    /*
     * Due to a GWT bug and the fact that not all browser DOM
     * implementations support xml namespaces, this doesn't actually work.
     * 
     * The result will be xmlns="";
     */
    workflowElement.setAttribute(DWDLNames.xmlNamespace, DWDLNames.DWDL_NAMESPACE);

    /* Create description node */
    workflowElement.appendChild(createTextElement(DWDLNames.description, workflow.getDescription()));

    /* Create variable and role nodes */
    createVariablesAndRoles(workflowElement, workflow);

    /* Create fault handler node */
    workflowElement.appendChild(createFaultHandlerElement(workflow));

    /* Create container and invoke nodes */
    workflowElement.appendChild(createChildNodeElements(workflow, workflow, workflow.getChildNodeModels()));

    /* Create arcs */
    workflowElement.appendChild(createArcElements(workflow, workflow.getChildConnectionModels()));

    /* Append tree to root element */
    doc.appendChild(workflowElement);

    /* Add header element */
    String dwdl = workflow.getXmlProperties().getHeader() + doc.getDocumentElement().toString();
    return dwdl;
}

From source file:de.decidr.workflowmodeleditor.client.WorkflowEditorWidget.java

License:Apache License

/**
 * Sets the userlist (all users of the tenant) for the modeling tool. The
 * userlist is a xml document, in which every user element has the user id
 * and a display name for user.//  ww  w.  java2  s .c o m
 * 
 * @param userxml
 *            the user list as xml
 */
public void setUsers(String userxml) {
    users = new HashMap<Long, String>();

    Document doc = XMLParser.createDocument();
    doc = XMLParser.parse(userxml);
    NodeList list = doc.getElementsByTagName("user");

    for (int i = 0; i < list.getLength(); i++) {
        Element element = (Element) list.item(i);
        Long id = new Long(element.getAttribute("id"));
        String name = element.getAttribute("name");
        users.put(id, name);
    }
    canvas.setUsers(users);
}

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];/*  w  w  w.  j  ava2s. co  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();
}