List of usage examples for org.w3c.dom Node getTextContent
public String getTextContent() throws DOMException;
From source file:io.fabric8.forge.ipaas.repository.NexusConnectionRepository.java
private static String getNodeText(NodeList list, String name) { for (int i = 0; i < list.getLength(); i++) { Node child = list.item(i); if (name.equals(child.getNodeName())) { return child.getTextContent(); }/*from ww w . j a va 2 s . c o m*/ } return null; }
From source file:edu.ku.brc.util.thumbnails.Thumbnailer.java
/** * //from w w w. j a v a 2 s .c o m */ private static void readIconMap() { availableIcons = new HashMap<String, String>(); fallbackIcons = new HashMap<String, String>(); File mimeTypeFile = XMLHelper.getConfigDir("mime_icons.xml"); if (mimeTypeFile.exists()) { try { Document registry = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(mimeTypeFile); NodeList mimeNodes = registry.getElementsByTagName("mimetype"); for (int i = 0; i < mimeNodes.getLength(); ++i) { Node mimeNode = mimeNodes.item(i); Node iconNameNode = mimeNode.getAttributes().getNamedItem("icon"); Node fallbackNode = mimeNode.getAttributes().getNamedItem("fallback"); String iconName = iconNameNode.getNodeValue(); String fbStr = fallbackNode != null ? fallbackNode.getNodeValue() : null; boolean isFallBack = StringUtils.isNotEmpty(fbStr) && fbStr.equals("true"); NodeList extNodes = mimeNode.getChildNodes(); for (int j = 0; j < extNodes.getLength(); ++j) { Node extNode = extNodes.item(j); String ext = extNode.getTextContent().trim(); if (StringUtils.isNotEmpty(ext)) { if (isFallBack) { fallbackIcons.put(ext, iconName); } else { availableIcons.put(ext, iconName); } } } } } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } } }
From source file:Main.java
private static void printNote(NodeList nodeList) { for (int count = 0; count < nodeList.getLength(); count++) { Node tempNode = nodeList.item(count); // make sure it's element node. if (tempNode.getNodeType() == Node.ELEMENT_NODE) { // get node name and value System.out.println("\nNode Name =" + tempNode.getNodeName() + " [OPEN]"); System.out.println("Node Value =" + tempNode.getTextContent()); if (tempNode.hasAttributes()) { // get attributes names and values NamedNodeMap nodeMap = tempNode.getAttributes(); for (int i = 0; i < nodeMap.getLength(); i++) { Node node = nodeMap.item(i); System.out.println("attr name : " + node.getNodeName()); System.out.println("attr value : " + node.getNodeValue()); }//from ww w . ja va 2s . c o m } if (tempNode.hasChildNodes()) { // loop again if has child nodes printNote(tempNode.getChildNodes()); } System.out.println("Node Name =" + tempNode.getNodeName() + " [CLOSE]"); } } }
From source file:com.jaeksoft.searchlib.analysis.ClassFactory.java
/** * /*from w w w .jav a2 s. 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:edu.gslis.ts.ChunkToFile.java
public static Map<Integer, FeatureVector> readEvents(String path, Stopper stopper) { Map<Integer, FeatureVector> queries = new TreeMap<Integer, FeatureVector>(); try {//from w w w. j a v a 2 s. co m DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new File(path)); NodeList events = doc.getDocumentElement().getElementsByTagName("event"); for (int i = 0; i < events.getLength(); i++) { Node event = events.item(i); NodeList elements = event.getChildNodes(); int id = -1; String query = ""; for (int j = 0; j < elements.getLength(); j++) { Node element = elements.item(j); if (element == null) continue; if (element.getNodeName().equals("id")) id = Integer.parseInt(element.getTextContent()); else if (element.getNodeName().equals("query")) query = element.getTextContent(); } queries.put(id, new FeatureVector(query, stopper)); } } catch (Exception e) { e.printStackTrace(); } return queries; }
From source file:jp.go.nict.langrid.client.soap.io.SoapResponseParser.java
private static Node resolveHref(XPathWorkspace w, Node node) throws DOMException { Node href = node.getAttributes().getNamedItem("href"); if (href != null) { return findFirstDescendantHasAttr(node.getOwnerDocument().getDocumentElement(), "id", href.getTextContent().substring(1)); } else {// www . ja v a 2s . c o m return node; } }
From source file:com.msopentech.odatajclient.engine.data.json.DOMTreeUtilsV4.java
public static void writeSubtree(final ODataClient client, final JsonGenerator jgen, final Node content, final boolean propType) throws IOException { for (Node child : XMLUtils.getChildNodes(content, Node.ELEMENT_NODE)) { final String childName = XMLUtils.getSimpleName(child); final Node typeAttr = child.getAttributes().getNamedItem(ODataConstants.ATTR_M_TYPE); if (typeAttr != null && EdmSimpleType.isGeospatial(typeAttr.getTextContent())) { jgen.writeStringField(//from ww w . j ava2 s. c om propType ? ODataConstants.JSON_TYPE : childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); jgen.writeObjectFieldStart(childName); GeospatialJSONHandler.serialize(jgen, (Element) child, typeAttr.getTextContent()); jgen.writeEndObject(); } else if (XMLUtils.hasOnlyTextChildNodes(child)) { if (child.hasChildNodes()) { final String out; if (typeAttr == null) { out = child.getChildNodes().item(0).getNodeValue(); } else { if (typeAttr.getTextContent().startsWith("Edm.")) { final EdmSimpleType type = EdmSimpleType.fromValue(typeAttr.getTextContent()); final ODataPrimitiveValue value = client.getPrimitiveValueBuilder().setType(type) .setText(child.getChildNodes().item(0).getNodeValue()).build(); out = value.toString(); jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, type.toString()); } else { // enum out = child.getTextContent(); jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); } } jgen.writeStringField(childName, out); } else { if (child.getAttributes().getNamedItem(ODataConstants.ATTR_NULL) == null) { if (typeAttr != null && EdmSimpleType.String.toString().equals(typeAttr.getTextContent())) { jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); jgen.writeStringField(childName, StringUtils.EMPTY); } else { jgen.writeArrayFieldStart(childName); jgen.writeEndArray(); } } else { jgen.writeNullField(childName); } } } else { if (XMLUtils.hasElementsChildNode(child)) { jgen.writeArrayFieldStart(childName); for (Node nephew : XMLUtils.getChildNodes(child, Node.ELEMENT_NODE)) { if (XMLUtils.hasOnlyTextChildNodes(nephew)) { jgen.writeString(nephew.getChildNodes().item(0).getNodeValue()); } else { jgen.writeStartObject(); DOMTreeUtils.writeSubtree(client, jgen, nephew); jgen.writeEndObject(); } } jgen.writeEndArray(); } else { jgen.writeObjectFieldStart(childName); if (typeAttr != null) { jgen.writeStringField("@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); } DOMTreeUtils.writeSubtree(client, jgen, child); jgen.writeEndObject(); } } } }
From source file:Main.java
public static String argumentTagToCmd(Element jobElement) { // NodeList nl = jobElement.getChildNodes(); // for(int i=0;i<nl.getLength();i++) // {//w ww .ja va 2 s . c om // System.out.println(nl.item(i).getTextContent()); // } // System.exit(1); // Node n = jobElement.getElementsByTagName("argument").item(0); String taskName = jobElement.getAttribute("name"); // String nodeString = nodeToString(n); // nodeString = nodeString.replace("<"+n.getNodeName()+">", ""); // nodeString = nodeString.replace("</"+n.getNodeName()+">", ""); // nodeString = nodeString.trim(); // String[] lines = nodeString.split("\n"); StringBuilder cmd = new StringBuilder(taskName).append(";"); NodeList argList = jobElement.getElementsByTagName("argument").item(0).getChildNodes(); for (int i = 0; i < argList.getLength(); i++) { Node c = argList.item(i); String cStr; if (c.getNodeName().equals("file")) { Element ec = (Element) c; cStr = (ec.getAttribute("name")).trim(); if (!cStr.isEmpty()) { cmd.append(cStr).append(";"); } } else { cStr = (c.getTextContent().trim()); String[] cStrs = cStr.split("\\s+"); for (String cs : cStrs) { cs = cs.trim(); if (!cs.isEmpty()) { cmd.append(cs).append(";"); } } } } cmd.replace(cmd.length() - 1, cmd.length(), ""); return cmd.toString(); }
From source file:com.msopentech.odatajclient.engine.data.json.DOMTreeUtilsV3.java
/** * Serializes DOM content as JSON./* www . jav a2 s . c o m*/ * * @param client OData client. * @param jgen JSON generator. * @param content content. * @param propType whether to output type information in the way needed for property values or not. * @throws IOException in case of write error. */ public static void writeSubtree(final ODataClient client, final JsonGenerator jgen, final Node content, final boolean propType) throws IOException { for (Node child : XMLUtils.getChildNodes(content, Node.ELEMENT_NODE)) { final String childName = XMLUtils.getSimpleName(child); final Node typeAttr = child.getAttributes().getNamedItem(ODataConstants.ATTR_M_TYPE); if (typeAttr != null && EdmSimpleType.isGeospatial(typeAttr.getTextContent())) { jgen.writeStringField( propType ? ODataConstants.JSON_TYPE : childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); jgen.writeObjectFieldStart(childName); GeospatialJSONHandler.serialize(jgen, (Element) child, typeAttr.getTextContent()); jgen.writeEndObject(); } else if (XMLUtils.hasOnlyTextChildNodes(child)) { if (child.hasChildNodes()) { final String out; if (typeAttr == null) { out = child.getChildNodes().item(0).getNodeValue(); } else { final EdmSimpleType type = EdmSimpleType.fromValue(typeAttr.getTextContent()); final ODataPrimitiveValue value = client.getPrimitiveValueBuilder().setType(type) .setText(child.getChildNodes().item(0).getNodeValue()).build(); out = value.toString(); jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, type.toString()); } jgen.writeStringField(childName, out); } else { if (child.getAttributes().getNamedItem(ODataConstants.ATTR_NULL) == null) { if (typeAttr != null && EdmSimpleType.String.toString().equals(typeAttr.getTextContent())) { jgen.writeStringField(childName + "@" + ODataConstants.JSON_TYPE, typeAttr.getTextContent()); jgen.writeStringField(childName, StringUtils.EMPTY); } else { jgen.writeArrayFieldStart(childName); jgen.writeEndArray(); } } else { jgen.writeNullField(childName); } } } else { if (XMLUtils.hasElementsChildNode(child)) { jgen.writeArrayFieldStart(childName); for (Node nephew : XMLUtils.getChildNodes(child, Node.ELEMENT_NODE)) { if (XMLUtils.hasOnlyTextChildNodes(nephew)) { jgen.writeString(nephew.getChildNodes().item(0).getNodeValue()); } else { jgen.writeStartObject(); DOMTreeUtils.writeSubtree(client, jgen, nephew); jgen.writeEndObject(); } } jgen.writeEndArray(); } else { jgen.writeObjectFieldStart(childName); if (typeAttr != null) { jgen.writeStringField(ODataConstants.JSON_TYPE, typeAttr.getTextContent()); } DOMTreeUtils.writeSubtree(client, jgen, child); jgen.writeEndObject(); } } } }
From source file:net.roboconf.agent.internal.misc.UserDataUtils.java
private static String getSpecificAttributeOfTagInXMLFile(String filePath, String tagName, String attrName) throws ParserConfigurationException, SAXException, IOException { File fXmlFile = new File(filePath); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName(tagName); Node aNode = nList.item(2);/* ww w .jav a 2s . co m*/ NamedNodeMap attributes = aNode.getAttributes(); String attrValue = ""; for (int a = 0; a < attributes.getLength(); a++) { Node theAttribute = attributes.item(a); if (attrName.equals(theAttribute.getNodeName())) attrValue = theAttribute.getTextContent().split(":")[0]; } return attrValue; }