List of usage examples for org.w3c.dom Element getFirstChild
public Node getFirstChild();
From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java
private void addDocumentation(AxisDescription axisDescription, Element documentationElement) { if ((documentationElement != null) && (documentationElement.getFirstChild() != null)) { Node firstChild = documentationElement.getFirstChild(); String documentation = DOM2Writer.nodeToString(firstChild); if (!"".equals(documentation)) { axisDescription.setDocumentation(documentation); }/* w w w .jav a2s . co m*/ } }
From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java
/** * This method is used for adding documentation for the message types of the service operations * eg: input message//from w ww. java 2 s. c om * output message * fault messages * * @param axisOperation * @param documentationElement * @param messageLabel */ private void addMessageDocumentation(AxisOperation axisOperation, Element documentationElement, String messageLabel) { if ((documentationElement != null) && (documentationElement.getFirstChild() != null)) { Node firstChild = documentationElement.getFirstChild(); String documentation = DOM2Writer.nodeToString(firstChild); if (!"".equals(documentation)) { (axisOperation.getMessage(messageLabel)).setDocumentation(documentation); } } }
From source file:org.apache.axis2.description.WSDL20ToAxisServiceBuilder.java
/** * Adds documentation details to a given AxisDescription. * The documentation details is extracted from the WSDL element given. * @param axisDescription - The documentation will be added to this * @param element - The element that the documentation is extracted from. */// w ww. j a v a2s .c o m private void addDocumentation(AxisDescription axisDescription, DocumentableElement element) { DocumentationElement[] documentationElements = element.getDocumentationElements(); String documentation = ""; for (int i = 0; i < documentationElements.length; i++) { DocumentationElement documentationElement = documentationElements[i]; XMLElement contentElement = documentationElement.getContent(); Element content = (Element) contentElement.getSource(); if (content != null) { documentation = documentation + DOM2Writer.nodeToString(content.getFirstChild()); } } if (!"".equals(documentation)) { axisDescription.setDocumentation(documentation); } }
From source file:org.apache.camel.component.cxf.CxfConsumerPayloadXPathClientServerTest.java
@Override protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override//from w w w . j a v a2s. c o m public void configure() { from(simpleEndpointURI + "&dataFormat=PAYLOAD").to("log:info").process(new Processor() { @SuppressWarnings("unchecked") @Override public void process(final Exchange exchange) throws Exception { Object request = exchange.getIn().getBody(); assertIsInstanceOf(CxfPayload.class, request); //attempt 1) applying XPath to exchange.getIn().getBody() receivedMessageCxfPayloadApplyingXPath = XPathBuilder.xpath("//*[name()='arg0']/text()") .evaluate(context, request, String.class); //attempt 2) in stead of XPATH, browse the DOM-tree CxfPayload<SoapHeader> payload = (CxfPayload<SoapHeader>) request; Element el = payload.getBody().get(0); Element el2 = (Element) el.getFirstChild(); Text textnode = (Text) el2.getFirstChild(); receivedMessageByDom = textnode.getNodeValue(); textnode = (Text) textnode.getNextSibling(); while (textnode != null) { //the textnode appears to have siblings! receivedMessageByDom = receivedMessageByDom + textnode.getNodeValue(); textnode = (Text) textnode.getNextSibling(); } //attempt 3) apply XPATH after converting CxfPayload to String request = exchange.getIn().getBody(String.class); assertIsInstanceOf(String.class, request); receivedMessageStringApplyingXPath = XPathBuilder.xpath("//*[name()='arg0']/text()") .evaluate(context, request, String.class); //build some dummy response XmlConverter converter = new XmlConverter(); Document outDocument = converter.toDOMDocument(ECHO_RESPONSE); List<Source> outElements = new ArrayList<Source>(); outElements.add(new DOMSource(outDocument.getDocumentElement())); // set the payload header with null CxfPayload<SoapHeader> responsePayload = new CxfPayload<SoapHeader>(null, outElements, null); exchange.getOut().setBody(responsePayload); } }); } }; }
From source file:org.apache.camel.maven.DocumentationEnricher.java
private void addDocumentation(Element item, String textContent) { Element annotation = document.createElement(Constants.XS_ANNOTATION_ELEMENT_NAME); Element documentation = document.createElement(Constants.XS_DOCUMENTATION_ELEMENT_NAME); documentation.setAttribute("xml:lang", "en"); CDATASection cdataDocumentationText = document.createCDATASection(formatTextContent(item, textContent)); documentation.appendChild(cdataDocumentationText); annotation.appendChild(documentation); if (item.getFirstChild() != null) { item.insertBefore(annotation, item.getFirstChild()); } else {//from w w w .j a v a 2s .c o m item.appendChild(annotation); } }
From source file:org.apache.cxf.systest.provider.CXF4130Test.java
@Test public void testCxf4130() throws Exception { InputStream body = getClass().getResourceAsStream("cxf4130data.txt"); HttpClient client = new HttpClient(); PostMethod post = new PostMethod(ADDRESS); post.setRequestEntity(new InputStreamRequestEntity(body, "text/xml")); client.executeMethod(post);/*from w w w .j a va 2 s . c om*/ Document doc = StaxUtils.read(post.getResponseBodyAsStream()); Element root = doc.getDocumentElement(); Node child = root.getFirstChild(); boolean foundBody = false; while (child != null) { if ("Body".equals(child.getLocalName())) { foundBody = true; assertEquals(1, child.getChildNodes().getLength()); assertEquals("FooResponse", child.getFirstChild().getLocalName()); } child = child.getNextSibling(); } assertTrue("Did not find the soap:Body element", foundBody); }
From source file:org.apache.cxf.systest.provider.CXF4818Test.java
@Test public void testCXF4818() throws Exception { InputStream body = getClass().getResourceAsStream("cxf4818data.txt"); HttpClient client = new HttpClient(); PostMethod post = new PostMethod(ADDRESS); post.setRequestEntity(new InputStreamRequestEntity(body, "text/xml")); client.executeMethod(post);/*from w w w .j av a 2 s. c o m*/ Document doc = StaxUtils.read(post.getResponseBodyAsStream()); //System.out.println(StaxUtils.toString(doc)); Element root = doc.getDocumentElement(); Node child = root.getFirstChild(); boolean foundBody = false; boolean foundHeader = false; while (child != null) { if ("Header".equals(child.getLocalName())) { foundHeader = true; assertFalse("Already found body", foundBody); } else if ("Body".equals(child.getLocalName())) { foundBody = true; assertTrue("Did not find header before the body", foundHeader); } child = child.getNextSibling(); } assertTrue("Did not find the soap:Body element", foundBody); assertTrue("Did not find the soap:Header element", foundHeader); }
From source file:org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBindingParser.java
void parseElement(JAXWSBinding jaxwsBinding, Element element) { Node child = element.getFirstChild(); if (child == null) { // global binding if (isAsyncElement(element)) { jaxwsBinding.setEnableAsyncMapping(getNodeValue(element)); }/*from www .j av a 2 s. co m*/ if (isMIMEElement(element)) { jaxwsBinding.setEnableMime(getNodeValue(element)); } if (isPackageElement(element)) { jaxwsBinding.setPackage(getPackageName(element)); } if (isWrapperStyle(element)) { jaxwsBinding.setEnableWrapperStyle(getNodeValue(element)); } } else { // other binding while (child != null) { if (isAsyncElement(child)) { jaxwsBinding.setEnableAsyncMapping(getNodeValue(child)); } else if (isMIMEElement(child)) { jaxwsBinding.setEnableMime(getNodeValue(child)); } else if (isWrapperStyle(child)) { jaxwsBinding.setEnableWrapperStyle(getNodeValue(child)); } else if (isPackageElement(child)) { jaxwsBinding.setPackage(getPackageName(child)); Node docChild = DOMUtils.getChild(child, Element.ELEMENT_NODE); if (docChild != null && this.isJAXWSClassDoc(docChild)) { jaxwsBinding.setPackageJavaDoc(StringEscapeUtils.escapeHtml(DOMUtils.getContent(docChild))); } } else if (isJAXWSMethodElement(child)) { jaxwsBinding.setMethodName(getMethodName(child)); Node docChild = DOMUtils.getChild(child, Element.ELEMENT_NODE); if (docChild != null && this.isJAXWSClassDoc(docChild)) { jaxwsBinding.setMethodJavaDoc(StringEscapeUtils.escapeHtml(DOMUtils.getContent(docChild))); } } else if (isJAXWSParameterElement(child)) { Element childElement = (Element) child; String partPath = "//" + childElement.getAttribute("part"); Node node = queryXPathNode(element.getOwnerDocument().getDocumentElement(), partPath); String messageName = ""; String partName = ""; if (node != null) { partName = ((Element) node).getAttribute("name"); Node messageNode = node.getParentNode(); if (messageNode != null) { Element messageEle = (Element) messageNode; messageName = messageEle.getAttribute("name"); } } String name = childElement.getAttribute("name"); String elementNameString = childElement.getAttribute("childElementName"); QName elementName = null; if (!StringUtils.isEmpty(elementNameString)) { String ns = ""; if (elementNameString.indexOf(':') != -1) { ns = elementNameString.substring(0, elementNameString.indexOf(':')); ns = childElement.lookupNamespaceURI(ns); elementNameString = elementNameString.substring(elementNameString.indexOf(':') + 1); } elementName = new QName(ns, elementNameString); } JAXWSParameter jpara = new JAXWSParameter(messageName, partName, elementName, name); jaxwsBinding.addJaxwsPara(jpara); } else if (isJAXWSClass(child)) { Element childElement = (Element) child; String clzName = childElement.getAttribute("name"); String javadoc = ""; Node docChild = DOMUtils.getChild(child, Element.ELEMENT_NODE); if (docChild != null && this.isJAXWSClassDoc(docChild)) { javadoc = StringEscapeUtils.escapeHtml(DOMUtils.getContent(docChild)); } JAXWSClass jaxwsClass = new JAXWSClass(clzName, javadoc); jaxwsBinding.setJaxwsClass(jaxwsClass); } child = child.getNextSibling(); } } }
From source file:org.apache.hadoop.conf.Configuration.java
private void loadResource(Properties properties, Object name, boolean quiet) { try {/* w ww . jav a2s. c o m*/ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); //ignore all comments inside the xml file docBuilderFactory.setIgnoringComments(true); //allow includes in the xml file docBuilderFactory.setNamespaceAware(true); try { docBuilderFactory.setXIncludeAware(true); } catch (UnsupportedOperationException e) { LOG.error("Failed to set setXIncludeAware(true) for parser " + docBuilderFactory + ":" + e, e); } DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); Document doc = null; Element root = null; if (name instanceof URL) { // an URL resource URL url = (URL) name; if (url != null) { if (!quiet) { LOG.info("parsing " + url); } doc = builder.parse(url.toString()); } } else if (name instanceof String) { // a CLASSPATH resource URL url = getResource((String) name); if (url != null) { if (!quiet) { LOG.info("parsing " + url); } doc = builder.parse(url.toString()); } } else if (name instanceof Path) { // a file resource // Can't use FileSystem API or we get an infinite loop // since FileSystem uses Configuration API. Use java.io.File instead. File file = new File(((Path) name).toUri().getPath()).getAbsoluteFile(); if (file.exists()) { if (!quiet) { LOG.info("parsing " + file); } InputStream in = new BufferedInputStream(new FileInputStream(file)); try { doc = builder.parse(in); } finally { in.close(); } } } else if (name instanceof InputStream) { try { doc = builder.parse((InputStream) name); } finally { ((InputStream) name).close(); } } else if (name instanceof Element) { root = (Element) name; } if (doc == null && root == null) { if (quiet) return; throw new RuntimeException(name + " not found"); } if (root == null) { root = doc.getDocumentElement(); } if (!"configuration".equals(root.getTagName())) LOG.fatal("bad conf file: top-level element not <configuration>"); NodeList props = root.getChildNodes(); for (int i = 0; i < props.getLength(); i++) { Node propNode = props.item(i); if (!(propNode instanceof Element)) continue; Element prop = (Element) propNode; if ("configuration".equals(prop.getTagName())) { loadResource(properties, prop, quiet); continue; } if (!"property".equals(prop.getTagName())) LOG.warn("bad conf file: element not <property>"); NodeList fields = prop.getChildNodes(); String attr = null; String value = null; boolean finalParameter = false; for (int j = 0; j < fields.getLength(); j++) { Node fieldNode = fields.item(j); if (!(fieldNode instanceof Element)) continue; Element field = (Element) fieldNode; if ("name".equals(field.getTagName()) && field.hasChildNodes()) attr = ((Text) field.getFirstChild()).getData().trim(); if ("value".equals(field.getTagName()) && field.hasChildNodes()) value = ((Text) field.getFirstChild()).getData(); if ("final".equals(field.getTagName()) && field.hasChildNodes()) finalParameter = "true".equals(((Text) field.getFirstChild()).getData()); } // Ignore this parameter if it has already been marked as 'final' if (attr != null) { if (value != null) { if (!finalParameters.contains(attr)) { properties.setProperty(attr, value); if (storeResource) { updatingResource.put(attr, name.toString()); } } else if (!value.equals(properties.getProperty(attr))) { LOG.warn(name + ":a attempt to override final parameter: " + attr + "; Ignoring."); } } if (finalParameter) { finalParameters.add(attr); } } } } catch (IOException e) { LOG.fatal("error parsing conf file: " + e); throw new RuntimeException(e); } catch (DOMException e) { LOG.fatal("error parsing conf file: " + e); throw new RuntimeException(e); } catch (SAXException e) { LOG.fatal("error parsing conf file: " + e); throw new RuntimeException(e); } catch (ParserConfigurationException e) { LOG.fatal("error parsing conf file: " + e); throw new RuntimeException(e); } }
From source file:org.apache.hadoop.corona.ConfigManager.java
/** * Get the text inside of the Xml element * @param element xml element//from ww w. ja v a2 s. c o m * @return the text inside of the xml element */ private static String getText(Element element) { if (element.getFirstChild() == null) { return ""; } return ((Text) element.getFirstChild()).getData().trim(); }