List of usage examples for org.jdom2 Element setText
public Element setText(final String text)
From source file:com.kixeye.kixmpp.client.KixmppClient.java
License:Apache License
/** * Performs auth./*w ww . j av a 2s . co m*/ */ private void performAuth() { byte[] authToken = ("\0" + jid.getNode() + "\0" + password).getBytes(StandardCharsets.UTF_8); Element auth = new Element("auth", "urn:ietf:params:xml:ns:xmpp-sasl"); auth.setAttribute("mechanism", "PLAIN"); ByteBuf rawCredentials = channel.get().alloc().buffer().writeBytes(authToken); ByteBuf encodedCredentials = Base64.encode(rawCredentials); String encodedCredentialsString = encodedCredentials.toString(StandardCharsets.UTF_8); encodedCredentials.release(); rawCredentials.release(); auth.setText(encodedCredentialsString); channel.get().writeAndFlush(auth); }
From source file:com.kixeye.kixmpp.client.module.chat.MessageKixmppClientModule.java
License:Apache License
/** * Sends a private message./*from w w w .j ava2s.c o m*/ * * @param toJid * @param body */ public void sendMessage(KixmppJid toJid, String body) { Element messageElement = new Element("message"); messageElement.setAttribute("type", "chat"); messageElement.setAttribute("from", client.getJid().getFullJid()); messageElement.setAttribute("to", toJid.getBaseJid()); Element bodyElement = new Element("body"); bodyElement.setText(body); messageElement.addContent(bodyElement); client.sendStanza(messageElement); }
From source file:com.kixeye.kixmpp.client.module.muc.MucKixmppClientModule.java
License:Apache License
/** * Sends a room message to a room./*from ww w .j av a 2s . c o m*/ * * @param roomJid * @param roomMessage */ public void sendRoomMessage(KixmppJid roomJid, String roomMessage, String nickname) { Element message = new Element("message"); message.setAttribute("from", client.getJid().toString()); message.setAttribute("to", roomJid.toString()); message.setAttribute("type", "groupchat"); Element bodyElement = new Element("body", message.getNamespace()); bodyElement.setText(roomMessage); message.addContent(bodyElement); client.sendStanza(message); }
From source file:com.kixeye.kixmpp.client.module.presence.PresenceKixmppClientModule.java
License:Apache License
/** * Updates the current user's presence./* w ww. j a va 2 s . co m*/ * * @param presence */ public void updatePresence(Presence presence) { Element presenceElement = new Element("presence"); if (presence.getType() != null) { presenceElement.setAttribute("type", presence.getType()); } if (presence.getStatus() != null) { Element statusElement = new Element("status"); statusElement.setText(presence.getStatus()); presenceElement.addContent(statusElement); } if (presence.getShow() != null) { Element showElement = new Element("show"); showElement.setText(presence.getShow()); presenceElement.addContent(showElement); } client.sendStanza(presenceElement); }
From source file:com.kixeye.kixmpp.server.cluster.message.PrivateChatTask.java
License:Apache License
/** * @see org.fusesource.hawtdispatch.Task#run() *///from ww w . j a va 2s .co m public void run() { KixmppJid fromJid = KixmppJid.fromRawJid(this.fromJid); KixmppJid toJid = KixmppJid.fromRawJid(this.toJid); KixmppServer server = getKixmppServer(); // broadcast message stanza to all channels of the recipient for (Channel toChannel : server.getChannels(toJid.getNode())) { Element messageElement = new Element("message"); messageElement.setAttribute("type", "chat"); messageElement.setAttribute("from", fromJid.getFullJid()); messageElement.setAttribute("to", toJid.getFullJid()); Element bodyElement = new Element("body"); bodyElement.setText(body); messageElement.addContent(bodyElement); toChannel.writeAndFlush(messageElement); } // broadcast message stanza to all channels of the sender // except for the channel it was sent from for (Channel fromChannel : server.getChannels(fromJid.getNode())) { // skip the channel message was sent from if (fromChannel.attr(BindKixmppServerModule.JID).get().toString() .equalsIgnoreCase(fromJid.toString())) { continue; } Element messageElement = new Element("message"); messageElement.setAttribute("type", "chat"); messageElement.setAttribute("from", fromJid.getFullJid()); messageElement.setAttribute("to", toJid.getFullJid()); Element bodyElement = new Element("body"); bodyElement.setText(body); messageElement.addContent(bodyElement); fromChannel.writeAndFlush(messageElement); } }
From source file:com.kixeye.kixmpp.server.module.auth.SaslKixmppServerModule.java
License:Apache License
/** * @see com.kixeye.kixmpp.server.module.KixmppServerModule#getFeatures(io.netty.channel.Channel) *//*from ww w . j a va2s . c om*/ public List<Element> getFeatures(Channel channel) { List<Element> features = new LinkedList<>(); Boolean isAuthed = channel.attr(IS_AUTHENTICATED).get(); if (isAuthed == null || isAuthed == false) { Element mechanisms = new Element("mechanisms", null, "urn:ietf:params:xml:ns:xmpp-sasl"); Element plainMechanism = new Element("mechanism", "urn:ietf:params:xml:ns:xmpp-sasl"); plainMechanism.setText("PLAIN"); mechanisms.addContent(plainMechanism); features.add(mechanisms); } return features; }
From source file:com.kixeye.kixmpp.server.module.muc.MucRoom.java
License:Apache License
/** * Sends a mediated invitation to a user. *//*ww w. j ava2 s . c o m*/ public void sendMediatedInvite(KixmppJid from, Channel userChannelToInvite, String reason) { Element invite = new Element("invite"); invite.setAttribute("from", from.getFullJid()); if (reason != null) { Element el = new Element("reason"); el.setText(reason); invite.addContent(el); } Element x = new Element("x", Namespace.getNamespace("http://jabber.org/protocol/muc#user")); x.addContent(invite); Element message = new Element("message"); message.setAttribute("to", userChannelToInvite.attr(BindKixmppServerModule.JID).get().getFullJid()); message.setAttribute("from", roomJid.getFullJid()); message.addContent(x); userChannelToInvite.writeAndFlush(message); }
From source file:com.lapis.jsfexporter.xml.XMLExportType.java
License:Apache License
@Override public Element exportRow(IExportRow row) { Element currentElement = (Element) row.getParentRowId(); if (currentElement == null) { currentElement = rootElement;//from w w w. j ava2 s. c o m } for (String namePart : row.getName()) { Element subElement = new Element(cleanElementName(namePart)); currentElement.addContent(subElement); currentElement = subElement; } for (IExportCell cell : row.getCells()) { Element cellElement = currentElement; for (String namePart : cell.getName()) { Element subElement = cellElement.getChild(namePart); if (subElement == null) { subElement = new Element(cleanElementName(namePart)); cellElement.addContent(subElement); } cellElement = subElement; } if (!cellElement.getText().equals("")) { String cellName = cellElement.getName(); cellElement = cellElement.getParentElement(); Element newCellElement = new Element(cellName); cellElement.addContent(newCellElement); cellElement = newCellElement; } cellElement.setText(cell.getValue()); } return currentElement; }
From source file:com.medvision360.medrecord.basex.AbstractXmlConverter.java
License:Creative Commons License
protected void set(Element element, String xpath, String value) { Element currentElement = element; String[] paths = xpath.split("/"); for (int i = 0; i < paths.length; i++) { String pathPart = paths[i].trim(); if (pathPart.isEmpty()) { continue; }// w w w . ja va2 s . c o m Element newElement = element.getChild(pathPart); if (newElement == null) { newElement = new Element(pathPart); currentElement.addContent(newElement); } currentElement = newElement; } currentElement.setText(value); }
From source file:com.medvision360.medrecord.basex.MockLocatableSerializer.java
License:Creative Commons License
private void set(Element element, String xpath, String value) { Element currentElement = element; String[] paths = xpath.split("/"); for (int i = 0; i < paths.length; i++) { String pathPart = paths[i].trim(); if (pathPart.isEmpty()) { continue; }// w ww .j a v a2 s . co m Element newElement = element.getChild(pathPart); if (newElement == null) { newElement = new Element(pathPart); } currentElement.addContent(newElement); currentElement = newElement; } currentElement.setText(value); }