List of usage examples for org.dom4j QName get
public static QName get(String qualifiedName, String uri)
From source file:net.sf.kraken.BaseTransport.java
License:Open Source License
/** * Handle last request./*from www .j ava2s . co m*/ * * @param packet An IQ packet in the jabber:iq:last namespace. * @return A list of IQ packets to be returned to the user. */ private List<Packet> handleIQLast(IQ packet) { List<Packet> reply = new ArrayList<Packet>(); JID from = packet.getFrom(); JID to = packet.getTo(); if (packet.getType() == IQ.Type.get) { IQ result = IQ.createResultIQ(packet); if (from.getNode() != null) { try { TransportSession<B> session = sessionManager.getSession(from); Element response = DocumentHelper.createElement(QName.get("query", NameSpace.IQ_LAST)); Long timestamp = session.getBuddyManager().getBuddy(to).getLastActivityTimestamp(); String lastevent = session.getBuddyManager().getBuddy(to).getLastActivityEvent(); response.addAttribute("seconds", new Long(new Date().getTime() - timestamp).toString()); if (lastevent != null) { response.addCDATA(lastevent); } result.setChildElement(response); } catch (NotFoundException e) { Log.debug("Contact not found while retrieving last activity for: " + from); result.setError(Condition.item_not_found); } } else { result.setError(Condition.feature_not_implemented); } reply.add(result); } else if (packet.getType() == IQ.Type.set) { IQ result = IQ.createResultIQ(packet); result.setError(Condition.forbidden); reply.add(result); } return reply; }
From source file:net.sf.kraken.BaseTransport.java
License:Open Source License
/** * Handle version request.//from ww w. java 2s .c o m * * @param packet An IQ packet in the iq version namespace. * @return A list of IQ packets to be returned to the user. */ private List<Packet> handleIQVersion(IQ packet) { List<Packet> reply = new ArrayList<Packet>(); if (packet.getType() == IQ.Type.get) { IQ result = IQ.createResultIQ(packet); Element query = DocumentHelper.createElement(QName.get("query", NameSpace.IQ_VERSION)); query.addElement("name").addText("Openfire " + this.getDescription()); query.addElement("version") .addText(XMPPServer.getInstance().getServerInfo().getVersion().getVersionString() + " - " + this.getVersionString()); query.addElement("os").addText(System.getProperty("os.name")); result.setChildElement(query); reply.add(result); } return reply; }
From source file:net.sf.kraken.muc.BaseMUCTransport.java
License:Open Source License
/** * Handle service discovery info request. * * @param packet An IQ packet in the disco info namespace. * @return A list of IQ packets to be returned to the user. *//* ww w. java 2s. c o m*/ private List<Packet> handleDiscoInfo(IQ packet) { List<Packet> reply = new ArrayList<Packet>(); JID from = packet.getFrom(); JID to = packet.getTo(); if (packet.getTo().getNode() == null) { // Requested info from transport itself. IQ result = IQ.createResultIQ(packet); if (from.getNode() == null || getTransport().permissionManager.hasAccess(from)) { Element response = DocumentHelper.createElement(QName.get("query", NameSpace.DISCO_INFO)); response.addElement("identity").addAttribute("category", "conference").addAttribute("type", "text") .addAttribute("name", this.getDescription()); response.addElement("feature").addAttribute("var", NameSpace.DISCO_INFO); response.addElement("feature").addAttribute("var", NameSpace.DISCO_ITEMS); response.addElement("feature").addAttribute("var", NameSpace.MUC); result.setChildElement(response); } else { result.setError(PacketError.Condition.forbidden); } reply.add(result); } else { // Ah, a request for information about a room. IQ result = IQ.createResultIQ(packet); try { TransportSession<B> session = getTransport().getSessionManager().getSession(from); if (session.isLoggedIn()) { storePendingRequest(packet); session.getRoomInfo(getTransport().convertJIDToID(to)); } else { // Not logged in? Not logged in then. result.setError(PacketError.Condition.forbidden); reply.add(result); } } catch (NotFoundException e) { // Not found? No active session then. result.setError(PacketError.Condition.forbidden); reply.add(result); } } return reply; }
From source file:net.sf.kraken.muc.BaseMUCTransport.java
License:Open Source License
/** * Sends a list of rooms as a response to a service discovery request. * * @param to JID we will be sending the response to. * @param rooms List of MUCTransportRoom objects to send as a response. *//*from ww w . j a v a 2s . c om*/ public void sendRooms(JID to, Collection<MUCTransportRoom> rooms) { IQ request = getPendingRequest(to, this.getJID(), NameSpace.DISCO_ITEMS); if (request != null) { IQ result = IQ.createResultIQ(request); Element response = DocumentHelper.createElement(QName.get("query", NameSpace.DISCO_ITEMS)); for (MUCTransportRoom room : rooms) { Element item = response.addElement("item"); item.addAttribute("jid", room.getJid().toBareJID()); item.addAttribute("name", room.getName()); } result.setChildElement(response); this.sendPacket(result); } }
From source file:net.sf.kraken.muc.BaseMUCTransport.java
License:Open Source License
/** * Sends information about a room as a response to a service discovery request. * * @param to JID we will be sending the response to. * @param roomjid JID of the room info was requested about. * @param room A MUCTransportRoom object containing information to return as a response. */// www . j a v a2s. co m public void sendRoomInfo(JID to, JID roomjid, MUCTransportRoom room) { IQ request = getPendingRequest(to, roomjid, NameSpace.DISCO_INFO); if (request != null) { IQ result = IQ.createResultIQ(request); Element response = DocumentHelper.createElement(QName.get("query", NameSpace.DISCO_INFO)); response.addElement("identity").addAttribute("category", "conference").addAttribute("type", "text") .addAttribute("name", room.getName()); response.addElement("feature").addAttribute("var", NameSpace.MUC); response.addElement("feature").addAttribute("var", NameSpace.DISCO_INFO); response.addElement("feature").addAttribute("var", NameSpace.DISCO_ITEMS); if (room.getPassword_protected()) { response.addElement("feature").addAttribute("var", "muc_passwordprotected"); } if (room.getHidden()) { response.addElement("feature").addAttribute("var", "muc_hidden"); } if (room.getTemporary()) { response.addElement("feature").addAttribute("var", "muc_temporary"); } if (room.getOpen()) { response.addElement("feature").addAttribute("var", "muc_open"); } if (!room.getModerated()) { response.addElement("feature").addAttribute("var", "muc_unmoderated"); } if (!room.getAnonymous()) { response.addElement("feature").addAttribute("var", "muc_nonanonymous"); } Element form = DocumentHelper.createElement(QName.get("x", NameSpace.XDATA)); form.addAttribute("type", "result"); form.addElement("field").addAttribute("var", "FORM_TYPE").addAttribute("type", "hidden") .addElement("value").addCDATA("http://jabber.org/protocol/muc#roominfo"); if (room.getContact() != null) { form.addElement("field").addAttribute("var", "muc#roominfo_contactjid") .addAttribute("label", "Contact Addresses").addElement("value") .addCDATA(room.getContact().toString()); } if (room.getName() != null) { form.addElement("field").addAttribute("var", "muc#roominfo_description") .addAttribute("label", "Short Description of Room").addElement("value") .addCDATA(room.getName()); } if (room.getLanguage() != null) { form.addElement("field").addAttribute("var", "muc#roominfo_lang") .addAttribute("label", "Natural Language for Room Discussions").addElement("value") .addCDATA(room.getLanguage()); } if (room.getLog_location() != null) { form.addElement("field").addAttribute("var", "muc#roominfo_logs") .addAttribute("label", "URL for Archived Discussion Logs").addElement("value") .addCDATA(room.getLog_location()); } if (room.getOccupant_count() != null) { form.addElement("field").addAttribute("var", "muc#roominfo_occupants") .addAttribute("label", "Current Number of Occupants in Room").addElement("value") .addCDATA(room.getOccupant_count().toString()); } if (room.getTopic() != null) { form.addElement("field").addAttribute("var", "muc#roominfo_subject") .addAttribute("label", "Current Subject or Discussion Topic in Room").addElement("value") .addCDATA(room.getTopic()); } response.add(form); result.setChildElement(response); this.sendPacket(result); } }
From source file:net.sf.kraken.muc.BaseMUCTransport.java
License:Open Source License
/** * Sends a list of rooms as a response to a service discovery request. * * @param to JID we will be sending the response to. * @param roomjid JID of the room info was requested about. * @param members List of MUCTransportRoomMember objects to send as a response. *//*from w w w . j a v a2 s . com*/ public void sendRoomMembers(JID to, JID roomjid, List<MUCTransportRoomMember> members) { IQ request = getPendingRequest(to, roomjid, NameSpace.DISCO_ITEMS); if (request != null) { IQ result = IQ.createResultIQ(request); Element response = DocumentHelper.createElement(QName.get("query", NameSpace.DISCO_ITEMS)); for (MUCTransportRoomMember member : members) { Element item = response.addElement("item"); item.addAttribute("jid", member.getJid().toBareJID()); } result.setChildElement(response); this.sendPacket(result); } }
From source file:net.sf.kraken.registration.RegistrationHandler.java
License:Open Source License
/** * Handles a IQ-register 'get' request, which is to be interpreted as a * request for a registration form template. The template will be prefilled * with data, if the requestee has a current registration with the gateway. * * @param packet the IQ-register 'get' stanza. * @throws UnauthorizedException if the user is not allowed to make use of the gateway. *//* w ww . j a v a 2 s.c o m*/ private void getRegistrationForm(IQ packet) throws UnauthorizedException { final JID from = packet.getFrom(); final IQ result = IQ.createResultIQ(packet); // search for existing registrations String curUsername = null; String curPassword = null; String curNickname = null; Boolean registered = false; final Collection<Registration> registrations = RegistrationManager.getInstance().getRegistrations(from, parent.transportType); if (registrations.iterator().hasNext()) { Registration registration = registrations.iterator().next(); curUsername = registration.getUsername(); curPassword = registration.getPassword(); curNickname = registration.getNickname(); registered = true; } // Verify that the user is allowed to make use of the gateway. if (!registered && !parent.permissionManager.hasAccess(from)) { // User does not have permission to register with transport. // We want to allow them to change settings if they are already // registered. throw new UnauthorizedException( LocaleUtils.getLocalizedString("gateway.base.registrationdeniedbyacls", "kraken")); } // generate a template registration form. final Element response = DocumentHelper.createElement(QName.get("query", NameSpace.IQ_REGISTER)); final DataForm form = new DataForm(DataForm.Type.form); form.addInstruction(parent.getTerminologyRegistration()); final FormField usernameField = form.addField(); usernameField.setLabel(parent.getTerminologyUsername()); usernameField.setVariable("username"); usernameField.setType(FormField.Type.text_single); if (curUsername != null) { usernameField.addValue(curUsername); } final FormField passwordField = form.addField(); passwordField.setLabel(parent.getTerminologyPassword()); passwordField.setVariable("password"); passwordField.setType(FormField.Type.text_private); if (curPassword != null) { passwordField.addValue(curPassword); } final String nicknameTerm = parent.getTerminologyNickname(); if (nicknameTerm != null) { FormField nicknameField = form.addField(); nicknameField.setLabel(nicknameTerm); nicknameField.setVariable("nick"); nicknameField.setType(FormField.Type.text_single); if (curNickname != null) { nicknameField.addValue(curNickname); } } response.add(form.getElement()); response.addElement("instructions").addText(parent.getTerminologyRegistration()); // prefill the template with existing data if a registration already // exists. if (registered) { response.addElement("registered"); response.addElement("username").addText(curUsername); if (curPassword == null) { response.addElement("password"); } else { response.addElement("password").addText(curPassword); } if (nicknameTerm != null) { if (curNickname == null) { response.addElement("nick"); } else { response.addElement("nick").addText(curNickname); } } } else { response.addElement("username"); response.addElement("password"); if (nicknameTerm != null) { response.addElement("nick"); } } // Add special indicator for rosterless gateway handling. response.addElement("x").addNamespace("", NameSpace.IQ_GATEWAY_REGISTER); result.setChildElement(response); parent.sendPacket(result); }
From source file:net.sf.kraken.roster.TransportBuddy.java
License:Open Source License
/** * Returns the entire vcard element for an avatar. * * This will return a vCard element, filled in as much as possible, regardless of whether we have * real data for the user. It'll return minimal regardless. * * @return vCard element//ww w. j a v a 2 s . c o m */ public Element getVCard() { Element vcard = DocumentHelper.createElement(QName.get("vCard", NameSpace.VCARD_TEMP)); vcard.addElement("VERSION").addCDATA("2.0"); vcard.addElement("JABBERID").addCDATA(getJID().toString()); vcard.addElement("NICKNAME").addCDATA(getNickname() == null ? getName() : getNickname()); if (JiveGlobals.getBooleanProperty( "plugin.gateway." + getManager().getSession().getTransport().getType() + ".avatars", true)) { addVCardPhoto(vcard); } return vcard; }
From source file:org.androidpn.server.xmpp.session.SessionManager.java
License:Open Source License
/** * Creates a new notification IQ and returns it. *//*w w w. ja v a 2 s . co m*/ private IQ createNotificationIQ(String apiKey, String title, String message, String uri) { Random random = new Random(); String id = Integer.toHexString(random.nextInt()); // String id = String.valueOf(System.currentTimeMillis()); Element notification = DocumentHelper .createElement(QName.get("notification", NotificationManager.NOTIFICATION_NAMESPACE)); notification.addElement("id").setText(id); notification.addElement("apiKey").setText(apiKey); notification.addElement("title").setText(title); notification.addElement("message").setText(message); notification.addElement("uri").setText(uri); IQ iq = new IQ(); iq.setType(IQ.Type.set); iq.setChildElement(notification); return iq; }
From source file:org.arquillian.graphene.visual.testing.impl.JCRMaskHandler.java
private void addMasksToConfiguration(List<MaskFromREST> masks, Document doc) { Namespace ns = Namespace.get(RushEye.NAMESPACE_VISUAL_SUITE); String xPath = "/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"visual-suite\"]/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"global-configuration\"]"; Element configurationNode = (Element) doc.selectSingleNode(xPath); for (MaskFromREST mask : masks) { Element maskElement = configurationNode.addElement(QName.get("mask", ns)); maskElement.addAttribute("id", mask.getId()); maskElement.addAttribute("source", mask.getSourceUrl()); maskElement.addAttribute("type", mask.getMaskType().value()); }/* w w w . ja v a 2s.c o m*/ }