Search in sources :

Example 11 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project openhab1-addons by openhab.

the class FeatureTemplateLoader method s_makeHandlerEntry.

private static HandlerEntry s_makeHandlerEntry(Element e) throws ParsingException {
    String handler = e.getTextContent();
    if (handler == null) {
        throw new ParsingException("Could not find Handler for: " + e.getTextContent());
    }
    NamedNodeMap attributes = e.getAttributes();
    HashMap<String, String> params = new HashMap<String, String>();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node n = attributes.item(i);
        params.put(n.getNodeName(), n.getNodeValue());
    }
    return new HandlerEntry(handler, params);
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) HashMap(java.util.HashMap) ParsingException(org.openhab.binding.insteonplm.internal.utils.Utils.ParsingException) Node(org.w3c.dom.Node)

Example 12 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project OpenAM by OpenRock.

the class ObligationImpl method processElement.

private void processElement(Element element) throws XACMLException {
    String value = null;
    if (element == null) {
        XACMLSDKUtils.debug.error("ObligationImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    // First check that we're really parsing an Obligation
    if (!element.getLocalName().equals(XACMLConstants.OBLIGATION)) {
        XACMLSDKUtils.debug.error("ObligationImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    NamedNodeMap attrs = element.getAttributes();
    try {
        obligationId = new URI(attrs.getNamedItem(XACMLConstants.OBLIGATION_ID).getNodeValue());
    } catch (Exception e) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("attribute_not_uri"));
    }
    if (obligationId == null) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("attribute_missing"));
    }
    try {
        fulfillOn = attrs.getNamedItem(XACMLConstants.FULFILL_ON).getNodeValue();
    } catch (Exception e) {
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("error_parsing_attribute"));
    }
    // now we get the AttributeAssignment(s)
    // AttributeAssignment requires AttributeId and DataType 
    NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if ((node.getNodeType() == Node.ELEMENT_NODE)) {
            if (node.getLocalName().equals(XACMLConstants.ATTRIBUTE_ASSIGNMENT)) {
                if (attributeAssignments == null) {
                    attributeAssignments = new ArrayList();
                }
                Element aa = (Element) node;
                // aa should have attributes AtributeId, DataType
                String aid = aa.getAttribute(XACMLConstants.ATTRIBUTE_ID);
                if ((aid == null) || (aid.length() == 0)) {
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_attribute"));
                }
                String dt = aa.getAttribute(XACMLConstants.DATA_TYPE);
                if ((dt == null) || (dt.length() == 0)) {
                    throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_attribute"));
                }
                attributeAssignments.add(aa);
            } else {
                throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_element"));
            }
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) URI(java.net.URI) XACMLException(com.sun.identity.xacml.common.XACMLException) XACMLException(com.sun.identity.xacml.common.XACMLException)

Example 13 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project midpoint by Evolveum.

the class DOMUtil method showDomNode.

private static void showDomNode(Node node, StringBuilder sb, int level) {
    if (sb == null) {
        // buffer not provided, return immediately
        return;
    }
    // indent
    for (int i = 0; i < level; i++) {
        sb.append("  ");
    }
    if (node == null) {
        sb.append("null\n");
    } else {
        sb.append(node.getNodeName());
        sb.append(" (");
        NamedNodeMap attributes = node.getAttributes();
        boolean broken = false;
        if (attributes != null) {
            for (int ii = 0; ii < attributes.getLength(); ii++) {
                Node attribute = attributes.item(ii);
                sb.append(attribute.getPrefix());
                sb.append(":");
                sb.append(attribute.getLocalName());
                sb.append("='");
                sb.append(attribute.getNodeValue());
                sb.append("',");
                if (attribute.getPrefix() == null && attribute.getLocalName().equals("xmlns") && (attribute.getNodeValue() == null || attribute.getNodeValue().isEmpty())) {
                    broken = true;
                }
            }
        }
        sb.append(")");
        if (broken) {
            sb.append(" *** WARNING: empty default namespace");
        }
        sb.append("\n");
        NodeList childNodes = node.getChildNodes();
        for (int ii = 0; ii < childNodes.getLength(); ii++) {
            Node subnode = childNodes.item(ii);
            showDomNode(subnode, sb, level + 1);
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList)

Example 14 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project OpenAM by OpenRock.

the class ValidationErrorHandler method printAttributeValue.

/**
     * Print SAML Attribute Element and replace its prefix with the input
     * prefix.
     * 
     * @param node
     *            A DOM tree Node
     * @param prefix
     *            A String representing the new prefix
     * @return An xml String representation of the DOM tree.
     */
public static String printAttributeValue(Element node, String prefix) {
    if (node == null) {
        return null;
    }
    StringBuffer xml = new StringBuffer(100);
    xml.append('<');
    xml.append(prefix).append(node.getLocalName());
    NamedNodeMap attrs = node.getAttributes();
    int length = attrs.getLength();
    for (int i = 0; i < length; i++) {
        Attr attr = (Attr) attrs.item(i);
        xml.append(' ');
        xml.append(attr.getNodeName());
        xml.append("=\"");
        // xml.append(normalize(attr.getNodeValue()));
        xml.append(attr.getNodeValue());
        xml.append('"');
    }
    xml.append('>');
    NodeList children = node.getChildNodes();
    if (children != null) {
        int len = children.getLength();
        for (int i = 0; i < len; i++) {
            xml.append(print(children.item(i)));
        }
    }
    xml.append("</");
    xml.append(prefix).append(node.getLocalName());
    xml.append('>');
    return xml.toString();
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Attr(org.w3c.dom.Attr)

Example 15 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project OpenAM by OpenRock.

the class ValidationErrorHandler method getNodeAttributeValue.

public static String getNodeAttributeValue(Node node, String attrName) {
    NamedNodeMap attrs = node.getAttributes();
    if (attrs == null)
        return (null);
    Node value = attrs.getNamedItem(attrName);
    if (value == null)
        return (null);
    return (value.getNodeValue());
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node)

Aggregations

NamedNodeMap (org.w3c.dom.NamedNodeMap)991 Node (org.w3c.dom.Node)688 NodeList (org.w3c.dom.NodeList)338 Attr (org.w3c.dom.Attr)295 Element (org.w3c.dom.Element)237 Document (org.w3c.dom.Document)153 ArrayList (java.util.ArrayList)92 HashMap (java.util.HashMap)91 DocumentBuilder (javax.xml.parsers.DocumentBuilder)59 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)58 IOException (java.io.IOException)53 SAXException (org.xml.sax.SAXException)41 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)40 List (java.util.List)36 Map (java.util.Map)33 File (java.io.File)27 InputStream (java.io.InputStream)26 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)25 DOMException (org.w3c.dom.DOMException)25 ByteArrayInputStream (java.io.ByteArrayInputStream)19