List of usage examples for org.w3c.dom Element getTextContent
public String getTextContent() throws DOMException;
From source file:Main.java
public static List<String> getAllLeaveValues(Element element) throws XPathExpressionException { if (element == null) { return null; }/*w w w. j a v a 2 s . co m*/ List<String> ret = new LinkedList<String>(); if (isLeaf(element)) { ret.add(element.getTextContent()); } else { NodeList nl = element.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n instanceof Element) { Element childElement = (Element) n; for (String childText : getAllLeaveValues(childElement)) { ret.add(childText); } } } } return ret; }
From source file:at.ac.tuwien.big.testsuite.impl.validator.XhtmlValidator.java
private static String getTitle(Element msgElement) { return msgElement == null ? null : msgElement.getTextContent(); }
From source file:com.mtgi.analytics.aop.config.TemplateBeanDefinitionParser.java
/** * Convenience method to update a template bean definition from overriding XML data. * If <code>overrides</code> contains attribute <code>attribute</code> or a child element * with name <code>attribute</code>, transfer that * attribute as a bean property onto <code>template</code>, overwriting the default value. * @param reference if true, the value of the attribute is to be interpreted as a runtime bean name reference; otherwise it is interpreted as a literal value *///from ww w. j ava 2 s . com public static boolean overrideProperty(String attribute, BeanDefinition template, Element overrides, boolean reference) { Object value = null; if (overrides.hasAttribute(attribute)) { value = overrides.getAttribute(attribute); } else { NodeList children = overrides.getElementsByTagNameNS("*", attribute); if (children.getLength() == 1) { Element child = (Element) children.item(0); value = child.getTextContent(); } } if (value != null) { if (reference) value = new RuntimeBeanReference(value.toString()); String propName = Conventions.attributeNameToPropertyName(attribute); MutablePropertyValues props = template.getPropertyValues(); props.removePropertyValue(propName); props.addPropertyValue(propName, value); return true; } return false; }
From source file:com.bluexml.xforms.actions.EnumAction.java
private static void addValue(Element element, Map<String, String> values, Map<String, String> keys) { String id = null;/*from w w w .java 2 s . c om*/ String value = null; NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); if (child instanceof Element) { Element e = (Element) child; if (StringUtils.equals(e.getTagName(), "id")) { id = e.getTextContent(); } if (StringUtils.equals(e.getTagName(), "value")) { value = e.getTextContent(); } } } if (id != null && value != null) { values.put(id, value); keys.put(value, id); } }
From source file:it.cilea.osd.common.utils.XMLUtils.java
public static String getElementValue(Element dataRoot, String name) { NodeList nodeList = dataRoot.getElementsByTagName(name); Element element = null; if (nodeList != null && nodeList.getLength() > 0) { element = (Element) nodeList.item(0); }/*from ww w. ja v a 2 s .com*/ String elementValue = null; if (element != null) { elementValue = element.getTextContent(); if (StringUtils.isNotBlank(elementValue)) { elementValue = elementValue.trim(); } else elementValue = null; } return elementValue; }
From source file:com.hdsfed.cometapi.XMLHelper.java
public static String GetSimpleTagContent(Document doc, String tag) { tag = StringHelper.toTitleCase(tag); String content = ""; NodeList nList2 = doc.getElementsByTagName(tag); if (nList2.getLength() == 0) { nList2 = doc.getElementsByTagName(tag.toUpperCase()); }//w w w.j a v a2s . co m if (nList2.getLength() == 0) { nList2 = doc.getElementsByTagName(tag.toLowerCase()); } if (nList2.getLength() == 0) return ""; for (int temp = 0; temp < nList2.getLength(); temp++) { Node nNode2 = nList2.item(temp); if (nNode2.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode2; if (eElement != null) { content = eElement.getTextContent(); } // end if eelement } // end if nnode.getnodetype() } //end for int temp return content; }
From source file:org.xacml4j.spring.pdp.PolicyDecisionPointDefinitionParser.java
private static BeanDefinitionBuilder parseComponent(Element element) { BeanDefinitionBuilder component = element.getLocalName().equals("PolicyIdReference") ? BeanDefinitionBuilder.rootBeanDefinition(PolicyIDReferenceFactoryBean.class) : BeanDefinitionBuilder.rootBeanDefinition(PolicySetIDReferenceFactoryBean.class); String id = element.getTextContent(); if (StringUtils.hasText(id)) { component.addPropertyValue("id", id); }//from w w w . j a va 2s. c o m String version = element.getAttribute("version"); if (StringUtils.hasText(version)) { component.addPropertyValue("version", version); } String latest = element.getAttribute("latest"); if (StringUtils.hasText(latest)) { component.addPropertyValue("latest", latest); } String earliest = element.getAttribute("earliest"); if (StringUtils.hasText(earliest)) { component.addPropertyValue("earliest", earliest); } return component; }
From source file:com.cburch.draw.shapes.SvgReader.java
private static AbstractCanvasObject createText(Element elt) { int x = Integer.parseInt(elt.getAttribute("x")); int y = Integer.parseInt(elt.getAttribute("y")); String text = elt.getTextContent(); Text ret = new Text(x, y, text); String fontFamily = elt.getAttribute("font-family"); String fontStyle = elt.getAttribute("font-style"); String fontWeight = elt.getAttribute("font-weight"); String fontSize = elt.getAttribute("font-size"); int styleFlags = 0; if (fontStyle.equals("italic")) styleFlags |= Font.ITALIC; if (fontWeight.equals("bold")) styleFlags |= Font.BOLD;/*from w ww .jav a2s . c om*/ int size = Integer.parseInt(fontSize); ret.setValue(DrawAttr.FONT, new Font(fontFamily, styleFlags, size)); String alignStr = elt.getAttribute("text-anchor"); AttributeOption halign; if (alignStr.equals("start")) { halign = DrawAttr.ALIGN_LEFT; } else if (alignStr.equals("end")) { halign = DrawAttr.ALIGN_RIGHT; } else { halign = DrawAttr.ALIGN_CENTER; } ret.setValue(DrawAttr.ALIGNMENT, halign); // fill color is handled after we return return ret; }
From source file:gov.nij.processor.MessageProcessor.java
/** * This method returns a map with the following keys to get at WS-Addressing properties "MessageID", "ReplyTo", "From", "To" * We can add to this method to return additional properties as they are needed. * //from w w w .j a va2 s. c o m * @param exchange * @return */ @SuppressWarnings("unchecked") public static HashMap<String, String> returnWSAddressingHeadersFromCamelSoapHeaders(Exchange exchange) { String messageID = null; String replyTo = null; String from = null; String to = null; HashMap<String, String> wsAddressingMessageProperties = new HashMap<String, String>(); List<SoapHeader> soapHeaders = (List<SoapHeader>) exchange.getIn().getHeader(Header.HEADER_LIST); for (SoapHeader soapHeader : soapHeaders) { log.debug("Soap Header: " + soapHeader.getName()); log.debug("Soap Direction: " + soapHeader.getDirection()); if (soapHeader.getName().toString().equals("{http://www.w3.org/2005/08/addressing}MessageID")) { Element element = (Element) soapHeader.getObject(); if (element != null) { messageID = element.getTextContent(); } log.info("WS-Addressing Message ID: " + messageID); wsAddressingMessageProperties.put("MessageID", messageID); } if (soapHeader.getName().toString().equals("{http://www.w3.org/2005/08/addressing}ReplyTo")) { Element element = (Element) soapHeader.getObject(); if (element != null) { replyTo = element.getTextContent(); } log.info("WS-Addressing ReplyTo: " + replyTo); wsAddressingMessageProperties.put("ReplyTo", replyTo); } if (soapHeader.getName().toString().equals("{http://www.w3.org/2005/08/addressing}From")) { Element element = (Element) soapHeader.getObject(); if (element != null) { from = element.getTextContent(); } log.info("WS-Addressing From: " + from); wsAddressingMessageProperties.put("From", from); } if (soapHeader.getName().toString().equals("{http://www.w3.org/2005/08/addressing}To")) { Element element = (Element) soapHeader.getObject(); if (element != null) { to = element.getTextContent(); } log.info("WS-Addressing To: " + to); wsAddressingMessageProperties.put("To", to); } } return wsAddressingMessageProperties; }
From source file:org.dataone.proto.trove.mn.http.client.HttpExceptionHandler.java
private static ErrorElements deserializeXml(HttpResponse response) throws IllegalStateException, IOException // throws NotFound, InvalidToken, ServiceFailure, NotAuthorized, // NotFound, IdentifierNotUnique, UnsupportedType, // InsufficientResources, InvalidSystemMetadata, NotImplemented, // InvalidCredentials, InvalidRequest, IOException { { ErrorElements ee = new ErrorElements(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); Document doc;//from w ww. j a va 2 s. c o m int httpCode = response.getStatusLine().getStatusCode(); if (response.getEntity() != null) { BufferedInputStream bErrorStream = new BufferedInputStream(response.getEntity().getContent()); bErrorStream.mark(5000); // good for resetting up to 5000 bytes String detailCode = null; String description = null; String name = null; int errorCode = -1; try { DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(bErrorStream); Element root = doc.getDocumentElement(); root.normalize(); if (root.getNodeName().equalsIgnoreCase("error")) { if (root.hasAttribute("errorCode")) { try { errorCode = Integer.getInteger(root.getAttribute("errorCode")); } catch (NumberFormatException nfe) { System.out.println("errorCode unexpectedly not able to parse to int," + " using http status for creating exception"); errorCode = httpCode; } } if (errorCode != httpCode) // throw new ServiceFailure("1000","errorCode in message body doesn't match httpStatus"); { System.out.println("errorCode in message body doesn't match httpStatus," + " using errorCode for creating exception"); } if (root.hasAttribute("detailCode")) { detailCode = root.getAttribute("detailCode"); } else { detailCode = "detail code is Not Set!"; } if (root.hasAttribute("name")) { name = root.getAttribute("name"); } else { name = "Exception"; } Node child = root.getFirstChild(); do { if (child.getNodeType() == Node.ELEMENT_NODE) { if (child.getNodeName().equalsIgnoreCase("description")) { Element element = (Element) child; description = element.getTextContent(); break; } } } while ((child = child.getNextSibling()) != null); } else { description = domToString(doc); detailCode = "detail code was never Set!"; } } catch (TransformerException e) { description = deserializeNonXMLErrorStream(bErrorStream, e); } catch (SAXException e) { description = deserializeNonXMLErrorStream(bErrorStream, e); } catch (IOException e) { description = deserializeNonXMLErrorStream(bErrorStream, e); } catch (ParserConfigurationException e) { description = deserializeNonXMLErrorStream(bErrorStream, e); } ee.setCode(errorCode); ee.setName(name); ee.setDetailCode(detailCode); ee.setDescription(description); } return ee; }