Example usage for com.google.gwt.xml.client Element getTagName

List of usage examples for com.google.gwt.xml.client Element getTagName

Introduction

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

Prototype

String getTagName();

Source Link

Document

This method retrieves the tag name.

Usage

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

License:Open Source License

static ElementAndSubtype domParser(String xmlText) {

    Document doc = XMLParser.parse(xmlText);

    ElementAndSubtype elementAndSubtype = new ElementAndSubtype();
    Element documentElement = doc.getDocumentElement();
    elementAndSubtype.element = documentElement;
    String[] parts = extractNameAndSubtype(documentElement.getTagName());
    elementAndSubtype.subtype = parts[1];

    return elementAndSubtype;
}

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   www  .  j a va  2 s . com*/
        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:carteirainveste.client.DateUtil.java

License:Creative Commons License

void loadDb(NodeList nodeList) {

    dbLogConsole.clear();// www  .  j  ava  2 s  .c om

    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:com.anzsoft.client.XMPP.impl.JsJacPresence.java

License:Open Source License

public String getNick() {
    String xml = toXML();//from w  w  w .j a va  2s  .  c  o m
    Document doc = XMLParser.parse(xml);
    Element rootEl = doc.getDocumentElement();
    if (!rootEl.getTagName().equals("presence"))
        return "";
    Element nickEl = XMLHelper.findSubTag(rootEl, "nick");
    if (nickEl != null && nickEl.getAttribute("xmlns").equals("http://jabber.org/protocol/nick"))
        return nickEl.getNodeValue();
    return "";
}

From source file:com.calclab.emite.base.xml.XMLPacketImplGWT.java

License:Open Source License

@Override
public XMLPacket getFirstChild(final String name, final String namespace) {
    checkNotNull(name);/*from w  ww . j a v  a  2s  . c o m*/
    checkNotNull(namespace);

    final NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        final Node node = nodes.item(i);
        if (node.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        final Element element = (Element) node;
        if (!"*".equals(name) && !name.equals(element.getTagName())) {
            continue;
        }

        if (!"*".equals(namespace) && !namespace.equals(element.getNamespaceURI())) {
            continue;
        }

        return new XMLPacketImplGWT(element);
    }

    return null;
}

From source file:com.calclab.emite.base.xml.XMLPacketImplGWT.java

License:Open Source License

@Override
public ImmutableList<XMLPacket> getChildren(final String name, final String namespace) {
    checkNotNull(name);/*from  w w w  .ja  v a  2  s. co  m*/
    checkNotNull(namespace);

    final ImmutableList.Builder<XMLPacket> result = ImmutableList.builder();

    final NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        final Node node = nodes.item(i);
        if (node.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        final Element element = (Element) node;
        if (!"*".equals(name) && !name.equals(element.getTagName())) {
            continue;
        }

        if (!"*".equals(namespace) && !namespace.equals(element.getNamespaceURI())) {
            continue;
        }

        result.add(new XMLPacketImplGWT(element));
    }

    return result.build();
}

From source file:com.colinalworth.xmlview.client.ElementCell.java

License:Apache License

@Override
public void onBrowserEvent(Cell.Context context, com.google.gwt.dom.client.Element parent, Node value,
        NativeEvent event, ValueUpdater<Node> valueUpdater) {
    super.onBrowserEvent(context, parent, value, event, valueUpdater);
    com.google.gwt.dom.client.Element target = event.getEventTarget().cast();

    String eventType = event.getType();

    // if the user clicked on the context menu, show it
    if ("click".equals(eventType) && target.getClassName().equals("actions")) {
        menu.setPopupPosition(event.getClientX(), event.getClientY());
        menu.show(value);//from   w ww. ja  v a 2s  .  co m
        return;
    }

    // otherwise, if the user is currently editing, interpret their commands as edit comands
    if (isEditing(context, parent, value)) {
        // Ignore events that don't target the input.
        if (!"INPUT".equals(target.getTagName()) && !target.getTagName().equals("TEXTAREA")) {
            return;
        }
        if ("keyup".equals(eventType)) {
            updateViewState(context.getKey(), value, target);
        } else if ("focus".equals(eventType)) {
            lastKey = context.getKey();
            updateViewState(context.getKey(), value, target);
        } else if ("blur".equals(eventType)) {
            finishEdit(value, target);
            valueUpdater.update(value);
            lastKey = null;
        }
    } else {// last, if not context, and not editing, they are trying to edit, so focus
        if ("click".equals(eventType)) {
            lastKey = context.getKey();
            updateViewState(context.getKey(), value, target);
            setValue(context, parent, value);
            getActiveInput(parent).focus();
        }
    }

}

From source file:com.colinalworth.xmlview.client.ElementCell.java

License:Apache License

@Override
protected void onEnterKeyDown(Cell.Context context, com.google.gwt.dom.client.Element parent, Node value,
        NativeEvent event, ValueUpdater<Node> valueUpdater) {
    //if the event is directed at an input, finish editing, otherwise focus on first elt
    com.google.gwt.dom.client.Element target = event.getEventTarget().cast();
    if (target.getTagName().equals("INPUT") || target.getTagName().equals("SELECT")
            || target.getTagName().equals("TEXTAREA")) {
        finishEdit(value, target);//from  w  w w .  j a  va  2 s.  c  om
        valueUpdater.update(value);
        // TODO move focus to next field (if attr name, then value, if has children, 
        // then first child, if has next sibling, then it, if parent has sibling, then it, 
        // recursively)
    } else {
        this.lastKey = context.getKey();
        parent.getFirstChildElement().focus();
    }
}

From source file:com.sciencegadgets.client.entities.Equation.java

License:Open Source License

/**
 * Checks if the equation is solved, (in the form [variable = number]). 
 * @return variable id - If solved, the variable ID is returned. If not solved, null is returned.
 * @throws Exception//w w w  .  ja va2s .  com
 */
public String getVarIdIfSolved() throws Exception {
    Document doc = PARSE_DOCUMENT(mathML);
    Node eqRootNode = doc.getFirstChild();
    NodeList elements = eqRootNode.getChildNodes();

    ArrayList<String> tagsRequired = new ArrayList<String>();
    tagsRequired.add(TypeSGET.Operation.getTag());
    tagsRequired.add(TypeSGET.Variable.getTag());
    tagsRequired.add(TypeSGET.Number.getTag());

    for (int i = 0; i < elements.getLength(); i++) {
        Element el = (Element) elements.item(i);
        boolean containedTag = tagsRequired.remove(el.getTagName());
        if (!containedTag) {
            return null;
        }
    }

    if (TypeSGET.Number.getTag().equals(elements.item(0).getNodeName())) {
        eqRootNode.appendChild(elements.item(1));
        eqRootNode.appendChild(elements.item(0));
        mathML = eqRootNode.toString();
        reCreateHTML();
    }

    Element var = (Element) elements.item(0);
    return var.getAttribute(MathAttribute.ID.getAttributeName());
}

From source file:com.smartgwt.mobile.client.data.DataSource.java

License:Open Source License

protected static Element extractDataElement(Element rootEl, String dataTagName) {
    Element dataEl = null;//  w  w  w  . j  a  v a2s. com
    if (dataTagName == null) {
        dataEl = rootEl;
    } else {
        // Find the <data> element.
        NodeList children = rootEl.getChildNodes();
        for (int childIndex = 0; childIndex < children.getLength(); ++childIndex) {
            Node child = children.item(childIndex);
            if (!(child instanceof Element))
                continue;
            Element childEl = (Element) child;
            if (dataTagName.equals(childEl.getTagName())) {
                dataEl = childEl;
                break;
            }
        }
    }
    if (dataEl == null) {
        dataEl = rootEl;
    }
    return dataEl;
}