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:DomPrintUtil.java
private boolean checkNewLine(Node target) { if (indent && target.hasChildNodes()) { short type = target.getFirstChild().getNodeType(); if (type == Node.TEXT_NODE || type == Node.CDATA_SECTION_NODE) { return false; }/*from w w w . j av a 2s.c o m*/ return true; } return false; }
From source file:ItemSearcher.java
public short acceptNode(Node n) { if (n.getNodeType() == Node.TEXT_NODE) { Node parent = n.getParentNode(); if ((parent.getNodeName().equalsIgnoreCase("b")) || (parent.getNodeName().equalsIgnoreCase("i"))) { return FILTER_ACCEPT; }/*from w w w .j a v a2 s . co m*/ } // If we got here, not interested return FILTER_SKIP; }
From source file:com.dinochiesa.edgecallouts.EditXmlNode.java
private short getNewNodeType(MessageContext msgCtxt) throws Exception { String nodetype = getSimpleRequiredProperty("new-node-type", msgCtxt); nodetype = nodetype.toLowerCase();/*w w w . j ava 2s .co m*/ if (nodetype.equals("element")) return Node.ELEMENT_NODE; if (nodetype.equals("attribute")) return Node.ATTRIBUTE_NODE; if (nodetype.equals("text")) return Node.TEXT_NODE; throw new IllegalStateException("new-node-type value is unknown: (" + nodetype + ")"); }
From source file:com.duroty.lucene.parser.SimpleXmlParser.java
/** * DOCUMENT ME!/*w w w . ja va 2s . c o m*/ * * @param node DOCUMENT ME! */ private void traverseTree(Node node) { /*if (sleep > 0) { try { Thread.sleep(sleep); } catch (Exception ex) { } }*/ if (node == null) { return; } int type = node.getNodeType(); if (type == Node.DOCUMENT_NODE) { traverseTree(((org.w3c.dom.Document) node).getDocumentElement()); } else if (type == Node.TEXT_NODE) { try { String value = node.getNodeValue(); if ((value != null) && !value.equals("") && !value.startsWith("\n")) { buffer.append(value + "\n"); } } catch (Exception ex) { //buffer.append("\n"); } NodeList childNodes = node.getChildNodes(); if (childNodes != null) { for (int i = 0; i < childNodes.getLength(); i++) { traverseTree(childNodes.item(i)); } } } else { NodeList childNodes = node.getChildNodes(); if (childNodes != null) { for (int i = 0; i < childNodes.getLength(); i++) { traverseTree(childNodes.item(i)); } } } }
From source file:Main.java
/** * Find all direct child elements of an element. Children which are * all-whitespace text nodes or comments are ignored; others cause an * exception to be thrown./*w ww . ja v a2 s .com*/ * * @param parent a parent element in a DOM tree * @return a list of direct child elements (may be empty) * @throws IllegalArgumentException if there are non-element children * besides whitespace * * @since 8.4 */ public static List<Element> findSubElements(Element parent) throws IllegalArgumentException { NodeList l = parent.getChildNodes(); List<Element> elements = new ArrayList<Element>(l.getLength()); for (int i = 0; i < l.getLength(); i++) { Node n = l.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { elements.add((Element) n); } else if (n.getNodeType() == Node.TEXT_NODE) { String text = ((Text) n).getNodeValue(); if (text.trim().length() > 0) { throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N } } else if (n.getNodeType() == Node.COMMENT_NODE) { // OK, ignore } else { throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N } } return elements; }
From source file:com.vmware.o11n.plugin.powershell.model.RemotePsType.java
/** * The result form PowerShell execution deserialized in objects of type PSObjectList, PSObject or simple type *///from ww w . ja va 2s . co m @VsoMethod(description = "Returns result of PowerShell script invocation converted in corresponding vCO type. The result can be simple type, ArrayList, Properties or PowerShellPSObject") public Object getRootObject() { initDomDocument(); if (doc == null) { return null; } NodeList nodes = doc.getDocumentElement().getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.TEXT_NODE) { continue; } //The result is always wrapped in single element. // so even if we have array of items, they will be wrapped in <LST> element return read(node); } return null; }
From source file:de.betterform.xml.xforms.model.constraints.RelevanceSelector.java
private static void addChildren(Element relevantElement, Node instanceNode) { Document ownerDocument = relevantElement.getOwnerDocument(); NodeList instanceChildren = instanceNode.getChildNodes(); for (int index = 0; index < instanceChildren.getLength(); index++) { Node instanceChild = (Node) instanceChildren.item(index); if (isEnabled(instanceChild)) { switch (instanceChild.getNodeType()) { case Node.TEXT_NODE: /* rather not, otherwise we cannot follow specs when * serializing to multipart/form-data for example *// w ww .j a v a 2 s . co m // denormalize text for better whitespace handling during serialization List list = DOMWhitespace.denormalizeText(instanceChild.getNodeValue()); for (int item = 0; item < list.size(); item++) { relevantElement.appendChild(ownerDocument.createTextNode(list.get(item).toString())); } */ relevantElement.appendChild(ownerDocument.createTextNode(instanceChild.getNodeValue())); break; case Node.CDATA_SECTION_NODE: relevantElement.appendChild(ownerDocument.createCDATASection(instanceChild.getNodeValue())); break; case Node.ELEMENT_NODE: addElement(relevantElement, instanceChild); break; default: // ignore break; } } } }
From source file:de.betterform.connector.serializer.FormDataSerializer.java
protected void serializeElement(PrintWriter writer, Element element, String boundary, String charset) throws Exception { /* The specs http://www.w3.org/TR/2003/REC-xforms-20031014/slice11.html#serialize-form-data *//from w ww . java 2 s .c om * Each element node is visited in document order. * * Each element that has exactly one text node child is selected * for inclusion. * * Element nodes selected for inclusion are as encoded as * Content-Disposition: form-data MIME parts as defined in * [RFC 2387], with the name parameter being the element local name. * * Element nodes of any datatype populated by upload are serialized * as the specified content and additionally have a * Content-Disposition filename parameter, if available. * * The Content-Type must be text/plain except for xsd:base64Binary, * xsd:hexBinary, and derived types, in which case the header * represents the media type of the attachment if known, otherwise * application/octet-stream. If a character set is applicable, the * Content-Type may have a charset parameter. * */ String nodeValue = null; boolean isCDATASection = false; boolean includeTextNode = true; NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); switch (n.getNodeType()) { /* CDATA sections are not mentioned ... ignore for now case Node.CDATA_SECTION_NODE: isCDATASection = true; */ case Node.TEXT_NODE: if (includeTextNode) { if (nodeValue != null) { /* only one text node allowed by specs */ includeTextNode = false; } else { nodeValue = n.getNodeValue(); } } break; /* Real ambiguity in specs, what if there's one text node and * n elements ? Let's assume if there is an element, ignore the * text nodes */ case Node.ELEMENT_NODE: includeTextNode = false; serializeElement(writer, (Element) n, boundary, charset); break; default: // ignore comments and other nodes... } } if (nodeValue != null && includeTextNode) { Object object = element.getUserData(""); if (object != null && !(object instanceof ModelItem)) { throw new XFormsException("Unknown instance data format."); } ModelItem item = (ModelItem) object; writer.print("\r\n--" + boundary); String name = element.getLocalName(); if (name == null) { name = element.getNodeName(); } // mediatype tells about file upload if (item != null && item.getMediatype() != null) { writer.print("\r\nContent-Disposition: form-data; name=\"" + name + "\";"); if (item.getFilename() != null) { File file = new File(item.getFilename()); writer.print(" filename=\"" + file.getName() + "\";"); } writer.print("\r\nContent-Type: " + item.getMediatype()); } else { writer.print("\r\nContent-Disposition: form-data; name=\"" + name + "\";"); writer.print("\r\nContent-Type: text/plain; charset=\"" + charset + "\";"); } String encoding = "8bit"; if (item != null && "base64Binary".equalsIgnoreCase(item.getDeclarationView().getDatatype())) { encoding = "base64"; } else if (item != null && "hexBinary".equalsIgnoreCase(item.getDeclarationView().getDatatype())) { // recode to base64 because of MIME nodeValue = new String(Base64.encodeBase64(Hex.decodeHex(nodeValue.toCharArray()), true)); encoding = "base64"; } writer.print("\r\nContent-Transfer-Encoding: " + encoding); writer.print("\r\n\r\n" + nodeValue); } writer.flush(); }
From source file:esg.security.yadis.XrdsDoc.java
protected Map extractElementsByParent(String ns, String elem, Set parents, Document document) { Map result = new HashMap(); NodeList nodes = document.getElementsByTagNameNS(ns, elem); Node node;/*from w ww. j a v a 2 s . c o m*/ for (int i = 0; i < nodes.getLength(); i++) { node = nodes.item(i); if (node == null || !parents.contains(node.getParentNode())) continue; String localId = node.getFirstChild() != null && node.getFirstChild().getNodeType() == Node.TEXT_NODE ? node.getFirstChild().getNodeValue() : null; result.put(node.getParentNode(), localId); } return result; }
From source file:org.dozer.eclipse.plugin.sourcepage.validation.Validator.java
@SuppressWarnings("restriction") private void checkClassNodes(NodeList nodeList, IFile file, ValidationInfo validationReport) throws JavaModelException, DOMException { int len = nodeList.getLength(); for (int i = 0; i < len; i++) { Node node = nodeList.item(i); Node textNode = node.getFirstChild(); if (textNode.getNodeType() == Node.TEXT_NODE) { String className = textNode.getNodeValue(); IType javaType = JdtUtils.getJavaType(file.getProject(), className); //class not found if (javaType == null) { Integer[] location = (Integer[]) node.getUserData("location"); validationReport.addError("Class " + className + " not found.", location[0], location[1], validationReport.getFileURI()); }/*from w ww . j a v a2 s . c om*/ } } }