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

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

Introduction

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

Prototype

Attr getAttributeNode(String name);

Source Link

Document

This method retrieves the attribute node which has a name of name.

Usage

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

License:Apache License

/**
 * @param context/*from   w w  w .  ja  va 2 s .  c om*/
 * @param value
 */
private void finishEdit(Node value, com.google.gwt.dom.client.Element target) {
    ElementCell.ViewState state = updateViewState(lastKey, value, target);
    String newValue = target.<InputElement>cast().getValue();
    boolean valid = true;
    Element parent = (Element) value.getParentNode();
    switch (state.section) {
    case AttributeName:
        Attr attr = (Attr) value;
        //TODO this might lose namespace data
        parent.removeAttribute(attr.getName());
        parent.setAttribute(newValue, attr.getValue());

        valid = validator.isAttributeNameValid(parent.getAttributeNode(attr.getName()), parent);
        break;
    case AttributeValue:
        value.setNodeValue(newValue);
        valid = validator.isAttributeValueValid((Attr) value, parent);
        break;
    case Content:
        ((CharacterData) value).setData(newValue);
        valid = validator.isContentsValid((CharacterData) value);
        break;
    case TagName:
        Element elt = (Element) value;
        Element replacement = elt.getOwnerDocument().createElement(newValue);
        while (elt.getChildNodes().getLength() != 0) {
            replacement.appendChild(elt.getChildNodes().item(0));
        }
        //TODO this might lose namespace data
        for (int i = 0; i < elt.getAttributes().getLength(); i++) {
            Attr a = (Attr) elt.getAttributes().item(i);
            replacement.setAttribute(a.getName(), a.getValue());
        }

        parent.replaceChild(replacement, elt);

        valid = validator.isElementNameValid(replacement);
    }
    if (!valid) {
        Window.alert("Seems to be invalid: " + newValue + " in " + parent.getNodeName());
        //TODO mark invalid
    }
    this.lastKey = null;
    target.blur();
}

From source file:org.soa4all.dashboard.gwt.module.wsmolite.client.editor.model.ElementNode.java

License:Apache License

public ElementNode(Element element) {
    set("tag", element.getNodeName());
    set("ns", element.getNamespaceURI());
    if (element.getAttributeNode("xID") != null) {
        set("xID", element.getAttribute("xID"));
        element.removeAttribute("xID");
    }// w  w w  .j  av a  2  s.c o m
    if (element.getAttributeNode("xTooltip") != null) {
        set("xTooltip", element.getAttribute("xTooltip"));
        element.removeAttribute("xTooltip");
    }
    if (element.getAttributeNode("xLab") != null) {
        set("lab", element.getAttribute("xLab"));
        element.removeAttribute("xLab");
    }
    parseAttributes(element.getAttributes());
}