List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:de.elbe5.base.data.XmlData.java
public LocalDateTime getDateAttribute(Node node, String key) { LocalDateTime result = null;//from w w w . j a va 2 s . c o m if (node.hasAttributes()) { NamedNodeMap attrMap = node.getAttributes(); Node attr = attrMap.getNamedItem(key); if (attr != null) { try { result = LocalDateTime.parse(attr.getNodeValue(), datetimeFormatter); } catch (Exception ignored) { } } } return result; }
From source file:de.elbe5.base.data.XmlData.java
public Locale getLocaleAttribute(Node node, String key) { Locale result = Locale.getDefault(); if (node.hasAttributes()) { NamedNodeMap attrMap = node.getAttributes(); Node attr = attrMap.getNamedItem(key); if (attr != null) { try { result = new Locale(attr.getNodeValue()); } catch (Exception ignored) { }/*from www . jav a2 s. com*/ } } return result; }
From source file:com.ibm.sbt.test.lib.MockSerializer.java
public HttpResponse replayResponse() throws ClientServicesException { try {//ww w. ja va 2 s. c om Node r = getReader().next(); NamedNodeMap nnm = r.getAttributes(); String code = nnm.getNamedItem("statusCode").getTextContent(); String reason = nnm.getNamedItem("statusReason").getTextContent(); Node headers = (Node) DOMUtil.evaluateXPath(r, "./headers").getSingleNode(); Node data = (Node) DOMUtil.evaluateXPath(r, "./data").getSingleNode(); String entity = null; if (data != null) { if (data.getFirstChild() == null) entity = ""; else entity = ((CharacterData) data.getFirstChild()).getData(); } Iterator<Node> hIt = (Iterator<Node>) DOMUtil.evaluateXPath(headers, "./header").getNodeIterator(); ArrayList<Header> allHeaders = new ArrayList<Header>(); while (hIt.hasNext()) { Node headerNode = hIt.next(); String name = ((Node) DOMUtil.evaluateXPath(headerNode, "./name").getSingleNode()).getTextContent(); String value = ((Node) DOMUtil.evaluateXPath(headerNode, "./value").getSingleNode()) .getTextContent(); allHeaders.add(new BasicHeader(name, value)); } return buildResponse(allHeaders.toArray(new Header[allHeaders.size()]), Integer.valueOf(code), reason, entity); } catch (FileNotFoundException e) { StackTraceElement trace = getStackTraceElement(); String fullClassName = trace.getClassName(); String methodName = trace.getMethodName(); String endpointName = getEndpointName(); throw new MockingException(e, "Mocking file missing for test: " + fullClassName + "." + methodName + "/" + endpointName); } catch (Exception e) { throw new MockingException(e, "Corrupted Mocking file, please regenerate: " + getPath()); } }
From source file:de.xplib.xdbm.util.I18N.java
/** * @param localeIn ...//ww w . ja v a2 s. co m */ public void setLocale(final Locale localeIn) { InputStream is = this.getClass().getClassLoader() .getResourceAsStream("de/xplib/xdbm/ui/res/i18n/" + localeIn.getLanguage() + ".xml"); try { DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = db.parse(is); this.entries.clear(); NodeList nl = doc.getDocumentElement().getElementsByTagName("entry"); for (int i = 0, l = nl.getLength(); i < l; i++) { NamedNodeMap nnm = nl.item(i).getAttributes(); if (nnm == null) { continue; } Node n = nnm.getNamedItem("key"); if (n == null) { continue; } this.entries.put(n.getNodeValue(), nnm); } this.notifyObservers(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.moss.schematrax.SchemaData.java
private void initVersions(Document document) throws MissingElementException { NamedNodeMap attributes = document.getDocumentElement().getAttributes(); String currentVersionId = attributes.getNamedItem(ROOT_TAG_CURRENT_VERSION_ATTRIBUTE).getNodeValue(); NodeList nodes = document.getElementsByTagName(VERSION_TAG_NAME); versions = new SchemaVersion[nodes.getLength()]; for (int x = 0; x < nodes.getLength(); x++) { Node versionTag = nodes.item(x); Node versionId = versionTag.getAttributes().getNamedItem("id"); LazyLoadingSchemaVersion version = new LazyLoadingSchemaVersion(versionId.getNodeValue()); // Set the prior_version Node priorVersionAttribute = versionTag.getAttributes() .getNamedItem(VERSION_TAG_PRIOR_VERSION_ATTRIBUTE); if (priorVersionAttribute != null) version.setPriorVersionId(priorVersionAttribute.getNodeValue()); Node createScriptAttribute = versionTag.getAttributes() .getNamedItem(VERSION_TAG_CREATE_SCRIPT_ATTRIBUTE); if (createScriptAttribute != null) version.setCreationScript(getUpdate(createScriptAttribute.getNodeValue())); versions[x] = version;/*from w ww.java 2s. c o m*/ NodeList children = versionTag.getChildNodes(); for (int y = 0; y < children.getLength(); y++) { Node child = children.item(y); if (child.getNodeName().equals(APPLY_UPDATE_TAG_NAME)) { String updateId = child.getAttributes().getNamedItem("update_id").getNodeValue(); SchemaUpdate update = getUpdate(updateId); version.addUpdate(update); } } } if (currentVersionId != null) { for (int x = 0; x < versions.length; x++) { SchemaVersion version = versions[x]; if (version.getId().equals(currentVersionId)) { this.currentVersion = version; } } } }
From source file:com.signavio.warehouse.business.util.jpdl4.Sql.java
public Sql(org.w3c.dom.Node sql) { this.uuid = "oryx_" + UUID.randomUUID().toString(); NamedNodeMap attributes = sql.getAttributes(); this.name = JpdlToJson.getAttribute(attributes, "name"); this.unique = Boolean.parseBoolean(JpdlToJson.getAttribute(attributes, "unique")); this.var = JpdlToJson.getAttribute(attributes, "var"); this.bounds = JpdlToJson.getBounds(attributes.getNamedItem("g")); if (sql.hasChildNodes()) for (org.w3c.dom.Node a = sql.getFirstChild(); a != null; a = a.getNextSibling()) { if (a.getNodeName().equals("query")) this.query = a.getTextContent(); if (a.getNodeName().equals("parameters")) this.parameters = new Parameters(a); }/*from w w w .j ava 2s . co m*/ }
From source file:com.avlesh.web.filter.responseheaderfilter.ConfigProcessor.java
/** * Default response header parser for the filter. * <br/>// ww w .j a va 2s .c om * Parses all the <header> nodes inside a <response-headers> * <br/> * Returns a <code>null</code>, if there are no "valid" <header> nodes to be parsed. A <header> node * is considered invalid if any of the attributes (<code>key</code> or <code>value</code>) is missing or undeclared. * * @param node (<response-headers> {@link Node} in the <code>configFile</code>) * @return {@link Mapping.ResponseHeader} (parsed <header> tags in the <code>node</code>) */ private List<Mapping.ResponseHeader> getResponseHeader(Node node) { List<Mapping.ResponseHeader> responseHeaders = null; NodeList nodeList = node.getChildNodes(); if (nodeList != null && nodeList.getLength() > 0) { for (int k = 0; k < nodeList.getLength(); k++) { Node responseHeaderNode = nodeList.item(k); String responseHeaderNodeName = responseHeaderNode.getNodeName(); //parse the <response-headers> tags for the incoming node //if there are multiple such headers, last one wins if (Constants.RESPONSE_HEADERS.equalsIgnoreCase(responseHeaderNodeName)) { responseHeaders = new ArrayList<Mapping.ResponseHeader>(); NodeList responseHeaderNodes = responseHeaderNode.getChildNodes(); if (responseHeaderNodes != null && responseHeaderNodes.getLength() > 0) { for (int l = 0; l < responseHeaderNodes.getLength(); l++) { Node headerNode = responseHeaderNodes.item(l); if (Constants.HEADER.equalsIgnoreCase(headerNode.getNodeName())) { NamedNodeMap attributeMap = headerNode.getAttributes(); Node keyNode = attributeMap.getNamedItem("key"); Node valueNode = attributeMap.getNamedItem("value"); //accepting a <header> node, only if the "key" and "value" attributes are present if (keyNode != null && valueNode != null) { String key = keyNode.getNodeValue(); String value = valueNode.getNodeValue(); //empty values for either the "key" or the "value" are not acceptable if (StringUtils.isNotEmpty(key) && StringUtils.isNotEmpty(value)) { Mapping.ResponseHeader responseHeader = new Mapping.ResponseHeader(); responseHeader.setResponseHeaderKey(key); responseHeader.setResponseHeaderValue(value); responseHeaders.add(responseHeader); } } //something wrong with the header declaration, issuing a warning if (responseHeaders.isEmpty()) { logger.warn("Skipping a <" + Constants.HEADER + "> node. " + "key and value are required attributes for these nodes"); } } } } } } } return responseHeaders; }
From source file:hudson.plugins.plot.XMLSeries.java
/** * Convert a given object into a String. * //from w w w. j av a2 s. c om * @param obj * Xpath Object * @return String representation of the node */ private String nodeToString(Object obj) { String ret = null; if (nodeType == XPathConstants.BOOLEAN) { return (((Boolean) obj)) ? "1" : "0"; } if (nodeType == XPathConstants.NUMBER) return ((Double) obj).toString().trim(); if (nodeType == XPathConstants.NODE || nodeType == XPathConstants.NODESET) { if (obj instanceof String) { ret = ((String) obj).trim(); } else { if (null == obj) { return null; } Node node = (Node) obj; NamedNodeMap nodeMap = node.getAttributes(); if ((null != nodeMap) && (null != nodeMap.getNamedItem("time"))) { ret = nodeMap.getNamedItem("time").getTextContent(); } if (null == ret) { ret = node.getTextContent().trim(); } } } if (nodeType == XPathConstants.STRING) ret = ((String) obj).trim(); // for Node/String/NodeSet, try and parse it as a double. // we don't store a double, so just throw away the result. Scanner scanner = new Scanner(ret); if (scanner.hasNextDouble()) { return String.valueOf(scanner.nextDouble()); } return null; }
From source file:eu.planets_project.tb.impl.properties.ManuallyMeasuredPropertyHandlerImpl.java
private List<ManuallyMeasuredProperty> parseManualPropertiesXML(Element root, boolean bUserCreated) { List<ManuallyMeasuredProperty> ret = new ArrayList<ManuallyMeasuredProperty>(); NodeList nProperties = root.getChildNodes(); for (int i = 0; i < nProperties.getLength(); i++) { Node nProperty = nProperties.item(i); if (nProperty.getNodeName().equals("property")) { //now iterate over its children to extract name and description NodeList nPropChilds = nProperty.getChildNodes(); String name = null, description = null, tburi = null; for (int j = 0; j < nPropChilds.getLength(); j++) { Node nPropChild = nPropChilds.item(j); if (nPropChild.getNodeName().equals("name")) { name = nPropChild.getTextContent(); }/*from ww w . java 2 s. c o m*/ if (nPropChild.getNodeName().equals("description")) { description = nPropChild.getTextContent(); } } NamedNodeMap attributes = nProperty.getAttributes(); if (attributes.getNamedItem("tburi") != null) { tburi = attributes.getNamedItem("tburi").getNodeValue(); } //check if name and description were properly extracted if ((name != null) && (description != null) && (tburi != null)) { //now create the ManuallyMeasuredProperty ret.add(new ManuallyMeasuredPropertyImpl(name, description, tburi, bUserCreated)); log.debug("added propery: " + name + " " + tburi); } else { log.debug("error creating ManuallyMeasuredProperty for property item nr: " + i); } } } return ret; }
From source file:au.csiro.casda.sodalint.ValidateServiceDescriptor.java
private void checkInputParams(Reporter reporter, Node sodaSvcNode) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); String[] requiredAttrs = new String[] { "name", "ucd", "datatype" }; NodeList paramList = (NodeList) xpath.evaluate( "*[local-name()='GROUP' and @name='inputParams']/*[local-name()='PARAM']", sodaSvcNode, XPathConstants.NODESET); // <PARAM name="ID" ucd="meta.ref.url;meta.curation" datatype="char" arraysize="*" /> Map<String, Node> paramMap = new HashMap<>(); for (int i = 0; i < paramList.getLength(); i++) { Node paramNode = paramList.item(i); NamedNodeMap attributes = paramNode.getAttributes(); String paramName = "Unnamed"; boolean valid = true; for (String attrName : requiredAttrs) { Node attrNode = attributes.getNamedItem(attrName); if (attrNode == null) { reporter.report(SodaCode.E_SDIP, "Service descriptor " + paramName + " PARAM is missing the required attribute " + attrName + "."); valid = false;/*from w w w .j a v a 2 s .co m*/ } else if ("name".equals(attrName)) { paramName = attrNode.getNodeValue(); } } if (valid) { paramMap.put(paramName, paramNode); } } // Check for ID support - error if not present if (!paramMap.containsKey("ID")) { reporter.report(SodaCode.E_SDMP, "Required service descriptor ID PARAM is missing."); } for (SodaParameter standardParam : SodaParameter.values()) { if (paramMap.containsKey(standardParam.name())) { checkParamAttributes(reporter, paramMap.get(standardParam.name()), standardParam); } else if (!"ID".equals(standardParam.name())) { reporter.report(SodaCode.W_SDSP, "Standard service descriptor " + standardParam.name() + " PARAM is missing."); } } }