Example usage for org.w3c.dom Attr getName

List of usage examples for org.w3c.dom Attr getName

Introduction

In this page you can find the example usage for org.w3c.dom Attr getName.

Prototype

public String getName();

Source Link

Document

Returns the name of this attribute.

Usage

From source file:org.infoscoop.service.SiteAggregationMenuService.java

private static void buildAuthorizedMenuXml(Element siteNode, StringBuffer buf, boolean noAuth)
        throws ClassNotFoundException {

    NodeList childNodes = siteNode.getChildNodes();
    Collection childSites = new ArrayList();
    Element propertiesNode = null;
    boolean accessible = true;

    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if ("auths".equals(node.getNodeName()) && !noAuth) {
            accessible = false;//  w  w w.  jav a  2 s .  c  om
            Element rolesEl = (Element) node;
            NodeList roles = rolesEl.getElementsByTagName("auth");
            for (int j = 0; j < roles.getLength(); j++) {
                Element auth = (Element) roles.item(j);
                String type = auth.getAttribute("type");
                String regx = auth.getAttribute("regx");
                if (RoleUtil.isPermitted(type, regx)) {
                    accessible = true;
                }
            }
        }
        if ("site".equals(node.getNodeName())) {
            childSites.add(node);
        }
        if ("properties".equals(node.getNodeName())) {
            propertiesNode = (Element) node;
        }
    }
    if (!accessible) {
        return;
    }

    buf.append("<").append(siteNode.getNodeName());
    NamedNodeMap attrs = siteNode.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        buf.append(" ").append(attr.getName()).append("=\"").append(XmlUtil.escapeXmlEntities(attr.getValue()))
                .append("\"");
    }
    buf.append(">\n");

    if (propertiesNode != null) {
        NodeList properties = propertiesNode.getElementsByTagName("property");
        buf.append("<properties>\n");
        for (int i = 0; i < properties.getLength(); i++) {
            Element property = (Element) properties.item(i);
            setElement2Buf(property, buf);
        }
        buf.append("</properties>\n");
    }

    for (Iterator it = childSites.iterator(); it.hasNext();) {
        Element site = (Element) it.next();
        buildAuthorizedMenuXml(site, buf, noAuth);
    }

    buf.append("</").append(siteNode.getNodeName()).append(">\n");

}

From source file:org.infoscoop.service.SiteAggregationMenuService.java

private static void setElement2Buf(Element xml, StringBuffer buf) {
    buf.append("<").append(xml.getNodeName());
    NamedNodeMap attrs = xml.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        buf.append(" ").append(attr.getName()).append("=\"").append(XmlUtil.escapeXmlEntities(attr.getValue()))
                .append("\"");
    }/*from  w  w  w .  j a v a  2s  .co m*/
    if (xml.hasChildNodes()) {
        buf.append(">").append(XmlUtil.escapeXmlEntities(xml.getFirstChild().getNodeValue())).append("</")
                .append(xml.getNodeName()).append(">");
    } else {
        buf.append("/>\n");
    }
}

From source file:org.jboss.bpm.console.server.util.DOMUtils.java

/** Get the attributes as Map<QName, String>
 *///from  w  w w  .  j  av  a2 s .  com
public static Map getAttributes(Element el) {
    Map attmap = new HashMap();
    NamedNodeMap attribs = el.getAttributes();
    for (int i = 0; i < attribs.getLength(); i++) {
        Attr attr = (Attr) attribs.item(i);
        String name = attr.getName();
        QName qname = resolveQName(el, name);
        String value = attr.getNodeValue();
        attmap.put(qname, value);
    }
    return attmap;
}

From source file:org.jboss.bpm.console.server.util.DOMUtils.java

/** Copy attributes between elements
 *//* w  w w . j  a  va2s .com*/
public static void copyAttributes(Element destElement, Element srcElement) {
    NamedNodeMap attribs = srcElement.getAttributes();
    for (int i = 0; i < attribs.getLength(); i++) {
        Attr attr = (Attr) attribs.item(i);
        String uri = attr.getNamespaceURI();
        String qname = attr.getName();
        String value = attr.getNodeValue();

        // Prevent DOMException: NAMESPACE_ERR: An attempt is made to create or
        // change an object in a way which is incorrect with regard to namespaces.
        if (uri == null && qname.startsWith("xmlns")) {
            log.trace("Ignore attribute: [uri=" + uri + ",qname=" + qname + ",value=" + value + "]");
        } else {
            destElement.setAttributeNS(uri, qname, value);
        }
    }
}

From source file:org.omg.bpmn.miwg.util.xml.diff.AbstractXmlDifferenceListener.java

private boolean containsIgnorableAttributeValues(Node node) {
    NamedNodeMap attrs = node.getAttributes();
    if (attrs == null) {
        return false;
    }/*w w  w  .j a  v  a  2s  .  c o  m*/

    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        if (isEmptyOrIgnorableAttributeValue(attr.getValue(), attr.getName())) {
            return true;
        }
    }
    return false;
}

From source file:org.openestate.io.core.XmlUtils.java

private static void printNode(Element node, int indent) {
    String prefix = (indent > 0) ? StringUtils.repeat(">", indent) + " " : "";
    LOGGER.debug(prefix + "<" + node.getTagName() + "> / " + node.getNamespaceURI() + " / " + node.getPrefix());

    prefix = StringUtils.repeat(">", indent + 1) + " ";
    NamedNodeMap attribs = node.getAttributes();
    for (int i = 0; i < attribs.getLength(); i++) {
        Attr attrib = (Attr) attribs.item(i);
        LOGGER.debug(prefix + "@" + attrib.getName() + " / " + attrib.getNamespaceURI() + " / "
                + attrib.getPrefix());/*  www . j  a  va2s  .co m*/
    }
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            XmlUtils.printNode((Element) child, indent + 1);
        }
    }
}

From source file:org.opensingular.form.io.SFormXMLUtil.java

private static void lerAtributos(SInstance instancia, MElement xml) {
    NamedNodeMap atributos = xml.getAttributes();
    if (atributos != null) {
        for (int i = 0; i < atributos.getLength(); i++) {
            Attr at = (Attr) atributos.item(i);
            if (at.getName().equals(ATRIBUTO_ID)) {
                instancia.setId(Integer.valueOf(at.getValue()));
            } else if (!at.getName().equals(ATRIBUTO_LAST_ID)) {
                getInternalAccess().setAttributeValueSavingForLatter(instancia, at.getName(), at.getValue());
            }/* w w  w.  jav a2 s.c  o m*/
        }
    }
}

From source file:org.regenstrief.util.XMLUtil.java

/**
 * Strips namespaces and prefixes from a Node tree
 * /*w w w  . ja va2 s  .co m*/
 * @param n the root Node
 * @return the stripped Node
 **/
public final static Node stripNamespaces(final Node n) {
    if (n == null) {
        return null;
    }

    final Document doc = n.getOwnerDocument();
    if (n instanceof Element) {
        final Element eOld = (Element) n;
        final Element eNew = doc.createElement(getLocalName(eOld));
        final NamedNodeMap map = eOld.getAttributes();
        for (int i = 0, size = size(map); i < size; i++) {
            final Attr attr = (Attr) map.item(i);
            String name = attr.getName();
            if (name == null) {
                name = attr.getLocalName();
            }
            if (!("xmlns".equals(name) || ((name != null) && name.startsWith("xmlns:"))
                    || "xmlns".equals(attr.getPrefix()))) {
                final int j = name.indexOf(':');
                eNew.setAttribute(j < 0 ? name : name.substring(j + 1), attr.getValue());
            }
        }
        final NodeList list = n.getChildNodes();
        for (int i = 0, size = size(list); i < size; i++) {
            appendChild(eNew, stripNamespaces(list.item(i)));
        }
        return eNew;
    } else if (n instanceof Attr) {
        return null;
    }
    return n.cloneNode(false);
}

From source file:org.sd.xml.DomElement.java

public Attr removeAttributeNode(Attr oldAttr) {
    Attr result = null;//from   w  w  w.  j  a va2s . co m

    if (hasAttributes()) {
        final DomNamedNodeMap attributes = getDomAttributes();
        result = (Attr) attributes.removeNamedItem(oldAttr.getName());
        markAsModified();
    }

    return result;
}

From source file:org.structr.web.entity.dom.DOMElement.java

@Override
public Attr setAttributeNode(final Attr attr) throws DOMException {

    // save existing attribute node
    Attr attribute = getAttributeNode(attr.getName());

    // set value//from  w ww  .j  a v a  2s.  c o  m
    setAttribute(attr.getName(), attr.getValue());

    // set parent of attribute node
    if (attr instanceof DOMAttribute) {
        ((DOMAttribute) attr).setParent(this);
    }

    return attribute;
}