mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-11 01:59:38 +02:00
New API design (SMACK-545)
This commit is contained in:
parent
201152ef42
commit
8d3814a8a7
152 changed files with 394 additions and 493 deletions
|
@ -31,12 +31,13 @@ import org.jivesoftware.smack.filter.PacketIDFilter;
|
|||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smackx.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||
|
||||
/**
|
||||
* Packet extension for XEP-0280: Message Carbons. This class implements
|
||||
* the manager for registering {@link Carbon} support, enabling and disabling
|
||||
* the manager for registering {@link CarbonExtension} support, enabling and disabling
|
||||
* message carbons.
|
||||
*
|
||||
* You should call enableCarbons() before sending your first undirected
|
||||
|
@ -62,7 +63,7 @@ public class CarbonManager {
|
|||
|
||||
private CarbonManager(Connection connection) {
|
||||
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
sdm.addFeature(Carbon.NAMESPACE);
|
||||
sdm.addFeature(CarbonExtension.NAMESPACE);
|
||||
weakRefConnection = new WeakReference<Connection>(connection);
|
||||
instances.put(connection, this);
|
||||
}
|
||||
|
@ -87,7 +88,7 @@ public class CarbonManager {
|
|||
private IQ carbonsEnabledIQ(final boolean new_state) {
|
||||
IQ setIQ = new IQ() {
|
||||
public String getChildElementXML() {
|
||||
return "<" + (new_state? "enable" : "disable") + " xmlns='" + Carbon.NAMESPACE + "'/>";
|
||||
return "<" + (new_state? "enable" : "disable") + " xmlns='" + CarbonExtension.NAMESPACE + "'/>";
|
||||
}
|
||||
};
|
||||
setIQ.setType(IQ.Type.SET);
|
||||
|
@ -104,7 +105,7 @@ public class CarbonManager {
|
|||
try {
|
||||
DiscoverInfo result = ServiceDiscoveryManager
|
||||
.getInstanceFor(connection).discoverInfo(connection.getServiceName());
|
||||
return result.containsFeature(Carbon.NAMESPACE);
|
||||
return result.containsFeature(CarbonExtension.NAMESPACE);
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
return false;
|
||||
|
@ -199,10 +200,10 @@ public class CarbonManager {
|
|||
*
|
||||
* @return a Carbon if available, null otherwise.
|
||||
*/
|
||||
public static Carbon getCarbon(Message msg) {
|
||||
Carbon cc = (Carbon)msg.getExtension("received", Carbon.NAMESPACE);
|
||||
public static CarbonExtension getCarbon(Message msg) {
|
||||
CarbonExtension cc = (CarbonExtension)msg.getExtension("received", CarbonExtension.NAMESPACE);
|
||||
if (cc == null)
|
||||
cc = (Carbon)msg.getExtension("sent", Carbon.NAMESPACE);
|
||||
cc = (CarbonExtension)msg.getExtension("sent", CarbonExtension.NAMESPACE);
|
||||
return cc;
|
||||
}
|
||||
|
||||
|
@ -212,6 +213,6 @@ public class CarbonManager {
|
|||
* @param msg Message object to mark private
|
||||
*/
|
||||
public static void disableCarbons(Message msg) {
|
||||
msg.addExtension(new Carbon.Private());
|
||||
msg.addExtension(new CarbonExtension.Private());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.carbons;
|
||||
package org.jivesoftware.smackx.carbons.packet;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smackx.forward.Forwarded;
|
||||
|
@ -30,7 +30,7 @@ import org.jivesoftware.smackx.forward.Forwarded;
|
|||
*
|
||||
* @author Georg Lukas
|
||||
*/
|
||||
public class Carbon implements PacketExtension {
|
||||
public class CarbonExtension implements PacketExtension {
|
||||
public static final String NAMESPACE = "urn:xmpp:carbons:2";
|
||||
|
||||
private Direction dir;
|
||||
|
@ -42,7 +42,7 @@ public class Carbon implements PacketExtension {
|
|||
* @param dir Determines if the carbon is being sent/received
|
||||
* @param fwd The forwarded message.
|
||||
*/
|
||||
public Carbon(Direction dir, Forwarded fwd) {
|
||||
public CarbonExtension(Direction dir, Forwarded fwd) {
|
||||
this.dir = dir;
|
||||
this.fwd = fwd;
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public class Carbon implements PacketExtension {
|
|||
}
|
||||
|
||||
/**
|
||||
* Defines the direction of a {@link Carbon} message.
|
||||
* Defines the direction of a {@link CarbonExtension} message.
|
||||
*/
|
||||
public static enum Direction {
|
||||
received,
|
||||
|
@ -107,11 +107,11 @@ public class Carbon implements PacketExtension {
|
|||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return Carbon.NAMESPACE;
|
||||
return CarbonExtension.NAMESPACE;
|
||||
}
|
||||
|
||||
public String toXML() {
|
||||
return "<" + ELEMENT + " xmlns=\"" + Carbon.NAMESPACE + "\"/>";
|
||||
return "<" + ELEMENT + " xmlns=\"" + CarbonExtension.NAMESPACE + "\"/>";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,14 +19,14 @@ package org.jivesoftware.smackx.carbons.provider;
|
|||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smackx.carbons.Carbon;
|
||||
import org.jivesoftware.smackx.carbons.Carbon.Direction;
|
||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction;
|
||||
import org.jivesoftware.smackx.forward.Forwarded;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* This class implements the {@link PacketExtensionProvider} to parse
|
||||
* cabon copied messages from a packet. It will return a {@link Carbon} packet extension.
|
||||
* cabon copied messages from a packet. It will return a {@link CarbonExtension} packet extension.
|
||||
*
|
||||
* @author Georg Lukas
|
||||
*
|
||||
|
@ -48,6 +48,6 @@ public class CarbonManagerProvider implements PacketExtensionProvider {
|
|||
}
|
||||
if (fwd == null)
|
||||
throw new Exception("sent/received must contain exactly one <forwarded> tag");
|
||||
return new Carbon(dir, fwd);
|
||||
return new CarbonExtension(dir, fwd);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.jivesoftware.smackx.workgroup.agent;
|
||||
|
||||
import org.jivesoftware.smackx.muc.packet.MUCUser;
|
||||
import org.jivesoftware.smackx.search.ReportedData;
|
||||
import org.jivesoftware.smackx.workgroup.MetaData;
|
||||
import org.jivesoftware.smackx.workgroup.QueueUser;
|
||||
import org.jivesoftware.smackx.workgroup.WorkgroupInvitation;
|
||||
|
@ -29,13 +31,11 @@ import org.jivesoftware.smackx.workgroup.ext.notes.ChatNotes;
|
|||
import org.jivesoftware.smackx.workgroup.packet.*;
|
||||
import org.jivesoftware.smackx.workgroup.settings.GenericSettings;
|
||||
import org.jivesoftware.smackx.workgroup.settings.SearchSettings;
|
||||
import org.jivesoftware.smackx.xdata.Form;
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.filter.*;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.Form;
|
||||
import org.jivesoftware.smackx.ReportedData;
|
||||
import org.jivesoftware.smackx.packet.MUCUser;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
|
|
@ -17,15 +17,15 @@
|
|||
|
||||
package org.jivesoftware.smackx.workgroup.agent;
|
||||
|
||||
import org.jivesoftware.smackx.search.ReportedData;
|
||||
import org.jivesoftware.smackx.workgroup.packet.TranscriptSearch;
|
||||
import org.jivesoftware.smackx.xdata.Form;
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.Form;
|
||||
import org.jivesoftware.smackx.ReportedData;
|
||||
|
||||
/**
|
||||
* A TranscriptSearchManager helps to retrieve the form to use for searching transcripts
|
||||
|
|
|
@ -25,17 +25,17 @@ import org.jivesoftware.smackx.workgroup.packet.QueueUpdate;
|
|||
import org.jivesoftware.smackx.workgroup.packet.SessionID;
|
||||
import org.jivesoftware.smackx.workgroup.packet.UserID;
|
||||
import org.jivesoftware.smackx.workgroup.settings.*;
|
||||
import org.jivesoftware.smackx.xdata.Form;
|
||||
import org.jivesoftware.smackx.xdata.FormField;
|
||||
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.filter.*;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.Form;
|
||||
import org.jivesoftware.smackx.FormField;
|
||||
import org.jivesoftware.smackx.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.muc.MultiUserChat;
|
||||
import org.jivesoftware.smackx.packet.DataForm;
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.packet.MUCUser;
|
||||
import org.jivesoftware.smackx.muc.packet.MUCUser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.util.Properties;
|
|||
|
||||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
||||
import org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider;
|
||||
import org.jivesoftware.smackx.forward.Forwarded;
|
||||
import org.jivesoftware.smackx.forward.provider.ForwardedProvider;
|
||||
|
@ -44,7 +45,7 @@ public class CarbonTest {
|
|||
public void carbonSentTest() throws Exception {
|
||||
XmlPullParser parser;
|
||||
String control;
|
||||
Carbon cc;
|
||||
CarbonExtension cc;
|
||||
Forwarded fwd;
|
||||
|
||||
control = XMLBuilder.create("sent")
|
||||
|
@ -55,11 +56,11 @@ public class CarbonTest {
|
|||
.asString(outputProperties);
|
||||
|
||||
parser = TestUtils.getParser(control, "sent");
|
||||
cc = (Carbon) new CarbonManagerProvider().parseExtension(parser);
|
||||
cc = (CarbonExtension) new CarbonManagerProvider().parseExtension(parser);
|
||||
fwd = cc.getForwarded();
|
||||
|
||||
// meta
|
||||
assertEquals(Carbon.Direction.sent, cc.getDirection());
|
||||
assertEquals(CarbonExtension.Direction.sent, cc.getDirection());
|
||||
|
||||
// no delay in packet
|
||||
assertEquals(null, fwd.getDelayInfo());
|
||||
|
@ -76,7 +77,7 @@ public class CarbonTest {
|
|||
public void carbonReceivedTest() throws Exception {
|
||||
XmlPullParser parser;
|
||||
String control;
|
||||
Carbon cc;
|
||||
CarbonExtension cc;
|
||||
|
||||
control = XMLBuilder.create("received")
|
||||
.e("forwarded")
|
||||
|
@ -86,9 +87,9 @@ public class CarbonTest {
|
|||
.asString(outputProperties);
|
||||
|
||||
parser = TestUtils.getParser(control, "received");
|
||||
cc = (Carbon) new CarbonManagerProvider().parseExtension(parser);
|
||||
cc = (CarbonExtension) new CarbonManagerProvider().parseExtension(parser);
|
||||
|
||||
assertEquals(Carbon.Direction.received, cc.getDirection());
|
||||
assertEquals(CarbonExtension.Direction.received, cc.getDirection());
|
||||
|
||||
// check end of tag
|
||||
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue