public String getLanguage() { // Default language is English ("en"). final String language = document.getRootElement().attributeValue( QName.get( "lang", XMLConstants.XML_NS_URI ) ); if ( language == null || "".equals( language ) ) { return "en"; } return language; }
@Override public Element getSubsriptionErrorDetail() { return DocumentHelper.createElement( QName.get("closed-node", "http://jabber.org/protocol/pubsub#errors")); }
@Override public Element getSubsriptionErrorDetail() { return DocumentHelper.createElement(QName.get("not-subscribed", "http://jabber.org/protocol/pubsub#errors")); }
@Override public Element getSubsriptionErrorDetail() { return DocumentHelper.createElement(QName.get("presence-subscription-required", "http://jabber.org/protocol/pubsub#errors")); }
@Override public Element getSubsriptionErrorDetail() { return DocumentHelper.createElement( QName.get("not-in-roster-group", "http://jabber.org/protocol/pubsub#errors")); }
/** * Returns a value that is an appropriate unique and stable stanza ID in * context of XEP-0359: it's either the origin-id value, or a UUID. * * @param packet The stanza for what to return the ID (cannot be null). * @return The ID (never null or empty string). */ public static String generateUniqueAndStableStanzaID( final Packet packet ) { String result = null; final Iterator<Element> existingElementIterator = packet.getElement().elementIterator( QName.get( "origin-id", "urn:xmpp:sid:0" ) ); while (existingElementIterator.hasNext() && (result == null || result.isEmpty() ) ) { final Element element = existingElementIterator.next(); result = element.attributeValue( "id" ); } if ( result == null || result.isEmpty() ) { result = UUID.randomUUID().toString(); Log.debug( "Using newly generated value '{}' for stanza that has id '{}'.", result, packet.getID() ); } else { Log.debug( "Using origin-id provided value '{}' for stanza that has id '{}'.", result, packet.getID() ); } return result; } }
/** * Retrieves an <code>Iterator</code> over the attribute elements that * match the supplied name. * * @param contextNode the origin context node * @param localName the local name of the attributes to return, always present * @param namespacePrefix the prefix of the namespace of the attributes to return * @param namespaceURI the URI of the namespace of the attributes to return * @return an Iterator that traverses the named attributes, not null */ public Iterator getAttributeAxisIterator( Object contextNode, String localName, String namespacePrefix, String namespaceURI) { if ( contextNode instanceof Element ) { Element node = (Element) contextNode; Attribute attr = node.attribute(QName.get(localName, namespacePrefix, namespaceURI)); if (attr == null) { return JaxenConstants.EMPTY_ITERATOR; } return new SingleObjectIterator(attr); } return JaxenConstants.EMPTY_ITERATOR; }
/** * Stores in the SessionData the fields and their values as specified in the completed * data form by the user. * * @param iqCommand the command element containing the data form element. * @param session the SessionData for this command execution. */ private void saveCompletedForm(Element iqCommand, SessionData session) { Element formElement = iqCommand.element(QName.get("x", "jabber:x:data")); if (formElement != null) { // Generate a Map with the variable names and variables values Map<String, List<String>> data = new HashMap<>(); DataForm dataForm = new DataForm(formElement); for (FormField field : dataForm.getFields()) { data.put(field.getVariable(), field.getValues()); } // Store the variables and their values in the session data session.addStageForm(data); } }
protected String createEmptyBody(boolean terminate) { final Element body = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) ); if (terminate) { body.addAttribute("type", "terminate"); } body.addAttribute("ack", String.valueOf(getLastAcknowledged())); return body.asXML(); }
protected static String createErrorBody(String type, String condition) { final Element body = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) ); body.addAttribute("type", type); body.addAttribute("condition", condition); return body.asXML(); }
private void initiateSession(Element stanza) { String host = stanza.attributeValue("to"); StreamError streamError = null; Locale language = Locale.forLanguageTag(stanza.attributeValue(QName.get("lang", XMLConstants.XML_NS_URI), "en")); if (STREAM_FOOTER.equals(stanza.getName())) { // an error occurred while setting up the session Log.warn("Client closed stream before session was established"); } else if (!STREAM_HEADER.equals(stanza.getName())) { streamError = new StreamError(StreamError.Condition.unsupported_stanza_type); Log.warn("Closing session due to incorrect stream header. Tag: " + stanza.getName()); } else if (!FRAMING_NAMESPACE.equals(stanza.getNamespace().getURI())) { // Validate the stream namespace (https://tools.ietf.org/html/rfc7395#section-3.3.2) streamError = new StreamError(StreamError.Condition.invalid_namespace); Log.warn("Closing session due to invalid namespace in stream header. Namespace: " + stanza.getNamespace().getURI()); } else if (!validateHost(host)) { streamError = new StreamError(StreamError.Condition.host_unknown); Log.warn("Closing session due to incorrect hostname in stream header. Host: " + host); } else { // valid stream; initiate session xmppSession = SessionManager.getInstance().createClientSession(wsConnection, language); xmppSession.setSessionData("ws", Boolean.TRUE); } if (xmppSession == null) { closeStream(streamError); } else { openStream(language.toLanguageTag(), stanza.attributeValue("from")); configureStream(); } }
@Override public void setPresence(Presence newPresence) { // Try to remove the element whose namespace is "http://jabber.org/protocol/muc" since we // don't need to include that element in future presence broadcasts Element element = newPresence.getElement().element(QName.get("x", "http://jabber.org/protocol/muc")); if (element != null) { newPresence.getElement().remove(element); } this.presence = newPresence; this.presence.setFrom(getRoleAddress()); updatePresence(); }
private void updatePresence() { if (extendedInformation != null && presence != null) { // Remove any previous extendedInformation, then re-add it. Element mucUser = presence.getElement().element(QName.get("x", "http://jabber.org/protocol/muc#user")); if (mucUser != null) { // Remove any previous extendedInformation, then re-add it. presence.getElement().remove(mucUser); } Element exi = extendedInformation.createCopy(); presence.getElement().add(exi); } }
private void populate(Element copy, Date delay, JID delayFrom) { copy.setQName(QName.get("message", "jabber:client")); for (Object element : copy.elements()) { if (element instanceof Element) { Element el = (Element) element; // Only set the "jabber:client" namespace if the namespace is empty (otherwise the resulting xml would look like <body xmlns=""/>) if ("".equals(el.getNamespace().getStringValue())) { el.setQName(QName.get(el.getName(), "jabber:client")); } } } if (delay != null) { Element delayInfo = element.addElement("delay", "urn:xmpp:delay"); delayInfo.addAttribute("stamp", XMPPDateTimeFormat.format(delay)); if (delayFrom != null) { // Set the Full JID as the "from" attribute delayInfo.addAttribute("from", delayFrom.toString()); } } element.add(copy); } }
private String createSessionRestartResponse() { final Element response = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) ); response.addNamespace("stream", "http://etherx.jabber.org/streams"); final Element features = response.addElement("stream:features"); for (Element feature : getAvailableStreamFeaturesElements()) { features.add(feature); } return response.asXML(); }
@Override public IQ handleIQ(IQ packet) { IQ response = IQ.createResultIQ(packet); Element timeElement = DocumentHelper.createElement(QName.get(info.getName(), info.getNamespace())); timeElement.addElement("tzo").setText(formatsTimeZone(TimeZone.getDefault())); timeElement.addElement("utc").setText(getUtcDate(new Date())); response.setChildElement(timeElement); return response; }
private void getDefaultNodeConfiguration(PubSubService service, IQ iq, Element childElement, Element defaultElement) { String type = defaultElement.attributeValue("type"); type = type == null ? "leaf" : type; boolean isLeafType = "leaf".equals(type); DefaultNodeConfiguration config = service.getDefaultNodeConfiguration(isLeafType); if (config == null) { // Service does not support the requested node type so return an error Element pubsubError = DocumentHelper.createElement( QName.get("unsupported", "http://jabber.org/protocol/pubsub#errors")); pubsubError.addAttribute("feature", isLeafType ? "leaf" : "collections"); sendErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError); return; } // Return data form containing default node configuration IQ reply = IQ.createResultIQ(iq); Element replyChildElement = childElement.createCopy(); reply.setChildElement(replyChildElement); replyChildElement.element("default").add(config.getConfigurationForm().getElement()); router.route(reply); }
public Element asXMLElement() { Element option = DocumentHelper.createElement(QName.get("option", "jabber:x:data")); if (getLabel() != null) { option.addAttribute("label", getLabel()); } if (getValue() != null) { option.addElement("value").addText(getValue()); } return option; } }
public IQVersionHandler() { super("XMPP Server Version Handler"); info = new IQHandlerInfo("query", "jabber:iq:version"); if (bodyElement == null) { bodyElement = DocumentHelper.createElement(QName.get("query", "jabber:iq:version")); bodyElement.addElement("name").setText(AdminConsole.getAppName()); bodyElement.addElement("version").setText(AdminConsole.getVersionString()); } }
private static String createSessionCreationResponse(HttpSession session) throws DocumentException { Element response = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) ); response.addNamespace("stream", "http://etherx.jabber.org/streams"); response.addAttribute("from", session.getServerName()); response.addAttribute("authid", session.getStreamID().getID()); response.addAttribute("sid", session.getStreamID().getID()); response.addAttribute("secure", Boolean.TRUE.toString()); response.addAttribute("requests", String.valueOf(session.getMaxRequests())); response.addAttribute("inactivity", String.valueOf(session.getInactivityTimeout())); response.addAttribute("polling", String.valueOf(session.getMaxPollingInterval())); response.addAttribute("wait", String.valueOf(session.getWait())); if ((session.getMajorVersion() == 1 && session.getMinorVersion() >= 6) || session.getMajorVersion() > 1) { response.addAttribute("hold", String.valueOf(session.getHold())); response.addAttribute("ack", String.valueOf(session.getLastAcknowledged())); response.addAttribute("maxpause", String.valueOf(session.getMaxPause())); response.addAttribute("ver", String.valueOf(session.getMajorVersion()) + "." + String.valueOf(session.getMinorVersion())); } Element features = response.addElement("stream:features"); for (Element feature : session.getAvailableStreamFeaturesElements()) { features.add(feature); } return response.asXML(); }