List of usage examples for org.w3c.dom Element getTextContent
public String getTextContent() throws DOMException;
From source file:org.openmrs.module.xforms.aop.XformsProviderAdvisor.java
/** * Refreshes a provider in a given xforms select1 node. * //from ww w. jav a2s.com * @param operation the refresh operation. * @param providerSelect1Element the provider select1 node. * @param user the provider. * @param oldName the provider name before editing. * @param doc the xforms document. * @param xform the xform object. * @param xformsService the xforms service. * @throws Exception */ private void refreshProviderWithId(RefreshOperation operation, Element providerSelect1Element, User user, String oldName, Document doc, Xform xform, XformsService xformsService) throws Exception { Integer personId = XformsUtil.getPersonId(user); String sPersonId = personId.toString(); if (operation == RefreshOperation.DELETE || operation == RefreshOperation.EDIT) { //Get all xf:item nodes. NodeList elements = providerSelect1Element .getElementsByTagName(XformBuilder.PREFIX_XFORMS + ":" + "item"); boolean providerFound = false; //Look for an item node having an id attribute equal to the userId. for (int index = 0; index < elements.getLength(); index++) { Element itemElement = (Element) elements.item(index); if (!sPersonId.equals(itemElement.getAttribute(XformBuilder.ATTRIBUTE_ID))) continue; //Not the provider we are looking for. //If the user has been deleted, then remove their item node from the xforms document. if (operation == RefreshOperation.DELETE) { providerSelect1Element.removeChild(itemElement); } else { //New name for the provider after editing. String newName = XformBuilder.getProviderName(user, personId); //If name has not changed, then just do nothing. if (newName.equals(oldName)) return; //If the user name has been edited, then change the xf:label node text. NodeList labels = itemElement.getElementsByTagName(XformBuilder.PREFIX_XFORMS + ":" + "label"); //If the existing xforms label is not the same as the previous user's name, then //do not change it, possibly the user wants the xforms value not to match the user's name. Element labelElement = (Element) labels.item(0); if (!oldName.equals(labelElement.getTextContent())) return; labelElement.setTextContent(newName); } providerFound = true; break; } //select1 node does not have the provider to delete or edit. if (!providerFound) { if (operation == RefreshOperation.DELETE) return; //This must be a person who has just got a provider role which he or she did not have before. addNewProviderNode(doc, providerSelect1Element, user, personId); } } else { //Older versions of openmrs call AOP advisors more than once hence resulting into duplicates //if this check is not performed. if (providerExists(providerSelect1Element, sPersonId)) return; //Add new provider addNewProviderNode(doc, providerSelect1Element, user, personId); } xform.setXformXml(XformsUtil.doc2String(doc)); xformsService.saveXform(xform); }
From source file:com.bluexml.side.portal.alfresco.reverse.reverser.EclipseReverser.java
protected void readAnyElements(Map<String, String> props, List<Object> any) { for (Object object : any) { String nodeName = null;//from www .j av a2 s. c o m String nodeValue = null; if (object instanceof Element) { System.out.println(" any Element (w3c) ?" + object); Element el = (Element) object; nodeName = el.getNodeName(); nodeValue = el.getTextContent(); props.put(nodeName, nodeValue); } else if (object instanceof JAXBElement) { JAXBElement<String> jaxbE = (JAXBElement<String>) object; QName name = jaxbE.getName(); nodeName = name.getLocalPart(); nodeValue = jaxbE.getValue(); } props.put(nodeName, nodeValue); } }
From source file:com.github.koraktor.steamcondenser.community.XMLData.java
/** * Returns the string value of the element with the given name (or path) * * @param names The name of the elements representing the path to the * target element/*from w w w . j a v a 2s .c o m*/ * @return The string value of the named element */ public String getString(String... names) { Element element = this.getElement(names).getRoot(); if (element == null) { return null; } else { return element.getTextContent(); } }
From source file:com.cisco.dvbu.ps.common.adapters.config.SoapHttpConfig.java
private void parse(Document doc) throws AdapterException { XPath xpath = XPathFactory.newInstance().newXPath(); try {//from w w w. j av a2s .c o m Element e = (Element) xpath.evaluate(AdapterConstants.XPATH_CONN_ENDPOINTS, doc, XPathConstants.NODE); if (e != null) { NodeList nlList = e.getElementsByTagName(AdapterConstants.CONNECTOR_SH_ENDPOINT); if (nlList != null && nlList.item(0) != null) { for (int i = 0; i < nlList.getLength(); i++) { Element elem = (Element) nlList.item(i); connEndpoints.put(elem.getAttribute(AdapterConstants.CONNECTOR_SE_NAME), elem.getTextContent()); log.debug(elem.getAttribute(AdapterConstants.CONNECTOR_SE_NAME) + ": " + elem.getTextContent()); } } } } catch (Exception e) { log.error("Configuration File Error! One or more mandatory configuration options are missing"); throw new AdapterException(403, "Configuration File Error! One or more mandatory configuration options are missing.", e); } try { parseCallbacks((Element) xpath.evaluate(AdapterConstants.XPATH_CALLBACKS, doc, XPathConstants.NODE)); } catch (AdapterException ae) { throw ae; } catch (Exception e) { log.error("Configuration File Error! One or more mandatory configuration options are missing"); throw new AdapterException(404, "Configuration File Error! One or more mandatory configuration options are missing.", e); } }
From source file:honeypot.services.WepawetServiceImpl.java
/** * Parses the queue messages into the correct queues. * @param input The input stream containing the response from the Wepawet queue service. * @param hash The hash from the Wepawet processing service. A way to uniquely identify the query. * @throws ParserConfigurationException If an error occurs parsing the XML response. * @throws SAXException If an error occurs processing the XML response. * @throws IOException If an I/O Error occurs. *//* w ww . jav a2s .c o m*/ private void handleQueryMsg(final InputStream input, final String hash) throws ParserConfigurationException, SAXException, IOException { final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); final DocumentBuilder db = dbf.newDocumentBuilder(); final Document doc = db.parse(input); doc.getDocumentElement().normalize(); Element response = doc.getDocumentElement(); String state = response.getAttribute("state"); if ("ok".equals(state)) { // Success. final Element statusEl = (Element) doc.getElementsByTagName("status").item(0); final String status = statusEl.getTextContent(); if (!"queued".equals(status)) { final Element reportEl = (Element) doc.getElementsByTagName("report_url").item(0); final Element resultEl = (Element) doc.getElementsByTagName("result").item(0); // Remove the processing record. WepawetProcessing wepawetProcessing = (WepawetProcessing) entityManager .createQuery("FROM WepawetProcessing p WHERE p.hash = :hash").setParameter("hash", hash) .getSingleResult(); entityManager.remove(wepawetProcessing); WepawetResult wepawetResult = new WepawetResult(); wepawetResult.setReport(reportEl.getTextContent()); wepawetResult.setResult(resultEl.getTextContent()); wepawetResult.setCreated(new Date()); entityManager.persist(wepawetResult); } else { log.info("The status for {} is {}.", hash, status); } } else { // Failure. final Element error = (Element) doc.getElementsByTagName("error").item(0); WepawetError wepawetError = new WepawetError(); wepawetError.setCode(error.getAttribute("code")); wepawetError.setMessage(error.getAttribute("message")); wepawetError.setCreated(new Date()); // Save the error to the database. entityManager.persist(wepawetError); // Remove the processing record. WepawetProcessing wepawetProcessing = (WepawetProcessing) entityManager .createNamedQuery("FROM WepawetProcessing p WHERE p.hash = :hash").setParameter("hash", hash) .getSingleResult(); entityManager.remove(wepawetProcessing); } }
From source file:au.gov.ga.earthsci.discovery.csw.CSWDiscoveryResult.java
public CSWDiscoveryResult(CSWDiscovery discovery, int index, Element cswRecordElement) throws XPathExpressionException { super(discovery, index); XPath xpath = WWXML.makeXPath(); String title = (String) xpath.compile("title/text()").evaluate(cswRecordElement, XPathConstants.STRING); //$NON-NLS-1$ title = StringEscapeUtils.unescapeXml(title); String description = (String) xpath.compile("description/text()").evaluate(cswRecordElement, //$NON-NLS-1$ XPathConstants.STRING); description = StringEscapeUtils.unescapeXml(description); //normalize newlines description = description.replace("\r\n", "\n").replace("\r", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ this.title = title; this.description = description; NodeList referenceElements = (NodeList) xpath.compile("references/reference").evaluate(cswRecordElement, //$NON-NLS-1$ XPathConstants.NODESET); for (int i = 0; i < referenceElements.getLength(); i++) { Element referenceElement = (Element) referenceElements.item(i); String scheme = referenceElement.getAttribute("scheme"); //$NON-NLS-1$ try {/* w w w .j av a2 s . c o m*/ URL url = new URL(referenceElement.getTextContent()); references.add(url); referenceSchemes.add(scheme); } catch (MalformedURLException e) { } } Sector bounds = null; String min = (String) xpath.compile("boundingBox/lowerCorner/text()").evaluate(cswRecordElement, //$NON-NLS-1$ XPathConstants.STRING); String max = (String) xpath.compile("boundingBox/upperCorner/text()").evaluate(cswRecordElement, //$NON-NLS-1$ XPathConstants.STRING); if (!Util.isBlank(min) && !Util.isBlank(max)) { min = StringEscapeUtils.unescapeXml(min); max = StringEscapeUtils.unescapeXml(max); String doubleGroup = "([-+]?(?:\\d*\\.?\\d+)|(?:\\d+\\.))"; //$NON-NLS-1$ Pattern pattern = Pattern.compile("\\s*" + doubleGroup + "\\s+" + doubleGroup + "\\s*"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Matcher minMatcher = pattern.matcher(min); Matcher maxMatcher = pattern.matcher(max); if (minMatcher.matches() && maxMatcher.matches()) { double minLon = Double.parseDouble(minMatcher.group(1)); double minLat = Double.parseDouble(minMatcher.group(2)); double maxLon = Double.parseDouble(maxMatcher.group(1)); double maxLat = Double.parseDouble(maxMatcher.group(2)); bounds = Sector.fromDegrees(minLat, maxLat, minLon, maxLon); } } this.bounds = Bounds.fromSector(bounds); }
From source file:net.bpelunit.util.XMLUtilTest.java
@Test public void testAddTextNode() { Document xml = XMLUtil.createDocument(); Element element = xml.createElement("a"); Text t = XMLUtil.appendTextNode(element, "abc"); assertEquals("abc", element.getTextContent()); assertEquals(1, element.getChildNodes().getLength()); assertSame(t, element.getChildNodes().item(0)); }
From source file:fr.aliasource.webmail.indexing.SearchAction.java
private ConversationReference loadChat(Map<String, Object> payload) { if (logger.isDebugEnabled()) { for (String s : payload.keySet()) { logger.debug(" * " + s + ": " + payload.get(s)); }//from w ww. j av a 2 s . c om } String id = "" + payload.get("id"); String xmlData = payload.get("data").toString(); try { Document doc = DOMUtils.parse(new ByteArrayInputStream(xmlData.getBytes())); Element root = doc.getDocumentElement(); NodeList nl = root.getElementsByTagName("item"); Set<String> who = new HashSet<String>(); StringBuilder preview = new StringBuilder(); StringBuilder html = new StringBuilder(); MessageBeautifier mb = new MessageBeautifier(); for (int i = 0; i < nl.getLength(); i++) { html.append("<p><b>"); Element e = (Element) nl.item(i); String from = e.getAttribute("from"); html.append(from); html.append("</b>: "); who.add(from); preview.append(e.getTextContent()); preview.append(" "); html.append(mb.beautify(e.getTextContent())); html.append("</p>"); } StringBuilder subject = new StringBuilder("Chat with "); LinkedList<Address> ads = new LinkedList<Address>(); Iterator<String> it = who.iterator(); for (int i = 0; it.hasNext(); i++) { String s = it.next(); if (i > 0) { subject.append(", "); } int idx = s.indexOf("@"); if (idx > 0) { String cut = s.substring(0, idx); subject.append(cut); ads.add(new Address(cut, s)); } else { subject.append(s); ads.add(new Address(s)); } } ConversationReference cr = new SetConversationReference(id, subject.toString(), "#chat"); cr.setLastMessageDate(Long.parseLong(root.getAttribute("ts"))); cr.addMetadata("preview", preview.toString()); cr.addMetadata("html", html.toString()); for (Address a : ads) { cr.addParticipant(a); } return cr; } catch (Exception e) { logger.error("Error loading chat from history"); } return null; }
From source file:fr.aliasource.webmail.server.proxy.client.http.AbstractMessageMethod.java
protected void parseMessageList(Conversation c, Element root, List<ClientMessage> cml) { NodeList mnl = root.getElementsByTagName("m"); Calendar cal = Calendar.getInstance(); for (int i = 0; i < mnl.getLength(); i++) { Element m = (Element) mnl.item(i); ClientMessage cMess = parseMessage(cal, m); cMess.setConvId(c.getId());/*from ww w . jav a 2s . c om*/ if (cMess.isLoaded()) { Element invitation = DOMUtils.getUniqueElement((Element) mnl.item(i), "invitation"); if (invitation != null) { cMess.setHasInvitation("true".equals(invitation.getTextContent())); } fetchFwdMessage(cMess, cal, m); } cml.add(cMess); cMess.setFolderName(c.getSourceFolder()); } }