List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:org.hibernate.type.ByteArrayBlobType.java
License:Open Source License
public Object fromXMLNode(Node xml, Mapping factory) throws HibernateException { String xmlText = xml.getText(); return xmlText == null || xmlText.length() == 0 ? null : fromString(xmlText); }
From source file:org.hudsonci.xpath.impl.Dom2Dom.java
License:Open Source License
private org.w3c.dom.Node createChild(Node child, org.w3c.dom.Node wparent) { int type = child.getNodeType(); // Collapse multiple consecutive text nodes to a single text node // with trimmed value. if (type != Node.TEXT_NODE) endText(wparent);//from w w w . ja v a 2 s. c om Name name; org.w3c.dom.Node node = null; switch (type) { case Node.ATTRIBUTE_NODE: break; case Node.CDATA_SECTION_NODE: CDATA cd = (CDATA) child; wparent.appendChild(node = wdoc.createCDATASection(cd.getText())); break; case Node.COMMENT_NODE: Comment co = (Comment) child; wparent.appendChild(node = wdoc.createComment(co.getText())); break; case Node.DOCUMENT_TYPE_NODE: DocumentType dt = (DocumentType) child; wparent.appendChild(new XDocumentType(dt, wparent)); break; case Node.ELEMENT_NODE: Element el = (Element) child; name = new Name(el); org.w3c.dom.Element e = name.namespaceURI == null ? wdoc.createElement(name.qualifiedName) : wdoc.createElementNS(name.namespaceURI, name.qualifiedName); wparent.appendChild(e); node = currentElement = e; for (int i = 0, n = el.attributeCount(); i < n; i++) { Attribute at = el.attribute(i); name = new Name(at); if (name.namespaceURI == null) e.setAttribute(name.qualifiedName, at.getValue()); else e.setAttributeNS(name.namespaceURI, name.qualifiedName, at.getValue()); } return e; case Node.ENTITY_REFERENCE_NODE: break; case Node.PROCESSING_INSTRUCTION_NODE: ProcessingInstruction p = (ProcessingInstruction) child; wparent.appendChild(node = wdoc.createProcessingInstruction(p.getTarget(), p.getText())); break; case Node.TEXT_NODE: textBuilder.append(child.getText()); lastText = (Text) child; break; case Node.NAMESPACE_NODE: Namespace ns = (Namespace) child; name = new Name(ns); currentElement.setAttribute(name.qualifiedName, ns.getURI()); break; default: throw new IllegalStateException("Unknown node type"); } if (node != null) reverseMap.put(node, child); return null; }
From source file:org.infoglue.igide.cms.InfoglueCMS.java
License:Open Source License
public static String getAttributeValue(ContentVersion contentVersionVO, String key) { String value = ""; String xpath = "//*[local-name()='" + key + "']"; if (contentVersionVO != null) { try {/*from ww w . ja v a 2 s .c om*/ Document doc = DocumentHelper.parseText(contentVersionVO.getValue()); Element root = doc.getRootElement(); Node nodeValue = root.selectSingleNode(xpath); if (nodeValue != null) { value = nodeValue.getText(); } } catch (Exception e) { e.printStackTrace(); } } return value; }
From source file:org.jage.platform.config.xml.loaders.PlaceholderResolver.java
License:Open Source License
@SuppressWarnings("unchecked") private void fillPlaceholders(final Properties properties, final Document document) throws ConfigurationException { for (final Node node : (List<Node>) ATTRIBUTE_PLACEHOLDERS.selectNodes(document)) { final String text = node.getText(); final String placeholderName = text.substring(PREFIX.length(), text.length() - SUFFIX.length()); final String placeholderValue = properties.getProperty(placeholderName); if (placeholderValue == null) { throw new ConfigurationException( format("No property value found for placeholder '%s'", placeholderName)); }//from ww w. j a va 2 s . co m node.setText(placeholderValue); } }
From source file:org.jasig.portal.io.xml.SpELDataTemplatingStrategy.java
License:Apache License
@Override public Source processTemplates(Document data, String filename) { log.trace("Processing templates for document XML={}", data.asXML()); for (String xpath : XPATH_EXPRESSIONS) { @SuppressWarnings("unchecked") List<Node> nodes = data.selectNodes(xpath); for (Node n : nodes) { String inpt, otpt;/* w w w.j ava2 s . co m*/ switch (n.getNodeType()) { case org.w3c.dom.Node.ATTRIBUTE_NODE: Attribute a = (Attribute) n; inpt = a.getValue(); otpt = processText(inpt); if (otpt == null) { throw new RuntimeException("Invalid expression '" + inpt + "' in file " + filename); } if (!otpt.equals(inpt)) { a.setValue(otpt); } break; case org.w3c.dom.Node.TEXT_NODE: case org.w3c.dom.Node.CDATA_SECTION_NODE: inpt = n.getText(); otpt = processText(inpt); if (otpt == null) { throw new RuntimeException("Invalid expression '" + inpt + "' in file " + filename); } if (!otpt.equals(inpt)) { n.setText(otpt); } break; default: String msg = "Unsupported node type: " + n.getNodeTypeName(); throw new RuntimeException(msg); } } } final SAXSource rslt = new DocumentSource(data); rslt.setSystemId(filename); // must be set, else import chokes return rslt; }
From source file:org.jivesoftware.openfire.clearspace.ClearspaceGroupProvider.java
License:Open Source License
/** * Translate a XML response of a group to a <code>Group</code>. * * @param responseNode the XML representation of a CS group. * @return the group that corresponds to the XML. *///from w w w . j a v a2s . c o m private Group translateGroup(Element responseNode) { Node groupNode = responseNode.selectSingleNode("return"); // Gets the CS DISPLAY NAME that is OF NAME String name = groupNode.selectSingleNode("displayName").getText(); // Gets the CS NAME that is OF DISPLAY NAME String displayName = groupNode.selectSingleNode("name").getText(); // Gets the group ID long id = Long.parseLong(groupNode.selectSingleNode("ID").getText()); // Gets the group type int type = Integer.parseInt(groupNode.selectSingleNode("typeID").getText()); // Gets the group description if it exist String description = null; Node tmpNode = groupNode.selectSingleNode("description"); if (tmpNode != null) { description = tmpNode.getText(); } // Get the members and administrators Collection<JID> members = new ArrayList<JID>(); Collection<JID> administrators = new ArrayList<JID>(); try { XMPPServer server = XMPPServer.getInstance(); // Gets the JID from the response List<Element> membersElement = (List<Element>) getGroupMembers(id).elements("return"); for (Element memberElement : membersElement) { String username = memberElement.element("user").element("username").getText(); // Escape username to accept usernames with @ or spaces String escapedUsername = JID.escapeNode(username); String typeID = memberElement.element("typeID").getText(); if (TYPE_ID_OWNER.equals(typeID)) { administrators.add(server.createJID(escapedUsername, null)); } else if (TYPE_ID_MEMBER.equals(typeID)) { members.add(server.createJID(escapedUsername, null)); } else { // nothing to do, waiting for approval } } } catch (GroupNotFoundException e) { // this won't happen, the group exists. } Map<String, String> properties = new HashMap<String, String>(); // Type 0 is OPEN if (type == 0) { properties.put("sharedRoster.showInRoster", "everybody"); } else { // Types 1, 2 or 3 are MEMBER_ONLY, PRIVATE, SECRET properties.put("sharedRoster.showInRoster", "onlyGroup"); } properties.put("sharedRoster.displayName", displayName); properties.put("sharedRoster.groupList", ""); // Creates the group // There are some interesting things happening here. // If this is the first time that this group is loaded from CS, the OF will save this properties. // If this is not the first time and these properties haven't changed, then nothing happens // If this is not the first time but these properties have changed, then OF will update it's saved data. // And this is OK, event if this "getGroup" is to be used in a "change group properties event", the group should // always show the last information. return new Group(name, description, members, administrators, properties); }
From source file:org.jivesoftware.openfire.clearspace.ClearspaceManager.java
License:Open Source License
/** * If CS throws an exception it handled and transalated to a Openfire exception if possible. * This is done using <code>exceptionMap</code> that has a mapping from CS to OF. If * no mapping is found then it tries to instantiete the original exception. If this fails * it throws a <code>Exception</code> with the message of the CS exception. * * @param response the response from CS to check if it is an exception message. * @throws Exception if the response is an exception message. *//*from w w w .j a v a2 s . co m*/ private void checkFault(Element response) throws Exception { Node node = response.selectSingleNode("ns1:faultstring"); if (node != null) { String exceptionText = node.getText(); // Text accepted samples: // 'java.lang.Exception: Exception message' // 'java.lang.Exception' // Get the exception class and message if any int index = exceptionText.indexOf(":"); String className; String message; // If there is no message, save the class only if (index == -1) { className = exceptionText; message = null; } else { // Else save both className = exceptionText.substring(0, index); message = exceptionText.substring(index + 2); } // Map the exception to a Openfire one, if possible if (exceptionMap.containsKey(className)) { className = exceptionMap.get(className); } //Tries to create an instance with the message Exception exception; try { Class exceptionClass = Class.forName(className); if (message == null) { exception = (Exception) exceptionClass.newInstance(); } else { Constructor constructor = exceptionClass.getConstructor(String.class); exception = (Exception) constructor.newInstance(message); } } catch (Exception e) { // failed to create an specific exception, creating a standard one. exception = new Exception(exceptionText); } throw exception; } }
From source file:org.jivesoftware.openfire.clearspace.ClearspaceUserProvider.java
License:Open Source License
/** * Translates a Clearspace xml user response into a Openfire User * * @param responseNode the Clearspace response * @return a User instance with its information *///w w w. j a v a2 s . c o m private User translate(Node responseNode) { String username; String name = null; String email = null; Date creationDate = null; Date modificationDate = null; Node userNode = responseNode.selectSingleNode("return"); Node tmpNode; // Gets the username username = userNode.selectSingleNode("username").getText(); // Escape the username so that it can be used as a JID. username = JID.escapeNode(username); // Gets the name if it is visible boolean nameVisible = Boolean.valueOf(userNode.selectSingleNode("nameVisible").getText()); // Gets the name tmpNode = userNode.selectSingleNode("name"); if (tmpNode != null) { name = tmpNode.getText(); } // Gets the email if it is visible boolean emailVisible = Boolean.valueOf(userNode.selectSingleNode("emailVisible").getText()); // Gets the email tmpNode = userNode.selectSingleNode("email"); if (tmpNode != null) { email = tmpNode.getText(); } // Gets the creation date tmpNode = userNode.selectSingleNode("creationDate"); if (tmpNode != null) { creationDate = WSUtils.parseDate(tmpNode.getText()); } // Gets the modification date tmpNode = userNode.selectSingleNode("modificationDate"); if (tmpNode != null) { modificationDate = WSUtils.parseDate(tmpNode.getText()); } // Creates the user User user = new User(username, name, email, creationDate, modificationDate); user.setNameVisible(nameVisible); user.setEmailVisible(emailVisible); return user; }
From source file:org.jivesoftware.openfire.clearspace.WSUtils.java
License:Open Source License
/** * Returns the text of the first an element with name 'name'. * * @param node the element to search for a "name" element. * @param name the name of the element to search * @return the text of the corresponding element *///w w w.jav a 2s . c om protected static String getElementText(Node node, String name) { Node n = node.selectSingleNode(name); if (n != null) { return n.getText(); } return null; }
From source file:org.jivesoftware.openfire.clearspace.WSUtils.java
License:Open Source License
/** * Parse REST responses of the type String[], that are XML of the form: * <pre>/* w w w . jav a 2 s .com*/ * {@code * <something> * <return>text1</return> * <return>text2</return> * <return>text3</return> * </something> * } * </pre> * * @param element Element from REST response to be parsed. * @return An array of strings from the REST response. */ protected static List<String> parseStringArray(Element element) { List<String> list = new ArrayList<String>(); @SuppressWarnings("unchecked") List<Node> nodes = (List<Node>) element.selectNodes("return"); for (Node node : nodes) { list.add(node.getText()); } return list; }