List of usage examples for org.w3c.dom Node CDATA_SECTION_NODE
short CDATA_SECTION_NODE
To view the source code for org.w3c.dom Node CDATA_SECTION_NODE.
Click Source Link
CDATASection
. From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
private void addElement(SOAPMessage responseMessage, SOAPEnvelope soapEnvelope, Context context, Element elementToAdd, SOAPElement soapElement) throws SOAPException { SOAPElement soapMethodResponseElement = (SOAPElement) soapEnvelope.getBody().getFirstChild(); String targetNamespace = soapMethodResponseElement.getNamespaceURI(); String prefix = soapMethodResponseElement.getPrefix(); String nodeType = elementToAdd.getAttribute("type"); SOAPElement childSoapElement = soapElement; boolean elementAdded = true; boolean bTable = false; if (nodeType.equals("table")) { bTable = true;// www .j a v a2 s . co m /*childSoapElement = soapElement.addChildElement("ArrayOf" + context.transactionName + "_" + tableName + "_Row", ""); if (!context.httpServletRequest.getServletPath().endsWith(".wsl")) { childSoapElement.addAttribute(soapEnvelope.createName("xsi:type"), "soapenc:Array"); }*/ childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); } else if (nodeType.equals("row")) { /*String elementType = context.transactionName + "_" + tableName + "_Row"; childSoapElement = soapElement.addChildElement(elementType, "");*/ childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); } else if (nodeType.equals("attachment")) { childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); if (context.requestedObject instanceof AbstractHttpTransaction) { AttachmentDetails attachment = AttachmentManager.getAttachment(elementToAdd); if (attachment != null) { byte[] raw = attachment.getData(); if (raw != null) childSoapElement.addTextNode(Base64.encodeBase64String(raw)); } /* DON'T WORK YET *\ AttachmentPart ap = responseMessage.createAttachmentPart(new ByteArrayInputStream(raw), elementToAdd.getAttribute("content-type")); ap.setContentId(key); ap.setContentLocation(elementToAdd.getAttribute("url")); responseMessage.addAttachmentPart(ap); \* DON'T WORK YET */ } } else { String elementNodeName = elementToAdd.getNodeName(); String elementNodeNsUri = elementToAdd.getNamespaceURI(); String elementNodePrefix = getPrefix(context.projectName, elementNodeNsUri); XmlSchemaElement xmlSchemaElement = getXmlSchemaElementByName(context.projectName, elementNodeName); boolean isGlobal = xmlSchemaElement != null; if (isGlobal) { elementNodeNsUri = xmlSchemaElement.getQName().getNamespaceURI(); elementNodePrefix = getPrefix(context.projectName, elementNodeNsUri); } // ignore original SOAP message response elements // if ((elementNodeName.toUpperCase().indexOf("SOAP-ENV:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("SOAP-ENV:") != -1)) || // (elementNodeName.toUpperCase().indexOf("SOAPENV:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("SOAPENV:") != -1)) || // (elementNodeName.toUpperCase().indexOf("NS0:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1))) { // elementAdded = false; // } if ("http://schemas.xmlsoap.org/soap/envelope/".equals(elementToAdd.getNamespaceURI()) || "http://schemas.xmlsoap.org/soap/envelope/" .equals(elementToAdd.getParentNode().getNamespaceURI()) || elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1 || elementNodeName.toUpperCase().indexOf("NS0:") != -1) { elementAdded = false; } else { if (XsdForm.qualified == context.project.getSchemaElementForm() || isGlobal) { if (elementNodePrefix == null) { childSoapElement = soapElement .addChildElement(soapEnvelope.createName(elementNodeName, prefix, targetNamespace)); } else { childSoapElement = soapElement.addChildElement( soapEnvelope.createName(elementNodeName, elementNodePrefix, elementNodeNsUri)); } } else { childSoapElement = soapElement.addChildElement(elementNodeName); } } } if (elementAdded && elementToAdd.hasAttributes()) { addAttributes(responseMessage, soapEnvelope, context, elementToAdd.getAttributes(), childSoapElement); } if (elementToAdd.hasChildNodes()) { NodeList childNodes = elementToAdd.getChildNodes(); int len = childNodes.getLength(); if (bTable) { /*if (!context.httpServletRequest.getServletPath().endsWith(".wsl")) { childSoapElement.addAttribute(soapEnvelope.createName("soapenc:arrayType"), context.projectName+"_ns:" + context.transactionName + "_" + tableName + "_Row[" + (len - 1) + "]"); }*/ } org.w3c.dom.Node node; Element childElement; for (int i = 0; i < len; i++) { node = childNodes.item(i); switch (node.getNodeType()) { case org.w3c.dom.Node.ELEMENT_NODE: childElement = (Element) node; addElement(responseMessage, soapEnvelope, context, childElement, childSoapElement); break; case org.w3c.dom.Node.CDATA_SECTION_NODE: case org.w3c.dom.Node.TEXT_NODE: String text = node.getNodeValue(); text = (text == null) ? "" : text; childSoapElement.addTextNode(text); break; default: break; } } /*org.w3c.dom.Node node; Element childElement; for (int i = 0 ; i < len ; i++) { node = childNodes.item(i); if (node instanceof Element) { childElement = (Element) node; addElement(responseMessage, soapEnvelope, context, childElement, childSoapElement); } else if (node instanceof CDATASection) { Node textNode = XMLUtils.findChildNode(elementToAdd, org.w3c.dom.Node.CDATA_SECTION_NODE); String text = textNode.getNodeValue(); if (text == null) { text = ""; } childSoapElement.addTextNode(text); } else { Node textNode = XMLUtils.findChildNode(elementToAdd, org.w3c.dom.Node.TEXT_NODE); if (textNode != null) { String text = textNode.getNodeValue(); if (text == null) { text = ""; } childSoapElement.addTextNode(text); } } }*/ } }
From source file:autohit.creator.compiler.SimCompiler.java
/** * Get the text out of an XML node./*from ww w .j a v a 2 s . co m*/ * * @param cdn XML node. * @return the text. */ private String getText(Node cdn) { try { if ((cdn.getNodeType() == Node.TEXT_NODE) || (cdn.getNodeType() != Node.CDATA_SECTION_NODE)) { CharacterData cdnc = (CharacterData) cdn; return cdnc.getData(); } } catch (Exception e) { } // ignore. re are returning empty anyway return null; }
From source file:jef.tools.XMLUtils.java
/** * Element(??)// w ww . j av a2 s . co m * * @param node * * @param tagName * ????nullElement * @return ?? */ public static List<Element> childElements(Node node, String... tagName) { if (node == null) throw new NullPointerException("the input node can not be null!"); List<Element> list = new ArrayList<Element>(); NodeList nds = node.getChildNodes(); if (tagName.length == 0 || tagName[0] == null) {// ?API tagName = null; } for (int i = 0; i < nds.getLength(); i++) { Node child = nds.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) child; if (tagName == null || ArrayUtils.contains(tagName, e.getNodeName())) { list.add(e); } } else if (child.getNodeType() == Node.CDATA_SECTION_NODE) { } else if (child.getNodeType() == Node.COMMENT_NODE) { } else if (child.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) { } else if (child.getNodeType() == Node.DOCUMENT_NODE) { } else if (child.getNodeType() == Node.DOCUMENT_TYPE_NODE) { } else if (child.getNodeType() == Node.ATTRIBUTE_NODE) { } else if (child.getNodeType() == Node.TEXT_NODE) { } } return list; }
From source file:jef.tools.XMLUtils.java
/** * ?(Trimed)/*from w ww. j a v a2 s. c o m*/ * * @param element * * @return xml */ public static String nodeText(Node element) { Node first = first(element, Node.TEXT_NODE, Node.CDATA_SECTION_NODE); if (first != null && first.getNodeType() == Node.CDATA_SECTION_NODE) { return ((CDATASection) first).getTextContent(); } StringBuilder sb = new StringBuilder(); if (first == null || StringUtils.isBlank(first.getTextContent())) { for (Node n : toArray(element.getChildNodes())) { if (n.getNodeType() == Node.TEXT_NODE) { sb.append(n.getTextContent()); } else if (n.getNodeType() == Node.CDATA_SECTION_NODE) { sb.append(((CDATASection) n).getTextContent()); } } } else { sb.append(first.getTextContent()); } return StringUtils.trimToNull(StringEscapeUtils.unescapeHtml(sb.toString())); }
From source file:jef.tools.XMLUtils.java
/** * text//w ww .ja v a 2 s . c om * * @param element * * @param withChildren * ??? * @return xml */ public static String nodeText(Node element, boolean withChildren) { StringBuilder sb = new StringBuilder(); for (Node node : toArray(element.getChildNodes())) { if (node.getNodeType() == Node.TEXT_NODE) { sb.append(node.getNodeValue().trim()); } else if (node.getNodeType() == Node.CDATA_SECTION_NODE) { sb.append(((CDATASection) node).getTextContent()); } else if (withChildren) { if (node.getNodeType() == Node.ELEMENT_NODE) { sb.append(nodeText((Element) node, true)); } } } return sb.toString(); }
From source file:jef.tools.XMLUtils.java
private static String getValue(Node node) { switch (node.getNodeType()) { case Node.ELEMENT_NODE: return nodeText((Element) node); case Node.TEXT_NODE: return StringUtils.trimToNull(StringEscapeUtils.unescapeHtml(node.getTextContent())); case Node.CDATA_SECTION_NODE: return ((CDATASection) node).getTextContent(); default:/*from w ww . java2 s.c om*/ return StringEscapeUtils.unescapeHtml(node.getNodeValue()); } }
From source file:net.sourceforge.pmd.lang.xml.ast.DOMLineNumbers.java
private int determineLocation(Node n, int index) { int nextIndex = index; if (n.getNodeType() == Node.DOCUMENT_TYPE_NODE) { nextIndex = xmlString.indexOf("<!DOCTYPE", nextIndex); } else if (n.getNodeType() == Node.COMMENT_NODE) { nextIndex = xmlString.indexOf("<!--", nextIndex); } else if (n.getNodeType() == Node.ELEMENT_NODE) { nextIndex = xmlString.indexOf("<" + n.getNodeName(), nextIndex); } else if (n.getNodeType() == Node.CDATA_SECTION_NODE) { nextIndex = xmlString.indexOf("<![CDATA[", nextIndex); } else if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { ProcessingInstruction pi = (ProcessingInstruction) n; nextIndex = xmlString.indexOf("<?" + pi.getTarget(), nextIndex); } else if (n.getNodeType() == Node.TEXT_NODE) { String te = unexpandEntities(n, n.getNodeValue()); int newIndex = xmlString.indexOf(te, nextIndex); if (newIndex > 0) { nextIndex = newIndex;// w w w . jav a2 s. c o m } } else if (n.getNodeType() == Node.ENTITY_REFERENCE_NODE) { nextIndex = xmlString.indexOf("&" + n.getNodeName() + ";", nextIndex); } setBeginLocation(n, nextIndex); if (n.hasChildNodes()) { NodeList childs = n.getChildNodes(); for (int i = 0; i < childs.getLength(); i++) { nextIndex = determineLocation(childs.item(i), nextIndex); } } if (n.getNodeType() == Node.ELEMENT_NODE) { nextIndex += 2 + n.getNodeName().length() + 1; // </nodename> } else if (n.getNodeType() == Node.DOCUMENT_TYPE_NODE) { Node nextSibling = n.getNextSibling(); if (nextSibling.getNodeType() == Node.ELEMENT_NODE) { nextIndex = xmlString.indexOf("<" + nextSibling.getNodeName(), nextIndex) - 1; } else if (nextSibling.getNodeType() == Node.COMMENT_NODE) { nextIndex = xmlString.indexOf("<!--", nextIndex); } else { nextIndex = xmlString.indexOf(">", nextIndex); } } else if (n.getNodeType() == Node.COMMENT_NODE) { nextIndex += 4 + 3; // <!-- and --> nextIndex += n.getNodeValue().length(); } else if (n.getNodeType() == Node.TEXT_NODE) { String te = unexpandEntities(n, n.getNodeValue()); nextIndex += te.length(); } else if (n.getNodeType() == Node.CDATA_SECTION_NODE) { nextIndex += "<![CDATA[".length() + n.getNodeValue().length() + "]]>".length(); } else if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { ProcessingInstruction pi = (ProcessingInstruction) n; nextIndex += "<?".length() + pi.getTarget().length() + "?>".length() + pi.getData().length(); } setEndLocation(n, nextIndex - 1); return nextIndex; }
From source file:net.sourceforge.pmd.rules.RuleFactory.java
/** * Parse a String from a textually type node. * * @param node The node./*w ww . j a va 2s .c om*/ * * @return The String. */ private static String parseTextNode(Node node) { final int nodeCount = node.getChildNodes().getLength(); if (nodeCount == 0) { return ""; } StringBuilder buffer = new StringBuilder(); for (int i = 0; i < nodeCount; i++) { Node childNode = node.getChildNodes().item(i); if (childNode.getNodeType() == Node.CDATA_SECTION_NODE || childNode.getNodeType() == Node.TEXT_NODE) { buffer.append(childNode.getNodeValue()); } } return buffer.toString(); }
From source file:net.sourceforge.pmd.RuleSetFactory.java
/** * Parse a String from a textually type node. * * @param node/*from w w w . j a v a 2s.c o m*/ * The node. * @return The String. */ private static String parseTextNode(Node node) { final int nodeCount = node.getChildNodes().getLength(); if (nodeCount == 0) { return ""; } StringBuilder buffer = new StringBuilder(); for (int i = 0; i < nodeCount; i++) { Node childNode = node.getChildNodes().item(i); if (childNode.getNodeType() == Node.CDATA_SECTION_NODE || childNode.getNodeType() == Node.TEXT_NODE) { buffer.append(childNode.getNodeValue()); } } return buffer.toString(); }
From source file:net.sourceforge.pmd.testframework.RuleTst.java
private static String parseTextNode(Node exampleNode) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < exampleNode.getChildNodes().getLength(); i++) { Node node = exampleNode.getChildNodes().item(i); if (node.getNodeType() == Node.CDATA_SECTION_NODE || node.getNodeType() == Node.TEXT_NODE) { buffer.append(node.getNodeValue()); }/*w w w. j av a2 s. c om*/ } return buffer.toString().trim(); }