1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 13:32:07 +01:00

Enable LeftCurly checkstyle check

This commit is contained in:
Florian Schmaus 2018-04-06 10:21:46 +02:00
parent 5a841ff0a8
commit 9b5dafe541
93 changed files with 549 additions and 1087 deletions

View file

@ -80,6 +80,7 @@
<module name="GenericWhitespace"/>
<module name="EmptyStatement"/>
<module name="PackageDeclaration"/>
<module name="LeftCurly"/>
<module name="RegexpSinglelineJava">
<property name="format" value="printStackTrace"/>
<property name="message" value="Usage of printStackTrace"/>

View file

@ -193,8 +193,7 @@ public final class ProviderManager {
*/
@SuppressWarnings("unchecked")
public static void addIQProvider(String elementName, String namespace,
Object provider)
{
Object provider) {
validate(elementName, namespace);
// First remove existing providers
String key = removeIQProvider(elementName, namespace);
@ -255,8 +254,7 @@ public final class ProviderManager {
*/
@SuppressWarnings("unchecked")
public static void addExtensionProvider(String elementName, String namespace,
Object provider)
{
Object provider) {
validate(elementName, namespace);
// First remove existing providers
String key = removeExtensionProvider(elementName, namespace);

View file

@ -37,8 +37,7 @@ class HTTPProxySocketConnection implements ProxySocketConnection {
private final ProxyInfo proxy;
HTTPProxySocketConnection(ProxyInfo proxy)
{
HTTPProxySocketConnection(ProxyInfo proxy) {
this.proxy = proxy;
}
@ -51,12 +50,10 @@ class HTTPProxySocketConnection implements ProxySocketConnection {
String hostport = "CONNECT " + host + ":" + port;
String proxyLine;
String username = proxy.getProxyUsername();
if (username == null)
{
if (username == null) {
proxyLine = "";
}
else
{
else {
String password = proxy.getProxyPassword();
proxyLine = "\r\nProxy-Authorization: Basic " + Base64.encode(username + ":" + password);
}
@ -67,41 +64,33 @@ class HTTPProxySocketConnection implements ProxySocketConnection {
StringBuilder got = new StringBuilder(100);
int nlchars = 0;
while (true)
{
while (true) {
int inByte = in.read();
if (inByte == -1)
{
if (inByte == -1) {
throw new ProxyException(ProxyInfo.ProxyType.HTTP);
}
char c = (char) inByte;
got.append(c);
if (got.length() > 1024)
{
if (got.length() > 1024) {
throw new ProxyException(ProxyInfo.ProxyType.HTTP, "Received " +
"header of >1024 characters from "
+ proxyhost + ", cancelling connection");
}
if ((nlchars == 0 || nlchars == 2) && c == '\r')
{
if ((nlchars == 0 || nlchars == 2) && c == '\r') {
nlchars++;
}
else if ((nlchars == 1 || nlchars == 3) && c == '\n')
{
else if ((nlchars == 1 || nlchars == 3) && c == '\n') {
nlchars++;
}
else
{
else {
nlchars = 0;
}
if (nlchars == 4)
{
if (nlchars == 4) {
break;
}
}
if (nlchars != 4)
{
if (nlchars != 4) {
throw new ProxyException(ProxyInfo.ProxyType.HTTP, "Never " +
"received blank line from "
+ proxyhost + ", cancelling connection");
@ -112,23 +101,20 @@ class HTTPProxySocketConnection implements ProxySocketConnection {
BufferedReader br = new BufferedReader(new StringReader(gotstr));
String response = br.readLine();
if (response == null)
{
if (response == null) {
throw new ProxyException(ProxyInfo.ProxyType.HTTP, "Empty proxy " +
"response from " + proxyhost + ", cancelling");
}
Matcher m = RESPONSE_PATTERN.matcher(response);
if (!m.matches())
{
if (!m.matches()) {
throw new ProxyException(ProxyInfo.ProxyType.HTTP , "Unexpected " +
"proxy response from " + proxyhost + ": " + response);
}
int code = Integer.parseInt(m.group(1));
if (code != HttpURLConnection.HTTP_OK)
{
if (code != HttpURLConnection.HTTP_OK) {
throw new ProxyException(ProxyInfo.ProxyType.HTTP);
}
}

View file

@ -29,13 +29,11 @@ public class ProxyException extends IOException {
*/
private static final long serialVersionUID = 1L;
public ProxyException(ProxyInfo.ProxyType type, String ex)
{
public ProxyException(ProxyInfo.ProxyType type, String ex) {
super("Proxy Exception " + type.toString() + " : " + ex);
}
public ProxyException(ProxyInfo.ProxyType type)
{
public ProxyException(ProxyInfo.ProxyType type) {
super("Proxy Exception " + type.toString() + " : " + "Unknown Error");
}
}

View file

@ -23,10 +23,8 @@ package org.jivesoftware.smack.proxy;
* @author Atul Aggarwal
*/
public class ProxyInfo
{
public enum ProxyType
{
public class ProxyInfo {
public enum ProxyType {
HTTP,
SOCKS4,
SOCKS5
@ -40,8 +38,7 @@ public class ProxyInfo
private final ProxySocketConnection proxySocketConnection;
public ProxyInfo(ProxyType pType, String pHost, int pPort, String pUser,
String pPass)
{
String pPass) {
this.proxyType = pType;
this.proxyAddress = pHost;
this.proxyPort = pPort;
@ -63,45 +60,37 @@ public class ProxyInfo
}
public static ProxyInfo forHttpProxy(String pHost, int pPort, String pUser,
String pPass)
{
String pPass) {
return new ProxyInfo(ProxyType.HTTP, pHost, pPort, pUser, pPass);
}
public static ProxyInfo forSocks4Proxy(String pHost, int pPort, String pUser,
String pPass)
{
String pPass) {
return new ProxyInfo(ProxyType.SOCKS4, pHost, pPort, pUser, pPass);
}
public static ProxyInfo forSocks5Proxy(String pHost, int pPort, String pUser,
String pPass)
{
String pPass) {
return new ProxyInfo(ProxyType.SOCKS5, pHost, pPort, pUser, pPass);
}
public ProxyType getProxyType()
{
public ProxyType getProxyType() {
return proxyType;
}
public String getProxyAddress()
{
public String getProxyAddress() {
return proxyAddress;
}
public int getProxyPort()
{
public int getProxyPort() {
return proxyPort;
}
public String getProxyUsername()
{
public String getProxyUsername() {
return proxyUsername;
}
public String getProxyPassword()
{
public String getProxyPassword() {
return proxyPassword;
}

View file

@ -33,8 +33,7 @@ import org.jivesoftware.smack.util.StringUtils;
public class Socks4ProxySocketConnection implements ProxySocketConnection {
private final ProxyInfo proxy;
Socks4ProxySocketConnection(ProxyInfo proxy)
{
Socks4ProxySocketConnection(ProxyInfo proxy) {
this.proxy = proxy;
}
@ -47,8 +46,7 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
int proxy_port = proxy.getProxyPort();
String user = proxy.getProxyUsername();
try
{
try {
socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout);
in = socket.getInputStream();
out = socket.getOutputStream();
@ -84,13 +82,11 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
InetAddress inetAddress = InetAddress.getByName(proxy_host);
byte[] byteAddress = inetAddress.getAddress();
for (int i = 0; i < byteAddress.length; i++)
{
for (int i = 0; i < byteAddress.length; i++) {
buf[index++] = byteAddress[i];
}
if (user != null)
{
if (user != null) {
byte[] userBytes = user.getBytes(StringUtils.UTF8);
System.arraycopy(userBytes, 0, buf, index, user.length());
index += user.length();
@ -127,29 +123,23 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
int len = 6;
int s = 0;
while (s < len)
{
while (s < len) {
int i = in.read(buf, s, len - s);
if (i <= 0)
{
if (i <= 0) {
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4,
"stream is closed");
}
s += i;
}
if (buf[0] != 0)
{
if (buf[0] != 0) {
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4,
"server returns VN " + buf[0]);
}
if (buf[1] != 90)
{
try
{
if (buf[1] != 90) {
try {
socket.close();
}
catch (Exception eee)
{
catch (Exception eee) {
}
String message = "ProxySOCKS4: server returns CD " + buf[1];
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, message);
@ -157,18 +147,14 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
byte[] temp = new byte[2];
in.read(temp, 0, 2);
}
catch (RuntimeException e)
{
catch (RuntimeException e) {
throw e;
}
catch (Exception e)
{
try
{
catch (Exception e) {
try {
socket.close();
}
catch (Exception eee)
{
catch (Exception eee) {
}
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, e.toString());
}

View file

@ -32,8 +32,7 @@ import org.jivesoftware.smack.util.StringUtils;
public class Socks5ProxySocketConnection implements ProxySocketConnection {
private final ProxyInfo proxy;
Socks5ProxySocketConnection(ProxyInfo proxy)
{
Socks5ProxySocketConnection(ProxyInfo proxy) {
this.proxy = proxy;
}
@ -47,8 +46,7 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
String user = proxy.getProxyUsername();
String passwd = proxy.getProxyPassword();
try
{
try {
socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout);
in = socket.getInputStream();
out = socket.getOutputStream();
@ -100,14 +98,12 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
fill(in, buf, 2);
boolean check = false;
switch ((buf[1]) & 0xff)
{
switch ((buf[1]) & 0xff) {
case 0: // NO AUTHENTICATION REQUIRED
check = true;
break;
case 2: // USERNAME/PASSWORD
if (user == null || passwd == null)
{
if (user == null || passwd == null) {
break;
}
@ -160,22 +156,18 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
connection.
*/
fill(in, buf, 2);
if (buf[1] == 0)
{
if (buf[1] == 0) {
check = true;
}
break;
default:
}
if (!check)
{
try
{
if (!check) {
try {
socket.close();
}
catch (Exception eee)
{
catch (Exception eee) {
}
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5,
"fail in SOCKS5 proxy");
@ -260,21 +252,17 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
fill(in, buf, 4);
if (buf[1] != 0)
{
try
{
if (buf[1] != 0) {
try {
socket.close();
}
catch (Exception eee)
{
catch (Exception eee) {
}
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5,
"server returns " + buf[1]);
}
switch (buf[3] & 0xff)
{
switch (buf[3] & 0xff) {
case 1:
fill(in, buf, 6);
break;
@ -288,18 +276,14 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
default:
}
}
catch (RuntimeException e)
{
catch (RuntimeException e) {
throw e;
}
catch (Exception e)
{
try
{
catch (Exception e) {
try {
socket.close();
}
catch (Exception eee)
{
catch (Exception eee) {
}
// TODO convert to IOException(e) when minimum Android API level is 9 or higher
throw new IOException(e.getLocalizedMessage());
@ -307,14 +291,11 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
}
private static void fill(InputStream in, byte[] buf, int len)
throws IOException
{
throws IOException {
int s = 0;
while (s < len)
{
while (s < len) {
int i = in.read(buf, s, len - s);
if (i <= 0)
{
if (i <= 0) {
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5, "stream " +
"is closed");
}

View file

@ -24,16 +24,13 @@ import org.jivesoftware.smack.packet.Stanza;
import org.junit.Test;
public class StanzaCollectorTest
{
public class StanzaCollectorTest {
@Test
public void verifyRollover() throws InterruptedException
{
public void verifyRollover() throws InterruptedException {
TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), 5);
for (int i = 0; i < 6; i++)
{
for (int i = 0; i < 6; i++) {
Stanza testPacket = new TestPacket(i);
collector.processStanza(testPacket);
}
@ -46,8 +43,7 @@ public class StanzaCollectorTest
assertEquals("5", collector.pollResult().getStanzaId());
assertNull(collector.pollResult());
for (int i = 10; i < 15; i++)
{
for (int i = 10; i < 15; i++) {
Stanza testPacket = new TestPacket(i);
collector.processStanza(testPacket);
}
@ -67,26 +63,18 @@ public class StanzaCollectorTest
* catch problems.
*/
@Test
public void verifyThreadSafety()
{
public void verifyThreadSafety() {
int insertCount = 500;
final TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), insertCount);
Thread consumer1 = new Thread(new Runnable()
{
Thread consumer1 = new Thread(new Runnable() {
@Override
public void run()
{
try
{
while (true)
{
try
{
public void run() {
try {
while (true) {
try {
Thread.sleep(3);
}
catch (InterruptedException e)
{
} catch (InterruptedException e) {
}
@SuppressWarnings("unused")
Stanza packet = collector.nextResultBlockForever();
@ -100,26 +88,19 @@ public class StanzaCollectorTest
});
consumer1.setName("consumer 1");
Thread consumer2 = new Thread(new Runnable()
{
Thread consumer2 = new Thread(new Runnable() {
@Override
public void run()
{
public void run() {
Stanza p;
do
{
try
{
do {
try {
Thread.sleep(3);
}
catch (InterruptedException e)
{
} catch (InterruptedException e) {
}
try {
p = collector.nextResult(1);
}
catch (InterruptedException e) {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// System.out.println(Thread.currentThread().getName() + " packet: " + p);
@ -129,26 +110,19 @@ public class StanzaCollectorTest
});
consumer2.setName("consumer 2");
Thread consumer3 = new Thread(new Runnable()
{
Thread consumer3 = new Thread(new Runnable() {
@Override
public void run()
{
public void run() {
Stanza p;
do
{
try
{
do {
try {
Thread.sleep(3);
}
catch (InterruptedException e)
{
} catch (InterruptedException e) {
}
p = collector.pollResult();
// System.out.println(Thread.currentThread().getName() + " packet: " + p);
}
while (p != null);
} while (p != null);
}
});
consumer3.setName("consumer 3");
@ -157,54 +131,43 @@ public class StanzaCollectorTest
consumer2.start();
consumer3.start();
for (int i = 0; i < insertCount; i++)
{
for (int i = 0; i < insertCount; i++) {
collector.processStanza(new TestPacket(i));
}
try
{
try {
Thread.sleep(5000);
consumer3.join();
consumer2.join();
consumer1.interrupt();
}
catch (InterruptedException e)
{
} catch (InterruptedException e) {
}
// We cannot guarantee that this is going to pass due to the possible issue of timing between consumer 1
// and main, but the probability is extremely remote.
assertNull(collector.pollResult());
}
static class OKEverything implements StanzaFilter
{
static class OKEverything implements StanzaFilter {
@Override
public boolean accept(Stanza packet)
{
public boolean accept(Stanza packet) {
return true;
}
}
static class TestStanzaCollector extends StanzaCollector
{
protected TestStanzaCollector(XMPPConnection conection, StanzaFilter packetFilter, int size)
{
static class TestStanzaCollector extends StanzaCollector {
protected TestStanzaCollector(XMPPConnection conection, StanzaFilter packetFilter, int size) {
super(conection, StanzaCollector.newConfiguration().setStanzaFilter(packetFilter).setSize(size));
}
}
static class TestPacket extends Stanza
{
TestPacket(int i)
{
static class TestPacket extends Stanza {
TestPacket(int i) {
setStanzaId(String.valueOf(i));
}
@Override
public String toXML()
{
public String toXML() {
return "<packetId>" + getStanzaId() + "</packetId>";
}

View file

@ -45,8 +45,7 @@ public class FromMatchesFilterTest {
private static final Jid SERVICE_JID2 = JidTestUtil.PUBSUB_EXAMPLE_ORG;
@Test
public void autoCompareMatchingEntityFullJid()
{
public void autoCompareMatchingEntityFullJid() {
FromMatchesFilter filter = FromMatchesFilter.create(FULL_JID1_R1);
Stanza packet = new Message();
@ -70,8 +69,7 @@ public class FromMatchesFilterTest {
}
@Test
public void autoCompareMatchingBaseJid()
{
public void autoCompareMatchingBaseJid() {
FromMatchesFilter filter = FromMatchesFilter.create(BASE_JID1);
Stanza packet = new Message();
@ -95,8 +93,7 @@ public class FromMatchesFilterTest {
}
@Test
public void autoCompareMatchingServiceJid()
{
public void autoCompareMatchingServiceJid() {
FromMatchesFilter filter = FromMatchesFilter.create(SERVICE_JID1);
Stanza packet = new Message();
@ -117,8 +114,7 @@ public class FromMatchesFilterTest {
}
@Test
public void bareCompareMatchingEntityFullJid()
{
public void bareCompareMatchingEntityFullJid() {
FromMatchesFilter filter = FromMatchesFilter.createBare(FULL_JID1_R1);
Stanza packet = new Message();
@ -142,8 +138,7 @@ public class FromMatchesFilterTest {
}
@Test
public void bareCompareMatchingBaseJid()
{
public void bareCompareMatchingBaseJid() {
FromMatchesFilter filter = FromMatchesFilter.createBare(BASE_JID1);
Stanza packet = new Message();
@ -167,8 +162,7 @@ public class FromMatchesFilterTest {
}
@Test
public void bareCompareMatchingServiceJid()
{
public void bareCompareMatchingServiceJid() {
FromMatchesFilter filter = FromMatchesFilter.createBare(SERVICE_JID1);
Stanza packet = new Message();
@ -189,8 +183,7 @@ public class FromMatchesFilterTest {
}
@Test
public void fullCompareMatchingEntityFullJid()
{
public void fullCompareMatchingEntityFullJid() {
FromMatchesFilter filter = FromMatchesFilter.createFull(FULL_JID1_R1);
Stanza packet = new Message();
@ -214,8 +207,7 @@ public class FromMatchesFilterTest {
}
@Test
public void fullCompareMatchingBaseJid()
{
public void fullCompareMatchingBaseJid() {
FromMatchesFilter filter = FromMatchesFilter.createFull(BASE_JID1);
Stanza packet = new Message();
@ -239,8 +231,7 @@ public class FromMatchesFilterTest {
}
@Test
public void fullCompareMatchingServiceJid()
{
public void fullCompareMatchingServiceJid() {
FromMatchesFilter filter = FromMatchesFilter.createFull(SERVICE_JID1);
Stanza packet = new Message();

View file

@ -434,8 +434,7 @@ public class EnhancedDebugger extends SmackDebugger {
int index = str.lastIndexOf(">");
if (index != -1) {
if (receivedText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS)
{
if (receivedText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
try {
receivedText.replaceRange("", 0, receivedText.getLineEndOffset(0));
}

View file

@ -71,8 +71,9 @@ public class MultipleRecipientManager {
* @throws NotConnectedException
* @throws InterruptedException
*/
public static void send(XMPPConnection connection, Stanza packet, Collection<? extends Jid> to, Collection<? extends Jid> cc, Collection<? extends Jid> bcc) throws NoResponseException, XMPPErrorException, FeatureNotSupportedException, NotConnectedException, InterruptedException
{
public static void send(XMPPConnection connection, Stanza packet, Collection<? extends Jid> to,
Collection<? extends Jid> cc, Collection<? extends Jid> bcc) throws NoResponseException, XMPPErrorException,
FeatureNotSupportedException, NotConnectedException, InterruptedException {
send(connection, packet, to, cc, bcc, null, null, false);
}
@ -143,8 +144,8 @@ public class MultipleRecipientManager {
* @throws XMPPErrorException
* @throws InterruptedException
*/
public static void reply(XMPPConnection connection, Message original, Message reply) throws SmackException, XMPPErrorException, InterruptedException
{
public static void reply(XMPPConnection connection, Message original, Message reply)
throws SmackException, XMPPErrorException, InterruptedException {
MultipleRecipientInfo info = getMultipleRecipientInfo(original);
if (info == null) {
throw new SmackException("Original message does not contain multiple recipient info");

View file

@ -60,8 +60,7 @@ public final class BookmarkManager {
* exist it is created.
* @throws IllegalArgumentException when the connection is null.
*/
public static synchronized BookmarkManager getBookmarkManager(XMPPConnection connection)
{
public static synchronized BookmarkManager getBookmarkManager(XMPPConnection connection) {
BookmarkManager manager = bookmarkManagerMap.get(connection);
if (manager == null) {
manager = new BookmarkManager(connection);
@ -114,8 +113,7 @@ public final class BookmarkManager {
* @throws InterruptedException
*/
public void addBookmarkedConference(String name, EntityBareJid jid, boolean isAutoJoin,
Resourcepart nickname, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
Resourcepart nickname, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
retrieveBookmarks();
BookmarkedConference bookmark
= new BookmarkedConference(name, jid, isAutoJoin, nickname, password);

View file

@ -40,8 +40,7 @@ public class BookmarkedConference implements SharedBookmark {
}
protected BookmarkedConference(String name, EntityBareJid jid, boolean autoJoin, Resourcepart nickname,
String password)
{
String password) {
this.name = name;
this.jid = jid;
this.autoJoin = autoJoin;

View file

@ -232,13 +232,11 @@ public class Bookmarks implements PrivateData {
}
}
else if (eventType == XmlPullParser.START_TAG &&
"conference".equals(parser.getName()))
{
"conference".equals(parser.getName())) {
final BookmarkedConference conference = getConferenceStorage(parser);
storage.addBookmarkedConference(conference);
}
else if (eventType == XmlPullParser.END_TAG && "storage".equals(parser.getName()))
{
else if (eventType == XmlPullParser.END_TAG && "storage".equals(parser.getName())) {
done = true;
}
}

View file

@ -606,8 +606,7 @@ public final class AdHocCommandManager extends Manager {
* @throws NotConnectedException
*/
private static IQ respondError(AdHocCommandData response, XMPPError.Condition condition,
AdHocCommand.SpecificErrorCondition specificCondition)
{
AdHocCommand.SpecificErrorCondition specificCondition) {
XMPPError.Builder error = XMPPError.getBuilder(condition).addExtension(new AdHocCommandData.SpecificError(specificCondition));
return respondError(response, error);
}
@ -672,8 +671,7 @@ public final class AdHocCommandManager extends Manager {
private LocalCommandFactory factory;
private AdHocCommandInfo(String node, String name, Jid ownerJID,
LocalCommandFactory factory)
{
LocalCommandFactory factory) {
this.node = node;
this.name = name;
this.ownerJID = ownerJID;
@ -681,8 +679,7 @@ public final class AdHocCommandManager extends Manager {
}
public LocalCommand getCommandInstance() throws InstantiationException,
IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException
{
IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
return factory.getInstance();
}

View file

@ -654,8 +654,7 @@ public final class ServiceDiscoveryManager extends Manager {
*/
@Deprecated
// TODO: Remove in Smack 4.4
public void publishItems(Jid entityID, String node, DiscoverItems discoverItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public void publishItems(Jid entityID, String node, DiscoverItems discoverItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
discoverItems.setType(IQ.Type.set);
discoverItems.setTo(entityID);
discoverItems.setNode(node);

View file

@ -204,8 +204,7 @@ public abstract class FileTransfer {
}
protected void writeToStream(final InputStream in, final OutputStream out)
throws IOException
{
throws IOException {
final byte[] b = new byte[BUFFER_SIZE];
int count = 0;
amountWritten = 0;

View file

@ -161,8 +161,7 @@ public class OutgoingFileTransfer extends FileTransfer {
*/
public synchronized void sendFile(final String fileName,
final long fileSize, final String description,
final NegotiationProgress progress)
{
final NegotiationProgress progress) {
if (progress == null) {
throw new IllegalArgumentException("Callback progress cannot be null.");
}

View file

@ -51,8 +51,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
}
@Override
public OutputStream createOutgoingStream(String streamID, Jid initiator, Jid target) throws SmackException, XMPPException
{
public OutputStream createOutgoingStream(String streamID, Jid initiator, Jid target) throws SmackException, XMPPException {
try {
return this.manager.establishSession(target, streamID).getOutputStream();
}

View file

@ -73,8 +73,7 @@ public abstract class StreamNegotiator extends Manager {
* @return The response to be forwarded to the initiator.
*/
protected static StreamInitiation createInitiationAccept(
StreamInitiation streamInitiationOffer, String[] namespaces)
{
StreamInitiation streamInitiationOffer, String[] namespaces) {
StreamInitiation response = new StreamInitiation();
response.setTo(streamInitiationOffer.getFrom());
response.setFrom(streamInitiationOffer.getTo());

View file

@ -115,8 +115,7 @@ public final class PrivateDataManager extends Manager {
* @param provider the private data provider.
*/
public static void addPrivateDataProvider(String elementName, String namespace,
PrivateDataProvider provider)
{
PrivateDataProvider provider) {
String key = XmppStringUtils.generateKey(elementName, namespace);
privateDataProviders.put(key, provider);
}
@ -159,8 +158,7 @@ public final class PrivateDataManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
public PrivateData getPrivateData(final String elementName, final String namespace) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public PrivateData getPrivateData(final String elementName, final String namespace) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// Create an IQ packet to get the private data.
IQ privateDataGet = new PrivateDataIQ(elementName, namespace);

View file

@ -1583,8 +1583,7 @@ public class MultiUserChat {
* @throws NotConnectedException
* @throws InterruptedException
*/
private void changeAffiliationByAdmin(Jid jid, MUCAffiliation affiliation, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
private void changeAffiliationByAdmin(Jid jid, MUCAffiliation affiliation, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCAdmin iq = new MUCAdmin();
iq.setTo(room);
iq.setType(IQ.Type.set);

View file

@ -22,8 +22,8 @@ package org.jivesoftware.smackx.pubsub;
*
* @author Robin Collier
*/
public enum AccessModel
{
public enum AccessModel {
/** Anyone may subscribe and retrieve items. */
open,

View file

@ -35,8 +35,7 @@ import org.jxmpp.jid.BareJid;
*
* @author Robin Collier
*/
public class Affiliation implements ExtensionElement
{
public class Affiliation implements ExtensionElement {
public static final String ELEMENT = "affiliation";
private final BareJid jid;
@ -44,8 +43,7 @@ public class Affiliation implements ExtensionElement
private final Type affiliation;
private final PubSubNamespace namespace;
public enum Type
{
public enum Type {
member, none, outcast, owner, publisher
}

View file

@ -28,8 +28,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*
* @author Robin Collier
*/
public class AffiliationsExtension extends NodeExtension
{
public class AffiliationsExtension extends NodeExtension {
protected List<Affiliation> items = Collections.emptyList();
private final String node;
@ -47,20 +46,16 @@ public class AffiliationsExtension extends NodeExtension
this.node = node;
}
public List<Affiliation> getAffiliations()
{
public List<Affiliation> getAffiliations() {
return items;
}
@Override
public CharSequence toXML()
{
if ((items == null) || (items.size() == 0))
{
public CharSequence toXML() {
if ((items == null) || (items.size() == 0)) {
return super.toXML();
}
else
{
else {
// Can't use XmlStringBuilder(this), because we don't want the namespace to be included
XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement(getElementName());

View file

@ -22,8 +22,7 @@ package org.jivesoftware.smackx.pubsub;
*
* @author Robin Collier
*/
public enum ChildrenAssociationPolicy
{
public enum ChildrenAssociationPolicy {
/** Anyone may associate leaf nodes with the collection. */
all,

View file

@ -18,8 +18,7 @@ package org.jivesoftware.smackx.pubsub;
public class CollectionNode extends Node {
CollectionNode(PubSubManager pubSubManager, String nodeId)
{
CollectionNode(PubSubManager pubSubManager, String nodeId) {
super(pubSubManager, nodeId);
}

View file

@ -29,29 +29,24 @@ import org.jivesoftware.smack.packet.ExtensionElement;
*
* @author Robin Collier
*/
public class ConfigurationEvent extends NodeExtension implements EmbeddedPacketExtension
{
public class ConfigurationEvent extends NodeExtension implements EmbeddedPacketExtension {
private ConfigureForm form;
public ConfigurationEvent(String nodeId)
{
public ConfigurationEvent(String nodeId) {
super(PubSubElementType.CONFIGURATION, nodeId);
}
public ConfigurationEvent(String nodeId, ConfigureForm configForm)
{
public ConfigurationEvent(String nodeId, ConfigureForm configForm) {
super(PubSubElementType.CONFIGURATION, nodeId);
form = configForm;
}
public ConfigureForm getConfiguration()
{
public ConfigureForm getConfiguration() {
return form;
}
@Override
public List<ExtensionElement> getExtensions()
{
public List<ExtensionElement> getExtensions() {
if (getConfiguration() == null)
return Collections.emptyList();
else

View file

@ -33,16 +33,14 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
*
* @author Robin Collier
*/
public class ConfigureForm extends Form
{
public class ConfigureForm extends Form {
/**
* Create a decorator from an existing {@link DataForm} that has been
* retrieved from parsing a node configuration request.
*
* @param configDataForm
*/
public ConfigureForm(DataForm configDataForm)
{
public ConfigureForm(DataForm configDataForm) {
super(configDataForm);
}
@ -53,8 +51,7 @@ public class ConfigureForm extends Form
*
* @param nodeConfigForm
*/
public ConfigureForm(Form nodeConfigForm)
{
public ConfigureForm(Form nodeConfigForm) {
super(nodeConfigForm.getDataFormToSend());
}
@ -65,8 +62,7 @@ public class ConfigureForm extends Form
* using the resulting form to create a answer form. See {@link #ConfigureForm(Form)}.
* @param formType
*/
public ConfigureForm(DataForm.Type formType)
{
public ConfigureForm(DataForm.Type formType) {
super(formType);
}
@ -75,8 +71,7 @@ public class ConfigureForm extends Form
*
* @return The current {@link AccessModel}
*/
public AccessModel getAccessModel()
{
public AccessModel getAccessModel() {
String value = getFieldValue(ConfigureNodeFields.access_model);
if (value == null)
@ -90,8 +85,7 @@ public class ConfigureForm extends Form
*
* @param accessModel
*/
public void setAccessModel(AccessModel accessModel)
{
public void setAccessModel(AccessModel accessModel) {
addField(ConfigureNodeFields.access_model, FormField.Type.list_single);
setAnswer(ConfigureNodeFields.access_model.getFieldName(), getListSingle(accessModel.toString()));
}
@ -102,8 +96,7 @@ public class ConfigureForm extends Form
*
* @return URL to an XSL
*/
public String getBodyXSLT()
{
public String getBodyXSLT() {
return getFieldValue(ConfigureNodeFields.body_xslt);
}
@ -113,8 +106,7 @@ public class ConfigureForm extends Form
*
* @param bodyXslt The URL of an XSL
*/
public void setBodyXSLT(String bodyXslt)
{
public void setBodyXSLT(String bodyXslt) {
addField(ConfigureNodeFields.body_xslt, FormField.Type.text_single);
setAnswer(ConfigureNodeFields.body_xslt.getFieldName(), bodyXslt);
}
@ -124,8 +116,7 @@ public class ConfigureForm extends Form
*
* @return list of child nodes.
*/
public List<String> getChildren()
{
public List<String> getChildren() {
return getFieldValues(ConfigureNodeFields.children);
}
@ -134,8 +125,7 @@ public class ConfigureForm extends Form
*
* @param children
*/
public void setChildren(List<String> children)
{
public void setChildren(List<String> children) {
addField(ConfigureNodeFields.children, FormField.Type.text_multi);
setAnswer(ConfigureNodeFields.children.getFieldName(), children);
}
@ -145,8 +135,7 @@ public class ConfigureForm extends Form
*
* @return The current policy
*/
public ChildrenAssociationPolicy getChildrenAssociationPolicy()
{
public ChildrenAssociationPolicy getChildrenAssociationPolicy() {
String value = getFieldValue(ConfigureNodeFields.children_association_policy);
if (value == null)
@ -160,8 +149,7 @@ public class ConfigureForm extends Form
*
* @param policy The policy being set
*/
public void setChildrenAssociationPolicy(ChildrenAssociationPolicy policy)
{
public void setChildrenAssociationPolicy(ChildrenAssociationPolicy policy) {
addField(ConfigureNodeFields.children_association_policy, FormField.Type.list_single);
List<String> values = new ArrayList<>(1);
values.add(policy.toString());
@ -175,8 +163,7 @@ public class ConfigureForm extends Form
*
* @return List of the whitelist
*/
public List<String> getChildrenAssociationWhitelist()
{
public List<String> getChildrenAssociationWhitelist() {
return getFieldValues(ConfigureNodeFields.children_association_whitelist);
}
@ -187,8 +174,7 @@ public class ConfigureForm extends Form
*
* @param whitelist The list of JID's
*/
public void setChildrenAssociationWhitelist(List<String> whitelist)
{
public void setChildrenAssociationWhitelist(List<String> whitelist) {
addField(ConfigureNodeFields.children_association_whitelist, FormField.Type.jid_multi);
setAnswer(ConfigureNodeFields.children_association_whitelist.getFieldName(), whitelist);
}
@ -198,8 +184,7 @@ public class ConfigureForm extends Form
*
* @return The maximum number of child nodes
*/
public int getChildrenMax()
{
public int getChildrenMax() {
return Integer.parseInt(getFieldValue(ConfigureNodeFields.children_max));
}
@ -208,8 +193,7 @@ public class ConfigureForm extends Form
*
* @param max The maximum number of child nodes.
*/
public void setChildrenMax(int max)
{
public void setChildrenMax(int max) {
addField(ConfigureNodeFields.children_max, FormField.Type.text_single);
setAnswer(ConfigureNodeFields.children_max.getFieldName(), max);
}
@ -219,8 +203,7 @@ public class ConfigureForm extends Form
*
* @return The collection node id
*/
public String getCollection()
{
public String getCollection() {
return getFieldValue(ConfigureNodeFields.collection);
}
@ -229,8 +212,7 @@ public class ConfigureForm extends Form
*
* @param collection The node id of the collection node
*/
public void setCollection(String collection)
{
public void setCollection(String collection) {
addField(ConfigureNodeFields.collection, FormField.Type.text_single);
setAnswer(ConfigureNodeFields.collection.getFieldName(), collection);
}
@ -242,8 +224,7 @@ public class ConfigureForm extends Form
*
* @return The URL of an XSL transformation
*/
public String getDataformXSLT()
{
public String getDataformXSLT() {
return getFieldValue(ConfigureNodeFields.dataform_xslt);
}
@ -254,8 +235,7 @@ public class ConfigureForm extends Form
*
* @param url The URL of an XSL transformation
*/
public void setDataformXSLT(String url)
{
public void setDataformXSLT(String url) {
addField(ConfigureNodeFields.dataform_xslt, FormField.Type.text_single);
setAnswer(ConfigureNodeFields.dataform_xslt.getFieldName(), url);
}
@ -265,8 +245,7 @@ public class ConfigureForm extends Form
*
* @return true if it does, false otherwise
*/
public boolean isDeliverPayloads()
{
public boolean isDeliverPayloads() {
return parseBoolean(getFieldValue(ConfigureNodeFields.deliver_payloads));
}
@ -275,8 +254,7 @@ public class ConfigureForm extends Form
*
* @param deliver true if the payload will be delivered, false otherwise
*/
public void setDeliverPayloads(boolean deliver)
{
public void setDeliverPayloads(boolean deliver) {
addField(ConfigureNodeFields.deliver_payloads, FormField.Type.bool);
setAnswer(ConfigureNodeFields.deliver_payloads.getFieldName(), deliver);
}
@ -286,8 +264,7 @@ public class ConfigureForm extends Form
*
* @return Who should get the reply
*/
public ItemReply getItemReply()
{
public ItemReply getItemReply() {
String value = getFieldValue(ConfigureNodeFields.itemreply);
if (value == null)
@ -301,8 +278,7 @@ public class ConfigureForm extends Form
*
* @param reply Defines who should get the reply
*/
public void setItemReply(ItemReply reply)
{
public void setItemReply(ItemReply reply) {
addField(ConfigureNodeFields.itemreply, FormField.Type.list_single);
setAnswer(ConfigureNodeFields.itemreply.getFieldName(), getListSingle(reply.toString()));
}
@ -313,8 +289,7 @@ public class ConfigureForm extends Form
*
* @return The maximum number of items to persist
*/
public int getMaxItems()
{
public int getMaxItems() {
return Integer.parseInt(getFieldValue(ConfigureNodeFields.max_items));
}
@ -324,8 +299,7 @@ public class ConfigureForm extends Form
*
* @param max The maximum number of items to persist
*/
public void setMaxItems(int max)
{
public void setMaxItems(int max) {
addField(ConfigureNodeFields.max_items, FormField.Type.text_single);
setAnswer(ConfigureNodeFields.max_items.getFieldName(), max);
}
@ -335,8 +309,7 @@ public class ConfigureForm extends Form
*
* @return The maximum payload size
*/
public int getMaxPayloadSize()
{
public int getMaxPayloadSize() {
return Integer.parseInt(getFieldValue(ConfigureNodeFields.max_payload_size));
}
@ -345,8 +318,7 @@ public class ConfigureForm extends Form
*
* @param max The maximum payload size
*/
public void setMaxPayloadSize(int max)
{
public void setMaxPayloadSize(int max) {
addField(ConfigureNodeFields.max_payload_size, FormField.Type.text_single);
setAnswer(ConfigureNodeFields.max_payload_size.getFieldName(), max);
}
@ -356,8 +328,7 @@ public class ConfigureForm extends Form
*
* @return The node type
*/
public NodeType getNodeType()
{
public NodeType getNodeType() {
String value = getFieldValue(ConfigureNodeFields.node_type);
if (value == null)
@ -371,8 +342,7 @@ public class ConfigureForm extends Form
*
* @param type The node type
*/
public void setNodeType(NodeType type)
{
public void setNodeType(NodeType type) {
addField(ConfigureNodeFields.node_type, FormField.Type.list_single);
setAnswer(ConfigureNodeFields.node_type.getFieldName(), getListSingle(type.toString()));
}
@ -382,8 +352,7 @@ public class ConfigureForm extends Form
*
* @return true if they should be notified, false otherwise
*/
public boolean isNotifyConfig()
{
public boolean isNotifyConfig() {
return parseBoolean(getFieldValue(ConfigureNodeFields.notify_config));
}
@ -392,8 +361,7 @@ public class ConfigureForm extends Form
*
* @param notify true if subscribers should be notified, false otherwise
*/
public void setNotifyConfig(boolean notify)
{
public void setNotifyConfig(boolean notify) {
addField(ConfigureNodeFields.notify_config, FormField.Type.bool);
setAnswer(ConfigureNodeFields.notify_config.getFieldName(), notify);
}
@ -403,8 +371,7 @@ public class ConfigureForm extends Form
*
* @return true if subscribers should be notified, false otherwise
*/
public boolean isNotifyDelete()
{
public boolean isNotifyDelete() {
return parseBoolean(getFieldValue(ConfigureNodeFields.notify_delete));
}
@ -413,8 +380,7 @@ public class ConfigureForm extends Form
*
* @param notify true if subscribers should be notified, false otherwise
*/
public void setNotifyDelete(boolean notify)
{
public void setNotifyDelete(boolean notify) {
addField(ConfigureNodeFields.notify_delete, FormField.Type.bool);
setAnswer(ConfigureNodeFields.notify_delete.getFieldName(), notify);
}
@ -425,8 +391,7 @@ public class ConfigureForm extends Form
*
* @return true if subscribers should be notified, false otherwise
*/
public boolean isNotifyRetract()
{
public boolean isNotifyRetract() {
return parseBoolean(getFieldValue(ConfigureNodeFields.notify_retract));
}
@ -436,8 +401,7 @@ public class ConfigureForm extends Form
*
* @param notify true if subscribers should be notified, false otherwise
*/
public void setNotifyRetract(boolean notify)
{
public void setNotifyRetract(boolean notify) {
addField(ConfigureNodeFields.notify_retract, FormField.Type.bool);
setAnswer(ConfigureNodeFields.notify_retract.getFieldName(), notify);
}
@ -447,8 +411,7 @@ public class ConfigureForm extends Form
*
* @return true if items are persisted
*/
public boolean isPersistItems()
{
public boolean isPersistItems() {
return parseBoolean(getFieldValue(ConfigureNodeFields.persist_items));
}
@ -457,8 +420,7 @@ public class ConfigureForm extends Form
*
* @param persist true if items should be persisted, false otherwise
*/
public void setPersistentItems(boolean persist)
{
public void setPersistentItems(boolean persist) {
addField(ConfigureNodeFields.persist_items, FormField.Type.bool);
setAnswer(ConfigureNodeFields.persist_items.getFieldName(), persist);
}
@ -468,8 +430,7 @@ public class ConfigureForm extends Form
*
* @return true if users must be available
*/
public boolean isPresenceBasedDelivery()
{
public boolean isPresenceBasedDelivery() {
return parseBoolean(getFieldValue(ConfigureNodeFields.presence_based_delivery));
}
@ -478,8 +439,7 @@ public class ConfigureForm extends Form
*
* @param presenceBased true if user must be available, false otherwise
*/
public void setPresenceBasedDelivery(boolean presenceBased)
{
public void setPresenceBasedDelivery(boolean presenceBased) {
addField(ConfigureNodeFields.presence_based_delivery, FormField.Type.bool);
setAnswer(ConfigureNodeFields.presence_based_delivery.getFieldName(), presenceBased);
}
@ -489,8 +449,7 @@ public class ConfigureForm extends Form
*
* @return The publishing model
*/
public PublishModel getPublishModel()
{
public PublishModel getPublishModel() {
String value = getFieldValue(ConfigureNodeFields.publish_model);
if (value == null)
@ -504,8 +463,7 @@ public class ConfigureForm extends Form
*
* @param publish The enum representing the possible options for the publishing model
*/
public void setPublishModel(PublishModel publish)
{
public void setPublishModel(PublishModel publish) {
addField(ConfigureNodeFields.publish_model, FormField.Type.list_single);
setAnswer(ConfigureNodeFields.publish_model.getFieldName(), getListSingle(publish.toString()));
}
@ -515,8 +473,7 @@ public class ConfigureForm extends Form
*
* @return The reply room JID's
*/
public List<String> getReplyRoom()
{
public List<String> getReplyRoom() {
return getFieldValues(ConfigureNodeFields.replyroom);
}
@ -525,8 +482,7 @@ public class ConfigureForm extends Form
*
* @param replyRooms The multi user chat room to use as reply rooms
*/
public void setReplyRoom(List<String> replyRooms)
{
public void setReplyRoom(List<String> replyRooms) {
addField(ConfigureNodeFields.replyroom, FormField.Type.list_multi);
setAnswer(ConfigureNodeFields.replyroom.getFieldName(), replyRooms);
}
@ -536,8 +492,7 @@ public class ConfigureForm extends Form
*
* @return The JID's
*/
public List<String> getReplyTo()
{
public List<String> getReplyTo() {
return getFieldValues(ConfigureNodeFields.replyto);
}
@ -546,8 +501,7 @@ public class ConfigureForm extends Form
*
* @param replyTos The JID's to reply to
*/
public void setReplyTo(List<String> replyTos)
{
public void setReplyTo(List<String> replyTos) {
addField(ConfigureNodeFields.replyto, FormField.Type.list_multi);
setAnswer(ConfigureNodeFields.replyto.getFieldName(), replyTos);
}
@ -557,8 +511,7 @@ public class ConfigureForm extends Form
*
* @return The roster groups
*/
public List<String> getRosterGroupsAllowed()
{
public List<String> getRosterGroupsAllowed() {
return getFieldValues(ConfigureNodeFields.roster_groups_allowed);
}
@ -567,8 +520,7 @@ public class ConfigureForm extends Form
*
* @param groups The roster groups
*/
public void setRosterGroupsAllowed(List<String> groups)
{
public void setRosterGroupsAllowed(List<String> groups) {
addField(ConfigureNodeFields.roster_groups_allowed, FormField.Type.list_multi);
setAnswer(ConfigureNodeFields.roster_groups_allowed.getFieldName(), groups);
}
@ -580,8 +532,7 @@ public class ConfigureForm extends Form
* @deprecated use {@link #isSubscribe()} instead
*/
@Deprecated
public boolean isSubscibe()
{
public boolean isSubscibe() {
return isSubscribe();
}
@ -599,8 +550,7 @@ public class ConfigureForm extends Form
*
* @param subscribe true if they are, false otherwise
*/
public void setSubscribe(boolean subscribe)
{
public void setSubscribe(boolean subscribe) {
addField(ConfigureNodeFields.subscribe, FormField.Type.bool);
setAnswer(ConfigureNodeFields.subscribe.getFieldName(), subscribe);
}
@ -611,8 +561,7 @@ public class ConfigureForm extends Form
* @return The node title
*/
@Override
public String getTitle()
{
public String getTitle() {
return getFieldValue(ConfigureNodeFields.title);
}
@ -622,8 +571,7 @@ public class ConfigureForm extends Form
* @param title The node title
*/
@Override
public void setTitle(String title)
{
public void setTitle(String title) {
addField(ConfigureNodeFields.title, FormField.Type.text_single);
setAnswer(ConfigureNodeFields.title.getFieldName(), title);
}
@ -633,8 +581,7 @@ public class ConfigureForm extends Form
*
* @return The type of node data
*/
public String getDataType()
{
public String getDataType() {
return getFieldValue(ConfigureNodeFields.type);
}
@ -643,27 +590,23 @@ public class ConfigureForm extends Form
*
* @param type The type of node data
*/
public void setDataType(String type)
{
public void setDataType(String type) {
addField(ConfigureNodeFields.type, FormField.Type.text_single);
setAnswer(ConfigureNodeFields.type.getFieldName(), type);
}
@Override
public String toString()
{
public String toString() {
StringBuilder result = new StringBuilder(getClass().getName() + " Content [");
for (FormField formField : getFields())
{
for (FormField formField : getFields()) {
result.append('(');
result.append(formField.getVariable());
result.append(':');
StringBuilder valuesBuilder = new StringBuilder();
for (String value : formField.getValues())
{
for (String value : formField.getValues()) {
if (valuesBuilder.length() > 0)
result.append(',');
valuesBuilder.append(value);
@ -678,39 +621,33 @@ public class ConfigureForm extends Form
return result.toString();
}
private static boolean parseBoolean(String fieldValue)
{
private static boolean parseBoolean(String fieldValue) {
return ("1".equals(fieldValue) || "true".equals(fieldValue));
}
private String getFieldValue(ConfigureNodeFields field)
{
private String getFieldValue(ConfigureNodeFields field) {
FormField formField = getField(field.getFieldName());
return (formField.getValues().isEmpty()) ? null : formField.getValues().get(0);
}
private List<String> getFieldValues(ConfigureNodeFields field)
{
private List<String> getFieldValues(ConfigureNodeFields field) {
FormField formField = getField(field.getFieldName());
return formField.getValues();
}
private void addField(ConfigureNodeFields nodeField, FormField.Type type)
{
private void addField(ConfigureNodeFields nodeField, FormField.Type type) {
String fieldName = nodeField.getFieldName();
if (getField(fieldName) == null)
{
if (getField(fieldName) == null) {
FormField field = new FormField(fieldName);
field.setType(type);
addField(field);
}
}
private static List<String> getListSingle(String value)
{
private static List<String> getListSingle(String value) {
List<String> list = new ArrayList<>(1);
list.add(value);
return list;

View file

@ -27,8 +27,7 @@ import org.jivesoftware.smackx.xdata.Form;
*
* @author Robin Collier
*/
public enum ConfigureNodeFields
{
public enum ConfigureNodeFields {
/**
* Determines who may subscribe and retrieve items.
*
@ -214,8 +213,7 @@ public enum ConfigureNodeFields
*/
type;
public String getFieldName()
{
public String getFieldName() {
return "pubsub#" + toString();
}
}

View file

@ -37,8 +37,7 @@ import org.jivesoftware.smack.util.PacketParserUtils;
*
* @author Robin Collier
*/
public interface EmbeddedPacketExtension extends ExtensionElement
{
public interface EmbeddedPacketExtension extends ExtensionElement {
/**
* Get the list of embedded {@link ExtensionElement} objects.
*

View file

@ -33,8 +33,7 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
*
* @author Robin Collier
*/
public class EventElement implements EmbeddedPacketExtension
{
public class EventElement implements EmbeddedPacketExtension {
/**
* The constant String "event".
*/
@ -48,37 +47,31 @@ public class EventElement implements EmbeddedPacketExtension
private final EventElementType type;
private final NodeExtension ext;
public EventElement(EventElementType eventType, NodeExtension eventExt)
{
public EventElement(EventElementType eventType, NodeExtension eventExt) {
type = eventType;
ext = eventExt;
}
public EventElementType getEventType()
{
public EventElementType getEventType() {
return type;
}
@Override
public List<ExtensionElement> getExtensions()
{
public List<ExtensionElement> getExtensions() {
return Arrays.asList(new ExtensionElement[] {getEvent()});
}
public NodeExtension getEvent()
{
public NodeExtension getEvent() {
return ext;
}
@Override
public String getElementName()
{
public String getElementName() {
return "event";
}
@Override
public String getNamespace()
{
public String getNamespace() {
return PubSubNamespace.EVENT.getXmlns();
}

View file

@ -22,8 +22,8 @@ package org.jivesoftware.smackx.pubsub;
*
* @author Robin Collier
*/
public enum EventElementType
{
public enum EventElementType {
/** A node has been associated or disassociated with a collection node. */
collection,

View file

@ -26,8 +26,7 @@ import org.jivesoftware.smackx.xdata.Form;
*
* @author Robin Collier
*/
public class FormNode extends NodeExtension
{
public class FormNode extends NodeExtension {
private final Form configForm;
/**
@ -36,8 +35,7 @@ public class FormNode extends NodeExtension
* @param formType The type of form being sent
* @param submitForm The form
*/
public FormNode(FormNodeType formType, Form submitForm)
{
public FormNode(FormNodeType formType, Form submitForm) {
super(formType.getNodeElement());
if (submitForm == null)
@ -53,8 +51,7 @@ public class FormNode extends NodeExtension
* @param nodeId The node the form is associated with
* @param submitForm The form
*/
public FormNode(FormNodeType formType, String nodeId, Form submitForm)
{
public FormNode(FormNodeType formType, String nodeId, Form submitForm) {
super(formType.getNodeElement(), nodeId);
if (submitForm == null)
@ -67,25 +64,20 @@ public class FormNode extends NodeExtension
*
* @return The form
*/
public Form getForm()
{
public Form getForm() {
return configForm;
}
@Override
public CharSequence toXML()
{
if (configForm == null)
{
public CharSequence toXML() {
if (configForm == null) {
return super.toXML();
}
else
{
else {
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
if (getNode() != null)
{
if (getNode() != null) {
builder.append(" node='");
builder.append(getNode());
builder.append("'>");

View file

@ -38,15 +38,12 @@ public enum FormNodeType {
/** Form which represents the default node configuration options. */
DEFAULT;
public PubSubElementType getNodeElement()
{
public PubSubElementType getNodeElement() {
return PubSubElementType.valueOf(toString());
}
public static FormNodeType valueOfFromElementName(String elem, String configNamespace)
{
if ("configure".equals(elem) && PubSubNamespace.OWNER.getXmlns().equals(configNamespace))
{
public static FormNodeType valueOfFromElementName(String elem, String configNamespace) {
if ("configure".equals(elem) && PubSubNamespace.OWNER.getXmlns().equals(configNamespace)) {
return CONFIGURE_OWNER;
}
return valueOf(elem.toUpperCase(Locale.US));

View file

@ -23,40 +23,33 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*
* @author Robin Collier
*/
public class GetItemsRequest extends NodeExtension
{
public class GetItemsRequest extends NodeExtension {
protected final String subId;
protected final int maxItems;
public GetItemsRequest(String nodeId)
{
public GetItemsRequest(String nodeId) {
this(nodeId, null, -1);
}
public GetItemsRequest(String nodeId, String subscriptionId)
{
public GetItemsRequest(String nodeId, String subscriptionId) {
this(nodeId, subscriptionId, -1);
}
public GetItemsRequest(String nodeId, int maxItemsToReturn)
{
public GetItemsRequest(String nodeId, int maxItemsToReturn) {
this(nodeId, null, maxItemsToReturn);
}
public GetItemsRequest(String nodeId, String subscriptionId, int maxItemsToReturn)
{
public GetItemsRequest(String nodeId, String subscriptionId, int maxItemsToReturn) {
super(PubSubElementType.ITEMS, nodeId);
maxItems = maxItemsToReturn;
subId = subscriptionId;
}
public String getSubscriptionId()
{
public String getSubscriptionId() {
return subId;
}
public int getMaxItems()
{
public int getMaxItems() {
return maxItems;
}

View file

@ -49,8 +49,7 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider;
*
* @author Robin Collier
*/
public class Item extends NodeExtension
{
public class Item extends NodeExtension {
private String id;
/**
@ -60,8 +59,7 @@ public class Item extends NodeExtension
* set to false, no <tt>Item</tt> is sent to the node, you have to use the {@link LeafNode#publish()}
* method in this case.
*/
public Item()
{
public Item() {
super(PubSubElementType.ITEM);
}
@ -72,8 +70,7 @@ public class Item extends NodeExtension
* @param itemId The id if the item. It must be unique within the node unless overwriting and existing item.
* Passing null is the equivalent of calling {@link #Item()}.
*/
public Item(String itemId)
{
public Item(String itemId) {
// The element type is actually irrelevant since we override getNamespace() to return null
super(PubSubElementType.ITEM);
id = itemId;
@ -90,8 +87,7 @@ public class Item extends NodeExtension
* @param itemId The id of the item.
* @param nodeId The id of the node which the item was published to.
*/
public Item(String itemId, String nodeId)
{
public Item(String itemId, String nodeId) {
super(PubSubElementType.ITEM_EVENT, nodeId);
id = itemId;
}
@ -101,24 +97,20 @@ public class Item extends NodeExtension
*
* @return The id
*/
public String getId()
{
public String getId() {
return id;
}
@Override
public String getNamespace()
{
public String getNamespace() {
return null;
}
@Override
public String toXML()
{
public String toXML() {
StringBuilder builder = new StringBuilder("<item");
if (id != null)
{
if (id != null) {
builder.append(" id='");
builder.append(id);
builder.append('\'');
@ -135,8 +127,7 @@ public class Item extends NodeExtension
}
@Override
public String toString()
{
public String toString() {
return getClass().getName() + " | Content [" + toXML() + "]";
}
}

View file

@ -24,8 +24,7 @@ import java.util.List;
*
* @author Robin Collier
*/
public class ItemDeleteEvent extends SubscriptionEvent
{
public class ItemDeleteEvent extends SubscriptionEvent {
private List<String> itemIds = Collections.emptyList();
/**
@ -38,8 +37,7 @@ public class ItemDeleteEvent extends SubscriptionEvent
* @param deletedItemIds The item ids of the items that were deleted.
* @param subscriptionIds The subscriptions that match the event.
*/
public ItemDeleteEvent(String nodeId, List<String> deletedItemIds, List<String> subscriptionIds)
{
public ItemDeleteEvent(String nodeId, List<String> deletedItemIds, List<String> subscriptionIds) {
super(nodeId, subscriptionIds);
if (deletedItemIds == null)
@ -52,14 +50,12 @@ public class ItemDeleteEvent extends SubscriptionEvent
*
* @return List of item id's
*/
public List<String> getItemIds()
{
public List<String> getItemIds() {
return Collections.unmodifiableList(itemIds);
}
@Override
public String toString()
{
public String toString() {
return getClass().getName() + " [subscriptions: " + getSubscriptions() + "], [Deleted Items: " + itemIds + ']';
}
}

View file

@ -25,8 +25,7 @@ import java.util.List;
*
* @author Robin Collier
*/
public class ItemPublishEvent<T extends Item> extends SubscriptionEvent
{
public class ItemPublishEvent<T extends Item> extends SubscriptionEvent {
private List<T> items;
private Date originalDate;
@ -37,8 +36,7 @@ public class ItemPublishEvent<T extends Item> extends SubscriptionEvent
* @param nodeId The id of the node the event came from
* @param eventItems The list of {@link Item} that were published
*/
public ItemPublishEvent(String nodeId, List<T> eventItems)
{
public ItemPublishEvent(String nodeId, List<T> eventItems) {
super(nodeId);
items = eventItems;
}
@ -53,8 +51,7 @@ public class ItemPublishEvent<T extends Item> extends SubscriptionEvent
* @param eventItems The list of {@link Item} that were published
* @param subscriptionIds The list of subscriptionIds
*/
public ItemPublishEvent(String nodeId, List<T> eventItems, List<String> subscriptionIds)
{
public ItemPublishEvent(String nodeId, List<T> eventItems, List<String> subscriptionIds) {
super(nodeId, subscriptionIds);
items = eventItems;
}
@ -71,8 +68,7 @@ public class ItemPublishEvent<T extends Item> extends SubscriptionEvent
* @param subscriptionIds The list of subscriptionIds
* @param publishedDate date of publication.
*/
public ItemPublishEvent(String nodeId, List<T> eventItems, List<String> subscriptionIds, Date publishedDate)
{
public ItemPublishEvent(String nodeId, List<T> eventItems, List<String> subscriptionIds, Date publishedDate) {
super(nodeId, subscriptionIds);
items = eventItems;
@ -85,8 +81,7 @@ public class ItemPublishEvent<T extends Item> extends SubscriptionEvent
*
* @return The list of published {@link Item}
*/
public List<T> getItems()
{
public List<T> getItems() {
return Collections.unmodifiableList(items);
}
@ -100,8 +95,7 @@ public class ItemPublishEvent<T extends Item> extends SubscriptionEvent
*
* @return true if the items are delayed, false otherwise.
*/
public boolean isDelayed()
{
public boolean isDelayed() {
return (originalDate != null);
}
@ -111,14 +105,12 @@ public class ItemPublishEvent<T extends Item> extends SubscriptionEvent
*
* @return date of publication.
*/
public Date getPublishedDate()
{
public Date getPublishedDate() {
return originalDate;
}
@Override
public String toString()
{
public String toString() {
return getClass().getName() + " [subscriptions: " + getSubscriptions() + "], [Delayed: " +
(isDelayed() ? originalDate.toString() : "false") + ']';
}

View file

@ -22,8 +22,7 @@ package org.jivesoftware.smackx.pubsub;
*
* @author Robin Collier
*/
public enum ItemReply
{
public enum ItemReply {
/** The node owner. */
owner,

View file

@ -34,14 +34,12 @@ import org.jivesoftware.smack.packet.ExtensionElement;
*
* @author Robin Collier
*/
public class ItemsExtension extends NodeExtension implements EmbeddedPacketExtension
{
public class ItemsExtension extends NodeExtension implements EmbeddedPacketExtension {
protected ItemsElementType type;
protected Boolean notify;
protected List<? extends ExtensionElement> items;
public enum ItemsElementType
{
public enum ItemsElementType {
/** An items element, which has an optional <b>max_items</b> attribute when requesting items. */
items(PubSubElementType.ITEMS, "max_items"),
@ -51,19 +49,16 @@ public class ItemsExtension extends NodeExtension implements EmbeddedPacketExten
private final PubSubElementType elem;
private final String att;
ItemsElementType(PubSubElementType nodeElement, String attribute)
{
ItemsElementType(PubSubElementType nodeElement, String attribute) {
elem = nodeElement;
att = attribute;
}
public PubSubElementType getNodeElement()
{
public PubSubElementType getNodeElement() {
return elem;
}
public String getElementAttribute()
{
public String getElementAttribute() {
return att;
}
}
@ -87,8 +82,7 @@ public class ItemsExtension extends NodeExtension implements EmbeddedPacketExten
* @param nodeId The node to which the items are being sent or deleted
* @param items The list of {@link Item} or {@link RetractItem}
*/
public ItemsExtension(ItemsElementType itemsType, String nodeId, List<? extends ExtensionElement> items)
{
public ItemsExtension(ItemsElementType itemsType, String nodeId, List<? extends ExtensionElement> items) {
super(itemsType.getNodeElement(), nodeId);
type = itemsType;
this.items = items;
@ -113,8 +107,7 @@ public class ItemsExtension extends NodeExtension implements EmbeddedPacketExten
* @param items The list of {@link Item} or {@link RetractItem}
* @param notify
*/
public ItemsExtension(String nodeId, List<? extends ExtensionElement> items, boolean notify)
{
public ItemsExtension(String nodeId, List<? extends ExtensionElement> items, boolean notify) {
super(ItemsElementType.retract.getNodeElement(), nodeId);
type = ItemsElementType.retract;
this.items = items;
@ -126,15 +119,13 @@ public class ItemsExtension extends NodeExtension implements EmbeddedPacketExten
*
* @return The element type
*/
public ItemsElementType getItemsElementType()
{
public ItemsElementType getItemsElementType() {
return type;
}
@Override
@SuppressWarnings("unchecked")
public List<ExtensionElement> getExtensions()
{
public List<ExtensionElement> getExtensions() {
return (List<ExtensionElement>) getItems();
}
@ -143,8 +134,7 @@ public class ItemsExtension extends NodeExtension implements EmbeddedPacketExten
*
* @return List of {@link Item}, {@link RetractItem}, or null
*/
public List<? extends ExtensionElement> getItems()
{
public List<? extends ExtensionElement> getItems() {
return items;
}
@ -153,38 +143,31 @@ public class ItemsExtension extends NodeExtension implements EmbeddedPacketExten
*
* @return The attribute value
*/
public boolean getNotify()
{
public boolean getNotify() {
return notify;
}
@Override
public CharSequence toXML()
{
if ((items == null) || (items.size() == 0))
{
public CharSequence toXML() {
if ((items == null) || (items.size() == 0)) {
return super.toXML();
}
else
{
else {
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
builder.append(" node='");
builder.append(getNode());
if (notify != null)
{
if (notify != null) {
builder.append("' ");
builder.append(type.getElementAttribute());
builder.append("='");
builder.append(notify.equals(Boolean.TRUE) ? 1 : 0);
builder.append("'>");
}
else
{
else {
builder.append("'>");
for (ExtensionElement item : items)
{
for (ExtensionElement item : items) {
builder.append(item.toXML());
}
}
@ -197,8 +180,7 @@ public class ItemsExtension extends NodeExtension implements EmbeddedPacketExten
}
@Override
public String toString()
{
public String toString() {
return getClass().getName() + "Content [" + toXML() + "]";
}

View file

@ -37,10 +37,8 @@ import org.jivesoftware.smackx.pubsub.packet.PubSub;
*
* @author Robin Collier
*/
public class LeafNode extends Node
{
LeafNode(PubSubManager pubSubManager, String nodeId)
{
public class LeafNode extends Node {
LeafNode(PubSubManager pubSubManager, String nodeId) {
super(pubSubManager, nodeId);
}
@ -54,8 +52,7 @@ public class LeafNode extends Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverItems discoverItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public DiscoverItems discoverItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverItems items = new DiscoverItems();
items.setTo(pubSubManager.getServiceJid());
items.setNode(getId());
@ -72,8 +69,7 @@ public class LeafNode extends Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public <T extends Item> List<T> getItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return getItems((List<ExtensionElement>) null, null);
}
@ -92,8 +88,7 @@ public class LeafNode extends Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public <T extends Item> List<T> getItems(String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), subscriptionId));
return getItems(request);
}
@ -114,12 +109,10 @@ public class LeafNode extends Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(Collection<String> ids) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public <T extends Item> List<T> getItems(Collection<String> ids) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
List<Item> itemList = new ArrayList<>(ids.size());
for (String id : ids)
{
for (String id : ids) {
itemList.add(new Item(id));
}
PubSub request = createPubsubPacket(Type.get, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList));
@ -138,8 +131,7 @@ public class LeafNode extends Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(int maxItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public <T extends Item> List<T> getItems(int maxItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), maxItems));
return getItems(request);
}
@ -160,8 +152,7 @@ public class LeafNode extends Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(int maxItems, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public <T extends Item> List<T> getItems(int maxItems, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), subscriptionId, maxItems));
return getItems(request);
}
@ -224,8 +215,7 @@ public class LeafNode extends Node
* @deprecated use {@link #publish()} instead.
*/
@Deprecated
public void send() throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException
{
public void send() throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
publish();
}
@ -248,8 +238,7 @@ public class LeafNode extends Node
*/
@SuppressWarnings("unchecked")
@Deprecated
public <T extends Item> void send(T item) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException
{
public <T extends Item> void send(T item) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
publish(item);
}
@ -269,8 +258,7 @@ public class LeafNode extends Node
* @deprecated use {@link #publish(Collection)} instead.
*/
@Deprecated
public <T extends Item> void send(Collection<T> items) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException
{
public <T extends Item> void send(Collection<T> items) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
publish(items);
}
@ -287,8 +275,7 @@ public class LeafNode extends Node
* @throws InterruptedException
*
*/
public void publish() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public void publish() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId()));
pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
@ -316,8 +303,7 @@ public class LeafNode extends Node
*
*/
@SuppressWarnings("unchecked")
public <T extends Item> void publish(T item) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public <T extends Item> void publish(T item) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Collection<T> items = new ArrayList<>(1);
items.add((item == null ? (T) new Item() : item));
publish(items);
@ -338,8 +324,7 @@ public class LeafNode extends Node
* @throws InterruptedException
*
*/
public <T extends Item> void publish(Collection<T> items) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public <T extends Item> void publish(Collection<T> items) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub packet = createPubsubPacket(Type.set, new PublishItem<>(getId(), items));
pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
@ -355,8 +340,7 @@ public class LeafNode extends Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deleteAllItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public void deleteAllItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub request = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PURGE_OWNER, getId()), PubSubElementType.PURGE_OWNER.getNamespace());
pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
@ -371,8 +355,7 @@ public class LeafNode extends Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deleteItem(String itemId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public void deleteItem(String itemId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Collection<String> items = new ArrayList<>(1);
items.add(itemId);
deleteItem(items);
@ -387,12 +370,10 @@ public class LeafNode extends Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deleteItem(Collection<String> itemIds) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public void deleteItem(Collection<String> itemIds) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
List<Item> items = new ArrayList<>(itemIds.size());
for (String id : itemIds)
{
for (String id : itemIds) {
items.add(new Item(id));
}
PubSub request = createPubsubPacket(Type.set, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items));

View file

@ -44,8 +44,7 @@ import org.jivesoftware.smackx.shim.packet.Header;
import org.jivesoftware.smackx.shim.packet.HeadersExtension;
import org.jivesoftware.smackx.xdata.Form;
public abstract class Node
{
public abstract class Node {
protected final PubSubManager pubSubManager;
protected final String id;
@ -60,8 +59,7 @@ public abstract class Node
* @param pubSubManager The PubSubManager for the connection the node is associated with
* @param nodeId The node id
*/
Node(PubSubManager pubSubManager, String nodeId)
{
Node(PubSubManager pubSubManager, String nodeId) {
this.pubSubManager = pubSubManager;
id = nodeId;
}
@ -71,8 +69,7 @@ public abstract class Node
*
* @return the node id
*/
public String getId()
{
public String getId() {
return id;
}
/**
@ -85,8 +82,7 @@ public abstract class Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public ConfigureForm getNodeConfiguration() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public ConfigureForm getNodeConfiguration() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(
PubSubElementType.CONFIGURE_OWNER, getId()), PubSubNamespace.OWNER);
Stanza reply = sendPubsubPacket(pubSub);
@ -102,8 +98,7 @@ public abstract class Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public void sendConfigurationForm(Form submitForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public void sendConfigurationForm(Form submitForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub packet = createPubsubPacket(Type.set, new FormNode(FormNodeType.CONFIGURE_OWNER,
getId(), submitForm), PubSubNamespace.OWNER);
pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
@ -118,8 +113,7 @@ public abstract class Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverInfo discoverInfo() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public DiscoverInfo discoverInfo() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverInfo info = new DiscoverInfo();
info.setTo(pubSubManager.getServiceJid());
info.setNode(getId());
@ -136,8 +130,7 @@ public abstract class Node
* @throws InterruptedException
*
*/
public List<Subscription> getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public List<Subscription> getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return getSubscriptions(null, null);
}
@ -365,8 +358,7 @@ public abstract class Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public Subscription subscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public Subscription subscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub pubSub = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
PubSub reply = sendPubsubPacket(pubSub);
return reply.getExtension(PubSubElementType.SUBSCRIPTION);
@ -394,8 +386,7 @@ public abstract class Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public Subscription subscribe(String jid, SubscribeForm subForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public Subscription subscribe(String jid, SubscribeForm subForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub request = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
request.addExtension(new FormNode(FormNodeType.OPTIONS, subForm));
PubSub reply = sendPubsubPacket(request);
@ -414,8 +405,7 @@ public abstract class Node
* @throws InterruptedException
*
*/
public void unsubscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public void unsubscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
unsubscribe(jid, null);
}
@ -429,8 +419,7 @@ public abstract class Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public void unsubscribe(String jid, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public void unsubscribe(String jid, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
sendPubsubPacket(createPubsubPacket(Type.set, new UnsubscribeExtension(jid, getId(), subscriptionId)));
}
@ -446,8 +435,7 @@ public abstract class Node
* @throws NotConnectedException
* @throws InterruptedException
*/
public SubscribeForm getSubscriptionOptions(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public SubscribeForm getSubscriptionOptions(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return getSubscriptionOptions(jid, null);
}
@ -465,8 +453,7 @@ public abstract class Node
* @throws InterruptedException
*
*/
public SubscribeForm getSubscriptionOptions(String jid, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public SubscribeForm getSubscriptionOptions(String jid, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub packet = sendPubsubPacket(createPubsubPacket(Type.get, new OptionsExtension(jid, getId(), subscriptionId)));
FormNode ext = packet.getExtension(PubSubElementType.OPTIONS);
return new SubscribeForm(ext.getForm());
@ -480,8 +467,7 @@ public abstract class Node
* @param listener The handler for the event
*/
@SuppressWarnings("unchecked")
public void addItemEventListener(@SuppressWarnings("rawtypes") ItemEventListener listener)
{
public void addItemEventListener(@SuppressWarnings("rawtypes") ItemEventListener listener) {
StanzaListener conListener = new ItemEventTranslator(listener);
itemEventToListenerMap.put(listener, conListener);
pubSubManager.getConnection().addSyncStanzaListener(conListener, new EventContentFilter(EventElementType.items.toString(), "item"));
@ -492,8 +478,7 @@ public abstract class Node
*
* @param listener The handler to unregister
*/
public void removeItemEventListener(@SuppressWarnings("rawtypes") ItemEventListener listener)
{
public void removeItemEventListener(@SuppressWarnings("rawtypes") ItemEventListener listener) {
StanzaListener conListener = itemEventToListenerMap.remove(listener);
if (conListener != null)
@ -506,8 +491,7 @@ public abstract class Node
*
* @param listener The handler for the event
*/
public void addConfigurationListener(NodeConfigListener listener)
{
public void addConfigurationListener(NodeConfigListener listener) {
StanzaListener conListener = new NodeConfigTranslator(listener);
configEventToListenerMap.put(listener, conListener);
pubSubManager.getConnection().addSyncStanzaListener(conListener, new EventContentFilter(EventElementType.configuration.toString()));
@ -518,8 +502,7 @@ public abstract class Node
*
* @param listener The handler to unregister
*/
public void removeConfigurationListener(NodeConfigListener listener)
{
public void removeConfigurationListener(NodeConfigListener listener) {
StanzaListener conListener = configEventToListenerMap .remove(listener);
if (conListener != null)
@ -532,8 +515,7 @@ public abstract class Node
*
* @param listener The handler for the event
*/
public void addItemDeleteListener(ItemDeleteListener listener)
{
public void addItemDeleteListener(ItemDeleteListener listener) {
StanzaListener delListener = new ItemDeleteTranslator(listener);
itemDeleteToListenerMap.put(listener, delListener);
EventContentFilter deleteItem = new EventContentFilter(EventElementType.items.toString(), "retract");
@ -547,8 +529,7 @@ public abstract class Node
*
* @param listener The handler to unregister
*/
public void removeItemDeleteListener(ItemDeleteListener listener)
{
public void removeItemDeleteListener(ItemDeleteListener listener) {
StanzaListener conListener = itemDeleteToListenerMap .remove(listener);
if (conListener != null)
@ -556,38 +537,31 @@ public abstract class Node
}
@Override
public String toString()
{
public String toString() {
return super.toString() + " " + getClass().getName() + " id: " + id;
}
protected PubSub createPubsubPacket(Type type, ExtensionElement ext)
{
protected PubSub createPubsubPacket(Type type, ExtensionElement ext) {
return createPubsubPacket(type, ext, null);
}
protected PubSub createPubsubPacket(Type type, ExtensionElement ext, PubSubNamespace ns)
{
protected PubSub createPubsubPacket(Type type, ExtensionElement ext, PubSubNamespace ns) {
return PubSub.createPubsubPacket(pubSubManager.getServiceJid(), type, ext, ns);
}
protected PubSub sendPubsubPacket(PubSub packet) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
protected PubSub sendPubsubPacket(PubSub packet) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return pubSubManager.sendPubsubPacket(packet);
}
private static List<String> getSubscriptionIds(Stanza packet)
{
private static List<String> getSubscriptionIds(Stanza packet) {
HeadersExtension headers = packet.getExtension("headers", "http://jabber.org/protocol/shim");
List<String> values = null;
if (headers != null)
{
if (headers != null) {
values = new ArrayList<>(headers.getHeaders().size());
for (Header header : headers.getHeaders())
{
for (Header header : headers.getHeaders()) {
values.add(header.getValue());
}
}
@ -600,20 +574,17 @@ public abstract class Node
*
* @author Robin Collier
*/
public static class ItemEventTranslator implements StanzaListener
{
public static class ItemEventTranslator implements StanzaListener {
@SuppressWarnings("rawtypes")
private final ItemEventListener listener;
public ItemEventTranslator(@SuppressWarnings("rawtypes") ItemEventListener eventListener)
{
public ItemEventTranslator(@SuppressWarnings("rawtypes") ItemEventListener eventListener) {
listener = eventListener;
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void processStanza(Stanza packet)
{
public void processStanza(Stanza packet) {
EventElement event = packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
ItemsExtension itemsElem = (ItemsExtension) event.getEvent();
ItemPublishEvent eventItems = new ItemPublishEvent(itemsElem.getNode(), itemsElem.getItems(), getSubscriptionIds(packet), DelayInformationManager.getDelayTimestamp(packet));
@ -627,36 +598,30 @@ public abstract class Node
*
* @author Robin Collier
*/
public static class ItemDeleteTranslator implements StanzaListener
{
public static class ItemDeleteTranslator implements StanzaListener {
private final ItemDeleteListener listener;
public ItemDeleteTranslator(ItemDeleteListener eventListener)
{
public ItemDeleteTranslator(ItemDeleteListener eventListener) {
listener = eventListener;
}
@Override
public void processStanza(Stanza packet)
{
public void processStanza(Stanza packet) {
// CHECKSTYLE:OFF
EventElement event = packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
List<ExtensionElement> extList = event.getExtensions();
if (extList.get(0).getElementName().equals(PubSubElementType.PURGE_EVENT.getElementName()))
{
if (extList.get(0).getElementName().equals(PubSubElementType.PURGE_EVENT.getElementName())) {
listener.handlePurge();
}
else
{
else {
ItemsExtension itemsElem = (ItemsExtension)event.getEvent();
@SuppressWarnings("unchecked")
Collection<RetractItem> pubItems = (Collection<RetractItem>) itemsElem.getItems();
List<String> items = new ArrayList<>(pubItems.size());
for (RetractItem item : pubItems)
{
for (RetractItem item : pubItems) {
items.add(item.getId());
}
@ -673,18 +638,15 @@ public abstract class Node
*
* @author Robin Collier
*/
public static class NodeConfigTranslator implements StanzaListener
{
public static class NodeConfigTranslator implements StanzaListener {
private final NodeConfigListener listener;
public NodeConfigTranslator(NodeConfigListener eventListener)
{
public NodeConfigTranslator(NodeConfigListener eventListener) {
listener = eventListener;
}
@Override
public void processStanza(Stanza packet)
{
public void processStanza(Stanza packet) {
EventElement event = packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
ConfigurationEvent config = (ConfigurationEvent) event.getEvent();
@ -698,19 +660,16 @@ public abstract class Node
*
* @author Robin Collier
*/
class EventContentFilter extends FlexibleStanzaTypeFilter<Message>
{
class EventContentFilter extends FlexibleStanzaTypeFilter<Message> {
private final String firstElement;
private final String secondElement;
private final boolean allowEmpty;
EventContentFilter(String elementName)
{
EventContentFilter(String elementName) {
this(elementName, null);
}
EventContentFilter(String firstLevelElement, String secondLevelElement)
{
EventContentFilter(String firstLevelElement, String secondLevelElement) {
firstElement = firstLevelElement;
secondElement = secondLevelElement;
allowEmpty = firstElement.equals(EventElementType.items.toString())
@ -729,16 +688,14 @@ public abstract class Node
if (embedEvent == null)
return false;
if (embedEvent.getElementName().equals(firstElement))
{
if (embedEvent.getElementName().equals(firstElement)) {
if (!embedEvent.getNode().equals(getId()))
return false;
if (secondElement == null)
return true;
if (embedEvent instanceof EmbeddedPacketExtension)
{
if (embedEvent instanceof EmbeddedPacketExtension) {
List<ExtensionElement> secondLevelList = ((EmbeddedPacketExtension) embedEvent).getExtensions();
// XEP-0060 allows no elements on second level for notifications. See schema or

View file

@ -16,17 +16,14 @@
*/
package org.jivesoftware.smackx.pubsub;
public abstract class NodeEvent
{
public abstract class NodeEvent {
private String nodeId;
protected NodeEvent(String id)
{
protected NodeEvent(String id) {
nodeId = id;
}
public String getNodeId()
{
public String getNodeId() {
return nodeId;
}
}

View file

@ -26,8 +26,7 @@ import org.jivesoftware.smack.packet.ExtensionElement;
*
* @author Robin Collier
*/
public class NodeExtension implements ExtensionElement
{
public class NodeExtension implements ExtensionElement {
private final PubSubElementType element;
private final String node;
@ -38,8 +37,7 @@ public class NodeExtension implements ExtensionElement
* @param elem Defines the element name and namespace
* @param nodeId Specifies the id of the node
*/
public NodeExtension(PubSubElementType elem, String nodeId)
{
public NodeExtension(PubSubElementType elem, String nodeId) {
element = elem;
this.node = nodeId;
}
@ -50,8 +48,7 @@ public class NodeExtension implements ExtensionElement
*
* @param elem Defines the element name and namespace
*/
public NodeExtension(PubSubElementType elem)
{
public NodeExtension(PubSubElementType elem) {
this(elem, null);
}
@ -60,32 +57,27 @@ public class NodeExtension implements ExtensionElement
*
* @return The node id
*/
public String getNode()
{
public String getNode() {
return node;
}
@Override
public String getElementName()
{
public String getElementName() {
return element.getElementName();
}
@Override
public String getNamespace()
{
public String getNamespace() {
return element.getNamespace().getXmlns();
}
@Override
public CharSequence toXML()
{
public CharSequence toXML() {
return '<' + getElementName() + (node == null ? "" : " node='" + node + '\'') + "/>";
}
@Override
public String toString()
{
public String toString() {
return getClass().getName() + " - content [" + toXML() + "]";
}
}

View file

@ -21,8 +21,7 @@ package org.jivesoftware.smackx.pubsub;
*
* @author Robin Collier
*/
public enum NodeType
{
public enum NodeType {
leaf,
collection
}

View file

@ -23,35 +23,29 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*
* @author Robin Collier
*/
public class OptionsExtension extends NodeExtension
{
public class OptionsExtension extends NodeExtension {
protected String jid;
protected String id;
public OptionsExtension(String subscriptionJid)
{
public OptionsExtension(String subscriptionJid) {
this(subscriptionJid, null, null);
}
public OptionsExtension(String subscriptionJid, String nodeId)
{
public OptionsExtension(String subscriptionJid, String nodeId) {
this(subscriptionJid, nodeId, null);
}
public OptionsExtension(String jid, String nodeId, String subscriptionId)
{
public OptionsExtension(String jid, String nodeId, String subscriptionId) {
super(PubSubElementType.OPTIONS, nodeId);
this.jid = jid;
id = subscriptionId;
}
public String getJid()
{
public String getJid() {
return jid;
}
public String getId()
{
public String getId() {
return id;
}

View file

@ -48,8 +48,7 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider;
*
* @author Robin Collier
*/
public class PayloadItem<E extends ExtensionElement> extends Item
{
public class PayloadItem<E extends ExtensionElement> extends Item {
private final E payload;
/**
@ -57,8 +56,7 @@ public class PayloadItem<E extends ExtensionElement> extends Item
*
* @param payloadExt A {@link ExtensionElement} which represents the payload data.
*/
public PayloadItem(E payloadExt)
{
public PayloadItem(E payloadExt) {
super();
if (payloadExt == null)
@ -72,8 +70,7 @@ public class PayloadItem<E extends ExtensionElement> extends Item
* @param itemId The id of this item. It can be null if we want the server to set the id.
* @param payloadExt A {@link ExtensionElement} which represents the payload data.
*/
public PayloadItem(String itemId, E payloadExt)
{
public PayloadItem(String itemId, E payloadExt) {
super(itemId);
if (payloadExt == null)
@ -95,8 +92,7 @@ public class PayloadItem<E extends ExtensionElement> extends Item
* @param nodeId The id of the node the item was published to.
* @param payloadExt A {@link ExtensionElement} which represents the payload data.
*/
public PayloadItem(String itemId, String nodeId, E payloadExt)
{
public PayloadItem(String itemId, String nodeId, E payloadExt) {
super(itemId, nodeId);
if (payloadExt == null)
@ -110,18 +106,15 @@ public class PayloadItem<E extends ExtensionElement> extends Item
*
* @return The payload as a {@link ExtensionElement}.
*/
public E getPayload()
{
public E getPayload() {
return payload;
}
@Override
public String toXML()
{
public String toXML() {
StringBuilder builder = new StringBuilder("<item");
if (getId() != null)
{
if (getId() != null) {
builder.append(" id='");
builder.append(getId());
builder.append('\'');
@ -140,8 +133,7 @@ public class PayloadItem<E extends ExtensionElement> extends Item
}
@Override
public String toString()
{
public String toString() {
return getClass().getName() + " | Content [" + toXML() + "]";
}
}

View file

@ -22,7 +22,6 @@ package org.jivesoftware.smackx.pubsub;
*
* @author Robin Collier
*/
public enum PresenceState
{
public enum PresenceState {
chat, online, away, xa, dnd
}

View file

@ -26,8 +26,7 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
*
* @author Robin Collier
*/
public enum PubSubElementType
{
public enum PubSubElementType {
CREATE("create", PubSubNamespace.BASIC),
DELETE("delete", PubSubNamespace.OWNER),
DELETE_EVENT("delete", PubSubNamespace.EVENT),
@ -54,29 +53,24 @@ public enum PubSubElementType
private final String eName;
private final PubSubNamespace nSpace;
PubSubElementType(String elemName, PubSubNamespace ns)
{
PubSubElementType(String elemName, PubSubNamespace ns) {
eName = elemName;
nSpace = ns;
}
public PubSubNamespace getNamespace()
{
public PubSubNamespace getNamespace() {
return nSpace;
}
public String getElementName()
{
public String getElementName() {
return eName;
}
public static PubSubElementType valueOfFromElemName(String elemName, String namespace)
{
public static PubSubElementType valueOfFromElemName(String elemName, String namespace) {
int index = namespace.lastIndexOf('#');
String fragment = (index == -1 ? null : namespace.substring(index + 1));
if (fragment != null)
{
if (fragment != null) {
return valueOf((elemName + '_' + fragment).toUpperCase(Locale.US));
}
return valueOf(elemName.toUpperCase(Locale.US).replace('-', '_'));

View file

@ -141,8 +141,7 @@ public final class PubSubManager extends Manager {
* @param connection The XMPP connection
* @param toAddress The pubsub specific to address (required for some servers)
*/
PubSubManager(XMPPConnection connection, BareJid toAddress)
{
PubSubManager(XMPPConnection connection, BareJid toAddress) {
super(connection);
pubSubService = toAddress;
}
@ -156,8 +155,7 @@ public final class PubSubManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
public LeafNode createNode() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public LeafNode createNode() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub reply = sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.CREATE), null);
NodeExtension elem = reply.getExtension("create", PubSubNamespace.BASIC.getXmlns());
@ -178,8 +176,7 @@ public final class PubSubManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
public LeafNode createNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public LeafNode createNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return (LeafNode) createNode(nodeId, null);
}
@ -197,13 +194,11 @@ public final class PubSubManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
public Node createNode(String nodeId, Form config) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public Node createNode(String nodeId, Form config) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub request = PubSub.createPubsubPacket(pubSubService, Type.set, new NodeExtension(PubSubElementType.CREATE, nodeId), null);
boolean isLeafNode = true;
if (config != null)
{
if (config != null) {
request.addExtension(new FormNode(FormNodeType.CONFIGURE, config));
FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName());
@ -234,12 +229,10 @@ public final class PubSubManager extends Manager {
* @throws InterruptedException
* @throws NotAPubSubNodeException
*/
public <T extends Node> T getNode(String id) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotAPubSubNodeException
{
public <T extends Node> T getNode(String id) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotAPubSubNodeException {
Node node = nodeMap.get(id);
if (node == null)
{
if (node == null) {
DiscoverInfo info = new DiscoverInfo();
info.setTo(pubSubService);
info.setNode(id);
@ -429,8 +422,7 @@ public final class PubSubManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverItems discoverNodes(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public DiscoverItems discoverNodes(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverItems items = new DiscoverItems();
if (nodeId != null)
@ -449,8 +441,7 @@ public final class PubSubManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Subscription> getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public List<Subscription> getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Stanza reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS), null);
SubscriptionsExtension subElem = reply.getExtension(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns());
return subElem.getSubscriptions();
@ -466,8 +457,7 @@ public final class PubSubManager extends Manager {
* @throws InterruptedException
*
*/
public List<Affiliation> getAffiliations() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public List<Affiliation> getAffiliations() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS), null);
AffiliationsExtension listElem = reply.getExtension(PubSubElementType.AFFILIATIONS);
return listElem.getAffiliations();
@ -482,8 +472,7 @@ public final class PubSubManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deleteNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public void deleteNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.DELETE, nodeId), PubSubElementType.DELETE.getNamespace());
nodeMap.remove(nodeId);
}
@ -497,8 +486,7 @@ public final class PubSubManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
public ConfigureForm getDefaultConfiguration() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public ConfigureForm getDefaultConfiguration() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// Errors will cause exceptions in getReply, so it only returns
// on success.
PubSub reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.DEFAULT), PubSubElementType.DEFAULT.getNamespace());
@ -524,8 +512,7 @@ public final class PubSubManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverInfo getSupportedFeatures() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public DiscoverInfo getSupportedFeatures() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
ServiceDiscoveryManager mgr = ServiceDiscoveryManager.getInstanceFor(connection());
return mgr.discoverInfo(pubSubService);
}

View file

@ -24,8 +24,7 @@ import java.util.Collection;
*
* @author Robin Collier
*/
public class PublishItem<T extends Item> extends NodeExtension
{
public class PublishItem<T extends Item> extends NodeExtension {
protected Collection<T> items;
/**
@ -34,8 +33,7 @@ public class PublishItem<T extends Item> extends NodeExtension
* @param nodeId The node to publish to
* @param toPublish The {@link Item} to publish
*/
public PublishItem(String nodeId, T toPublish)
{
public PublishItem(String nodeId, T toPublish) {
super(PubSubElementType.PUBLISH, nodeId);
items = new ArrayList<>(1);
items.add(toPublish);
@ -47,23 +45,20 @@ public class PublishItem<T extends Item> extends NodeExtension
* @param nodeId The node to publish to
* @param toPublish The list of {@link Item} to publish
*/
public PublishItem(String nodeId, Collection<T> toPublish)
{
public PublishItem(String nodeId, Collection<T> toPublish) {
super(PubSubElementType.PUBLISH, nodeId);
items = toPublish;
}
@Override
public String toXML()
{
public String toXML() {
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
builder.append(" node='");
builder.append(getNode());
builder.append("'>");
for (Item item : items)
{
for (Item item : items) {
builder.append(item.toXML());
}
builder.append("</publish>");

View file

@ -22,8 +22,7 @@ package org.jivesoftware.smackx.pubsub;
*
* @author Robin Collier
*/
public enum PublishModel
{
public enum PublishModel {
/** Only publishers may publish. */
publishers,

View file

@ -25,8 +25,7 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
*
* @author Robin Collier
*/
public class RetractItem implements ExtensionElement
{
public class RetractItem implements ExtensionElement {
private final String id;
/**
@ -34,33 +33,28 @@ public class RetractItem implements ExtensionElement
*
* @param itemId The id if the item deleted
*/
public RetractItem(String itemId)
{
public RetractItem(String itemId) {
if (itemId == null)
throw new IllegalArgumentException("itemId must not be 'null'");
id = itemId;
}
public String getId()
{
public String getId() {
return id;
}
@Override
public String getElementName()
{
public String getElementName() {
return "retract";
}
@Override
public String getNamespace()
{
public String getNamespace() {
return PubSubNamespace.EVENT.getXmlns();
}
@Override
public String toXML()
{
public String toXML() {
return "<retract id='" + id + "'/>";
}
}

View file

@ -24,8 +24,7 @@ import org.jivesoftware.smack.packet.ExtensionElement;
*
* @author Robin Collier
*/
public class SimplePayload implements ExtensionElement
{
public class SimplePayload implements ExtensionElement {
private final String elemName;
private final String ns;
private final CharSequence payload;
@ -38,34 +37,29 @@ public class SimplePayload implements ExtensionElement
* @param namespace The namespace of the payload, null if there is none
* @param xmlPayload The payload data
*/
public SimplePayload(String elementName, String namespace, CharSequence xmlPayload)
{
public SimplePayload(String elementName, String namespace, CharSequence xmlPayload) {
elemName = elementName;
payload = xmlPayload;
ns = namespace;
}
@Override
public String getElementName()
{
public String getElementName() {
return elemName;
}
@Override
public String getNamespace()
{
public String getNamespace() {
return ns;
}
@Override
public CharSequence toXML()
{
public CharSequence toXML() {
return payload;
}
@Override
public String toString()
{
public String toString() {
return getClass().getName() + "payload [" + toXML() + "]";
}
}

View file

@ -21,35 +21,29 @@ package org.jivesoftware.smackx.pubsub;
*
* @author Robin Collier
*/
public class SubscribeExtension extends NodeExtension
{
public class SubscribeExtension extends NodeExtension {
protected String jid;
public SubscribeExtension(String subscribeJid)
{
public SubscribeExtension(String subscribeJid) {
super(PubSubElementType.SUBSCRIBE);
jid = subscribeJid;
}
public SubscribeExtension(String subscribeJid, String nodeId)
{
public SubscribeExtension(String subscribeJid, String nodeId) {
super(PubSubElementType.SUBSCRIBE, nodeId);
jid = subscribeJid;
}
public String getJid()
{
public String getJid() {
return jid;
}
@Override
public String toXML()
{
public String toXML() {
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
if (getNode() != null)
{
if (getNode() != null) {
builder.append(" node='");
builder.append(getNode());
builder.append('\'');

View file

@ -39,20 +39,16 @@ import org.jxmpp.util.XmppDateTime;
*
* @author Robin Collier
*/
public class SubscribeForm extends Form
{
public SubscribeForm(DataForm configDataForm)
{
public class SubscribeForm extends Form {
public SubscribeForm(DataForm configDataForm) {
super(configDataForm);
}
public SubscribeForm(Form subscribeOptionsForm)
{
public SubscribeForm(Form subscribeOptionsForm) {
super(subscribeOptionsForm.getDataFormToSend());
}
public SubscribeForm(DataForm.Type formType)
{
public SubscribeForm(DataForm.Type formType) {
super(formType);
}
@ -61,8 +57,7 @@ public class SubscribeForm extends Form
*
* @return true if want to receive, false otherwise
*/
public boolean isDeliverOn()
{
public boolean isDeliverOn() {
return parseBoolean(getFieldValue(SubscribeOptionFields.deliver));
}
@ -71,8 +66,7 @@ public class SubscribeForm extends Form
*
* @param deliverNotifications
*/
public void setDeliverOn(boolean deliverNotifications)
{
public void setDeliverOn(boolean deliverNotifications) {
addField(SubscribeOptionFields.deliver, FormField.Type.bool);
setAnswer(SubscribeOptionFields.deliver.getFieldName(), deliverNotifications);
}
@ -82,8 +76,7 @@ public class SubscribeForm extends Form
*
* @return true to aggregate, false otherwise
*/
public boolean isDigestOn()
{
public boolean isDigestOn() {
return parseBoolean(getFieldValue(SubscribeOptionFields.digest));
}
@ -92,8 +85,7 @@ public class SubscribeForm extends Form
*
* @param digestOn true to aggregate, false otherwise
*/
public void setDigestOn(boolean digestOn)
{
public void setDigestOn(boolean digestOn) {
addField(SubscribeOptionFields.deliver, FormField.Type.bool);
setAnswer(SubscribeOptionFields.deliver.getFieldName(), digestOn);
}
@ -103,8 +95,7 @@ public class SubscribeForm extends Form
*
* @return The frequency in milliseconds
*/
public int getDigestFrequency()
{
public int getDigestFrequency() {
return Integer.parseInt(getFieldValue(SubscribeOptionFields.digest_frequency));
}
@ -113,8 +104,7 @@ public class SubscribeForm extends Form
*
* @param frequency The frequency in milliseconds
*/
public void setDigestFrequency(int frequency)
{
public void setDigestFrequency(int frequency) {
addField(SubscribeOptionFields.digest_frequency, FormField.Type.text_single);
setAnswer(SubscribeOptionFields.digest_frequency.getFieldName(), frequency);
}
@ -124,15 +114,12 @@ public class SubscribeForm extends Form
*
* @return The expiry date
*/
public Date getExpiry()
{
public Date getExpiry() {
String dateTime = getFieldValue(SubscribeOptionFields.expire);
try
{
try {
return XmppDateTime.parseDate(dateTime);
}
catch (ParseException e)
{
catch (ParseException e) {
UnknownFormatConversionException exc = new UnknownFormatConversionException(dateTime);
exc.initCause(e);
throw exc;
@ -144,8 +131,7 @@ public class SubscribeForm extends Form
*
* @param expire The expiry date
*/
public void setExpiry(Date expire)
{
public void setExpiry(Date expire) {
addField(SubscribeOptionFields.expire, FormField.Type.text_single);
setAnswer(SubscribeOptionFields.expire.getFieldName(), XmppDateTime.formatXEP0082Date(expire));
}
@ -156,8 +142,7 @@ public class SubscribeForm extends Form
*
* @return true to receive the message body, false otherwise
*/
public boolean isIncludeBody()
{
public boolean isIncludeBody() {
return parseBoolean(getFieldValue(SubscribeOptionFields.include_body));
}
@ -167,8 +152,7 @@ public class SubscribeForm extends Form
*
* @param include true to receive the message body, false otherwise
*/
public void setIncludeBody(boolean include)
{
public void setIncludeBody(boolean include) {
addField(SubscribeOptionFields.include_body, FormField.Type.bool);
setAnswer(SubscribeOptionFields.include_body.getFieldName(), include);
}
@ -179,12 +163,10 @@ public class SubscribeForm extends Form
*
* @return the list of states
*/
public List<PresenceState> getShowValues()
{
public List<PresenceState> getShowValues() {
ArrayList<PresenceState> result = new ArrayList<>(5);
for (String state : getFieldValues(SubscribeOptionFields.show_values))
{
for (String state : getFieldValues(SubscribeOptionFields.show_values)) {
result.add(PresenceState.valueOf(state));
}
return result;
@ -196,12 +178,10 @@ public class SubscribeForm extends Form
*
* @param stateValues The list of states
*/
public void setShowValues(Collection<PresenceState> stateValues)
{
public void setShowValues(Collection<PresenceState> stateValues) {
ArrayList<String> values = new ArrayList<>(stateValues.size());
for (PresenceState state : stateValues)
{
for (PresenceState state : stateValues) {
values.add(state.toString());
}
addField(SubscribeOptionFields.show_values, FormField.Type.list_multi);
@ -209,31 +189,26 @@ public class SubscribeForm extends Form
}
private static boolean parseBoolean(String fieldValue)
{
private static boolean parseBoolean(String fieldValue) {
return ("1".equals(fieldValue) || "true".equals(fieldValue));
}
private String getFieldValue(SubscribeOptionFields field)
{
private String getFieldValue(SubscribeOptionFields field) {
FormField formField = getField(field.getFieldName());
return formField.getValues().get(0);
}
private List<String> getFieldValues(SubscribeOptionFields field)
{
private List<String> getFieldValues(SubscribeOptionFields field) {
FormField formField = getField(field.getFieldName());
return formField.getValues();
}
private void addField(SubscribeOptionFields nodeField, FormField.Type type)
{
private void addField(SubscribeOptionFields nodeField, FormField.Type type) {
String fieldName = nodeField.getFieldName();
if (getField(fieldName) == null)
{
if (getField(fieldName) == null) {
FormField field = new FormField(fieldName);
field.setType(type);
addField(field);

View file

@ -24,8 +24,7 @@ import java.util.Calendar;
*
* @author Robin Collier
*/
public enum SubscribeOptionFields
{
public enum SubscribeOptionFields {
/**
* Whether an entity wants to receive or disable notifications.
*
@ -83,15 +82,13 @@ public enum SubscribeOptionFields
*/
subscription_depth;
public String getFieldName()
{
public String getFieldName() {
if (this == show_values)
return "pubsub#" + toString().replace('_', '-');
return "pubsub#" + toString();
}
public static SubscribeOptionFields valueOfFromElement(String elementName)
{
public static SubscribeOptionFields valueOfFromElement(String elementName) {
String portion = elementName.substring(elementName.lastIndexOf('#' + 1));
if ("show-values".equals(portion))

View file

@ -25,15 +25,13 @@ import org.jxmpp.jid.Jid;
*
* @author Robin Collier
*/
public class Subscription extends NodeExtension
{
public class Subscription extends NodeExtension {
protected Jid jid;
protected String id;
protected State state;
protected boolean configRequired = false;
public enum State
{
public enum State {
subscribed, unconfigured, pending, none
}
@ -43,8 +41,7 @@ public class Subscription extends NodeExtension
*
* @param subscriptionJid The subscriber JID
*/
public Subscription(Jid subscriptionJid)
{
public Subscription(Jid subscriptionJid) {
this(subscriptionJid, null, null, null);
}
@ -55,8 +52,7 @@ public class Subscription extends NodeExtension
* @param subscriptionJid The subscriber JID
* @param nodeId The node id
*/
public Subscription(Jid subscriptionJid, String nodeId)
{
public Subscription(Jid subscriptionJid, String nodeId) {
this(subscriptionJid, nodeId, null, null);
}
@ -69,8 +65,7 @@ public class Subscription extends NodeExtension
* @param subscriptionId The id of this subscription
* @param state The current state of the subscription
*/
public Subscription(Jid jid, String nodeId, String subscriptionId, State state)
{
public Subscription(Jid jid, String nodeId, String subscriptionId, State state) {
super(PubSubElementType.SUBSCRIPTION, nodeId);
this.jid = jid;
id = subscriptionId;
@ -88,8 +83,7 @@ public class Subscription extends NodeExtension
* @param state The current state of the subscription
* @param configRequired Is configuration required to complete the subscription
*/
public Subscription(Jid jid, String nodeId, String subscriptionId, State state, boolean configRequired)
{
public Subscription(Jid jid, String nodeId, String subscriptionId, State state, boolean configRequired) {
super(PubSubElementType.SUBSCRIPTION, nodeId);
this.jid = jid;
id = subscriptionId;
@ -102,8 +96,7 @@ public class Subscription extends NodeExtension
*
* @return The JID
*/
public Jid getJid()
{
public Jid getJid() {
return jid;
}
@ -112,8 +105,7 @@ public class Subscription extends NodeExtension
*
* @return The subscription id
*/
public String getId()
{
public String getId() {
return id;
}
@ -122,8 +114,7 @@ public class Subscription extends NodeExtension
*
* @return Current subscription state
*/
public State getState()
{
public State getState() {
return state;
}
@ -132,14 +123,12 @@ public class Subscription extends NodeExtension
*
* @return true if configuration is required, false otherwise
*/
public boolean isConfigRequired()
{
public boolean isConfigRequired() {
return configRequired;
}
@Override
public XmlStringBuilder toXML()
{
public XmlStringBuilder toXML() {
XmlStringBuilder builder = new XmlStringBuilder(this);
builder.attribute("jid", jid);
@ -151,8 +140,7 @@ public class Subscription extends NodeExtension
return builder;
}
private static void appendAttribute(StringBuilder builder, String att, String value)
{
private static void appendAttribute(StringBuilder builder, String att, String value) {
builder.append(' ');
builder.append(att);
builder.append("='");

View file

@ -24,8 +24,7 @@ import java.util.List;
*
* @author Robin Collier
*/
public abstract class SubscriptionEvent extends NodeEvent
{
public abstract class SubscriptionEvent extends NodeEvent {
private List<String> subIds = Collections.emptyList();
/**
@ -36,8 +35,7 @@ public abstract class SubscriptionEvent extends NodeEvent
*
* @param nodeId The id of the node the event came from
*/
protected SubscriptionEvent(String nodeId)
{
protected SubscriptionEvent(String nodeId) {
super(nodeId);
}
@ -47,8 +45,7 @@ public abstract class SubscriptionEvent extends NodeEvent
* @param nodeId The id of the node the event came from
* @param subscriptionIds The list of subscription id's
*/
protected SubscriptionEvent(String nodeId, List<String> subscriptionIds)
{
protected SubscriptionEvent(String nodeId, List<String> subscriptionIds) {
super(nodeId);
if (subscriptionIds != null)
@ -60,8 +57,7 @@ public abstract class SubscriptionEvent extends NodeEvent
*
* @return List of subscription id's
*/
public List<String> getSubscriptions()
{
public List<String> getSubscriptions() {
return Collections.unmodifiableList(subIds);
}
@ -70,8 +66,7 @@ public abstract class SubscriptionEvent extends NodeEvent
*
* @param subscriptionIds The list of subscription id's
*/
protected void setSubscriptions(List<String> subscriptionIds)
{
protected void setSubscriptions(List<String> subscriptionIds) {
if (subscriptionIds != null)
subIds = subscriptionIds;
}

View file

@ -24,8 +24,7 @@ import java.util.List;
*
* @author Robin Collier
*/
public class SubscriptionsExtension extends NodeExtension
{
public class SubscriptionsExtension extends NodeExtension {
protected List<Subscription> items = Collections.emptyList();
/**
@ -33,8 +32,7 @@ public class SubscriptionsExtension extends NodeExtension
*
* @param subList The list of subscriptions
*/
public SubscriptionsExtension(List<Subscription> subList)
{
public SubscriptionsExtension(List<Subscription> subList) {
super(PubSubElementType.SUBSCRIPTIONS);
if (subList != null)
@ -47,8 +45,7 @@ public class SubscriptionsExtension extends NodeExtension
* @param nodeId The node subscribed to
* @param subList The list of subscriptions
*/
public SubscriptionsExtension(String nodeId, List<Subscription> subList)
{
public SubscriptionsExtension(String nodeId, List<Subscription> subList) {
super(PubSubElementType.SUBSCRIPTIONS, nodeId);
if (subList != null)
@ -60,33 +57,27 @@ public class SubscriptionsExtension extends NodeExtension
*
* @return List of subscriptions
*/
public List<Subscription> getSubscriptions()
{
public List<Subscription> getSubscriptions() {
return items;
}
@Override
public CharSequence toXML()
{
if ((items == null) || (items.size() == 0))
{
public CharSequence toXML() {
if ((items == null) || (items.size() == 0)) {
return super.toXML();
}
else
{
else {
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
if (getNode() != null)
{
if (getNode() != null) {
builder.append(" node='");
builder.append(getNode());
builder.append('\'');
}
builder.append('>');
for (Subscription item : items)
{
for (Subscription item : items) {
builder.append(item.toXML());
}

View file

@ -24,35 +24,29 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*
* @author Robin Collier
*/
public class UnsubscribeExtension extends NodeExtension
{
public class UnsubscribeExtension extends NodeExtension {
protected String jid;
protected String id;
public UnsubscribeExtension(String subscriptionJid)
{
public UnsubscribeExtension(String subscriptionJid) {
this(subscriptionJid, null, null);
}
public UnsubscribeExtension(String subscriptionJid, String nodeId)
{
public UnsubscribeExtension(String subscriptionJid, String nodeId) {
this(subscriptionJid, nodeId, null);
}
public UnsubscribeExtension(String jid, String nodeId, String subscriptionId)
{
public UnsubscribeExtension(String jid, String nodeId, String subscriptionId) {
super(PubSubElementType.UNSUBSCRIBE, nodeId);
this.jid = jid;
id = subscriptionId;
}
public String getJid()
{
public String getJid() {
return jid;
}
public String getId()
{
public String getId() {
return id;
}

View file

@ -26,8 +26,7 @@ import org.jivesoftware.smackx.pubsub.LeafNode;
*
* @author Robin Collier
*/
public interface ItemDeleteListener
{
public interface ItemDeleteListener {
/**
* Called when items are deleted from a node the listener is
* registered with.

View file

@ -27,8 +27,7 @@ import org.jivesoftware.smackx.pubsub.LeafNode;
*
* @author Robin Collier
*/
public interface ItemEventListener<T extends Item>
{
public interface ItemEventListener<T extends Item> {
/**
* Called whenever an item is published to the node the listener
* is registered with.

View file

@ -26,8 +26,7 @@ import org.jivesoftware.smackx.pubsub.LeafNode;
*
* @author Robin Collier
*/
public interface NodeConfigListener
{
public interface NodeConfigListener {
/**
* Called whenever the node the listener
* is registered with is configured.

View file

@ -30,8 +30,7 @@ import org.jxmpp.jid.Jid;
*
* @author Robin Collier
*/
public class PubSub extends IQ
{
public class PubSub extends IQ {
public static final String ELEMENT = "pubsub";
public static final String NAMESPACE = "http://jabber.org/protocol/pubsub";
@ -50,8 +49,7 @@ public class PubSub extends IQ
}
@SuppressWarnings("unchecked")
public <PE extends ExtensionElement> PE getExtension(PubSubElementType elem)
{
public <PE extends ExtensionElement> PE getExtension(PubSubElementType elem) {
return (PE) getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
}

View file

@ -42,22 +42,18 @@ public enum PubSubNamespace {
}
}
public String getXmlns()
{
public String getXmlns() {
return fullNamespace;
}
public String getFragment()
{
public String getFragment() {
return fragment;
}
public static PubSubNamespace valueOfFromXmlns(String ns)
{
public static PubSubNamespace valueOfFromXmlns(String ns) {
int index = ns.lastIndexOf('#');
if (index != -1)
{
if (index != -1) {
String suffix = ns.substring(ns.lastIndexOf('#') + 1);
return valueOf(suffix.toUpperCase(Locale.US));
}

View file

@ -30,12 +30,10 @@ import org.jivesoftware.smackx.pubsub.AffiliationsExtension;
* as specified in the <a href="http://xmpp.org/extensions/xep-0060.html#schemas-pubsub">affiliation schema</a>.
*
* @author Robin Collier
*/public class AffiliationsProvider extends EmbeddedExtensionProvider<AffiliationsExtension>
{
*/public class AffiliationsProvider extends EmbeddedExtensionProvider<AffiliationsExtension> {
@SuppressWarnings("unchecked")
@Override
protected AffiliationsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
protected AffiliationsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content) {
return new AffiliationsExtension((List<Affiliation>) content);
}

View file

@ -32,11 +32,9 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
*
* @author Robin Collier
*/
public class ConfigEventProvider extends EmbeddedExtensionProvider<ConfigurationEvent>
{
public class ConfigEventProvider extends EmbeddedExtensionProvider<ConfigurationEvent> {
@Override
protected ConfigurationEvent createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends ExtensionElement> content)
{
protected ConfigurationEvent createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends ExtensionElement> content) {
if (content.size() == 0)
return new ConfigurationEvent(attMap.get("node"));
else

View file

@ -32,11 +32,9 @@ import org.jivesoftware.smackx.pubsub.NodeExtension;
*
* @author Robin Collier
*/
public class EventProvider extends EmbeddedExtensionProvider<EventElement>
{
public class EventProvider extends EmbeddedExtensionProvider<EventElement> {
@Override
protected EventElement createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends ExtensionElement> content)
{
protected EventElement createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends ExtensionElement> content) {
return new EventElement(EventElementType.valueOf(content.get(0).getElementName()), (NodeExtension) content.get(0));
}
}

View file

@ -33,11 +33,9 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
*
* @author Robin Collier
*/
public class FormNodeProvider extends EmbeddedExtensionProvider<FormNode>
{
public class FormNodeProvider extends EmbeddedExtensionProvider<FormNode> {
@Override
protected FormNode createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
protected FormNode createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content) {
return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form((DataForm) content.iterator().next()));
}
}

View file

@ -36,8 +36,7 @@ import org.xmlpull.v1.XmlPullParser;
*
* @author Robin Collier
*/
public class ItemProvider extends ExtensionElementProvider<Item>
{
public class ItemProvider extends ExtensionElementProvider<Item> {
@Override
public Item parse(XmlPullParser parser, int initialDepth)
throws Exception {
@ -46,23 +45,19 @@ public class ItemProvider extends ExtensionElementProvider<Item>
int tag = parser.next();
if (tag == XmlPullParser.END_TAG)
{
if (tag == XmlPullParser.END_TAG) {
return new Item(id, node);
}
else
{
else {
String payloadElemName = parser.getName();
String payloadNS = parser.getNamespace();
final ExtensionElementProvider<ExtensionElement> extensionProvider = ProviderManager.getExtensionProvider(payloadElemName, payloadNS);
if (extensionProvider == null)
{
if (extensionProvider == null) {
CharSequence payloadText = PacketParserUtils.parseElement(parser, true);
return new PayloadItem<>(id, node, new SimplePayload(payloadElemName, payloadNS, payloadText));
}
else
{
else {
return new PayloadItem<>(id, node, extensionProvider.parse(parser));
}
}

View file

@ -30,12 +30,10 @@ import org.jivesoftware.smackx.pubsub.ItemsExtension;
*
* @author Robin Collier
*/
public class ItemsProvider extends EmbeddedExtensionProvider<ItemsExtension>
{
public class ItemsProvider extends EmbeddedExtensionProvider<ItemsExtension> {
@Override
protected ItemsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
protected ItemsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content) {
return new ItemsExtension(ItemsExtension.ItemsElementType.items, attributeMap.get("node"), content);
}

View file

@ -31,8 +31,7 @@ import org.xmlpull.v1.XmlPullParser;
*
* @author Robin Collier
*/
public class PubSubProvider extends IQProvider<PubSub>
{
public class PubSubProvider extends IQProvider<PubSub> {
@Override
public PubSub parse(XmlPullParser parser, int initialDepth)
throws Exception {
@ -40,8 +39,7 @@ public class PubSubProvider extends IQProvider<PubSub>
PubSubNamespace pubSubNamespace = PubSubNamespace.valueOfFromXmlns(namespace);
PubSub pubsub = new PubSub(pubSubNamespace);
outerloop: while (true)
{
outerloop: while (true) {
int eventType = parser.next();
switch (eventType) {
case XmlPullParser.START_TAG:

View file

@ -31,11 +31,9 @@ import org.jivesoftware.smackx.pubsub.RetractItem;
*
* @author Robin Collier
*/
public class RetractEventProvider extends EmbeddedExtensionProvider<RetractItem>
{
public class RetractEventProvider extends EmbeddedExtensionProvider<RetractItem> {
@Override
protected RetractItem createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
protected RetractItem createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content) {
return new RetractItem(attributeMap.get("id"));
}

View file

@ -31,11 +31,9 @@ import org.jivesoftware.smackx.pubsub.PubSubElementType;
*
* @author Robin Collier
*/
public class SimpleNodeProvider extends EmbeddedExtensionProvider<NodeExtension>
{
public class SimpleNodeProvider extends EmbeddedExtensionProvider<NodeExtension> {
@Override
protected NodeExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
protected NodeExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content) {
return new NodeExtension(PubSubElementType.valueOfFromElemName(currentElement, currentNamespace), attributeMap.get("node"));
}
}

View file

@ -33,8 +33,7 @@ import org.xmlpull.v1.XmlPullParserException;
*
* @author Robin Collier
*/
public class SubscriptionProvider extends ExtensionElementProvider<Subscription>
{
public class SubscriptionProvider extends ExtensionElementProvider<Subscription> {
@Override
public Subscription parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
@ -46,8 +45,7 @@ public class SubscriptionProvider extends ExtensionElementProvider<Subscription>
int tag = parser.next();
if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("subscribe-options"))
{
if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("subscribe-options")) {
tag = parser.next();
if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("required"))

View file

@ -31,12 +31,10 @@ import org.jivesoftware.smackx.pubsub.SubscriptionsExtension;
*
* @author Robin Collier
*/
public class SubscriptionsProvider extends EmbeddedExtensionProvider<SubscriptionsExtension>
{
public class SubscriptionsProvider extends EmbeddedExtensionProvider<SubscriptionsExtension> {
@SuppressWarnings("unchecked")
@Override
protected SubscriptionsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
protected SubscriptionsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content) {
return new SubscriptionsExtension(attributeMap.get("node"), (List<Subscription>) content);
}

View file

@ -28,8 +28,7 @@ import org.jivesoftware.smackx.xdata.Form;
*
* @author Robin Collier
*/
public class NodeUtils
{
public class NodeUtils {
/**
* Get a {@link ConfigureForm} from a packet.
*
@ -37,8 +36,7 @@ public class NodeUtils
* @param elem
* @return The configuration form
*/
public static ConfigureForm getFormFromPacket(Stanza packet, PubSubElementType elem)
{
public static ConfigureForm getFormFromPacket(Stanza packet, PubSubElementType elem) {
FormNode config = packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
Form formReply = config.getForm();
return new ConfigureForm(formReply);

View file

@ -31,8 +31,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*
* @author Georg Lukas
*/
public class DeliveryReceipt implements ExtensionElement
{
public class DeliveryReceipt implements ExtensionElement {
public static final String NAMESPACE = "urn:xmpp:receipts";
public static final String ELEMENT = "received";
@ -41,31 +40,26 @@ public class DeliveryReceipt implements ExtensionElement
*/
private final String id;
public DeliveryReceipt(String id)
{
public DeliveryReceipt(String id) {
this.id = StringUtils.requireNotNullOrEmpty(id, "id must not be null");
}
public String getId()
{
public String getId() {
return id;
}
@Override
public String getElementName()
{
public String getElementName() {
return ELEMENT;
}
@Override
public String getNamespace()
{
public String getNamespace() {
return NAMESPACE;
}
@Override
public XmlStringBuilder toXML()
{
public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.attribute("id", id);
xml.closeEmptyElement();
@ -97,13 +91,11 @@ public class DeliveryReceipt implements ExtensionElement
/**
* This Provider parses and returns DeliveryReceipt packets.
*/
public static class Provider extends EmbeddedExtensionProvider<DeliveryReceipt>
{
public static class Provider extends EmbeddedExtensionProvider<DeliveryReceipt> {
@Override
protected DeliveryReceipt createReturnExtension(String currentElement, String currentNamespace,
Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
Map<String, String> attributeMap, List<? extends ExtensionElement> content) {
return new DeliveryReceipt(attributeMap.get("id"));
}

View file

@ -33,25 +33,21 @@ import org.xmlpull.v1.XmlPullParserException;
*
* @author Georg Lukas
*/
public class DeliveryReceiptRequest implements ExtensionElement
{
public class DeliveryReceiptRequest implements ExtensionElement {
public static final String ELEMENT = "request";
@Override
public String getElementName()
{
public String getElementName() {
return ELEMENT;
}
@Override
public String getNamespace()
{
public String getNamespace() {
return DeliveryReceipt.NAMESPACE;
}
@Override
public String toXML()
{
public String toXML() {
return "<request xmlns='" + DeliveryReceipt.NAMESPACE + "'/>";
}

View file

@ -44,19 +44,16 @@ import org.junit.Test;
* @author Robin Collier
*
*/
public class ConfigureFormTest extends InitExtensions
{
public class ConfigureFormTest extends InitExtensions {
@Test
public void checkChildrenAssocPolicy()
{
public void checkChildrenAssocPolicy() {
ConfigureForm form = new ConfigureForm(DataForm.Type.submit);
form.setChildrenAssociationPolicy(ChildrenAssociationPolicy.owners);
assertEquals(ChildrenAssociationPolicy.owners, form.getChildrenAssociationPolicy());
}
@Test
public void getConfigFormWithInsufficientPrivileges() throws XMPPException, SmackException, IOException, InterruptedException
{
public void getConfigFormWithInsufficientPrivileges() throws XMPPException, SmackException, IOException, InterruptedException {
ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
DiscoverInfo info = new DiscoverInfo();
@ -75,20 +72,17 @@ public class ConfigureFormTest extends InitExtensions
errorIq.setError(error);
con.addIQReply(errorIq);
try
{
try {
node.getNodeConfiguration();
fail();
}
catch (XMPPErrorException e)
{
catch (XMPPErrorException e) {
Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType());
}
}
@Test(expected = SmackException.class)
public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException
{
public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException {
ThreadedDummyConnection con = new ThreadedDummyConnection();
PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
DiscoverInfo info = new DiscoverInfo();

View file

@ -42,8 +42,7 @@ public class ItemValidationTest extends InitExtensions {
private ThreadedDummyConnection connection;
@Before
public void setUp() throws Exception
{
public void setUp() throws Exception {
// Uncomment this to enable debug output
// SmackConfiguration.DEBUG = true;
@ -53,15 +52,13 @@ public class ItemValidationTest extends InitExtensions {
}
@After
public void tearDown() throws Exception
{
public void tearDown() throws Exception {
if (connection != null)
connection.disconnect();
}
@Test
public void verifyBasicItem() throws Exception
{
public void verifyBasicItem() throws Exception {
Item simpleItem = new Item();
String simpleCtrl = "<item />";
assertXMLEqual(simpleCtrl, simpleItem.toXML());
@ -76,8 +73,7 @@ public class ItemValidationTest extends InitExtensions {
}
@Test
public void verifyPayloadItem() throws Exception
{
public void verifyPayloadItem() throws Exception {
SimplePayload payload = new SimplePayload(null, null, "<data>This is the payload</data>");
PayloadItem<SimplePayload> simpleItem = new PayloadItem<>(payload);
@ -94,8 +90,7 @@ public class ItemValidationTest extends InitExtensions {
}
@Test
public void parseBasicItem() throws Exception
{
public void parseBasicItem() throws Exception {
XmlPullParser parser = PacketParserUtils.getParserFor(
"<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" +
"<event xmlns='http://jabber.org/protocol/pubsub#event'>" +
@ -121,8 +116,7 @@ public class ItemValidationTest extends InitExtensions {
}
@Test
public void parseSimplePayloadItem() throws Exception
{
public void parseSimplePayloadItem() throws Exception {
String itemContent = "<foo xmlns='smack:test'>Some text</foo>";
XmlPullParser parser = PacketParserUtils.getParserFor(
@ -154,8 +148,7 @@ public class ItemValidationTest extends InitExtensions {
}
@Test
public void parseComplexItem() throws Exception
{
public void parseComplexItem() throws Exception {
String itemContent =
"<entry xmlns='http://www.w3.org/2005/Atom'>" +
"<title>Soliloquy</title>" +
@ -201,8 +194,7 @@ public class ItemValidationTest extends InitExtensions {
}
@Test
public void parseEmptyTag() throws Exception
{
public void parseEmptyTag() throws Exception {
String itemContent = "<foo xmlns='smack:test'><bar/></foo>";
XmlPullParser parser = PacketParserUtils.getParserFor(

View file

@ -1015,8 +1015,7 @@ public class AgentSession {
* @throws NotConnectedException
* @throws InterruptedException
*/
public void sendRoomInvitation(RoomInvitation.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public void sendRoomInvitation(RoomInvitation.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
final RoomInvitation invitation = new RoomInvitation(type, invitee, sessionID, reason);
IQ iq = new RoomInvitation.RoomInvitationIQ(invitation);
iq.setType(IQ.Type.set);
@ -1053,8 +1052,7 @@ public class AgentSession {
* @throws NotConnectedException
* @throws InterruptedException
*/
public void sendRoomTransfer(RoomTransfer.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
public void sendRoomTransfer(RoomTransfer.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
final RoomTransfer transfer = new RoomTransfer(type, invitee, sessionID, reason);
IQ iq = new RoomTransfer.RoomTransferIQ(transfer);
iq.setType(IQ.Type.set);

View file

@ -67,8 +67,7 @@ public class Offer {
*/
Offer(XMPPConnection conn, AgentSession agentSession, Jid userID,
Jid userJID, Jid workgroupName, Date expiresDate,
String sessionID, Map<String, List<String>> metaData, OfferContent content)
{
String sessionID, Map<String, List<String>> metaData, OfferContent content) {
this.connection = conn;
this.session = agentSession;
this.userID = userID;

View file

@ -129,8 +129,7 @@ public class AgentStatusRequest extends IQ {
statusRequest.agents.add(parseAgent(parser));
}
else if (eventType == XmlPullParser.END_TAG &&
"agent-status-request".equals(parser.getName()))
{
"agent-status-request".equals(parser.getName())) {
done = true;
}
}
@ -149,8 +148,7 @@ public class AgentStatusRequest extends IQ {
name = parser.nextText();
}
else if (eventType == XmlPullParser.END_TAG &&
"agent".equals(parser.getName()))
{
"agent".equals(parser.getName())) {
done = true;
}
}

View file

@ -124,8 +124,7 @@ public class OfferRequestProvider extends IQProvider<IQ> {
private final OfferContent content;
public OfferRequestPacket(Jid userJID, Jid userID, int timeout, Map<String, List<String>> metaData,
String sessionID, OfferContent content)
{
String sessionID, OfferContent content) {
super(ELEMENT, NAMESPACE);
this.userJID = userJID;
this.userID = userID;

View file

@ -59,8 +59,7 @@ public class OfferRevokeProvider extends IQProvider<IQ> {
userID = ParserUtils.getJidAttribute(parser, "id");
}
else if ((eventType == XmlPullParser.END_TAG) && parser.getName().equals(
"offer-revoke"))
{
"offer-revoke")) {
done = true;
}
}

View file

@ -153,8 +153,7 @@ public final class QueueDetails implements ExtensionElement {
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_TAG &&
"notify-queue-details".equals(parser.getName()))
{
"notify-queue-details".equals(parser.getName())) {
eventType = parser.next();
while ((eventType == XmlPullParser.START_TAG) && "user".equals(parser.getName())) {
String uid;
@ -170,8 +169,7 @@ public final class QueueDetails implements ExtensionElement {
eventType = parser.next();
while ((eventType != XmlPullParser.END_TAG)
|| (!"user".equals(parser.getName())))
{
|| (!"user".equals(parser.getName()))) {
if ("position".equals(parser.getName())) {
position = Integer.parseInt(parser.nextText());
}

View file

@ -134,8 +134,7 @@ public class QueueOverview implements ExtensionElement {
eventType = parser.next();
while ((eventType != XmlPullParser.END_TAG)
|| (!ELEMENT_NAME.equals(parser.getName())))
{
|| (!ELEMENT_NAME.equals(parser.getName()))) {
if ("count".equals(parser.getName())) {
queueOverview.setUserCount(Integer.parseInt(parser.nextText()));
}

View file

@ -68,8 +68,7 @@ public class ListenerEventDispatcher implements Runnable {
* @param methodArguments the arguments supplied to the notification method
*/
public void addListenerTriplet(Object listenerInstance, Method listenerMethod,
Object[] methodArguments)
{
Object[] methodArguments) {
if (!this.isRunning) {
this.triplets.add(new TripletContainer(listenerInstance, listenerMethod,
methodArguments));

View file

@ -34,27 +34,23 @@ public class DefaultMessageEventRequestListener implements MessageEventRequestLi
@Override
public void deliveredNotificationRequested(Jid from, String packetID,
MessageEventManager messageEventManager) throws NotConnectedException, InterruptedException
{
MessageEventManager messageEventManager) throws NotConnectedException, InterruptedException {
// Send to the message's sender that the message has been delivered
messageEventManager.sendDeliveredNotification(from, packetID);
}
@Override
public void displayedNotificationRequested(Jid from, String packetID,
MessageEventManager messageEventManager)
{
MessageEventManager messageEventManager) {
}
@Override
public void composingNotificationRequested(Jid from, String packetID,
MessageEventManager messageEventManager)
{
MessageEventManager messageEventManager) {
}
@Override
public void offlineNotificationRequested(Jid from, String packetID,
MessageEventManager messageEventManager)
{
MessageEventManager messageEventManager) {
}
}

View file

@ -113,8 +113,7 @@ public final class MessageEventManager extends Manager {
* @param composing specifies if the composing event is requested.
*/
public static void addNotificationsRequests(Message message, boolean offline,
boolean delivered, boolean displayed, boolean composing)
{
boolean delivered, boolean displayed, boolean composing) {
// Create a MessageEvent Package and add it to the message
MessageEvent messageEvent = new MessageEvent();
messageEvent.setOffline(offline);