List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:com.connexta.arbitro.attr.xacml3.AttributeSelector.java
/** * Creates a new <code>AttributeSelector</code> based on the DOM root of the XML type. Note that * as of XACML 1.1 the XPathVersion element is required in any policy that uses a selector, so * if the <code>xpathVersion</code> string is null, then this will throw an exception. * * @param root the root of the DOM tree for the XML AttributeSelectorType XML type * @param metaData the meta-data associated with the containing policy * * @return an <code>AttributeSelector</code> * * @throws ParsingException if the AttributeSelectorType was invalid */// w ww .j a v a 2 s . c o m public static AttributeSelector getInstance(Node root, PolicyMetaData metaData) throws ParsingException { URI category = null; URI type = null; URI contextSelectorId = null; String path = null; boolean mustBePresent = false; String xpathVersion = metaData.getXPathIdentifier(); // make sure we were given an xpath version if (xpathVersion == null) { throw new ParsingException("An XPathVersion is required for " + "any policies that use selectors"); } NamedNodeMap attrs = root.getAttributes(); try { // there's always a DataType attribute category = new URI(attrs.getNamedItem("Category").getNodeValue()); } catch (Exception e) { throw new ParsingException("Error parsing required Category " + "attribute in AttributeSelector", e); } try { // there's always a DataType attribute type = new URI(attrs.getNamedItem("DataType").getNodeValue()); } catch (Exception e) { throw new ParsingException("Error parsing required DataType " + "attribute in AttributeSelector", e); } try { // there's always a RequestPath path = attrs.getNamedItem("Path").getNodeValue(); } catch (Exception e) { throw new ParsingException("Error parsing required " + "Path attribute in " + "AttributeSelector", e); } try { String stringValue = attrs.getNamedItem("MustBePresent").getNodeValue(); mustBePresent = Boolean.parseBoolean(stringValue); } catch (Exception e) { throw new ParsingException("Error parsing required MustBePresent attribute " + "in AttributeSelector", e); } try { Node node = attrs.getNamedItem("ContextSelectorId"); if (node != null) { contextSelectorId = new URI(node.getNodeValue()); } } catch (Exception e) { throw new ParsingException("Error parsing required MustBePresent attribute " + "in AttributeSelector", e); } return new AttributeSelector(category, type, contextSelectorId, path, mustBePresent, xpathVersion); }
From source file:com.jaspersoft.jasperserver.ws.xml.Unmarshaller.java
private static ListItem readResourceParameter(Node rpNode) { ListItem rp = new ListItem(); NamedNodeMap nodeAttributes = rpNode.getAttributes(); if (nodeAttributes.getNamedItem("name") != null) rp.setLabel(nodeAttributes.getNamedItem("name").getNodeValue()); if (nodeAttributes.getNamedItem("isListItem") != null) rp.setIsListItem(nodeAttributes.getNamedItem("isListItem").getNodeValue().equals("true")); rp.setValue(readPCDATA(rpNode));/*w ww . j ava 2 s .c o m*/ return rp; }
From source file:com.jaeksoft.searchlib.analysis.ClassFactory.java
/** * /*from ww w.j a v a2s . c o m*/ * @param classFactory * @return * @throws SearchLibException * @throws ClassNotFoundException * @throws DOMException */ protected static ClassFactory create(Config config, String packageName, Node node, String attributeNodeName) throws SearchLibException, DOMException, ClassNotFoundException { if (node == null) return null; NamedNodeMap nnm = node.getAttributes(); if (nnm == null) return null; Node classNode = nnm.getNamedItem(ClassPropertyEnum.CLASS.getAttribute()); if (classNode == null) return null; ClassFactory newClassFactory = create(config, packageName, classNode.getNodeValue()); newClassFactory.addProperties(nnm); List<Node> attrNodes = DomUtils.getNodes(node, attributeNodeName, "attribute"); if (attrNodes != null) for (Node attrNode : attrNodes) newClassFactory.addProperty(DomUtils.getAttributeText(attrNode, "name"), attrNode.getTextContent()); return newClassFactory; }
From source file:com.jaspersoft.jasperserver.ws.xml.Unmarshaller.java
private static ResourceProperty readResourceProperty(Node rpNode) { ResourceProperty rp = new ResourceProperty(null); NamedNodeMap nodeAttributes = rpNode.getAttributes(); if (nodeAttributes.getNamedItem("name") != null) rp.setName(nodeAttributes.getNamedItem("name").getNodeValue()); NodeList childsOfChild = rpNode.getChildNodes(); for (int c_count = 0; c_count < childsOfChild.getLength(); c_count++) { Node child_child = (Node) childsOfChild.item(c_count); if (child_child.getNodeType() == Node.ELEMENT_NODE && child_child.getNodeName().equals("value")) { rp.setValue(readPCDATA(child_child)); } else if (child_child.getNodeType() == Node.ELEMENT_NODE && child_child.getNodeName().equals("resourceProperty")) { rp.getProperties().add(readResourceProperty(child_child)); }/*w ww . j a v a2s . co m*/ } return rp; }
From source file:Main.java
/** * Convert the given Node to an XML String. * <p>/*w w w . j a v a 2 s. c o m*/ * This method is a simplified version of... * <p> * <code> * ByteArrayOutputStream out = new ByteArrayOutputStream();<br/> * javax.xml.Transformer transformer = TransformerFactory.newInstance().newTransformer();<br/> * transformer.transform( new DOMSource( node ), new StreamResult( out ));<br/> * return out.toString(); * </code> * <p> * ...but not all platforms (eg. Android) support <code>javax.xml.transform.Transformer</code>. * * @param indent * how much to indent the output. -1 for no indent. */ private static String nodeToString(Node node, int indent) { // Text nodes if (node == null) { return null; } if (!(node instanceof Element)) { String value = node.getNodeValue(); if (value == null) { return null; } return escapeForXml(value.trim()); } // (use StringBuffer for J2SE 1.4 compatibility) StringBuffer buffer = new StringBuffer(); // Open tag indent(buffer, indent); String nodeName = escapeForXml(node.getNodeName()); buffer.append("<"); buffer.append(nodeName); // Changing namespace String namespace = node.getNamespaceURI(); Node parentNode = node.getParentNode(); if (namespace != null && (parentNode == null || !namespace.equals(parentNode.getNamespaceURI()))) { buffer.append(" xmlns=\""); buffer.append(namespace); buffer.append("\""); } // Attributes NamedNodeMap attributes = node.getAttributes(); // Always put name first for easy unit tests Node name = attributes.getNamedItem("name"); if (name != null) { buffer.append(" name=\""); buffer.append(escapeForXml(name.getNodeValue())); buffer.append("\""); } for (int loop = 0; loop < attributes.getLength(); loop++) { Node attribute = attributes.item(loop); String attributeName = attribute.getNodeName(); // (I'm a bit surprised xmlns is an attribute - is that a bug?) if ("xmlns".equals(attributeName)) { continue; } // (always put name first for easy unit tests) if ("name".equals(attributeName)) { continue; } buffer.append(" "); buffer.append(escapeForXml(attributeName)); buffer.append("=\""); buffer.append(escapeForXml(attribute.getNodeValue())); buffer.append("\""); } // Children (if any) NodeList children = node.getChildNodes(); int length = children.getLength(); if (length == 0) { buffer.append("/>"); } else { buffer.append(">"); int nextIndent = indent; if (indent != -1) { nextIndent++; } for (int loop = 0; loop < length; loop++) { Node childNode = children.item(loop); if (indent != -1 && childNode instanceof Element) { buffer.append("\n"); } buffer.append(nodeToString(childNode, nextIndent)); } if (indent != -1 && buffer.charAt(buffer.length() - 1) == '>') { buffer.append("\n"); indent(buffer, indent); } // Close tag buffer.append("</"); buffer.append(nodeName); buffer.append(">"); } return buffer.toString(); }
From source file:com.ryderbot.utils.ModelUtils.java
public static AccountBalance generateAccountBalance(NamedNodeMap attributes) { Long accountID = new Long(attributes.getNamedItem("accountID").getNodeValue()); Long accountKey = new Long(attributes.getNamedItem("accountKey").getNodeValue()); Double balance = new Double(attributes.getNamedItem("balance").getNodeValue()); AccountBalance accountBalance = new AccountBalance(accountID); accountBalance.setAccountKey(accountKey); accountBalance.setBalance(balance);//from w ww.j av a 2 s. co m return accountBalance; }
From source file:com.ryderbot.utils.ModelUtils.java
public static Blueprint generateBlueprint(NamedNodeMap attributes) { Long itemID = Long.parseLong(attributes.getNamedItem("itemID").getNodeValue()); Long locationID = Long.parseLong(attributes.getNamedItem("locationID").getNodeValue()); Long typeID = Long.parseLong(attributes.getNamedItem("typeID").getNodeValue()); String typeName = attributes.getNamedItem("typeName").getNodeValue(); Integer flagID = Integer.parseInt(attributes.getNamedItem("flagID").getNodeValue()); Integer quantity = Integer.parseInt(attributes.getNamedItem("quantity").getNodeValue()); Integer timeEfficiency = Integer.parseInt(attributes.getNamedItem("timeEfficiency").getNodeValue()); Integer materialEfficiency = Integer.parseInt(attributes.getNamedItem("materialEfficiency").getNodeValue()); Integer runs = Integer.parseInt(attributes.getNamedItem("runs").getNodeValue()); Blueprint blueprint = new Blueprint(itemID); blueprint.setLocationID(locationID); blueprint.setTypeID(typeID);/*from ww w . ja v a2 s .c o m*/ blueprint.setTypeName(typeName); blueprint.setFlagID(flagID); blueprint.setQuantity(quantity); blueprint.setTimeEfficiency(timeEfficiency); blueprint.setMaterialEfficiency(materialEfficiency); blueprint.setRuns(runs); return blueprint; }
From source file:com.connexta.arbitro.attr.xacml3.AttributeDesignator.java
/** * Creates a new <code>AttributeDesignator</code> based on the DOM root of the XML data. * * @param root the DOM root of the AttributeDesignatorType XML type * @return the designator//w w w . j a v a 2 s .c om * @throws ParsingException if the AttributeDesignatorType was invalid */ public static AttributeDesignator getInstance(Node root) throws ParsingException { URI type = null; URI id = null; String issuer = null; URI category = null; boolean mustBePresent = false; // First check to be sure the node passed is indeed a AttributeDesignator node. String tagName = DOMHelper.getLocalName(root); if (!tagName.equals("AttributeDesignator")) { throw new ParsingException( "AttributeDesignator cannot be constructed using " + "type: " + DOMHelper.getLocalName(root)); } NamedNodeMap attrs = root.getAttributes(); try { id = new URI(attrs.getNamedItem("AttributeId").getNodeValue()); } catch (Exception e) { throw new ParsingException("Required AttributeId missing in " + "AttributeDesignator", e); } try { category = new URI(attrs.getNamedItem("Category").getNodeValue()); } catch (Exception e) { throw new ParsingException("Required Category missing in " + "AttributeDesignator", e); } try { String nodeValue = attrs.getNamedItem("MustBePresent").getNodeValue(); if ("true".equals(nodeValue)) { mustBePresent = true; } } catch (Exception e) { throw new ParsingException("Required MustBePresent missing in " + "AttributeDesignator", e); } try { type = new URI(attrs.getNamedItem("DataType").getNodeValue()); } catch (Exception e) { throw new ParsingException("Required DataType missing in " + "AttributeDesignator", e); } try { Node node = attrs.getNamedItem("Issuer"); if (node != null) { issuer = node.getNodeValue(); } } catch (Exception e) { throw new ParsingException("Error parsing AttributeDesignator " + "optional attributes", e); } return new AttributeDesignator(type, id, mustBePresent, issuer, category); }
From source file:de.akra.idocit.wsdl.services.DocumentationParser.java
/** * Extracts from the docpart element the addressees with their individual * documentation./*from w w w . j av a2 s . c om*/ * * @param docpartElem * The docpart element that should be parsed. * @return A new {@link Documentation} with the documentations for the addresses. */ private static Documentation parseAddressees(Node docpartElem) { Documentation doc = new Documentation(); Map<Addressee, String> docMap = doc.getDocumentation(); List<Addressee> addresseeSequence = doc.getAddresseeSequence(); NodeList childList = docpartElem.getChildNodes(); // iterate all child nodes to find addressee elements for (int i = 0; i < childList.getLength(); i++) { Node item = childList.item(i); // if found addressee element, add the documentation to the map // in general there should be only addressee elements if (item.getNodeName().equals(ADDRESSEE_ELEMENT_NAME)) { NamedNodeMap attributes = item.getAttributes(); Node attribute = attributes.getNamedItem(ADDRESSEE_GROUP_ATTRIBUTE_NAME); Addressee addressee = DescribedItemUtils.findAddressee(attribute.getNodeValue()); logger.log(Level.FINE, attribute.getNodeName() + " -> " + attribute.getNodeValue() + " | Addressee=" + addressee.getName()); String text = readTextFromAddresseElement(item); // add documentation for addressee docMap.put(addressee, text); // save sequence of adding addressees addresseeSequence.add(addressee); } else { logger.log(Level.FINE, "Expect <" + ADDRESSEE_ELEMENT_NAME + ">, but found: name=" + item.getNodeName() + ", type=" + item.getNodeType()); } } return doc; }
From source file:de.akra.idocit.wsdl.services.DocumentationParser.java
/** * Extracts from the docpart element the addressees with their individual * documentations and the attributes/*from ww w. j ava2 s . c om*/ * {@link DocumentationParser#THEMATIC_ROLE_ATTRIBUTE_NAME}, * {@link DocumentationParser#THEMATIC_SCOPE_ATTRIBUTE_NAME} and * {@link DocumentationParser#SIGNATURE_ELEMENT_ATTRIBUTE_NAME} of the docpart and * returns a new {@link Documentation} with this information. If an attribute is not * available or has an unknown value it is simply ignored and not set. * * @param docpartElem * docpart element that should be parsed. * @return A new {@link Documentation} with the parsed information. */ private static Documentation parseDocPartElement(Node docpartElem) { Documentation doc = parseAddressees(docpartElem); // read attributes NamedNodeMap attributes = docpartElem.getAttributes(); Node attr; if ((attr = attributes.getNamedItem(THEMATIC_ROLE_ATTRIBUTE_NAME)) != null) { logger.log(Level.FINE, THEMATIC_ROLE_ATTRIBUTE_NAME + "=\"" + attr.getNodeValue() + "\""); ThematicRole role = DescribedItemUtils.findThematicRole(attr.getNodeValue()); doc.setThematicRole(role); } if ((attr = attributes.getNamedItem(DocumentationParser.SIGNATURE_ELEMENT_ATTRIBUTE_NAME)) != null) { logger.log(Level.FINE, DocumentationParser.SIGNATURE_ELEMENT_ATTRIBUTE_NAME + "=\"" + attr.getNodeValue() + "\""); doc.setSignatureElementIdentifier(attr.getNodeValue()); } if ((attr = attributes.getNamedItem(DocumentationParser.ERROR_DOCUMENTATION_ATTRIBUTE_NAME)) != null) { logger.log(Level.FINE, DocumentationParser.ERROR_DOCUMENTATION_ATTRIBUTE_NAME + "=\"" + attr.getNodeValue() + "\""); doc.setErrorCase(Boolean.parseBoolean(attr.getNodeValue())); } return doc; }