List of usage examples for org.dom4j Element addText
Element addText(String text);
Text
node with the given text to this element. From source file:org.jinglenodes.jingle.Reason.java
License:Open Source License
public Element getElement() { final Element parent = DocumentHelper.createElement(REASON); final Element child = DocumentHelper.createElement(getType().toString().replace('_', '-')); parent.add(child);/*from w w w . ja v a2 s. co m*/ if (text != null) { final Element text = DocumentHelper.createElement("text"); parent.add(text); text.addText(getText()); } return parent; }
From source file:org.jivesoftware.openfire.clearspace.ClearspaceSecurityAuditProvider.java
License:Open Source License
/** * The ClearspaceSecurityAuditProvider will log events into Clearspace via the AuditService * web service, provided by Clearspace.//ww w . ja v a 2s . c o m * @see org.jivesoftware.openfire.security.SecurityAuditProvider#logEvent(String, String, String) */ public void logEvent(String username, String summary, String details) { try { // Request to log event String path = AUDIT_URL_PREFIX + "audit"; // Creates the XML with the data Document auditDoc = DocumentHelper.createDocument(); Element rootE = auditDoc.addElement("auditEvent"); Element userE = rootE.addElement("username"); // Un-escape username. username = JID.unescapeNode(username); // Encode potentially non-ASCII characters username = URLUTF8Encoder.encode(username); userE.addText(username); Element descE = rootE.addElement("description"); if (summary != null) { descE.addText("[Openfire] " + summary); } else { descE.addText("[Openfire] No summary provided."); } Element detlE = rootE.addElement("details"); if (details != null) { detlE.addText(details); } else { detlE.addText("No details provided."); } ClearspaceManager.getInstance().executeRequest(POST, path, auditDoc.asXML()); } catch (Exception e) { // Error while setting properties? Log.error("Unable to send audit log via REST service to Clearspace:", e); } }
From source file:org.jivesoftware.openfire.clearspace.ClearspaceUserProvider.java
License:Open Source License
/** * Creates user using the userService/users POST service. If Clearspace is a read only * provider throws an UnsupportedOperationException. If there is already a user with * the username throws a UserAlreadyExistsException. * * @param username the username of the user * @param password the password of the user * @param name the name of the user (optional) * @param email the email of the user * @return an instance of the created user * @throws UserAlreadyExistsException If there is already a user with the username * @throws UnsupportedOperationException If Clearspace is a read only provider *///w w w . java2 s . c o m public User createUser(String username, String password, String name, String email) throws UserAlreadyExistsException { if (isReadOnly()) { // Reject the operation since the provider is read-only throw new UnsupportedOperationException(); } try { String path = USER_URL_PREFIX + "users/"; // Creates the XML with the data Document groupDoc = DocumentHelper.createDocument(); Element rootE = groupDoc.addElement("createUserWithUser"); Element userE = rootE.addElement("user"); // adds the username Element usernameE = userE.addElement("username"); // Un-escape username. username = JID.unescapeNode(username); // Encode potentially non-ASCII characters username = URLUTF8Encoder.encode(username); usernameE.addText(username); // adds the name if it is not empty if (name != null && !"".equals(name.trim())) { Element nameE = userE.addElement("name"); nameE.addText(name); } // adds the password Element passwordE = userE.addElement("password"); passwordE.addText(password); // adds the the email Element emailE = userE.addElement("email"); emailE.addText(email); // new user are always enabled Element enabledE = userE.addElement("enabled"); enabledE.addText("true"); Element user = ClearspaceManager.getInstance().executeRequest(POST, path, groupDoc.asXML()); return translate(user); } catch (UserAlreadyExistsException uaee) { throw uaee; } catch (Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } return new User(username, name, email, new Date(), new Date()); }
From source file:org.jivesoftware.openfire.plugin.SearchPlugin.java
License:Open Source License
/** * Constructs a query that is returned as an IQ packet that contains the search results. * //from ww w . j av a 2 s . c o m * @param users * set of users that will be used to construct the search results * @param packet * the IQ packet sent by the client * @return the iq packet that contains the search results */ private IQ replyNonDataFormResult(Collection<User> users, IQ packet) { IQ replyPacket = IQ.createResultIQ(packet); Element replyQuery = replyPacket.setChildElement("query", NAMESPACE_JABBER_IQ_SEARCH); for (User user : users) { Element item = replyQuery.addElement("item"); String username = JID.unescapeNode(user.getUsername()); item.addAttribute("jid", username + "@" + serverName); // return to the client the same fields that were submitted for (String field : reverseFieldLookup.keySet()) { if ("Username".equals(field)) { Element element = item.addElement(reverseFieldLookup.get(field)); element.addText(username); } if ("Name".equals(field)) { Element element = item.addElement(reverseFieldLookup.get(field)); element.addText(user.isNameVisible() ? removeNull(user.getName()) : ""); } if ("Email".equals(field)) { Element element = item.addElement(reverseFieldLookup.get(field)); element.addText(user.isEmailVisible() ? removeNull(user.getEmail()) : ""); } } } return replyPacket; }
From source file:org.jivesoftware.openfire.plugin.Xep227Exporter.java
License:Apache License
/** * Add roster and its groups to a DOM element * // w ww . jav a2 s. c om * @param userElement * DOM element * @param user * User */ private void exportRoster(Element userElement, User user) { Element rosterElement = userElement.addElement(QUERY_ELEMENT_NAME, JABBER_IQ_ROSTER_NS); Collection<RosterItem> roster = user.getRoster().getRosterItems(); for (RosterItem ri : roster) { Element itemElement = rosterElement.addElement(ITEM_ELEMENT_NAME); itemElement.addAttribute(JID_NAME, ri.getJid().toBareJID()); itemElement.addAttribute(NAME_NAME, ri.getNickname()); itemElement.addAttribute(SUBSCRIPTION_NAME, ri.getSubStatus().getName()); if (ri.getAskStatus() == AskType.SUBSCRIBE) { itemElement.addAttribute(ASK_NAME, ASK_SUBSCRIBE_ENUM); } /** * Adding groups */ Element groupElement = itemElement.addElement(GROUP_ELEMENT_NAME); List<String> groups = ri.getGroups(); for (String group : groups) { groupElement.addText(group); } } }
From source file:org.jivesoftware.openfire.plugin.Xep227Exporter.java
License:Apache License
/** * Adding offline messages, if there are some. * //from ww w . java 2s. com * @param hostname * host name * @param userElement * DOM element * @param userName * user name */ @SuppressWarnings("unchecked") private void exportOfflineMessages(String hostname, Element userElement, String userName) { Collection<OfflineMessage> offlineMessages = offlineMessagesStore.getMessages(userName, false); if (!offlineMessages.isEmpty()) { Element offlineElement = userElement.addElement(OFFLINE_MESSAGES_ELEMENT_NAME); for (OfflineMessage offMessage : offlineMessages) { Element messageElement = offlineElement.addElement(new QName(MESSAGE_ELEMENT_NAME, JABBER_MSG_NS)); for (Object att : offMessage.getElement().attributes()) { Attribute attribute = (Attribute) att; messageElement.addAttribute(attribute.getQName(), attribute.getValue()); } for (Iterator<Element> iterator = offMessage.getElement().elementIterator(); iterator.hasNext();) { Element element = iterator.next(); messageElement.add(element.createCopy(new QName(element.getName(), (element.getNamespace() == Namespace.NO_NAMESPACE ? JABBER_MSG_NS : element.getNamespace())))); } /** * Adding delay element */ Element delayElement = messageElement.addElement("delay", "urn:xmpp:delay"); delayElement.addAttribute(FROM_NAME, hostname); delayElement.addAttribute("stamp", XMPPDateTimeFormat.format(offMessage.getCreationDate())); delayElement.addText("Offline Storage"); } } }
From source file:org.jivesoftware.openfire.update.UpdateManager.java
License:Open Source License
private String getAvailablePluginsUpdateRequest() { Element xmlRequest = docFactory.createDocument().addElement("available"); // Add locale so we can get current name and description of plugins Element locale = xmlRequest.addElement("locale"); locale.addText(JiveGlobals.getLocale().toString()); return xmlRequest.asXML(); }
From source file:org.mitre.jawb.io.ATLASHelper.java
License:Open Source License
/** * Read in an .aif file from the specified URI, and write it out with * localized refernces to the output stream. * @param aifURI location of input .aif file. <strong>MUST BE ABSOLUTE.</strong> * @param out stream that localized version of input is written to * @param relativize rewrite the absolute signal URI as relative based on * input/*from ww w. j a v a 2 s. com*/ * @param cheatMap A map of undocumented values that we use in Callisto * to store data in the AIF which ATLAS won't. */ public static void externalize(URI aifURI, OutputStream out, boolean relativize, Map cheatMap) throws IOException { if (DEBUG > 0) System.err.println("ATHelp.externalize: aifURI=" + aifURI); Document doc = parse(aifURI); DocumentType doctype = doc.getDocType(); Element corpus = doc.getRootElement(); Element signal = getTextSignal(corpus); // Replace local ATLAS DTD reference w/ external reference doctype.setSystemID("http://www.nist.gov/speech/atlas/aif.dtd"); // Replace local MAIA Scheme w/ external reference String maiaString = corpus.attributeValue("schemeLocation"); Task task = findTask(maiaString, LOCAL); if (task == null) System.err.println("Unable to extern Maia: Unknown:\n " + maiaString); else corpus.addAttribute("schemeLocation", task.getMaiaURI().toString()); // It's possible to /not/ have a text signal referenced if (signal != null) { // Perhaps replace absolute URI with relative URI if (relativize) { String signalHREF = signal.attributeValue("href"); try { String path = aifURI.getRawPath(); URI aifBase = aifURI.resolve(path.substring(0, path.lastIndexOf('/') + 1)); URI signalURI = new URI(signalHREF); URI relativeURI = aifBase.relativize(signalURI); if (DEBUG > 0) { System.err.println("ATHelp.extern:\n base= " + aifBase + "\n signal= " + signalURI + "\n relative= " + relativeURI); } signal.addAttribute("href", relativeURI.toString()); } catch (URISyntaxException x) { System.err.println("WARNING: aif file specifies invalid signal URI:" + " not relativizing:\n aifURI= " + aifURI + "\n signalURI=" + signalHREF); System.err.println(x.getMessage()); } } // ATLAS ignores encoding so use the cheats signal.addAttribute("encoding", (String) cheatMap.get("encoding")); signal.addAttribute("mimeType", (String) cheatMap.get("mimeType")); if (cheatMap.get(SIGNAL_DATA) != null) { String embedded = Base64.encode((byte[]) cheatMap.get(SIGNAL_DATA)); Element body = signal.addElement("body"); body.addAttribute("encoding", "Base64"); body.addText(embedded); } } // if (signal != null) dump(doc, out); }
From source file:org.mitre.jawb.io.ATLASHelper.java
License:Open Source License
/** * Read in an .aif file from the specified URI, and write it out with * localized refernces to the output stream. * @param aifURI location of input .aif file. <strong>MUST BE ABSOLUTE.</strong> * @param out stream that localized version of input is written to * @param relativize rewrite the absolute signal URI as relative based on * input//from w ww . ja va 2 s .com * @param cheatMap A map of undocumented values that we use in Callisto * to store data in the AIF which ATLAS won't. */ public static void externalize(URI aifURI, InputStream in, OutputStream out, boolean relativize, Map cheatMap) throws IOException { // if (DEBUG > 0) // System.err.println ("ATHelp.externalize: aifURI="+aifURI); Document doc = parse(in); DocumentType doctype = doc.getDocType(); Element corpus = doc.getRootElement(); Element signal = getTextSignal(corpus); // Replace local ATLAS DTD reference w/ external reference doctype.setSystemID("http://www.nist.gov/speech/atlas/aif.dtd"); // Replace local MAIA Scheme w/ external reference String maiaString = corpus.attributeValue("schemeLocation"); Task task = findTask(maiaString, LOCAL); if (task == null) System.err.println("Unable to extern Maia: Unknown:\n " + maiaString); else corpus.addAttribute("schemeLocation", task.getMaiaURI().toString()); // It's possible to /not/ have a text signal referenced if (signal != null) { // Perhaps replace absolute URI with relative URI if (relativize) { String signalHREF = signal.attributeValue("href"); try { String path = aifURI.getRawPath(); URI aifBase = aifURI.resolve(path.substring(0, path.lastIndexOf('/') + 1)); URI signalURI = new URI(signalHREF); URI relativeURI = aifBase.relativize(signalURI); if (DEBUG > 0) { System.err.println("ATHelp.extern:\n base= " + aifBase + "\n signal= " + signalURI + "\n relative= " + relativeURI); } signal.addAttribute("href", relativeURI.toString()); } catch (URISyntaxException x) { System.err.println("WARNING: aif file specifies invalid signal URI:" + " not relativizing:\n aifURI= " + aifURI + "\n signalURI=" + signalHREF); System.err.println(x.getMessage()); } } // ATLAS ignores encoding so use the cheats signal.addAttribute("encoding", (String) cheatMap.get("encoding")); signal.addAttribute("mimeType", (String) cheatMap.get("mimeType")); if (cheatMap.get(SIGNAL_DATA) != null) { String embedded = Base64.encode((byte[]) cheatMap.get(SIGNAL_DATA)); Element body = signal.addElement("body"); body.addAttribute("encoding", "Base64"); body.addText(embedded); } } // if (signal != null) dump(doc, out); }
From source file:org.neuclear.id.builders.IdentityBuilder.java
License:LGPL
public void addAddContactLink() { Element p = body.addElement("a"); p.addAttribute("href", "http://localhost:11870/AddContact?" + getOriginal()); p.addElement("img").addAttribute("src", "http://pkyp.org/images/contact_new.png"); p.addText("Add to contacts in Personal Trader"); }