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);
}
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"));
}
}
}
}
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);
}
}
}
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();
}
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());
}
Aggregations