List of usage examples for org.w3c.dom Node getTextContent
public String getTextContent() throws DOMException;
From source file:org.gvnix.dynamic.configuration.roo.addon.ConfigurationsImpl.java
/** * {@inheritDoc}//from w ww. ja va 2 s . co m */ public DynProperty parseProperty(Element prop) { // Create a dynamic property from property element Node key = getKeyElement(prop); Node value = getValueElement(prop); return new DynProperty(key.getTextContent(), value == null ? null : value.getTextContent()); }
From source file:edu.cornell.mannlib.vitro.utilities.containerneutral.CheckContainerNeutrality.java
/** * Dump the first 20 nodes of an XML context, excluding comments and blank * text nodes./* w ww . j av a 2 s . co m*/ */ @SuppressWarnings("unused") private int dumpXml(Node xmlNode, int... parms) { int remaining = (parms.length == 0) ? 20 : parms[0]; int level = (parms.length < 2) ? 1 : parms[1]; Node n = xmlNode; if (Node.COMMENT_NODE == n.getNodeType()) { return 0; } if (Node.TEXT_NODE == n.getNodeType()) { if (StringUtils.isBlank(n.getTextContent())) { return 0; } } int used = 1; System.out.println(StringUtils.repeat("-->", level) + n); NodeList nl = n.getChildNodes(); for (int i = 0; (i < nl.getLength() && remaining > used); i++) { used += dumpXml(nl.item(i), remaining - used, level + 1); } return used; }
From source file:edu.ur.ir.ir_import.service.DefaultCollectionImportService.java
/** * Create a collection from the xml data. * // ww w . j av a2 s .c o m * @param node - root collection node * @return * @throws DuplicateNameException */ private void importCollection(Node node, Repository repository, ZipFile zip) throws DuplicateNameException { if (log.isDebugEnabled()) { log.debug("import collections"); } String name = null; String id = null; String description = null; String copyright = null; Node links = null; Node collectionChildren = null; Node pictures = null; String primaryPicture = null; NodeList children = node.getChildNodes(); for (int index = 0; index < children.getLength(); index++) { Node child = children.item(index); if (child.getNodeName().equals("name")) { name = child.getTextContent(); } else if (child.getNodeName().equals("id")) { id = child.getTextContent(); } else if (child.getNodeName().equals("description")) { description = child.getTextContent(); } else if (child.getNodeName().equals("copyright")) { copyright = child.getTextContent(); } else if (child.getNodeName().equals("links")) { links = child; } else if (child.getNodeName().equals("children")) { collectionChildren = child; } else if (child.getNodeName().equals("pictures")) { pictures = child; } else if (child.getNodeName().equals("primary_picture")) { primaryPicture = child.getTextContent(); } } if (name != null && !name.trim().equals("")) { log.debug("creating collection with name " + name + " to repo " + repository); InstitutionalCollection c = new InstitutionalCollection(repository, name); institutionalCollectionService.saveCollection(c); c.setDescription(description); c.setCopyright(copyright); repositoryService.saveRepository(repository); if (primaryPicture != null) { this.addPrimaryPicture(primaryPicture, c, repository, zip); } if (links != null) { this.addLinks(links, c); } if (pictures != null) { addPictures(pictures, c, repository, zip); } if (collectionChildren != null) { this.addChildren(collectionChildren, c, repository, zip); } if (id != null) { // procsss id } institutionalCollectionService.saveCollection(c); } }
From source file:edu.ur.ir.ir_import.service.DefaultCollectionImportService.java
/** * Add the child collection.//from ww w .ja va 2s .c om * * @param childCollectionNode * @param parent * @param repository * @param zip * @throws DuplicateNameException */ private void addChild(Node childCollectionNode, InstitutionalCollection parent, Repository repository, ZipFile zip) throws DuplicateNameException { if (log.isDebugEnabled()) { log.debug("import child collection"); } String name = null; String id = null; String description = null; String copyright = null; Node links = null; Node collectionChildren = null; Node pictures = null; String primaryPicture = null; NodeList children = childCollectionNode.getChildNodes(); for (int index = 0; index < children.getLength(); index++) { Node child = children.item(index); if (child.getNodeName().equals("name")) { name = child.getTextContent(); } else if (child.getNodeName().equals("id")) { id = child.getTextContent(); } else if (child.getNodeName().equals("description")) { description = child.getTextContent(); } else if (child.getNodeName().equals("copyright")) { copyright = child.getTextContent(); } else if (child.getNodeName().equals("links")) { links = child; } else if (child.getNodeName().equals("children")) { collectionChildren = child; } else if (child.getNodeName().equals("pictures")) { pictures = child; } else if (child.getNodeName().equals("primary_picture")) { primaryPicture = child.getTextContent(); } } if (name != null && !name.trim().equals("")) { if (log.isDebugEnabled()) { log.debug("creating collection with name " + name + " to parent collection " + parent); } InstitutionalCollection c = parent.createChild(name); c.setDescription(description); c.setCopyright(copyright); institutionalCollectionService.saveCollection(c); if (primaryPicture != null) { this.addPrimaryPicture(primaryPicture, c, repository, zip); } if (links != null) { this.addLinks(links, c); } if (pictures != null) { addPictures(pictures, c, repository, zip); } if (collectionChildren != null) { this.addChildren(collectionChildren, c, repository, zip); } if (id != null) { // procsss id } institutionalCollectionService.saveCollection(c); } }
From source file:com.tibco.businessworks6.sonar.plugin.source.XmlSource.java
/** * Return a list of violation if the input mapping context ({@link Node}) is hard coded * @param rule violated {@link Rule} * @param context input mapping {@link Node} to validate * @param message violations message {@link String} * /*from ww w . j a v a 2 s . c o m*/ * @return List<Violation> */ public List<Violation> getViolationsHardCodedMapping(Rule rule, Node context, String message) { List<Violation> violations = new ArrayList<Violation>(); // By default no violation boolean violated = false; int line = getLineForNode(context); if (context.getTextContent() != null && !context.getTextContent().trim().isEmpty()) { // If forced constant set violated violated = true; } else { // Select value-of child node Node valueOf = XmlHelper.firstChildElement((Element) context, "http://www.w3.org/1999/XSL/Transform", "value-of"); if (valueOf != null) { // Select select attribute Node select = valueOf.getAttributes().getNamedItem("select"); if (select != null) { // Get select content String selectFormula = select.getTextContent(); if (selectFormula.startsWith("\"") && selectFormula.endsWith("\"")) { // If double quoted string set violated violated = true; line = getLineForNode(select); } else if (selectFormula.startsWith("'") && selectFormula.endsWith("'")) { // If simple quoted string set violated violated = true; line = getLineForNode(select); } else if (selectFormula.matches("[0-9]+(.[0-9]*)?")) { // If number set violated violated = true; line = getLineForNode(select); } else if ("true()".equals(selectFormula)) { // If true function set violated violated = true; line = getLineForNode(select); } else if ("false()".equals(selectFormula)) { // If false function set violated violated = true; line = getLineForNode(select); } } } } if (violated) { // If violated add a new violation violations.add(new DefaultViolation(rule, line, message)); } return violations; }
From source file:com.esri.gpt.server.openls.provider.services.poi.DirectoryProvider.java
/** * Parse directory request//from w w w . j a va2s . c om * @param context * @param ndReq * @param xpath * @throws XPathExpressionException */ private void parseRequest(OperationContext context, Node ndReq, XPath xpath) throws XPathExpressionException { DirectoryParams params = context.getRequestOptions().getDirectoryOptions(); HashMap<String, String> poiProperties = null; HashMap<String, Object> poiLocations = null; Node ndPoiLoc = (Node) xpath.evaluate("xls:POILocation", ndReq, XPathConstants.NODE); if (ndPoiLoc != null) { poiLocations = new HashMap<String, Object>(); Node ndPos = (Node) xpath.evaluate("xls:Nearest/xls:Position/gml:Point/gml:pos", ndPoiLoc, XPathConstants.NODE); if (ndPos != null) { String[] xy = ndPos.getTextContent().split(" "); Point loc = new Point(xy[0], xy[1]); poiLocations.put("nearest", loc); } @SuppressWarnings("unused") Node ndWDAL = (Node) xpath.evaluate("xls:WithinDistance/xls:POI/xls:POIAttributeList/xls:POIInfoList", ndPoiLoc, XPathConstants.NODE); String maxDist = (String) xpath.evaluate("xls:WithinDistance/xls:MaximumDistance/@value", ndPoiLoc, XPathConstants.STRING); if (maxDist != null) { poiLocations.put("withinDistance", maxDist); } } Node ndPoiProp = (Node) xpath.evaluate("xls:POIProperties", ndReq, XPathConstants.NODE); if (ndPoiProp != null) { NodeList nlProp = (NodeList) xpath.evaluate("xls:POIProperty", ndPoiProp, XPathConstants.NODESET); if (nlProp != null) { for (int j = 0; j < nlProp.getLength(); j++) { Node ndProp = nlProp.item(j); poiProperties = new HashMap<String, String>(); String name = (String) xpath.evaluate("@name", ndProp, XPathConstants.STRING); String param = context.getRequestContext().getApplicationConfiguration() .getCatalogConfiguration().getParameters().getValue(name); String value = (String) xpath.evaluate("@value", ndProp, XPathConstants.STRING); poiProperties.put(param, value); } } } params.setPoiLocations(poiLocations); params.setPoiProperties(poiProperties); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.xml.XmlReaderXPath.java
/** * Add the text in current node to document text buffer, create and add to index a Field * annotation out of the text. This usually processes a document. *//*w w w .j a va2 s . c o m*/ private void processNode(CAS cas, Node node, StringBuilder documentText) { if (node.hasChildNodes()) { if (docIdTag != null) { ensureIdValidity(node); } NodeList docFields = node.getChildNodes(); for (int i = 0; i < docFields.getLength(); i++) { Node field = docFields.item(i); int begin = documentText.length(); String nodeTag = field.getLocalName(); if (nodeTag != null && isIncluded(nodeTag)) { String nodeText = field.getTextContent(); documentText = documentText.append(nodeText); int end = documentText.length(); documentText = documentText.append("\n"); // Substitue tag if specified if (useSubstitution && substitution.containsKey(nodeTag)) { nodeTag = substitution.get(nodeTag); } createFieldAnnotation(cas, nodeTag, begin, end); } } } }
From source file:edu.toronto.cs.cidb.ncbieutils.NCBIEUtilsAccessService.java
protected List<Map<String, Object>> getSummaries(List<String> idList) { // response example at // http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=omim&id=190685,605298,604829,602917,601088,602523,602259 // response type: XML // return it/*from ww w. jav a 2s.co m*/ String queryList = getSerializedList(idList); String url = composeURL(TERM_SUMMARY_QUERY_SCRIPT, TERM_SUMMARY_PARAM_NAME, queryList); try { Document response = readXML(url); NodeList nodes = response.getElementsByTagName("Item"); // OMIM titles are all UPPERCASE, try to fix this for (int i = 0; i < nodes.getLength(); ++i) { Node n = nodes.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { if (n.getFirstChild() != null) { n.replaceChild(response.createTextNode(fixCase(n.getTextContent())), n.getFirstChild()); } } } List<Map<String, Object>> result = new LinkedList<Map<String, Object>>(); nodes = response.getElementsByTagName("DocSum"); for (int i = 0; i < nodes.getLength(); ++i) { Element n = (Element) nodes.item(i); Map<String, Object> doc = new HashMap<String, Object>(); doc.put("id", n.getElementsByTagName("Id").item(0).getTextContent()); NodeList items = n.getElementsByTagName("Item"); for (int j = 0; j < items.getLength(); ++j) { Element item = (Element) items.item(j); if ("List".equals(item.getAttribute("Type"))) { NodeList subitems = item.getElementsByTagName("Item"); if (subitems.getLength() > 0) { List<String> values = new ArrayList<String>(subitems.getLength()); for (int k = 0; k < subitems.getLength(); ++k) { values.add(subitems.item(k).getTextContent()); } doc.put(item.getAttribute("Name"), values); } } else { String value = item.getTextContent(); if (StringUtils.isNotEmpty(value)) { doc.put(item.getAttribute("Name"), value); } } } result.add(doc); } return result; } catch (Exception ex) { this.logger.error("Error while trying to retrieve summaries for ids " + idList + " " + ex.getClass().getName() + " " + ex.getMessage(), ex); } return Collections.emptyList(); }
From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapter.java
public static String elementToString(Node n) { String name = n.getNodeName(); short type = n.getNodeType(); if (Node.CDATA_SECTION_NODE == type) { return "<![CDATA[" + n.getNodeValue() + "]]>"; }/*from w w w . j a v a2 s. com*/ if (name.startsWith("#")) { return ""; } StringBuffer sb = new StringBuffer(); sb.append('<').append(name); NamedNodeMap attrs = n.getAttributes(); if (attrs != null) { for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); sb.append(' ').append(attr.getNodeName()).append("=\"").append(attr.getNodeValue()).append("\""); } } String textContent = null; NodeList children = n.getChildNodes(); if (children.getLength() == 0) { if ((textContent = n.getTextContent()) != null && !"".equals(textContent)) { sb.append(textContent).append("</").append(name).append('>'); } else { sb.append("/>").append('\n'); } } else { sb.append('>').append('\n'); boolean hasValidChildren = false; for (int i = 0; i < children.getLength(); i++) { String childToString = elementToString(children.item(i)); if (!"".equals(childToString)) { sb.append(childToString); hasValidChildren = true; } } if (!hasValidChildren && ((textContent = n.getTextContent()) != null)) { sb.append(textContent); } sb.append("</").append(name).append('>'); } return sb.toString(); }
From source file:edu.cornell.mannlib.semservices.service.impl.AgrovocService.java
protected String getAgrovocTermCode(String rdf) throws Exception { String termcode = new String(); try {//from ww w . ja v a2 s .c o m Document doc = XMLUtils.parse(rdf); NodeList nodes = doc.getElementsByTagName("hasCodeAgrovoc"); if (nodes.item(0) != null) { Node node = nodes.item(0); termcode = node.getTextContent(); } } catch (SAXException e) { // e.printStackTrace(); throw e; } catch (ParserConfigurationException e) { // e.printStackTrace(); throw e; } catch (IOException e) { // e.printStackTrace(); throw e; } return termcode; }