Example usage for com.google.gwt.xml.client NodeList getLength

List of usage examples for com.google.gwt.xml.client NodeList getLength

Introduction

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

Prototype

int getLength();

Source Link

Document

This method retrieves the number of items in this NodeList object.

Usage

From source file:anzsoft.xmpp4gwt.client.packet.PacketGwtImpl.java

License:Open Source License

public List<? extends Packet> getChildren() {
    NodeList nodes = this.element.getChildNodes();
    ArrayList<PacketGwtImpl> result = new ArrayList<PacketGwtImpl>();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node instanceof Element) {
            PacketGwtImpl gpi = new PacketGwtImpl((Element) node);
            result.add(gpi);// w  w  w.  ja  v  a  2s. c  o  m
        }
    }
    return result;
}

From source file:anzsoft.xmpp4gwt.client.packet.PacketGwtImpl.java

License:Open Source License

public Packet getFirstChild(String name) {
    NodeList nodes = this.element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node instanceof Element) {
            PacketGwtImpl gpi = new PacketGwtImpl((Element) node);
            if (name.equals(gpi.getName())) {
                return gpi;
            }//from  www .ja  v  a2 s.  c o  m
        }
    }
    return null;
}

From source file:anzsoft.xmpp4gwt.client.packet.PacketGwtImpl.java

License:Open Source License

public void setCData(String cdata) {
    final NodeList nodes = element.getChildNodes();
    for (int index = 0; index < nodes.getLength(); index++) {
        final Node child = nodes.item(index);
        if (child.getNodeType() == Node.TEXT_NODE) {
            element.removeChild(child);/*from   ww w  . j a  v  a2 s. c o m*/
        }
    }
    element.appendChild(element.getOwnerDocument().createTextNode(cdata));
}

From source file:bz.davide.dmxmljson.unmarshalling.xml.gwt.GWTXMLStructure.java

License:Open Source License

private void extractChildElementByName() {
    NodeList nl = this.element.element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);//from w w w  .ja  v  a 2s  .  c om
        if (node instanceof Element) {
            Element element = (Element) node;

            String tagName = element.getTagName();
            String[] parts = GWTXMLStructure.extractNameAndSubtype(tagName);

            String attrName = parts[0];
            ElementAndSubtype elementAndSubtype = new ElementAndSubtype();
            elementAndSubtype.element = element;
            elementAndSubtype.subtype = parts[1];

            ArrayList<ElementAndSubtype> elements = this.elementsByName.get(attrName);
            if (elements == null) {
                elements = new ArrayList<ElementAndSubtype>();
                this.elementsByName.put(attrName, elements);
            }
            elements.add(elementAndSubtype);

            ElementAndSubtype childElementAndSubtype = new ElementAndSubtype();
            childElementAndSubtype.element = element;
            childElementAndSubtype.subtype = tagName;
            // Convert first letter to upper case, because java classes start normally with upper case
            childElementAndSubtype.subtype = childElementAndSubtype.subtype.substring(0, 1).toUpperCase()
                    + childElementAndSubtype.subtype.substring(1);
            this.childNodes.add(childElementAndSubtype);
        }
        if (node instanceof Text) {
            String txt = node.getNodeValue();
            if (txt.trim().length() > 0) {
                ElementAndSubtype childElementAndSubtype = new ElementAndSubtype();
                childElementAndSubtype.element = node;
                childElementAndSubtype.subtype = "TextNode";
                this.childNodes.add(childElementAndSubtype);
            }
        }
    }
}

From source file:bz.davide.dmxmljson.unmarshalling.xml.gwt.GWTXMLValue.java

License:Open Source License

void recursiveText(Node node, StringBuffer sb) {
    if (node.getNodeType() == Node.TEXT_NODE) {
        sb.append(node.getNodeValue());//from w  ww  . j av a 2s. c  om
    }
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        NodeList nl = node.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            this.recursiveText(nl.item(i), sb);
        }
    }
}

From source file:carteirainveste.client.DateUtil.java

License:Creative Commons License

void loadDb(NodeList nodeList) {

    dbLogConsole.clear();// w ww  .  j  ava 2  s  . c  o  m

    dbLog("Clearing quote list");
    clearQuoteList();

    dbLog("Clearing operation list");
    clearOperationList();

    dbLog("Parsing XML DB...");

    for (int i = 0; i < nodeList.getLength(); ++i) {
        Node node = nodeList.item(i);
        if (!(node instanceof Element))
            continue;
        Element elem = (Element) node;
        String tag = elem.getTagName();

        if (tag.equals(Constant.XML_TAG_PREFERENCES)) {
            Preference.loadFromDb(elem);
            continue;
        }

        if (tag.equals(Constant.XML_TAG_QUOTE)) {
            addQuote(elem);
            continue;
        }

        if (!tag.equals(Constant.XML_TAG_OPERATION))
            continue;
        String opType = elem.getAttribute("type");

        if (opType.equals("buy")) {
            try {
                Buy op = new Buy(elem);
                addOperation(op);
            } catch (IllegalArgumentException e) {
                dbLog("Could not parse Buy operation: " + e);
            }
            continue;
        }
        if (opType.equals("sell")) {
            try {
                Sell op = new Sell(elem);
                addOperation(op);
            } catch (IllegalArgumentException e) {
                dbLog("Could not parse Sell operation: " + e);
            }
            continue;
        }
        if (opType.equals("daytrade")) {
            try {
                DayTrade op = new DayTrade(elem);
                addOperation(op);
            } catch (IllegalArgumentException e) {
                dbLog("Could not parse DayTrade operation: " + e);
            }
            continue;
        }
        if (opType.equals("deposit")) {
            try {
                Deposit op = new Deposit(elem);
                addOperation(op);
            } catch (IllegalArgumentException e) {
                dbLog("Could not parse Deposit operation: " + e);
            }
            continue;
        }
        if (opType.equals("withdraw")) {
            try {
                Withdraw op = new Withdraw(elem);
                addOperation(op);
            } catch (IllegalArgumentException e) {
                dbLog("Could not parse Withdraw operation: " + e);
            }
            continue;
        }
        if (opType.equals("fee")) {
            try {
                Fee op = new Fee(elem);
                addOperation(op);
            } catch (IllegalArgumentException e) {
                dbLog("Could not parse Fee operation: " + e);
            }
            continue;
        }
        if (opType.equals("transfer")) {
            try {
                Transfer op = new Transfer(elem);
                addOperation(op);
            } catch (IllegalArgumentException e) {
                dbLog("Could not parse Transfer operation: " + e);
            }
            continue;
        }
        if (opType.equals("yield")) {
            try {
                Yield op = new Yield(elem);
                addOperation(op);
            } catch (IllegalArgumentException e) {
                dbLog("Could not parse Yield operation: " + e);
            }
            continue;
        }
        if (opType.equals("split")) {
            try {
                Split op = new Split(elem);
                addOperation(op);
            } catch (IllegalArgumentException e) {
                dbLog("Could not parse Split operation: " + e);
            }
            continue;
        }
    } // for (nodeList)

    dbLog("Parsing XML DB... done");

    dbLog("Updating data structures...");

    buildOpTab();
    buildOpPanel();
    buildAccTab();
    buildAccPanel();
    buildAddQuoteAssetDropBox();
    buildQuoteGrid();
    buildYieldTable();
    buildSplitGrid();
    buildAddAssetAccountDropBox();
    buildAddYieldAccountDropBox();
    updateTaxGrid();
    updatePrefPanel();

    dbLog("Updating data structures... done");
}

From source file:ccc.client.gwt.core.GWTValidations.java

License:Open Source License

/** {@inheritDoc} */
@Override/*ww w  .  j a v a  2  s . co  m*/
public String notValidXML(final String definition) {
    try {
        final Document d = XMLParser.parse(definition);
        final NodeList fields = d.getElementsByTagName("field");
        if (fields.getLength() > 32) {
            return UI_CONSTANTS.tooManyFields();
        }

        final NodeList l = d.getElementsByTagName("option");
        for (int n = 0; n < l.getLength(); n++) {
            final NamedNodeMap al = l.item(n).getAttributes();
            final Node value = al.getNamedItem("value");
            if (value != null && value.getNodeValue().indexOf(',') != -1) {
                return "XML option value " + UI_CONSTANTS.mustNotContainComma();
            }
        }
    } catch (final DOMParseException e) {
        return "XML " + UI_CONSTANTS.isNotValid();
    }
    return null;
}

From source file:ccc.client.gwt.widgets.EditPagePanel.java

License:Open Source License

/**
 * Adds necessary fields for the panel./*from   ww  w  .  java 2  s  .  com*/
 *
 * @param definition XML of the definition.
 */
private void createFields(final String definition) {
    if (definition == null || definition.trim().equals("")) {
        return;
    }
    addStaticFields();

    final Document def = XMLParser.parse(definition);

    final NodeList fields = def.getElementsByTagName("field");

    for (int i = 0; i < fields.getLength(); i++) {

        final Element field = ((Element) fields.item(i));
        final String type = field.getAttribute("type");
        final String name = field.getAttribute("name");
        final String title = field.getAttribute("title");
        final String desc = field.getAttribute("description");
        final String regexp = field.getAttribute("regexp");
        final String vocabulary = field.getAttribute("vocabulary");
        final List<Option> options = parseOptions(field);

        PageElement<? extends Component> pe = null;

        if ("text_field".equals(type)) {
            pe = new CCTextField(name, regexp, title, desc);
        } else if ("text_area".equals(type)) {
            pe = new CCTextAreaField(name, regexp, title, desc);
        } else if ("date".equals(type)) {
            pe = new CCDateField(name, title, desc);
        } else if ("html".equals(type)) {
            pe = new CCHtmlField(name, title, desc);
        } else if ("checkbox".equals(type)) {
            pe = new CCCheckBoxField(name, title, desc, options);
        } else if ("radio".equals(type)) {
            pe = new CCRadioField(name, title, desc, options);
        } else if ("combobox".equals(type)) {
            pe = new CCComboBoxField(name, title, desc, options);
        } else if ("list".equals(type)) {
            pe = new CCListField(name, title, desc, options);
        } else if ("image".equals(type)) {
            pe = new CCImageField(name, title, desc);
        } else if ("resource".equals(type)) {
            pe = new CCResourceField(name, title, desc, _targetRoot);
        } else if ("taxonomy".equals(type)) {
            pe = new CCTaxonomyField(name, title, desc, vocabulary, _targetRoot);
        } else if ("number".equals(type)) {
            pe = new CCNumberField(name, title, desc);
        }

        if (null != pe) {
            add(pe.getUI(), new FormData("95%"));
            _pageElements.add(pe);
        }
    }
}

From source file:ccc.client.gwt.widgets.EditPagePanel.java

License:Open Source License

private List<Option> parseOptions(final Element field) {
    final List<Option> options = new ArrayList<Option>();
    final NodeList nl = field.getElementsByTagName("option");
    for (int i = 0; i < nl.getLength(); i++) {
        final Element option = ((Element) nl.item(i));

        final String def = option.getAttribute("default");
        final String title = option.getAttribute("title");
        final String value = option.getAttribute("value");

        options.add(new Option(title, value, Boolean.valueOf("true".equals(def))));
    }/*from w  w  w . j a  v  a 2s  . c o m*/
    return options;
}

From source file:com.anzsoft.client.utils.XMLHelper.java

License:Open Source License

public static Element queryTag(final Element e) {
    if (e == null)
        return null;
    NodeList list = e.getElementsByTagName("query");
    if (list.getLength() > 0)
        return (Element) list.item(0);
    else/*from   w w  w  . j  a v a  2 s .  com*/
        return null;
}