List of usage examples for org.w3c.dom Node COMMENT_NODE
short COMMENT_NODE
To view the source code for org.w3c.dom Node COMMENT_NODE.
Click Source Link
Comment
. From source file:org.cruxframework.crux.core.declarativeui.crossdevice.CrossDevices.java
/** * @param parentElement//from w w w .j a v a2s . co m * @return */ static List<Element> extractChildrenElements(Element parentElement) { List<Element> result = new ArrayList<Element>(); NodeList childNodes = parentElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); switch (node.getNodeType()) { case Node.COMMENT_NODE: //ignore node break; case Node.TEXT_NODE: Text textNode = (Text) node; if (textNode.getWholeText().trim().length() > 0) { return null; } break; case Node.ELEMENT_NODE: result.add((Element) node); break; default: return null; } } return result; }
From source file:org.dhatim.delivery.dom.serialize.Serializer.java
/** * Recursively write the DOM tree to the supplied writer. * @param element Element to write./*from w w w.j a v a2 s .c o m*/ * @param writer Writer to use. * @param isRoot Is the supplied element the document root element. * @throws IOException Exception writing to Writer. */ private void recursiveDOMWrite(Element element, Writer writer, boolean isRoot) throws IOException { SerializationUnit elementSU; NodeList children = element.getChildNodes(); elementSU = getSerializationUnit(element, isRoot); try { if (elementSU != null) { elementSU.writeElementStart(element, writer, executionContext); } if (children != null && children.getLength() > 0) { int childCount = children.getLength(); for (int i = 0; i < childCount; i++) { Node childNode = children.item(i); if (elementSU != null) { switch (childNode.getNodeType()) { case Node.CDATA_SECTION_NODE: { elementSU.writeElementCDATA((CDATASection) childNode, writer, executionContext); break; } case Node.COMMENT_NODE: { elementSU.writeElementComment((Comment) childNode, writer, executionContext); break; } case Node.ELEMENT_NODE: { if (elementSU.writeChildElements()) { recursiveDOMWrite((Element) childNode, writer, false); } break; } case Node.ENTITY_REFERENCE_NODE: { elementSU.writeElementEntityRef((EntityReference) childNode, writer, executionContext); break; } case Node.TEXT_NODE: { elementSU.writeElementText((Text) childNode, writer, executionContext); break; } default: { elementSU.writeElementNode(childNode, writer, executionContext); break; } } } else if (childNode.getNodeType() == Node.ELEMENT_NODE) { recursiveDOMWrite((Element) childNode, writer, false); } } } if (elementSU != null) { elementSU.writeElementEnd(element, writer, executionContext); } } catch (Throwable thrown) { String error = "Failed to apply serialization unit [" + elementSU.getClass().getName() + "] to [" + executionContext.getDocumentSource() + ":" + DomUtils.getXPath(element) + "]."; if (terminateOnVisitorException) { if (thrown instanceof SmooksException) { throw (SmooksException) thrown; } else { throw new SmooksException(error, thrown); } } else { logger.debug(error, thrown); } } }
From source file:org.dhatim.delivery.dom.serialize.Serializer.java
/** * Recursively write the DOM tree to the supplied writer. * @param element Element to write./*from w w w .j a v a 2s. c o m*/ * @param writer Writer to use. * @throws IOException Exception writing to Writer. */ public static void recursiveDOMWrite(Element element, Writer writer) throws IOException { NodeList children = element.getChildNodes(); try { defaultSerializer.writeElementStart(element, writer); if (children != null && children.getLength() > 0) { int childCount = children.getLength(); for (int i = 0; i < childCount; i++) { Node childNode = children.item(i); switch (childNode.getNodeType()) { case Node.CDATA_SECTION_NODE: { defaultSerializer.writeElementCDATA((CDATASection) childNode, writer, null); break; } case Node.COMMENT_NODE: { defaultSerializer.writeElementComment((Comment) childNode, writer, null); break; } case Node.ELEMENT_NODE: { recursiveDOMWrite((Element) childNode, writer); break; } case Node.ENTITY_REFERENCE_NODE: { defaultSerializer.writeElementEntityRef((EntityReference) childNode, writer, null); break; } case Node.TEXT_NODE: { defaultSerializer.writeElementText((Text) childNode, writer, null); break; } default: { defaultSerializer.writeElementNode(childNode, writer, null); break; } } } } defaultSerializer.writeElementEnd(element, writer); } catch (Throwable thrown) { if (thrown instanceof SmooksException) { throw (SmooksException) thrown; } else { throw new SmooksException("Serailization Error.", thrown); } } }
From source file:org.dhatim.xml.DomUtils.java
/** * Construct the XPath of the supplied DOM Node. * <p/>// w ww . ja v a2s . c om * Supports element, comment and cdata sections DOM Node types. * @param node DOM node for XPath generation. * @return XPath string representation of the supplied DOM Node. */ public static String getXPath(Node node) { AssertArgument.isNotNull(node, "node"); StringBuffer xpath = new StringBuffer(); Node parent = node.getParentNode(); switch (node.getNodeType()) { case Node.ELEMENT_NODE: xpath.append(getXPathToken((Element) node)); break; case Node.COMMENT_NODE: int commentNum = DomUtils.countNodesBefore(node, Node.COMMENT_NODE); xpath.append("/{COMMENT}[" + commentNum + 1 + "]"); break; case Node.CDATA_SECTION_NODE: int cdataNum = DomUtils.countNodesBefore(node, Node.CDATA_SECTION_NODE); xpath.append("/{CDATA}[" + cdataNum + 1 + "]"); break; default: throw new UnsupportedOperationException( "XPath generation for supplied DOM Node type not supported. Only supports element, comment and cdata section DOM nodes."); } while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) { xpath.insert(0, getXPathToken((Element) parent)); parent = parent.getParentNode(); } return xpath.toString(); }
From source file:org.dhatim.xml.DomUtils.java
/** * Get the combined text from all the text, comment and cdata DOM nodes * contained within the supplied parent element. * @param parent The parent DOM element.//from www . j a v a 2 s . c om * @param removeEntities Remove all HTML entity and character references from * the DOM Text child nodes and replace them with their equivalent characters. Note * this is not performed on Comment or CDATA section nodes. * @return The combined (concatenated) contents of all child text, comment * and cdata DOM nodes. An empty String no such nodes are present. */ public static String getAllText(Element parent, boolean removeEntities) { AssertArgument.isNotNull(parent, "parent"); NodeList children = parent.getChildNodes(); StringBuffer text = new StringBuffer(); int childCount = children.getLength(); for (int i = 0; i < childCount; i++) { Node child = children.item(i); switch (child.getNodeType()) { case Node.TEXT_NODE: String data = ((Text) child).getData(); if (removeEntities) { text.append(XmlUtil.removeEntities(data)); } else { text.append(data); } break; case Node.CDATA_SECTION_NODE: // CDATA_SECTION_NODE nodes are a subtype of the Text node. text.append(((Text) child).getData()); break; case Node.COMMENT_NODE: text.append(((Comment) child).getData()); break; default: break; } } return text.toString(); }
From source file:org.directwebremoting.spring.DwrNamespaceHandler.java
/** * Registers a new {@link org.directwebremoting.extend.Creator} in the registry using name <code>javascript</code>. * @param registry The definition of all the Beans * @param javascript The name of the bean in the registry. * @param creatorConfig/*w w w .j a va 2 s . c o m*/ * @param params * @param children The node list to check for nested elements */ @SuppressWarnings("unchecked") protected void registerCreator(BeanDefinitionRegistry registry, String javascript, BeanDefinitionBuilder creatorConfig, Map<String, String> params, NodeList children) { registerSpringConfiguratorIfNecessary(registry); List<String> includes = new ArrayList<String>(); creatorConfig.addPropertyValue("includes", includes); List<String> excludes = new ArrayList<String>(); creatorConfig.addPropertyValue("excludes", excludes); Properties auth = new Properties(); creatorConfig.addPropertyValue("auth", auth); // check to see if there are any nested elements here for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.COMMENT_NODE) { continue; } Element child = (Element) node; if ("dwr:latencyfilter".equals(node.getNodeName())) { BeanDefinitionBuilder beanFilter = BeanDefinitionBuilder .rootBeanDefinition(ExtraLatencyAjaxFilter.class); beanFilter.addPropertyValue("delay", child.getAttribute("delay")); BeanDefinitionHolder holder2 = new BeanDefinitionHolder(beanFilter.getBeanDefinition(), "__latencyFilter_" + javascript); BeanDefinitionReaderUtils.registerBeanDefinition(holder2, registry); ManagedList filterList = new ManagedList(); filterList.add(new RuntimeBeanReference("__latencyFilter_" + javascript)); creatorConfig.addPropertyValue("filters", filterList); } else if ("dwr:include".equals(node.getNodeName())) { includes.add(child.getAttribute("method")); } else if ("dwr:exclude".equals(node.getNodeName())) { excludes.add(child.getAttribute("method")); } else if ("dwr:auth".equals(node.getNodeName())) { auth.setProperty(child.getAttribute("method"), child.getAttribute("role")); } else if ("dwr:convert".equals(node.getNodeName())) { Element element = (Element) node; String type = element.getAttribute("type"); String className = element.getAttribute("class"); ConverterConfig converterConfig = new ConverterConfig(); converterConfig.setType(type); parseConverterSettings(converterConfig, element); lookupConverters(registry).put(className, converterConfig); } else if ("dwr:filter".equals(node.getNodeName())) { Element element = (Element) node; String filterClass = element.getAttribute("class"); List<Element> filterParamElements = DomUtils.getChildElementsByTagName(element, "param"); BeanDefinitionBuilder beanFilter; try { beanFilter = BeanDefinitionBuilder.rootBeanDefinition(ClassUtils.forName(filterClass)); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("DWR filter class '" + filterClass + "' was not found. " + "Check the class name specified in <dwr:filter class=\"" + filterClass + "\" /> exists"); } for (Element filterParamElement : filterParamElements) { beanFilter.addPropertyValue(filterParamElement.getAttribute("name"), filterParamElement.getAttribute("value")); } BeanDefinitionHolder holder2 = new BeanDefinitionHolder(beanFilter.getBeanDefinition(), "__filter_" + filterClass + "_" + javascript); BeanDefinitionReaderUtils.registerBeanDefinition(holder2, registry); ManagedList filterList = new ManagedList(); filterList.add(new RuntimeBeanReference("__filter_" + filterClass + "_" + javascript)); creatorConfig.addPropertyValue("filters", filterList); } else if ("dwr:param".equals(node.getNodeName())) { Element element = (Element) node; String name = element.getAttribute("name"); String value = element.getAttribute("value"); params.put(name, value); } else { throw new RuntimeException("an unknown dwr:remote sub node was fouund: " + node.getNodeName()); } } creatorConfig.addPropertyValue("params", params); String creatorConfigName = "__" + javascript; BeanDefinitionHolder holder3 = new BeanDefinitionHolder(creatorConfig.getBeanDefinition(), creatorConfigName); BeanDefinitionReaderUtils.registerBeanDefinition(holder3, registry); lookupCreators(registry).put(javascript, new RuntimeBeanReference(creatorConfigName)); }
From source file:org.directwebremoting.spring.DwrNamespaceHandler.java
/** * @param converterConfig/*from w w w .ja va2s .c om*/ * @param parent */ protected void parseConverterSettings(ConverterConfig converterConfig, Element parent) { NodeList children = parent.getChildNodes(); // check to see if there are any nested elements here for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.COMMENT_NODE) { continue; } Element child = (Element) node; if ("dwr:include".equals(child.getNodeName())) { converterConfig.addInclude(child.getAttribute("method")); } else if ("dwr:exclude".equals(child.getNodeName())) { converterConfig.addExclude(child.getAttribute("method")); } /* TODO Why is this only a property of ObjectConverter? else if (child.getNodeName().equals("dwr:force")) { converterConfig.setForce(Boolean.parseBoolean(child.getAttribute("value"))); } */ else { throw new RuntimeException("an unknown dwr:remote sub node was found: " + node.getNodeName()); } } }
From source file:org.eclipse.birt.report.engine.emitter.docx.writer.BasicComponent.java
private void processNodes(Element ele, HashMap cssStyles, HTMLWriter writer, Map appContext) { for (Node node = ele.getFirstChild(); node != null; node = node.getNextSibling()) { // At present we only deal with the text, comment and element nodes short nodeType = node.getNodeType(); if (nodeType == Node.TEXT_NODE) { if (isScriptText(node)) { writer.cdata(node.getNodeValue()); } else { // bug132213 in text item should only deal with the // escape special characters: < > & // writer.text( node.getNodeValue( ), false, true ); writer.text(node.getNodeValue()); }//w w w .j a v a 2 s . c o m } else if (nodeType == Node.COMMENT_NODE) { writer.comment(node.getNodeValue()); } else if (nodeType == Node.ELEMENT_NODE) { Element element = (Element) node; if ("br".equalsIgnoreCase(node.getNodeName())) { // <br/> is correct. <br></br> is not correct. The brower // will treat the <br></br> as <br><br> boolean bImplicitCloseTag = writer.isImplicitCloseTag(); writer.setImplicitCloseTag(true); startNode(node, cssStyles, writer, appContext); processNodes((Element) node, cssStyles, writer, appContext); endNode(node, writer); writer.setImplicitCloseTag(bImplicitCloseTag); } else { startNode(node, cssStyles, writer, appContext); processNodes((Element) node, cssStyles, writer, appContext); endNode(node, writer); } } } }
From source file:org.eclipse.smila.connectivity.framework.crawler.web.parse.html.DOMContentUtils.java
private boolean getTextHelper(StringBuffer sb, Node node, boolean abortOnNestedAnchors, int anchorDepth) { if ("script".equalsIgnoreCase(node.getNodeName())) { return false; }/*from w w w.j a v a 2 s. c o m*/ if ("style".equalsIgnoreCase(node.getNodeName())) { return false; } if (abortOnNestedAnchors && "a".equalsIgnoreCase(node.getNodeName())) { anchorDepth++; if (anchorDepth > 1) { return true; } } if (node.getNodeType() == Node.COMMENT_NODE) { return false; } if (node.getNodeType() == Node.TEXT_NODE) { // cleanup and trim the value String text = node.getNodeValue(); text = text.replaceAll("\\s+", " "); text = text.trim(); if (text.length() > 0) { if (sb.length() > 0) { sb.append(' '); } sb.append(text); } } boolean abort = false; NodeList children = node.getChildNodes(); if (children != null) { int len = children.getLength(); for (int i = 0; i < len; i++) { if (getTextHelper(sb, children.item(i), abortOnNestedAnchors, anchorDepth)) { abort = true; break; } } } return abort; }
From source file:org.eclipse.wst.xsl.xalan.debugger.XalanVariable.java
private String processNodeList(NodeList nodeList) { String value = ""; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node != null) { int nodeType = node.getNodeType(); if (node.getNodeType() == Node.ELEMENT_NODE) { value = createElement(value, node); }//from www . ja va 2s . com if (nodeType == Node.COMMENT_NODE) { value = value + "<!-- " + node.getNodeValue() + " -->"; } if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) { ProcessingInstruction pi = (ProcessingInstruction) node; value = value + "<?" + pi.getData() + " ?>"; } } } return value; }