List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:com.library.essay.tinymce.spellchecker.GoogleSpellChekerServlet.java
private JSONObject receiveData(String method, String textToCheck) throws IOException, ParserConfigurationException, SAXException, JSONException { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(uc.getInputStream()); JSONArray wordArray = new JSONArray(); if (method.equalsIgnoreCase("checkWords")) { NodeList cList = doc.getElementsByTagName("c"); for (int i = 0; i < cList.getLength(); i++) { Node cNode = cList.item(i); NamedNodeMap attrs = cNode.getAttributes(); int offset = Integer.parseInt(attrs.getNamedItem("o").getNodeValue());//offset int length = Integer.parseInt(attrs.getNamedItem("l").getNodeValue());//length wordArray.put(textToCheck.substring(offset, offset + length)); }//from w w w . j a v a 2 s . co m } else if (method.equalsIgnoreCase("getSuggestions")) { NodeList cList = doc.getElementsByTagName("c"); if (cList.getLength() < 1) { return null;//Catch and response with an error } Node cNode = cList.item(0);//Should be only one if (cNode.getFirstChild() == null) { return null; } String[] suggestions = cNode.getFirstChild().getNodeValue().split("\t"); for (String suggestion : suggestions) { wordArray.put(suggestion); } } JSONObject returnObject = new JSONObject(); returnObject.put("result", wordArray); return returnObject; }
From source file:com.googlecode.ehcache.annotations.config.EhCacheConfigBeanDefinitionParserTest.java
/** * Validate an evict-expired-elements Element with a single include element. *//* w ww.ja va 2 s .c om*/ @Test public void testParseEvictExpiredSingleInclude() { Node nameAttribute = EasyMock.createMock(Node.class); EasyMock.expect(nameAttribute.getTextContent()).andReturn("foo"); NamedNodeMap includeAttributes = EasyMock.createMock(NamedNodeMap.class); EasyMock.expect(includeAttributes.getNamedItem(EhCacheConfigBeanDefinitionParser.XSD_ATTRIBUTE__NAME)) .andReturn(nameAttribute); Node includeNode = EasyMock.createMock(Node.class); EasyMock.expect(includeNode.getNodeType()).andReturn(Node.ELEMENT_NODE); EasyMock.expect(includeNode.getLocalName()).andReturn("include"); EasyMock.expect(includeNode.getAttributes()).andReturn(includeAttributes); NodeList childNodes = EasyMock.createMock(NodeList.class); EasyMock.expect(childNodes.getLength()).andReturn(1); EasyMock.expect(childNodes.item(0)).andReturn(includeNode); Element evictExpired = EasyMock.createMock(Element.class); EasyMock.expect(evictExpired.getChildNodes()).andReturn(childNodes); EasyMock.replay(nameAttribute, includeAttributes, includeNode, childNodes, evictExpired); EhCacheConfigBeanDefinitionParser parser = new EhCacheConfigBeanDefinitionParser(); List<CacheNameMatcher> matchers = parser.parseEvictExpiredElement(evictExpired); Assert.assertNotNull(matchers); Assert.assertEquals(1, matchers.size()); CacheNameMatcher matcher = matchers.get(0); Assert.assertTrue(matcher instanceof ExactCacheNameMatcherImpl); ExactCacheNameMatcherImpl casted = (ExactCacheNameMatcherImpl) matcher; Assert.assertEquals("foo", casted.getName()); EasyMock.verify(nameAttribute, includeAttributes, includeNode, childNodes, evictExpired); }
From source file:eu.planets_project.tb.impl.model.benchmark.BenchmarkGoalsHandlerImpl.java
private Vector<String> parseCategoryNames() { Vector<String> vRet = new Vector<String>(); NodeList cathegories = root.getChildNodes(); for (int i = 0; i < cathegories.getLength(); i++) { Node category = cathegories.item(i); //We only want to add Element Nodes and not Text Nodes if ((category.getNodeType() == Node.ELEMENT_NODE) && (category.getNodeName().equals("category"))) { NamedNodeMap attributes = category.getAttributes(); vRet.add(attributes.getNamedItem("name").getNodeValue()); }/*from w w w . j a v a 2 s.c o m*/ } return vRet; }
From source file:de.tudarmstadt.ukp.uby.integration.alignment.xml.transform.sensealignments.VnFnSenseAlignmentXml.java
/** * @param metadata// w w w . j av a 2 s.c o m * @throws IOException */ @Override public void toAlignmentXml(XmlMeta metadata) throws IOException { Lexicon vn = uby.getLexiconByName(lexiconName); TreeMap<String, Source> sourceMap = new TreeMap<>(); int noSource = 0; int lines = 0; int count = 0; ArrayList<String> output = new ArrayList<String>(); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new File(alignmentFile)); doc.getDocumentElement().normalize(); NodeList entries = doc.getElementsByTagName("vncls"); for (int i = 0; i < entries.getLength(); i++) { Node alignment = entries.item(i); NamedNodeMap atts = alignment.getAttributes(); String vnClass = atts.getNamedItem("class").getTextContent(); String vnLemma = atts.getNamedItem("vnmember").getTextContent(); String luId = atts.getNamedItem("fnlexent").getTextContent(); // there are mappings with empty (fn) target: if (luId.equals("")) { noSource++; } else { // add output here output.add(luId + "\t" + vnLemma + "\t" + vnClass + "\n"); List<LexicalEntry> vnentries = uby.getLexicalEntries(vnLemma, EPartOfSpeech.verb, vn); if (vnentries.size() > 0) { for (LexicalEntry e : vnentries) { List<Sense> vnSenses = e.getSenses(); for (Sense vns : vnSenses) { String senseId = vns.getId(); // filter by VN-class List<SemanticLabel> labels = uby.getSemanticLabelsbySenseIdbyType(senseId, ELabelTypeSemantics.verbnetClass.toString()); for (SemanticLabel l : labels) { String[] labelItems = l.getLabel().split("-"); StringBuffer parsedLabel = new StringBuffer(); parsedLabel.append(labelItems[1]); for (int ji = 2; ji < labelItems.length; ji++) { parsedLabel.append("-" + labelItems[ji]); } if (parsedLabel.toString().equals(vnClass)) { // get sourceMa Source source = null; if (sourceMap.containsKey(luId)) { source = sourceMap.get(luId); } else { source = new Source(); source.ref = luId; } Target target = new Target(); target.ref = vns.getMonolingualExternalRefs().iterator().next() .getExternalReference(); target.decision = new Decision(); target.decision.value = true; target.decision.confidence = DEFAULTCONFIDENCE; // add target to source if (source.targets.size() > 0) { source.targets.add(target); } else { source.targets.add(target); } count++; sourceMap.put(source.ref, source); } } } } } } lines++; } } catch (IOException | ParserConfigurationException | SAXException e) { throw new IOException(e); } logString.append("Converted " + alignmentFile + ", statistics:" + LF); logString.append("\tInput Lines: " + lines + LF); logString.append("\tOutput: " + output.size() + LF); logString.append("\tNo alignment target: " + noSource + LF); logString.append("\tControl: output + no alignment = input lines: " + (output.size() + noSource) + LF); logString.append("\tNumber of alignment pairs in output:" + count); logger.info(logString.toString()); writer.writeMetaData(metadata); Alignments alignments = new Alignments(); alignments.source = new LinkedList<>(); alignments.source.addAll(sourceMap.values()); writer.writeAlignments(alignments); writer.close(); }
From source file:edu.cornell.mannlib.semservices.service.impl.LCSHService.java
protected List<String> getConceptURIFromXML(String rdf) { List<String> uris = new ArrayList<String>(); String conceptUri = new String(); try {// ww w .j a v a 2s . c om Document doc = XMLUtils.parse(rdf); NodeList nodes = doc.getElementsByTagName("search:result"); int len = nodes.getLength(); int i; for (i = 0; i < len; i++) { Node node = nodes.item(i); NamedNodeMap attrs = node.getAttributes(); Attr idAttr = (Attr) attrs.getNamedItem("uri"); conceptUri = idAttr.getTextContent(); log.debug("concept uri is " + conceptUri); uris.add(conceptUri); } } catch (IOException e) { log.error("error occurred in parsing " + rdf, e); } catch (SAXException e) { log.error("error occurred in parsing " + rdf, e); } catch (ParserConfigurationException e) { log.error("error occurred in parsing " + rdf, e); } return uris; }
From source file:com.googlecode.ehcache.annotations.config.EhCacheConfigBeanDefinitionParserTest.java
/** * Validate an evict-expired-elements Element with a single exclude element. * Presence of exclude element will prepend a Include All matcher to the front of the list. */// ww w. ja v a 2 s . c om @Test public void testParseEvictExpiredSingleExclude() { Node nameAttribute = EasyMock.createMock(Node.class); EasyMock.expect(nameAttribute.getTextContent()).andReturn("foo"); NamedNodeMap excludeAttributes = EasyMock.createMock(NamedNodeMap.class); EasyMock.expect(excludeAttributes.getNamedItem(EhCacheConfigBeanDefinitionParser.XSD_ATTRIBUTE__NAME)) .andReturn(nameAttribute); Node excludeNode = EasyMock.createMock(Node.class); EasyMock.expect(excludeNode.getNodeType()).andReturn(Node.ELEMENT_NODE); EasyMock.expect(excludeNode.getLocalName()).andReturn("exclude"); EasyMock.expect(excludeNode.getAttributes()).andReturn(excludeAttributes); NodeList childNodes = EasyMock.createMock(NodeList.class); EasyMock.expect(childNodes.getLength()).andReturn(1); EasyMock.expect(childNodes.item(0)).andReturn(excludeNode); Element evictExpired = EasyMock.createMock(Element.class); EasyMock.expect(evictExpired.getChildNodes()).andReturn(childNodes); EasyMock.replay(nameAttribute, excludeAttributes, excludeNode, childNodes, evictExpired); EhCacheConfigBeanDefinitionParser parser = new EhCacheConfigBeanDefinitionParser(); List<CacheNameMatcher> matchers = parser.parseEvictExpiredElement(evictExpired); Assert.assertNotNull(matchers); Assert.assertEquals(2, matchers.size()); Assert.assertEquals(EhCacheConfigBeanDefinitionParser.INCLUDE_ALL_CACHE_NAME_MATCHER, matchers.get(0)); CacheNameMatcher matcher = matchers.get(1); Assert.assertTrue(matcher instanceof NotCacheNameMatcherImpl); NotCacheNameMatcherImpl casted = (NotCacheNameMatcherImpl) matcher; ExactCacheNameMatcherImpl wrapped = (ExactCacheNameMatcherImpl) casted.getWrapped(); Assert.assertEquals("foo", wrapped.getName()); EasyMock.verify(nameAttribute, excludeAttributes, excludeNode, childNodes, evictExpired); }
From source file:eu.masconsult.bgbanking.banks.fibank.ebanking.EFIBankClient.java
private RawBankAccount obtainBankAccountFromExposition(Node exposition) { NamedNodeMap attributes = exposition.getAttributes(); return new RawBankAccount().setServerId(attributes.getNamedItem("accountid").getTextContent()) .setIBAN(attributes.getNamedItem("iban").getTextContent()) .setCurrency(attributes.getNamedItem("curr").getTextContent()) .setName(attributes.getNamedItem("alias").getTextContent()) .setLastTransaction(attributes.getNamedItem("lastmovement").getTextContent()) .setBalance(Convert.strToFloat(attributes.getNamedItem("balance").getTextContent())) .setAvailableBalance(Convert.strToFloat(attributes.getNamedItem("available").getTextContent())); }
From source file:au.csiro.casda.sodalint.ValidateServiceDescriptor.java
private void checkParamAttributes(Reporter reporter, Node paramNode, SodaParameter sodaParam) { NamedNodeMap attributes = paramNode.getAttributes(); String paramName = attributes.getNamedItem("name").getNodeValue(); for (Entry<String, String> reqAttr : sodaParam.getRequiredAttribs().entrySet()) { Node attrNode = attributes.getNamedItem(reqAttr.getKey()); if (attrNode == null) { reporter.report(SodaCode.E_SDIP, "Service descriptor " + paramName + " PARAM is missing the required attribute " + reqAttr.getKey() + "."); } else if (!reqAttr.getValue().equals(attrNode.getNodeValue())) { reporter.report(SodaCode.E_SDIP, "Service descriptor " + paramName + " PARAM should have an attribute " + reqAttr.getKey() + " with the value '" + reqAttr.getValue() + "'."); }// w ww . j a v a2 s . com } }
From source file:com.sparkred.mdex.metrics.publish.EndecaMDEXAgent.java
/** * sample XML : <throughput units="req/sec" five_minute_avg="0.02" * one_minute_avg="0.06" ten_second_avg="0.07" /> * /*from w w w .j a v a 2 s .com*/ * * @param pDoc */ private void reportThroughputMetrics(Document pDoc) { NodeList thorughPut_stats = pDoc.getElementsByTagName("throughput"); Node node = thorughPut_stats.item(0); NamedNodeMap attr = node.getAttributes(); Double fiveMinuteAvg = Double.valueOf(attr.getNamedItem("five_minute_avg").getNodeValue()); Double oneMinuteAvg = Double.valueOf(attr.getNamedItem("one_minute_avg").getNodeValue()); Double tenSecondAvg = Double.valueOf(attr.getNamedItem("ten_second_avg").getNodeValue()); reportMetric(METRIC_THRPT_5_MIN_AVG, UNIT_REQ_SEC, fiveMinuteAvg); reportMetric(METRIC_THRPT_1_MIN_AVG, UNIT_REQ_SEC, oneMinuteAvg); reportMetric(METRIC_THRPT_10_SEC_AVG, UNIT_REQ_SEC, tenSecondAvg); }
From source file:broadwick.Broadwick.java
/** * Get the XML string of the model with the given id from a list of configured models. * <p>/*from ww w .j a v a2s. com*/ * @param id the id of the model to be found. * @param models a list of XML <model> nodes. * @return the XML string for the model. */ private String getModelsConfiguration(final String id, final NodeList models) { try { for (int i = 0; i < models.getLength(); i++) { final NamedNodeMap attributes = models.item(i).getAttributes(); final String nodeId = attributes.getNamedItem("id").getNodeValue(); if (id.equals(nodeId)) { final TransformerFactory transFactory = TransformerFactory.newInstance(); final Transformer transformer = transFactory.newTransformer(); final StringWriter buffer = new StringWriter(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(models.item(i)), new StreamResult(buffer)); return buffer.toString(); } } } catch (TransformerException ex) { log.error("Could not get the configuration for the model [{}]. {}", id, ex.getLocalizedMessage()); } return ""; }