mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 21:42:07 +01:00
Enable PacketExtensions for IQs
This is actually only part one, i.e. with this commit if the user adds a PacketExtension to an IQ it will be included in IQ.toXml(). Which was previously only the case if the IQ subclass explicitly included packet extensions. The second part of the change is to change the IQ provider, so that packet extensions are automatically parsed. Cases where PacketExtensions are used for Message and IQ are slightly changed. The IQ sublcass now only has a field with this PacketExtension (see for example bytestreams.ibb.packet.DataPacketExtension). Also changed hoxt API: Removed unnecessary indirection and made the API more Smack idiomatic.
This commit is contained in:
parent
a9c798f3bb
commit
9e797c1b17
93 changed files with 1347 additions and 1438 deletions
|
@ -65,13 +65,11 @@ In this example we are HTTP client, so we send request (POST) and handle the
|
||||||
response:
|
response:
|
||||||
|
|
||||||
```
|
```
|
||||||
// register listener for IQ packets
|
|
||||||
connection.addPacketListener(new IqPacketListener(), new PacketTypeFilter(IQ.class));
|
|
||||||
// create a request body
|
// create a request body
|
||||||
String urlEncodedMessage = "I_love_you";
|
String urlEncodedMessage = "I_love_you";
|
||||||
|
|
||||||
// create request
|
// create request
|
||||||
HttpOverXmppReq.Req req = new HttpOverXmppReq.Req(HttpMethod.POST, "/mailbox");
|
HttpOverXmppReq req = new HttpOverXmppReq(HttpMethod.POST, "/mailbox");
|
||||||
req.setVersion("1.1");
|
req.setVersion("1.1");
|
||||||
|
|
||||||
// prepare headers
|
// prepare headers
|
||||||
|
@ -86,52 +84,25 @@ AbstractHttpOverXmpp.Text child = new AbstractHttpOverXmpp.Text(urlEncodedMessag
|
||||||
AbstractHttpOverXmpp.Data data = new AbstractHttpOverXmpp.Data(child);
|
AbstractHttpOverXmpp.Data data = new AbstractHttpOverXmpp.Data(child);
|
||||||
req.setData(data);
|
req.setData(data);
|
||||||
|
|
||||||
// create IQ packet
|
// add to
|
||||||
HttpOverXmppReq packet = new HttpOverXmppReq();
|
req.setTo("juliet@capulet.com/balcony");
|
||||||
packet.setReq(req);
|
|
||||||
packet.setTo("juliet@capulet.com/balcony");
|
|
||||||
packet.setType(IQ.Type.SET);
|
|
||||||
packet.setPacketID("42");
|
|
||||||
|
|
||||||
// send it
|
// send it
|
||||||
connection.sendPacket(packet);
|
connection.sendIqWithResponseCallback(req, new PacketListener() {
|
||||||
|
public void processPacket(Packet packet) {
|
||||||
|
HttpOverXmppResp resp = (HttpOverXmppResp) iq;
|
||||||
// then in your PacketListener
|
// check HTTP response code
|
||||||
private class IqPacketListener implements PacketListener {
|
if (resp.getStatusCode() == 200) {
|
||||||
|
// get content of the response
|
||||||
@Override
|
NamedElement child = resp.getData().getChild();
|
||||||
public void processPacket(Packet packet) {
|
// check which type of content of the response arrived
|
||||||
IQ iq = (IQ) packet;
|
if (child instanceof AbstractHttpOverXmpp.Xml) {
|
||||||
|
// print the message and anxiously read if from console ;)
|
||||||
// verify from and packed ID
|
System.out.println(((AbstractHttpOverXmpp.Xml) child).getText());
|
||||||
if (iq.getFrom().equals("juliet@capulet.com/balcony") && (iq.getPacketID().equals("42"))) {
|
} else {
|
||||||
|
// process other AbstractHttpOverXmpp.DataChild subtypes
|
||||||
// ensure it's not ERROR
|
|
||||||
if (iq.getType().equals(IQ.Type.RESULT)) {
|
|
||||||
|
|
||||||
// check if correct IQ implementation arrived
|
|
||||||
if (iq instanceof HttpOverXmppResp) {
|
|
||||||
HttpOverXmppResp resp = (HttpOverXmppResp) iq;
|
|
||||||
|
|
||||||
// check HTTP response code
|
|
||||||
if (resp.getResp().getStatusCode() == 200) {
|
|
||||||
|
|
||||||
// get content of the response
|
|
||||||
AbstractHttpOverXmpp.DataChild child = resp.getResp().getData().getChild();
|
|
||||||
|
|
||||||
// check which type of content of the response arrived
|
|
||||||
if (child instanceof AbstractHttpOverXmpp.Xml) {
|
|
||||||
|
|
||||||
// print the message and anxiously read if from console ;)
|
|
||||||
System.out.println(((AbstractHttpOverXmpp.Xml) child).getText());
|
|
||||||
} else {
|
|
||||||
// process other AbstractHttpOverXmpp.DataChild subtypes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
package org.jivesoftware.smack.packet;
|
package org.jivesoftware.smack.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IQ packet used by Smack to bind a resource and to obtain the jid assigned by the server.
|
* IQ packet used by Smack to bind a resource and to obtain the jid assigned by the server.
|
||||||
* There are two ways to bind a resource. One is simply sending an empty Bind packet where the
|
* There are two ways to bind a resource. One is simply sending an empty Bind packet where the
|
||||||
|
@ -39,6 +37,7 @@ public class Bind extends IQ {
|
||||||
private final String jid;
|
private final String jid;
|
||||||
|
|
||||||
public Bind(String resource, String jid) {
|
public Bind(String resource, String jid) {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
this.resource = resource;
|
this.resource = resource;
|
||||||
this.jid = jid;
|
this.jid = jid;
|
||||||
}
|
}
|
||||||
|
@ -62,12 +61,10 @@ public class Bind extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
xml.rightAngleBracket();
|
||||||
xml.halfOpenElement(ELEMENT).xmlnsAttribute(NAMESPACE).rightAngleBracket();
|
|
||||||
xml.optElement("resource", resource);
|
xml.optElement("resource", resource);
|
||||||
xml.optElement("jid", jid);
|
xml.optElement("jid", jid);
|
||||||
xml.closeElement(ELEMENT);
|
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright © 2014 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smack.packet;
|
||||||
|
|
||||||
|
public class EmptyResultIQ extends IQ {
|
||||||
|
|
||||||
|
public EmptyResultIQ() {
|
||||||
|
super(null, null);
|
||||||
|
type = IQ.Type.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EmptyResultIQ(IQ request) {
|
||||||
|
this();
|
||||||
|
if (!(request.getType() == Type.get || request.getType() == Type.set)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"IQ must be of type 'set' or 'get'. Original IQ: " + request.toXML());
|
||||||
|
}
|
||||||
|
setPacketID(request.getPacketID());
|
||||||
|
setFrom(request.getTo());
|
||||||
|
setTo(request.getFrom());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
|
// Empty result IQs don't have an child elements
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright © 2014 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smack.packet;
|
||||||
|
|
||||||
|
public class ErrorIQ extends SimpleIQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = XMPPError.ERROR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new error IQ.
|
||||||
|
* <p>
|
||||||
|
* According to RFC 6120 § 8.3.1 "4. An error stanza MUST contain an <error/> child element.", so the xmppError argument is mandatory.
|
||||||
|
* </p>
|
||||||
|
* @param xmppError the XMPPError (required).
|
||||||
|
*/
|
||||||
|
public ErrorIQ(XMPPError xmppError) {
|
||||||
|
super(ELEMENT, null);
|
||||||
|
if (xmppError == null) {
|
||||||
|
throw new IllegalArgumentException("XMPPError must not be null");
|
||||||
|
}
|
||||||
|
type = IQ.Type.error;
|
||||||
|
setError(xmppError);
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,16 +43,27 @@ public abstract class IQ extends Packet {
|
||||||
public static final String ELEMENT = "iq";
|
public static final String ELEMENT = "iq";
|
||||||
public static final String QUERY_ELEMENT = "query";
|
public static final String QUERY_ELEMENT = "query";
|
||||||
|
|
||||||
private Type type = Type.get;
|
private final String childElementName;
|
||||||
|
private final String childElementNamespace;
|
||||||
|
|
||||||
public IQ() {
|
protected Type type = Type.get;
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IQ(IQ iq) {
|
public IQ(IQ iq) {
|
||||||
super(iq);
|
super(iq);
|
||||||
type = iq.getType();
|
type = iq.getType();
|
||||||
|
this.childElementName = iq.childElementName;
|
||||||
|
this.childElementNamespace = iq.childElementNamespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected IQ(String childElementName) {
|
||||||
|
this(childElementName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ(String childElementName, String childElementNamespace) {
|
||||||
|
this.childElementName = childElementName;
|
||||||
|
this.childElementNamespace = childElementNamespace;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of the IQ packet.
|
* Returns the type of the IQ packet.
|
||||||
*
|
*
|
||||||
|
@ -76,8 +87,16 @@ public abstract class IQ extends Packet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final String getChildElementName() {
|
||||||
|
return childElementName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String getChildElementNamespace() {
|
||||||
|
return childElementNamespace;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence toXML() {
|
public final XmlStringBuilder toXML() {
|
||||||
XmlStringBuilder buf = new XmlStringBuilder();
|
XmlStringBuilder buf = new XmlStringBuilder();
|
||||||
buf.halfOpenElement(ELEMENT);
|
buf.halfOpenElement(ELEMENT);
|
||||||
addCommonAttributes(buf);
|
addCommonAttributes(buf);
|
||||||
|
@ -88,26 +107,84 @@ public abstract class IQ extends Packet {
|
||||||
buf.attribute("type", type.toString());
|
buf.attribute("type", type.toString());
|
||||||
}
|
}
|
||||||
buf.rightAngleBracket();
|
buf.rightAngleBracket();
|
||||||
// Add the query section if there is one.
|
buf.append(getChildElementXML());
|
||||||
buf.optAppend(getChildElementXML());
|
|
||||||
// Add the error sub-packet, if there is one.
|
|
||||||
XMPPError error = getError();
|
|
||||||
if (error != null) {
|
|
||||||
buf.append(error.toXML());
|
|
||||||
}
|
|
||||||
buf.closeElement(ELEMENT);
|
buf.closeElement(ELEMENT);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the sub-element XML section of the IQ packet, or <tt>null</tt> if there
|
* Returns the sub-element XML section of the IQ packet, or the empty String if there
|
||||||
* isn't one. Packet extensions <b>must</b> be included, if any are defined.<p>
|
* isn't one.
|
||||||
*
|
|
||||||
* Extensions of this class must override this method.
|
|
||||||
*
|
*
|
||||||
* @return the child element section of the IQ XML.
|
* @return the child element section of the IQ XML.
|
||||||
*/
|
*/
|
||||||
public abstract CharSequence getChildElementXML();
|
public final XmlStringBuilder getChildElementXML() {
|
||||||
|
XmlStringBuilder xml = new XmlStringBuilder();
|
||||||
|
if (type == Type.error) {
|
||||||
|
// Add the error sub-packet, if there is one.
|
||||||
|
appendErrorIfExists(xml);
|
||||||
|
}
|
||||||
|
else if (childElementName != null) {
|
||||||
|
// Add the query section if there is one.
|
||||||
|
IQChildElementXmlStringBuilder iqChildElement = getIQChildElementBuilder(new IQChildElementXmlStringBuilder(this));
|
||||||
|
if (iqChildElement != null) {
|
||||||
|
xml.append(iqChildElement);
|
||||||
|
XmlStringBuilder extensionsXml = getExtensionsXML();
|
||||||
|
if (iqChildElement.isEmptyElement) {
|
||||||
|
if (extensionsXml.length() == 0) {
|
||||||
|
xml.closeEmptyElement();
|
||||||
|
return xml;
|
||||||
|
} else {
|
||||||
|
xml.rightAngleBracket();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xml.append(extensionsXml);
|
||||||
|
xml.closeElement(iqChildElement.element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method must be overwritten by IQ subclasses to create their child content. It is important that the builder
|
||||||
|
* <b>does not include the final end element</b>. This will be done automatically by IQChildelementXmlStringBuilder
|
||||||
|
* after eventual existing packet extensions have been added.
|
||||||
|
* <p>
|
||||||
|
* For example to create an IQ with a extra attribute and an additional child element
|
||||||
|
* </p>
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <iq to='foo@example.org' id='123'>
|
||||||
|
* <bar xmlns='example:bar' extraAttribute='blaz'>
|
||||||
|
* <extraElement>elementText</extraElement>
|
||||||
|
* </bar>
|
||||||
|
* </iq>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* the body of the {@code getIQChildElementBuilder} looks like
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* // The builder 'xml' will already have the child element and the 'xmlns' attribute added
|
||||||
|
* // So the current builder state is "<bar xmlns='example:bar'"
|
||||||
|
* xml.attribute("extraAttribute", "blaz");
|
||||||
|
* xml.rightAngleBracket();
|
||||||
|
* xml.element("extraElement", "elementText");
|
||||||
|
* // Do not close the 'bar' attribute by calling xml.closeElement('bar')
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* If your IQ only contains attributes and no child elements, i.e. it can be represented as empty element, then you
|
||||||
|
* can mark it as such.
|
||||||
|
* <pre>
|
||||||
|
* xml.attribute("myAttribute", "myAttributeValue");
|
||||||
|
* xml.setEmptyElement();
|
||||||
|
* </pre>
|
||||||
|
* If your IQ does not contain any attributes or child elements (besides packet extensions), consider sub-classing
|
||||||
|
* {@link SimpleIQ} instead.
|
||||||
|
*
|
||||||
|
* @param xml a pre-created builder which already has the child element and the 'xmlns' attribute set.
|
||||||
|
* @return the build to create the IQ child content.
|
||||||
|
*/
|
||||||
|
protected abstract IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method to create a new empty {@link Type#result IQ.Type.result}
|
* Convenience method to create a new empty {@link Type#result IQ.Type.result}
|
||||||
|
@ -126,20 +203,7 @@ public abstract class IQ extends Packet {
|
||||||
* @return a new {@link Type#result IQ.Type.result} IQ based on the originating IQ.
|
* @return a new {@link Type#result IQ.Type.result} IQ based on the originating IQ.
|
||||||
*/
|
*/
|
||||||
public static IQ createResultIQ(final IQ request) {
|
public static IQ createResultIQ(final IQ request) {
|
||||||
if (!(request.getType() == Type.get || request.getType() == Type.set)) {
|
return new EmptyResultIQ(request);
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"IQ must be of type 'set' or 'get'. Original IQ: " + request.toXML());
|
|
||||||
}
|
|
||||||
final IQ result = new IQ() {
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
result.setType(Type.result);
|
|
||||||
result.setPacketID(request.getPacketID());
|
|
||||||
result.setFrom(request.getTo());
|
|
||||||
result.setTo(request.getFrom());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,17 +229,10 @@ public abstract class IQ extends Packet {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"IQ must be of type 'set' or 'get'. Original IQ: " + request.toXML());
|
"IQ must be of type 'set' or 'get'. Original IQ: " + request.toXML());
|
||||||
}
|
}
|
||||||
final IQ result = new IQ() {
|
final IQ result = new ErrorIQ(error);
|
||||||
@Override
|
|
||||||
public CharSequence getChildElementXML() {
|
|
||||||
return request.getChildElementXML();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
result.setType(Type.error);
|
|
||||||
result.setPacketID(request.getPacketID());
|
result.setPacketID(request.getPacketID());
|
||||||
result.setFrom(request.getTo());
|
result.setFrom(request.getTo());
|
||||||
result.setTo(request.getFrom());
|
result.setTo(request.getFrom());
|
||||||
result.setError(error);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,4 +266,27 @@ public abstract class IQ extends Packet {
|
||||||
return Type.valueOf(string.toLowerCase(Locale.US));
|
return Type.valueOf(string.toLowerCase(Locale.US));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class IQChildElementXmlStringBuilder extends XmlStringBuilder {
|
||||||
|
private final String element;
|
||||||
|
|
||||||
|
private boolean isEmptyElement;
|
||||||
|
|
||||||
|
private IQChildElementXmlStringBuilder(IQ iq) {
|
||||||
|
this(iq.getChildElementName(), iq.getChildElementNamespace());
|
||||||
|
}
|
||||||
|
|
||||||
|
public IQChildElementXmlStringBuilder(PacketExtension pe) {
|
||||||
|
this(pe.getElementName(), pe.getNamespace());
|
||||||
|
}
|
||||||
|
|
||||||
|
private IQChildElementXmlStringBuilder(String element, String namespace) {
|
||||||
|
prelude(element, namespace);
|
||||||
|
this.element = element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmptyElement() {
|
||||||
|
isEmptyElement = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -430,10 +430,7 @@ public final class Message extends Packet {
|
||||||
buf.optElement("thread", thread);
|
buf.optElement("thread", thread);
|
||||||
// Append the error subpacket if the message type is an error.
|
// Append the error subpacket if the message type is an error.
|
||||||
if (type == Type.error) {
|
if (type == Type.error) {
|
||||||
XMPPError error = getError();
|
appendErrorIfExists(buf);
|
||||||
if (error != null) {
|
|
||||||
buf.append(error.toXML());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Add packet extensions, if any are defined.
|
// Add packet extensions, if any are defined.
|
||||||
buf.append(getExtensionsXML());
|
buf.append(getExtensionsXML());
|
||||||
|
|
|
@ -383,9 +383,21 @@ public abstract class Packet extends TopLevelStreamElement {
|
||||||
* @param xml
|
* @param xml
|
||||||
*/
|
*/
|
||||||
protected void addCommonAttributes(XmlStringBuilder xml) {
|
protected void addCommonAttributes(XmlStringBuilder xml) {
|
||||||
xml.optAttribute("id", getPacketID());
|
|
||||||
xml.optAttribute("to", getTo());
|
xml.optAttribute("to", getTo());
|
||||||
xml.optAttribute("from", getFrom());
|
xml.optAttribute("from", getFrom());
|
||||||
|
xml.optAttribute("id", getPacketID());
|
||||||
xml.xmllangAttribute(getLanguage());
|
xml.xmllangAttribute(getLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append an XMPPError is this packet has one set.
|
||||||
|
*
|
||||||
|
* @param xml the XmlStringBuilder to append the error to.
|
||||||
|
*/
|
||||||
|
protected void appendErrorIfExists(XmlStringBuilder xml) {
|
||||||
|
XMPPError error = getError();
|
||||||
|
if (error != null) {
|
||||||
|
xml.append(error.toXML());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,10 +223,8 @@ public final class Presence extends Packet {
|
||||||
buf.append(getExtensionsXML());
|
buf.append(getExtensionsXML());
|
||||||
|
|
||||||
// Add the error sub-packet, if there is one.
|
// Add the error sub-packet, if there is one.
|
||||||
XMPPError error = getError();
|
appendErrorIfExists(buf);
|
||||||
if (error != null) {
|
|
||||||
buf.append(error.toXML());
|
|
||||||
}
|
|
||||||
buf.closeElement(ELEMENT);
|
buf.closeElement(ELEMENT);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
|
|
|
@ -40,6 +40,10 @@ public class RosterPacket extends IQ {
|
||||||
private final List<Item> rosterItems = new ArrayList<Item>();
|
private final List<Item> rosterItems = new ArrayList<Item>();
|
||||||
private String rosterVersion;
|
private String rosterVersion;
|
||||||
|
|
||||||
|
public RosterPacket() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a roster item to the packet.
|
* Adds a roster item to the packet.
|
||||||
*
|
*
|
||||||
|
@ -74,10 +78,7 @@ public class RosterPacket extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
XmlStringBuilder buf = new XmlStringBuilder();
|
|
||||||
buf.halfOpenElement(ELEMENT);
|
|
||||||
buf.xmlnsAttribute(NAMESPACE);
|
|
||||||
buf.optAttribute("ver", rosterVersion);
|
buf.optAttribute("ver", rosterVersion);
|
||||||
buf.rightAngleBracket();
|
buf.rightAngleBracket();
|
||||||
|
|
||||||
|
@ -86,7 +87,6 @@ public class RosterPacket extends IQ {
|
||||||
buf.append(entry.toXML());
|
buf.append(entry.toXML());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf.closeElement(ELEMENT);
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ package org.jivesoftware.smack.packet;
|
||||||
*
|
*
|
||||||
* @author Gaston Dombiak
|
* @author Gaston Dombiak
|
||||||
*/
|
*/
|
||||||
public class Session extends IQ {
|
public class Session extends SimpleIQ {
|
||||||
|
|
||||||
public static final String ELEMENT = "session";
|
public static final String ELEMENT = "session";
|
||||||
public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-session";
|
public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-session";
|
||||||
|
@ -38,14 +38,10 @@ public class Session extends IQ {
|
||||||
private static final String SESSION = '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
private static final String SESSION = '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
||||||
|
|
||||||
public Session() {
|
public Session() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
setType(IQ.Type.set);
|
setType(IQ.Type.set);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return SESSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Feature implements PacketExtension {
|
public static class Feature implements PacketExtension {
|
||||||
|
|
||||||
public static final Session.Feature INSTANCE = new Feature();
|
public static final Session.Feature INSTANCE = new Feature();
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright © 2014 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smack.packet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple IQ.
|
||||||
|
* <p>
|
||||||
|
* Simple IQs child elements do not contain further attributes besides 'xmlns'. They may contain additional packet
|
||||||
|
* extensions.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public abstract class SimpleIQ extends IQ {
|
||||||
|
|
||||||
|
protected SimpleIQ(String childElementName, String childElementNamespace) {
|
||||||
|
super(childElementName, childElementNamespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
|
xml.setEmptyElement();
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -32,6 +32,8 @@ import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.compress.packet.Compress;
|
import org.jivesoftware.smack.compress.packet.Compress;
|
||||||
import org.jivesoftware.smack.packet.DefaultPacketExtension;
|
import org.jivesoftware.smack.packet.DefaultPacketExtension;
|
||||||
|
import org.jivesoftware.smack.packet.EmptyResultIQ;
|
||||||
|
import org.jivesoftware.smack.packet.ErrorIQ;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
|
@ -634,10 +636,12 @@ public class PacketParserUtils {
|
||||||
}
|
}
|
||||||
// Only handle unknown IQs of type result. Types of 'get' and 'set' which are not understood
|
// Only handle unknown IQs of type result. Types of 'get' and 'set' which are not understood
|
||||||
// have to be answered with an IQ error response. See the code a few lines below
|
// have to be answered with an IQ error response. See the code a few lines below
|
||||||
|
// Note that if we reach this code, it is guranteed that the result IQ contained a child element
|
||||||
|
// (RFC 6120 § 8.2.3 6) because otherwhise we would have reached the END_TAG first.
|
||||||
else if (IQ.Type.result == type){
|
else if (IQ.Type.result == type){
|
||||||
// No Provider found for the IQ stanza, parse it to an UnparsedIQ instance
|
// No Provider found for the IQ stanza, parse it to an UnparsedIQ instance
|
||||||
// so that the content of the IQ can be examined later on
|
// so that the content of the IQ can be examined later on
|
||||||
iqPacket = new UnparsedResultIQ(parseElement(parser));
|
iqPacket = new UnparsedResultIQ(elementName, namespace, parseElement(parser));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -652,32 +656,28 @@ public class PacketParserUtils {
|
||||||
}
|
}
|
||||||
// Decide what to do when an IQ packet was not understood
|
// Decide what to do when an IQ packet was not understood
|
||||||
if (iqPacket == null) {
|
if (iqPacket == null) {
|
||||||
if (connection != null && (IQ.Type.get == type || IQ.Type.set == type)) {
|
switch (type) {
|
||||||
|
case get:
|
||||||
|
case set:
|
||||||
|
if (connection == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
// If the IQ stanza is of type "get" or "set" containing a child element qualified
|
// If the IQ stanza is of type "get" or "set" containing a child element qualified
|
||||||
// by a namespace with no registered Smack provider, then answer an IQ of type
|
// by a namespace with no registered Smack provider, then answer an IQ of type
|
||||||
// "error" with code 501 ("feature-not-implemented")
|
// "error" with code 501 ("feature-not-implemented")
|
||||||
iqPacket = new IQ() {
|
iqPacket = new ErrorIQ(new XMPPError(XMPPError.Condition.feature_not_implemented));
|
||||||
@Override
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
iqPacket.setPacketID(id);
|
iqPacket.setPacketID(id);
|
||||||
iqPacket.setTo(from);
|
iqPacket.setTo(from);
|
||||||
iqPacket.setFrom(to);
|
iqPacket.setFrom(to);
|
||||||
iqPacket.setType(IQ.Type.error);
|
|
||||||
iqPacket.setError(new XMPPError(XMPPError.Condition.feature_not_implemented));
|
|
||||||
connection.sendPacket(iqPacket);
|
connection.sendPacket(iqPacket);
|
||||||
return null;
|
return null;
|
||||||
}
|
case error:
|
||||||
else {
|
// If an IQ packet wasn't created above, create an empty error IQ packet.
|
||||||
// If an IQ packet wasn't created above, create an empty IQ packet.
|
iqPacket = new ErrorIQ(error);
|
||||||
iqPacket = new IQ() {
|
break;
|
||||||
@Override
|
case result:
|
||||||
public String getChildElementXML() {
|
iqPacket = new EmptyResultIQ();
|
||||||
return null;
|
break;
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1077,15 +1077,20 @@ public class PacketParserUtils {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static class UnparsedResultIQ extends IQ {
|
public static class UnparsedResultIQ extends IQ {
|
||||||
public UnparsedResultIQ(CharSequence content) {
|
private UnparsedResultIQ(String element, String namespace, CharSequence content) {
|
||||||
|
super(element, namespace);
|
||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final CharSequence content;
|
private final CharSequence content;
|
||||||
|
|
||||||
|
public CharSequence getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
return this.content;
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,15 @@ public class XmlStringBuilder implements Appendable, CharSequence {
|
||||||
halfOpenElement(e.getElementName());
|
halfOpenElement(e.getElementName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XmlStringBuilder escapedElement(String name, String escapedContent) {
|
||||||
|
assert escapedContent != null;
|
||||||
|
openElement(name);
|
||||||
|
append(escapedContent);
|
||||||
|
closeElement(name);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does nothing if content is null.
|
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* @param content
|
* @param content
|
||||||
|
@ -94,6 +101,7 @@ public class XmlStringBuilder implements Appendable, CharSequence {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmlStringBuilder halfOpenElement(String name) {
|
public XmlStringBuilder halfOpenElement(String name) {
|
||||||
|
assert(StringUtils.isNotEmpty(name));
|
||||||
sb.append('<').append(name);
|
sb.append('<').append(name);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -235,8 +243,12 @@ public class XmlStringBuilder implements Appendable, CharSequence {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmlStringBuilder prelude(PacketExtension pe) {
|
public XmlStringBuilder prelude(PacketExtension pe) {
|
||||||
halfOpenElement(pe.getElementName());
|
return prelude(pe.getElementName(), pe.getNamespace());
|
||||||
xmlnsAttribute(pe.getNamespace());
|
}
|
||||||
|
|
||||||
|
public XmlStringBuilder prelude(String elementName, String namespace) {
|
||||||
|
halfOpenElement(elementName);
|
||||||
|
xmlnsAttribute(namespace);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,6 +259,13 @@ public class XmlStringBuilder implements Appendable, CharSequence {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XmlStringBuilder optAppend(Element element) {
|
||||||
|
if (element != null) {
|
||||||
|
append(element.toXML());
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public XmlStringBuilder append(XmlStringBuilder xsb) {
|
public XmlStringBuilder append(XmlStringBuilder xsb) {
|
||||||
assert xsb != null;
|
assert xsb != null;
|
||||||
sb.append(xsb.sb);
|
sb.append(xsb.sb);
|
||||||
|
|
|
@ -655,14 +655,7 @@ public class RosterTest {
|
||||||
connection.processPacket(rosterPush);
|
connection.processPacket(rosterPush);
|
||||||
|
|
||||||
// Create and process the IQ response
|
// Create and process the IQ response
|
||||||
final IQ response = new IQ() {
|
final IQ response = IQ.createResultIQ(rosterRequest);
|
||||||
public String getChildElementXML() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
response.setPacketID(rosterRequest.getPacketID());
|
|
||||||
response.setType(Type.result);
|
|
||||||
response.setTo(connection.getUser());
|
|
||||||
connection.processPacket(response);
|
connection.processPacket(response);
|
||||||
|
|
||||||
// Verify the roster update request
|
// Verify the roster update request
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright © Florian Schmaus
|
* Copyright © 2014 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
import org.jivesoftware.smack.packet.TestIQ;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -27,26 +28,15 @@ public class StanzaIdTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIqId() {
|
public void testIqId() {
|
||||||
IQ iq1 = new TestIqId();
|
IQ iq1 = new TestIQ();
|
||||||
String iq1Id = iq1.getPacketID();
|
String iq1Id = iq1.getPacketID();
|
||||||
assertTrue(StringUtils.isNotEmpty(iq1Id));
|
assertTrue(StringUtils.isNotEmpty(iq1Id));
|
||||||
|
|
||||||
IQ iq2 = new TestIqId();
|
IQ iq2 = new TestIQ();
|
||||||
String iq2Id = iq2.getPacketID();
|
String iq2Id = iq2.getPacketID();
|
||||||
assertTrue(StringUtils.isNotEmpty(iq2Id));
|
assertTrue(StringUtils.isNotEmpty(iq2Id));
|
||||||
|
|
||||||
assertFalse(iq1Id.equals(iq2Id));
|
assertFalse(iq1Id.equals(iq2Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestIqId extends IQ {
|
|
||||||
|
|
||||||
public TestIqId() {
|
|
||||||
setType(Type.set);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getChildElementXML() {
|
|
||||||
return "<testIqId/>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.jivesoftware.smack.packet;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -32,18 +31,15 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class IQResponseTest {
|
public class IQResponseTest {
|
||||||
|
|
||||||
final static private String childElement = "<child xmlns=\"http://igniterealtime.org/protocol/test\"/>";
|
private static final String ELEMENT = "child";
|
||||||
|
private static final String NAMESPACE = "http://igniterealtime.org/protocol/test";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test creating a simple and empty IQ response.
|
* Test creating a simple and empty IQ response.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeneratingSimpleResponse() {
|
public void testGeneratingSimpleResponse() {
|
||||||
final IQ request = new IQ() {
|
final IQ request = new TestIQ(ELEMENT, NAMESPACE);
|
||||||
public String getChildElementXML() {
|
|
||||||
return childElement;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
request.setFrom("sender@test/Smack");
|
request.setFrom("sender@test/Smack");
|
||||||
request.setTo("receiver@test/Smack");
|
request.setTo("receiver@test/Smack");
|
||||||
|
|
||||||
|
@ -54,7 +50,7 @@ public class IQResponseTest {
|
||||||
assertEquals(request.getPacketID(), result.getPacketID());
|
assertEquals(request.getPacketID(), result.getPacketID());
|
||||||
assertEquals(request.getFrom(), result.getTo());
|
assertEquals(request.getFrom(), result.getTo());
|
||||||
assertEquals(request.getTo(), result.getFrom());
|
assertEquals(request.getTo(), result.getFrom());
|
||||||
assertNull(result.getChildElementXML());
|
assertEquals("", result.getChildElementXML().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,11 +59,8 @@ public class IQResponseTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGeneratingValidErrorResponse() {
|
public void testGeneratingValidErrorResponse() {
|
||||||
final XMPPError error = new XMPPError(XMPPError.Condition.bad_request);
|
final XMPPError error = new XMPPError(XMPPError.Condition.bad_request);
|
||||||
final IQ request = new IQ() {
|
final IQ request = new TestIQ(ELEMENT, NAMESPACE);
|
||||||
public String getChildElementXML() {
|
|
||||||
return childElement;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
request.setType(IQ.Type.set);
|
request.setType(IQ.Type.set);
|
||||||
request.setFrom("sender@test/Smack");
|
request.setFrom("sender@test/Smack");
|
||||||
request.setTo("receiver@test/Smack");
|
request.setTo("receiver@test/Smack");
|
||||||
|
@ -79,7 +72,8 @@ public class IQResponseTest {
|
||||||
assertEquals(request.getPacketID(), result.getPacketID());
|
assertEquals(request.getPacketID(), result.getPacketID());
|
||||||
assertEquals(request.getFrom(), result.getTo());
|
assertEquals(request.getFrom(), result.getTo());
|
||||||
assertEquals(error, result.getError());
|
assertEquals(error, result.getError());
|
||||||
assertEquals(childElement, result.getChildElementXML());
|
// TODO this test was never valid
|
||||||
|
// assertEquals(CHILD_ELEMENT, result.getChildElementXML());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,11 +82,8 @@ public class IQResponseTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeneratingResponseBasedOnResult() {
|
public void testGeneratingResponseBasedOnResult() {
|
||||||
final IQ request = new IQ() {
|
final IQ request = new TestIQ(ELEMENT, NAMESPACE);
|
||||||
public String getChildElementXML() {
|
|
||||||
return childElement;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
request.setType(IQ.Type.result);
|
request.setType(IQ.Type.result);
|
||||||
request.setFrom("sender@test/Smack");
|
request.setFrom("sender@test/Smack");
|
||||||
request.setTo("receiver@test/Smack");
|
request.setTo("receiver@test/Smack");
|
||||||
|
@ -114,11 +105,8 @@ public class IQResponseTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGeneratingErrorBasedOnError() {
|
public void testGeneratingErrorBasedOnError() {
|
||||||
final XMPPError error = new XMPPError(XMPPError.Condition.bad_request);
|
final XMPPError error = new XMPPError(XMPPError.Condition.bad_request);
|
||||||
final IQ request = new IQ() {
|
final IQ request = new TestIQ(ELEMENT, NAMESPACE);
|
||||||
public String getChildElementXML() {
|
|
||||||
return childElement;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
request.setType(IQ.Type.error);
|
request.setType(IQ.Type.error);
|
||||||
request.setFrom("sender@test/Smack");
|
request.setFrom("sender@test/Smack");
|
||||||
request.setTo("receiver@test/Smack");
|
request.setTo("receiver@test/Smack");
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright © 2014 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smack.packet;
|
||||||
|
|
||||||
|
public class TestIQ extends SimpleIQ {
|
||||||
|
|
||||||
|
public TestIQ() {
|
||||||
|
this(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TestIQ(String element, String namespace) {
|
||||||
|
super(element, namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
|
if (getChildElementName() == null)
|
||||||
|
return null;
|
||||||
|
return super.getIQChildElementBuilder(xml);
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,7 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.carbons.packet;
|
package org.jivesoftware.smackx.carbons.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.SimpleIQ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Carbon IQs
|
* Carbon IQs
|
||||||
|
@ -24,29 +24,23 @@ import org.jivesoftware.smack.packet.IQ;
|
||||||
public class Carbon {
|
public class Carbon {
|
||||||
public static final String NAMESPACE = "urn:xmpp:carbons:2";
|
public static final String NAMESPACE = "urn:xmpp:carbons:2";
|
||||||
|
|
||||||
public static class Enable extends IQ {
|
public static class Enable extends SimpleIQ {
|
||||||
public static final String ELEMENT = "enable";
|
public static final String ELEMENT = "enable";
|
||||||
|
|
||||||
public Enable() {
|
public Enable() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
setType(Type.set);
|
setType(Type.set);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return "<" + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Disable extends IQ {
|
public static class Disable extends SimpleIQ {
|
||||||
public static final String ELEMENT = "disable";
|
public static final String ELEMENT = "disable";
|
||||||
|
|
||||||
public Disable() {
|
public Disable() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
setType(Type.set);
|
setType(Type.set);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return "<" + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager for HTTP ove XMPP transport (XEP-0332) extension.
|
* Manager for HTTP ove XMPP transport (XEP-0332) extension.
|
||||||
|
@ -35,7 +36,7 @@ public class HOXTManager {
|
||||||
/**
|
/**
|
||||||
* Namespace for this extension.
|
* Namespace for this extension.
|
||||||
*/
|
*/
|
||||||
public static final String NAMESPACE = "urn:xmpp:http";
|
public static final String NAMESPACE = AbstractHttpOverXmpp.NAMESPACE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
package org.jivesoftware.smackx.hoxt.packet;
|
package org.jivesoftware.smackx.hoxt.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
import org.jivesoftware.smack.packet.NamedElement;
|
||||||
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
import org.jivesoftware.smackx.shim.packet.HeadersExtension;
|
import org.jivesoftware.smackx.shim.packet.HeadersExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,97 +29,84 @@ import org.jivesoftware.smackx.shim.packet.HeadersExtension;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractHttpOverXmpp extends IQ {
|
public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
|
|
||||||
|
public static final String NAMESPACE = "urn:xmpp:http";
|
||||||
|
|
||||||
|
protected AbstractHttpOverXmpp(String element) {
|
||||||
|
super(element, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private HeadersExtension headers;
|
||||||
|
private Data data;
|
||||||
|
|
||||||
|
protected String version;
|
||||||
|
|
||||||
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
|
IQChildElementXmlStringBuilder builder = getIQHoxtChildElementBuilder(xml);
|
||||||
|
builder.append(headers.toXML());
|
||||||
|
builder.append(data.toXML());
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract representation of parent of Req and Resp elements.
|
* Returns start tag.
|
||||||
|
*
|
||||||
|
* @return start tag
|
||||||
*/
|
*/
|
||||||
public static abstract class AbstractBody {
|
protected abstract IQChildElementXmlStringBuilder getIQHoxtChildElementBuilder(IQChildElementXmlStringBuilder xml);
|
||||||
|
|
||||||
private HeadersExtension headers;
|
/**
|
||||||
private Data data;
|
* Returns version attribute.
|
||||||
|
*
|
||||||
|
* @return version attribute
|
||||||
|
*/
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
protected String version;
|
/**
|
||||||
|
* Sets version attribute.
|
||||||
|
*
|
||||||
|
* @param version version attribute
|
||||||
|
*/
|
||||||
|
public void setVersion(String version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns string containing xml representation of this object.
|
* Returns Headers element.
|
||||||
*
|
*
|
||||||
* @return xml representation of this object
|
* @return Headers element
|
||||||
*/
|
*/
|
||||||
public String toXML() {
|
public HeadersExtension getHeaders() {
|
||||||
StringBuilder builder = new StringBuilder();
|
return headers;
|
||||||
builder.append(getStartTag());
|
}
|
||||||
builder.append(headers.toXML());
|
|
||||||
builder.append(data.toXML());
|
|
||||||
builder.append(getEndTag());
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns start tag.
|
* Sets Headers element.
|
||||||
*
|
*
|
||||||
* @return start tag
|
* @param headers Headers element
|
||||||
*/
|
*/
|
||||||
protected abstract String getStartTag();
|
public void setHeaders(HeadersExtension headers) {
|
||||||
|
this.headers = headers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns end tag.
|
* Returns Data element.
|
||||||
*
|
*
|
||||||
* @return end tag
|
* @return Data element
|
||||||
*/
|
*/
|
||||||
protected abstract String getEndTag();
|
public Data getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns version attribute.
|
* Sets Data element.
|
||||||
*
|
*
|
||||||
* @return version attribute
|
* @param data Headers element
|
||||||
*/
|
*/
|
||||||
public String getVersion() {
|
public void setData(Data data) {
|
||||||
return version;
|
this.data = data;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets version attribute.
|
|
||||||
*
|
|
||||||
* @param version version attribute
|
|
||||||
*/
|
|
||||||
public void setVersion(String version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns Headers element.
|
|
||||||
*
|
|
||||||
* @return Headers element
|
|
||||||
*/
|
|
||||||
public HeadersExtension getHeaders() {
|
|
||||||
return headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets Headers element.
|
|
||||||
*
|
|
||||||
* @param headers Headers element
|
|
||||||
*/
|
|
||||||
public void setHeaders(HeadersExtension headers) {
|
|
||||||
this.headers = headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns Data element.
|
|
||||||
*
|
|
||||||
* @return Data element
|
|
||||||
*/
|
|
||||||
public Data getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets Data element.
|
|
||||||
*
|
|
||||||
* @param data Headers element
|
|
||||||
*/
|
|
||||||
public void setData(Data data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,14 +115,14 @@ public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
*/
|
*/
|
||||||
public static class Data {
|
public static class Data {
|
||||||
|
|
||||||
private final DataChild child;
|
private final NamedElement child;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates Data element.
|
* Creates Data element.
|
||||||
*
|
*
|
||||||
* @param child element nested by Data
|
* @param child element nested by Data
|
||||||
*/
|
*/
|
||||||
public Data(DataChild child) {
|
public Data(NamedElement child) {
|
||||||
this.child = child;
|
this.child = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,29 +144,18 @@ public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
*
|
*
|
||||||
* @return element nested by Data
|
* @return element nested by Data
|
||||||
*/
|
*/
|
||||||
public DataChild getChild() {
|
public NamedElement getChild() {
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for child elements of Data element.
|
|
||||||
*/
|
|
||||||
public static interface DataChild {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns string containing xml representation of this object.
|
|
||||||
*
|
|
||||||
* @return xml representation of this object
|
|
||||||
*/
|
|
||||||
public String toXML();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representation of Text element.<p>
|
* Representation of Text element.<p>
|
||||||
* This class is immutable.
|
* This class is immutable.
|
||||||
*/
|
*/
|
||||||
public static class Text implements DataChild {
|
public static class Text implements NamedElement {
|
||||||
|
|
||||||
|
public static final String ELEMENT = "text";
|
||||||
|
|
||||||
private final String text;
|
private final String text;
|
||||||
|
|
||||||
|
@ -191,14 +169,12 @@ public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toXML() {
|
public XmlStringBuilder toXML() {
|
||||||
StringBuilder builder = new StringBuilder();
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||||
builder.append("<text>");
|
xml.rightAngleBracket();
|
||||||
if (text != null) {
|
xml.optAppend(text);
|
||||||
builder.append(text);
|
xml.closeElement(this);
|
||||||
}
|
return xml;
|
||||||
builder.append("</text>");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -209,13 +185,20 @@ public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
public String getText() {
|
public String getText() {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementName() {
|
||||||
|
return ELEMENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representation of Base64 element.<p>
|
* Representation of Base64 element.<p>
|
||||||
* This class is immutable.
|
* This class is immutable.
|
||||||
*/
|
*/
|
||||||
public static class Base64 implements DataChild {
|
public static class Base64 implements NamedElement {
|
||||||
|
|
||||||
|
public static final String ELEMENT = "base64";
|
||||||
|
|
||||||
private final String text;
|
private final String text;
|
||||||
|
|
||||||
|
@ -229,14 +212,12 @@ public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toXML() {
|
public XmlStringBuilder toXML() {
|
||||||
StringBuilder builder = new StringBuilder();
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||||
builder.append("<base64>");
|
xml.rightAngleBracket();
|
||||||
if (text != null) {
|
xml.optAppend(text);
|
||||||
builder.append(text);
|
xml.closeElement(this);
|
||||||
}
|
return xml;
|
||||||
builder.append("</base64>");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -247,18 +228,25 @@ public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
public String getText() {
|
public String getText() {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementName() {
|
||||||
|
return ELEMENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representation of Xml element.<p>
|
* Representation of Xml element.<p>
|
||||||
* This class is immutable.
|
* This class is immutable.
|
||||||
*/
|
*/
|
||||||
public static class Xml implements DataChild {
|
public static class Xml implements NamedElement {
|
||||||
|
|
||||||
|
public static final String ELEMENT = "xml";
|
||||||
|
|
||||||
private final String text;
|
private final String text;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates this element.
|
* Creates this element.builder.toString();
|
||||||
*
|
*
|
||||||
* @param text value of text
|
* @param text value of text
|
||||||
*/
|
*/
|
||||||
|
@ -267,14 +255,12 @@ public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toXML() {
|
public XmlStringBuilder toXML() {
|
||||||
StringBuilder builder = new StringBuilder();
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||||
builder.append("<xml>");
|
xml.rightAngleBracket();
|
||||||
if (text != null) {
|
xml.optAppend(text);
|
||||||
builder.append(text);
|
xml.closeElement(this);
|
||||||
}
|
return xml;
|
||||||
builder.append("</xml>");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -285,13 +271,20 @@ public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
public String getText() {
|
public String getText() {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementName() {
|
||||||
|
return ELEMENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representation of ChunkedBase64 element.<p>
|
* Representation of ChunkedBase64 element.<p>
|
||||||
* This class is immutable.
|
* This class is immutable.
|
||||||
*/
|
*/
|
||||||
public static class ChunkedBase64 implements DataChild {
|
public static class ChunkedBase64 implements NamedElement {
|
||||||
|
|
||||||
|
public static final String ELEMENT = "chunkedBase64";
|
||||||
|
|
||||||
private final String streamId;
|
private final String streamId;
|
||||||
|
|
||||||
|
@ -305,12 +298,11 @@ public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toXML() {
|
public XmlStringBuilder toXML() {
|
||||||
StringBuilder builder = new StringBuilder();
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||||
builder.append("<chunkedBase64 streamId='");
|
xml.attribute("streamId", streamId);
|
||||||
builder.append(streamId);
|
xml.closeEmptyElement();
|
||||||
builder.append("'/>");
|
return xml;
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -321,13 +313,20 @@ public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
public String getStreamId() {
|
public String getStreamId() {
|
||||||
return streamId;
|
return streamId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementName() {
|
||||||
|
return ELEMENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Representation of Ibb element.<p>
|
* Representation of Ibb element.<p>
|
||||||
* This class is immutable.
|
* This class is immutable.
|
||||||
*/
|
*/
|
||||||
public static class Ibb implements DataChild {
|
public static class Ibb implements NamedElement {
|
||||||
|
|
||||||
|
public static final String ELEMENT = "ibb";
|
||||||
|
|
||||||
private final String sid;
|
private final String sid;
|
||||||
|
|
||||||
|
@ -341,12 +340,11 @@ public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toXML() {
|
public XmlStringBuilder toXML() {
|
||||||
StringBuilder builder = new StringBuilder();
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||||
builder.append("<ibb sid='");
|
xml.attribute("sid", sid);
|
||||||
builder.append(sid);
|
xml.closeEmptyElement();
|
||||||
builder.append("'/>");
|
return xml;
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -357,5 +355,10 @@ public abstract class AbstractHttpOverXmpp extends IQ {
|
||||||
public String getSid() {
|
public String getSid() {
|
||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementName() {
|
||||||
|
return ELEMENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package org.jivesoftware.smackx.hoxt.packet;
|
package org.jivesoftware.smackx.hoxt.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jivesoftware.smackx.hoxt.HOXTManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents Req IQ packet.
|
* Represents Req IQ packet.
|
||||||
|
@ -27,177 +26,136 @@ import org.jivesoftware.smackx.hoxt.HOXTManager;
|
||||||
*/
|
*/
|
||||||
public class HttpOverXmppReq extends AbstractHttpOverXmpp {
|
public class HttpOverXmppReq extends AbstractHttpOverXmpp {
|
||||||
|
|
||||||
private Req req;
|
public static final String ELEMENT = "req";
|
||||||
|
|
||||||
|
|
||||||
|
public HttpOverXmppReq(HttpMethod method, String resource) {
|
||||||
|
super(ELEMENT);
|
||||||
|
this.method = method;
|
||||||
|
this.resource = resource;
|
||||||
|
type = Type.set;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpMethod method;
|
||||||
|
private String resource;
|
||||||
|
|
||||||
|
// TODO: validate: xs:minInclusive value='256' xs:maxInclusive value='65536'
|
||||||
|
private int maxChunkSize = 0; // 0 means not set
|
||||||
|
|
||||||
|
private boolean sipub = true;
|
||||||
|
|
||||||
|
private boolean ibb = true;
|
||||||
|
private boolean jingle = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQHoxtChildElementBuilder(IQChildElementXmlStringBuilder builder) {
|
||||||
return req.toXML();
|
builder.append(" ");
|
||||||
|
builder.append("method='").append(method.toString()).append("'");
|
||||||
|
builder.append(" ");
|
||||||
|
builder.append("resource='").append(StringUtils.escapeForXML(resource)).append("'");
|
||||||
|
builder.append(" ");
|
||||||
|
builder.append("version='").append(StringUtils.escapeForXML(version)).append("'");
|
||||||
|
if (maxChunkSize != 0) {
|
||||||
|
builder.append(" ");
|
||||||
|
builder.append("maxChunkSize='").append(Integer.toString(maxChunkSize)).append("'");
|
||||||
|
}
|
||||||
|
builder.append(" ");
|
||||||
|
builder.append("sipub='").append(Boolean.toString(sipub)).append("'");
|
||||||
|
builder.append(" ");
|
||||||
|
builder.append("ibb='").append(Boolean.toString(ibb)).append("'");
|
||||||
|
builder.append(" ");
|
||||||
|
builder.append("jingle='").append(Boolean.toString(jingle)).append("'");
|
||||||
|
builder.append(">");
|
||||||
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns Req element.
|
* Returns method attribute.
|
||||||
*
|
*
|
||||||
* @return Req element
|
* @return method attribute
|
||||||
*/
|
*/
|
||||||
public Req getReq() {
|
public HttpMethod getMethod() {
|
||||||
return req;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Req element.
|
* Returns resource attribute.
|
||||||
*
|
*
|
||||||
* @param req Req element
|
* @return resource attribute
|
||||||
*/
|
*/
|
||||||
public void setReq(Req req) {
|
public String getResource() {
|
||||||
this.req = req;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents Req element.
|
* Returns maxChunkSize attribute.
|
||||||
|
*
|
||||||
|
* @return maxChunkSize attribute
|
||||||
*/
|
*/
|
||||||
public static class Req extends AbstractBody {
|
public int getMaxChunkSize() {
|
||||||
|
return maxChunkSize;
|
||||||
|
}
|
||||||
|
|
||||||
private HttpMethod method;
|
/**
|
||||||
private String resource;
|
* Sets maxChunkSize attribute.
|
||||||
|
*
|
||||||
|
* @param maxChunkSize maxChunkSize attribute
|
||||||
|
*/
|
||||||
|
public void setMaxChunkSize(int maxChunkSize) {
|
||||||
|
this.maxChunkSize = maxChunkSize;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: validate: xs:minInclusive value='256' xs:maxInclusive value='65536'
|
/**
|
||||||
private int maxChunkSize = 0; // 0 means not set
|
* Returns sipub attribute.
|
||||||
|
*
|
||||||
|
* @return sipub attribute
|
||||||
|
*/
|
||||||
|
public boolean isSipub() {
|
||||||
|
return sipub;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean sipub = true;
|
/**
|
||||||
|
* Sets sipub attribute.
|
||||||
|
*
|
||||||
|
* @param sipub sipub attribute
|
||||||
|
*/
|
||||||
|
public void setSipub(boolean sipub) {
|
||||||
|
this.sipub = sipub;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean ibb = true;
|
/**
|
||||||
private boolean jingle = true;
|
* Returns ibb attribute.
|
||||||
|
*
|
||||||
|
* @return ibb attribute
|
||||||
|
*/
|
||||||
|
public boolean isIbb() {
|
||||||
|
return ibb;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates this object.
|
* Sets ibb attribute.
|
||||||
*
|
*
|
||||||
* @param method method attribute
|
* @param ibb ibb attribute
|
||||||
* @param resource resource attribute
|
*/
|
||||||
*/
|
public void setIbb(boolean ibb) {
|
||||||
public Req(HttpMethod method, String resource) {
|
this.ibb = ibb;
|
||||||
this.method = method;
|
}
|
||||||
this.resource = resource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
protected String getStartTag() {
|
* Returns jingle attribute.
|
||||||
StringBuilder builder = new StringBuilder();
|
*
|
||||||
builder.append("<req");
|
* @return jingle attribute
|
||||||
builder.append(" ");
|
*/
|
||||||
builder.append("xmlns='").append(HOXTManager.NAMESPACE).append("'");
|
public boolean isJingle() {
|
||||||
builder.append(" ");
|
return jingle;
|
||||||
builder.append("method='").append(method.toString()).append("'");
|
}
|
||||||
builder.append(" ");
|
|
||||||
builder.append("resource='").append(StringUtils.escapeForXML(resource)).append("'");
|
|
||||||
builder.append(" ");
|
|
||||||
builder.append("version='").append(StringUtils.escapeForXML(version)).append("'");
|
|
||||||
if (maxChunkSize != 0) {
|
|
||||||
builder.append(" ");
|
|
||||||
builder.append("maxChunkSize='").append(Integer.toString(maxChunkSize)).append("'");
|
|
||||||
}
|
|
||||||
builder.append(" ");
|
|
||||||
builder.append("sipub='").append(Boolean.toString(sipub)).append("'");
|
|
||||||
builder.append(" ");
|
|
||||||
builder.append("ibb='").append(Boolean.toString(ibb)).append("'");
|
|
||||||
builder.append(" ");
|
|
||||||
builder.append("jingle='").append(Boolean.toString(jingle)).append("'");
|
|
||||||
builder.append(">");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
protected String getEndTag() {
|
* Sets jingle attribute.
|
||||||
return "</req>";
|
*
|
||||||
}
|
* @param jingle jingle attribute
|
||||||
|
*/
|
||||||
/**
|
public void setJingle(boolean jingle) {
|
||||||
* Returns method attribute.
|
this.jingle = jingle;
|
||||||
*
|
|
||||||
* @return method attribute
|
|
||||||
*/
|
|
||||||
public HttpMethod getMethod() {
|
|
||||||
return method;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns resource attribute.
|
|
||||||
*
|
|
||||||
* @return resource attribute
|
|
||||||
*/
|
|
||||||
public String getResource() {
|
|
||||||
return resource;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns maxChunkSize attribute.
|
|
||||||
*
|
|
||||||
* @return maxChunkSize attribute
|
|
||||||
*/
|
|
||||||
public int getMaxChunkSize() {
|
|
||||||
return maxChunkSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets maxChunkSize attribute.
|
|
||||||
*
|
|
||||||
* @param maxChunkSize maxChunkSize attribute
|
|
||||||
*/
|
|
||||||
public void setMaxChunkSize(int maxChunkSize) {
|
|
||||||
this.maxChunkSize = maxChunkSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns sipub attribute.
|
|
||||||
*
|
|
||||||
* @return sipub attribute
|
|
||||||
*/
|
|
||||||
public boolean isSipub() {
|
|
||||||
return sipub;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets sipub attribute.
|
|
||||||
*
|
|
||||||
* @param sipub sipub attribute
|
|
||||||
*/
|
|
||||||
public void setSipub(boolean sipub) {
|
|
||||||
this.sipub = sipub;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns ibb attribute.
|
|
||||||
*
|
|
||||||
* @return ibb attribute
|
|
||||||
*/
|
|
||||||
public boolean isIbb() {
|
|
||||||
return ibb;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets ibb attribute.
|
|
||||||
*
|
|
||||||
* @param ibb ibb attribute
|
|
||||||
*/
|
|
||||||
public void setIbb(boolean ibb) {
|
|
||||||
this.ibb = ibb;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns jingle attribute.
|
|
||||||
*
|
|
||||||
* @return jingle attribute
|
|
||||||
*/
|
|
||||||
public boolean isJingle() {
|
|
||||||
return jingle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets jingle attribute.
|
|
||||||
*
|
|
||||||
* @param jingle jingle attribute
|
|
||||||
*/
|
|
||||||
public void setJingle(boolean jingle) {
|
|
||||||
this.jingle = jingle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package org.jivesoftware.smackx.hoxt.packet;
|
package org.jivesoftware.smackx.hoxt.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jivesoftware.smackx.hoxt.HOXTManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents Resp IQ packet.
|
* Represents Resp IQ packet.
|
||||||
|
@ -27,96 +26,63 @@ import org.jivesoftware.smackx.hoxt.HOXTManager;
|
||||||
*/
|
*/
|
||||||
public class HttpOverXmppResp extends AbstractHttpOverXmpp {
|
public class HttpOverXmppResp extends AbstractHttpOverXmpp {
|
||||||
|
|
||||||
private Resp resp;
|
public static final String ELEMENT = "resp";
|
||||||
|
|
||||||
|
|
||||||
|
public HttpOverXmppResp() {
|
||||||
|
super(ELEMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int statusCode;
|
||||||
|
private String statusMessage = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQHoxtChildElementBuilder(IQChildElementXmlStringBuilder builder) {
|
||||||
return resp.toXML();
|
builder.append(" ");
|
||||||
|
builder.append("version='").append(StringUtils.escapeForXML(version)).append("'");
|
||||||
|
builder.append(" ");
|
||||||
|
builder.append("statusCode='").append(Integer.toString(statusCode)).append("'");
|
||||||
|
if (statusMessage != null) {
|
||||||
|
builder.append(" ");
|
||||||
|
builder.append("statusMessage='").append(StringUtils.escapeForXML(statusMessage)).append("'");
|
||||||
|
}
|
||||||
|
builder.append(">");
|
||||||
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns Resp element.
|
* Returns statusCode attribute.
|
||||||
*
|
*
|
||||||
* @return Resp element
|
* @return statusCode attribute
|
||||||
*/
|
*/
|
||||||
public Resp getResp() {
|
public int getStatusCode() {
|
||||||
return resp;
|
return statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Resp element.
|
* Sets statusCode attribute.
|
||||||
*
|
*
|
||||||
* @param resp Resp element
|
* @param statusCode statusCode attribute
|
||||||
*/
|
*/
|
||||||
public void setResp(Resp resp) {
|
public void setStatusCode(int statusCode) {
|
||||||
this.resp = resp;
|
this.statusCode = statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents Resp element.
|
* Returns statusMessage attribute.
|
||||||
|
*
|
||||||
|
* @return statusMessage attribute
|
||||||
*/
|
*/
|
||||||
public static class Resp extends AbstractBody {
|
public String getStatusMessage() {
|
||||||
|
return statusMessage;
|
||||||
|
}
|
||||||
|
|
||||||
private int statusCode;
|
/**
|
||||||
private String statusMessage = null;
|
* Sets statusMessage attribute.
|
||||||
|
*
|
||||||
@Override
|
* @param statusMessage statusMessage attribute
|
||||||
protected String getStartTag() {
|
*/
|
||||||
StringBuilder builder = new StringBuilder();
|
public void setStatusMessage(String statusMessage) {
|
||||||
builder.append("<resp");
|
this.statusMessage = statusMessage;
|
||||||
builder.append(" ");
|
|
||||||
builder.append("xmlns='").append(HOXTManager.NAMESPACE).append("'");
|
|
||||||
builder.append(" ");
|
|
||||||
builder.append("version='").append(StringUtils.escapeForXML(version)).append("'");
|
|
||||||
builder.append(" ");
|
|
||||||
builder.append("statusCode='").append(Integer.toString(statusCode)).append("'");
|
|
||||||
if (statusMessage != null) {
|
|
||||||
builder.append(" ");
|
|
||||||
builder.append("statusMessage='").append(StringUtils.escapeForXML(statusMessage)).append("'");
|
|
||||||
}
|
|
||||||
builder.append(">");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getEndTag() {
|
|
||||||
return "</resp>";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns statusCode attribute.
|
|
||||||
*
|
|
||||||
* @return statusCode attribute
|
|
||||||
*/
|
|
||||||
public int getStatusCode() {
|
|
||||||
return statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets statusCode attribute.
|
|
||||||
*
|
|
||||||
* @param statusCode statusCode attribute
|
|
||||||
*/
|
|
||||||
public void setStatusCode(int statusCode) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns statusMessage attribute.
|
|
||||||
*
|
|
||||||
* @return statusMessage attribute
|
|
||||||
*/
|
|
||||||
public String getStatusMessage() {
|
|
||||||
return statusMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets statusMessage attribute.
|
|
||||||
*
|
|
||||||
* @param statusMessage statusMessage attribute
|
|
||||||
*/
|
|
||||||
public void setStatusMessage(String statusMessage) {
|
|
||||||
this.statusMessage = statusMessage;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.jivesoftware.smackx.hoxt.provider;
|
package org.jivesoftware.smackx.hoxt.provider;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
|
import org.jivesoftware.smack.packet.NamedElement;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp;
|
import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp;
|
||||||
|
@ -63,7 +64,7 @@ public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmp
|
||||||
* @throws XmlPullParserException
|
* @throws XmlPullParserException
|
||||||
* @throws SmackException
|
* @throws SmackException
|
||||||
*/
|
*/
|
||||||
protected void parseHeadersAndData(XmlPullParser parser, String elementName, AbstractHttpOverXmpp.AbstractBody body) throws XmlPullParserException, IOException, SmackException {
|
protected void parseHeadersAndData(XmlPullParser parser, String elementName, AbstractHttpOverXmpp body) throws XmlPullParserException, IOException, SmackException {
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
|
@ -110,7 +111,7 @@ public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmp
|
||||||
}
|
}
|
||||||
|
|
||||||
private AbstractHttpOverXmpp.Data parseData(XmlPullParser parser) throws XmlPullParserException, IOException {
|
private AbstractHttpOverXmpp.Data parseData(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||||
AbstractHttpOverXmpp.DataChild child = null;
|
NamedElement child = null;
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
|
|
|
@ -32,18 +32,10 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||||
*/
|
*/
|
||||||
public class HttpOverXmppReqProvider extends AbstractHttpOverXmppProvider<HttpOverXmppReq> {
|
public class HttpOverXmppReqProvider extends AbstractHttpOverXmppProvider<HttpOverXmppReq> {
|
||||||
|
|
||||||
private static final String ELEMENT_REQ = "req";
|
|
||||||
|
|
||||||
private static final String ATTRIBUTE_METHOD = "method";
|
private static final String ATTRIBUTE_METHOD = "method";
|
||||||
private static final String ATTRIBUTE_RESOURCE = "resource";
|
private static final String ATTRIBUTE_RESOURCE = "resource";
|
||||||
private static final String ATTRIBUTE_MAX_CHUNK_SIZE = "maxChunkSize";
|
private static final String ATTRIBUTE_MAX_CHUNK_SIZE = "maxChunkSize";
|
||||||
|
|
||||||
/**
|
|
||||||
* Mandatory no argument constructor.
|
|
||||||
*/
|
|
||||||
public HttpOverXmppReqProvider() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpOverXmppReq parse(XmlPullParser parser, int initialDepth)
|
public HttpOverXmppReq parse(XmlPullParser parser, int initialDepth)
|
||||||
throws XmlPullParserException, IOException, SmackException {
|
throws XmlPullParserException, IOException, SmackException {
|
||||||
|
@ -53,7 +45,7 @@ public class HttpOverXmppReqProvider extends AbstractHttpOverXmppProvider<HttpOv
|
||||||
String maxChunkSize = parser.getAttributeValue("", ATTRIBUTE_MAX_CHUNK_SIZE);
|
String maxChunkSize = parser.getAttributeValue("", ATTRIBUTE_MAX_CHUNK_SIZE);
|
||||||
|
|
||||||
HttpMethod reqMethod = HttpMethod.valueOf(method);
|
HttpMethod reqMethod = HttpMethod.valueOf(method);
|
||||||
HttpOverXmppReq.Req req = new HttpOverXmppReq.Req(reqMethod, resource);
|
HttpOverXmppReq req = new HttpOverXmppReq(reqMethod, resource);
|
||||||
req.setVersion(version);
|
req.setVersion(version);
|
||||||
|
|
||||||
Boolean sipub = true;
|
Boolean sipub = true;
|
||||||
|
@ -83,9 +75,7 @@ public class HttpOverXmppReqProvider extends AbstractHttpOverXmppProvider<HttpOv
|
||||||
req.setMaxChunkSize(maxChunkSizeValue);
|
req.setMaxChunkSize(maxChunkSizeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
parseHeadersAndData(parser, ELEMENT_REQ, req);
|
parseHeadersAndData(parser, HttpOverXmppReq.ELEMENT, req);
|
||||||
HttpOverXmppReq packet = new HttpOverXmppReq();
|
return req;
|
||||||
packet.setReq(req);
|
|
||||||
return packet;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,6 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||||
*/
|
*/
|
||||||
public class HttpOverXmppRespProvider extends AbstractHttpOverXmppProvider<HttpOverXmppResp> {
|
public class HttpOverXmppRespProvider extends AbstractHttpOverXmppProvider<HttpOverXmppResp> {
|
||||||
|
|
||||||
private static final String ELEMENT_RESP = "resp";
|
|
||||||
|
|
||||||
private static final String ATTRIBUTE_STATUS_MESSAGE = "statusMessage";
|
private static final String ATTRIBUTE_STATUS_MESSAGE = "statusMessage";
|
||||||
private static final String ATTRIBUTE_STATUS_CODE = "statusCode";
|
private static final String ATTRIBUTE_STATUS_CODE = "statusCode";
|
||||||
|
|
||||||
|
@ -44,15 +42,12 @@ public class HttpOverXmppRespProvider extends AbstractHttpOverXmppProvider<HttpO
|
||||||
String statusCodeString = parser.getAttributeValue("", ATTRIBUTE_STATUS_CODE);
|
String statusCodeString = parser.getAttributeValue("", ATTRIBUTE_STATUS_CODE);
|
||||||
int statusCode = Integer.parseInt(statusCodeString);
|
int statusCode = Integer.parseInt(statusCodeString);
|
||||||
|
|
||||||
HttpOverXmppResp.Resp resp = new HttpOverXmppResp.Resp();
|
HttpOverXmppResp resp = new HttpOverXmppResp();
|
||||||
|
|
||||||
resp.setVersion(version);
|
resp.setVersion(version);
|
||||||
resp.setStatusMessage(statusMessage);
|
resp.setStatusMessage(statusMessage);
|
||||||
resp.setStatusCode(statusCode);
|
resp.setStatusCode(statusCode);
|
||||||
|
parseHeadersAndData(parser, HttpOverXmppResp.ELEMENT, resp);
|
||||||
parseHeadersAndData(parser, ELEMENT_RESP, resp);
|
return resp;
|
||||||
|
|
||||||
HttpOverXmppResp packet = new HttpOverXmppResp();
|
|
||||||
packet.setResp(resp);
|
|
||||||
return packet;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class AbstractHttpOverXmppProviderTest {
|
||||||
|
|
||||||
IQ iq = provider.parse(parser);
|
IQ iq = provider.parse(parser);
|
||||||
assertTrue(iq instanceof HttpOverXmppResp);
|
assertTrue(iq instanceof HttpOverXmppResp);
|
||||||
AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppResp) iq).getResp();
|
HttpOverXmppResp body = ((HttpOverXmppResp) iq);
|
||||||
|
|
||||||
checkHeaders(body.getHeaders(), expectedHeaders);
|
checkHeaders(body.getHeaders(), expectedHeaders);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public class AbstractHttpOverXmppProviderTest {
|
||||||
|
|
||||||
IQ iq = provider.parse(parser);
|
IQ iq = provider.parse(parser);
|
||||||
assertTrue(iq instanceof HttpOverXmppReq);
|
assertTrue(iq instanceof HttpOverXmppReq);
|
||||||
AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppReq) iq).getReq();
|
HttpOverXmppReq body = ((HttpOverXmppReq) iq);
|
||||||
|
|
||||||
checkHeaders(body.getHeaders(), expectedHeaders);
|
checkHeaders(body.getHeaders(), expectedHeaders);
|
||||||
}
|
}
|
||||||
|
@ -180,14 +180,14 @@ public class AbstractHttpOverXmppProviderTest {
|
||||||
assertEquals(sid, ibbValue.getSid());
|
assertEquals(sid, ibbValue.getSid());
|
||||||
}
|
}
|
||||||
|
|
||||||
private AbstractHttpOverXmpp.AbstractBody parseAbstractBody(String string, String tag) throws Exception {
|
// TODO The method name makes no sense after the HOXT re-design, change to parseHttpOverXmppResp()
|
||||||
|
private HttpOverXmppResp parseAbstractBody(String string, String tag) throws Exception {
|
||||||
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
|
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
|
||||||
XmlPullParser parser = PacketParserUtils.getParserFor(string, tag);
|
XmlPullParser parser = PacketParserUtils.getParserFor(string, tag);
|
||||||
|
|
||||||
IQ iq = provider.parse(parser);
|
IQ iq = provider.parse(parser);
|
||||||
assertTrue(iq instanceof HttpOverXmppResp);
|
assertTrue(iq instanceof HttpOverXmppResp);
|
||||||
AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppResp) iq).getResp();
|
return (HttpOverXmppResp) iq;
|
||||||
return body;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkHeaders(HeadersExtension headers, Map<String, String> expectedHeaders) {
|
private void checkHeaders(HeadersExtension headers, Map<String, String> expectedHeaders) {
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class HttpOverXmppReqProviderTest {
|
||||||
@Test
|
@Test
|
||||||
public void areAllReqAttributesCorrectlyParsed() throws Exception {
|
public void areAllReqAttributesCorrectlyParsed() throws Exception {
|
||||||
String string = "<req xmlns='urn:xmpp:http' method='OPTIONS' resource='*' version='1.1'/>";
|
String string = "<req xmlns='urn:xmpp:http' method='OPTIONS' resource='*' version='1.1'/>";
|
||||||
HttpOverXmppReq.Req req = parseReq(string);
|
HttpOverXmppReq req = parseReq(string);
|
||||||
assertEquals(req.getVersion(), "1.1");
|
assertEquals(req.getVersion(), "1.1");
|
||||||
assertEquals(req.getMethod(), HttpMethod.OPTIONS);
|
assertEquals(req.getMethod(), HttpMethod.OPTIONS);
|
||||||
assertEquals(req.getResource(), "*");
|
assertEquals(req.getResource(), "*");
|
||||||
|
@ -40,7 +40,7 @@ public class HttpOverXmppReqProviderTest {
|
||||||
@Test
|
@Test
|
||||||
public void areGetRequestAttributesCorrectlyParsed() throws Exception {
|
public void areGetRequestAttributesCorrectlyParsed() throws Exception {
|
||||||
String string = "<req xmlns='urn:xmpp:http' method='GET' resource='/rdf/xep' version='1.1'/>";
|
String string = "<req xmlns='urn:xmpp:http' method='GET' resource='/rdf/xep' version='1.1'/>";
|
||||||
HttpOverXmppReq.Req req = parseReq(string);
|
HttpOverXmppReq req = parseReq(string);
|
||||||
assertEquals(req.getVersion(), "1.1");
|
assertEquals(req.getVersion(), "1.1");
|
||||||
assertEquals(req.getMethod(), HttpMethod.GET);
|
assertEquals(req.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(req.getResource(), "/rdf/xep");
|
assertEquals(req.getResource(), "/rdf/xep");
|
||||||
|
@ -49,7 +49,7 @@ public class HttpOverXmppReqProviderTest {
|
||||||
@Test
|
@Test
|
||||||
public void getReqOptionAttributesCorrectlyParsed() throws Exception {
|
public void getReqOptionAttributesCorrectlyParsed() throws Exception {
|
||||||
String string = "<req xmlns='urn:xmpp:http' method='OPTIONS' resource='*' version='1.1' maxChunkSize='256' sipub='false' ibb='true' jingle='false'/>";
|
String string = "<req xmlns='urn:xmpp:http' method='OPTIONS' resource='*' version='1.1' maxChunkSize='256' sipub='false' ibb='true' jingle='false'/>";
|
||||||
HttpOverXmppReq.Req req = parseReq(string);
|
HttpOverXmppReq req = parseReq(string);
|
||||||
assertEquals(req.getMaxChunkSize(), 256);
|
assertEquals(req.getMaxChunkSize(), 256);
|
||||||
assertEquals(req.isSipub(), false);
|
assertEquals(req.isSipub(), false);
|
||||||
assertEquals(req.isIbb(), true);
|
assertEquals(req.isIbb(), true);
|
||||||
|
@ -59,18 +59,18 @@ public class HttpOverXmppReqProviderTest {
|
||||||
@Test
|
@Test
|
||||||
public void getReqOptionalAttributesDefaultValues() throws Exception {
|
public void getReqOptionalAttributesDefaultValues() throws Exception {
|
||||||
String string = "<req xmlns='urn:xmpp:http' method='OPTIONS' resource='*' version='1.1'/>";
|
String string = "<req xmlns='urn:xmpp:http' method='OPTIONS' resource='*' version='1.1'/>";
|
||||||
HttpOverXmppReq.Req req = parseReq(string);
|
HttpOverXmppReq req = parseReq(string);
|
||||||
assertEquals(req.isSipub(), true);
|
assertEquals(req.isSipub(), true);
|
||||||
assertEquals(req.isIbb(), true);
|
assertEquals(req.isIbb(), true);
|
||||||
assertEquals(req.isJingle(), true);
|
assertEquals(req.isJingle(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpOverXmppReq.Req parseReq(String string) throws Exception {
|
private HttpOverXmppReq parseReq(String string) throws Exception {
|
||||||
HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider();
|
HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider();
|
||||||
XmlPullParser parser = PacketParserUtils.getParserFor(string);
|
XmlPullParser parser = PacketParserUtils.getParserFor(string);
|
||||||
IQ iq = provider.parse(parser);
|
IQ iq = provider.parse(parser);
|
||||||
assertTrue(iq instanceof HttpOverXmppReq);
|
assertTrue(iq instanceof HttpOverXmppReq);
|
||||||
HttpOverXmppReq castedIq = (HttpOverXmppReq) iq;
|
HttpOverXmppReq castedIq = (HttpOverXmppReq) iq;
|
||||||
return castedIq.getReq();
|
return castedIq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,7 @@ public class HttpOverXmppRespProviderTest {
|
||||||
|
|
||||||
IQ iq = provider.parse(parser);
|
IQ iq = provider.parse(parser);
|
||||||
assertTrue(iq instanceof HttpOverXmppResp);
|
assertTrue(iq instanceof HttpOverXmppResp);
|
||||||
HttpOverXmppResp castedIq = (HttpOverXmppResp) iq;
|
HttpOverXmppResp resp = (HttpOverXmppResp) iq;
|
||||||
HttpOverXmppResp.Resp resp = castedIq.getResp();
|
|
||||||
|
|
||||||
assertEquals(resp.getVersion(), "1.1");
|
assertEquals(resp.getVersion(), "1.1");
|
||||||
assertEquals(resp.getStatusCode(), 200);
|
assertEquals(resp.getStatusCode(), 200);
|
||||||
|
@ -55,8 +54,7 @@ public class HttpOverXmppRespProviderTest {
|
||||||
|
|
||||||
IQ iq = provider.parse(parser);
|
IQ iq = provider.parse(parser);
|
||||||
assertTrue(iq instanceof HttpOverXmppResp);
|
assertTrue(iq instanceof HttpOverXmppResp);
|
||||||
HttpOverXmppResp castedIq = (HttpOverXmppResp) iq;
|
HttpOverXmppResp resp = (HttpOverXmppResp) iq;
|
||||||
HttpOverXmppResp.Resp resp = castedIq.getResp();
|
|
||||||
|
|
||||||
assertEquals(resp.getVersion(), "1.1");
|
assertEquals(resp.getVersion(), "1.1");
|
||||||
assertEquals(resp.getStatusCode(), 200);
|
assertEquals(resp.getStatusCode(), 200);
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||||
|
@ -450,9 +449,7 @@ public class InBandBytestreamSession implements BytestreamSession {
|
||||||
|
|
||||||
public void processPacket(Packet packet) throws NotConnectedException {
|
public void processPacket(Packet packet) throws NotConnectedException {
|
||||||
// get data packet extension
|
// get data packet extension
|
||||||
DataPacketExtension data = (DataPacketExtension) packet.getExtension(
|
DataPacketExtension data = ((Data) packet).getDataPacketExtension();
|
||||||
DataPacketExtension.ELEMENT,
|
|
||||||
DataPacketExtension.NAMESPACE);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* check if sequence was not used already (see XEP-0047 Section 2.2)
|
* check if sequence was not used already (see XEP-0047 Section 2.2)
|
||||||
|
@ -562,15 +559,20 @@ public class InBandBytestreamSession implements BytestreamSession {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// stanza contains data packet extension
|
DataPacketExtension data;
|
||||||
PacketExtension packetExtension = packet.getExtension(DataPacketExtension.ELEMENT,
|
if (packet instanceof Data) {
|
||||||
DataPacketExtension.NAMESPACE);
|
data = ((Data) packet).getDataPacketExtension();
|
||||||
if (packetExtension == null || !(packetExtension instanceof DataPacketExtension)) {
|
} else {
|
||||||
return false;
|
// stanza contains data packet extension
|
||||||
|
data = packet.getExtension(
|
||||||
|
DataPacketExtension.ELEMENT,
|
||||||
|
DataPacketExtension.NAMESPACE);
|
||||||
|
if (data == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// session ID equals this session ID
|
// session ID equals this session ID
|
||||||
DataPacketExtension data = (DataPacketExtension) packetExtension;
|
|
||||||
if (!data.getSessionID().equals(byteStreamRequest.getSessionID())) {
|
if (!data.getSessionID().equals(byteStreamRequest.getSessionID())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package org.jivesoftware.smackx.bytestreams.ibb.packet;
|
package org.jivesoftware.smackx.bytestreams.ibb.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a request to close an In-Band Bytestream.
|
* Represents a request to close an In-Band Bytestream.
|
||||||
|
@ -27,6 +26,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
public class Close extends IQ {
|
public class Close extends IQ {
|
||||||
|
|
||||||
public static final String ELEMENT = "close";
|
public static final String ELEMENT = "close";
|
||||||
|
public static final String NAMESPACE = DataPacketExtension.NAMESPACE;
|
||||||
|
|
||||||
/* unique session ID identifying this In-Band Bytestream */
|
/* unique session ID identifying this In-Band Bytestream */
|
||||||
private final String sessionID;
|
private final String sessionID;
|
||||||
|
@ -37,6 +37,7 @@ public class Close extends IQ {
|
||||||
* @param sessionID unique session ID identifying this In-Band Bytestream
|
* @param sessionID unique session ID identifying this In-Band Bytestream
|
||||||
*/
|
*/
|
||||||
public Close(String sessionID) {
|
public Close(String sessionID) {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
if (sessionID == null || "".equals(sessionID)) {
|
if (sessionID == null || "".equals(sessionID)) {
|
||||||
throw new IllegalArgumentException("Session ID must not be null or empty");
|
throw new IllegalArgumentException("Session ID must not be null or empty");
|
||||||
}
|
}
|
||||||
|
@ -54,12 +55,9 @@ public class Close extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
|
||||||
xml.halfOpenElement(ELEMENT);
|
|
||||||
xml.xmlnsAttribute(DataPacketExtension.NAMESPACE);
|
|
||||||
xml.attribute("sid", sessionID);
|
xml.attribute("sid", sessionID);
|
||||||
xml.closeEmptyElement();
|
xml.setEmptyElement();
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package org.jivesoftware.smackx.bytestreams.ibb.packet;
|
package org.jivesoftware.smackx.bytestreams.ibb.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a chunk of data sent over an In-Band Bytestream encapsulated in an
|
* Represents a chunk of data sent over an In-Band Bytestream encapsulated in an
|
||||||
|
@ -36,24 +35,17 @@ public class Data extends IQ {
|
||||||
* @param data data packet extension containing the encoded data
|
* @param data data packet extension containing the encoded data
|
||||||
*/
|
*/
|
||||||
public Data(DataPacketExtension data) {
|
public Data(DataPacketExtension data) {
|
||||||
|
super(DataPacketExtension.ELEMENT, DataPacketExtension.NAMESPACE);
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
throw new IllegalArgumentException("Data must not be null");
|
throw new IllegalArgumentException("Data must not be null");
|
||||||
}
|
}
|
||||||
this.dataPacketExtension = data;
|
this.dataPacketExtension = data;
|
||||||
|
|
||||||
/*
|
|
||||||
* also set as packet extension so that data packet extension can be
|
|
||||||
* retrieved from IQ stanza and message stanza in the same way
|
|
||||||
*/
|
|
||||||
addExtension(data);
|
|
||||||
setType(IQ.Type.set);
|
setType(IQ.Type.set);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the data packet extension.
|
* Returns the data packet extension.
|
||||||
* <p>
|
|
||||||
* Convenience method for <code>packet.getExtension("data",
|
|
||||||
* "http://jabber.org/protocol/ibb")</code>.
|
|
||||||
*
|
*
|
||||||
* @return the data packet extension
|
* @return the data packet extension
|
||||||
*/
|
*/
|
||||||
|
@ -62,8 +54,8 @@ public class Data extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
return dataPacketExtension.toXML();
|
return dataPacketExtension.getIQChildElementBuilder(xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.jivesoftware.smackx.bytestreams.ibb.packet;
|
package org.jivesoftware.smackx.bytestreams.ibb.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
|
import org.jivesoftware.smack.packet.IQ.IQChildElementXmlStringBuilder;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||||
|
|
||||||
|
@ -135,13 +136,16 @@ public class DataPacketExtension implements PacketExtension {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder toXML() {
|
public XmlStringBuilder toXML() {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
XmlStringBuilder xml = getIQChildElementBuilder(new IQChildElementXmlStringBuilder(this));
|
||||||
xml.attribute("seq", Long.toString(seq));
|
|
||||||
xml.attribute("sid", sessionID);
|
|
||||||
xml.rightAngleBracket();
|
|
||||||
xml.append(data);
|
|
||||||
xml.closeElement(this);
|
xml.closeElement(this);
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
|
xml.attribute("seq", Long.toString(seq));
|
||||||
|
xml.attribute("sid", sessionID);
|
||||||
|
xml.rightAngleBracket();
|
||||||
|
xml.append(data);
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ package org.jivesoftware.smackx.bytestreams.ibb.packet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
import org.jivesoftware.smack.packet.IQ.IQChildElementXmlStringBuilder;
|
||||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType;
|
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +30,7 @@ import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaTyp
|
||||||
public class Open extends IQ {
|
public class Open extends IQ {
|
||||||
|
|
||||||
public static final String ELEMENT = "open";
|
public static final String ELEMENT = "open";
|
||||||
|
public static final String NAMESPACE = DataPacketExtension.NAMESPACE;
|
||||||
|
|
||||||
/* unique session ID identifying this In-Band Bytestream */
|
/* unique session ID identifying this In-Band Bytestream */
|
||||||
private final String sessionID;
|
private final String sessionID;
|
||||||
|
@ -54,6 +55,7 @@ public class Open extends IQ {
|
||||||
* @param stanza stanza type used to encapsulate the data
|
* @param stanza stanza type used to encapsulate the data
|
||||||
*/
|
*/
|
||||||
public Open(String sessionID, int blockSize, StanzaType stanza) {
|
public Open(String sessionID, int blockSize, StanzaType stanza) {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
if (sessionID == null || "".equals(sessionID)) {
|
if (sessionID == null || "".equals(sessionID)) {
|
||||||
throw new IllegalArgumentException("Session ID must not be null or empty");
|
throw new IllegalArgumentException("Session ID must not be null or empty");
|
||||||
}
|
}
|
||||||
|
@ -111,14 +113,11 @@ public class Open extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
|
||||||
xml.halfOpenElement(ELEMENT);
|
|
||||||
xml.xmlnsAttribute(DataPacketExtension.NAMESPACE);
|
|
||||||
xml.attribute("block-size", Integer.toString(blockSize));
|
xml.attribute("block-size", Integer.toString(blockSize));
|
||||||
xml.attribute("sid", sessionID);
|
xml.attribute("sid", sessionID);
|
||||||
xml.attribute("stanza", stanza.toString().toLowerCase(Locale.US));
|
xml.attribute("stanza", stanza.toString().toLowerCase(Locale.US));
|
||||||
xml.closeEmptyElement();
|
xml.setEmptyElement();
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ public class Bytestream extends IQ {
|
||||||
* The default constructor
|
* The default constructor
|
||||||
*/
|
*/
|
||||||
public Bytestream() {
|
public Bytestream() {
|
||||||
|
super(QUERY_ELEMENT, NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,6 +59,7 @@ public class Bytestream extends IQ {
|
||||||
* @see #setSessionID(String)
|
* @see #setSessionID(String)
|
||||||
*/
|
*/
|
||||||
public Bytestream(final String SID) {
|
public Bytestream(final String SID) {
|
||||||
|
this();
|
||||||
setSessionID(SID);
|
setSessionID(SID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,11 +217,7 @@ public class Bytestream extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
|
||||||
xml.halfOpenElement(QUERY_ELEMENT);
|
|
||||||
xml.xmlnsAttribute(NAMESPACE);
|
|
||||||
|
|
||||||
switch(getType()) {
|
switch(getType()) {
|
||||||
case set:
|
case set:
|
||||||
xml.optAttribute("sid", getSessionID());
|
xml.optAttribute("sid", getSessionID());
|
||||||
|
@ -236,25 +234,20 @@ public class Bytestream extends IQ {
|
||||||
break;
|
break;
|
||||||
case result:
|
case result:
|
||||||
xml.rightAngleBracket();
|
xml.rightAngleBracket();
|
||||||
if (getUsedHost() != null) {
|
xml.optAppend(getUsedHost());
|
||||||
xml.append(getUsedHost().toXML());
|
// TODO Bytestream can include either used host *or* streamHosts. Never both. This should be ensured by the
|
||||||
}
|
// constructions mechanisms of Bytestream
|
||||||
// A result from the server can also contain stream hosts
|
// A result from the server can also contain stream hosts
|
||||||
else if (countStreamHosts() > 0) {
|
for (StreamHost host : streamHosts) {
|
||||||
for (StreamHost host : streamHosts) {
|
xml.append(host.toXML());
|
||||||
xml.append(host.toXML());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case get:
|
case get:
|
||||||
xml.closeEmptyElement();
|
xml.setEmptyElement();
|
||||||
// Return here so that we don't run into the
|
break;
|
||||||
// closeElement(QUERY_ELEMNT) section
|
|
||||||
return xml;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
xml.closeElement(QUERY_ELEMENT);
|
|
||||||
|
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.jivesoftware.smackx.commands.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
import org.jivesoftware.smackx.commands.AdHocCommand;
|
import org.jivesoftware.smackx.commands.AdHocCommand;
|
||||||
import org.jivesoftware.smackx.commands.AdHocCommand.Action;
|
import org.jivesoftware.smackx.commands.AdHocCommand.Action;
|
||||||
import org.jivesoftware.smackx.commands.AdHocCommand.SpecificErrorCondition;
|
import org.jivesoftware.smackx.commands.AdHocCommand.SpecificErrorCondition;
|
||||||
|
@ -66,12 +65,11 @@ public class AdHocCommandData extends IQ {
|
||||||
private AdHocCommand.Action executeAction;
|
private AdHocCommand.Action executeAction;
|
||||||
|
|
||||||
public AdHocCommandData() {
|
public AdHocCommandData() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
|
||||||
xml.halfOpenElement(ELEMENT).xmlnsAttribute(NAMESPACE);
|
|
||||||
xml.attribute("node", node);
|
xml.attribute("node", node);
|
||||||
xml.optAttribute("sessionid", sessionID);
|
xml.optAttribute("sessionid", sessionID);
|
||||||
xml.optAttribute("status", status);
|
xml.optAttribute("status", status);
|
||||||
|
@ -108,7 +106,6 @@ public class AdHocCommandData extends IQ {
|
||||||
// buf.append(getError().toXML());
|
// buf.append(getError().toXML());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
xml.closeElement(ELEMENT);
|
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public class DiscoverInfo extends IQ implements Cloneable {
|
public class DiscoverInfo extends IQ implements Cloneable {
|
||||||
|
|
||||||
|
public static final String ELEMENT = QUERY_ELEMENT;
|
||||||
public static final String NAMESPACE = "http://jabber.org/protocol/disco#info";
|
public static final String NAMESPACE = "http://jabber.org/protocol/disco#info";
|
||||||
|
|
||||||
private final List<Feature> features = new LinkedList<Feature>();
|
private final List<Feature> features = new LinkedList<Feature>();
|
||||||
|
@ -50,7 +51,7 @@ public class DiscoverInfo extends IQ implements Cloneable {
|
||||||
private boolean containsDuplicateFeatures;
|
private boolean containsDuplicateFeatures;
|
||||||
|
|
||||||
public DiscoverInfo() {
|
public DiscoverInfo() {
|
||||||
super();
|
super(ELEMENT, NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -212,10 +213,7 @@ public class DiscoverInfo extends IQ implements Cloneable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
|
||||||
xml.halfOpenElement("query");
|
|
||||||
xml.xmlnsAttribute(NAMESPACE);
|
|
||||||
xml.optAttribute("node", getNode());
|
xml.optAttribute("node", getNode());
|
||||||
xml.rightAngleBracket();
|
xml.rightAngleBracket();
|
||||||
for (Identity identity : identities) {
|
for (Identity identity : identities) {
|
||||||
|
@ -224,9 +222,7 @@ public class DiscoverInfo extends IQ implements Cloneable {
|
||||||
for (Feature feature : features) {
|
for (Feature feature : features) {
|
||||||
xml.append(feature.toXML());
|
xml.append(feature.toXML());
|
||||||
}
|
}
|
||||||
// Add packet extensions, if any are defined.
|
|
||||||
xml.append(getExtensionsXML());
|
|
||||||
xml.closeElement("query");
|
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,16 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class DiscoverItems extends IQ {
|
public class DiscoverItems extends IQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = QUERY_ELEMENT;
|
||||||
public static final String NAMESPACE = "http://jabber.org/protocol/disco#items";
|
public static final String NAMESPACE = "http://jabber.org/protocol/disco#items";
|
||||||
|
|
||||||
private final List<Item> items = new LinkedList<Item>();
|
private final List<Item> items = new LinkedList<Item>();
|
||||||
private String node;
|
private String node;
|
||||||
|
|
||||||
|
public DiscoverItems() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new item to the discovered information.
|
* Adds a new item to the discovered information.
|
||||||
*
|
*
|
||||||
|
@ -97,10 +102,8 @@ public class DiscoverItems extends IQ {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmlStringBuilder getChildElementXML() {
|
@Override
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
xml.halfOpenElement("query");
|
|
||||||
xml.xmlnsAttribute(NAMESPACE);
|
|
||||||
xml.optAttribute("node", getNode());
|
xml.optAttribute("node", getNode());
|
||||||
xml.rightAngleBracket();
|
xml.rightAngleBracket();
|
||||||
|
|
||||||
|
@ -108,7 +111,6 @@ public class DiscoverItems extends IQ {
|
||||||
xml.append(item.toXML());
|
xml.append(item.toXML());
|
||||||
}
|
}
|
||||||
|
|
||||||
xml.closeElement("query");
|
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.io.IOException;
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
@ -37,12 +36,14 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||||
*/
|
*/
|
||||||
public class LastActivity extends IQ {
|
public class LastActivity extends IQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = QUERY_ELEMENT;
|
||||||
public static final String NAMESPACE = "jabber:iq:last";
|
public static final String NAMESPACE = "jabber:iq:last";
|
||||||
|
|
||||||
public long lastActivity = -1;
|
public long lastActivity = -1;
|
||||||
public String message;
|
public String message;
|
||||||
|
|
||||||
public LastActivity() {
|
public LastActivity() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
setType(IQ.Type.get);
|
setType(IQ.Type.get);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,15 +53,12 @@ public class LastActivity extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
|
||||||
xml.halfOpenElement(IQ.QUERY_ELEMENT);
|
|
||||||
xml.xmlnsAttribute(NAMESPACE);
|
|
||||||
xml.optLongAttribute("seconds", lastActivity);
|
xml.optLongAttribute("seconds", lastActivity);
|
||||||
|
|
||||||
// We don't support adding the optional message attribute, because it is usually only added
|
// We don't support adding the optional message attribute, because it is usually only added
|
||||||
// by XMPP servers and not by client entities.
|
// by XMPP servers and not by client entities.
|
||||||
xml.closeEmptyElement();
|
xml.setEmptyElement();
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smackx.iqprivate.packet.DefaultPrivateData;
|
import org.jivesoftware.smackx.iqprivate.packet.DefaultPrivateData;
|
||||||
import org.jivesoftware.smackx.iqprivate.packet.PrivateData;
|
import org.jivesoftware.smackx.iqprivate.packet.PrivateData;
|
||||||
|
import org.jivesoftware.smackx.iqprivate.packet.PrivateDataIQ;
|
||||||
import org.jivesoftware.smackx.iqprivate.provider.PrivateDataProvider;
|
import org.jivesoftware.smackx.iqprivate.provider.PrivateDataProvider;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
@ -156,18 +157,9 @@ public class PrivateDataManager extends Manager {
|
||||||
public PrivateData getPrivateData(final String elementName, final String namespace) throws NoResponseException, XMPPErrorException, NotConnectedException
|
public PrivateData getPrivateData(final String elementName, final String namespace) throws NoResponseException, XMPPErrorException, NotConnectedException
|
||||||
{
|
{
|
||||||
// Create an IQ packet to get the private data.
|
// Create an IQ packet to get the private data.
|
||||||
IQ privateDataGet = new IQ() {
|
IQ privateDataGet = new PrivateDataIQ(elementName, namespace);
|
||||||
public String getChildElementXML() {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
buf.append("<query xmlns=\"jabber:iq:private\">");
|
|
||||||
buf.append("<").append(elementName).append(" xmlns=\"").append(namespace).append("\"/>");
|
|
||||||
buf.append("</query>");
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
privateDataGet.setType(IQ.Type.get);
|
|
||||||
|
|
||||||
PrivateDataResult response = (PrivateDataResult) connection().createPacketCollectorAndSend(
|
PrivateDataIQ response = connection().createPacketCollectorAndSend(
|
||||||
privateDataGet).nextResultOrThrow();
|
privateDataGet).nextResultOrThrow();
|
||||||
return response.getPrivateData();
|
return response.getPrivateData();
|
||||||
}
|
}
|
||||||
|
@ -184,16 +176,7 @@ public class PrivateDataManager extends Manager {
|
||||||
*/
|
*/
|
||||||
public void setPrivateData(final PrivateData privateData) throws NoResponseException, XMPPErrorException, NotConnectedException {
|
public void setPrivateData(final PrivateData privateData) throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||||
// Create an IQ packet to set the private data.
|
// Create an IQ packet to set the private data.
|
||||||
IQ privateDataSet = new IQ() {
|
IQ privateDataSet = new PrivateDataIQ(privateData);
|
||||||
public String getChildElementXML() {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
buf.append("<query xmlns=\"jabber:iq:private\">");
|
|
||||||
buf.append(privateData.toXML());
|
|
||||||
buf.append("</query>");
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
privateDataSet.setType(IQ.Type.set);
|
|
||||||
|
|
||||||
connection().createPacketCollectorAndSend(privateDataSet).nextResultOrThrow();
|
connection().createPacketCollectorAndSend(privateDataSet).nextResultOrThrow();
|
||||||
}
|
}
|
||||||
|
@ -214,10 +197,10 @@ public class PrivateDataManager extends Manager {
|
||||||
/**
|
/**
|
||||||
* An IQ provider to parse IQ results containing private data.
|
* An IQ provider to parse IQ results containing private data.
|
||||||
*/
|
*/
|
||||||
public static class PrivateDataIQProvider extends IQProvider<PrivateDataResult> {
|
public static class PrivateDataIQProvider extends IQProvider<PrivateDataIQ> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PrivateDataResult parse(XmlPullParser parser, int initialDepth)
|
public PrivateDataIQ parse(XmlPullParser parser, int initialDepth)
|
||||||
throws XmlPullParserException, IOException, SmackException {
|
throws XmlPullParserException, IOException, SmackException {
|
||||||
PrivateData privateData = null;
|
PrivateData privateData = null;
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
|
@ -268,33 +251,7 @@ public class PrivateDataManager extends Manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new PrivateDataResult(privateData);
|
return new PrivateDataIQ(privateData);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An IQ packet to hold PrivateData GET results.
|
|
||||||
*/
|
|
||||||
private static class PrivateDataResult extends IQ {
|
|
||||||
|
|
||||||
private PrivateData privateData;
|
|
||||||
|
|
||||||
PrivateDataResult(PrivateData privateData) {
|
|
||||||
this.privateData = privateData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrivateData getPrivateData() {
|
|
||||||
return privateData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getChildElementXML() {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
buf.append("<query xmlns=\"jabber:iq:private\">");
|
|
||||||
if (privateData != null) {
|
|
||||||
buf.append(privateData.toXML());
|
|
||||||
}
|
|
||||||
buf.append("</query>");
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright © 2014 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.iqprivate.packet;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
|
||||||
|
public class PrivateDataIQ extends IQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = QUERY_ELEMENT;
|
||||||
|
public static final String NAMESPACE = "jabber:iq:private";
|
||||||
|
|
||||||
|
private final PrivateData privateData;
|
||||||
|
private final String getElement;
|
||||||
|
private final String getNamespace;
|
||||||
|
|
||||||
|
public PrivateDataIQ(PrivateData privateData) {
|
||||||
|
this(privateData, null, null);
|
||||||
|
setType(Type.set);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivateDataIQ(String element, String namespace) {
|
||||||
|
this(null, element, namespace);
|
||||||
|
setType(Type.get);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PrivateDataIQ(PrivateData privateData, String getElement, String getNamespace) {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
|
this.privateData = privateData;
|
||||||
|
this.getElement = getElement;
|
||||||
|
this.getNamespace = getNamespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrivateData getPrivateData() {
|
||||||
|
return privateData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
|
xml.rightAngleBracket();
|
||||||
|
if (privateData != null) {
|
||||||
|
xml.append(privateData.toXML());
|
||||||
|
} else {
|
||||||
|
xml.halfOpenElement(getElement).xmlnsAttribute(getNamespace).closeEmptyElement();
|
||||||
|
}
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,7 +21,6 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents registration packets. An empty GET query will cause the server to return information
|
* Represents registration packets. An empty GET query will cause the server to return information
|
||||||
|
@ -48,6 +47,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
*/
|
*/
|
||||||
public class Registration extends IQ {
|
public class Registration extends IQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = QUERY_ELEMENT;
|
||||||
public static final String NAMESPACE = "jabber:iq:register";
|
public static final String NAMESPACE = "jabber:iq:register";
|
||||||
|
|
||||||
private final String instructions;
|
private final String instructions;
|
||||||
|
@ -62,6 +62,7 @@ public class Registration extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Registration(String instructions, Map<String, String> attributes) {
|
public Registration(String instructions, Map<String, String> attributes) {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
this.instructions = instructions;
|
this.instructions = instructions;
|
||||||
this.attributes = attributes;
|
this.attributes = attributes;
|
||||||
}
|
}
|
||||||
|
@ -87,10 +88,7 @@ public class Registration extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
|
||||||
xml.halfOpenElement(QUERY_ELEMENT);
|
|
||||||
xml.xmlnsAttribute(NAMESPACE);
|
|
||||||
xml.rightAngleBracket();
|
xml.rightAngleBracket();
|
||||||
xml.optElement("instructions", instructions);
|
xml.optElement("instructions", instructions);
|
||||||
if (attributes != null && attributes.size() > 0) {
|
if (attributes != null && attributes.size() > 0) {
|
||||||
|
@ -99,9 +97,6 @@ public class Registration extends IQ {
|
||||||
xml.element(name, value);
|
xml.element(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add packet extensions, if any are defined.
|
|
||||||
xml.append(getExtensionsXML());
|
|
||||||
xml.closeElement(QUERY_ELEMENT);
|
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.jivesoftware.smackx.iqversion.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Version IQ packet, which is used by XMPP clients to discover version information
|
* A Version IQ packet, which is used by XMPP clients to discover version information
|
||||||
|
@ -49,6 +48,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
* @author Gaston Dombiak
|
* @author Gaston Dombiak
|
||||||
*/
|
*/
|
||||||
public class Version extends IQ {
|
public class Version extends IQ {
|
||||||
|
public static final String ELEMENT = QUERY_ELEMENT;
|
||||||
public static final String NAMESPACE = "jabber:iq:version";
|
public static final String NAMESPACE = "jabber:iq:version";
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
@ -56,6 +56,7 @@ public class Version extends IQ {
|
||||||
private String os;
|
private String os;
|
||||||
|
|
||||||
public Version() {
|
public Version() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
name = null;
|
name = null;
|
||||||
version = null;
|
version = null;
|
||||||
setType(Type.get);
|
setType(Type.get);
|
||||||
|
@ -83,6 +84,7 @@ public class Version extends IQ {
|
||||||
* @param os The operating system of the queried entity. This element is OPTIONAL.
|
* @param os The operating system of the queried entity. This element is OPTIONAL.
|
||||||
*/
|
*/
|
||||||
public Version(String name, String version, String os) {
|
public Version(String name, String version, String os) {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
if (name == null)
|
if (name == null)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("name must not be null");
|
throw new IllegalArgumentException("name must not be null");
|
||||||
|
@ -141,15 +143,13 @@ public class Version extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
xml.rightAngleBracket();
|
||||||
xml.halfOpenElement(IQ.QUERY_ELEMENT).xmlnsAttribute(NAMESPACE).rightAngleBracket();
|
|
||||||
// Although not really optional elements, 'name' and 'version' are not set when sending a
|
// Although not really optional elements, 'name' and 'version' are not set when sending a
|
||||||
// version request. So we must handle the case that those are 'null' here.
|
// version request. So we must handle the case that those are 'null' here.
|
||||||
xml.optElement("name", name);
|
xml.optElement("name", name);
|
||||||
xml.optElement("version", version);
|
xml.optElement("version", version);
|
||||||
xml.optElement("os", os);
|
xml.optElement("os", os);
|
||||||
xml.closeElement(IQ.QUERY_ELEMENT);
|
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IQ packet that serves for kicking users, granting and revoking voice, banning users,
|
* IQ packet that serves for kicking users, granting and revoking voice, banning users,
|
||||||
|
@ -33,10 +32,15 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
*/
|
*/
|
||||||
public class MUCAdmin extends IQ {
|
public class MUCAdmin extends IQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = QUERY_ELEMENT;
|
||||||
public static final String NAMESPACE = MUCInitialPresence.NAMESPACE + "#admin";
|
public static final String NAMESPACE = MUCInitialPresence.NAMESPACE + "#admin";
|
||||||
|
|
||||||
private final List<MUCItem> items = new ArrayList<MUCItem>();
|
private final List<MUCItem> items = new ArrayList<MUCItem>();
|
||||||
|
|
||||||
|
public MUCAdmin() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a List of item childs that holds information about roles, affiliation,
|
* Returns a List of item childs that holds information about roles, affiliation,
|
||||||
* jids and nicks.
|
* jids and nicks.
|
||||||
|
@ -62,19 +66,15 @@ public class MUCAdmin extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
|
||||||
xml.halfOpenElement(IQ.QUERY_ELEMENT);
|
|
||||||
xml.xmlnsAttribute(NAMESPACE);
|
|
||||||
xml.rightAngleBracket();
|
xml.rightAngleBracket();
|
||||||
|
|
||||||
synchronized (items) {
|
synchronized (items) {
|
||||||
for (MUCItem item : items) {
|
for (MUCItem item : items) {
|
||||||
xml.append(item.toXML());
|
xml.append(item.toXML());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add packet extensions, if any are defined.
|
|
||||||
xml.append(getExtensionsXML());
|
|
||||||
xml.closeElement(IQ.QUERY_ELEMENT);
|
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
package org.jivesoftware.smackx.muc.packet;
|
package org.jivesoftware.smackx.muc.packet;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -32,11 +31,16 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class MUCOwner extends IQ {
|
public class MUCOwner extends IQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = QUERY_ELEMENT;
|
||||||
public static final String NAMESPACE = MUCInitialPresence.NAMESPACE + "#owner";
|
public static final String NAMESPACE = MUCInitialPresence.NAMESPACE + "#owner";
|
||||||
|
|
||||||
private final List<MUCItem> items = new ArrayList<MUCItem>();
|
private final List<MUCItem> items = new ArrayList<MUCItem>();
|
||||||
private Destroy destroy;
|
private Destroy destroy;
|
||||||
|
|
||||||
|
public MUCOwner() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a List of item childs that holds information about affiliation,
|
* Returns a List of item childs that holds information about affiliation,
|
||||||
* jids and nicks.
|
* jids and nicks.
|
||||||
|
@ -84,20 +88,16 @@ public class MUCOwner extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
|
||||||
xml.halfOpenElement(IQ.QUERY_ELEMENT);
|
|
||||||
xml.xmlnsAttribute(NAMESPACE);
|
|
||||||
xml.rightAngleBracket();
|
xml.rightAngleBracket();
|
||||||
|
|
||||||
synchronized (items) {
|
synchronized (items) {
|
||||||
for (MUCItem item : items) {
|
for (MUCItem item : items) {
|
||||||
xml.append(item.toXML());
|
xml.append(item.toXML());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xml.optElement(getDestroy());
|
xml.optElement(getDestroy());
|
||||||
// Add packet extensions, if any are defined.
|
|
||||||
xml.append(getExtensionsXML());
|
|
||||||
xml.closeElement(IQ.QUERY_ELEMENT);
|
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,17 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class OfflineMessageRequest extends IQ {
|
public class OfflineMessageRequest extends IQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = "offline";
|
||||||
|
public static final String NAMESPACE = "http://jabber.org/protocol/offline";
|
||||||
|
|
||||||
private List<Item> items = new ArrayList<Item>();
|
private List<Item> items = new ArrayList<Item>();
|
||||||
private boolean purge = false;
|
private boolean purge = false;
|
||||||
private boolean fetch = false;
|
private boolean fetch = false;
|
||||||
|
|
||||||
|
public OfflineMessageRequest() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a List of item childs that holds information about offline messages to
|
* Returns a List of item childs that holds information about offline messages to
|
||||||
* view or delete.
|
* view or delete.
|
||||||
|
@ -99,9 +106,10 @@ public class OfflineMessageRequest extends IQ {
|
||||||
this.fetch = fetch;
|
this.fetch = fetch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append("<offline xmlns=\"http://jabber.org/protocol/offline\">");
|
buf.rightAngleBracket();
|
||||||
|
|
||||||
synchronized (items) {
|
synchronized (items) {
|
||||||
for (int i = 0; i < items.size(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
Item item = items.get(i);
|
Item item = items.get(i);
|
||||||
|
@ -114,10 +122,8 @@ public class OfflineMessageRequest extends IQ {
|
||||||
if (fetch) {
|
if (fetch) {
|
||||||
buf.append("<fetch/>");
|
buf.append("<fetch/>");
|
||||||
}
|
}
|
||||||
// Add packet extensions, if any are defined.
|
|
||||||
buf.append(getExtensionsXML());
|
return buf;
|
||||||
buf.append("</offline>");
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,39 +29,20 @@ import org.jivesoftware.smack.packet.IQ;
|
||||||
*/
|
*/
|
||||||
public class PEPPubSub extends IQ {
|
public class PEPPubSub extends IQ {
|
||||||
|
|
||||||
PEPItem item;
|
public static final String ELEMENT = "pubsub";
|
||||||
|
public static final String NAMESPACE = "http://jabber.org/protocol/pubsub";
|
||||||
|
|
||||||
|
private final PEPItem item;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new PubSub.
|
* Creates a new PubSub.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public PEPPubSub(PEPItem item) {
|
public PEPPubSub(PEPItem item) {
|
||||||
super();
|
super(ELEMENT, NAMESPACE);
|
||||||
|
|
||||||
this.item = item;
|
this.item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the XML element name of the extension sub-packet root element.
|
|
||||||
* Always returns "x"
|
|
||||||
*
|
|
||||||
* @return the XML element name of the packet extension.
|
|
||||||
*/
|
|
||||||
public String getElementName() {
|
|
||||||
return "pubsub";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the XML namespace of the extension sub-packet root element.
|
|
||||||
* According the specification the namespace is always "jabber:x:roster"
|
|
||||||
* (which is not to be confused with the 'jabber:iq:roster' namespace
|
|
||||||
*
|
|
||||||
* @return the XML namespace of the packet extension.
|
|
||||||
*/
|
|
||||||
public String getNamespace() {
|
|
||||||
return "http://jabber.org/protocol/pubsub";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the XML representation of a Personal Event Publish according the specification.
|
* Returns the XML representation of a Personal Event Publish according the specification.
|
||||||
*
|
*
|
||||||
|
@ -79,14 +60,15 @@ public class PEPPubSub extends IQ {
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\">");
|
buf.rightAngleBracket();
|
||||||
buf.append("<publish node=\"").append(item.getNode()).append("\">");
|
|
||||||
|
buf.openElement("publish").attribute("node", item.getNode()).rightAngleBracket();
|
||||||
buf.append(item.toXML());
|
buf.append(item.toXML());
|
||||||
buf.append("</publish>");
|
buf.closeElement("publish");
|
||||||
buf.append("</").append(getElementName()).append(">");
|
|
||||||
return buf.toString();
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,25 +17,23 @@
|
||||||
package org.jivesoftware.smackx.ping.packet;
|
package org.jivesoftware.smackx.ping.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
import org.jivesoftware.smack.packet.SimpleIQ;
|
||||||
|
|
||||||
public class Ping extends IQ {
|
public class Ping extends SimpleIQ {
|
||||||
|
|
||||||
public static final String ELEMENT = "ping";
|
public static final String ELEMENT = "ping";
|
||||||
public static final String NAMESPACE = "urn:xmpp:ping";
|
public static final String NAMESPACE = "urn:xmpp:ping";
|
||||||
|
|
||||||
public Ping() {
|
public Ping() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ping(String to) {
|
public Ping(String to) {
|
||||||
|
this();
|
||||||
setTo(to);
|
setTo(to);
|
||||||
setType(IQ.Type.get);
|
setType(IQ.Type.get);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a XMPP Pong for this Ping
|
* Create a XMPP Pong for this Ping
|
||||||
*
|
*
|
||||||
|
|
|
@ -56,7 +56,7 @@ import org.jivesoftware.smackx.privacy.packet.PrivacyItem;
|
||||||
* @see <a href="http://xmpp.org/extensions/xep-0016.html">XEP-16: Privacy Lists</a>
|
* @see <a href="http://xmpp.org/extensions/xep-0016.html">XEP-16: Privacy Lists</a>
|
||||||
*/
|
*/
|
||||||
public class PrivacyListManager extends Manager {
|
public class PrivacyListManager extends Manager {
|
||||||
public static final String NAMESPACE = "jabber:iq:privacy";
|
public static final String NAMESPACE = Privacy.NAMESPACE;
|
||||||
|
|
||||||
private static final PacketFilter PACKET_FILTER = new AndFilter(IQTypeFilter.SET,
|
private static final PacketFilter PACKET_FILTER = new AndFilter(IQTypeFilter.SET,
|
||||||
new PacketExtensionFilter("query", NAMESPACE));
|
new PacketExtensionFilter("query", NAMESPACE));
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.privacy.PrivacyListManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Privacy IQ Packet, is used by the {@link org.jivesoftware.smackx.privacy.PrivacyListManager}
|
* A Privacy IQ Packet, is used by the {@link org.jivesoftware.smackx.privacy.PrivacyListManager}
|
||||||
|
@ -43,6 +42,9 @@ import org.jivesoftware.smackx.privacy.PrivacyListManager;
|
||||||
* @author Francisco Vives
|
* @author Francisco Vives
|
||||||
*/
|
*/
|
||||||
public class Privacy extends IQ {
|
public class Privacy extends IQ {
|
||||||
|
public static final String ELEMENT = QUERY_ELEMENT;
|
||||||
|
public static final String NAMESPACE = "jabber:iq:privacy";
|
||||||
|
|
||||||
/** declineActiveList is true when the user declines the use of the active list **/
|
/** declineActiveList is true when the user declines the use of the active list **/
|
||||||
private boolean declineActiveList=false;
|
private boolean declineActiveList=false;
|
||||||
/** activeName is the name associated with the active list set for the session **/
|
/** activeName is the name associated with the active list set for the session **/
|
||||||
|
@ -55,6 +57,10 @@ public class Privacy extends IQ {
|
||||||
* key is the name of the list and the value a collection with privacy items. **/
|
* key is the name of the list and the value a collection with privacy items. **/
|
||||||
private Map<String, List<PrivacyItem>> itemLists = new HashMap<String, List<PrivacyItem>>();
|
private Map<String, List<PrivacyItem>> itemLists = new HashMap<String, List<PrivacyItem>>();
|
||||||
|
|
||||||
|
public Privacy() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set or update a privacy list with privacy items.
|
* Set or update a privacy list with privacy items.
|
||||||
*
|
*
|
||||||
|
@ -276,10 +282,10 @@ public class Privacy extends IQ {
|
||||||
public Set<String> getPrivacyListNames() {
|
public Set<String> getPrivacyListNames() {
|
||||||
return this.itemLists.keySet();
|
return this.itemLists.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append("<query xmlns=\"" + PrivacyListManager.NAMESPACE + "\">");
|
buf.rightAngleBracket();
|
||||||
|
|
||||||
// Add the active tag
|
// Add the active tag
|
||||||
if (this.isDeclineActiveList()) {
|
if (this.isDeclineActiveList()) {
|
||||||
|
@ -318,10 +324,7 @@ public class Privacy extends IQ {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add packet extensions, if any are defined.
|
return buf;
|
||||||
buf.append(getExtensionsXML());
|
|
||||||
buf.append("</query>");
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ package org.jivesoftware.smackx.pubsub.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
import org.jivesoftware.smackx.pubsub.PubSubElementType;
|
import org.jivesoftware.smackx.pubsub.PubSubElementType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,9 +35,11 @@ public class PubSub extends IQ
|
||||||
private PubSubNamespace ns = PubSubNamespace.BASIC;
|
private PubSubNamespace ns = PubSubNamespace.BASIC;
|
||||||
|
|
||||||
public PubSub() {
|
public PubSub() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PubSub(String to, Type type) {
|
public PubSub(String to, Type type) {
|
||||||
|
this();
|
||||||
setTo(to);
|
setTo(to);
|
||||||
setType(type);
|
setType(type);
|
||||||
}
|
}
|
||||||
|
@ -119,11 +120,11 @@ public class PubSub extends IQ
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
// N.B. We could use SimpleIQ here, but PubSub IQs will nearly *always* have packet extensions, which means that
|
||||||
xml.halfOpenElement(getElementName()).xmlnsAttribute(getNamespace()).rightAngleBracket();
|
// SimpleIQs xml.setEmptyElement() is counter-productive in this case and we use xml.rightAngleBracket()
|
||||||
xml.append(getExtensionsXML());
|
// instead, as there are likely sub-elements to follow.
|
||||||
xml.closeElement(getElementName());
|
xml.rightAngleBracket();
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,16 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
class SimpleUserSearch extends IQ {
|
class SimpleUserSearch extends IQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = UserSearch.ELEMENT;
|
||||||
|
public static final String NAMESPACE = UserSearch.NAMESPACE;
|
||||||
|
|
||||||
private Form form;
|
private Form form;
|
||||||
private ReportedData data;
|
private ReportedData data;
|
||||||
|
|
||||||
|
public SimpleUserSearch() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
public void setForm(Form form) {
|
public void setForm(Form form) {
|
||||||
this.form = form;
|
this.form = form;
|
||||||
}
|
}
|
||||||
|
@ -46,13 +53,11 @@ class SimpleUserSearch extends IQ {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
StringBuilder buf = new StringBuilder();
|
buf.rightAngleBracket();
|
||||||
buf.append("<query xmlns=\"jabber:iq:search\">");
|
|
||||||
buf.append(getItemsToSearch());
|
buf.append(getItemsToSearch());
|
||||||
buf.append("</query>");
|
return buf;
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getItemsToSearch() {
|
private String getItemsToSearch() {
|
||||||
|
|
|
@ -24,9 +24,9 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
import org.jivesoftware.smack.packet.SimpleIQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
import org.jivesoftware.smackx.xdata.Form;
|
import org.jivesoftware.smackx.xdata.Form;
|
||||||
import org.jivesoftware.smackx.xdata.FormField;
|
import org.jivesoftware.smackx.xdata.FormField;
|
||||||
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||||
|
@ -43,25 +43,16 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||||
*
|
*
|
||||||
* @author Derek DeMoro
|
* @author Derek DeMoro
|
||||||
*/
|
*/
|
||||||
public class UserSearch extends IQ {
|
public class UserSearch extends SimpleIQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = QUERY_ELEMENT;
|
||||||
public static final String NAMESPACE = "jabber:iq:search";
|
public static final String NAMESPACE = "jabber:iq:search";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of UserSearch.
|
* Creates a new instance of UserSearch.
|
||||||
*/
|
*/
|
||||||
public UserSearch() {
|
public UserSearch() {
|
||||||
}
|
super(ELEMENT, NAMESPACE);
|
||||||
|
|
||||||
@Override
|
|
||||||
public XmlStringBuilder getChildElementXML() {
|
|
||||||
XmlStringBuilder xml = new XmlStringBuilder();
|
|
||||||
xml.halfOpenElement(IQ.QUERY_ELEMENT);
|
|
||||||
xml.xmlnsAttribute(NAMESPACE);
|
|
||||||
xml.rightAngleBracket();
|
|
||||||
xml.append(getExtensionsXML());
|
|
||||||
xml.closeElement(IQ.QUERY_ELEMENT);
|
|
||||||
return xml;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,8 +36,15 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class SharedGroupsInfo extends IQ {
|
public class SharedGroupsInfo extends IQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = "sharedgroup";
|
||||||
|
public static final String NAMESPACE = "http://www.jivesoftware.org/protocol/sharedgroup";
|
||||||
|
|
||||||
private List<String> groups = new ArrayList<String>();
|
private List<String> groups = new ArrayList<String>();
|
||||||
|
|
||||||
|
public SharedGroupsInfo() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a collection with the shared group names returned from the server.
|
* Returns a collection with the shared group names returned from the server.
|
||||||
*
|
*
|
||||||
|
@ -47,14 +54,13 @@ public class SharedGroupsInfo extends IQ {
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append("<sharedgroup xmlns=\"http://www.jivesoftware.org/protocol/sharedgroup\">");
|
buf.rightAngleBracket();
|
||||||
for (String group : groups) {
|
for (String group : groups) {
|
||||||
buf.append("<group>").append(group).append("</group>");
|
buf.element("group", group);
|
||||||
}
|
}
|
||||||
buf.append("</sharedgroup>");
|
return buf;
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,6 +31,9 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||||
*/
|
*/
|
||||||
public class StreamInitiation extends IQ {
|
public class StreamInitiation extends IQ {
|
||||||
|
|
||||||
|
public static final String ELEMENT = "si";
|
||||||
|
public static final String NAMESPACE = "http://jabber.org/protocol/si";
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
private String mimeType;
|
private String mimeType;
|
||||||
|
@ -39,6 +42,10 @@ public class StreamInitiation extends IQ {
|
||||||
|
|
||||||
private Feature featureNegotiation;
|
private Feature featureNegotiation;
|
||||||
|
|
||||||
|
public StreamInitiation() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The "id" attribute is an opaque identifier. This attribute MUST be
|
* The "id" attribute is an opaque identifier. This attribute MUST be
|
||||||
* present on type='set', and MUST be a valid string. This SHOULD NOT be
|
* present on type='set', and MUST be a valid string. This SHOULD NOT be
|
||||||
|
@ -127,41 +134,28 @@ public class StreamInitiation extends IQ {
|
||||||
return featureNegotiation.getData();
|
return featureNegotiation.getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
@Override
|
||||||
* (non-Javadoc)
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
*
|
switch (getType()) {
|
||||||
* @see org.jivesoftware.smack.packet.IQ#getChildElementXML()
|
case set:
|
||||||
*/
|
buf.optAttribute("id", getSessionID());
|
||||||
public String getChildElementXML() {
|
buf.optAttribute("mime-type", getMimeType());
|
||||||
StringBuilder buf = new StringBuilder();
|
buf.attribute("profile", NAMESPACE + "/profile/file-transfer");
|
||||||
if (this.getType().equals(IQ.Type.set)) {
|
buf.rightAngleBracket();
|
||||||
buf.append("<si xmlns=\"http://jabber.org/protocol/si\" ");
|
|
||||||
if (getSessionID() != null) {
|
|
||||||
buf.append("id=\"").append(getSessionID()).append("\" ");
|
|
||||||
}
|
|
||||||
if (getMimeType() != null) {
|
|
||||||
buf.append("mime-type=\"").append(getMimeType()).append("\" ");
|
|
||||||
}
|
|
||||||
buf
|
|
||||||
.append("profile=\"http://jabber.org/protocol/si/profile/file-transfer\">");
|
|
||||||
|
|
||||||
// Add the file section if there is one.
|
// Add the file section if there is one.
|
||||||
String fileXML = file.toXML();
|
buf.optAppend(file.toXML());
|
||||||
if (fileXML != null) {
|
break;
|
||||||
buf.append(fileXML);
|
case result:
|
||||||
}
|
buf.rightAngleBracket();
|
||||||
}
|
break;
|
||||||
else if (this.getType().equals(IQ.Type.result)) {
|
default:
|
||||||
buf.append("<si xmlns=\"http://jabber.org/protocol/si\">");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalArgumentException("IQ Type not understood");
|
throw new IllegalArgumentException("IQ Type not understood");
|
||||||
}
|
}
|
||||||
if (featureNegotiation != null) {
|
if (featureNegotiation != null) {
|
||||||
buf.append(featureNegotiation.toXML());
|
buf.append(featureNegotiation.toXML());
|
||||||
}
|
}
|
||||||
buf.append("</si>");
|
return buf;
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class Time extends IQ {
|
||||||
private String tzo;
|
private String tzo;
|
||||||
|
|
||||||
public Time() {
|
public Time() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
setType(Type.get);
|
setType(Type.get);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +54,7 @@ public class Time extends IQ {
|
||||||
* @param cal the time value.
|
* @param cal the time value.
|
||||||
*/
|
*/
|
||||||
public Time(Calendar cal) {
|
public Time(Calendar cal) {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
tzo = XmppDateTime.asString(cal.getTimeZone());
|
tzo = XmppDateTime.asString(cal.getTimeZone());
|
||||||
// Convert local time to the UTC time.
|
// Convert local time to the UTC time.
|
||||||
utc = XmppDateTime.formatXEP0082Date(cal.getTime());
|
utc = XmppDateTime.formatXEP0082Date(cal.getTime());
|
||||||
|
@ -128,14 +130,17 @@ public class Time extends IQ {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append("<" + ELEMENT + " xmlns='" + NAMESPACE + "'>");
|
buf.rightAngleBracket();
|
||||||
|
|
||||||
if (utc != null) {
|
if (utc != null) {
|
||||||
buf.append("<utc>").append(utc).append("</utc>");
|
buf.append("<utc>").append(utc).append("</utc>");
|
||||||
buf.append("<tzo>").append(tzo).append("</tzo>");
|
buf.append("<tzo>").append(tzo).append("</tzo>");
|
||||||
|
} else {
|
||||||
|
buf.setEmptyElement();
|
||||||
}
|
}
|
||||||
buf.append("</" + ELEMENT + ">");
|
|
||||||
return buf.toString();
|
return buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||||
import org.jivesoftware.smackx.vcardtemp.VCardManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A VCard class for use with the
|
* A VCard class for use with the
|
||||||
|
@ -82,6 +81,9 @@ import org.jivesoftware.smackx.vcardtemp.VCardManager;
|
||||||
* @author Kirill Maximov (kir@maxkir.com)
|
* @author Kirill Maximov (kir@maxkir.com)
|
||||||
*/
|
*/
|
||||||
public class VCard extends IQ {
|
public class VCard extends IQ {
|
||||||
|
public static final String ELEMENT = "vCard";
|
||||||
|
public static final String NAMESPACE = "vcard-temp";
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(VCard.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(VCard.class.getName());
|
||||||
|
|
||||||
private static final String DEFAULT_MIME_TYPE = "image/jpeg";
|
private static final String DEFAULT_MIME_TYPE = "image/jpeg";
|
||||||
|
@ -123,6 +125,7 @@ public class VCard extends IQ {
|
||||||
private Map<String, String> otherUnescapableFields = new HashMap<String, String>();
|
private Map<String, String> otherUnescapableFields = new HashMap<String, String>();
|
||||||
|
|
||||||
public VCard() {
|
public VCard() {
|
||||||
|
super(ELEMENT, NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -562,10 +565,87 @@ public class VCard extends IQ {
|
||||||
copyFieldsFrom(result);
|
copyFieldsFrom(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder sb = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
new VCardWriter(sb).write();
|
if (!hasContent()) {
|
||||||
return sb.toString();
|
xml.setEmptyElement();
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
|
xml.rightAngleBracket();
|
||||||
|
if (hasNameField()) {
|
||||||
|
xml.openElement("N");
|
||||||
|
xml.element("FAMILY", lastName);
|
||||||
|
xml.element("GIVEN", firstName);
|
||||||
|
xml.element("MIDDLE", middleName);
|
||||||
|
xml.closeElement("N");
|
||||||
|
}
|
||||||
|
if (hasOrganizationFields()) {
|
||||||
|
xml.openElement("ORG");
|
||||||
|
xml.element("ORGNAME", organization);
|
||||||
|
xml.element("ORGUNIT", organizationUnit);
|
||||||
|
xml.closeElement("ORG");
|
||||||
|
}
|
||||||
|
for (Entry<String, String> entry : otherSimpleFields.entrySet()) {
|
||||||
|
xml.element(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
for (Entry<String, String> entry : otherUnescapableFields.entrySet()) {
|
||||||
|
xml.openElement(entry.getKey());
|
||||||
|
xml.append(entry.getValue());
|
||||||
|
xml.closeElement(entry.getKey());
|
||||||
|
}
|
||||||
|
if (photoBinval != null) {
|
||||||
|
xml.openElement("PHOTO");
|
||||||
|
xml.escapedElement("BINVAL", photoBinval);
|
||||||
|
xml.element("TYPE", photoMimeType);
|
||||||
|
xml.closeElement("PHOTO");
|
||||||
|
}
|
||||||
|
if (emailWork != null) {
|
||||||
|
xml.openElement("EMAIL");
|
||||||
|
xml.emptyElement("WORK");
|
||||||
|
xml.emptyElement("INTERNET");
|
||||||
|
xml.emptyElement("PREF");
|
||||||
|
xml.element("USERID", emailWork);
|
||||||
|
xml.closeElement("EMAIL");
|
||||||
|
}
|
||||||
|
if (emailHome != null) {
|
||||||
|
xml.openElement("EMAIL");
|
||||||
|
xml.emptyElement("HOME");
|
||||||
|
xml.emptyElement("INTERNET");
|
||||||
|
xml.emptyElement("PREF");
|
||||||
|
xml.element("USERID", emailHome);
|
||||||
|
xml.closeElement("EMAIL");
|
||||||
|
}
|
||||||
|
for (Entry<String, String> phone : workPhones.entrySet()) {
|
||||||
|
xml.openElement("TEL");
|
||||||
|
xml.emptyElement("WORK");
|
||||||
|
xml.emptyElement(phone.getKey());
|
||||||
|
xml.element("NUMBER", phone.getValue());
|
||||||
|
xml.closeElement("TEL");
|
||||||
|
}
|
||||||
|
for (Entry<String, String> phone : homePhones.entrySet()) {
|
||||||
|
xml.openElement("TEL");
|
||||||
|
xml.emptyElement("HOME");
|
||||||
|
xml.emptyElement(phone.getKey());
|
||||||
|
xml.element("NUMBER", phone.getValue());
|
||||||
|
xml.closeElement("TEL");
|
||||||
|
}
|
||||||
|
if (!workAddr.isEmpty()) {
|
||||||
|
xml.openElement("ADR");
|
||||||
|
xml.emptyElement("WORK");
|
||||||
|
for (Entry<String, String> entry : workAddr.entrySet()) {
|
||||||
|
xml.element(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
xml.closeElement("ADR");
|
||||||
|
}
|
||||||
|
if (!homeAddr.isEmpty()) {
|
||||||
|
xml.openElement("ADR");
|
||||||
|
xml.emptyElement("HOME");
|
||||||
|
for (Entry<String, String> entry : homeAddr.entrySet()) {
|
||||||
|
xml.element(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
xml.closeElement("ADR");
|
||||||
|
}
|
||||||
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyFieldsFrom(VCard from) {
|
private void copyFieldsFrom(VCard from) {
|
||||||
|
@ -688,173 +768,5 @@ public class VCard extends IQ {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return getChildElementXML();
|
|
||||||
}
|
|
||||||
|
|
||||||
//==============================================================
|
|
||||||
|
|
||||||
private class VCardWriter {
|
|
||||||
|
|
||||||
private final StringBuilder sb;
|
|
||||||
|
|
||||||
VCardWriter(StringBuilder sb) {
|
|
||||||
this.sb = sb;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write() {
|
|
||||||
appendTag(VCardManager.ELEMENT, "xmlns", VCardManager.NAMESPACE, hasContent(), new ContentBuilder() {
|
|
||||||
public void addTagContent() {
|
|
||||||
buildActualContent();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buildActualContent() {
|
|
||||||
if (hasNameField()) {
|
|
||||||
appendN();
|
|
||||||
}
|
|
||||||
|
|
||||||
appendOrganization();
|
|
||||||
appendGenericFields();
|
|
||||||
appendPhoto();
|
|
||||||
|
|
||||||
appendEmail(emailWork, "WORK");
|
|
||||||
appendEmail(emailHome, "HOME");
|
|
||||||
|
|
||||||
appendPhones(workPhones, "WORK");
|
|
||||||
appendPhones(homePhones, "HOME");
|
|
||||||
|
|
||||||
appendAddress(workAddr, "WORK");
|
|
||||||
appendAddress(homeAddr, "HOME");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendPhoto() {
|
|
||||||
if (photoBinval == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
appendTag("PHOTO", true, new ContentBuilder() {
|
|
||||||
public void addTagContent() {
|
|
||||||
appendTag("BINVAL", photoBinval); // No need to escape photoBinval, as it's already Base64 encoded
|
|
||||||
appendTag("TYPE", StringUtils.escapeForXML(photoMimeType));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
private void appendEmail(final String email, final String type) {
|
|
||||||
if (email != null) {
|
|
||||||
appendTag("EMAIL", true, new ContentBuilder() {
|
|
||||||
public void addTagContent() {
|
|
||||||
appendEmptyTag(type);
|
|
||||||
appendEmptyTag("INTERNET");
|
|
||||||
appendEmptyTag("PREF");
|
|
||||||
appendTag("USERID", StringUtils.escapeForXML(email));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendPhones(Map<String, String> phones, final String code) {
|
|
||||||
for (final Map.Entry<String,String> entry : phones.entrySet()) {
|
|
||||||
appendTag("TEL", true, new ContentBuilder() {
|
|
||||||
public void addTagContent() {
|
|
||||||
appendEmptyTag(entry.getKey());
|
|
||||||
appendEmptyTag(code);
|
|
||||||
appendTag("NUMBER", StringUtils.escapeForXML(entry.getValue()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendAddress(final Map<String, String> addr, final String code) {
|
|
||||||
if (addr.size() > 0) {
|
|
||||||
appendTag("ADR", true, new ContentBuilder() {
|
|
||||||
public void addTagContent() {
|
|
||||||
appendEmptyTag(code);
|
|
||||||
|
|
||||||
for (final Entry<String, String> entry : addr.entrySet()) {
|
|
||||||
appendTag(entry.getKey(), StringUtils.escapeForXML(entry.getValue()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendEmptyTag(Object tag) {
|
|
||||||
sb.append('<').append(tag).append("/>");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendGenericFields() {
|
|
||||||
for (Map.Entry<String, String> entry : otherSimpleFields.entrySet()) {
|
|
||||||
appendTag(entry.getKey().toString(),
|
|
||||||
StringUtils.escapeForXML(entry.getValue()));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : otherUnescapableFields.entrySet()) {
|
|
||||||
appendTag(entry.getKey().toString(),entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendOrganization() {
|
|
||||||
if (hasOrganizationFields()) {
|
|
||||||
appendTag("ORG", true, new ContentBuilder() {
|
|
||||||
public void addTagContent() {
|
|
||||||
appendTag("ORGNAME", StringUtils.escapeForXML(organization));
|
|
||||||
appendTag("ORGUNIT", StringUtils.escapeForXML(organizationUnit));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendN() {
|
|
||||||
appendTag("N", true, new ContentBuilder() {
|
|
||||||
public void addTagContent() {
|
|
||||||
appendTag("FAMILY", StringUtils.escapeForXML(lastName));
|
|
||||||
appendTag("GIVEN", StringUtils.escapeForXML(firstName));
|
|
||||||
appendTag("MIDDLE", StringUtils.escapeForXML(middleName));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendTag(String tag, String attr, String attrValue, boolean hasContent,
|
|
||||||
ContentBuilder builder) {
|
|
||||||
sb.append('<').append(tag);
|
|
||||||
if (attr != null) {
|
|
||||||
sb.append(' ').append(attr).append('=').append('\'').append(attrValue).append('\'');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasContent) {
|
|
||||||
sb.append('>');
|
|
||||||
builder.addTagContent();
|
|
||||||
sb.append("</").append(tag).append(">\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sb.append("/>\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendTag(String tag, boolean hasContent, ContentBuilder builder) {
|
|
||||||
appendTag(tag, null, null, hasContent, builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendTag(String tag, final CharSequence tagText) {
|
|
||||||
if (tagText == null) return;
|
|
||||||
final ContentBuilder contentBuilder = new ContentBuilder() {
|
|
||||||
public void addTagContent() {
|
|
||||||
sb.append(tagText.toString().trim());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
appendTag(tag, true, contentBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//==============================================================
|
|
||||||
|
|
||||||
private interface ContentBuilder {
|
|
||||||
|
|
||||||
void addTagContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
//==============================================================
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.bytestreams.ibb;
|
package org.jivesoftware.smackx.bytestreams.ibb;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.EmptyResultIQ;
|
||||||
|
import org.jivesoftware.smack.packet.ErrorIQ;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
|
|
||||||
|
@ -35,17 +37,10 @@ public class IBBPacketUtils {
|
||||||
* @return an error IQ
|
* @return an error IQ
|
||||||
*/
|
*/
|
||||||
public static IQ createErrorIQ(String from, String to, XMPPError xmppError) {
|
public static IQ createErrorIQ(String from, String to, XMPPError xmppError) {
|
||||||
IQ errorIQ = new IQ() {
|
IQ errorIQ = new ErrorIQ(xmppError);
|
||||||
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
errorIQ.setType(IQ.Type.error);
|
errorIQ.setType(IQ.Type.error);
|
||||||
errorIQ.setFrom(from);
|
errorIQ.setFrom(from);
|
||||||
errorIQ.setTo(to);
|
errorIQ.setTo(to);
|
||||||
errorIQ.setError(xmppError);
|
|
||||||
return errorIQ;
|
return errorIQ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,13 +52,7 @@ public class IBBPacketUtils {
|
||||||
* @return a result IQ
|
* @return a result IQ
|
||||||
*/
|
*/
|
||||||
public static IQ createResultIQ(String from, String to) {
|
public static IQ createResultIQ(String from, String to) {
|
||||||
IQ result = new IQ() {
|
IQ result = new EmptyResultIQ();
|
||||||
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
result.setType(IQ.Type.result);
|
result.setType(IQ.Type.result);
|
||||||
result.setFrom(from);
|
result.setFrom(from);
|
||||||
result.setTo(to);
|
result.setTo(to);
|
||||||
|
|
|
@ -64,8 +64,8 @@ public class CloseTest {
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnValidIQStanzaXML() throws Exception {
|
public void shouldReturnValidIQStanzaXML() throws Exception {
|
||||||
String control = XMLBuilder.create("iq")
|
String control = XMLBuilder.create("iq")
|
||||||
.a("from", "romeo@montague.lit/orchard")
|
|
||||||
.a("to", "juliet@capulet.lit/balcony")
|
.a("to", "juliet@capulet.lit/balcony")
|
||||||
|
.a("from", "romeo@montague.lit/orchard")
|
||||||
.a("id", "us71g45j")
|
.a("id", "us71g45j")
|
||||||
.a("type", "set")
|
.a("type", "set")
|
||||||
.e("close")
|
.e("close")
|
||||||
|
|
|
@ -19,12 +19,10 @@ package org.jivesoftware.smackx.bytestreams.ibb.packet;
|
||||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -70,16 +68,7 @@ public class DataTest {
|
||||||
.t(encodedData)
|
.t(encodedData)
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
DataPacketExtension dpe = mock(DataPacketExtension.class);
|
DataPacketExtension dpe = new DataPacketExtension("i781hf64", 0, encodedData);
|
||||||
XmlStringBuilder dataTag = new XmlStringBuilder();
|
|
||||||
dataTag.halfOpenElement(DataPacketExtension.ELEMENT);
|
|
||||||
dataTag.xmlnsAttribute(DataPacketExtension.NAMESPACE);
|
|
||||||
dataTag.attribute("seq", "0");
|
|
||||||
dataTag.attribute("sid", "i781hf64");
|
|
||||||
dataTag.rightAngleBracket();
|
|
||||||
dataTag.escape(encodedData);
|
|
||||||
dataTag.closeElement(DataPacketExtension.ELEMENT);
|
|
||||||
when(dpe.toXML()).thenReturn(dataTag);
|
|
||||||
Data data = new Data(dpe);
|
Data data = new Data(dpe);
|
||||||
data.setFrom("romeo@montague.lit/orchard");
|
data.setFrom("romeo@montague.lit/orchard");
|
||||||
data.setTo("juliet@capulet.lit/balcony");
|
data.setTo("juliet@capulet.lit/balcony");
|
||||||
|
|
|
@ -34,9 +34,9 @@ import org.jivesoftware.smack.SmackException.FeatureNotSupportedException;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||||
|
import org.jivesoftware.smack.packet.ErrorIQ;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smack.packet.IQ.Type;
|
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
@ -426,14 +426,7 @@ public class Socks5ByteStreamManagerTest {
|
||||||
|
|
||||||
// build error packet to reject SOCKS5 Bytestream
|
// build error packet to reject SOCKS5 Bytestream
|
||||||
XMPPError xmppError = new XMPPError(XMPPError.Condition.not_acceptable);
|
XMPPError xmppError = new XMPPError(XMPPError.Condition.not_acceptable);
|
||||||
IQ rejectPacket = new IQ() {
|
IQ rejectPacket = new ErrorIQ(xmppError);
|
||||||
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
rejectPacket.setType(Type.error);
|
|
||||||
rejectPacket.setFrom(targetJID);
|
rejectPacket.setFrom(targetJID);
|
||||||
rejectPacket.setTo(initiatorJID);
|
rejectPacket.setTo(initiatorJID);
|
||||||
rejectPacket.setError(xmppError);
|
rejectPacket.setError(xmppError);
|
||||||
|
|
|
@ -30,9 +30,10 @@ import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||||
|
import org.jivesoftware.smack.packet.EmptyResultIQ;
|
||||||
|
import org.jivesoftware.smack.packet.ErrorIQ;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smack.packet.IQ.Type;
|
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
|
||||||
import org.jivesoftware.util.ConnectionUtils;
|
import org.jivesoftware.util.ConnectionUtils;
|
||||||
|
@ -197,17 +198,9 @@ public class Socks5ClientForInitiatorTest {
|
||||||
|
|
||||||
// build error response as reply to the stream activation
|
// build error response as reply to the stream activation
|
||||||
XMPPError xmppError = new XMPPError(XMPPError.Condition.internal_server_error);
|
XMPPError xmppError = new XMPPError(XMPPError.Condition.internal_server_error);
|
||||||
IQ error = new IQ() {
|
IQ error = new ErrorIQ(xmppError);
|
||||||
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
error.setType(Type.error);
|
|
||||||
error.setFrom(proxyJID);
|
error.setFrom(proxyJID);
|
||||||
error.setTo(initiatorJID);
|
error.setTo(initiatorJID);
|
||||||
error.setError(xmppError);
|
|
||||||
|
|
||||||
protocol.addResponse(error, Verification.correspondingSenderReceiver,
|
protocol.addResponse(error, Verification.correspondingSenderReceiver,
|
||||||
Verification.requestTypeSET);
|
Verification.requestTypeSET);
|
||||||
|
@ -249,17 +242,10 @@ public class Socks5ClientForInitiatorTest {
|
||||||
public void shouldSuccessfullyEstablishConnectionAndActivateSocks5Proxy() throws Exception {
|
public void shouldSuccessfullyEstablishConnectionAndActivateSocks5Proxy() throws Exception {
|
||||||
|
|
||||||
// build activation confirmation response
|
// build activation confirmation response
|
||||||
IQ activationResponse = new IQ() {
|
IQ activationResponse = new EmptyResultIQ();
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
activationResponse.setFrom(proxyJID);
|
activationResponse.setFrom(proxyJID);
|
||||||
activationResponse.setTo(initiatorJID);
|
activationResponse.setTo(initiatorJID);
|
||||||
activationResponse.setType(IQ.Type.result);
|
|
||||||
|
|
||||||
protocol.addResponse(activationResponse, Verification.correspondingSenderReceiver,
|
protocol.addResponse(activationResponse, Verification.correspondingSenderReceiver,
|
||||||
Verification.requestTypeSET, new Verification<Bytestream, IQ>() {
|
Verification.requestTypeSET, new Verification<Bytestream, IQ>() {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.bytestreams.socks5;
|
package org.jivesoftware.smackx.bytestreams.socks5;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.EmptyResultIQ;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||||
|
@ -100,17 +101,9 @@ public class Socks5PacketUtils {
|
||||||
* @return response IQ for a activation request to the proxy
|
* @return response IQ for a activation request to the proxy
|
||||||
*/
|
*/
|
||||||
public static IQ createActivationConfirmation(String from, String to) {
|
public static IQ createActivationConfirmation(String from, String to) {
|
||||||
IQ response = new IQ() {
|
IQ response = new EmptyResultIQ();
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
response.setFrom(from);
|
response.setFrom(from);
|
||||||
response.setTo(to);
|
response.setTo(to);
|
||||||
response.setType(IQ.Type.result);
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ public class RTPBridge extends IQ {
|
||||||
* @param sid
|
* @param sid
|
||||||
*/
|
*/
|
||||||
public RTPBridge(String sid) {
|
public RTPBridge(String sid) {
|
||||||
|
this();
|
||||||
this.sid = sid;
|
this.sid = sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +103,7 @@ public class RTPBridge extends IQ {
|
||||||
* @param action
|
* @param action
|
||||||
*/
|
*/
|
||||||
public RTPBridge(BridgeAction action) {
|
public RTPBridge(BridgeAction action) {
|
||||||
|
this();
|
||||||
this.bridgeAction = action;
|
this.bridgeAction = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +114,7 @@ public class RTPBridge extends IQ {
|
||||||
* @param bridgeAction
|
* @param bridgeAction
|
||||||
*/
|
*/
|
||||||
public RTPBridge(String sid, BridgeAction bridgeAction) {
|
public RTPBridge(String sid, BridgeAction bridgeAction) {
|
||||||
|
this();
|
||||||
this.sid = sid;
|
this.sid = sid;
|
||||||
this.bridgeAction = bridgeAction;
|
this.bridgeAction = bridgeAction;
|
||||||
}
|
}
|
||||||
|
@ -120,6 +123,7 @@ public class RTPBridge extends IQ {
|
||||||
* Creates a RTPBridge Packet without Session ID
|
* Creates a RTPBridge Packet without Session ID
|
||||||
*/
|
*/
|
||||||
public RTPBridge() {
|
public RTPBridge() {
|
||||||
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -298,9 +302,9 @@ public class RTPBridge extends IQ {
|
||||||
*
|
*
|
||||||
* @return the Child Element XML of the Packet
|
* @return the Child Element XML of the Packet
|
||||||
*/
|
*/
|
||||||
public String getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder str) {
|
||||||
StringBuilder str = new StringBuilder();
|
str.attribute("sid", sid);
|
||||||
str.append("<" + ELEMENT_NAME + " xmlns='" + NAMESPACE + "' sid='").append(sid).append("'>");
|
str.rightAngleBracket();
|
||||||
|
|
||||||
if (bridgeAction.equals(BridgeAction.create))
|
if (bridgeAction.equals(BridgeAction.create))
|
||||||
str.append("<candidate/>");
|
str.append("<candidate/>");
|
||||||
|
@ -309,8 +313,7 @@ public class RTPBridge extends IQ {
|
||||||
else
|
else
|
||||||
str.append("<publicip ").append(getAttributes()).append(" />");
|
str.append("<publicip ").append(getAttributes()).append(" />");
|
||||||
|
|
||||||
str.append("</" + ELEMENT_NAME + ">");
|
return str;
|
||||||
return str.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.PacketCollector;
|
import org.jivesoftware.smack.PacketCollector;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.SimpleIQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smack.provider.ProviderManager;
|
import org.jivesoftware.smack.provider.ProviderManager;
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
@ -44,7 +44,7 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||||
*
|
*
|
||||||
* @author Thiago Camargo
|
* @author Thiago Camargo
|
||||||
*/
|
*/
|
||||||
public class STUN extends IQ {
|
public class STUN extends SimpleIQ {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(STUN.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(STUN.class.getName());
|
||||||
|
|
||||||
|
@ -75,6 +75,7 @@ public class STUN extends IQ {
|
||||||
* Creates a STUN IQ
|
* Creates a STUN IQ
|
||||||
*/
|
*/
|
||||||
public STUN() {
|
public STUN() {
|
||||||
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,17 +105,6 @@ public class STUN extends IQ {
|
||||||
this.publicIp = publicIp;
|
this.publicIp = publicIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Child Element XML of the Packet
|
|
||||||
*
|
|
||||||
* @return the child element XML
|
|
||||||
*/
|
|
||||||
public String getChildElementXML() {
|
|
||||||
StringBuilder str = new StringBuilder();
|
|
||||||
str.append("<" + ELEMENT_NAME + " xmlns='" + NAMESPACE + "'/>");
|
|
||||||
return str.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IQProvider for RTP Bridge packets.
|
* IQProvider for RTP Bridge packets.
|
||||||
* Parse receive RTPBridge packet to a RTPBridge instance
|
* Parse receive RTPBridge packet to a RTPBridge instance
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class Jingle extends IQ {
|
||||||
*/
|
*/
|
||||||
public Jingle(final List<JingleContent> contents, final JingleContentInfo mi,
|
public Jingle(final List<JingleContent> contents, final JingleContentInfo mi,
|
||||||
final String sid) {
|
final String sid) {
|
||||||
super();
|
this();
|
||||||
|
|
||||||
if (contents != null) {
|
if (contents != null) {
|
||||||
contents.addAll(contents);
|
contents.addAll(contents);
|
||||||
|
@ -87,7 +87,7 @@ public class Jingle extends IQ {
|
||||||
* @param content a content
|
* @param content a content
|
||||||
*/
|
*/
|
||||||
public Jingle(final JingleContent content) {
|
public Jingle(final JingleContent content) {
|
||||||
super();
|
this();
|
||||||
|
|
||||||
addContent(content);
|
addContent(content);
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ public class Jingle extends IQ {
|
||||||
* @param info The content info
|
* @param info The content info
|
||||||
*/
|
*/
|
||||||
public Jingle(final JingleContentInfo info) {
|
public Jingle(final JingleContentInfo info) {
|
||||||
super();
|
this();
|
||||||
|
|
||||||
setContentInfo(info);
|
setContentInfo(info);
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ public class Jingle extends IQ {
|
||||||
* The default constructor
|
* The default constructor
|
||||||
*/
|
*/
|
||||||
public Jingle() {
|
public Jingle() {
|
||||||
super();
|
super(NODENAME, NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -338,11 +338,7 @@ public class Jingle extends IQ {
|
||||||
*
|
*
|
||||||
* @return the XML string
|
* @return the XML string
|
||||||
*/
|
*/
|
||||||
public String getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
|
|
||||||
buf.append("<").append(getElementName());
|
|
||||||
buf.append(" xmlns=\"").append(getNamespace()).append("\"");
|
|
||||||
if (getInitiator() != null) {
|
if (getInitiator() != null) {
|
||||||
buf.append(" initiator=\"").append(getInitiator()).append("\"");
|
buf.append(" initiator=\"").append(getInitiator()).append("\"");
|
||||||
}
|
}
|
||||||
|
@ -350,7 +346,7 @@ public class Jingle extends IQ {
|
||||||
buf.append(" responder=\"").append(getResponder()).append("\"");
|
buf.append(" responder=\"").append(getResponder()).append("\"");
|
||||||
}
|
}
|
||||||
if (getAction() != null) {
|
if (getAction() != null) {
|
||||||
buf.append(" action=\"").append(getAction()).append("\"");
|
buf.append(" action=\"").append(getAction().name()).append("\"");
|
||||||
}
|
}
|
||||||
if (getSid() != null) {
|
if (getSid() != null) {
|
||||||
buf.append(" sid=\"").append(getSid()).append("\"");
|
buf.append(" sid=\"").append(getSid()).append("\"");
|
||||||
|
@ -368,7 +364,6 @@ public class Jingle extends IQ {
|
||||||
buf.append(contentInfo.toXML());
|
buf.append(contentInfo.toXML());
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.append("</").append(getElementName()).append(">");
|
return buf;
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -781,13 +781,7 @@ public class AgentSession {
|
||||||
}
|
}
|
||||||
else if (packet instanceof OfferRevokeProvider.OfferRevokePacket) {
|
else if (packet instanceof OfferRevokeProvider.OfferRevokePacket) {
|
||||||
// Acknowledge the IQ set.
|
// Acknowledge the IQ set.
|
||||||
IQ reply = new IQ() {
|
IQ reply = IQ.createResultIQ((OfferRevokeProvider.OfferRevokePacket) packet);
|
||||||
public String getChildElementXML() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
reply.setPacketID(packet.getPacketID());
|
|
||||||
reply.setType(IQ.Type.result);
|
|
||||||
connection.sendPacket(reply);
|
connection.sendPacket(reply);
|
||||||
|
|
||||||
fireOfferRevokeEvent((OfferRevokeProvider.OfferRevokePacket)packet);
|
fireOfferRevokeEvent((OfferRevokeProvider.OfferRevokePacket)packet);
|
||||||
|
@ -962,12 +956,7 @@ public class AgentSession {
|
||||||
public void sendRoomInvitation(RoomInvitation.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException
|
public void sendRoomInvitation(RoomInvitation.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException
|
||||||
{
|
{
|
||||||
final RoomInvitation invitation = new RoomInvitation(type, invitee, sessionID, reason);
|
final RoomInvitation invitation = new RoomInvitation(type, invitee, sessionID, reason);
|
||||||
IQ iq = new IQ() {
|
IQ iq = new RoomInvitation.RoomInvitationIQ(invitation);
|
||||||
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return invitation.toXML();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
iq.setType(IQ.Type.set);
|
iq.setType(IQ.Type.set);
|
||||||
iq.setTo(workgroupJID);
|
iq.setTo(workgroupJID);
|
||||||
iq.setFrom(connection.getUser());
|
iq.setFrom(connection.getUser());
|
||||||
|
@ -1004,12 +993,7 @@ public class AgentSession {
|
||||||
public void sendRoomTransfer(RoomTransfer.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException
|
public void sendRoomTransfer(RoomTransfer.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException
|
||||||
{
|
{
|
||||||
final RoomTransfer transfer = new RoomTransfer(type, invitee, sessionID, reason);
|
final RoomTransfer transfer = new RoomTransfer(type, invitee, sessionID, reason);
|
||||||
IQ iq = new IQ() {
|
IQ iq = new RoomTransfer.RoomTransferIQ(transfer);
|
||||||
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return transfer.toXML();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
iq.setType(IQ.Type.set);
|
iq.setType(IQ.Type.set);
|
||||||
iq.setTo(workgroupJID);
|
iq.setTo(workgroupJID);
|
||||||
iq.setFrom(connection.getUser());
|
iq.setFrom(connection.getUser());
|
||||||
|
|
|
@ -194,13 +194,16 @@ public class Offer {
|
||||||
private class RejectPacket extends IQ {
|
private class RejectPacket extends IQ {
|
||||||
|
|
||||||
RejectPacket(String workgroup) {
|
RejectPacket(String workgroup) {
|
||||||
|
super("offer-reject", "http://jabber.org/protocol/workgroup");
|
||||||
this.setTo(workgroup);
|
this.setTo(workgroup);
|
||||||
this.setType(IQ.Type.set);
|
this.setType(IQ.Type.set);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
return "<offer-reject id=\"" + Offer.this.getSessionID() +
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
"\" xmlns=\"http://jabber.org/protocol/workgroup" + "\"/>";
|
xml.attribute("id", Offer.this.getSessionID());
|
||||||
|
xml.setEmptyElement();
|
||||||
|
return xml;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,13 +213,16 @@ public class Offer {
|
||||||
private class AcceptPacket extends IQ {
|
private class AcceptPacket extends IQ {
|
||||||
|
|
||||||
AcceptPacket(String workgroup) {
|
AcceptPacket(String workgroup) {
|
||||||
|
super("offer-accept", "http://jabber.org/protocol/workgroup");
|
||||||
this.setTo(workgroup);
|
this.setTo(workgroup);
|
||||||
this.setType(IQ.Type.set);
|
this.setType(IQ.Type.set);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
return "<offer-accept id=\"" + Offer.this.getSessionID() +
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
"\" xmlns=\"http://jabber.org/protocol/workgroup" + "\"/>";
|
xml.attribute("id", Offer.this.getSessionID());
|
||||||
|
xml.setEmptyElement();
|
||||||
|
return xml;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,15 +22,20 @@ import java.io.IOException;
|
||||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
import org.jivesoftware.smack.packet.SimpleIQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
|
||||||
public class OfferConfirmation extends IQ {
|
public class OfferConfirmation extends SimpleIQ {
|
||||||
private String userJID;
|
private String userJID;
|
||||||
private long sessionID;
|
private long sessionID;
|
||||||
|
|
||||||
|
public OfferConfirmation() {
|
||||||
|
super("offer-confirmation", "http://jabber.org/protocol/workgroup");
|
||||||
|
}
|
||||||
|
|
||||||
public String getUserJID() {
|
public String getUserJID() {
|
||||||
return userJID;
|
return userJID;
|
||||||
}
|
}
|
||||||
|
@ -53,13 +58,6 @@ public class OfferConfirmation extends IQ {
|
||||||
con.sendPacket(packet);
|
con.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
buf.append("<offer-confirmation xmlns=\"http://jabber.org/protocol/workgroup\">");
|
|
||||||
buf.append("</offer-confirmation>");
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Provider extends IQProvider<OfferConfirmation> {
|
public static class Provider extends IQProvider<OfferConfirmation> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,14 +101,18 @@ public class OfferConfirmation extends IQ {
|
||||||
String roomName;
|
String roomName;
|
||||||
|
|
||||||
NotifyServicePacket(String workgroup, String roomName) {
|
NotifyServicePacket(String workgroup, String roomName) {
|
||||||
|
super("offer-confirmation", "http://jabber.org/protocol/workgroup");
|
||||||
this.setTo(workgroup);
|
this.setTo(workgroup);
|
||||||
this.setType(IQ.Type.result);
|
this.setType(IQ.Type.result);
|
||||||
|
|
||||||
this.roomName = roomName;
|
this.roomName = roomName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
return "<offer-confirmation roomname=\"" + roomName + "\" xmlns=\"http://jabber.org/protocol/workgroup" + "\"/>";
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
|
xml.attribute("roomname", roomName);
|
||||||
|
xml.setEmptyElement();
|
||||||
|
return xml;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,13 +20,13 @@ package org.jivesoftware.smackx.workgroup.ext.forms;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.SimpleIQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
public class WorkgroupForm extends IQ {
|
public class WorkgroupForm extends SimpleIQ {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Element name of the packet extension.
|
* Element name of the packet extension.
|
||||||
|
@ -38,15 +38,8 @@ public class WorkgroupForm extends IQ {
|
||||||
*/
|
*/
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
public String getChildElementXML() {
|
public WorkgroupForm() {
|
||||||
StringBuilder buf = new StringBuilder();
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
|
|
||||||
// Add packet extensions, if any are defined.
|
|
||||||
buf.append(getExtensionsXML());
|
|
||||||
buf.append("</").append(ELEMENT_NAME).append("> ");
|
|
||||||
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,34 +33,6 @@ import java.util.List;
|
||||||
* to one or more jids and therefore retrievable.
|
* to one or more jids and therefore retrievable.
|
||||||
*/
|
*/
|
||||||
public class AgentChatHistory extends IQ {
|
public class AgentChatHistory extends IQ {
|
||||||
private String agentJID;
|
|
||||||
private int maxSessions;
|
|
||||||
private long startDate;
|
|
||||||
|
|
||||||
private List<AgentChatSession> agentChatSessions = new ArrayList<AgentChatSession>();
|
|
||||||
|
|
||||||
public AgentChatHistory(String agentJID, int maxSessions, Date startDate) {
|
|
||||||
this.agentJID = agentJID;
|
|
||||||
this.maxSessions = maxSessions;
|
|
||||||
this.startDate = startDate.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AgentChatHistory(String agentJID, int maxSessions) {
|
|
||||||
this.agentJID = agentJID;
|
|
||||||
this.maxSessions = maxSessions;
|
|
||||||
this.startDate = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AgentChatHistory() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addChatSession(AgentChatSession chatSession) {
|
|
||||||
agentChatSessions.add(chatSession);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<AgentChatSession> getAgentChatSessions() {
|
|
||||||
return agentChatSessions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Element name of the packet extension.
|
* Element name of the packet extension.
|
||||||
|
@ -72,19 +44,45 @@ public class AgentChatHistory extends IQ {
|
||||||
*/
|
*/
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
public String getChildElementXML() {
|
private String agentJID;
|
||||||
StringBuilder buf = new StringBuilder();
|
private int maxSessions;
|
||||||
|
private long startDate;
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
|
private List<AgentChatSession> agentChatSessions = new ArrayList<AgentChatSession>();
|
||||||
buf.append('"');
|
|
||||||
buf.append(NAMESPACE);
|
public AgentChatHistory(String agentJID, int maxSessions, Date startDate) {
|
||||||
buf.append('"');
|
this();
|
||||||
|
this.agentJID = agentJID;
|
||||||
|
this.maxSessions = maxSessions;
|
||||||
|
this.startDate = startDate.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AgentChatHistory(String agentJID, int maxSessions) {
|
||||||
|
this();
|
||||||
|
this.agentJID = agentJID;
|
||||||
|
this.maxSessions = maxSessions;
|
||||||
|
this.startDate = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AgentChatHistory() {
|
||||||
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addChatSession(AgentChatSession chatSession) {
|
||||||
|
agentChatSessions.add(chatSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<AgentChatSession> getAgentChatSessions() {
|
||||||
|
return agentChatSessions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append(" agentJID=\"" + agentJID + "\"");
|
buf.append(" agentJID=\"" + agentJID + "\"");
|
||||||
buf.append(" maxSessions=\"" + maxSessions + "\"");
|
buf.append(" maxSessions=\"" + maxSessions + "\"");
|
||||||
buf.append(" startDate=\"" + startDate + "\"");
|
buf.append(" startDate=\"" + startDate + "\"");
|
||||||
|
buf.setEmptyElement();
|
||||||
buf.append("></").append(ELEMENT_NAME).append("> ");
|
return buf;
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,6 +43,10 @@ public class ChatMetadata extends IQ {
|
||||||
|
|
||||||
private String sessionID;
|
private String sessionID;
|
||||||
|
|
||||||
|
public ChatMetadata() {
|
||||||
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
public String getSessionID() {
|
public String getSessionID() {
|
||||||
return sessionID;
|
return sessionID;
|
||||||
}
|
}
|
||||||
|
@ -62,15 +66,12 @@ public class ChatMetadata extends IQ {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getChildElementXML() {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
StringBuilder buf = new StringBuilder();
|
buf.rightAngleBracket();
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
|
|
||||||
buf.append("<sessionID>").append(getSessionID()).append("</sessionID>");
|
buf.append("<sessionID>").append(getSessionID()).append("</sessionID>");
|
||||||
buf.append("</").append(ELEMENT_NAME).append("> ");
|
|
||||||
|
|
||||||
return buf.toString();
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,10 +33,24 @@ import org.xmlpull.v1.XmlPullParser;
|
||||||
*/
|
*/
|
||||||
public class Macros extends IQ {
|
public class Macros extends IQ {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Element name of the packet extension.
|
||||||
|
*/
|
||||||
|
public static final String ELEMENT_NAME = "macros";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace of the packet extension.
|
||||||
|
*/
|
||||||
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
private MacroGroup rootGroup;
|
private MacroGroup rootGroup;
|
||||||
private boolean personal;
|
private boolean personal;
|
||||||
private MacroGroup personalMacroGroup;
|
private MacroGroup personalMacroGroup;
|
||||||
|
|
||||||
|
public Macros() {
|
||||||
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
public MacroGroup getRootGroup() {
|
public MacroGroup getRootGroup() {
|
||||||
return rootGroup;
|
return rootGroup;
|
||||||
}
|
}
|
||||||
|
@ -61,21 +75,10 @@ public class Macros extends IQ {
|
||||||
this.personalMacroGroup = personalMacroGroup;
|
this.personalMacroGroup = personalMacroGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
|
buf.rightAngleBracket();
|
||||||
|
|
||||||
/**
|
|
||||||
* Element name of the packet extension.
|
|
||||||
*/
|
|
||||||
public static final String ELEMENT_NAME = "macros";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Namespace of the packet extension.
|
|
||||||
*/
|
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
|
||||||
|
|
||||||
public String getChildElementXML() {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
|
|
||||||
if (isPersonal()) {
|
if (isPersonal()) {
|
||||||
buf.append("<personal>true</personal>");
|
buf.append("<personal>true</personal>");
|
||||||
}
|
}
|
||||||
|
@ -84,9 +87,8 @@ public class Macros extends IQ {
|
||||||
buf.append(StringUtils.escapeForXML(getPersonalMacroGroup().toXML()));
|
buf.append(StringUtils.escapeForXML(getPersonalMacroGroup().toXML()));
|
||||||
buf.append("</personalMacro>");
|
buf.append("</personalMacro>");
|
||||||
}
|
}
|
||||||
buf.append("</").append(ELEMENT_NAME).append("> ");
|
|
||||||
|
|
||||||
return buf.toString();
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,7 +21,6 @@ import java.io.IOException;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
@ -40,6 +39,9 @@ public class ChatNotes extends IQ {
|
||||||
*/
|
*/
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
|
public ChatNotes() {
|
||||||
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
private String sessionID;
|
private String sessionID;
|
||||||
private String notes;
|
private String notes;
|
||||||
|
@ -60,18 +62,17 @@ public class ChatNotes extends IQ {
|
||||||
this.notes = notes;
|
this.notes = notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
XmlStringBuilder buf = new XmlStringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
|
buf.rightAngleBracket();
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
|
|
||||||
buf.append("<sessionID>").append(getSessionID()).append("</sessionID>");
|
buf.append("<sessionID>").append(getSessionID()).append("</sessionID>");
|
||||||
|
|
||||||
if (getNotes() != null) {
|
if (getNotes() != null) {
|
||||||
buf.element("notes", getNotes());
|
buf.element("notes", getNotes());
|
||||||
}
|
}
|
||||||
buf.append("</").append(ELEMENT_NAME).append("> ");
|
|
||||||
|
|
||||||
return buf.toString();
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -42,6 +42,10 @@ public class AgentInfo extends IQ {
|
||||||
private String jid;
|
private String jid;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
public AgentInfo() {
|
||||||
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Agent's jid.
|
* Returns the Agent's jid.
|
||||||
*
|
*
|
||||||
|
@ -80,19 +84,18 @@ public class AgentInfo extends IQ {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
|
buf.rightAngleBracket();
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
|
|
||||||
if (jid != null) {
|
if (jid != null) {
|
||||||
buf.append("<jid>").append(getJid()).append("</jid>");
|
buf.append("<jid>").append(getJid()).append("</jid>");
|
||||||
}
|
}
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
buf.append("<name>").append(getName()).append("</name>");
|
buf.append("<name>").append(getName()).append("</name>");
|
||||||
}
|
}
|
||||||
buf.append("</").append(ELEMENT_NAME).append("> ");
|
|
||||||
|
|
||||||
return buf.toString();
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -50,6 +50,7 @@ public class AgentStatusRequest extends IQ {
|
||||||
private Set<Item> agents;
|
private Set<Item> agents;
|
||||||
|
|
||||||
public AgentStatusRequest() {
|
public AgentStatusRequest() {
|
||||||
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
agents = new HashSet<Item>();
|
agents = new HashSet<Item>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,9 +70,9 @@ public class AgentStatusRequest extends IQ {
|
||||||
return NAMESPACE;
|
return NAMESPACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
|
buf.rightAngleBracket();
|
||||||
synchronized (agents) {
|
synchronized (agents) {
|
||||||
for (Iterator<Item> i=agents.iterator(); i.hasNext(); ) {
|
for (Iterator<Item> i=agents.iterator(); i.hasNext(); ) {
|
||||||
Item item = (Item) i.next();
|
Item item = (Item) i.next();
|
||||||
|
@ -84,8 +85,7 @@ public class AgentStatusRequest extends IQ {
|
||||||
buf.append("</agent>");
|
buf.append("</agent>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf.append("</").append(this.getElementName()).append("> ");
|
return buf;
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Item {
|
public static class Item {
|
||||||
|
|
|
@ -40,6 +40,10 @@ public class AgentWorkgroups extends IQ {
|
||||||
private String agentJID;
|
private String agentJID;
|
||||||
private List<String> workgroups;
|
private List<String> workgroups;
|
||||||
|
|
||||||
|
private AgentWorkgroups() {
|
||||||
|
super("workgroups", "http://jabber.org/protocol/workgroup");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an AgentWorkgroups request for the given agent. This IQ will be sent and an answer
|
* Creates an AgentWorkgroups request for the given agent. This IQ will be sent and an answer
|
||||||
* will be received with the jid of the workgroups where the agent can work.
|
* will be received with the jid of the workgroups where the agent can work.
|
||||||
|
@ -47,6 +51,7 @@ public class AgentWorkgroups extends IQ {
|
||||||
* @param agentJID the id of the agent to get his workgroups.
|
* @param agentJID the id of the agent to get his workgroups.
|
||||||
*/
|
*/
|
||||||
public AgentWorkgroups(String agentJID) {
|
public AgentWorkgroups(String agentJID) {
|
||||||
|
this();
|
||||||
this.agentJID = agentJID;
|
this.agentJID = agentJID;
|
||||||
this.workgroups = new ArrayList<String>();
|
this.workgroups = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
@ -59,6 +64,7 @@ public class AgentWorkgroups extends IQ {
|
||||||
* @param workgroups the list of workgroup JIDs where the agent can work.
|
* @param workgroups the list of workgroup JIDs where the agent can work.
|
||||||
*/
|
*/
|
||||||
public AgentWorkgroups(String agentJID, List<String> workgroups) {
|
public AgentWorkgroups(String agentJID, List<String> workgroups) {
|
||||||
|
this();
|
||||||
this.agentJID = agentJID;
|
this.agentJID = agentJID;
|
||||||
this.workgroups = workgroups;
|
this.workgroups = workgroups;
|
||||||
}
|
}
|
||||||
|
@ -76,21 +82,16 @@ public class AgentWorkgroups extends IQ {
|
||||||
return Collections.unmodifiableList(workgroups);
|
return Collections.unmodifiableList(workgroups);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
|
buf.attribute("jid", agentJID).rightAngleBracket();
|
||||||
buf.append("<workgroups xmlns=\"http://jabber.org/protocol/workgroup\" jid=\"")
|
|
||||||
.append(agentJID)
|
|
||||||
.append("\">");
|
|
||||||
|
|
||||||
for (Iterator<String> it=workgroups.iterator(); it.hasNext();) {
|
for (Iterator<String> it=workgroups.iterator(); it.hasNext();) {
|
||||||
String workgroupJID = it.next();
|
String workgroupJID = it.next();
|
||||||
buf.append("<workgroup jid=\"" + workgroupJID + "\"/>");
|
buf.append("<workgroup jid=\"" + workgroupJID + "\"/>");
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.append("</workgroups>");
|
return buf;
|
||||||
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -34,6 +34,10 @@ public class DepartQueuePacket extends IQ {
|
||||||
|
|
||||||
private String user;
|
private String user;
|
||||||
|
|
||||||
|
private DepartQueuePacket() {
|
||||||
|
super("depart-queue", "http://jabber.org/protocol/workgroup");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a depart queue request packet to the specified workgroup.
|
* Creates a depart queue request packet to the specified workgroup.
|
||||||
*
|
*
|
||||||
|
@ -51,6 +55,7 @@ public class DepartQueuePacket extends IQ {
|
||||||
* @param user the user to make depart from the queue.
|
* @param user the user to make depart from the queue.
|
||||||
*/
|
*/
|
||||||
public DepartQueuePacket(String workgroup, String user) {
|
public DepartQueuePacket(String workgroup, String user) {
|
||||||
|
this();
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
|
||||||
setTo(workgroup);
|
setTo(workgroup);
|
||||||
|
@ -58,16 +63,14 @@ public class DepartQueuePacket extends IQ {
|
||||||
setFrom(user);
|
setFrom(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder("<depart-queue xmlns=\"http://jabber.org/protocol/workgroup\"");
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
|
buf.rightAngleBracket();
|
||||||
|
|
||||||
if (this.user != null) {
|
if (this.user != null) {
|
||||||
buf.append("><jid>").append(this.user).append("</jid></depart-queue>");
|
buf.append("<jid>").append(this.user).append("</jid>");
|
||||||
}
|
|
||||||
else {
|
|
||||||
buf.append("/>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.toString();
|
return buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,27 +55,19 @@ public class MonitorPacket extends IQ {
|
||||||
*/
|
*/
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
public String getElementName() {
|
public MonitorPacket() {
|
||||||
return ELEMENT_NAME;
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNamespace() {
|
@Override
|
||||||
return NAMESPACE;
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
}
|
buf.rightAngleBracket();
|
||||||
|
|
||||||
public String getChildElementXML() {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
|
|
||||||
buf.append('"');
|
|
||||||
buf.append(NAMESPACE);
|
|
||||||
buf.append('"');
|
|
||||||
buf.append(">");
|
|
||||||
if (sessionID != null) {
|
if (sessionID != null) {
|
||||||
buf.append("<makeOwner sessionID=\""+sessionID+"\"></makeOwner>");
|
buf.append("<makeOwner sessionID=\""+sessionID+"\"></makeOwner>");
|
||||||
}
|
}
|
||||||
buf.append("</").append(ELEMENT_NAME).append("> ");
|
|
||||||
return buf.toString();
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ public class OccupantsInfo extends IQ {
|
||||||
private final Set<OccupantInfo> occupants;
|
private final Set<OccupantInfo> occupants;
|
||||||
|
|
||||||
public OccupantsInfo(String roomID) {
|
public OccupantsInfo(String roomID) {
|
||||||
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
this.roomID = roomID;
|
this.roomID = roomID;
|
||||||
this.occupants = new HashSet<OccupantInfo>();
|
this.occupants = new HashSet<OccupantInfo>();
|
||||||
}
|
}
|
||||||
|
@ -76,9 +77,8 @@ public class OccupantsInfo extends IQ {
|
||||||
return Collections.unmodifiableSet(occupants);
|
return Collections.unmodifiableSet(occupants);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE);
|
|
||||||
buf.append("\" roomID=\"").append(roomID).append("\">");
|
buf.append("\" roomID=\"").append(roomID).append("\">");
|
||||||
synchronized (occupants) {
|
synchronized (occupants) {
|
||||||
for (OccupantInfo occupant : occupants) {
|
for (OccupantInfo occupant : occupants) {
|
||||||
|
@ -98,8 +98,7 @@ public class OccupantsInfo extends IQ {
|
||||||
buf.append("</occupant>");
|
buf.append("</occupant>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf.append("</").append(ELEMENT_NAME).append("> ");
|
return buf;
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class OccupantInfo {
|
public static class OccupantInfo {
|
||||||
|
|
|
@ -122,6 +122,7 @@ public class OfferRequestProvider extends IQProvider<IQ> {
|
||||||
public OfferRequestPacket(String userJID, String userID, int timeout, Map<String, List<String>> metaData,
|
public OfferRequestPacket(String userJID, String userID, int timeout, Map<String, List<String>> metaData,
|
||||||
String sessionID, OfferContent content)
|
String sessionID, OfferContent content)
|
||||||
{
|
{
|
||||||
|
super("offer", "http://jabber.org/protocol/workgroup");
|
||||||
this.userJID = userJID;
|
this.userJID = userJID;
|
||||||
this.userID = userID;
|
this.userID = userID;
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
|
@ -182,11 +183,10 @@ public class OfferRequestProvider extends IQProvider<IQ> {
|
||||||
return this.metaData;
|
return this.metaData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML () {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
|
buf.append(" jid=\"").append(userJID).append("\">");
|
||||||
buf.append("<offer xmlns=\"http://jabber.org/protocol/workgroup\" jid=\"").append(userJID).append("\">");
|
buf.append("<timeout>").append(Integer.toString(timeout)).append("</timeout>");
|
||||||
buf.append("<timeout>").append(timeout).append("</timeout>");
|
|
||||||
|
|
||||||
if (sessionID != null) {
|
if (sessionID != null) {
|
||||||
buf.append('<').append(SessionID.ELEMENT_NAME);
|
buf.append('<').append(SessionID.ELEMENT_NAME);
|
||||||
|
@ -206,9 +206,7 @@ public class OfferRequestProvider extends IQProvider<IQ> {
|
||||||
buf.append(UserID.NAMESPACE).append("\"/>");
|
buf.append(UserID.NAMESPACE).append("\"/>");
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.append("</offer>");
|
return buf;
|
||||||
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ public class OfferRevokeProvider extends IQProvider<IQ> {
|
||||||
private String reason;
|
private String reason;
|
||||||
|
|
||||||
public OfferRevokePacket (String userJID, String userID, String cause, String sessionID) {
|
public OfferRevokePacket (String userJID, String userID, String cause, String sessionID) {
|
||||||
|
super("offer-revoke", "http://jabber.org/protocol/workgroup");
|
||||||
this.userJID = userJID;
|
this.userJID = userJID;
|
||||||
this.userID = userID;
|
this.userID = userID;
|
||||||
this.reason = cause;
|
this.reason = cause;
|
||||||
|
@ -95,9 +96,9 @@ public class OfferRevokeProvider extends IQProvider<IQ> {
|
||||||
return this.sessionID;
|
return this.sessionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML () {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append("<offer-revoke xmlns=\"http://jabber.org/protocol/workgroup\" jid=\"").append(userID).append("\">");
|
buf.append(" jid=\"").append(userID).append("\">");
|
||||||
if (reason != null) {
|
if (reason != null) {
|
||||||
buf.append("<reason>").append(reason).append("</reason>");
|
buf.append("<reason>").append(reason).append("</reason>");
|
||||||
}
|
}
|
||||||
|
@ -107,8 +108,7 @@ public class OfferRevokeProvider extends IQProvider<IQ> {
|
||||||
if (userID != null) {
|
if (userID != null) {
|
||||||
buf.append(new UserID(userID).toXML());
|
buf.append(new UserID(userID).toXML());
|
||||||
}
|
}
|
||||||
buf.append("</offer-revoke>");
|
return buf;
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,11 @@ package org.jivesoftware.smackx.workgroup.packet;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
|
import org.jivesoftware.smack.packet.IQ.IQChildElementXmlStringBuilder;
|
||||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||||
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
@ -101,11 +104,15 @@ public class RoomInvitation implements PacketExtension {
|
||||||
return sessionID;
|
return sessionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
public XmlStringBuilder toXML() {
|
||||||
|
XmlStringBuilder xml = getIQChildElementBuilder(new IQChildElementXmlStringBuilder(this));
|
||||||
|
xml.closeElement(this);
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE);
|
public IQ.IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append("\" type=\"").append(type).append("\">");
|
buf.append("\" type=\"").append(type.name()).append("\">");
|
||||||
buf.append("<session xmlns=\"http://jivesoftware.com/protocol/workgroup\" id=\"").append(sessionID).append("\"></session>");
|
buf.append("<session xmlns=\"http://jivesoftware.com/protocol/workgroup\" id=\"").append(sessionID).append("\"></session>");
|
||||||
if (invitee != null) {
|
if (invitee != null) {
|
||||||
buf.append("<invitee>").append(invitee).append("</invitee>");
|
buf.append("<invitee>").append(invitee).append("</invitee>");
|
||||||
|
@ -116,10 +123,8 @@ public class RoomInvitation implements PacketExtension {
|
||||||
if (reason != null) {
|
if (reason != null) {
|
||||||
buf.append("<reason>").append(reason).append("</reason>");
|
buf.append("<reason>").append(reason).append("</reason>");
|
||||||
}
|
}
|
||||||
// Add packet extensions, if any are defined.
|
|
||||||
buf.append("</").append(ELEMENT_NAME).append("> ");
|
|
||||||
|
|
||||||
return buf.toString();
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,6 +146,18 @@ public class RoomInvitation implements PacketExtension {
|
||||||
workgroup
|
workgroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class RoomInvitationIQ extends IQ {
|
||||||
|
private final RoomInvitation roomInvitation;
|
||||||
|
public RoomInvitationIQ(RoomInvitation roomInvitation) {
|
||||||
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
this.roomInvitation = roomInvitation;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
|
return roomInvitation.getIQChildElementBuilder(xml);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class Provider extends PacketExtensionProvider<RoomInvitation> {
|
public static class Provider extends PacketExtensionProvider<RoomInvitation> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,8 +19,11 @@ package org.jivesoftware.smackx.workgroup.packet;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
|
import org.jivesoftware.smack.packet.IQ.IQChildElementXmlStringBuilder;
|
||||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||||
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
@ -101,11 +104,15 @@ public class RoomTransfer implements PacketExtension {
|
||||||
return sessionID;
|
return sessionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
public XmlStringBuilder toXML() {
|
||||||
|
XmlStringBuilder xml = getIQChildElementBuilder(new IQChildElementXmlStringBuilder(this));
|
||||||
|
xml.closeElement(this);
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE);
|
public IQ.IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append("\" type=\"").append(type).append("\">");
|
buf.append("\" type=\"").append(type.name()).append("\">");
|
||||||
buf.append("<session xmlns=\"http://jivesoftware.com/protocol/workgroup\" id=\"").append(sessionID).append("\"></session>");
|
buf.append("<session xmlns=\"http://jivesoftware.com/protocol/workgroup\" id=\"").append(sessionID).append("\"></session>");
|
||||||
if (invitee != null) {
|
if (invitee != null) {
|
||||||
buf.append("<invitee>").append(invitee).append("</invitee>");
|
buf.append("<invitee>").append(invitee).append("</invitee>");
|
||||||
|
@ -116,10 +123,8 @@ public class RoomTransfer implements PacketExtension {
|
||||||
if (reason != null) {
|
if (reason != null) {
|
||||||
buf.append("<reason>").append(reason).append("</reason>");
|
buf.append("<reason>").append(reason).append("</reason>");
|
||||||
}
|
}
|
||||||
// Add packet extensions, if any are defined.
|
|
||||||
buf.append("</").append(ELEMENT_NAME).append("> ");
|
|
||||||
|
|
||||||
return buf.toString();
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,6 +146,18 @@ public class RoomTransfer implements PacketExtension {
|
||||||
workgroup
|
workgroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class RoomTransferIQ extends IQ {
|
||||||
|
private final RoomTransfer roomTransfer;
|
||||||
|
public RoomTransferIQ(RoomTransfer roomTransfer) {
|
||||||
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
this.roomTransfer = roomTransfer;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
|
return roomTransfer.getIQChildElementBuilder(xml);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class Provider extends PacketExtensionProvider<RoomTransfer> {
|
public static class Provider extends PacketExtensionProvider<RoomTransfer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -42,8 +42,7 @@ public class Transcript extends IQ {
|
||||||
* @param sessionID the id of the session to get the conversation transcript.
|
* @param sessionID the id of the session to get the conversation transcript.
|
||||||
*/
|
*/
|
||||||
public Transcript(String sessionID) {
|
public Transcript(String sessionID) {
|
||||||
this.sessionID = sessionID;
|
this(sessionID, new ArrayList<Packet>());
|
||||||
this.packets = new ArrayList<Packet>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,6 +53,7 @@ public class Transcript extends IQ {
|
||||||
* @param packets the list of messages and presences send to the room.
|
* @param packets the list of messages and presences send to the room.
|
||||||
*/
|
*/
|
||||||
public Transcript(String sessionID, List<Packet> packets) {
|
public Transcript(String sessionID, List<Packet> packets) {
|
||||||
|
super("transcript", "http://jabber.org/protocol/workgroup");
|
||||||
this.sessionID = sessionID;
|
this.sessionID = sessionID;
|
||||||
this.packets = packets;
|
this.packets = packets;
|
||||||
}
|
}
|
||||||
|
@ -77,10 +77,9 @@ public class Transcript extends IQ {
|
||||||
return Collections.unmodifiableList(packets);
|
return Collections.unmodifiableList(packets);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
|
buf.append(" sessionID=\"")
|
||||||
buf.append("<transcript xmlns=\"http://jivesoftware.com/protocol/workgroup\" sessionID=\"")
|
|
||||||
.append(sessionID)
|
.append(sessionID)
|
||||||
.append("\">");
|
.append("\">");
|
||||||
|
|
||||||
|
@ -89,8 +88,6 @@ public class Transcript extends IQ {
|
||||||
buf.append(packet.toXML());
|
buf.append(packet.toXML());
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.append("</transcript>");
|
return buf;
|
||||||
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.jivesoftware.smackx.workgroup.packet;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.SimpleIQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
@ -32,7 +32,7 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||||
*
|
*
|
||||||
* @author Gaston Dombiak
|
* @author Gaston Dombiak
|
||||||
*/
|
*/
|
||||||
public class TranscriptSearch extends IQ {
|
public class TranscriptSearch extends SimpleIQ {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Element name of the packet extension.
|
* Element name of the packet extension.
|
||||||
|
@ -44,16 +44,9 @@ public class TranscriptSearch extends IQ {
|
||||||
*/
|
*/
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
public String getChildElementXML() {
|
public TranscriptSearch() {
|
||||||
StringBuilder buf = new StringBuilder();
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
}
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
|
|
||||||
// Add packet extensions, if any are defined.
|
|
||||||
buf.append(getExtensionsXML());
|
|
||||||
buf.append("</").append(ELEMENT_NAME).append("> ");
|
|
||||||
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An IQProvider for TranscriptSearch packets.
|
* An IQProvider for TranscriptSearch packets.
|
||||||
|
|
|
@ -50,8 +50,7 @@ public class Transcripts extends IQ {
|
||||||
* @param userID the id of the user to get his conversations transcripts.
|
* @param userID the id of the user to get his conversations transcripts.
|
||||||
*/
|
*/
|
||||||
public Transcripts(String userID) {
|
public Transcripts(String userID) {
|
||||||
this.userID = userID;
|
this(userID, new ArrayList<Transcripts.TranscriptSummary>());
|
||||||
this.summaries = new ArrayList<Transcripts.TranscriptSummary>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,6 +61,7 @@ public class Transcripts extends IQ {
|
||||||
* @param summaries the list of TranscriptSummaries.
|
* @param summaries the list of TranscriptSummaries.
|
||||||
*/
|
*/
|
||||||
public Transcripts(String userID, List<Transcripts.TranscriptSummary> summaries) {
|
public Transcripts(String userID, List<Transcripts.TranscriptSummary> summaries) {
|
||||||
|
super("transcripts", "http://jabber.org/protocol/workgroup");
|
||||||
this.userID = userID;
|
this.userID = userID;
|
||||||
this.summaries = summaries;
|
this.summaries = summaries;
|
||||||
}
|
}
|
||||||
|
@ -90,10 +90,9 @@ public class Transcripts extends IQ {
|
||||||
return Collections.unmodifiableList(summaries);
|
return Collections.unmodifiableList(summaries);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
|
buf.append(" userID=\"")
|
||||||
buf.append("<transcripts xmlns=\"http://jivesoftware.com/protocol/workgroup\" userID=\"")
|
|
||||||
.append(userID)
|
.append(userID)
|
||||||
.append("\">");
|
.append("\">");
|
||||||
|
|
||||||
|
@ -101,9 +100,7 @@ public class Transcripts extends IQ {
|
||||||
buf.append(transcriptSummary.toXML());
|
buf.append(transcriptSummary.toXML());
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.append("</transcripts>");
|
return buf;
|
||||||
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -49,11 +49,23 @@ public class ChatSettings extends IQ {
|
||||||
private String key;
|
private String key;
|
||||||
private int type = -1;
|
private int type = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Element name of the packet extension.
|
||||||
|
*/
|
||||||
|
public static final String ELEMENT_NAME = "chat-settings";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace of the packet extension.
|
||||||
|
*/
|
||||||
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
public ChatSettings() {
|
public ChatSettings() {
|
||||||
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
settings = new ArrayList<ChatSetting>();
|
settings = new ArrayList<ChatSetting>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatSettings(String key) {
|
public ChatSettings(String key) {
|
||||||
|
this();
|
||||||
setKey(key);
|
setKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,24 +106,8 @@ public class ChatSettings extends IQ {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
/**
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
* Element name of the packet extension.
|
|
||||||
*/
|
|
||||||
public static final String ELEMENT_NAME = "chat-settings";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Namespace of the packet extension.
|
|
||||||
*/
|
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
|
||||||
|
|
||||||
public String getChildElementXML() {
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
|
|
||||||
buf.append('"');
|
|
||||||
buf.append(NAMESPACE);
|
|
||||||
buf.append('"');
|
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
buf.append(" key=\"" + key + "\"");
|
buf.append(" key=\"" + key + "\"");
|
||||||
}
|
}
|
||||||
|
@ -119,9 +115,8 @@ public class ChatSettings extends IQ {
|
||||||
if (type != -1) {
|
if (type != -1) {
|
||||||
buf.append(" type=\"" + type + "\"");
|
buf.append(" type=\"" + type + "\"");
|
||||||
}
|
}
|
||||||
|
buf.setEmptyElement();
|
||||||
buf.append("></").append(ELEMENT_NAME).append("> ");
|
return buf;
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -60,22 +60,19 @@ public class GenericSettings extends IQ {
|
||||||
*/
|
*/
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
public String getChildElementXML() {
|
public GenericSettings() {
|
||||||
StringBuilder buf = new StringBuilder();
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
|
@Override
|
||||||
buf.append('"');
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append(NAMESPACE);
|
|
||||||
buf.append('"');
|
|
||||||
buf.append(">");
|
buf.append(">");
|
||||||
if (ModelUtil.hasLength(getQuery())) {
|
if (ModelUtil.hasLength(getQuery())) {
|
||||||
buf.append("<query>" + getQuery() + "</query>");
|
buf.append("<query>" + getQuery() + "</query>");
|
||||||
}
|
}
|
||||||
buf.append("</").append(ELEMENT_NAME).append("> ");
|
return buf;
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Packet extension provider for SoundSetting Packets.
|
* Packet extension provider for SoundSetting Packets.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -20,12 +20,12 @@ package org.jivesoftware.smackx.workgroup.settings;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.workgroup.util.ModelUtil;
|
import org.jivesoftware.smackx.workgroup.util.ModelUtil;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.SimpleIQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
public class OfflineSettings extends IQ {
|
public class OfflineSettings extends SimpleIQ {
|
||||||
private String redirectURL;
|
private String redirectURL;
|
||||||
|
|
||||||
private String offlineText;
|
private String offlineText;
|
||||||
|
@ -96,18 +96,10 @@ public class OfflineSettings extends IQ {
|
||||||
*/
|
*/
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
public String getChildElementXML() {
|
public OfflineSettings() {
|
||||||
StringBuilder buf = new StringBuilder();
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
|
|
||||||
buf.append('"');
|
|
||||||
buf.append(NAMESPACE);
|
|
||||||
buf.append('"');
|
|
||||||
buf.append("></").append(ELEMENT_NAME).append("> ");
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Packet extension provider for AgentStatusRequest packets.
|
* Packet extension provider for AgentStatusRequest packets.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,12 +19,12 @@ package org.jivesoftware.smackx.workgroup.settings;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.workgroup.util.ModelUtil;
|
import org.jivesoftware.smackx.workgroup.util.ModelUtil;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.SimpleIQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
public class SearchSettings extends IQ {
|
public class SearchSettings extends SimpleIQ {
|
||||||
private String forumsLocation;
|
private String forumsLocation;
|
||||||
private String kbLocation;
|
private String kbLocation;
|
||||||
|
|
||||||
|
@ -67,18 +67,10 @@ public class SearchSettings extends IQ {
|
||||||
*/
|
*/
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
public String getChildElementXML() {
|
public SearchSettings() {
|
||||||
StringBuilder buf = new StringBuilder();
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
|
|
||||||
buf.append('"');
|
|
||||||
buf.append(NAMESPACE);
|
|
||||||
buf.append('"');
|
|
||||||
buf.append("></").append(ELEMENT_NAME).append("> ");
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Packet extension provider for AgentStatusRequest packets.
|
* Packet extension provider for AgentStatusRequest packets.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,13 +19,13 @@ package org.jivesoftware.smackx.workgroup.settings;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.SimpleIQ;
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
public class SoundSettings extends IQ {
|
public class SoundSettings extends SimpleIQ {
|
||||||
private String outgoingSound;
|
private String outgoingSound;
|
||||||
private String incomingSound;
|
private String incomingSound;
|
||||||
|
|
||||||
|
@ -57,18 +57,10 @@ public class SoundSettings extends IQ {
|
||||||
*/
|
*/
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
public String getChildElementXML() {
|
public SoundSettings() {
|
||||||
StringBuilder buf = new StringBuilder();
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
|
|
||||||
buf.append('"');
|
|
||||||
buf.append(NAMESPACE);
|
|
||||||
buf.append('"');
|
|
||||||
buf.append("></").append(ELEMENT_NAME).append("> ");
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Packet extension provider for SoundSetting Packets.
|
* Packet extension provider for SoundSetting Packets.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -75,18 +75,17 @@ public class WorkgroupProperties extends IQ {
|
||||||
*/
|
*/
|
||||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||||
|
|
||||||
public String getChildElementXML() {
|
public WorkgroupProperties() {
|
||||||
StringBuilder buf = new StringBuilder();
|
super(ELEMENT_NAME, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
|
@Override
|
||||||
buf.append('"');
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
buf.append(NAMESPACE);
|
|
||||||
buf.append('"');
|
|
||||||
if (ModelUtil.hasLength(getJid())) {
|
if (ModelUtil.hasLength(getJid())) {
|
||||||
buf.append("jid=\"" + getJid() + "\" ");
|
buf.append("jid=\"" + getJid() + "\" ");
|
||||||
}
|
}
|
||||||
buf.append("></").append(ELEMENT_NAME).append("> ");
|
buf.setEmptyElement();
|
||||||
return buf.toString();
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -577,6 +577,7 @@ public class Workgroup {
|
||||||
private DataForm form;
|
private DataForm form;
|
||||||
|
|
||||||
public JoinQueuePacket(String workgroup, Form answerForm, String userID) {
|
public JoinQueuePacket(String workgroup, Form answerForm, String userID) {
|
||||||
|
super("join-queue", "http://jabber.org/protocol/workgroup");
|
||||||
this.userID = userID;
|
this.userID = userID;
|
||||||
|
|
||||||
setTo(workgroup);
|
setTo(workgroup);
|
||||||
|
@ -586,10 +587,9 @@ public class Workgroup {
|
||||||
addExtension(form);
|
addExtension(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getChildElementXML() {
|
@Override
|
||||||
StringBuilder buf = new StringBuilder();
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||||
|
buf.rightAngleBracket();
|
||||||
buf.append("<join-queue xmlns=\"http://jabber.org/protocol/workgroup\">");
|
|
||||||
buf.append("<queue-notifications/>");
|
buf.append("<queue-notifications/>");
|
||||||
// Add the user unique identification if the session is anonymous
|
// Add the user unique identification if the session is anonymous
|
||||||
if (connection.isAnonymous()) {
|
if (connection.isAnonymous()) {
|
||||||
|
@ -599,9 +599,7 @@ public class Workgroup {
|
||||||
// Append data form text
|
// Append data form text
|
||||||
buf.append(form.toXML());
|
buf.append(form.toXML());
|
||||||
|
|
||||||
buf.append("</join-queue>");
|
return buf;
|
||||||
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue