List of usage examples for org.w3c.dom Node TEXT_NODE
short TEXT_NODE
To view the source code for org.w3c.dom Node TEXT_NODE.
Click Source Link
Text
node. From source file:org.dozer.eclipse.plugin.sourcepage.hyperlink.DozerClassHyperlinkDetector.java
@SuppressWarnings("restriction") public final IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { if (region == null || textViewer == null) { return null; }//from w ww . j av a 2s .c o m IDocument document = textViewer.getDocument(); Node currentNode = BeansEditorUtils.getNodeByOffset(document, region.getOffset()); if (currentNode != null) { switch (currentNode.getNodeType()) { case Node.ELEMENT_NODE: // at first try to handle selected attribute value Attr currentAttr = BeansEditorUtils.getAttrByOffset(currentNode, region.getOffset()); IDOMAttr attr = (IDOMAttr) currentAttr; if (currentAttr != null && region.getOffset() >= attr.getValueRegionStartOffset()) { if (isLinkableAttr(currentAttr)) { IRegion hyperlinkRegion = getHyperlinkRegion(currentAttr); IHyperlink hyperLink = createHyperlink(currentAttr.getName(), currentAttr.getNodeValue(), currentNode, currentNode.getParentNode(), document, textViewer, hyperlinkRegion, region); if (hyperLink != null) { return new IHyperlink[] { hyperLink }; } } } break; case Node.TEXT_NODE: IRegion hyperlinkRegion = getHyperlinkRegion(currentNode); Node parentNode = currentNode.getParentNode(); if (parentNode != null) { IHyperlink hyperLink = createHyperlink(parentNode.getNodeName(), currentNode.getNodeValue(), currentNode, parentNode, document, textViewer, hyperlinkRegion, region); if (hyperLink != null) { return new IHyperlink[] { hyperLink }; } } break; } } return null; }
From source file:com.test.movierecordsjsf.controller.MovieRecordsController.java
public void uploadXML() { if (file != null) { try {/* w ww .j a v a 2s.c o m*/ InputStream is = file.getInputstream(); byte[] contents = IOUtils.toByteArray(is); is.close(); Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new ByteArrayInputStream(contents)); NodeList nlist = doc.getElementsByTagName("Movie"); for (int i = 0; i < nlist.getLength(); i++) { Node nod = nlist.item(i); MovieRecords movieRecord = new MovieRecords(); NodeList dataMovie = nod.getChildNodes(); for (int j = 0; j < dataMovie.getLength(); j++) { Node data = dataMovie.item(j); if (data.getNodeType() == Node.ELEMENT_NODE) { if (null != data.getNodeName()) //Show data type { switch (data.getNodeName()) { case "title": { //The value is contained in a child node Element Node dataContect = data.getFirstChild(); //Show the value in the node to be of type Text if (dataContect != null && dataContect.getNodeType() == Node.TEXT_NODE) { movieRecord.setTitle(dataContect.getNodeValue()); } break; } case "description": { //The value is contained in a child node Element Node dataContect = data.getFirstChild(); //Show the value in the node to be of type Text if (dataContect != null && dataContect.getNodeType() == Node.TEXT_NODE) { movieRecord.setDescription(dataContect.getNodeValue()); } break; } case "size": { System.out.print(data.getNodeName() + ": "); //The value is contained in a child node Element Node dataContect = data.getFirstChild(); //Show the value in the node to be of type Text if (dataContect != null && dataContect.getNodeType() == Node.TEXT_NODE) { movieRecord.setSize(Integer.parseInt(dataContect.getNodeValue())); } break; } case "rating": { //The value is contained in a child node Element Node dataContect = data.getFirstChild(); //Show the value in the node to be of type Text if (dataContect != null && dataContect.getNodeType() == Node.TEXT_NODE) { movieRecord.setRating(Integer.parseInt(dataContect.getNodeValue())); } break; } case "checksum": { //The value is contained in a child node Element Node dataContect = data.getFirstChild(); //Show the value in the node to be of type Text if (dataContect != null && dataContect.getNodeType() == Node.TEXT_NODE) { movieRecord.setChecksum(dataContect.getNodeValue()); } break; } case "staring": { //The value is contained in a child node Element Node dataContect = data.getFirstChild(); //Show the value in the node to be of type Text if (dataContect != null && dataContect.getNodeType() == Node.TEXT_NODE) { movieRecord.setStaring(dataContect.getNodeValue()); } break; } default: break; } } } } movieRecordFacade.create(movieRecord); } listMovie(); } catch (Exception ex) { Logger.getLogger(MovieRecordsController.class.getName()).log(Level.SEVERE, null, ex); } JsfUtil.msgInfo(file.getFileName() + " successfully uploaded."); } }
From source file:XmlUtil.java
/** * Returns value of first available child text node or <code>null</code> if not found. */// w w w . j a v a 2s . c o m public static String getFirstChildTextNodeValue(Node node) { NodeList children = node.getChildNodes(); int len = children.getLength(); for (int i = 0; i < len; i++) { Node n = children.item(i); if (n.getNodeType() == Node.TEXT_NODE) { return n.getNodeValue(); } } return null; }
From source file:XMLDocumentWriter.java
/** * Output the specified DOM Node object, printing it using the specified * indentation string/*from w w w . j a v a 2 s. c o m*/ */ public void write(Node node, String indent) { // The output depends on the type of the node switch (node.getNodeType()) { case Node.DOCUMENT_NODE: { // If its a Document node Document doc = (Document) node; out.println(indent + "<?xml version='1.0'?>"); // Output header Node child = doc.getFirstChild(); // Get the first node while (child != null) { // Loop 'till no more nodes write(child, indent); // Output node child = child.getNextSibling(); // Get next node } break; } case Node.DOCUMENT_TYPE_NODE: { // It is a <!DOCTYPE> tag DocumentType doctype = (DocumentType) node; // Note that the DOM Level 1 does not give us information about // the the public or system ids of the doctype, so we can't output // a complete <!DOCTYPE> tag here. We can do better with Level 2. out.println("<!DOCTYPE " + doctype.getName() + ">"); break; } case Node.ELEMENT_NODE: { // Most nodes are Elements Element elt = (Element) node; out.print(indent + "<" + elt.getTagName()); // Begin start tag NamedNodeMap attrs = elt.getAttributes(); // Get attributes for (int i = 0; i < attrs.getLength(); i++) { // Loop through them Node a = attrs.item(i); out.print(" " + a.getNodeName() + "='" + // Print attr. name fixup(a.getNodeValue()) + "'"); // Print attr. value } out.println(">"); // Finish start tag String newindent = indent + " "; // Increase indent Node child = elt.getFirstChild(); // Get child while (child != null) { // Loop write(child, newindent); // Output child child = child.getNextSibling(); // Get next child } out.println(indent + "</" + // Output end tag elt.getTagName() + ">"); break; } case Node.TEXT_NODE: { // Plain text node Text textNode = (Text) node; String text = textNode.getData().trim(); // Strip off space if ((text != null) && text.length() > 0) // If non-empty out.println(indent + fixup(text)); // print text break; } case Node.PROCESSING_INSTRUCTION_NODE: { // Handle PI nodes ProcessingInstruction pi = (ProcessingInstruction) node; out.println(indent + "<?" + pi.getTarget() + " " + pi.getData() + "?>"); break; } case Node.ENTITY_REFERENCE_NODE: { // Handle entities out.println(indent + "&" + node.getNodeName() + ";"); break; } case Node.CDATA_SECTION_NODE: { // Output CDATA sections CDATASection cdata = (CDATASection) node; // Careful! Don't put a CDATA section in the program itself! out.println(indent + "<" + "![CDATA[" + cdata.getData() + "]]" + ">"); break; } case Node.COMMENT_NODE: { // Comments Comment c = (Comment) node; out.println(indent + "<!--" + c.getData() + "-->"); break; } default: // Hopefully, this won't happen too much! System.err.println("Ignoring node: " + node.getClass().getName()); break; } }
From source file:com.google.publicalerts.cap.CapJsonBuilder.java
private void toJsonObjectInner(Element element, JSONObject object, Map<String, Set<String>> repeatedFieldsMap) throws JSONException { NodeList nl = element.getChildNodes(); Set<String> repeatedFields = repeatedFieldsMap.get(element.getNodeName()); for (int i = 0; i < nl.getLength(); i++) { Element child = (Element) nl.item(i); int gcLength = child.getChildNodes().getLength(); if (gcLength == 0) { continue; }//w w w . java2s.com String nodeName = child.getNodeName(); if (repeatedFields != null && repeatedFields.contains(nodeName)) { if (gcLength == 1 && child.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE) { object.append(nodeName, child.getTextContent()); } else { JSONObject childObj = new JSONObject(); toJsonObjectInner(child, childObj, repeatedFieldsMap); object.append(nodeName, childObj); } } else { if (gcLength == 1 && child.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE) { object.put(child.getNodeName(), child.getTextContent()); } else { JSONObject childObj = new JSONObject(); toJsonObjectInner(child, childObj, repeatedFieldsMap); object.put(child.getNodeName(), childObj); } } } }
From source file:com.redhat.rhevm.api.powershell.util.PowerShellParser.java
private static String getText(Node node) { StringBuffer buf = new StringBuffer(); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.TEXT_NODE) { buf.append(child.getNodeValue()); }//from w ww. java 2 s. com } String ret = buf.toString().trim(); return !ret.isEmpty() ? ret : null; }
From source file:DOMUtils.java
/** * Concat all the text and cdata node children of this elem and return * the resulting text.//from ww w . j a v a 2s . c o m * * @param parentEl the element whose cdata/text node values are to * be combined. * @return the concatanated string. */ static public String getChildCharacterData(Element parentEl) { if (parentEl == null) { return null; } Node tempNode = parentEl.getFirstChild(); StringBuffer strBuf = new StringBuffer(); CharacterData charData; while (tempNode != null) { switch (tempNode.getNodeType()) { case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: charData = (CharacterData) tempNode; strBuf.append(charData.getData()); break; } tempNode = tempNode.getNextSibling(); } return strBuf.toString(); }
From source file:ApplyXPathDOM.java
/** Decide if the node is text, and so must be handled specially */ static boolean isTextNode(Node n) { if (n == null) return false; short nodeType = n.getNodeType(); return nodeType == Node.CDATA_SECTION_NODE || nodeType == Node.TEXT_NODE; }
From source file:di.uniba.it.tee2.extraction.TemporalExtractor.java
public TaggedText process(String text) throws Exception { Date currentTime = Calendar.getInstance(TimeZone.getDefault()).getTime(); TaggedText taggedText = new TaggedText(); text = StringEscapeUtils.escapeXml11(text); taggedText.setText(text);//from www . j a v a 2s . co m String timemlOutput = heidelTagger.process(text, currentTime); taggedText.setTaggedText(timemlOutput); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); org.w3c.dom.Document doc = builder.parse(new InputSource(new StringReader(timemlOutput))); StringBuilder sb = new StringBuilder(); NodeList timemlNodes = doc.getElementsByTagName("TimeML"); for (int i = 0; i < timemlNodes.getLength(); i++) { NodeList childs = timemlNodes.item(i).getChildNodes(); for (int j = 0; j < childs.getLength(); j++) { Node child = childs.item(j); if (child.getNodeType() == Node.TEXT_NODE) { sb.append(child.getTextContent()); } else if (child.getNodeName().equals("TIMEX3")) { String timeText = child.getTextContent(); String timeValueString = child.getAttributes().getNamedItem("value").getNodeValue(); String normalizedTime = null; try { normalizedTime = TEEUtils.normalizeTime(timeValueString); } catch (Exception ex) { //logger.log(Level.WARNING, "Error to normalize time: ", ex); } if (normalizedTime != null) { TimeEvent event = new TimeEvent(sb.length(), sb.length() + timeText.length(), normalizedTime); event.setEventString(timeText); taggedText.getEvents().add(event); } sb.append(timeText); } //VERBOSE //System.out.println(child.getNodeType() + "\t" + child.getNodeName() + "\t" + child.getTextContent()); //System.out.println(); } } taggedText.setText(sb.toString()); return taggedText; }
From source file:XmlUtil.java
/** * Returns value of single child text node or <code>null</code>. *///from w ww .j a va 2 s . co m public static String getChildTextNodeValue(Node node) { if (node.getChildNodes().getLength() != 1) { return null; } Node item0 = node.getChildNodes().item(0); if (item0.getNodeType() != Node.TEXT_NODE) { return null; } return item0.getNodeValue(); }