From ef0af66b21fb9db79ae22d3242f585584581e07f Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 7 Feb 2017 22:02:40 +0100 Subject: [PATCH] Enfore spaces for indentation Although I'm in the tabs camp, Smack uses mostly spaces. Therefore it is the logical choice for the indentation style. --- config/checkstyle.xml | 8 +- .../android/ServerPingWithAlarmManager.java | 174 +-- .../android/AndroidSmackInitializer.java | 16 +- .../smack/filter/IQTypeFilter.java | 8 +- .../smack/StanzaCollectorTest.java | 300 ++--- .../org/jivesoftware/smack/util/SHA1Test.java | 2 +- .../smack/util/StringUtilsTest.java | 10 +- .../debugger/EnhancedDebuggerWindow.java | 2 +- .../blocking/AllJidsUnblockedListener.java | 2 +- .../smackx/blocking/JidsBlockedListener.java | 2 +- .../smackx/filetransfer/FileTransfer.java | 442 +++--- .../filetransfer/FileTransferListener.java | 14 +- .../filetransfer/FileTransferManager.java | 164 +-- .../filetransfer/FileTransferRequest.java | 194 +-- .../filetransfer/OutgoingFileTransfer.java | 546 ++++---- .../provider/RegistrationProvider.java | 2 +- .../jivesoftware/smackx/nick/packet/Nick.java | 114 +- .../smackx/privacy/PrivacyListManager.java | 258 ++-- .../smackx/privacy/packet/Privacy.java | 154 +-- .../privacy/provider/PrivacyProvider.java | 40 +- .../smackx/pubsub/AccessModel.java | 20 +- .../smackx/pubsub/Affiliation.java | 20 +- .../smackx/pubsub/AffiliationsExtension.java | 34 +- .../pubsub/ChildrenAssociationPolicy.java | 12 +- .../smackx/pubsub/CollectionNode.java | 8 +- .../smackx/pubsub/ConfigurationEvent.java | 42 +- .../smackx/pubsub/ConfigureForm.java | 1192 ++++++++--------- .../smackx/pubsub/ConfigureNodeFields.java | 328 ++--- .../pubsub/EmbeddedPacketExtension.java | 12 +- .../smackx/pubsub/EventElement.java | 54 +- .../smackx/pubsub/EventElementType.java | 24 +- .../jivesoftware/smackx/pubsub/FormNode.java | 126 +- .../smackx/pubsub/FormNodeType.java | 40 +- .../smackx/pubsub/GetItemsRequest.java | 50 +- .../org/jivesoftware/smackx/pubsub/Item.java | 146 +- .../smackx/pubsub/ItemDeleteEvent.java | 64 +- .../smackx/pubsub/ItemPublishEvent.java | 170 +-- .../jivesoftware/smackx/pubsub/ItemReply.java | 8 +- .../smackx/pubsub/ItemsExtension.java | 294 ++-- .../jivesoftware/smackx/pubsub/LeafNode.java | 588 ++++---- .../org/jivesoftware/smackx/pubsub/Node.java | 836 ++++++------ .../jivesoftware/smackx/pubsub/NodeEvent.java | 18 +- .../smackx/pubsub/NodeExtension.java | 100 +- .../jivesoftware/smackx/pubsub/NodeType.java | 4 +- .../smackx/pubsub/OptionsExtension.java | 48 +- .../smackx/pubsub/PayloadItem.java | 154 +-- .../smackx/pubsub/PresenceState.java | 2 +- .../smackx/pubsub/PubSubElementType.java | 94 +- .../smackx/pubsub/PubSubManager.java | 416 +++--- .../smackx/pubsub/PublishItem.java | 78 +- .../smackx/pubsub/PublishModel.java | 12 +- .../smackx/pubsub/RetractItem.java | 56 +- .../smackx/pubsub/SimplePayload.java | 70 +- .../smackx/pubsub/SubscribeExtension.java | 62 +- .../smackx/pubsub/SubscribeForm.java | 348 ++--- .../smackx/pubsub/SubscribeOptionFields.java | 126 +- .../smackx/pubsub/Subscription.java | 242 ++-- .../smackx/pubsub/SubscriptionEvent.java | 88 +- .../smackx/pubsub/SubscriptionsExtension.java | 122 +- .../smackx/pubsub/UnsubscribeExtension.java | 48 +- .../pubsub/listener/ItemDeleteListener.java | 24 +- .../pubsub/listener/ItemEventListener.java | 14 +- .../pubsub/listener/NodeConfigListener.java | 14 +- .../smackx/pubsub/packet/PubSub.java | 12 +- .../smackx/pubsub/packet/PubSubNamespace.java | 52 +- .../pubsub/provider/AffiliationsProvider.java | 10 +- .../pubsub/provider/ConfigEventProvider.java | 16 +- .../smackx/pubsub/provider/EventProvider.java | 12 +- .../pubsub/provider/FormNodeProvider.java | 8 +- .../smackx/pubsub/provider/ItemsProvider.java | 8 +- .../pubsub/provider/PubSubProvider.java | 2 +- .../pubsub/provider/RetractEventProvider.java | 10 +- .../pubsub/provider/SimpleNodeProvider.java | 8 +- .../pubsub/provider/SubscriptionProvider.java | 32 +- .../provider/SubscriptionsProvider.java | 12 +- .../smackx/pubsub/util/NodeUtils.java | 26 +- .../smackx/si/packet/StreamInitiation.java | 10 +- .../si/provider/StreamInitiationProvider.java | 106 +- .../smackx/pubsub/ConfigureFormTest.java | 88 +- .../smackx/pubsub/ItemValidationTest.java | 94 +- .../smackx/receipts/DeliveryReceiptTest.java | 2 +- .../smack/roster/RosterEntries.java | 2 +- .../smackx/jingleold/JingleException.java | 4 +- .../smackx/jingleold/JingleManager.java | 4 +- .../smackx/jingleold/JingleNegotiator.java | 10 +- .../smackx/jingleold/JingleSession.java | 34 +- .../jingleold/JingleSessionRequest.java | 22 +- .../jingleold/JingleSessionStateEnded.java | 4 +- .../jingleold/media/MediaNegotiator.java | 4 +- .../smackx/jingleold/mediaimpl/JMFInit.java | 6 +- .../jingleold/mediaimpl/jmf/AudioChannel.java | 4 +- .../mediaimpl/jmf/AudioMediaSession.java | 4 +- .../mediaimpl/jmf/AudioReceiver.java | 4 +- .../mediaimpl/jmf/JmfMediaManager.java | 4 +- .../mediaimpl/jspeex/AudioMediaSession.java | 4 +- .../mediaimpl/jspeex/SpeexMediaManager.java | 4 +- .../mediaimpl/sshare/ScreenShareSession.java | 4 +- .../sshare/api/AbstractBufferedImageOp.java | 52 +- .../mediaimpl/sshare/api/ImageReceiver.java | 4 +- .../sshare/api/ImageTransmitter.java | 4 +- .../sshare/api/OctTreeQuantizer.java | 426 +++--- .../mediaimpl/sshare/api/PixelUtils.java | 368 ++--- .../mediaimpl/sshare/api/QuantizeFilter.java | 254 ++-- .../mediaimpl/sshare/api/Quantizer.java | 50 +- .../sshare/api/WholeImageFilter.java | 48 +- .../smackx/jingleold/nat/HttpServer.java | 4 +- .../smackx/jingleold/nat/ICECandidate.java | 20 +- .../smackx/jingleold/nat/ICEResolver.java | 44 +- .../smackx/jingleold/nat/RTPBridge.java | 4 +- .../smackx/jingleold/nat/STUN.java | 4 +- .../smackx/jingleold/nat/STUNResolver.java | 4 +- .../jingleold/nat/TcpUdpBridgeClient.java | 4 +- .../jingleold/nat/TcpUdpBridgeServer.java | 4 +- .../jingleold/nat/TransportCandidate.java | 10 +- .../jingleold/nat/TransportNegotiator.java | 16 +- .../jingleold/nat/TransportResolver.java | 4 +- .../packet/JingleContentDescription.java | 14 +- .../jingleold/packet/JingleContentInfo.java | 6 +- .../jingleold/packet/JingleDescription.java | 4 +- .../smackx/jingleold/packet/JingleError.java | 4 +- .../JingleContentDescriptionProvider.java | 4 +- .../provider/JingleContentInfoProvider.java | 6 +- .../smackx/xroster/RemoteRosterEntry.java | 4 +- .../smackx/xroster/packet/RosterExchange.java | 14 +- .../SASLProvidedSmackInitializer.java | 14 +- 125 files changed, 5336 insertions(+), 5344 deletions(-) diff --git a/config/checkstyle.xml b/config/checkstyle.xml index 08703c562..ce2345c20 100644 --- a/config/checkstyle.xml +++ b/config/checkstyle.xml @@ -35,10 +35,6 @@ - - - - @@ -89,6 +85,10 @@ + + + + diff --git a/smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java b/smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java index 6d9fe943b..054bc0418 100644 --- a/smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java +++ b/smack-android-extensions/src/main/java/org/jivesoftware/smackx/ping/android/ServerPingWithAlarmManager.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2014 Florian Schmaus + * Copyright © 2014-2017 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,116 +63,116 @@ import android.os.SystemClock; */ public final class ServerPingWithAlarmManager extends Manager { - private static final Logger LOGGER = Logger.getLogger(ServerPingWithAlarmManager.class - .getName()); + private static final Logger LOGGER = Logger.getLogger(ServerPingWithAlarmManager.class + .getName()); - private static final String PING_ALARM_ACTION = "org.igniterealtime.smackx.ping.ACTION"; + private static final String PING_ALARM_ACTION = "org.igniterealtime.smackx.ping.ACTION"; - private static final Map INSTANCES = new WeakHashMap(); + private static final Map INSTANCES = new WeakHashMap(); - static { - XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { - @Override - public void connectionCreated(XMPPConnection connection) { - getInstanceFor(connection); - } - }); - } + static { + XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { + @Override + public void connectionCreated(XMPPConnection connection) { + getInstanceFor(connection); + } + }); + } - public static synchronized ServerPingWithAlarmManager getInstanceFor(XMPPConnection connection) { - ServerPingWithAlarmManager serverPingWithAlarmManager = INSTANCES.get(connection); - if (serverPingWithAlarmManager == null) { - serverPingWithAlarmManager = new ServerPingWithAlarmManager(connection); - INSTANCES.put(connection, serverPingWithAlarmManager); - } - return serverPingWithAlarmManager; - } + public static synchronized ServerPingWithAlarmManager getInstanceFor(XMPPConnection connection) { + ServerPingWithAlarmManager serverPingWithAlarmManager = INSTANCES.get(connection); + if (serverPingWithAlarmManager == null) { + serverPingWithAlarmManager = new ServerPingWithAlarmManager(connection); + INSTANCES.put(connection, serverPingWithAlarmManager); + } + return serverPingWithAlarmManager; + } - private boolean mEnabled = true; + private boolean mEnabled = true; - private ServerPingWithAlarmManager(XMPPConnection connection) { - super(connection); - } + private ServerPingWithAlarmManager(XMPPConnection connection) { + super(connection); + } /** * If enabled, ServerPingWithAlarmManager will call {@link PingManager#pingServerIfNecessary()} * for the connection of this instance every half hour. - * + * * @param enabled */ - public void setEnabled(boolean enabled) { - mEnabled = enabled; - } + public void setEnabled(boolean enabled) { + mEnabled = enabled; + } - public boolean isEnabled() { - return mEnabled; - } + public boolean isEnabled() { + return mEnabled; + } - private static final BroadcastReceiver ALARM_BROADCAST_RECEIVER = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - LOGGER.fine("Ping Alarm broadcast received"); - Set> managers; - synchronized (ServerPingWithAlarmManager.class) { - // Make a copy to avoid ConcurrentModificationException when - // iterating directly over INSTANCES and the Set is modified - // concurrently by creating a new ServerPingWithAlarmManager. - managers = new HashSet<>(INSTANCES.entrySet()); - } - for (Entry entry : managers) { - XMPPConnection connection = entry.getKey(); - if (entry.getValue().isEnabled()) { - LOGGER.fine("Calling pingServerIfNecessary for connection " - + connection); - final PingManager pingManager = PingManager.getInstanceFor(connection); - // Android BroadcastReceivers have a timeout of 60 seconds. - // The connections reply timeout may be higher, which causes - // timeouts of the broadcast receiver and a subsequent ANR - // of the App of the broadcast receiver. We therefore need - // to call pingServerIfNecessary() in a new thread to avoid - // this. It could happen that the device gets back to sleep - // until the Thread runs, but that's a risk we are willing - // to take into account as it's unlikely. - Async.go(new Runnable() { - @Override - public void run() { - pingManager.pingServerIfNecessary(); - } - }, "PingServerIfNecessary (" + connection.getConnectionCounter() + ')'); - } else { - LOGGER.fine("NOT calling pingServerIfNecessary (disabled) on connection " - + connection.getConnectionCounter()); - } - } - } - }; + private static final BroadcastReceiver ALARM_BROADCAST_RECEIVER = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + LOGGER.fine("Ping Alarm broadcast received"); + Set> managers; + synchronized (ServerPingWithAlarmManager.class) { + // Make a copy to avoid ConcurrentModificationException when + // iterating directly over INSTANCES and the Set is modified + // concurrently by creating a new ServerPingWithAlarmManager. + managers = new HashSet<>(INSTANCES.entrySet()); + } + for (Entry entry : managers) { + XMPPConnection connection = entry.getKey(); + if (entry.getValue().isEnabled()) { + LOGGER.fine("Calling pingServerIfNecessary for connection " + + connection); + final PingManager pingManager = PingManager.getInstanceFor(connection); + // Android BroadcastReceivers have a timeout of 60 seconds. + // The connections reply timeout may be higher, which causes + // timeouts of the broadcast receiver and a subsequent ANR + // of the App of the broadcast receiver. We therefore need + // to call pingServerIfNecessary() in a new thread to avoid + // this. It could happen that the device gets back to sleep + // until the Thread runs, but that's a risk we are willing + // to take into account as it's unlikely. + Async.go(new Runnable() { + @Override + public void run() { + pingManager.pingServerIfNecessary(); + } + }, "PingServerIfNecessary (" + connection.getConnectionCounter() + ')'); + } else { + LOGGER.fine("NOT calling pingServerIfNecessary (disabled) on connection " + + connection.getConnectionCounter()); + } + } + } + }; - private static Context sContext; - private static PendingIntent sPendingIntent; - private static AlarmManager sAlarmManager; + private static Context sContext; + private static PendingIntent sPendingIntent; + private static AlarmManager sAlarmManager; /** * Register a pending intent with the AlarmManager to be broadcasted every half hour and * register the alarm broadcast receiver to receive this intent. The receiver will check all * known questions if a ping is Necessary when invoked by the alarm intent. - * + * * @param context */ - public static void onCreate(Context context) { - sContext = context; - context.registerReceiver(ALARM_BROADCAST_RECEIVER, new IntentFilter(PING_ALARM_ACTION)); - sAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - sPendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(PING_ALARM_ACTION), 0); - sAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, - SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HALF_HOUR, - AlarmManager.INTERVAL_HALF_HOUR, sPendingIntent); - } + public static void onCreate(Context context) { + sContext = context; + context.registerReceiver(ALARM_BROADCAST_RECEIVER, new IntentFilter(PING_ALARM_ACTION)); + sAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + sPendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(PING_ALARM_ACTION), 0); + sAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, + SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_HALF_HOUR, + AlarmManager.INTERVAL_HALF_HOUR, sPendingIntent); + } /** * Unregister the alarm broadcast receiver and cancel the alarm. */ - public static void onDestroy() { - sContext.unregisterReceiver(ALARM_BROADCAST_RECEIVER); - sAlarmManager.cancel(sPendingIntent); - } + public static void onDestroy() { + sContext.unregisterReceiver(ALARM_BROADCAST_RECEIVER); + sAlarmManager.cancel(sPendingIntent); + } } diff --git a/smack-android/src/main/java/org/jivesoftware/smack/android/AndroidSmackInitializer.java b/smack-android/src/main/java/org/jivesoftware/smack/android/AndroidSmackInitializer.java index bae2beb93..b58f8679c 100644 --- a/smack-android/src/main/java/org/jivesoftware/smack/android/AndroidSmackInitializer.java +++ b/smack-android/src/main/java/org/jivesoftware/smack/android/AndroidSmackInitializer.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2014 Florian Schmaus + * Copyright © 2014-2017 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,12 +28,12 @@ import org.jivesoftware.smack.util.stringencoder.android.AndroidBase64UrlSafeEnc public class AndroidSmackInitializer implements SmackInitializer { - @Override - public List initialize() { - SmackConfiguration.setDefaultHostnameVerifier(new StrictHostnameVerifier()); - Base64.setEncoder(AndroidBase64Encoder.getInstance()); - Base64UrlSafeEncoder.setEncoder(AndroidBase64UrlSafeEncoder.getInstance()); - return null; - } + @Override + public List initialize() { + SmackConfiguration.setDefaultHostnameVerifier(new StrictHostnameVerifier()); + Base64.setEncoder(AndroidBase64Encoder.getInstance()); + Base64UrlSafeEncoder.setEncoder(AndroidBase64UrlSafeEncoder.getInstance()); + return null; + } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java index f84bdadb2..fe50083df 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java @@ -35,12 +35,12 @@ public final class IQTypeFilter extends FlexibleStanzaTypeFilter { public static final StanzaFilter ERROR = new IQTypeFilter(Type.error); public static final StanzaFilter GET_OR_SET = new OrFilter(GET, SET); - private final IQ.Type type; + private final IQ.Type type; - private IQTypeFilter(IQ.Type type) { + private IQTypeFilter(IQ.Type type) { super(IQ.class); - this.type = Objects.requireNonNull(type, "Type must not be null"); - } + this.type = Objects.requireNonNull(type, "Type must not be null"); + } @Override protected boolean acceptSpecific(IQ iq) { diff --git a/smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java b/smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java index be4f771f0..60560b504 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/StanzaCollectorTest.java @@ -26,190 +26,190 @@ import org.junit.Test; public class StanzaCollectorTest { - @Test - public void verifyRollover() throws InterruptedException - { - TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), 5); + @Test + public void verifyRollover() throws InterruptedException + { + TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), 5); - for (int i=0; i<6; i++) - { - Stanza testPacket = new TestPacket(i); - collector.processStanza(testPacket); - } + for (int i=0; i<6; i++) + { + Stanza testPacket = new TestPacket(i); + collector.processStanza(testPacket); + } - // Assert that '0' has rolled off - assertEquals("1", collector.nextResultBlockForever().getStanzaId()); - assertEquals("2", collector.nextResultBlockForever().getStanzaId()); - assertEquals("3", collector.nextResultBlockForever().getStanzaId()); - assertEquals("4", collector.nextResultBlockForever().getStanzaId()); - assertEquals("5", collector.pollResult().getStanzaId()); - assertNull(collector.pollResult()); + // Assert that '0' has rolled off + assertEquals("1", collector.nextResultBlockForever().getStanzaId()); + assertEquals("2", collector.nextResultBlockForever().getStanzaId()); + assertEquals("3", collector.nextResultBlockForever().getStanzaId()); + assertEquals("4", collector.nextResultBlockForever().getStanzaId()); + assertEquals("5", collector.pollResult().getStanzaId()); + assertNull(collector.pollResult()); - for (int i=10; i<15; i++) - { - Stanza testPacket = new TestPacket(i); - collector.processStanza(testPacket); - } + for (int i=10; i<15; i++) + { + Stanza testPacket = new TestPacket(i); + collector.processStanza(testPacket); + } - assertEquals("10", collector.nextResultBlockForever().getStanzaId()); - assertEquals("11", collector.nextResultBlockForever().getStanzaId()); - assertEquals("12", collector.nextResultBlockForever().getStanzaId()); - assertEquals("13", collector.nextResultBlockForever().getStanzaId()); - assertEquals("14", collector.pollResult().getStanzaId()); - assertNull(collector.pollResult()); + assertEquals("10", collector.nextResultBlockForever().getStanzaId()); + assertEquals("11", collector.nextResultBlockForever().getStanzaId()); + assertEquals("12", collector.nextResultBlockForever().getStanzaId()); + assertEquals("13", collector.nextResultBlockForever().getStanzaId()); + assertEquals("14", collector.pollResult().getStanzaId()); + assertNull(collector.pollResult()); - assertNull(collector.nextResult(1000)); - } + assertNull(collector.nextResult(1000)); + } /** * Although this doesn't guarentee anything due to the nature of threading, it can potentially * catch problems. */ - @Test - public void verifyThreadSafety() - { - int insertCount = 500; - final TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), insertCount); + @Test + public void verifyThreadSafety() + { + int insertCount = 500; + final TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), insertCount); - Thread consumer1 = new Thread(new Runnable() - { - @Override - public void run() - { - try - { - while (true) - { - try - { - Thread.sleep(3); - } - catch (InterruptedException e) - { - } - @SuppressWarnings("unused") - Stanza packet = collector.nextResultBlockForever(); -// System.out.println(Thread.currentThread().getName() + " packet: " + packet); - } - } + Thread consumer1 = new Thread(new Runnable() + { + @Override + public void run() + { + try + { + while (true) + { + try + { + Thread.sleep(3); + } + catch (InterruptedException e) + { + } + @SuppressWarnings("unused") + Stanza packet = collector.nextResultBlockForever(); +// System.out.println(Thread.currentThread().getName() + " packet: " + packet); + } + } catch (InterruptedException e) { throw new RuntimeException(e); } - } - }); - consumer1.setName("consumer 1"); + } + }); + consumer1.setName("consumer 1"); - Thread consumer2 = new Thread(new Runnable() - { - @Override - public void run() - { - Stanza p = null; + Thread consumer2 = new Thread(new Runnable() + { + @Override + public void run() + { + Stanza p = null; - do - { - try - { - Thread.sleep(3); - } - catch (InterruptedException e) - { - } - try { + do + { + try + { + Thread.sleep(3); + } + catch (InterruptedException e) + { + } + try { p = collector.nextResult(1); } catch (InterruptedException e) { throw new RuntimeException(e); } -// System.out.println(Thread.currentThread().getName() + " packet: " + p); - } - while (p != null); - } - }); - consumer2.setName("consumer 2"); +// System.out.println(Thread.currentThread().getName() + " packet: " + p); + } + while (p != null); + } + }); + consumer2.setName("consumer 2"); - Thread consumer3 = new Thread(new Runnable() - { - @Override - public void run() - { - Stanza p = null; + Thread consumer3 = new Thread(new Runnable() + { + @Override + public void run() + { + Stanza p = null; - do - { - try - { - Thread.sleep(3); - } - catch (InterruptedException e) - { - } - p = collector.pollResult(); -// System.out.println(Thread.currentThread().getName() + " packet: " + p); - } - while (p != null); - } - }); - consumer3.setName("consumer 3"); + do + { + try + { + Thread.sleep(3); + } + catch (InterruptedException e) + { + } + p = collector.pollResult(); +// System.out.println(Thread.currentThread().getName() + " packet: " + p); + } + while (p != null); + } + }); + consumer3.setName("consumer 3"); - consumer1.start(); - consumer2.start(); - consumer3.start(); + consumer1.start(); + consumer2.start(); + consumer3.start(); - for(int i=0; i" + getStanzaId() + ""; - } + @Override + public String toXML() + { + return "" + getStanzaId() + ""; + } @Override public String toString() { return toXML(); } - } + } } diff --git a/smack-core/src/test/java/org/jivesoftware/smack/util/SHA1Test.java b/smack-core/src/test/java/org/jivesoftware/smack/util/SHA1Test.java index b9fc3818d..ada3d4d99 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/util/SHA1Test.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/util/SHA1Test.java @@ -28,7 +28,7 @@ import org.junit.Test; */ public class SHA1Test { - @Test + @Test public void testHash() { // Test null // @TODO - should the StringUtils.hash(String) method be fixed to handle null input? diff --git a/smack-core/src/test/java/org/jivesoftware/smack/util/StringUtilsTest.java b/smack-core/src/test/java/org/jivesoftware/smack/util/StringUtilsTest.java index bd0d5ad05..f9bfae04f 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/util/StringUtilsTest.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/util/StringUtilsTest.java @@ -27,7 +27,7 @@ import org.junit.Test; * A test case for the StringUtils class. */ public class StringUtilsTest { - @Test + @Test public void testEscapeForXml() { String input = null; @@ -67,11 +67,11 @@ public class StringUtilsTest { assertCharSequenceEquals("It's a good day today", StringUtils.escapeForXml(input)); } - public static void assertCharSequenceEquals(CharSequence expected, CharSequence actual) { + public static void assertCharSequenceEquals(CharSequence expected, CharSequence actual) { assertEquals(expected.toString(), actual.toString()); - } + } - @Test + @Test public void testEncodeHex() { String input = ""; String output = ""; @@ -84,7 +84,7 @@ public class StringUtilsTest { new String(output.getBytes())); } - @Test + @Test public void testRandomString() { // Boundary test String result = StringUtils.randomString(-1); diff --git a/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java b/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java index d5ec26ec8..893a6607b 100644 --- a/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java +++ b/smack-debug/src/main/java/org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow.java @@ -203,7 +203,7 @@ public final class EnhancedDebuggerWindow { * a tab panel for each connection that is being debugged. */ @SuppressWarnings({ "rawtypes", "unchecked" }) - private void createDebug() { + private void createDebug() { frame = new JFrame("Smack Debug Window"); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/AllJidsUnblockedListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/AllJidsUnblockedListener.java index 0648d0e0c..27b1f477c 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/AllJidsUnblockedListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/AllJidsUnblockedListener.java @@ -18,6 +18,6 @@ package org.jivesoftware.smackx.blocking; public interface AllJidsUnblockedListener { - void onAllJidsUnblocked(); + void onAllJidsUnblocked(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsBlockedListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsBlockedListener.java index e907a7a5b..e4b1a086e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsBlockedListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/JidsBlockedListener.java @@ -22,6 +22,6 @@ import org.jxmpp.jid.Jid; public interface JidsBlockedListener { - void onJidsBlocked(List blockedJids); + void onJidsBlocked(List blockedJids); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java index ae99f6224..5f5177183 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransfer.java @@ -31,27 +31,27 @@ import org.jxmpp.jid.Jid; */ public abstract class FileTransfer { - private String fileName; + private String fileName; - private String filePath; + private String filePath; - private long fileSize; + private long fileSize; - private Jid peer; + private Jid peer; - private Status status = Status.initial; + private Status status = Status.initial; private final Object statusMonitor = new Object(); - protected FileTransferNegotiator negotiator; + protected FileTransferNegotiator negotiator; - protected String streamID; + protected String streamID; - protected long amountWritten = -1; + protected long amountWritten = -1; - private Error error; + private Error error; - private Exception exception; + private Exception exception; /** * Buffer size between input and output @@ -59,137 +59,137 @@ public abstract class FileTransfer { private static final int BUFFER_SIZE = 8192; protected FileTransfer(Jid peer, String streamID, - FileTransferNegotiator negotiator) { - this.peer = peer; - this.streamID = streamID; - this.negotiator = negotiator; - } + FileTransferNegotiator negotiator) { + this.peer = peer; + this.streamID = streamID; + this.negotiator = negotiator; + } - protected void setFileInfo(String fileName, long fileSize) { - this.fileName = fileName; - this.fileSize = fileSize; - } + protected void setFileInfo(String fileName, long fileSize) { + this.fileName = fileName; + this.fileSize = fileSize; + } - protected void setFileInfo(String path, String fileName, long fileSize) { - this.filePath = path; - this.fileName = fileName; - this.fileSize = fileSize; - } + protected void setFileInfo(String path, String fileName, long fileSize) { + this.filePath = path; + this.fileName = fileName; + this.fileSize = fileSize; + } - /** - * Returns the size of the file being transfered. - * - * @return Returns the size of the file being transfered. - */ - public long getFileSize() { - return fileSize; - } + /** + * Returns the size of the file being transfered. + * + * @return Returns the size of the file being transfered. + */ + public long getFileSize() { + return fileSize; + } - /** - * Returns the name of the file being transfered. - * - * @return Returns the name of the file being transfered. - */ - public String getFileName() { - return fileName; - } + /** + * Returns the name of the file being transfered. + * + * @return Returns the name of the file being transfered. + */ + public String getFileName() { + return fileName; + } - /** - * Returns the local path of the file. - * - * @return Returns the local path of the file. - */ - public String getFilePath() { - return filePath; - } + /** + * Returns the local path of the file. + * + * @return Returns the local path of the file. + */ + public String getFilePath() { + return filePath; + } - /** - * Returns the JID of the peer for this file transfer. - * - * @return Returns the JID of the peer for this file transfer. - */ - public Jid getPeer() { - return peer; - } + /** + * Returns the JID of the peer for this file transfer. + * + * @return Returns the JID of the peer for this file transfer. + */ + public Jid getPeer() { + return peer; + } - /** - * Returns the progress of the file transfer as a number between 0 and 1. - * - * @return Returns the progress of the file transfer as a number between 0 - * and 1. - */ - public double getProgress() { + /** + * Returns the progress of the file transfer as a number between 0 and 1. + * + * @return Returns the progress of the file transfer as a number between 0 + * and 1. + */ + public double getProgress() { if (amountWritten <= 0 || fileSize <= 0) { return 0; } return (double) amountWritten / (double) fileSize; - } + } - /** - * Returns true if the transfer has been cancelled, if it has stopped because - * of a an error, or the transfer completed successfully. - * - * @return Returns true if the transfer has been cancelled, if it has stopped - * because of a an error, or the transfer completed successfully. - */ - public boolean isDone() { - return status == Status.cancelled || status == Status.error - || status == Status.complete || status == Status.refused; - } + /** + * Returns true if the transfer has been cancelled, if it has stopped because + * of a an error, or the transfer completed successfully. + * + * @return Returns true if the transfer has been cancelled, if it has stopped + * because of a an error, or the transfer completed successfully. + */ + public boolean isDone() { + return status == Status.cancelled || status == Status.error + || status == Status.complete || status == Status.refused; + } - /** - * Returns the current status of the file transfer. - * - * @return Returns the current status of the file transfer. - */ - public Status getStatus() { - return status; - } + /** + * Returns the current status of the file transfer. + * + * @return Returns the current status of the file transfer. + */ + public Status getStatus() { + return status; + } - protected void setError(Error type) { - this.error = type; - } + protected void setError(Error type) { + this.error = type; + } - /** - * When {@link #getStatus()} returns that there was an {@link Status#error} - * during the transfer, the type of error can be retrieved through this - * method. - * - * @return Returns the type of error that occurred if one has occurred. - */ - public Error getError() { - return error; - } + /** + * When {@link #getStatus()} returns that there was an {@link Status#error} + * during the transfer, the type of error can be retrieved through this + * method. + * + * @return Returns the type of error that occurred if one has occurred. + */ + public Error getError() { + return error; + } - /** - * If an exception occurs asynchronously it will be stored for later - * retrieval. If there is an error there maybe an exception set. - * - * @return The exception that occurred or null if there was no exception. - * @see #getError() - */ - public Exception getException() { - return exception; - } + /** + * If an exception occurs asynchronously it will be stored for later + * retrieval. If there is an error there maybe an exception set. + * + * @return The exception that occurred or null if there was no exception. + * @see #getError() + */ + public Exception getException() { + return exception; + } public String getStreamID() { return streamID; } - /** - * Cancels the file transfer. - */ - public abstract void cancel(); + /** + * Cancels the file transfer. + */ + public abstract void cancel(); - protected void setException(Exception exception) { - this.exception = exception; - } + protected void setException(Exception exception) { + this.exception = exception; + } - protected void setStatus(Status status) { + protected void setStatus(Status status) { synchronized (statusMonitor) { // CHECKSTYLE:OFF - this.status = status; - } + this.status = status; + } // CHECKSTYLE:ON } @@ -206,91 +206,91 @@ public abstract class FileTransfer { protected void writeToStream(final InputStream in, final OutputStream out) throws IOException { - final byte[] b = new byte[BUFFER_SIZE]; - int count = 0; - amountWritten = 0; + final byte[] b = new byte[BUFFER_SIZE]; + int count = 0; + amountWritten = 0; while ((count = in.read(b)) > 0 && !getStatus().equals(Status.cancelled)) { out.write(b, 0, count); amountWritten += count; } - // the connection was likely terminated abruptly if these are not equal - if (!getStatus().equals(Status.cancelled) && getError() == Error.none - && amountWritten != fileSize) { + // the connection was likely terminated abruptly if these are not equal + if (!getStatus().equals(Status.cancelled) && getError() == Error.none + && amountWritten != fileSize) { setStatus(Status.error); - this.error = Error.connection; - } - } + this.error = Error.connection; + } + } - /** - * A class to represent the current status of the file transfer. - * - * @author Alexander Wenckus - * - */ - public enum Status { + /** + * A class to represent the current status of the file transfer. + * + * @author Alexander Wenckus + * + */ + public enum Status { - /** - * An error occurred during the transfer. - * - * @see FileTransfer#getError() - */ - error("Error"), + /** + * An error occurred during the transfer. + * + * @see FileTransfer#getError() + */ + error("Error"), - /** + /** * The initial status of the file transfer. */ initial("Initial"), /** - * The file transfer is being negotiated with the peer. The party - * Receiving the file has the option to accept or refuse a file transfer - * request. If they accept, then the process of stream negotiation will - * begin. If they refuse the file will not be transfered. - * - * @see #negotiating_stream - */ - negotiating_transfer("Negotiating Transfer"), + * The file transfer is being negotiated with the peer. The party + * Receiving the file has the option to accept or refuse a file transfer + * request. If they accept, then the process of stream negotiation will + * begin. If they refuse the file will not be transfered. + * + * @see #negotiating_stream + */ + negotiating_transfer("Negotiating Transfer"), - /** - * The peer has refused the file transfer request halting the file - * transfer negotiation process. - */ - refused("Refused"), + /** + * The peer has refused the file transfer request halting the file + * transfer negotiation process. + */ + refused("Refused"), - /** - * The stream to transfer the file is being negotiated over the chosen - * stream type. After the stream negotiating process is complete the - * status becomes negotiated. - * - * @see #negotiated - */ - negotiating_stream("Negotiating Stream"), + /** + * The stream to transfer the file is being negotiated over the chosen + * stream type. After the stream negotiating process is complete the + * status becomes negotiated. + * + * @see #negotiated + */ + negotiating_stream("Negotiating Stream"), - /** - * After the stream negotiation has completed the intermediate state - * between the time when the negotiation is finished and the actual - * transfer begins. - */ - negotiated("Negotiated"), + /** + * After the stream negotiation has completed the intermediate state + * between the time when the negotiation is finished and the actual + * transfer begins. + */ + negotiated("Negotiated"), - /** - * The transfer is in progress. - * - * @see FileTransfer#getProgress() - */ - in_progress("In Progress"), + /** + * The transfer is in progress. + * + * @see FileTransfer#getProgress() + */ + in_progress("In Progress"), - /** - * The transfer has completed successfully. - */ - complete("Complete"), + /** + * The transfer has completed successfully. + */ + complete("Complete"), - /** - * The file transfer was cancelled. - */ - cancelled("Cancelled"); + /** + * The file transfer was cancelled. + */ + cancelled("Cancelled"); private String status; @@ -312,55 +312,55 @@ public abstract class FileTransfer { } public enum Error { - /** - * No error. - */ - none("No error"), + /** + * No error. + */ + none("No error"), - /** - * The peer did not find any of the provided stream mechanisms - * acceptable. - */ - not_acceptable("The peer did not find any of the provided stream mechanisms acceptable."), + /** + * The peer did not find any of the provided stream mechanisms + * acceptable. + */ + not_acceptable("The peer did not find any of the provided stream mechanisms acceptable."), - /** - * The provided file to transfer does not exist or could not be read. - */ - bad_file("The provided file to transfer does not exist or could not be read."), + /** + * The provided file to transfer does not exist or could not be read. + */ + bad_file("The provided file to transfer does not exist or could not be read."), - /** - * The remote user did not respond or the connection timed out. - */ - no_response("The remote user did not respond or the connection timed out."), + /** + * The remote user did not respond or the connection timed out. + */ + no_response("The remote user did not respond or the connection timed out."), - /** - * An error occurred over the socket connected to send the file. - */ - connection("An error occured over the socket connected to send the file."), + /** + * An error occurred over the socket connected to send the file. + */ + connection("An error occured over the socket connected to send the file."), - /** - * An error occurred while sending or receiving the file. - */ - stream("An error occured while sending or recieving the file."); + /** + * An error occurred while sending or receiving the file. + */ + stream("An error occured while sending or recieving the file."); - private final String msg; + private final String msg; - private Error(String msg) { - this.msg = msg; - } + private Error(String msg) { + this.msg = msg; + } - /** - * Returns a String representation of this error. - * - * @return Returns a String representation of this error. - */ - public String getMessage() { - return msg; - } + /** + * Returns a String representation of this error. + * + * @return Returns a String representation of this error. + */ + public String getMessage() { + return msg; + } - public String toString() { - return msg; - } - } + public String toString() { + return msg; + } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferListener.java index 179e3f930..cb1852afc 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferListener.java @@ -23,11 +23,11 @@ package org.jivesoftware.smackx.filetransfer; * @author Alexander Wenckus */ public interface FileTransferListener { - /** - * A request to send a file has been recieved from another user. - * - * @param request - * The request from the other user. - */ - public void fileTransferRequest(final FileTransferRequest request); + /** + * A request to send a file has been recieved from another user. + * + * @param request + * The request from the other user. + */ + public void fileTransferRequest(final FileTransferRequest request); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java index ac20d7171..78f397758 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferManager.java @@ -56,20 +56,20 @@ public final class FileTransferManager extends Manager { return fileTransferManager; } - private final FileTransferNegotiator fileTransferNegotiator; + private final FileTransferNegotiator fileTransferNegotiator; - private final List listeners = new CopyOnWriteArrayList(); + private final List listeners = new CopyOnWriteArrayList(); - /** - * Creates a file transfer manager to initiate and receive file transfers. - * - * @param connection - * The XMPPConnection that the file transfers will use. - */ - private FileTransferManager(XMPPConnection connection) { - super(connection); - this.fileTransferNegotiator = FileTransferNegotiator - .getInstanceFor(connection); + /** + * Creates a file transfer manager to initiate and receive file transfers. + * + * @param connection + * The XMPPConnection that the file transfers will use. + */ + private FileTransferManager(XMPPConnection connection) { + super(connection); + this.fileTransferNegotiator = FileTransferNegotiator + .getInstanceFor(connection); connection.registerIQRequestHandler(new AbstractIqRequestHandler(StreamInitiation.ELEMENT, StreamInitiation.NAMESPACE, IQ.Type.set, Mode.async) { @Override @@ -82,42 +82,42 @@ public final class FileTransferManager extends Manager { return null; } }); - } + } - /** - * Add a file transfer listener to listen to incoming file transfer - * requests. - * - * @param li - * The listener - * @see #removeFileTransferListener(FileTransferListener) - * @see FileTransferListener - */ - public void addFileTransferListener(final FileTransferListener li) { - listeners.add(li); - } + /** + * Add a file transfer listener to listen to incoming file transfer + * requests. + * + * @param li + * The listener + * @see #removeFileTransferListener(FileTransferListener) + * @see FileTransferListener + */ + public void addFileTransferListener(final FileTransferListener li) { + listeners.add(li); + } - /** - * Removes a file transfer listener. - * - * @param li - * The file transfer listener to be removed - * @see FileTransferListener - */ - public void removeFileTransferListener(final FileTransferListener li) { - listeners.remove(li); - } + /** + * Removes a file transfer listener. + * + * @param li + * The file transfer listener to be removed + * @see FileTransferListener + */ + public void removeFileTransferListener(final FileTransferListener li) { + listeners.remove(li); + } - /** - * Creates an OutgoingFileTransfer to send a file to another user. - * - * @param userID - * The fully qualified jabber ID (i.e. full JID) with resource of the user to - * send the file to. - * @return The send file object on which the negotiated transfer can be run. - * @exception IllegalArgumentException if userID is null or not a full JID - */ - public OutgoingFileTransfer createOutgoingFileTransfer(EntityFullJid userID) { + /** + * Creates an OutgoingFileTransfer to send a file to another user. + * + * @param userID + * The fully qualified jabber ID (i.e. full JID) with resource of the user to + * send the file to. + * @return The send file object on which the negotiated transfer can be run. + * @exception IllegalArgumentException if userID is null or not a full JID + */ + public OutgoingFileTransfer createOutgoingFileTransfer(EntityFullJid userID) { // We need to create outgoing file transfers with a full JID since this method will later // use XEP-0095 to negotiate the stream. This is done with IQ stanzas that need to be addressed to a full JID // in order to reach an client entity. @@ -125,45 +125,45 @@ public final class FileTransferManager extends Manager { throw new IllegalArgumentException("userID was null"); } - return new OutgoingFileTransfer(connection().getUser(), userID, - FileTransferNegotiator.getNextStreamID(), - fileTransferNegotiator); - } - - /** - * When the file transfer request is acceptable, this method should be - * invoked. It will create an IncomingFileTransfer which allows the - * transmission of the file to procede. - * - * @param request - * The remote request that is being accepted. - * @return The IncomingFileTransfer which manages the download of the file - * from the transfer initiator. - */ - protected IncomingFileTransfer createIncomingFileTransfer( - FileTransferRequest request) { - if (request == null) { - throw new NullPointerException("RecieveRequest cannot be null"); - } - - IncomingFileTransfer transfer = new IncomingFileTransfer(request, + return new OutgoingFileTransfer(connection().getUser(), userID, + FileTransferNegotiator.getNextStreamID(), fileTransferNegotiator); - transfer.setFileInfo(request.getFileName(), request.getFileSize()); + } - return transfer; - } + /** + * When the file transfer request is acceptable, this method should be + * invoked. It will create an IncomingFileTransfer which allows the + * transmission of the file to procede. + * + * @param request + * The remote request that is being accepted. + * @return The IncomingFileTransfer which manages the download of the file + * from the transfer initiator. + */ + protected IncomingFileTransfer createIncomingFileTransfer( + FileTransferRequest request) { + if (request == null) { + throw new NullPointerException("RecieveRequest cannot be null"); + } - /** - * Reject an incoming file transfer. - *

- * Specified in XEP-95 4.2 and 3.2 Example 8 - *

- * @param request - * @throws NotConnectedException - * @throws InterruptedException - */ - protected void rejectIncomingFileTransfer(FileTransferRequest request) throws NotConnectedException, InterruptedException { - StreamInitiation initiation = request.getStreamInitiation(); + IncomingFileTransfer transfer = new IncomingFileTransfer(request, + fileTransferNegotiator); + transfer.setFileInfo(request.getFileName(), request.getFileSize()); + + return transfer; + } + + /** + * Reject an incoming file transfer. + *

+ * Specified in XEP-95 4.2 and 3.2 Example 8 + *

+ * @param request + * @throws NotConnectedException + * @throws InterruptedException + */ + protected void rejectIncomingFileTransfer(FileTransferRequest request) throws NotConnectedException, InterruptedException { + StreamInitiation initiation = request.getStreamInitiation(); // Reject as specified in XEP-95 4.2. Note that this is not to be confused with the Socks 5 // Bytestream rejection as specified in XEP-65 5.3.1 Example 13, which says that @@ -172,5 +172,5 @@ public final class FileTransferManager extends Manager { IQ rejection = IQ.createErrorResponse(initiation, XMPPError.getBuilder( XMPPError.Condition.forbidden)); connection().sendStanza(rejection); - } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java index dd954642e..61e4e3934 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferRequest.java @@ -27,113 +27,113 @@ import org.jxmpp.jid.Jid; * */ public class FileTransferRequest { - private final StreamInitiation streamInitiation; + private final StreamInitiation streamInitiation; - private final FileTransferManager manager; + private final FileTransferManager manager; - /** - * A recieve request is constructed from the Stream Initiation request - * received from the initator. - * - * @param manager - * The manager handling this file transfer - * - * @param si - * The Stream initiaton recieved from the initiator. - */ - public FileTransferRequest(FileTransferManager manager, StreamInitiation si) { - this.streamInitiation = si; - this.manager = manager; - } + /** + * A recieve request is constructed from the Stream Initiation request + * received from the initator. + * + * @param manager + * The manager handling this file transfer + * + * @param si + * The Stream initiaton recieved from the initiator. + */ + public FileTransferRequest(FileTransferManager manager, StreamInitiation si) { + this.streamInitiation = si; + this.manager = manager; + } - /** - * Returns the name of the file. - * - * @return Returns the name of the file. - */ - public String getFileName() { - return streamInitiation.getFile().getName(); - } + /** + * Returns the name of the file. + * + * @return Returns the name of the file. + */ + public String getFileName() { + return streamInitiation.getFile().getName(); + } - /** - * Returns the size in bytes of the file. - * - * @return Returns the size in bytes of the file. - */ - public long getFileSize() { - return streamInitiation.getFile().getSize(); - } + /** + * Returns the size in bytes of the file. + * + * @return Returns the size in bytes of the file. + */ + public long getFileSize() { + return streamInitiation.getFile().getSize(); + } - /** - * Returns the description of the file provided by the requestor. - * - * @return Returns the description of the file provided by the requestor. - */ - public String getDescription() { - return streamInitiation.getFile().getDesc(); - } + /** + * Returns the description of the file provided by the requestor. + * + * @return Returns the description of the file provided by the requestor. + */ + public String getDescription() { + return streamInitiation.getFile().getDesc(); + } - /** - * Returns the mime-type of the file. - * - * @return Returns the mime-type of the file. - */ - public String getMimeType() { - return streamInitiation.getMimeType(); - } + /** + * Returns the mime-type of the file. + * + * @return Returns the mime-type of the file. + */ + public String getMimeType() { + return streamInitiation.getMimeType(); + } - /** - * Returns the fully-qualified jabber ID of the user that requested this - * file transfer. - * - * @return Returns the fully-qualified jabber ID of the user that requested - * this file transfer. - */ - public Jid getRequestor() { - return streamInitiation.getFrom(); - } + /** + * Returns the fully-qualified jabber ID of the user that requested this + * file transfer. + * + * @return Returns the fully-qualified jabber ID of the user that requested + * this file transfer. + */ + public Jid getRequestor() { + return streamInitiation.getFrom(); + } - /** - * Returns the stream ID that uniquely identifies this file transfer. - * - * @return Returns the stream ID that uniquely identifies this file - * transfer. - */ - public String getStreamID() { - return streamInitiation.getSessionID(); - } + /** + * Returns the stream ID that uniquely identifies this file transfer. + * + * @return Returns the stream ID that uniquely identifies this file + * transfer. + */ + public String getStreamID() { + return streamInitiation.getSessionID(); + } - /** - * Returns the stream initiation stanza(/packet) that was sent by the requestor which - * contains the parameters of the file transfer being transfer and also the - * methods available to transfer the file. - * - * @return Returns the stream initiation stanza(/packet) that was sent by the - * requestor which contains the parameters of the file transfer - * being transfer and also the methods available to transfer the - * file. - */ - protected StreamInitiation getStreamInitiation() { - return streamInitiation; - } + /** + * Returns the stream initiation stanza(/packet) that was sent by the requestor which + * contains the parameters of the file transfer being transfer and also the + * methods available to transfer the file. + * + * @return Returns the stream initiation stanza(/packet) that was sent by the + * requestor which contains the parameters of the file transfer + * being transfer and also the methods available to transfer the + * file. + */ + protected StreamInitiation getStreamInitiation() { + return streamInitiation; + } - /** - * Accepts this file transfer and creates the incoming file transfer. - * - * @return Returns the IncomingFileTransfer on which the - * file transfer can be carried out. - */ - public IncomingFileTransfer accept() { - return manager.createIncomingFileTransfer(this); - } + /** + * Accepts this file transfer and creates the incoming file transfer. + * + * @return Returns the IncomingFileTransfer on which the + * file transfer can be carried out. + */ + public IncomingFileTransfer accept() { + return manager.createIncomingFileTransfer(this); + } - /** - * Rejects the file transfer request. - * @throws NotConnectedException - * @throws InterruptedException - */ - public void reject() throws NotConnectedException, InterruptedException { - manager.rejectIncomingFileTransfer(this); - } + /** + * Rejects the file transfer request. + * @throws NotConnectedException + * @throws InterruptedException + */ + public void reject() throws NotConnectedException, InterruptedException { + manager.rejectIncomingFileTransfer(this); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java index c8eaf8cf9..7d8777b63 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/OutgoingFileTransfer.java @@ -43,7 +43,7 @@ import org.jxmpp.jid.Jid; public class OutgoingFileTransfer extends FileTransfer { private static final Logger LOGGER = Logger.getLogger(OutgoingFileTransfer.class.getName()); - private static int RESPONSE_TIMEOUT = 60 * 1000; + private static int RESPONSE_TIMEOUT = 60 * 1000; private NegotiationProgress callback; /** @@ -58,349 +58,349 @@ public class OutgoingFileTransfer extends FileTransfer { return RESPONSE_TIMEOUT; } - /** - * Sets the time in milliseconds after which the file transfer negotiation - * process will timeout if the other user has not responded. - * - * @param responseTimeout - * The timeout time in milliseconds. - */ - public static void setResponseTimeout(int responseTimeout) { - RESPONSE_TIMEOUT = responseTimeout; - } + /** + * Sets the time in milliseconds after which the file transfer negotiation + * process will timeout if the other user has not responded. + * + * @param responseTimeout + * The timeout time in milliseconds. + */ + public static void setResponseTimeout(int responseTimeout) { + RESPONSE_TIMEOUT = responseTimeout; + } - private OutputStream outputStream; + private OutputStream outputStream; - private Jid initiator; + private Jid initiator; - private Thread transferThread; + private Thread transferThread; - protected OutgoingFileTransfer(Jid initiator, Jid target, - String streamID, FileTransferNegotiator transferNegotiator) { - super(target, streamID, transferNegotiator); - this.initiator = initiator; - } + protected OutgoingFileTransfer(Jid initiator, Jid target, + String streamID, FileTransferNegotiator transferNegotiator) { + super(target, streamID, transferNegotiator); + this.initiator = initiator; + } - protected void setOutputStream(OutputStream stream) { - if (outputStream == null) { - this.outputStream = stream; - } - } + protected void setOutputStream(OutputStream stream) { + if (outputStream == null) { + this.outputStream = stream; + } + } - /** - * Returns the output stream connected to the peer to transfer the file. It - * is only available after it has been successfully negotiated by the - * {@link StreamNegotiator}. - * - * @return Returns the output stream connected to the peer to transfer the - * file. - */ - protected OutputStream getOutputStream() { - if (getStatus().equals(FileTransfer.Status.negotiated)) { - return outputStream; - } else { - return null; - } - } + /** + * Returns the output stream connected to the peer to transfer the file. It + * is only available after it has been successfully negotiated by the + * {@link StreamNegotiator}. + * + * @return Returns the output stream connected to the peer to transfer the + * file. + */ + protected OutputStream getOutputStream() { + if (getStatus().equals(FileTransfer.Status.negotiated)) { + return outputStream; + } else { + return null; + } + } - /** - * This method handles the negotiation of the file transfer and the stream, - * it only returns the created stream after the negotiation has been completed. - * - * @param fileName - * The name of the file that will be transmitted. It is - * preferable for this name to have an extension as it will be - * used to determine the type of file it is. - * @param fileSize - * The size in bytes of the file that will be transmitted. - * @param description - * A description of the file that will be transmitted. - * @return The OutputStream that is connected to the peer to transmit the - * file. - * @throws XMPPException - * Thrown if an error occurs during the file transfer - * negotiation process. - * @throws SmackException if there was no response from the server. - * @throws InterruptedException - */ - public synchronized OutputStream sendFile(String fileName, long fileSize, - String description) throws XMPPException, SmackException, InterruptedException { - if (isDone() || outputStream != null) { - throw new IllegalStateException( - "The negotation process has already" - + " been attempted on this file transfer"); - } - try { - setFileInfo(fileName, fileSize); - this.outputStream = negotiateStream(fileName, fileSize, description); - } catch (XMPPErrorException e) { - handleXMPPException(e); - throw e; - } - return outputStream; - } + /** + * This method handles the negotiation of the file transfer and the stream, + * it only returns the created stream after the negotiation has been completed. + * + * @param fileName + * The name of the file that will be transmitted. It is + * preferable for this name to have an extension as it will be + * used to determine the type of file it is. + * @param fileSize + * The size in bytes of the file that will be transmitted. + * @param description + * A description of the file that will be transmitted. + * @return The OutputStream that is connected to the peer to transmit the + * file. + * @throws XMPPException + * Thrown if an error occurs during the file transfer + * negotiation process. + * @throws SmackException if there was no response from the server. + * @throws InterruptedException + */ + public synchronized OutputStream sendFile(String fileName, long fileSize, + String description) throws XMPPException, SmackException, InterruptedException { + if (isDone() || outputStream != null) { + throw new IllegalStateException( + "The negotation process has already" + + " been attempted on this file transfer"); + } + try { + setFileInfo(fileName, fileSize); + this.outputStream = negotiateStream(fileName, fileSize, description); + } catch (XMPPErrorException e) { + handleXMPPException(e); + throw e; + } + return outputStream; + } - /** - * This methods handles the transfer and stream negotiation process. It - * returns immediately and its progress will be updated through the - * {@link NegotiationProgress} callback. - * - * @param fileName - * The name of the file that will be transmitted. It is - * preferable for this name to have an extension as it will be - * used to determine the type of file it is. - * @param fileSize - * The size in bytes of the file that will be transmitted. - * @param description - * A description of the file that will be transmitted. - * @param progress - * A callback to monitor the progress of the file transfer - * negotiation process and to retrieve the OutputStream when it - * is complete. - */ - public synchronized void sendFile(final String fileName, - final long fileSize, final String description, - final NegotiationProgress progress) + /** + * This methods handles the transfer and stream negotiation process. It + * returns immediately and its progress will be updated through the + * {@link NegotiationProgress} callback. + * + * @param fileName + * The name of the file that will be transmitted. It is + * preferable for this name to have an extension as it will be + * used to determine the type of file it is. + * @param fileSize + * The size in bytes of the file that will be transmitted. + * @param description + * A description of the file that will be transmitted. + * @param progress + * A callback to monitor the progress of the file transfer + * negotiation process and to retrieve the OutputStream when it + * is complete. + */ + public synchronized void sendFile(final String fileName, + final long fileSize, final String description, + final NegotiationProgress progress) { if(progress == null) { throw new IllegalArgumentException("Callback progress cannot be null."); } checkTransferThread(); - if (isDone() || outputStream != null) { - throw new IllegalStateException( - "The negotation process has already" - + " been attempted for this file transfer"); - } + if (isDone() || outputStream != null) { + throw new IllegalStateException( + "The negotation process has already" + + " been attempted for this file transfer"); + } setFileInfo(fileName, fileSize); this.callback = progress; transferThread = new Thread(new Runnable() { - public void run() { - try { - OutgoingFileTransfer.this.outputStream = negotiateStream( - fileName, fileSize, description); + public void run() { + try { + OutgoingFileTransfer.this.outputStream = negotiateStream( + fileName, fileSize, description); progress.outputStreamEstablished(OutgoingFileTransfer.this.outputStream); } catch (XMPPErrorException e) { - handleXMPPException(e); - } + handleXMPPException(e); + } catch (Exception e) { setException(e); } - } - }, "File Transfer Negotiation " + streamID); - transferThread.start(); - } + } + }, "File Transfer Negotiation " + streamID); + transferThread.start(); + } - private void checkTransferThread() { - if (transferThread != null && transferThread.isAlive() || isDone()) { - throw new IllegalStateException( - "File transfer in progress or has already completed."); - } - } + private void checkTransferThread() { + if (transferThread != null && transferThread.isAlive() || isDone()) { + throw new IllegalStateException( + "File transfer in progress or has already completed."); + } + } /** - * This method handles the stream negotiation process and transmits the file - * to the remote user. It returns immediately and the progress of the file - * transfer can be monitored through several methods: - * - *
    - *
  • {@link FileTransfer#getStatus()} - *
  • {@link FileTransfer#getProgress()} - *
  • {@link FileTransfer#isDone()} - *
- * + * This method handles the stream negotiation process and transmits the file + * to the remote user. It returns immediately and the progress of the file + * transfer can be monitored through several methods: + * + *
    + *
  • {@link FileTransfer#getStatus()} + *
  • {@link FileTransfer#getProgress()} + *
  • {@link FileTransfer#isDone()} + *
+ * * @param file the file to transfer to the remote entity. * @param description a description for the file to transfer. - * @throws SmackException - * If there is an error during the negotiation process or the - * sending of the file. - */ - public synchronized void sendFile(final File file, final String description) - throws SmackException { - checkTransferThread(); - if (file == null || !file.exists() || !file.canRead()) { - throw new IllegalArgumentException("Could not read file"); - } else { - setFileInfo(file.getAbsolutePath(), file.getName(), file.length()); - } + * @throws SmackException + * If there is an error during the negotiation process or the + * sending of the file. + */ + public synchronized void sendFile(final File file, final String description) + throws SmackException { + checkTransferThread(); + if (file == null || !file.exists() || !file.canRead()) { + throw new IllegalArgumentException("Could not read file"); + } else { + setFileInfo(file.getAbsolutePath(), file.getName(), file.length()); + } - transferThread = new Thread(new Runnable() { - public void run() { - try { - outputStream = negotiateStream(file.getName(), file - .length(), description); - } catch (XMPPErrorException e) { - handleXMPPException(e); - return; - } + transferThread = new Thread(new Runnable() { + public void run() { + try { + outputStream = negotiateStream(file.getName(), file + .length(), description); + } catch (XMPPErrorException e) { + handleXMPPException(e); + return; + } catch (Exception e) { setException(e); } - if (outputStream == null) { - return; - } + if (outputStream == null) { + return; + } if (!updateStatus(Status.negotiated, Status.in_progress)) { - return; - } + return; + } - InputStream inputStream = null; - try { - inputStream = new FileInputStream(file); - writeToStream(inputStream, outputStream); - } catch (FileNotFoundException e) { - setStatus(FileTransfer.Status.error); - setError(Error.bad_file); - setException(e); - } catch (IOException e) { - setStatus(FileTransfer.Status.error); - setException(e); - } finally { - if (inputStream != null) { - try { + InputStream inputStream = null; + try { + inputStream = new FileInputStream(file); + writeToStream(inputStream, outputStream); + } catch (FileNotFoundException e) { + setStatus(FileTransfer.Status.error); + setError(Error.bad_file); + setException(e); + } catch (IOException e) { + setStatus(FileTransfer.Status.error); + setException(e); + } finally { + if (inputStream != null) { + try { inputStream.close(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Closing input stream", e); } - } + } - try { + try { outputStream.close(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Closing output stream", e); } - } + } updateStatus(Status.in_progress, FileTransfer.Status.complete); - } + } - }, "File Transfer " + streamID); - transferThread.start(); - } + }, "File Transfer " + streamID); + transferThread.start(); + } /** - * This method handles the stream negotiation process and transmits the file - * to the remote user. It returns immediately and the progress of the file - * transfer can be monitored through several methods: - * - *
    - *
  • {@link FileTransfer#getStatus()} - *
  • {@link FileTransfer#getProgress()} - *
  • {@link FileTransfer#isDone()} - *
- * + * This method handles the stream negotiation process and transmits the file + * to the remote user. It returns immediately and the progress of the file + * transfer can be monitored through several methods: + * + *
    + *
  • {@link FileTransfer#getStatus()} + *
  • {@link FileTransfer#getProgress()} + *
  • {@link FileTransfer#isDone()} + *
+ * * @param in the stream to transfer to the remote entity. * @param fileName the name of the file that is transferred * @param fileSize the size of the file that is transferred * @param description a description for the file to transfer. - */ - public synchronized void sendStream(final InputStream in, final String fileName, final long fileSize, final String description){ - checkTransferThread(); + */ + public synchronized void sendStream(final InputStream in, final String fileName, final long fileSize, final String description){ + checkTransferThread(); - setFileInfo(fileName, fileSize); - transferThread = new Thread(new Runnable() { - public void run() { + setFileInfo(fileName, fileSize); + transferThread = new Thread(new Runnable() { + public void run() { //Create packet filter try { - outputStream = negotiateStream(fileName, fileSize, description); - } catch (XMPPErrorException e) { - handleXMPPException(e); - return; - } + outputStream = negotiateStream(fileName, fileSize, description); + } catch (XMPPErrorException e) { + handleXMPPException(e); + return; + } catch (Exception e) { setException(e); } - if (outputStream == null) { - return; - } + if (outputStream == null) { + return; + } if (!updateStatus(Status.negotiated, Status.in_progress)) { - return; - } - try { - writeToStream(in, outputStream); - } catch (IOException e) { - setStatus(FileTransfer.Status.error); - setException(e); - } finally { - try { - if (in != null) { - in.close(); - } + return; + } + try { + writeToStream(in, outputStream); + } catch (IOException e) { + setStatus(FileTransfer.Status.error); + setException(e); + } finally { + try { + if (in != null) { + in.close(); + } - outputStream.flush(); - outputStream.close(); - } catch (IOException e) { + outputStream.flush(); + outputStream.close(); + } catch (IOException e) { /* Do Nothing */ - } - } + } + } updateStatus(Status.in_progress, FileTransfer.Status.complete); - } + } - }, "File Transfer " + streamID); - transferThread.start(); - } + }, "File Transfer " + streamID); + transferThread.start(); + } - private void handleXMPPException(XMPPErrorException e) { - XMPPError error = e.getXMPPError(); - if (error != null) { - switch (error.getCondition()) { - case forbidden: - setStatus(Status.refused); - return; - case bad_request: - setStatus(Status.error); - setError(Error.not_acceptable); - break; + private void handleXMPPException(XMPPErrorException e) { + XMPPError error = e.getXMPPError(); + if (error != null) { + switch (error.getCondition()) { + case forbidden: + setStatus(Status.refused); + return; + case bad_request: + setStatus(Status.error); + setError(Error.not_acceptable); + break; default: setStatus(FileTransfer.Status.error); } } setException(e); - } + } - /** - * Returns the amount of bytes that have been sent for the file transfer. Or - * -1 if the file transfer has not started. - *

- * Note: This method is only useful when the {@link #sendFile(File, String)} - * method is called, as it is the only method that actually transmits the - * file. - * - * @return Returns the amount of bytes that have been sent for the file - * transfer. Or -1 if the file transfer has not started. - */ - public long getBytesSent() { - return amountWritten; - } + /** + * Returns the amount of bytes that have been sent for the file transfer. Or + * -1 if the file transfer has not started. + *

+ * Note: This method is only useful when the {@link #sendFile(File, String)} + * method is called, as it is the only method that actually transmits the + * file. + * + * @return Returns the amount of bytes that have been sent for the file + * transfer. Or -1 if the file transfer has not started. + */ + public long getBytesSent() { + return amountWritten; + } - private OutputStream negotiateStream(String fileName, long fileSize, - String description) throws SmackException, XMPPException, InterruptedException { - // Negotiate the file transfer profile + private OutputStream negotiateStream(String fileName, long fileSize, + String description) throws SmackException, XMPPException, InterruptedException { + // Negotiate the file transfer profile if (!updateStatus(Status.initial, Status.negotiating_transfer)) { throw new IllegalStateChangeException(); } - StreamNegotiator streamNegotiator = negotiator.negotiateOutgoingTransfer( - getPeer(), streamID, fileName, fileSize, description, - RESPONSE_TIMEOUT); + StreamNegotiator streamNegotiator = negotiator.negotiateOutgoingTransfer( + getPeer(), streamID, fileName, fileSize, description, + RESPONSE_TIMEOUT); // Negotiate the stream if (!updateStatus(Status.negotiating_transfer, Status.negotiating_stream)) { throw new IllegalStateChangeException(); } - outputStream = streamNegotiator.createOutgoingStream(streamID, + outputStream = streamNegotiator.createOutgoingStream(streamID, initiator, getPeer()); if (!updateStatus(Status.negotiating_stream, Status.negotiated)) { throw new IllegalStateChangeException(); - } - return outputStream; - } + } + return outputStream; + } - public void cancel() { - setStatus(Status.cancelled); - } + public void cancel() { + setStatus(Status.cancelled); + } @Override protected boolean updateStatus(Status oldStatus, Status newStatus) { @@ -429,30 +429,30 @@ public class OutgoingFileTransfer extends FileTransfer { } /** - * A callback class to retrieve the status of an outgoing transfer - * negotiation process. - * - * @author Alexander Wenckus - * - */ - public interface NegotiationProgress { + * A callback class to retrieve the status of an outgoing transfer + * negotiation process. + * + * @author Alexander Wenckus + * + */ + public interface NegotiationProgress { - /** - * Called when the status changes. + /** + * Called when the status changes. * * @param oldStatus the previous status of the file transfer. * @param newStatus the new status of the file transfer. */ - void statusUpdated(Status oldStatus, Status newStatus); + void statusUpdated(Status oldStatus, Status newStatus); - /** - * Once the negotiation process is completed the output stream can be - * retrieved. + /** + * Once the negotiation process is completed the output stream can be + * retrieved. * * @param stream the established stream which can be used to transfer the file to the remote * entity - */ - void outputStreamEstablished(OutputStream stream); + */ + void outputStreamEstablished(OutputStream stream); /** * Called when an exception occurs during the negotiation progress. diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/provider/RegistrationProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/provider/RegistrationProvider.java index bf3aa34e0..f4063c5a8 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/provider/RegistrationProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/provider/RegistrationProvider.java @@ -71,6 +71,6 @@ public class RegistrationProvider extends IQProvider { Registration registration = new Registration(instruction, fields); registration.addExtensions(packetExtensions); return registration; - } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/nick/packet/Nick.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/nick/packet/Nick.java index 0038dd0a4..2275993b7 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/nick/packet/Nick.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/nick/packet/Nick.java @@ -31,77 +31,77 @@ import org.xmlpull.v1.XmlPullParserException; */ public class Nick implements ExtensionElement { - public static final String NAMESPACE = "http://jabber.org/protocol/nick"; + public static final String NAMESPACE = "http://jabber.org/protocol/nick"; - public static final String ELEMENT_NAME = "nick"; + public static final String ELEMENT_NAME = "nick"; - private String name = null; + private String name = null; - public Nick(String name) { - this.name = name; - } + public Nick(String name) { + this.name = name; + } - /** - * The value of this nickname. - * - * @return the nickname - */ - public String getName() { - return name; - } + /** + * The value of this nickname. + * + * @return the nickname + */ + public String getName() { + return name; + } - /** - * Sets the value of this nickname. - * - * @param name - * the name to set - */ - public void setName(String name) { - this.name = name; - } + /** + * Sets the value of this nickname. + * + * @param name + * the name to set + */ + public void setName(String name) { + this.name = name; + } - /* - * (non-Javadoc) - * - * @see org.jivesoftware.smack.packet.PacketExtension#getElementName() - */ - public String getElementName() { - return ELEMENT_NAME; - } + /* + * (non-Javadoc) + * + * @see org.jivesoftware.smack.packet.PacketExtension#getElementName() + */ + public String getElementName() { + return ELEMENT_NAME; + } - /* - * (non-Javadoc) - * - * @see org.jivesoftware.smack.packet.PacketExtension#getNamespace() - */ - public String getNamespace() { - return NAMESPACE; - } + /* + * (non-Javadoc) + * + * @see org.jivesoftware.smack.packet.PacketExtension#getNamespace() + */ + public String getNamespace() { + return NAMESPACE; + } - /* - * (non-Javadoc) - * - * @see org.jivesoftware.smack.packet.PacketExtension#toXML() - */ - public String toXML() { - final StringBuilder buf = new StringBuilder(); + /* + * (non-Javadoc) + * + * @see org.jivesoftware.smack.packet.PacketExtension#toXML() + */ + public String toXML() { + final StringBuilder buf = new StringBuilder(); - buf.append('<').append(ELEMENT_NAME).append(" xmlns=\"").append( - NAMESPACE).append("\">"); - buf.append(getName()); - buf.append("'); + buf.append('<').append(ELEMENT_NAME).append(" xmlns=\"").append( + NAMESPACE).append("\">"); + buf.append(getName()); + buf.append("'); - return buf.toString(); - } + return buf.toString(); + } - public static class Provider extends ExtensionElementProvider { + public static class Provider extends ExtensionElementProvider { @Override public Nick parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { - final String name = parser.nextText(); + final String name = parser.nextText(); - return new Nick(name); - } - } + return new Nick(name); + } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java index 73aa34c7a..727bb4fdb 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/PrivacyListManager.java @@ -95,7 +95,7 @@ public final class PrivacyListManager extends Manager { * * @param connection the XMPP connection. */ - private PrivacyListManager(XMPPConnection connection) { + private PrivacyListManager(XMPPConnection connection) { super(connection); connection.registerIQRequestHandler(new AbstractIqRequestHandler(Privacy.ELEMENT, Privacy.NAMESPACE, @@ -215,24 +215,24 @@ public final class PrivacyListManager extends Manager { return plm; } - /** - * Send the {@link Privacy} stanza(/packet) to the server in order to know some privacy content and then - * waits for the answer. - * - * @param requestPrivacy is the {@link Privacy} stanza(/packet) configured properly whose XML + /** + * Send the {@link Privacy} stanza(/packet) to the server in order to know some privacy content and then + * waits for the answer. + * + * @param requestPrivacy is the {@link Privacy} stanza(/packet) configured properly whose XML * will be sent to the server. - * @return a new {@link Privacy} with the data received from the server. - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - private Privacy getRequest(Privacy requestPrivacy) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - // The request is a get iq type - requestPrivacy.setType(Privacy.Type.get); + * @return a new {@link Privacy} with the data received from the server. + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + private Privacy getRequest(Privacy requestPrivacy) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + // The request is a get iq type + requestPrivacy.setType(Privacy.Type.get); return connection().createStanzaCollectorAndSend(requestPrivacy).nextResultOrThrow(); - } + } /** * Send the {@link Privacy} stanza(/packet) to the server in order to modify the server privacy and waits @@ -253,22 +253,22 @@ public final class PrivacyListManager extends Manager { return connection().createStanzaCollectorAndSend(requestPrivacy).nextResultOrThrow(); } - /** - * Answer a privacy containing the list structure without {@link PrivacyItem}. - * - * @return a Privacy with the list names. - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - private Privacy getPrivacyWithListNames() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - // The request of the list is an empty privacy message - Privacy request = new Privacy(); + /** + * Answer a privacy containing the list structure without {@link PrivacyItem}. + * + * @return a Privacy with the list names. + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + private Privacy getPrivacyWithListNames() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + // The request of the list is an empty privacy message + Privacy request = new Privacy(); - // Send the package to the server and get the answer - return getRequest(request); - } + // Send the package to the server and get the answer + return getRequest(request); + } /** * Answer the active privacy list. Returns null if there is no active list. @@ -386,20 +386,20 @@ public final class PrivacyListManager extends Manager { return privacyAnswer.getPrivacyList(listName); } - /** - * Answer the privacy list items under listName with the allowed and blocked permissions. - * - * @param listName the name of the list to get the allowed and blocked permissions. - * @return a privacy list under the list listName. - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public PrivacyList getPrivacyList(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + /** + * Answer the privacy list items under listName with the allowed and blocked permissions. + * + * @param listName the name of the list to get the allowed and blocked permissions. + * @return a privacy list under the list listName. + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public PrivacyList getPrivacyList(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { listName = StringUtils.requireNotNullOrEmpty(listName, "List name must not be null"); return new PrivacyList(false, false, listName, getPrivacyListItems(listName)); - } + } /** * Answer every privacy list with the allowed and blocked permissions. @@ -423,87 +423,87 @@ public final class PrivacyListManager extends Manager { return lists; } - /** - * Set or change the active list to listName. - * - * @param listName the list name to set as the active one. - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public void setActiveListName(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - // The request of the list is an privacy message with an empty list - Privacy request = new Privacy(); - request.setActiveName(listName); + /** + * Set or change the active list to listName. + * + * @param listName the list name to set as the active one. + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public void setActiveListName(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + // The request of the list is an privacy message with an empty list + Privacy request = new Privacy(); + request.setActiveName(listName); - // Send the package to the server - setRequest(request); - } + // Send the package to the server + setRequest(request); + } - /** - * Client declines the use of active lists. - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public void declineActiveList() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - // The request of the list is an privacy message with an empty list - Privacy request = new Privacy(); - request.setDeclineActiveList(true); + /** + * Client declines the use of active lists. + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public void declineActiveList() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + // The request of the list is an privacy message with an empty list + Privacy request = new Privacy(); + request.setDeclineActiveList(true); - // Send the package to the server - setRequest(request); - } + // Send the package to the server + setRequest(request); + } - /** - * Set or change the default list to listName. - * - * @param listName the list name to set as the default one. - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public void setDefaultListName(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - // The request of the list is an privacy message with an empty list - Privacy request = new Privacy(); - request.setDefaultName(listName); + /** + * Set or change the default list to listName. + * + * @param listName the list name to set as the default one. + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public void setDefaultListName(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + // The request of the list is an privacy message with an empty list + Privacy request = new Privacy(); + request.setDefaultName(listName); - // Send the package to the server - setRequest(request); - } + // Send the package to the server + setRequest(request); + } - /** - * Client declines the use of default lists. - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public void declineDefaultList() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - // The request of the list is an privacy message with an empty list - Privacy request = new Privacy(); - request.setDeclineDefaultList(true); + /** + * Client declines the use of default lists. + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public void declineDefaultList() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + // The request of the list is an privacy message with an empty list + Privacy request = new Privacy(); + request.setDeclineDefaultList(true); - // Send the package to the server - setRequest(request); - } + // Send the package to the server + setRequest(request); + } - /** - * The client has created a new list. It send the new one to the server. - * + /** + * The client has created a new list. It send the new one to the server. + * * @param listName the list that has changed its content. * @param privacyItems a List with every privacy item in the list. - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public void createPrivacyList(String listName, List privacyItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - updatePrivacyList(listName, privacyItems); - } + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public void createPrivacyList(String listName, List privacyItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + updatePrivacyList(listName, privacyItems); + } /** * The client has edited an existing list. It updates the server content with the resulting @@ -526,23 +526,23 @@ public final class PrivacyListManager extends Manager { setRequest(request); } - /** - * Remove a privacy list. - * + /** + * Remove a privacy list. + * * @param listName the list that has changed its content. - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public void deletePrivacyList(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { - // The request of the list is an privacy message with an empty list - Privacy request = new Privacy(); - request.setPrivacyList(listName, new ArrayList()); + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public void deletePrivacyList(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + // The request of the list is an privacy message with an empty list + Privacy request = new Privacy(); + request.setPrivacyList(listName, new ArrayList()); - // Send the package to the server - setRequest(request); - } + // Send the package to the server + setRequest(request); + } /** * Adds a privacy list listener that will be notified of any new update in the user diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/Privacy.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/Privacy.java index be45b3992..11b056a28 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/Privacy.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/packet/Privacy.java @@ -45,17 +45,17 @@ public class Privacy extends IQ { public static final String ELEMENT = QUERY_ELEMENT; public static final String NAMESPACE = "jabber:iq:privacy"; - /** declineActiveList is true when the user declines the use of the active list **/ - private boolean declineActiveList=false; - /** activeName is the name associated with the active list set for the session **/ - private String activeName; - /** declineDefaultList is true when the user declines the use of the default list **/ - private boolean declineDefaultList=false; - /** defaultName is the name of the default list that applies to the user as a whole **/ - private String defaultName; - /** itemLists holds the set of privacy items classified in lists. It is a map where the - * key is the name of the list and the value a collection with privacy items. **/ - private Map> itemLists = new HashMap>(); + /** declineActiveList is true when the user declines the use of the active list **/ + private boolean declineActiveList=false; + /** activeName is the name associated with the active list set for the session **/ + private String activeName; + /** declineDefaultList is true when the user declines the use of the default list **/ + private boolean declineDefaultList=false; + /** defaultName is the name of the default list that applies to the user as a whole **/ + private String defaultName; + /** itemLists holds the set of privacy items classified in lists. It is a map where the + * key is the name of the list and the value a collection with privacy items. **/ + private Map> itemLists = new HashMap>(); public Privacy() { super(ELEMENT, NAMESPACE); @@ -94,13 +94,13 @@ public class Privacy extends IQ { public void deletePrivacyList(String listName) { // Remove the list from the cache // CHECKSTYLE:OFF - this.getItemLists().remove(listName); + this.getItemLists().remove(listName); // CHECKSTYLE:ON // Check if deleted list was the default list if (this.getDefaultName() != null && listName.equals(this.getDefaultName())) { // CHECKSTYLE:OFF - this.setDefaultName(null); + this.setDefaultName(null); // CHECKSTYLE:ON } } @@ -114,9 +114,9 @@ public class Privacy extends IQ { // Check if we have the default list // CHECKSTYLE:OFF if (this.getActiveName() == null) { - return null; + return null; } else { - return this.getItemLists().get(this.getActiveName()); + return this.getItemLists().get(this.getActiveName()); } // CHECKSTYLE:ON } @@ -130,9 +130,9 @@ public class Privacy extends IQ { // Check if we have the default list // CHECKSTYLE:OFF if (this.getDefaultName() == null) { - return null; + return null; } else { - return this.getItemLists().get(this.getDefaultName()); + return this.getItemLists().get(this.getDefaultName()); } // CHECKSTYLE:ON } @@ -156,15 +156,15 @@ public class Privacy extends IQ { */ public PrivacyItem getItem(String listName, int order) { // CHECKSTYLE:OFF - Iterator values = getPrivacyList(listName).iterator(); - PrivacyItem itemFound = null; - while (itemFound == null && values.hasNext()) { - PrivacyItem element = values.next(); - if (element.getOrder() == order) { - itemFound = element; - } - } - return itemFound; + Iterator values = getPrivacyList(listName).iterator(); + PrivacyItem itemFound = null; + while (itemFound == null && values.hasNext()) { + PrivacyItem element = values.next(); + if (element.getOrder() == order) { + itemFound = element; + } + } + return itemFound; // CHECKSTYLE:ON } @@ -180,7 +180,7 @@ public class Privacy extends IQ { return true; } else { // CHECKSTYLE:OFF - return false; + return false; // CHECKSTYLE:ON } } @@ -192,7 +192,7 @@ public class Privacy extends IQ { */ public void deleteList(String listName) { // CHECKSTYLE:OFF - this.getItemLists().remove(listName); + this.getItemLists().remove(listName); // CHECKSTYLE:ON } @@ -203,9 +203,9 @@ public class Privacy extends IQ { * @return the name of the active list. */ // CHECKSTYLE:OFF - public String getActiveName() { - return activeName; - } + public String getActiveName() { + return activeName; + } // CHECKSTYLE:ON /** @@ -215,9 +215,9 @@ public class Privacy extends IQ { * @param activeName is the name of the active list. */ // CHECKSTYLE:OFF - public void setActiveName(String activeName) { - this.activeName = activeName; - } + public void setActiveName(String activeName) { + this.activeName = activeName; + } // CHECKSTYLE:ON /** @@ -228,9 +228,9 @@ public class Privacy extends IQ { * @return the name of the default list. */ // CHECKSTYLE:OFF - public String getDefaultName() { - return defaultName; - } + public String getDefaultName() { + return defaultName; + } // CHECKSTYLE:ON /** @@ -243,9 +243,9 @@ public class Privacy extends IQ { * @param defaultName is the name of the default list. */ // CHECKSTYLE:OFF - public void setDefaultName(String defaultName) { - this.defaultName = defaultName; - } + public void setDefaultName(String defaultName) { + this.defaultName = defaultName; + } // CHECKSTYLE:ON /** @@ -257,9 +257,9 @@ public class Privacy extends IQ { * collection of privacy items. */ // CHECKSTYLE:OFF - public Map> getItemLists() { - return itemLists; - } + public Map> getItemLists() { + return itemLists; + } // CHECKSTYLE:ON /** @@ -268,9 +268,9 @@ public class Privacy extends IQ { * @return the decline status of the list. */ // CHECKSTYLE:OFF - public boolean isDeclineActiveList() { - return declineActiveList; - } + public boolean isDeclineActiveList() { + return declineActiveList; + } // CHECKSYTLE:ON /** @@ -279,9 +279,9 @@ public class Privacy extends IQ { * @param declineActiveList indicates if the receiver declines the use of an active list. */ // CHECKSTYLE:OFF - public void setDeclineActiveList(boolean declineActiveList) { - this.declineActiveList = declineActiveList; - } + public void setDeclineActiveList(boolean declineActiveList) { + this.declineActiveList = declineActiveList; + } // CHECKSTYLE:ON /** @@ -290,9 +290,9 @@ public class Privacy extends IQ { * @return the decline status of the list. */ // CHECKSTYLE:OFF - public boolean isDeclineDefaultList() { - return declineDefaultList; - } + public boolean isDeclineDefaultList() { + return declineDefaultList; + } // CHECKSTYLE:ON /** @@ -301,18 +301,18 @@ public class Privacy extends IQ { * @param declineDefaultList indicates if the receiver declines the use of a default list. */ // CHECKSTYLE:OFF - public void setDeclineDefaultList(boolean declineDefaultList) { - this.declineDefaultList = declineDefaultList; - } + public void setDeclineDefaultList(boolean declineDefaultList) { + this.declineDefaultList = declineDefaultList; + } - /** + /** * Returns all the list names the user has defined to group restrictions. * * @return a Set with Strings containing every list names. */ - public Set getPrivacyListNames() { - return this.itemLists.keySet(); - } + public Set getPrivacyListNames() { + return this.itemLists.keySet(); + } // CHECKSTYLE:ON @Override @@ -322,40 +322,40 @@ public class Privacy extends IQ { // Add the active tag if (this.isDeclineActiveList()) { - buf.append(""); + buf.append(""); } else { - if (this.getActiveName() != null) { + if (this.getActiveName() != null) { buf.append(""); } } // Add the default tag if (this.isDeclineDefaultList()) { - buf.append(""); + buf.append(""); } else { - if (this.getDefaultName() != null) { + if (this.getDefaultName() != null) { buf.append(""); - } + } } // Add the list with their privacy items for (Map.Entry> entry : this.getItemLists().entrySet()) { String listName = entry.getKey(); List items = entry.getValue(); - // Begin the list tag - if (items.isEmpty()) { + // Begin the list tag + if (items.isEmpty()) { buf.append(""); - } else { + } else { buf.append(""); - } - for (PrivacyItem item : items) { - // Append the item xml representation - buf.append(item.toXML()); - } - // Close the list tag - if (!items.isEmpty()) { - buf.append(""); - } - } + } + for (PrivacyItem item : items) { + // Append the item xml representation + buf.append(item.toXML()); + } + // Close the list tag + if (!items.isEmpty()) { + buf.append(""); + } + } // CHECKSTYLE:ON return buf; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/provider/PrivacyProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/provider/PrivacyProvider.java index ac6a8e523..15db41f9a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/provider/PrivacyProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/privacy/provider/PrivacyProvider.java @@ -47,20 +47,20 @@ public class PrivacyProvider extends IQProvider { if (eventType == XmlPullParser.START_TAG) { // CHECKSTYLE:OFF if (parser.getName().equals("active")) { - String activeName = parser.getAttributeValue("", "name"); - if (activeName == null) { - privacy.setDeclineActiveList(true); - } else { - privacy.setActiveName(activeName); - } + String activeName = parser.getAttributeValue("", "name"); + if (activeName == null) { + privacy.setDeclineActiveList(true); + } else { + privacy.setActiveName(activeName); + } } else if (parser.getName().equals("default")) { - String defaultName = parser.getAttributeValue("", "name"); - if (defaultName == null) { - privacy.setDeclineDefaultList(true); - } else { - privacy.setDefaultName(defaultName); - } + String defaultName = parser.getAttributeValue("", "name"); + if (defaultName == null) { + privacy.setDeclineDefaultList(true); + } else { + privacy.setDefaultName(defaultName); + } } // CHECKSTYLE:ON else if (parser.getName().equals("list")) { @@ -75,10 +75,10 @@ public class PrivacyProvider extends IQProvider { } return privacy; - } + } - // Parse the list complex type - private static void parseList(XmlPullParser parser, Privacy privacy) throws XmlPullParserException, IOException, SmackException { + // Parse the list complex type + private static void parseList(XmlPullParser parser, Privacy privacy) throws XmlPullParserException, IOException, SmackException { boolean done = false; String listName = parser.getAttributeValue("", "name"); ArrayList items = new ArrayList(); @@ -87,7 +87,7 @@ public class PrivacyProvider extends IQProvider { if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("item")) { // CHECKSTYLE:OFF - items.add(parseItem(parser)); + items.add(parseItem(parser)); // CHECKSTYLE:ON } } @@ -100,10 +100,10 @@ public class PrivacyProvider extends IQProvider { privacy.setPrivacyList(listName, items); // CHECKSTYLE:OFF - } + } - // Parse the list complex type - private static PrivacyItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException { + // Parse the list complex type + private static PrivacyItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException { // CHECKSTYLE:ON // Retrieves the required attributes String actionValue = parser.getAttributeValue("", "action"); @@ -142,7 +142,7 @@ public class PrivacyProvider extends IQProvider { parseItemChildElements(parser, item); return item; // CHECKSTYLE:OFF - } + } // CHECKSTYLE:ON private static void parseItemChildElements(XmlPullParser parser, PrivacyItem privacyItem) throws XmlPullParserException, IOException { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/AccessModel.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/AccessModel.java index 6748cd40a..eb2614872 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/AccessModel.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/AccessModel.java @@ -24,18 +24,18 @@ package org.jivesoftware.smackx.pubsub; */ public enum AccessModel { - /** Anyone may subscribe and retrieve items. */ - open, + /** Anyone may subscribe and retrieve items. */ + open, - /** Subscription request must be approved and only subscribers may retrieve items. */ - authorize, + /** Subscription request must be approved and only subscribers may retrieve items. */ + authorize, - /** Anyone with a presence subscription of both or from may subscribe and retrieve items. */ - presence, + /** Anyone with a presence subscription of both or from may subscribe and retrieve items. */ + presence, - /** Anyone in the specified roster group(s) may subscribe and retrieve items. */ - roster, + /** Anyone in the specified roster group(s) may subscribe and retrieve items. */ + roster, - /** Only those on a whitelist may subscribe and retrieve items. */ - whitelist; + /** Only those on a whitelist may subscribe and retrieve items. */ + whitelist; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Affiliation.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Affiliation.java index 9bd1b8c2f..dde32fa25 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Affiliation.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Affiliation.java @@ -42,17 +42,17 @@ public class Affiliation implements ExtensionElement private final Type affiliation; private final PubSubNamespace namespace; - public enum Type - { - member, none, outcast, owner, publisher - } + public enum Type + { + member, none, outcast, owner, publisher + } - /** - * Constructs an affiliation. - * - * @param node The node the user is affiliated with. - * @param affiliation the optional affiliation. - */ + /** + * Constructs an affiliation. + * + * @param node The node the user is affiliated with. + * @param affiliation the optional affiliation. + */ public Affiliation(String node, Type affiliation) { this.node = StringUtils.requireNotNullOrEmpty(node, "node must not be null or empty"); this.affiliation = affiliation; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/AffiliationsExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/AffiliationsExtension.java index b365adc47..9e4ae26be 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/AffiliationsExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/AffiliationsExtension.java @@ -30,8 +30,8 @@ import org.jivesoftware.smack.util.XmlStringBuilder; */ public class AffiliationsExtension extends NodeExtension { - protected List items = Collections.emptyList(); - private final String node; + protected List items = Collections.emptyList(); + private final String node; public AffiliationsExtension() { this(null, null); @@ -47,20 +47,20 @@ public class AffiliationsExtension extends NodeExtension this.node = node; } - public List getAffiliations() - { - return items; - } + public List getAffiliations() + { + return items; + } - @Override - public CharSequence toXML() - { - if ((items == null) || (items.size() == 0)) - { - return super.toXML(); - } - else - { + @Override + public CharSequence toXML() + { + if ((items == null) || (items.size() == 0)) + { + return super.toXML(); + } + else + { // Can't use XmlStringBuilder(this), because we don't want the namespace to be included XmlStringBuilder xml = new XmlStringBuilder(); xml.openElement(getElementName()); @@ -69,6 +69,6 @@ public class AffiliationsExtension extends NodeExtension xml.append(items); xml.closeElement(this); return xml; - } - } + } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ChildrenAssociationPolicy.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ChildrenAssociationPolicy.java index cab4ddb64..9e5021b13 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ChildrenAssociationPolicy.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ChildrenAssociationPolicy.java @@ -24,12 +24,12 @@ package org.jivesoftware.smackx.pubsub; */ public enum ChildrenAssociationPolicy { - /** Anyone may associate leaf nodes with the collection. */ - all, + /** Anyone may associate leaf nodes with the collection. */ + all, - /** Only collection node owners may associate leaf nodes with the collection. */ - owners, + /** Only collection node owners may associate leaf nodes with the collection. */ + owners, - /** Only those on a whitelist may associate leaf nodes with the collection. */ - whitelist; + /** Only those on a whitelist may associate leaf nodes with the collection. */ + whitelist; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/CollectionNode.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/CollectionNode.java index 4b93f3bd5..47260e6bb 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/CollectionNode.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/CollectionNode.java @@ -18,9 +18,9 @@ package org.jivesoftware.smackx.pubsub; public class CollectionNode extends Node { - CollectionNode(PubSubManager pubSubManager, String nodeId) - { - super(pubSubManager, nodeId); - } + CollectionNode(PubSubManager pubSubManager, String nodeId) + { + super(pubSubManager, nodeId); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigurationEvent.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigurationEvent.java index fb46f78cc..112507953 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigurationEvent.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigurationEvent.java @@ -31,29 +31,29 @@ import org.jivesoftware.smack.packet.ExtensionElement; */ public class ConfigurationEvent extends NodeExtension implements EmbeddedPacketExtension { - private ConfigureForm form; + private ConfigureForm form; - public ConfigurationEvent(String nodeId) - { - super(PubSubElementType.CONFIGURATION, nodeId); - } + public ConfigurationEvent(String nodeId) + { + super(PubSubElementType.CONFIGURATION, nodeId); + } - public ConfigurationEvent(String nodeId, ConfigureForm configForm) - { - super(PubSubElementType.CONFIGURATION, nodeId); - form = configForm; - } + public ConfigurationEvent(String nodeId, ConfigureForm configForm) + { + super(PubSubElementType.CONFIGURATION, nodeId); + form = configForm; + } - public ConfigureForm getConfiguration() - { - return form; - } + public ConfigureForm getConfiguration() + { + return form; + } - public List getExtensions() - { - if (getConfiguration() == null) - return Collections.emptyList(); - else - return Arrays.asList(((ExtensionElement)getConfiguration().getDataFormToSend())); - } + public List getExtensions() + { + if (getConfiguration() == null) + return Collections.emptyList(); + else + return Arrays.asList(((ExtensionElement)getConfiguration().getDataFormToSend())); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java index 144c50393..5d6ecf683 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java @@ -35,555 +35,555 @@ import org.jivesoftware.smackx.xdata.packet.DataForm; */ 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) - { - super(configDataForm); - } + /** + * Create a decorator from an existing {@link DataForm} that has been + * retrieved from parsing a node configuration request. + * + * @param configDataForm + */ + public ConfigureForm(DataForm configDataForm) + { + super(configDataForm); + } - /** - * Create a decorator from an existing {@link Form} for node configuration. - * Typically, this can be used to create a decorator for an answer form - * by using the result of {@link #createAnswerForm()} as the input parameter. - * - * @param nodeConfigForm - */ - public ConfigureForm(Form nodeConfigForm) - { - super(nodeConfigForm.getDataFormToSend()); - } + /** + * Create a decorator from an existing {@link Form} for node configuration. + * Typically, this can be used to create a decorator for an answer form + * by using the result of {@link #createAnswerForm()} as the input parameter. + * + * @param nodeConfigForm + */ + public ConfigureForm(Form nodeConfigForm) + { + super(nodeConfigForm.getDataFormToSend()); + } - /** - * Create a new form for configuring a node. This would typically only be used - * when creating and configuring a node at the same time via {@link PubSubManager#createNode(String, Form)}, since - * configuration of an existing node is typically accomplished by calling {@link LeafNode#getNodeConfiguration()} and - * using the resulting form to create a answer form. See {@link #ConfigureForm(Form)}. - * @param formType - */ - public ConfigureForm(DataForm.Type formType) - { - super(formType); - } + /** + * Create a new form for configuring a node. This would typically only be used + * when creating and configuring a node at the same time via {@link PubSubManager#createNode(String, Form)}, since + * configuration of an existing node is typically accomplished by calling {@link LeafNode#getNodeConfiguration()} and + * using the resulting form to create a answer form. See {@link #ConfigureForm(Form)}. + * @param formType + */ + public ConfigureForm(DataForm.Type formType) + { + super(formType); + } - /** - * Get the currently configured {@link AccessModel}, null if it is not set. - * - * @return The current {@link AccessModel} - */ - public AccessModel getAccessModel() - { - String value = getFieldValue(ConfigureNodeFields.access_model); + /** + * Get the currently configured {@link AccessModel}, null if it is not set. + * + * @return The current {@link AccessModel} + */ + public AccessModel getAccessModel() + { + String value = getFieldValue(ConfigureNodeFields.access_model); - if (value == null) - return null; - else - return AccessModel.valueOf(value); - } + if (value == null) + return null; + else + return AccessModel.valueOf(value); + } - /** - * Sets the value of access model. - * - * @param accessModel - */ - public void setAccessModel(AccessModel accessModel) - { - addField(ConfigureNodeFields.access_model, FormField.Type.list_single); - setAnswer(ConfigureNodeFields.access_model.getFieldName(), getListSingle(accessModel.toString())); - } + /** + * Sets the value of access model. + * + * @param accessModel + */ + public void setAccessModel(AccessModel accessModel) + { + addField(ConfigureNodeFields.access_model, FormField.Type.list_single); + setAnswer(ConfigureNodeFields.access_model.getFieldName(), getListSingle(accessModel.toString())); + } - /** - * Returns the URL of an XSL transformation which can be applied to payloads in order to - * generate an appropriate message body element. - * - * @return URL to an XSL - */ - public String getBodyXSLT() - { - return getFieldValue(ConfigureNodeFields.body_xslt); - } + /** + * Returns the URL of an XSL transformation which can be applied to payloads in order to + * generate an appropriate message body element. + * + * @return URL to an XSL + */ + public String getBodyXSLT() + { + return getFieldValue(ConfigureNodeFields.body_xslt); + } - /** - * Set the URL of an XSL transformation which can be applied to payloads in order to - * generate an appropriate message body element. - * - * @param bodyXslt The URL of an XSL - */ - public void setBodyXSLT(String bodyXslt) - { - addField(ConfigureNodeFields.body_xslt, FormField.Type.text_single); - setAnswer(ConfigureNodeFields.body_xslt.getFieldName(), bodyXslt); - } + /** + * Set the URL of an XSL transformation which can be applied to payloads in order to + * generate an appropriate message body element. + * + * @param bodyXslt The URL of an XSL + */ + public void setBodyXSLT(String bodyXslt) + { + addField(ConfigureNodeFields.body_xslt, FormField.Type.text_single); + setAnswer(ConfigureNodeFields.body_xslt.getFieldName(), bodyXslt); + } - /** - * The id's of the child nodes associated with a collection node (both leaf and collection). - * - * @return list of child nodes. - */ - public List getChildren() - { - return getFieldValues(ConfigureNodeFields.children); - } + /** + * The id's of the child nodes associated with a collection node (both leaf and collection). + * + * @return list of child nodes. + */ + public List getChildren() + { + return getFieldValues(ConfigureNodeFields.children); + } - /** - * Set the list of child node ids that are associated with a collection node. - * - * @param children - */ - public void setChildren(List children) - { - addField(ConfigureNodeFields.children, FormField.Type.text_multi); - setAnswer(ConfigureNodeFields.children.getFieldName(), children); - } + /** + * Set the list of child node ids that are associated with a collection node. + * + * @param children + */ + public void setChildren(List children) + { + addField(ConfigureNodeFields.children, FormField.Type.text_multi); + setAnswer(ConfigureNodeFields.children.getFieldName(), children); + } - /** - * Returns the policy that determines who may associate children with the node. - * - * @return The current policy - */ - public ChildrenAssociationPolicy getChildrenAssociationPolicy() - { - String value = getFieldValue(ConfigureNodeFields.children_association_policy); + /** + * Returns the policy that determines who may associate children with the node. + * + * @return The current policy + */ + public ChildrenAssociationPolicy getChildrenAssociationPolicy() + { + String value = getFieldValue(ConfigureNodeFields.children_association_policy); - if (value == null) - return null; - else - return ChildrenAssociationPolicy.valueOf(value); - } + if (value == null) + return null; + else + return ChildrenAssociationPolicy.valueOf(value); + } - /** - * Sets the policy that determines who may associate children with the node. - * - * @param policy The policy being set - */ - public void setChildrenAssociationPolicy(ChildrenAssociationPolicy policy) - { - addField(ConfigureNodeFields.children_association_policy, FormField.Type.list_single); + /** + * Sets the policy that determines who may associate children with the node. + * + * @param policy The policy being set + */ + public void setChildrenAssociationPolicy(ChildrenAssociationPolicy policy) + { + addField(ConfigureNodeFields.children_association_policy, FormField.Type.list_single); List values = new ArrayList(1); values.add(policy.toString()); setAnswer(ConfigureNodeFields.children_association_policy.getFieldName(), values); - } + } - /** - * List of JID's that are on the whitelist that determines who can associate child nodes - * with the collection node. This is only relevant if {@link #getChildrenAssociationPolicy()} is set to - * {@link ChildrenAssociationPolicy#whitelist}. - * - * @return List of the whitelist - */ - public List getChildrenAssociationWhitelist() - { - return getFieldValues(ConfigureNodeFields.children_association_whitelist); - } + /** + * List of JID's that are on the whitelist that determines who can associate child nodes + * with the collection node. This is only relevant if {@link #getChildrenAssociationPolicy()} is set to + * {@link ChildrenAssociationPolicy#whitelist}. + * + * @return List of the whitelist + */ + public List getChildrenAssociationWhitelist() + { + return getFieldValues(ConfigureNodeFields.children_association_whitelist); + } - /** - * Set the JID's in the whitelist of users that can associate child nodes with the collection - * node. This is only relevant if {@link #getChildrenAssociationPolicy()} is set to - * {@link ChildrenAssociationPolicy#whitelist}. - * - * @param whitelist The list of JID's - */ - public void setChildrenAssociationWhitelist(List whitelist) - { - addField(ConfigureNodeFields.children_association_whitelist, FormField.Type.jid_multi); - setAnswer(ConfigureNodeFields.children_association_whitelist.getFieldName(), whitelist); - } + /** + * Set the JID's in the whitelist of users that can associate child nodes with the collection + * node. This is only relevant if {@link #getChildrenAssociationPolicy()} is set to + * {@link ChildrenAssociationPolicy#whitelist}. + * + * @param whitelist The list of JID's + */ + public void setChildrenAssociationWhitelist(List whitelist) + { + addField(ConfigureNodeFields.children_association_whitelist, FormField.Type.jid_multi); + setAnswer(ConfigureNodeFields.children_association_whitelist.getFieldName(), whitelist); + } - /** - * Gets the maximum number of child nodes that can be associated with the collection node. - * - * @return The maximum number of child nodes - */ - public int getChildrenMax() - { - return Integer.parseInt(getFieldValue(ConfigureNodeFields.children_max)); - } + /** + * Gets the maximum number of child nodes that can be associated with the collection node. + * + * @return The maximum number of child nodes + */ + public int getChildrenMax() + { + return Integer.parseInt(getFieldValue(ConfigureNodeFields.children_max)); + } - /** - * Set the maximum number of child nodes that can be associated with a collection node. - * - * @param max The maximum number of child nodes. - */ - public void setChildrenMax(int max) - { - addField(ConfigureNodeFields.children_max, FormField.Type.text_single); - setAnswer(ConfigureNodeFields.children_max.getFieldName(), max); - } + /** + * Set the maximum number of child nodes that can be associated with a collection node. + * + * @param max The maximum number of child nodes. + */ + public void setChildrenMax(int max) + { + addField(ConfigureNodeFields.children_max, FormField.Type.text_single); + setAnswer(ConfigureNodeFields.children_max.getFieldName(), max); + } - /** - * Gets the collection node which the node is affiliated with. - * - * @return The collection node id - */ - public String getCollection() - { - return getFieldValue(ConfigureNodeFields.collection); - } + /** + * Gets the collection node which the node is affiliated with. + * + * @return The collection node id + */ + public String getCollection() + { + return getFieldValue(ConfigureNodeFields.collection); + } - /** - * Sets the collection node which the node is affiliated with. - * - * @param collection The node id of the collection node - */ - public void setCollection(String collection) - { - addField(ConfigureNodeFields.collection, FormField.Type.text_single); - setAnswer(ConfigureNodeFields.collection.getFieldName(), collection); - } + /** + * Sets the collection node which the node is affiliated with. + * + * @param collection The node id of the collection node + */ + public void setCollection(String collection) + { + addField(ConfigureNodeFields.collection, FormField.Type.text_single); + setAnswer(ConfigureNodeFields.collection.getFieldName(), collection); + } - /** - * Gets the URL of an XSL transformation which can be applied to the payload - * format in order to generate a valid Data Forms result that the client could - * display using a generic Data Forms rendering engine. - * - * @return The URL of an XSL transformation - */ - public String getDataformXSLT() - { - return getFieldValue(ConfigureNodeFields.dataform_xslt); - } + /** + * Gets the URL of an XSL transformation which can be applied to the payload + * format in order to generate a valid Data Forms result that the client could + * display using a generic Data Forms rendering engine. + * + * @return The URL of an XSL transformation + */ + public String getDataformXSLT() + { + return getFieldValue(ConfigureNodeFields.dataform_xslt); + } - /** - * Sets the URL of an XSL transformation which can be applied to the payload - * format in order to generate a valid Data Forms result that the client could - * display using a generic Data Forms rendering engine. - * - * @param url The URL of an XSL transformation - */ - public void setDataformXSLT(String url) - { - addField(ConfigureNodeFields.dataform_xslt, FormField.Type.text_single); - setAnswer(ConfigureNodeFields.dataform_xslt.getFieldName(), url); - } + /** + * Sets the URL of an XSL transformation which can be applied to the payload + * format in order to generate a valid Data Forms result that the client could + * display using a generic Data Forms rendering engine. + * + * @param url The URL of an XSL transformation + */ + public void setDataformXSLT(String url) + { + addField(ConfigureNodeFields.dataform_xslt, FormField.Type.text_single); + setAnswer(ConfigureNodeFields.dataform_xslt.getFieldName(), url); + } - /** - * Does the node deliver payloads with event notifications. - * - * @return true if it does, false otherwise - */ - public boolean isDeliverPayloads() - { - return parseBoolean(getFieldValue(ConfigureNodeFields.deliver_payloads)); - } + /** + * Does the node deliver payloads with event notifications. + * + * @return true if it does, false otherwise + */ + public boolean isDeliverPayloads() + { + return parseBoolean(getFieldValue(ConfigureNodeFields.deliver_payloads)); + } - /** - * Sets whether the node will deliver payloads with event notifications. - * - * @param deliver true if the payload will be delivered, false otherwise - */ - public void setDeliverPayloads(boolean deliver) - { - addField(ConfigureNodeFields.deliver_payloads, FormField.Type.bool); - setAnswer(ConfigureNodeFields.deliver_payloads.getFieldName(), deliver); - } + /** + * Sets whether the node will deliver payloads with event notifications. + * + * @param deliver true if the payload will be delivered, false otherwise + */ + public void setDeliverPayloads(boolean deliver) + { + addField(ConfigureNodeFields.deliver_payloads, FormField.Type.bool); + setAnswer(ConfigureNodeFields.deliver_payloads.getFieldName(), deliver); + } - /** - * Determines who should get replies to items. - * - * @return Who should get the reply - */ - public ItemReply getItemReply() - { - String value = getFieldValue(ConfigureNodeFields.itemreply); + /** + * Determines who should get replies to items. + * + * @return Who should get the reply + */ + public ItemReply getItemReply() + { + String value = getFieldValue(ConfigureNodeFields.itemreply); - if (value == null) - return null; - else - return ItemReply.valueOf(value); - } + if (value == null) + return null; + else + return ItemReply.valueOf(value); + } - /** - * Sets who should get the replies to items. - * - * @param reply Defines who should get the reply - */ - public void setItemReply(ItemReply reply) - { - addField(ConfigureNodeFields.itemreply, FormField.Type.list_single); - setAnswer(ConfigureNodeFields.itemreply.getFieldName(), getListSingle(reply.toString())); - } + /** + * Sets who should get the replies to items. + * + * @param reply Defines who should get the reply + */ + public void setItemReply(ItemReply reply) + { + addField(ConfigureNodeFields.itemreply, FormField.Type.list_single); + setAnswer(ConfigureNodeFields.itemreply.getFieldName(), getListSingle(reply.toString())); + } - /** - * Gets the maximum number of items to persisted to this node if {@link #isPersistItems()} is - * true. - * - * @return The maximum number of items to persist - */ - public int getMaxItems() - { - return Integer.parseInt(getFieldValue(ConfigureNodeFields.max_items)); - } + /** + * Gets the maximum number of items to persisted to this node if {@link #isPersistItems()} is + * true. + * + * @return The maximum number of items to persist + */ + public int getMaxItems() + { + return Integer.parseInt(getFieldValue(ConfigureNodeFields.max_items)); + } - /** - * Set the maximum number of items to persisted to this node if {@link #isPersistItems()} is - * true. - * - * @param max The maximum number of items to persist - */ - public void setMaxItems(int max) - { - addField(ConfigureNodeFields.max_items, FormField.Type.text_single); - setAnswer(ConfigureNodeFields.max_items.getFieldName(), max); - } + /** + * Set the maximum number of items to persisted to this node if {@link #isPersistItems()} is + * true. + * + * @param max The maximum number of items to persist + */ + public void setMaxItems(int max) + { + addField(ConfigureNodeFields.max_items, FormField.Type.text_single); + setAnswer(ConfigureNodeFields.max_items.getFieldName(), max); + } - /** - * Gets the maximum payload size in bytes. - * - * @return The maximum payload size - */ - public int getMaxPayloadSize() - { - return Integer.parseInt(getFieldValue(ConfigureNodeFields.max_payload_size)); - } + /** + * Gets the maximum payload size in bytes. + * + * @return The maximum payload size + */ + public int getMaxPayloadSize() + { + return Integer.parseInt(getFieldValue(ConfigureNodeFields.max_payload_size)); + } - /** - * Sets the maximum payload size in bytes. - * - * @param max The maximum payload size - */ - public void setMaxPayloadSize(int max) - { - addField(ConfigureNodeFields.max_payload_size, FormField.Type.text_single); - setAnswer(ConfigureNodeFields.max_payload_size.getFieldName(), max); - } + /** + * Sets the maximum payload size in bytes. + * + * @param max The maximum payload size + */ + public void setMaxPayloadSize(int max) + { + addField(ConfigureNodeFields.max_payload_size, FormField.Type.text_single); + setAnswer(ConfigureNodeFields.max_payload_size.getFieldName(), max); + } - /** - * Gets the node type. - * - * @return The node type - */ - public NodeType getNodeType() - { - String value = getFieldValue(ConfigureNodeFields.node_type); + /** + * Gets the node type. + * + * @return The node type + */ + public NodeType getNodeType() + { + String value = getFieldValue(ConfigureNodeFields.node_type); - if (value == null) - return null; - else - return NodeType.valueOf(value); - } + if (value == null) + return null; + else + return NodeType.valueOf(value); + } - /** - * Sets the node type. - * - * @param type The node type - */ - public void setNodeType(NodeType type) - { - addField(ConfigureNodeFields.node_type, FormField.Type.list_single); - setAnswer(ConfigureNodeFields.node_type.getFieldName(), getListSingle(type.toString())); - } + /** + * Sets the node type. + * + * @param type The node type + */ + public void setNodeType(NodeType type) + { + addField(ConfigureNodeFields.node_type, FormField.Type.list_single); + setAnswer(ConfigureNodeFields.node_type.getFieldName(), getListSingle(type.toString())); + } - /** - * Determines if subscribers should be notified when the configuration changes. - * - * @return true if they should be notified, false otherwise - */ - public boolean isNotifyConfig() - { - return parseBoolean(getFieldValue(ConfigureNodeFields.notify_config)); - } + /** + * Determines if subscribers should be notified when the configuration changes. + * + * @return true if they should be notified, false otherwise + */ + public boolean isNotifyConfig() + { + return parseBoolean(getFieldValue(ConfigureNodeFields.notify_config)); + } - /** - * Sets whether subscribers should be notified when the configuration changes. - * - * @param notify true if subscribers should be notified, false otherwise - */ - public void setNotifyConfig(boolean notify) - { - addField(ConfigureNodeFields.notify_config, FormField.Type.bool); - setAnswer(ConfigureNodeFields.notify_config.getFieldName(), notify); - } + /** + * Sets whether subscribers should be notified when the configuration changes. + * + * @param notify true if subscribers should be notified, false otherwise + */ + public void setNotifyConfig(boolean notify) + { + addField(ConfigureNodeFields.notify_config, FormField.Type.bool); + setAnswer(ConfigureNodeFields.notify_config.getFieldName(), notify); + } - /** - * Determines whether subscribers should be notified when the node is deleted. - * - * @return true if subscribers should be notified, false otherwise - */ - public boolean isNotifyDelete() - { - return parseBoolean(getFieldValue(ConfigureNodeFields.notify_delete)); - } + /** + * Determines whether subscribers should be notified when the node is deleted. + * + * @return true if subscribers should be notified, false otherwise + */ + public boolean isNotifyDelete() + { + return parseBoolean(getFieldValue(ConfigureNodeFields.notify_delete)); + } - /** - * Sets whether subscribers should be notified when the node is deleted. - * - * @param notify true if subscribers should be notified, false otherwise - */ - public void setNotifyDelete(boolean notify) - { - addField(ConfigureNodeFields.notify_delete, FormField.Type.bool); - setAnswer(ConfigureNodeFields.notify_delete.getFieldName(), notify); - } + /** + * Sets whether subscribers should be notified when the node is deleted. + * + * @param notify true if subscribers should be notified, false otherwise + */ + public void setNotifyDelete(boolean notify) + { + addField(ConfigureNodeFields.notify_delete, FormField.Type.bool); + setAnswer(ConfigureNodeFields.notify_delete.getFieldName(), notify); + } - /** - * Determines whether subscribers should be notified when items are deleted - * from the node. - * - * @return true if subscribers should be notified, false otherwise - */ - public boolean isNotifyRetract() - { - return parseBoolean(getFieldValue(ConfigureNodeFields.notify_retract)); - } + /** + * Determines whether subscribers should be notified when items are deleted + * from the node. + * + * @return true if subscribers should be notified, false otherwise + */ + public boolean isNotifyRetract() + { + return parseBoolean(getFieldValue(ConfigureNodeFields.notify_retract)); + } - /** - * Sets whether subscribers should be notified when items are deleted - * from the node. - * - * @param notify true if subscribers should be notified, false otherwise - */ - public void setNotifyRetract(boolean notify) - { - addField(ConfigureNodeFields.notify_retract, FormField.Type.bool); - setAnswer(ConfigureNodeFields.notify_retract.getFieldName(), notify); - } + /** + * Sets whether subscribers should be notified when items are deleted + * from the node. + * + * @param notify true if subscribers should be notified, false otherwise + */ + public void setNotifyRetract(boolean notify) + { + addField(ConfigureNodeFields.notify_retract, FormField.Type.bool); + setAnswer(ConfigureNodeFields.notify_retract.getFieldName(), notify); + } - /** - * Determines whether items should be persisted in the node. - * - * @return true if items are persisted - */ - public boolean isPersistItems() - { - return parseBoolean(getFieldValue(ConfigureNodeFields.persist_items)); - } + /** + * Determines whether items should be persisted in the node. + * + * @return true if items are persisted + */ + public boolean isPersistItems() + { + return parseBoolean(getFieldValue(ConfigureNodeFields.persist_items)); + } - /** - * Sets whether items should be persisted in the node. - * - * @param persist true if items should be persisted, false otherwise - */ - public void setPersistentItems(boolean persist) - { - addField(ConfigureNodeFields.persist_items, FormField.Type.bool); - setAnswer(ConfigureNodeFields.persist_items.getFieldName(), persist); - } + /** + * Sets whether items should be persisted in the node. + * + * @param persist true if items should be persisted, false otherwise + */ + public void setPersistentItems(boolean persist) + { + addField(ConfigureNodeFields.persist_items, FormField.Type.bool); + setAnswer(ConfigureNodeFields.persist_items.getFieldName(), persist); + } - /** - * Determines whether to deliver notifications to available users only. - * - * @return true if users must be available - */ - public boolean isPresenceBasedDelivery() - { - return parseBoolean(getFieldValue(ConfigureNodeFields.presence_based_delivery)); - } + /** + * Determines whether to deliver notifications to available users only. + * + * @return true if users must be available + */ + public boolean isPresenceBasedDelivery() + { + return parseBoolean(getFieldValue(ConfigureNodeFields.presence_based_delivery)); + } - /** - * Sets whether to deliver notifications to available users only. - * - * @param presenceBased true if user must be available, false otherwise - */ - public void setPresenceBasedDelivery(boolean presenceBased) - { - addField(ConfigureNodeFields.presence_based_delivery, FormField.Type.bool); - setAnswer(ConfigureNodeFields.presence_based_delivery.getFieldName(), presenceBased); - } + /** + * Sets whether to deliver notifications to available users only. + * + * @param presenceBased true if user must be available, false otherwise + */ + public void setPresenceBasedDelivery(boolean presenceBased) + { + addField(ConfigureNodeFields.presence_based_delivery, FormField.Type.bool); + setAnswer(ConfigureNodeFields.presence_based_delivery.getFieldName(), presenceBased); + } - /** - * Gets the publishing model for the node, which determines who may publish to it. - * - * @return The publishing model - */ - public PublishModel getPublishModel() - { - String value = getFieldValue(ConfigureNodeFields.publish_model); + /** + * Gets the publishing model for the node, which determines who may publish to it. + * + * @return The publishing model + */ + public PublishModel getPublishModel() + { + String value = getFieldValue(ConfigureNodeFields.publish_model); - if (value == null) - return null; - else - return PublishModel.valueOf(value); - } + if (value == null) + return null; + else + return PublishModel.valueOf(value); + } - /** - * Sets the publishing model for the node, which determines who may publish to it. - * - * @param publish The enum representing the possible options for the publishing model - */ - public void setPublishModel(PublishModel publish) - { - addField(ConfigureNodeFields.publish_model, FormField.Type.list_single); - setAnswer(ConfigureNodeFields.publish_model.getFieldName(), getListSingle(publish.toString())); - } + /** + * Sets the publishing model for the node, which determines who may publish to it. + * + * @param publish The enum representing the possible options for the publishing model + */ + public void setPublishModel(PublishModel publish) + { + addField(ConfigureNodeFields.publish_model, FormField.Type.list_single); + setAnswer(ConfigureNodeFields.publish_model.getFieldName(), getListSingle(publish.toString())); + } - /** - * List of the multi user chat rooms that are specified as reply rooms. - * - * @return The reply room JID's - */ - public List getReplyRoom() - { - return getFieldValues(ConfigureNodeFields.replyroom); - } + /** + * List of the multi user chat rooms that are specified as reply rooms. + * + * @return The reply room JID's + */ + public List getReplyRoom() + { + return getFieldValues(ConfigureNodeFields.replyroom); + } - /** - * Sets the multi user chat rooms that are specified as reply rooms. - * - * @param replyRooms The multi user chat room to use as reply rooms - */ - public void setReplyRoom(List replyRooms) - { - addField(ConfigureNodeFields.replyroom, FormField.Type.list_multi); - setAnswer(ConfigureNodeFields.replyroom.getFieldName(), replyRooms); - } + /** + * Sets the multi user chat rooms that are specified as reply rooms. + * + * @param replyRooms The multi user chat room to use as reply rooms + */ + public void setReplyRoom(List replyRooms) + { + addField(ConfigureNodeFields.replyroom, FormField.Type.list_multi); + setAnswer(ConfigureNodeFields.replyroom.getFieldName(), replyRooms); + } - /** - * Gets the specific JID's for reply to. - * - * @return The JID's - */ - public List getReplyTo() - { - return getFieldValues(ConfigureNodeFields.replyto); - } + /** + * Gets the specific JID's for reply to. + * + * @return The JID's + */ + public List getReplyTo() + { + return getFieldValues(ConfigureNodeFields.replyto); + } - /** - * Sets the specific JID's for reply to. - * - * @param replyTos The JID's to reply to - */ - public void setReplyTo(List replyTos) - { - addField(ConfigureNodeFields.replyto, FormField.Type.list_multi); - setAnswer(ConfigureNodeFields.replyto.getFieldName(), replyTos); - } + /** + * Sets the specific JID's for reply to. + * + * @param replyTos The JID's to reply to + */ + public void setReplyTo(List replyTos) + { + addField(ConfigureNodeFields.replyto, FormField.Type.list_multi); + setAnswer(ConfigureNodeFields.replyto.getFieldName(), replyTos); + } - /** - * Gets the roster groups that are allowed to subscribe and retrieve items. - * - * @return The roster groups - */ - public List getRosterGroupsAllowed() - { - return getFieldValues(ConfigureNodeFields.roster_groups_allowed); - } + /** + * Gets the roster groups that are allowed to subscribe and retrieve items. + * + * @return The roster groups + */ + public List getRosterGroupsAllowed() + { + return getFieldValues(ConfigureNodeFields.roster_groups_allowed); + } - /** - * Sets the roster groups that are allowed to subscribe and retrieve items. - * - * @param groups The roster groups - */ - public void setRosterGroupsAllowed(List groups) - { - addField(ConfigureNodeFields.roster_groups_allowed, FormField.Type.list_multi); - setAnswer(ConfigureNodeFields.roster_groups_allowed.getFieldName(), groups); - } + /** + * Sets the roster groups that are allowed to subscribe and retrieve items. + * + * @param groups The roster groups + */ + public void setRosterGroupsAllowed(List groups) + { + addField(ConfigureNodeFields.roster_groups_allowed, FormField.Type.list_multi); + setAnswer(ConfigureNodeFields.roster_groups_allowed.getFieldName(), groups); + } - /** - * Determines if subscriptions are allowed. - * - * @return true if subscriptions are allowed, false otherwise - * @deprecated use {@link #isSubscribe()} instead - */ - @Deprecated - public boolean isSubscibe() - { - return isSubscribe(); - } + /** + * Determines if subscriptions are allowed. + * + * @return true if subscriptions are allowed, false otherwise + * @deprecated use {@link #isSubscribe()} instead + */ + @Deprecated + public boolean isSubscibe() + { + return isSubscribe(); + } /** * Determines if subscriptions are allowed. @@ -594,124 +594,124 @@ public class ConfigureForm extends Form return parseBoolean(getFieldValue(ConfigureNodeFields.subscribe)); } - /** - * Sets whether subscriptions are allowed. - * - * @param subscribe true if they are, false otherwise - */ - public void setSubscribe(boolean subscribe) - { - addField(ConfigureNodeFields.subscribe, FormField.Type.bool); - setAnswer(ConfigureNodeFields.subscribe.getFieldName(), subscribe); - } + /** + * Sets whether subscriptions are allowed. + * + * @param subscribe true if they are, false otherwise + */ + public void setSubscribe(boolean subscribe) + { + addField(ConfigureNodeFields.subscribe, FormField.Type.bool); + setAnswer(ConfigureNodeFields.subscribe.getFieldName(), subscribe); + } - /** - * Gets the human readable node title. - * - * @return The node title - */ - public String getTitle() - { - return getFieldValue(ConfigureNodeFields.title); - } + /** + * Gets the human readable node title. + * + * @return The node title + */ + public String getTitle() + { + return getFieldValue(ConfigureNodeFields.title); + } - /** - * Sets a human readable title for the node. - * - * @param title The node title - */ - public void setTitle(String title) - { - addField(ConfigureNodeFields.title, FormField.Type.text_single); - setAnswer(ConfigureNodeFields.title.getFieldName(), title); - } + /** + * Sets a human readable title for the node. + * + * @param title The node title + */ + public void setTitle(String title) + { + addField(ConfigureNodeFields.title, FormField.Type.text_single); + setAnswer(ConfigureNodeFields.title.getFieldName(), title); + } - /** - * The type of node data, usually specified by the namespace of the payload (if any). - * - * @return The type of node data - */ - public String getDataType() - { - return getFieldValue(ConfigureNodeFields.type); - } + /** + * The type of node data, usually specified by the namespace of the payload (if any). + * + * @return The type of node data + */ + public String getDataType() + { + return getFieldValue(ConfigureNodeFields.type); + } - /** - * Sets the type of node data, usually specified by the namespace of the payload (if any). - * - * @param type The type of node data - */ - public void setDataType(String type) - { - addField(ConfigureNodeFields.type, FormField.Type.text_single); - setAnswer(ConfigureNodeFields.type.getFieldName(), type); - } + /** + * Sets the type of node data, usually specified by the namespace of the payload (if any). + * + * @param type The type of node data + */ + public void setDataType(String type) + { + addField(ConfigureNodeFields.type, FormField.Type.text_single); + setAnswer(ConfigureNodeFields.type.getFieldName(), type); + } - @Override - public String toString() - { - StringBuilder result = new StringBuilder(getClass().getName() + " Content ["); + @Override + public String toString() + { + StringBuilder result = new StringBuilder(getClass().getName() + " Content ["); - for (FormField formField : getFields()) - { - result.append('('); - result.append(formField.getVariable()); - result.append(':'); + for (FormField formField : getFields()) + { + result.append('('); + result.append(formField.getVariable()); + result.append(':'); - StringBuilder valuesBuilder = new StringBuilder(); + StringBuilder valuesBuilder = new StringBuilder(); - for (String value : formField.getValues()) - { - if (valuesBuilder.length() > 0) - result.append(','); - valuesBuilder.append(value); - } + for (String value : formField.getValues()) + { + if (valuesBuilder.length() > 0) + result.append(','); + valuesBuilder.append(value); + } - if (valuesBuilder.length() == 0) - valuesBuilder.append("NOT SET"); - result.append(valuesBuilder); - result.append(')'); - } - result.append(']'); - return result.toString(); - } + if (valuesBuilder.length() == 0) + valuesBuilder.append("NOT SET"); + result.append(valuesBuilder); + result.append(')'); + } + result.append(']'); + return result.toString(); + } - static private boolean parseBoolean(String fieldValue) - { - return ("1".equals(fieldValue) || "true".equals(fieldValue)); - } + static private boolean parseBoolean(String fieldValue) + { + return ("1".equals(fieldValue) || "true".equals(fieldValue)); + } - private String getFieldValue(ConfigureNodeFields field) - { - FormField formField = getField(field.getFieldName()); + private String getFieldValue(ConfigureNodeFields field) + { + FormField formField = getField(field.getFieldName()); - return (formField.getValues().isEmpty()) ? null : formField.getValues().get(0); - } + return (formField.getValues().isEmpty()) ? null : formField.getValues().get(0); + } - private List getFieldValues(ConfigureNodeFields field) - { - FormField formField = getField(field.getFieldName()); + private List getFieldValues(ConfigureNodeFields field) + { + FormField formField = getField(field.getFieldName()); - return formField.getValues(); - } + return formField.getValues(); + } - private void addField(ConfigureNodeFields nodeField, FormField.Type type) - { - String fieldName = nodeField.getFieldName(); + private void addField(ConfigureNodeFields nodeField, FormField.Type type) + { + String fieldName = nodeField.getFieldName(); - if (getField(fieldName) == null) - { - FormField field = new FormField(fieldName); - field.setType(type); - addField(field); - } - } + if (getField(fieldName) == null) + { + FormField field = new FormField(fieldName); + field.setType(type); + addField(field); + } + } - private static List getListSingle(String value) - { - List list = new ArrayList(1); - list.add(value); - return list; - } + private static List getListSingle(String value) + { + List list = new ArrayList(1); + list.add(value); + return list; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureNodeFields.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureNodeFields.java index 7a3797a6a..47d01b80a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureNodeFields.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureNodeFields.java @@ -29,193 +29,193 @@ import org.jivesoftware.smackx.xdata.Form; */ public enum ConfigureNodeFields { - /** - * Determines who may subscribe and retrieve items. - * - *

Value: {@link AccessModel}

- */ - access_model, + /** + * Determines who may subscribe and retrieve items. + * + *

Value: {@link AccessModel}

+ */ + access_model, - /** - * The URL of an XSL transformation which can be applied to - * payloads in order to generate an appropriate message - * body element. - * - *

Value: {@link URL}

- */ - body_xslt, + /** + * The URL of an XSL transformation which can be applied to + * payloads in order to generate an appropriate message + * body element. + * + *

Value: {@link URL}

+ */ + body_xslt, - /** - * The collection with which a node is affiliated. - * - *

Value: String

- */ - collection, + /** + * The collection with which a node is affiliated. + * + *

Value: String

+ */ + collection, - /** - * The URL of an XSL transformation which can be applied to - * payload format in order to generate a valid Data Forms result - * that the client could display using a generic Data Forms - * rendering engine body element. - * - *

Value: {@link URL}

- */ - dataform_xslt, + /** + * The URL of an XSL transformation which can be applied to + * payload format in order to generate a valid Data Forms result + * that the client could display using a generic Data Forms + * rendering engine body element. + * + *

Value: {@link URL}

+ */ + dataform_xslt, - /** - * Whether to deliver payloads with event notifications. - * - *

Value: boolean

- */ - deliver_payloads, + /** + * Whether to deliver payloads with event notifications. + * + *

Value: boolean

+ */ + deliver_payloads, - /** - * Whether owners or publisher should receive replies to items. - * - *

Value: {@link ItemReply}

- */ - itemreply, + /** + * Whether owners or publisher should receive replies to items. + * + *

Value: {@link ItemReply}

+ */ + itemreply, - /** - * Who may associate leaf nodes with a collection. - * - *

Value: {@link ChildrenAssociationPolicy}

- */ - children_association_policy, + /** + * Who may associate leaf nodes with a collection. + * + *

Value: {@link ChildrenAssociationPolicy}

+ */ + children_association_policy, - /** - * The list of JIDs that may associate leaf nodes with a - * collection. - * - *

Value: List of JIDs as Strings

- */ - children_association_whitelist, + /** + * The list of JIDs that may associate leaf nodes with a + * collection. + * + *

Value: List of JIDs as Strings

+ */ + children_association_whitelist, - /** - * The child nodes (leaf or collection) associated with a collection. - * - *

Value: List of Strings

- */ - children, + /** + * The child nodes (leaf or collection) associated with a collection. + * + *

Value: List of Strings

+ */ + children, - /** - * The maximum number of child nodes that can be associated with a - * collection. - * - *

Value: int

- */ - children_max, + /** + * The maximum number of child nodes that can be associated with a + * collection. + * + *

Value: int

+ */ + children_max, - /** - * The maximum number of items to persist. - * - *

Value: int

- */ - max_items, + /** + * The maximum number of items to persist. + * + *

Value: int

+ */ + max_items, - /** - * The maximum payload size in bytes. - * - *

Value: int

- */ - max_payload_size, + /** + * The maximum payload size in bytes. + * + *

Value: int

+ */ + max_payload_size, - /** - * Whether the node is a leaf (default) or collection. - * - *

Value: {@link NodeType}

- */ - node_type, + /** + * Whether the node is a leaf (default) or collection. + * + *

Value: {@link NodeType}

+ */ + node_type, - /** - * Whether to notify subscribers when the node configuration changes. - * - *

Value: boolean

- */ - notify_config, + /** + * Whether to notify subscribers when the node configuration changes. + * + *

Value: boolean

+ */ + notify_config, - /** - * Whether to notify subscribers when the node is deleted. - * - *

Value: boolean

- */ - notify_delete, + /** + * Whether to notify subscribers when the node is deleted. + * + *

Value: boolean

+ */ + notify_delete, - /** - * Whether to notify subscribers when items are removed from the node. - * - *

Value: boolean

- */ - notify_retract, + /** + * Whether to notify subscribers when items are removed from the node. + * + *

Value: boolean

+ */ + notify_retract, - /** - * Whether to persist items to storage. This is required to have. multiple - * items in the node. - * - *

Value: boolean

- */ - persist_items, + /** + * Whether to persist items to storage. This is required to have. multiple + * items in the node. + * + *

Value: boolean

+ */ + persist_items, - /** - * Whether to deliver notifications to available users only. - * - *

Value: boolean

- */ - presence_based_delivery, + /** + * Whether to deliver notifications to available users only. + * + *

Value: boolean

+ */ + presence_based_delivery, - /** - * Defines who can publish to the node. - * - *

Value: {@link PublishModel}

- */ - publish_model, + /** + * Defines who can publish to the node. + * + *

Value: {@link PublishModel}

+ */ + publish_model, - /** - * The specific multi-user chat rooms to specify for replyroom. - * - *

Value: List of JIDs as Strings

- */ - replyroom, + /** + * The specific multi-user chat rooms to specify for replyroom. + * + *

Value: List of JIDs as Strings

+ */ + replyroom, - /** - * The specific JID(s) to specify for replyto. - * - *

Value: List of JIDs as Strings

- */ - replyto, + /** + * The specific JID(s) to specify for replyto. + * + *

Value: List of JIDs as Strings

+ */ + replyto, - /** - * The roster group(s) allowed to subscribe and retrieve items. - * - *

Value: List of strings

- */ - roster_groups_allowed, + /** + * The roster group(s) allowed to subscribe and retrieve items. + * + *

Value: List of strings

+ */ + roster_groups_allowed, - /** - * Whether to allow subscriptions. - * - *

Value: boolean

- */ - subscribe, + /** + * Whether to allow subscriptions. + * + *

Value: boolean

+ */ + subscribe, - /** - * A friendly name for the node. - * - *

Value: String

- */ - title, + /** + * A friendly name for the node. + * + *

Value: String

+ */ + title, - /** - * The type of node data, ussually specified by the namespace - * of the payload(if any);MAY be a list-single rather than a - * text single. - * - *

Value: String

- */ - type; + /** + * The type of node data, ussually specified by the namespace + * of the payload(if any);MAY be a list-single rather than a + * text single. + * + *

Value: String

+ */ + type; - public String getFieldName() - { - return "pubsub#" + toString(); - } + public String getFieldName() + { + return "pubsub#" + toString(); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EmbeddedPacketExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EmbeddedPacketExtension.java index b32a6e637..841a20cd8 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EmbeddedPacketExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EmbeddedPacketExtension.java @@ -39,10 +39,10 @@ import org.jivesoftware.smack.util.PacketParserUtils; */ public interface EmbeddedPacketExtension extends ExtensionElement { - /** - * Get the list of embedded {@link ExtensionElement} objects. - * - * @return List of embedded {@link ExtensionElement} - */ - List getExtensions(); + /** + * Get the list of embedded {@link ExtensionElement} objects. + * + * @return List of embedded {@link ExtensionElement} + */ + List getExtensions(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElement.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElement.java index cca9c2ae2..987fb4c14 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElement.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElement.java @@ -44,39 +44,39 @@ public class EventElement implements EmbeddedPacketExtension */ public static final String NAMESPACE = PubSubNamespace.EVENT.getXmlns(); - private EventElementType type; - private NodeExtension ext; + private EventElementType type; + private NodeExtension ext; - public EventElement(EventElementType eventType, NodeExtension eventExt) - { - type = eventType; - ext = eventExt; - } + public EventElement(EventElementType eventType, NodeExtension eventExt) + { + type = eventType; + ext = eventExt; + } - public EventElementType getEventType() - { - return type; - } + public EventElementType getEventType() + { + return type; + } - public List getExtensions() - { - return Arrays.asList(new ExtensionElement[]{getEvent()}); - } + public List getExtensions() + { + return Arrays.asList(new ExtensionElement[]{getEvent()}); + } - public NodeExtension getEvent() - { - return ext; - } + public NodeExtension getEvent() + { + return ext; + } - public String getElementName() - { - return "event"; - } + public String getElementName() + { + return "event"; + } - public String getNamespace() - { - return PubSubNamespace.EVENT.getXmlns(); - } + public String getNamespace() + { + return PubSubNamespace.EVENT.getXmlns(); + } @Override public XmlStringBuilder toXML() { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElementType.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElementType.java index e02de606b..0850e7d92 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElementType.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/EventElementType.java @@ -24,21 +24,21 @@ package org.jivesoftware.smackx.pubsub; */ public enum EventElementType { - /** A node has been associated or dissassociated with a collection node. */ - collection, + /** A node has been associated or dissassociated with a collection node. */ + collection, - /** A node has had its configuration changed. */ - configuration, + /** A node has had its configuration changed. */ + configuration, - /** A node has been deleted. */ - delete, + /** A node has been deleted. */ + delete, - /** Items have been published to a node. */ - items, + /** Items have been published to a node. */ + items, - /** All items have been purged from a node. */ - purge, + /** All items have been purged from a node. */ + purge, - /** A node has been subscribed to. */ - subscription + /** A node has been subscribed to. */ + subscription } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/FormNode.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/FormNode.java index 6be866197..5940c6aaf 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/FormNode.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/FormNode.java @@ -28,75 +28,75 @@ import org.jivesoftware.smackx.xdata.Form; */ public class FormNode extends NodeExtension { - private Form configForm; + private Form configForm; - /** - * Create a {@link FormNode} which contains the specified form. - * - * @param formType The type of form being sent - * @param submitForm The form - */ - public FormNode(FormNodeType formType, Form submitForm) - { - super(formType.getNodeElement()); + /** + * Create a {@link FormNode} which contains the specified form. + * + * @param formType The type of form being sent + * @param submitForm The form + */ + public FormNode(FormNodeType formType, Form submitForm) + { + super(formType.getNodeElement()); - if (submitForm == null) - throw new IllegalArgumentException("Submit form cannot be null"); - configForm = submitForm; - } + if (submitForm == null) + throw new IllegalArgumentException("Submit form cannot be null"); + configForm = submitForm; + } - /** - * Create a {@link FormNode} which contains the specified form, which is - * associated with the specified node. - * - * @param formType The type of form being sent - * @param nodeId The node the form is associated with - * @param submitForm The form - */ - public FormNode(FormNodeType formType, String nodeId, Form submitForm) - { - super(formType.getNodeElement(), nodeId); + /** + * Create a {@link FormNode} which contains the specified form, which is + * associated with the specified node. + * + * @param formType The type of form being sent + * @param nodeId The node the form is associated with + * @param submitForm The form + */ + public FormNode(FormNodeType formType, String nodeId, Form submitForm) + { + super(formType.getNodeElement(), nodeId); - if (submitForm == null) - throw new IllegalArgumentException("Submit form cannot be null"); - configForm = submitForm; - } + if (submitForm == null) + throw new IllegalArgumentException("Submit form cannot be null"); + configForm = submitForm; + } - /** - * Get the Form that is to be sent, or was retrieved from the server. - * - * @return The form - */ - public Form getForm() - { - return configForm; - } + /** + * Get the Form that is to be sent, or was retrieved from the server. + * + * @return The form + */ + public Form getForm() + { + return configForm; + } - @Override - public CharSequence toXML() - { - if (configForm == null) - { - return super.toXML(); - } - else - { - StringBuilder builder = new StringBuilder("<"); - builder.append(getElementName()); + @Override + public CharSequence toXML() + { + if (configForm == null) + { + return super.toXML(); + } + else + { + StringBuilder builder = new StringBuilder("<"); + builder.append(getElementName()); - if (getNode() != null) - { - builder.append(" node='"); - builder.append(getNode()); - builder.append("'>"); - } - else - builder.append('>'); - builder.append(configForm.getDataFormToSend().toXML()); - builder.append("'); - return builder.toString(); - } - } + if (getNode() != null) + { + builder.append(" node='"); + builder.append(getNode()); + builder.append("'>"); + } + else + builder.append('>'); + builder.append(configForm.getDataFormToSend().toXML()); + builder.append("'); + return builder.toString(); + } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/FormNodeType.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/FormNodeType.java index 95532f5fb..c8bed54c4 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/FormNodeType.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/FormNodeType.java @@ -27,29 +27,29 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace; */ public enum FormNodeType { - /** Form for configuring an existing node. */ - CONFIGURE_OWNER, + /** Form for configuring an existing node. */ + CONFIGURE_OWNER, - /** Form for configuring a node during creation. */ - CONFIGURE, + /** Form for configuring a node during creation. */ + CONFIGURE, - /** Form for configuring subscription options. */ - OPTIONS, + /** Form for configuring subscription options. */ + OPTIONS, - /** Form which represents the default node configuration options. */ - DEFAULT; + /** Form which represents the default node configuration options. */ + DEFAULT; - public PubSubElementType getNodeElement() - { - return PubSubElementType.valueOf(toString()); - } + public PubSubElementType getNodeElement() + { + return PubSubElementType.valueOf(toString()); + } - 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)); - } + 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)); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/GetItemsRequest.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/GetItemsRequest.java index 1d29ab1e2..05b94b716 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/GetItemsRequest.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/GetItemsRequest.java @@ -25,42 +25,42 @@ import org.jivesoftware.smack.util.XmlStringBuilder; */ public class GetItemsRequest extends NodeExtension { - protected final String subId; - protected final int maxItems; + protected final String subId; + protected final int maxItems; - public GetItemsRequest(String nodeId) - { - this(nodeId, null, -1); - } + 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; - } + subId = subscriptionId; + } - public String getSubscriptionId() - { - return subId; - } + public String getSubscriptionId() + { + return subId; + } - public int getMaxItems() - { - return maxItems; - } + public int getMaxItems() + { + return maxItems; + } - @Override + @Override public XmlStringBuilder toXML() { XmlStringBuilder xml = new XmlStringBuilder(); xml.halfOpenElement(getElementName()); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Item.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Item.java index 177f222d3..0e5eac49d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Item.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Item.java @@ -50,94 +50,92 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider; */ public class Item extends NodeExtension { - private String id; + private String id; - /** - * Create an empty Item with no id. This is a valid item for nodes which are configured - * so that {@link ConfigureForm#isDeliverPayloads()} is false. In most cases an id will be generated by the server. - * For nodes configured with {@link ConfigureForm#isDeliverPayloads()} and {@link ConfigureForm#isPersistItems()} - * set to false, no Item is sent to the node, you have to use {@link LeafNode#send()} or {@link LeafNode#publish()} - * methods in this case. - */ - public Item() - { - super(PubSubElementType.ITEM); - } - - /** - * Create an Item with an id but no payload. This is a valid item for nodes which are configured - * so that {@link ConfigureForm#isDeliverPayloads()} is false. - * - * @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) - { - // The element type is actually irrelevant since we override getNamespace() to return null - super(PubSubElementType.ITEM); - id = itemId; - } - - /** - * Create an Item with an id and a node id. - *

- * Note: This is not valid for publishing an item to a node, only receiving from - * one as part of {@link Message}. If used to create an Item to publish - * (via {@link LeafNode#publish(Item)}, the server may return an - * error for an invalid packet. - * - * @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) + /** + * Create an empty Item with no id. This is a valid item for nodes which are configured + * so that {@link ConfigureForm#isDeliverPayloads()} is false. In most cases an id will be generated by the server. + * For nodes configured with {@link ConfigureForm#isDeliverPayloads()} and {@link ConfigureForm#isPersistItems()} + * set to false, no Item is sent to the node, you have to use {@link LeafNode#send()} or {@link LeafNode#publish()} + * methods in this case. + */ + public Item() { - // CHECKSTYLE:OFF - super(PubSubElementType.ITEM_EVENT, nodeId); - // CHECKSTYLE:ON + super(PubSubElementType.ITEM); + } + + /** + * Create an Item with an id but no payload. This is a valid item for nodes which are configured + * so that {@link ConfigureForm#isDeliverPayloads()} is false. + * + * @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) + { + // The element type is actually irrelevant since we override getNamespace() to return null + super(PubSubElementType.ITEM); id = itemId; } - /** - * Get the item id. Unique to the node it is associated with. - * - * @return The id - */ - public String getId() - { - return id; - } + /** + * Create an Item with an id and a node id. + *

+ * Note: This is not valid for publishing an item to a node, only receiving from + * one as part of {@link Message}. If used to create an Item to publish + * (via {@link LeafNode#publish(Item)}, the server may return an + * error for an invalid packet. + * + * @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) + { + super(PubSubElementType.ITEM_EVENT, nodeId); + id = itemId; + } - @Override - public String getNamespace() - { - return null; - } + /** + * Get the item id. Unique to the node it is associated with. + * + * @return The id + */ + public String getId() + { + return id; + } - @Override - public String toXML() - { - StringBuilder builder = new StringBuilder(""); + builder.append("/>"); - return builder.toString(); - } + return builder.toString(); + } - @Override - public String toString() - { - return getClass().getName() + " | Content [" + toXML() + "]"; - } + @Override + public String toString() + { + return getClass().getName() + " | Content [" + toXML() + "]"; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemDeleteEvent.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemDeleteEvent.java index 4bfbe30d6..d2fbf1b18 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemDeleteEvent.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemDeleteEvent.java @@ -26,40 +26,40 @@ import java.util.List; */ public class ItemDeleteEvent extends SubscriptionEvent { - private List itemIds = Collections.emptyList(); + private List itemIds = Collections.emptyList(); - /** - * Constructs an ItemDeleteEvent that indicates the the supplied - * items (by id) have been deleted, and that the event matches the listed - * subscriptions. The subscriptions would have been created by calling - * {@link LeafNode#subscribe(String)}. - * - * @param nodeId The id of the node the event came from - * @param deletedItemIds The item ids of the items that were deleted. - * @param subscriptionIds The subscriptions that match the event. - */ - public ItemDeleteEvent(String nodeId, List deletedItemIds, List subscriptionIds) - { - super(nodeId, subscriptionIds); + /** + * Constructs an ItemDeleteEvent that indicates the the supplied + * items (by id) have been deleted, and that the event matches the listed + * subscriptions. The subscriptions would have been created by calling + * {@link LeafNode#subscribe(String)}. + * + * @param nodeId The id of the node the event came from + * @param deletedItemIds The item ids of the items that were deleted. + * @param subscriptionIds The subscriptions that match the event. + */ + public ItemDeleteEvent(String nodeId, List deletedItemIds, List subscriptionIds) + { + super(nodeId, subscriptionIds); - if (deletedItemIds == null) - throw new IllegalArgumentException("deletedItemIds cannot be null"); - itemIds = deletedItemIds; - } + if (deletedItemIds == null) + throw new IllegalArgumentException("deletedItemIds cannot be null"); + itemIds = deletedItemIds; + } - /** - * Get the item id's of the items that have been deleted. - * - * @return List of item id's - */ - public List getItemIds() - { - return Collections.unmodifiableList(itemIds); - } + /** + * Get the item id's of the items that have been deleted. + * + * @return List of item id's + */ + public List getItemIds() + { + return Collections.unmodifiableList(itemIds); + } - @Override - public String toString() - { - return getClass().getName() + " [subscriptions: " + getSubscriptions() + "], [Deleted Items: " + itemIds + ']'; - } + @Override + public String toString() + { + return getClass().getName() + " [subscriptions: " + getSubscriptions() + "], [Deleted Items: " + itemIds + ']'; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemPublishEvent.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemPublishEvent.java index ed49eb2fb..980797bdb 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemPublishEvent.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemPublishEvent.java @@ -27,98 +27,98 @@ import java.util.List; */ public class ItemPublishEvent extends SubscriptionEvent { - private List items; - private Date originalDate; + private List items; + private Date originalDate; - /** - * Constructs an ItemPublishEvent with the provided list - * of {@link Item} that were published. - * - * @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 eventItems) - { - super(nodeId); - items = eventItems; - } + /** + * Constructs an ItemPublishEvent with the provided list + * of {@link Item} that were published. + * + * @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 eventItems) + { + super(nodeId); + items = eventItems; + } - /** - * Constructs an ItemPublishEvent with the provided list - * of {@link Item} that were published. The list of subscription ids - * represents the subscriptions that matched the event, in the case - * of the user having multiple subscriptions. - * - * @param nodeId The id of the node the event came from - * @param eventItems The list of {@link Item} that were published - * @param subscriptionIds The list of subscriptionIds - */ - public ItemPublishEvent(String nodeId, List eventItems, List subscriptionIds) - { - super(nodeId, subscriptionIds); - items = eventItems; - } + /** + * Constructs an ItemPublishEvent with the provided list + * of {@link Item} that were published. The list of subscription ids + * represents the subscriptions that matched the event, in the case + * of the user having multiple subscriptions. + * + * @param nodeId The id of the node the event came from + * @param eventItems The list of {@link Item} that were published + * @param subscriptionIds The list of subscriptionIds + */ + public ItemPublishEvent(String nodeId, List eventItems, List subscriptionIds) + { + super(nodeId, subscriptionIds); + items = eventItems; + } - /** - * Constructs an ItemPublishEvent with the provided list - * of {@link Item} that were published in the past. The published - * date signifies that this is delayed event. The list of subscription ids - * represents the subscriptions that matched the event, in the case - * of the user having multiple subscriptions. - * - * @param nodeId The id of the node the event came from - * @param eventItems The list of {@link Item} that were published - * @param subscriptionIds The list of subscriptionIds - */ - public ItemPublishEvent(String nodeId, List eventItems, List subscriptionIds, Date publishedDate) - { - super(nodeId, subscriptionIds); - items = eventItems; + /** + * Constructs an ItemPublishEvent with the provided list + * of {@link Item} that were published in the past. The published + * date signifies that this is delayed event. The list of subscription ids + * represents the subscriptions that matched the event, in the case + * of the user having multiple subscriptions. + * + * @param nodeId The id of the node the event came from + * @param eventItems The list of {@link Item} that were published + * @param subscriptionIds The list of subscriptionIds + */ + public ItemPublishEvent(String nodeId, List eventItems, List subscriptionIds, Date publishedDate) + { + super(nodeId, subscriptionIds); + items = eventItems; - if (publishedDate != null) - originalDate = publishedDate; - } + if (publishedDate != null) + originalDate = publishedDate; + } - /** - * Get the list of {@link Item} that were published. - * - * @return The list of published {@link Item} - */ - public List getItems() - { - return Collections.unmodifiableList(items); - } + /** + * Get the list of {@link Item} that were published. + * + * @return The list of published {@link Item} + */ + public List getItems() + { + return Collections.unmodifiableList(items); + } - /** - * Indicates whether this event was delayed. That is, the items - * were published to the node at some time in the past. This will - * typically happen if there is an item already published to the node - * before a user subscribes to it. In this case, when the user - * subscribes, the server may send the last item published to the node - * with a delay date showing its time of original publication. - * - * @return true if the items are delayed, false otherwise. - */ - public boolean isDelayed() - { - return (originalDate != null); - } + /** + * Indicates whether this event was delayed. That is, the items + * were published to the node at some time in the past. This will + * typically happen if there is an item already published to the node + * before a user subscribes to it. In this case, when the user + * subscribes, the server may send the last item published to the node + * with a delay date showing its time of original publication. + * + * @return true if the items are delayed, false otherwise. + */ + public boolean isDelayed() + { + return (originalDate != null); + } - /** - * Gets the original date the items were published. This is only - * valid if {@link #isDelayed()} is true. - * - */ - public Date getPublishedDate() - { - return originalDate; - } + /** + * Gets the original date the items were published. This is only + * valid if {@link #isDelayed()} is true. + * + */ + public Date getPublishedDate() + { + return originalDate; + } - @Override - public String toString() - { - return getClass().getName() + " [subscriptions: " + getSubscriptions() + "], [Delayed: " + - (isDelayed() ? originalDate.toString() : "false") + ']'; - } + @Override + public String toString() + { + return getClass().getName() + " [subscriptions: " + getSubscriptions() + "], [Delayed: " + + (isDelayed() ? originalDate.toString() : "false") + ']'; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemReply.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemReply.java index 6928c6d79..3d39e82e5 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemReply.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemReply.java @@ -24,9 +24,9 @@ package org.jivesoftware.smackx.pubsub; */ public enum ItemReply { - /** The node owner. */ - owner, + /** The node owner. */ + owner, - /** The item publisher. */ - publisher; + /** The item publisher. */ + publisher; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemsExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemsExtension.java index 69ec1b7af..c8676f327 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemsExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemsExtension.java @@ -36,168 +36,168 @@ import org.jivesoftware.smack.packet.ExtensionElement; */ public class ItemsExtension extends NodeExtension implements EmbeddedPacketExtension { - protected ItemsElementType type; - protected Boolean notify; - protected List items; + protected ItemsElementType type; + protected Boolean notify; + protected List items; - public enum ItemsElementType - { - /** An items element, which has an optional max_items attribute when requesting items. */ - items(PubSubElementType.ITEMS, "max_items"), + public enum ItemsElementType + { + /** An items element, which has an optional max_items attribute when requesting items. */ + items(PubSubElementType.ITEMS, "max_items"), - /** A retract element, which has an optional notify attribute when publishing deletions. */ - retract(PubSubElementType.RETRACT, "notify"); + /** A retract element, which has an optional notify attribute when publishing deletions. */ + retract(PubSubElementType.RETRACT, "notify"); - private PubSubElementType elem; - private String att; + private PubSubElementType elem; + private String att; - private ItemsElementType(PubSubElementType nodeElement, String attribute) - { - elem = nodeElement; - att = attribute; - } + private ItemsElementType(PubSubElementType nodeElement, String attribute) + { + elem = nodeElement; + att = attribute; + } - public PubSubElementType getNodeElement() - { - return elem; - } + public PubSubElementType getNodeElement() + { + return elem; + } - public String getElementAttribute() - { - return att; - } - } + public String getElementAttribute() + { + return att; + } + } - /** - * Construct an instance with a list representing items that have been published or deleted. - * - *

Valid scenarios are:

- *
    - *
  • Request items from node - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and an - * optional value for the max_items attribute. - *
  • Request to delete items - itemsType = {@link ItemsElementType#retract}, items = list of {@link Item} containing - * only id's and an optional value for the notify attribute. - *
  • Items published event - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and - * attributeValue = null - *
  • Items deleted event - itemsType = {@link ItemsElementType#items}, items = list of {@link RetractItem} and - * attributeValue = null - *
- * - * @param itemsType Type of representation - * @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 items) - { - super(itemsType.getNodeElement(), nodeId); - type = itemsType; - this.items = items; - } + /** + * Construct an instance with a list representing items that have been published or deleted. + * + *

Valid scenarios are:

+ *
    + *
  • Request items from node - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and an + * optional value for the max_items attribute. + *
  • Request to delete items - itemsType = {@link ItemsElementType#retract}, items = list of {@link Item} containing + * only id's and an optional value for the notify attribute. + *
  • Items published event - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and + * attributeValue = null + *
  • Items deleted event - itemsType = {@link ItemsElementType#items}, items = list of {@link RetractItem} and + * attributeValue = null + *
+ * + * @param itemsType Type of representation + * @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 items) + { + super(itemsType.getNodeElement(), nodeId); + type = itemsType; + this.items = items; + } - /** - * Construct an instance with a list representing items that have been published or deleted. - * - *

Valid scenarios are:

- *
    - *
  • Request items from node - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and an - * optional value for the max_items attribute. - *
  • Request to delete items - itemsType = {@link ItemsElementType#retract}, items = list of {@link Item} containing - * only id's and an optional value for the notify attribute. - *
  • Items published event - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and - * attributeValue = null - *
  • Items deleted event - itemsType = {@link ItemsElementType#items}, items = list of {@link RetractItem} and - * attributeValue = null - *
- * - * @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(String nodeId, List items, boolean notify) - { - super(ItemsElementType.retract.getNodeElement(), nodeId); - type = ItemsElementType.retract; - this.items = items; - this.notify = notify; - } + /** + * Construct an instance with a list representing items that have been published or deleted. + * + *

Valid scenarios are:

+ *
    + *
  • Request items from node - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and an + * optional value for the max_items attribute. + *
  • Request to delete items - itemsType = {@link ItemsElementType#retract}, items = list of {@link Item} containing + * only id's and an optional value for the notify attribute. + *
  • Items published event - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and + * attributeValue = null + *
  • Items deleted event - itemsType = {@link ItemsElementType#items}, items = list of {@link RetractItem} and + * attributeValue = null + *
+ * + * @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(String nodeId, List items, boolean notify) + { + super(ItemsElementType.retract.getNodeElement(), nodeId); + type = ItemsElementType.retract; + this.items = items; + this.notify = notify; + } - /** - * Get the type of element. - * - * @return The element type - */ - public ItemsElementType getItemsElementType() - { - return type; - } + /** + * Get the type of element. + * + * @return The element type + */ + public ItemsElementType getItemsElementType() + { + return type; + } - @SuppressWarnings("unchecked") - public List getExtensions() - { - return (List)getItems(); - } + @SuppressWarnings("unchecked") + public List getExtensions() + { + return (List)getItems(); + } - /** - * Gets the items related to the type of request or event. - * - * return List of {@link Item}, {@link RetractItem}, or null - */ - public List getItems() - { - return items; - } + /** + * Gets the items related to the type of request or event. + * + * return List of {@link Item}, {@link RetractItem}, or null + */ + public List getItems() + { + return items; + } - /** - * Gets the value of the optional attribute related to the {@link ItemsElementType}. - * - * @return The attribute value - */ - public boolean getNotify() - { - return notify; - } + /** + * Gets the value of the optional attribute related to the {@link ItemsElementType}. + * + * @return The attribute value + */ + public boolean getNotify() + { + return notify; + } - @Override - public CharSequence toXML() - { - if ((items == null) || (items.size() == 0)) - { - return super.toXML(); - } - else - { - StringBuilder builder = new StringBuilder("<"); - builder.append(getElementName()); - builder.append(" node='"); - builder.append(getNode()); + @Override + public CharSequence toXML() + { + if ((items == null) || (items.size() == 0)) + { + return super.toXML(); + } + else + { + StringBuilder builder = new StringBuilder("<"); + builder.append(getElementName()); + builder.append(" node='"); + builder.append(getNode()); - if (notify != null) - { - builder.append("' "); - builder.append(type.getElementAttribute()); - builder.append("='"); - builder.append(notify.equals(Boolean.TRUE) ? 1 : 0); - builder.append("'>"); - } - else - { - builder.append("'>"); - for (ExtensionElement item : items) - { - builder.append(item.toXML()); - } - } + if (notify != null) + { + builder.append("' "); + builder.append(type.getElementAttribute()); + builder.append("='"); + builder.append(notify.equals(Boolean.TRUE) ? 1 : 0); + builder.append("'>"); + } + else + { + builder.append("'>"); + for (ExtensionElement item : items) + { + builder.append(item.toXML()); + } + } - builder.append("'); - return builder.toString(); - } - } + builder.append("'); + return builder.toString(); + } + } - @Override - public String toString() - { - return getClass().getName() + "Content [" + toXML() + "]"; - } + @Override + public String toString() + { + return getClass().getName() + "Content [" + toXML() + "]"; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java index cf53afdd5..653fdbe7d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java @@ -38,125 +38,125 @@ import org.jivesoftware.smackx.pubsub.packet.PubSub; */ public class LeafNode extends Node { - LeafNode(PubSubManager pubSubManager, String nodeId) - { - super(pubSubManager, nodeId); - } + LeafNode(PubSubManager pubSubManager, String nodeId) + { + super(pubSubManager, nodeId); + } - /** - * Get information on the items in the node in standard - * {@link DiscoverItems} format. - * - * @return The item details in {@link DiscoverItems} format - * @throws XMPPErrorException - * @throws NoResponseException if there was no response from the server. - * @throws NotConnectedException - * @throws InterruptedException - */ - public DiscoverItems discoverItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - DiscoverItems items = new DiscoverItems(); - items.setTo(pubSubManager.getServiceJid()); - items.setNode(getId()); + /** + * Get information on the items in the node in standard + * {@link DiscoverItems} format. + * + * @return The item details in {@link DiscoverItems} format + * @throws XMPPErrorException + * @throws NoResponseException if there was no response from the server. + * @throws NotConnectedException + * @throws InterruptedException + */ + public DiscoverItems discoverItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + DiscoverItems items = new DiscoverItems(); + items.setTo(pubSubManager.getServiceJid()); + items.setNode(getId()); return pubSubManager.getConnection().createStanzaCollectorAndSend(items).nextResultOrThrow(); - } + } - /** - * Get the current items stored in the node. - * - * @return List of {@link Item} in the node - * @throws XMPPErrorException - * @throws NoResponseException if there was no response from the server. - * @throws NotConnectedException - * @throws InterruptedException - */ - public List getItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { + /** + * Get the current items stored in the node. + * + * @return List of {@link Item} in the node + * @throws XMPPErrorException + * @throws NoResponseException if there was no response from the server. + * @throws NotConnectedException + * @throws InterruptedException + */ + public List getItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { return getItems((List) null, (List) null); - } + } - /** - * Get the current items stored in the node based - * on the subscription associated with the provided - * subscription id. - * - * @param subscriptionId - The subscription id for the - * associated subscription. - * @return List of {@link Item} in the node - * @throws XMPPErrorException - * @throws NoResponseException if there was no response from the server. - * @throws NotConnectedException - * @throws InterruptedException - */ - public List getItems(String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), subscriptionId)); + /** + * Get the current items stored in the node based + * on the subscription associated with the provided + * subscription id. + * + * @param subscriptionId - The subscription id for the + * associated subscription. + * @return List of {@link Item} in the node + * @throws XMPPErrorException + * @throws NoResponseException if there was no response from the server. + * @throws NotConnectedException + * @throws InterruptedException + */ + public List getItems(String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), subscriptionId)); return getItems(request); - } + } - /** - * Get the items specified from the node. This would typically be - * used when the server does not return the payload due to size - * constraints. The user would be required to retrieve the payload - * after the items have been retrieved via {@link #getItems()} or an - * event, that did not include the payload. - * - * @param ids Item ids of the items to retrieve - * - * @return The list of {@link Item} with payload - * @throws XMPPErrorException - * @throws NoResponseException if there was no response from the server. - * @throws NotConnectedException - * @throws InterruptedException - */ - public List getItems(Collection ids) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - List itemList = new ArrayList(ids.size()); + /** + * Get the items specified from the node. This would typically be + * used when the server does not return the payload due to size + * constraints. The user would be required to retrieve the payload + * after the items have been retrieved via {@link #getItems()} or an + * event, that did not include the payload. + * + * @param ids Item ids of the items to retrieve + * + * @return The list of {@link Item} with payload + * @throws XMPPErrorException + * @throws NoResponseException if there was no response from the server. + * @throws NotConnectedException + * @throws InterruptedException + */ + public List getItems(Collection ids) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + List itemList = new ArrayList(ids.size()); - for (String id : ids) - { - itemList.add(new Item(id)); - } - PubSub request = createPubsubPacket(Type.get, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList)); + for (String id : ids) + { + itemList.add(new Item(id)); + } + PubSub request = createPubsubPacket(Type.get, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList)); return getItems(request); - } + } - /** - * Get items persisted on the node, limited to the specified number. - * - * @param maxItems Maximum number of items to return - * - * @return List of {@link Item} - * @throws XMPPErrorException - * @throws NoResponseException if there was no response from the server. - * @throws NotConnectedException - * @throws InterruptedException - */ - public List getItems(int maxItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), maxItems)); + /** + * Get items persisted on the node, limited to the specified number. + * + * @param maxItems Maximum number of items to return + * + * @return List of {@link Item} + * @throws XMPPErrorException + * @throws NoResponseException if there was no response from the server. + * @throws NotConnectedException + * @throws InterruptedException + */ + public List getItems(int maxItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), maxItems)); return getItems(request); - } + } - /** - * Get items persisted on the node, limited to the specified number - * based on the subscription associated with the provided subscriptionId. - * - * @param maxItems Maximum number of items to return - * @param subscriptionId The subscription which the retrieval is based - * on. - * - * @return List of {@link Item} - * @throws XMPPErrorException - * @throws NoResponseException if there was no response from the server. - * @throws NotConnectedException - * @throws InterruptedException - */ - public List getItems(int maxItems, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), subscriptionId, maxItems)); + /** + * Get items persisted on the node, limited to the specified number + * based on the subscription associated with the provided subscriptionId. + * + * @param maxItems Maximum number of items to return + * @param subscriptionId The subscription which the retrieval is based + * on. + * + * @return List of {@link Item} + * @throws XMPPErrorException + * @throws NoResponseException if there was no response from the server. + * @throws NotConnectedException + * @throws InterruptedException + */ + public List getItems(int maxItems, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), subscriptionId, maxItems)); return getItems(request); - } + } /** * Get items persisted on the node. @@ -200,206 +200,206 @@ public class LeafNode extends Node return (List) itemsElem.getItems(); } - /** - * Publishes an event to the node. This is an empty event - * with no item. - * - * This is only acceptable for nodes with {@link ConfigureForm#isPersistItems()}=false - * and {@link ConfigureForm#isDeliverPayloads()}=false. - * - * This is an asynchronous call which returns as soon as the - * stanza(/packet) has been sent. - * - * For synchronous calls use {@link #send() send()}. - * @throws NotConnectedException - * @throws InterruptedException - */ - public void publish() throws NotConnectedException, InterruptedException - { - PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId())); + /** + * Publishes an event to the node. This is an empty event + * with no item. + * + * This is only acceptable for nodes with {@link ConfigureForm#isPersistItems()}=false + * and {@link ConfigureForm#isDeliverPayloads()}=false. + * + * This is an asynchronous call which returns as soon as the + * stanza(/packet) has been sent. + * + * For synchronous calls use {@link #send() send()}. + * @throws NotConnectedException + * @throws InterruptedException + */ + public void publish() throws NotConnectedException, InterruptedException + { + PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId())); - pubSubManager.getConnection().sendStanza(packet); - } + pubSubManager.getConnection().sendStanza(packet); + } - /** - * Publishes an event to the node. This is a simple item - * with no payload. - * - * If the id is null, an empty item (one without an id) will be sent. - * Please note that this is not the same as {@link #send()}, which - * publishes an event with NO item. - * - * This is an asynchronous call which returns as soon as the - * stanza(/packet) has been sent. - * - * For synchronous calls use {@link #send(Item) send(Item))}. - * - * @param item - The item being sent - * @throws NotConnectedException - * @throws InterruptedException - */ - @SuppressWarnings("unchecked") - public void publish(T item) throws NotConnectedException, InterruptedException - { - Collection items = new ArrayList(1); - items.add((T)(item == null ? new Item() : item)); - publish(items); - } + /** + * Publishes an event to the node. This is a simple item + * with no payload. + * + * If the id is null, an empty item (one without an id) will be sent. + * Please note that this is not the same as {@link #send()}, which + * publishes an event with NO item. + * + * This is an asynchronous call which returns as soon as the + * stanza(/packet) has been sent. + * + * For synchronous calls use {@link #send(Item) send(Item))}. + * + * @param item - The item being sent + * @throws NotConnectedException + * @throws InterruptedException + */ + @SuppressWarnings("unchecked") + public void publish(T item) throws NotConnectedException, InterruptedException + { + Collection items = new ArrayList(1); + items.add((T)(item == null ? new Item() : item)); + publish(items); + } - /** - * Publishes multiple events to the node. Same rules apply as in {@link #publish(Item)}. - * - * In addition, if {@link ConfigureForm#isPersistItems()}=false, only the last item in the input - * list will get stored on the node, assuming it stores the last sent item. - * - * This is an asynchronous call which returns as soon as the - * stanza(/packet) has been sent. - * - * For synchronous calls use {@link #send(Collection) send(Collection))}. - * - * @param items - The collection of items being sent - * @throws NotConnectedException - * @throws InterruptedException - */ - public void publish(Collection items) throws NotConnectedException, InterruptedException - { - PubSub packet = createPubsubPacket(Type.set, new PublishItem(getId(), items)); + /** + * Publishes multiple events to the node. Same rules apply as in {@link #publish(Item)}. + * + * In addition, if {@link ConfigureForm#isPersistItems()}=false, only the last item in the input + * list will get stored on the node, assuming it stores the last sent item. + * + * This is an asynchronous call which returns as soon as the + * stanza(/packet) has been sent. + * + * For synchronous calls use {@link #send(Collection) send(Collection))}. + * + * @param items - The collection of items being sent + * @throws NotConnectedException + * @throws InterruptedException + */ + public void publish(Collection items) throws NotConnectedException, InterruptedException + { + PubSub packet = createPubsubPacket(Type.set, new PublishItem(getId(), items)); - pubSubManager.getConnection().sendStanza(packet); - } + pubSubManager.getConnection().sendStanza(packet); + } - /** - * Publishes an event to the node. This is an empty event - * with no item. - * - * This is only acceptable for nodes with {@link ConfigureForm#isPersistItems()}=false - * and {@link ConfigureForm#isDeliverPayloads()}=false. - * - * This is a synchronous call which will throw an exception - * on failure. - * - * For asynchronous calls, use {@link #publish() publish()}. - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - * - */ - public void send() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId())); + /** + * Publishes an event to the node. This is an empty event + * with no item. + * + * This is only acceptable for nodes with {@link ConfigureForm#isPersistItems()}=false + * and {@link ConfigureForm#isDeliverPayloads()}=false. + * + * This is a synchronous call which will throw an exception + * on failure. + * + * For asynchronous calls, use {@link #publish() publish()}. + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + * + */ + public void send() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId())); - pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); - } + pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); + } - /** - * Publishes an event to the node. This can be either a simple item - * with no payload, or one with it. This is determined by the Node - * configuration. - * - * If the node has deliver_payload=false, the Item must not - * have a payload. - * - * If the id is null, an empty item (one without an id) will be sent. - * Please note that this is not the same as {@link #send()}, which - * publishes an event with NO item. - * - * This is a synchronous call which will throw an exception - * on failure. - * - * For asynchronous calls, use {@link #publish(Item) publish(Item)}. - * - * @param item - The item being sent - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - * - */ - @SuppressWarnings("unchecked") - public void send(T item) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - Collection items = new ArrayList(1); - items.add((item == null ? (T)new Item() : item)); - send(items); - } + /** + * Publishes an event to the node. This can be either a simple item + * with no payload, or one with it. This is determined by the Node + * configuration. + * + * If the node has deliver_payload=false, the Item must not + * have a payload. + * + * If the id is null, an empty item (one without an id) will be sent. + * Please note that this is not the same as {@link #send()}, which + * publishes an event with NO item. + * + * This is a synchronous call which will throw an exception + * on failure. + * + * For asynchronous calls, use {@link #publish(Item) publish(Item)}. + * + * @param item - The item being sent + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + * + */ + @SuppressWarnings("unchecked") + public void send(T item) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + Collection items = new ArrayList(1); + items.add((item == null ? (T)new Item() : item)); + send(items); + } - /** - * Publishes multiple events to the node. Same rules apply as in {@link #send(Item)}. - * - * In addition, if {@link ConfigureForm#isPersistItems()}=false, only the last item in the input - * list will get stored on the node, assuming it stores the last sent item. - * - * This is a synchronous call which will throw an exception - * on failure. - * - * For asynchronous calls, use {@link #publish(Collection) publish(Collection))}. - * - * @param items - The collection of {@link Item} objects being sent - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - * - */ - public void send(Collection items) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - PubSub packet = createPubsubPacket(Type.set, new PublishItem(getId(), items)); + /** + * Publishes multiple events to the node. Same rules apply as in {@link #send(Item)}. + * + * In addition, if {@link ConfigureForm#isPersistItems()}=false, only the last item in the input + * list will get stored on the node, assuming it stores the last sent item. + * + * This is a synchronous call which will throw an exception + * on failure. + * + * For asynchronous calls, use {@link #publish(Collection) publish(Collection))}. + * + * @param items - The collection of {@link Item} objects being sent + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + * + */ + public void send(Collection items) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + PubSub packet = createPubsubPacket(Type.set, new PublishItem(getId(), items)); - pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); - } + pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow(); + } - /** - * Purges the node of all items. - * - *

Note: Some implementations may keep the last item - * sent. - * @throws XMPPErrorException - * @throws NoResponseException if there was no response from the server. - * @throws NotConnectedException - * @throws InterruptedException - */ - public void deleteAllItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - PubSub request = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PURGE_OWNER, getId()), PubSubElementType.PURGE_OWNER.getNamespace()); + /** + * Purges the node of all items. + * + *

Note: Some implementations may keep the last item + * sent. + * @throws XMPPErrorException + * @throws NoResponseException if there was no response from the server. + * @throws NotConnectedException + * @throws 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(); - } + pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow(); + } - /** - * Delete the item with the specified id from the node. - * - * @param itemId The id of the item - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public void deleteItem(String itemId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - Collection items = new ArrayList(1); - items.add(itemId); - deleteItem(items); - } + /** + * Delete the item with the specified id from the node. + * + * @param itemId The id of the item + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public void deleteItem(String itemId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + Collection items = new ArrayList(1); + items.add(itemId); + deleteItem(items); + } - /** - * Delete the items with the specified id's from the node. - * - * @param itemIds The list of id's of items to delete - * @throws XMPPErrorException - * @throws NoResponseException if there was no response from the server. - * @throws NotConnectedException - * @throws InterruptedException - */ - public void deleteItem(Collection itemIds) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - List items = new ArrayList(itemIds.size()); + /** + * Delete the items with the specified id's from the node. + * + * @param itemIds The list of id's of items to delete + * @throws XMPPErrorException + * @throws NoResponseException if there was no response from the server. + * @throws NotConnectedException + * @throws InterruptedException + */ + public void deleteItem(Collection itemIds) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + List items = new ArrayList(itemIds.size()); - for (String id : itemIds) - { - items.add(new Item(id)); - } - PubSub request = createPubsubPacket(Type.set, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items)); - pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow(); - } + for (String id : itemIds) + { + items.add(new Item(id)); + } + PubSub request = createPubsubPacket(Type.set, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items)); + pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow(); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java index 22cc12b7a..265eb366a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java @@ -48,97 +48,97 @@ abstract public class Node protected final PubSubManager pubSubManager; protected final String id; - protected ConcurrentHashMap, StanzaListener> itemEventToListenerMap = new ConcurrentHashMap, StanzaListener>(); - protected ConcurrentHashMap itemDeleteToListenerMap = new ConcurrentHashMap(); - protected ConcurrentHashMap configEventToListenerMap = new ConcurrentHashMap(); + protected ConcurrentHashMap, StanzaListener> itemEventToListenerMap = new ConcurrentHashMap, StanzaListener>(); + protected ConcurrentHashMap itemDeleteToListenerMap = new ConcurrentHashMap(); + protected ConcurrentHashMap configEventToListenerMap = new ConcurrentHashMap(); - /** - * Construct a node associated to the supplied connection with the specified - * node id. - * - * @param connection The connection the node is associated with - * @param nodeName The node id - */ - Node(PubSubManager pubSubManager, String nodeId) - { - this.pubSubManager = pubSubManager; - id = nodeId; - } + /** + * Construct a node associated to the supplied connection with the specified + * node id. + * + * @param connection The connection the node is associated with + * @param nodeName The node id + */ + Node(PubSubManager pubSubManager, String nodeId) + { + this.pubSubManager = pubSubManager; + id = nodeId; + } - /** - * Get the NodeId. - * - * @return the node id - */ - public String getId() - { - return id; - } - /** - * Returns a configuration form, from which you can create an answer form to be submitted - * via the {@link #sendConfigurationForm(Form)}. - * - * @return the configuration form - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public ConfigureForm getNodeConfiguration() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { + /** + * Get the NodeId. + * + * @return the node id + */ + public String getId() + { + return id; + } + /** + * Returns a configuration form, from which you can create an answer form to be submitted + * via the {@link #sendConfigurationForm(Form)}. + * + * @return the configuration form + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws 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); - return NodeUtils.getFormFromPacket(reply, PubSubElementType.CONFIGURE_OWNER); - } + Stanza reply = sendPubsubPacket(pubSub); + return NodeUtils.getFormFromPacket(reply, PubSubElementType.CONFIGURE_OWNER); + } - /** - * Update the configuration with the contents of the new {@link Form}. - * - * @param submitForm - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public void sendConfigurationForm(Form submitForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { + /** + * Update the configuration with the contents of the new {@link Form}. + * + * @param submitForm + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws 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(); - } + } - /** - * Discover node information in standard {@link DiscoverInfo} format. - * - * @return The discovery information about the node. - * @throws XMPPErrorException - * @throws NoResponseException if there was no response from the server. - * @throws NotConnectedException - * @throws InterruptedException - */ - public DiscoverInfo discoverInfo() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - DiscoverInfo info = new DiscoverInfo(); - info.setTo(pubSubManager.getServiceJid()); - info.setNode(getId()); - return pubSubManager.getConnection().createStanzaCollectorAndSend(info).nextResultOrThrow(); - } + /** + * Discover node information in standard {@link DiscoverInfo} format. + * + * @return The discovery information about the node. + * @throws XMPPErrorException + * @throws NoResponseException if there was no response from the server. + * @throws NotConnectedException + * @throws InterruptedException + */ + public DiscoverInfo discoverInfo() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + DiscoverInfo info = new DiscoverInfo(); + info.setTo(pubSubManager.getServiceJid()); + info.setNode(getId()); + return pubSubManager.getConnection().createStanzaCollectorAndSend(info).nextResultOrThrow(); + } - /** - * Get the subscriptions currently associated with this node. - * - * @return List of {@link Subscription} - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - * - */ - public List getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { + /** + * Get the subscriptions currently associated with this node. + * + * @return List of {@link Subscription} + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + * + */ + public List getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { return getSubscriptions(null, null); - } + } /** * Get the subscriptions currently associated with this node. @@ -223,15 +223,15 @@ abstract public class Node return subElem.getSubscriptions(); } - /** - * Get the affiliations of this node. - * - * @return List of {@link Affiliation} - * @throws NoResponseException - * @throws XMPPErrorException - * @throws NotConnectedException - * @throws InterruptedException - */ + /** + * Get the affiliations of this node. + * + * @return List of {@link Affiliation} + * @throws NoResponseException + * @throws XMPPErrorException + * @throws NotConnectedException + * @throws InterruptedException + */ public List getAffiliations() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return getAffiliations(null, null); @@ -346,398 +346,394 @@ abstract public class Node return sendPubsubPacket(pubSub); } - /** - * The user subscribes to the node using the supplied jid. The - * bare jid portion of this one must match the jid for the connection. - * - * Please note that the {@link Subscription.State} should be checked - * on return since more actions may be required by the caller. - * {@link Subscription.State#pending} - The owner must approve the subscription - * request before messages will be received. - * {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true, - * the caller must configure the subscription before messages will be received. If it is false - * the caller can configure it but is not required to do so. - * @param jid The jid to subscribe as. - * @return The subscription - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public Subscription subscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { -// CHECKSTYLE:OFF - PubSub pubSub = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId())); -// CHECKSTYLE:ON - PubSub reply = sendPubsubPacket(pubSub); - return reply.getExtension(PubSubElementType.SUBSCRIPTION); - } + /** + * The user subscribes to the node using the supplied jid. The + * bare jid portion of this one must match the jid for the connection. + * + * Please note that the {@link Subscription.State} should be checked + * on return since more actions may be required by the caller. + * {@link Subscription.State#pending} - The owner must approve the subscription + * request before messages will be received. + * {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true, + * the caller must configure the subscription before messages will be received. If it is false + * the caller can configure it but is not required to do so. + * @param jid The jid to subscribe as. + * @return The subscription + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws 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); + } - /** - * The user subscribes to the node using the supplied jid and subscription - * options. The bare jid portion of this one must match the jid for the - * connection. - * - * Please note that the {@link Subscription.State} should be checked - * on return since more actions may be required by the caller. - * {@link Subscription.State#pending} - The owner must approve the subscription - * request before messages will be received. - * {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true, - * the caller must configure the subscription before messages will be received. If it is false - * the caller can configure it but is not required to do so. - * @param jid The jid to subscribe as. - * @return The subscription - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public Subscription subscribe(String jid, SubscribeForm subForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { -// CHECKSTYLE:OFF - PubSub request = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId())); -// CHECKSTYLE:ON - request.addExtension(new FormNode(FormNodeType.OPTIONS, subForm)); - PubSub reply = sendPubsubPacket(request); - return reply.getExtension(PubSubElementType.SUBSCRIPTION); - } + /** + * The user subscribes to the node using the supplied jid and subscription + * options. The bare jid portion of this one must match the jid for the + * connection. + * + * Please note that the {@link Subscription.State} should be checked + * on return since more actions may be required by the caller. + * {@link Subscription.State#pending} - The owner must approve the subscription + * request before messages will be received. + * {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true, + * the caller must configure the subscription before messages will be received. If it is false + * the caller can configure it but is not required to do so. + * @param jid The jid to subscribe as. + * @return The subscription + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws 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); + return reply.getExtension(PubSubElementType.SUBSCRIPTION); + } - /** - * Remove the subscription related to the specified JID. This will only - * work if there is only 1 subscription. If there are multiple subscriptions, - * use {@link #unsubscribe(String, String)}. - * - * @param jid The JID used to subscribe to the node - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - * - */ - public void unsubscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - unsubscribe(jid, null); - } + /** + * Remove the subscription related to the specified JID. This will only + * work if there is only 1 subscription. If there are multiple subscriptions, + * use {@link #unsubscribe(String, String)}. + * + * @param jid The JID used to subscribe to the node + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + * + */ + public void unsubscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + unsubscribe(jid, null); + } - /** - * Remove the specific subscription related to the specified JID. - * - * @param jid The JID used to subscribe to the node - * @param subscriptionId The id of the subscription being removed - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public void unsubscribe(String jid, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - sendPubsubPacket(createPubsubPacket(Type.set, new UnsubscribeExtension(jid, getId(), subscriptionId))); - } + /** + * Remove the specific subscription related to the specified JID. + * + * @param jid The JID used to subscribe to the node + * @param subscriptionId The id of the subscription being removed + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public void unsubscribe(String jid, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + sendPubsubPacket(createPubsubPacket(Type.set, new UnsubscribeExtension(jid, getId(), subscriptionId))); + } - /** - * Returns a SubscribeForm for subscriptions, from which you can create an answer form to be submitted - * via the {@link #sendConfigurationForm(Form)}. - * - * @return A subscription options form - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public SubscribeForm getSubscriptionOptions(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - return getSubscriptionOptions(jid, null); - } + /** + * Returns a SubscribeForm for subscriptions, from which you can create an answer form to be submitted + * via the {@link #sendConfigurationForm(Form)}. + * + * @return A subscription options form + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public SubscribeForm getSubscriptionOptions(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + return getSubscriptionOptions(jid, null); + } - /** - * Get the options for configuring the specified subscription. - * - * @param jid JID the subscription is registered under - * @param subscriptionId The subscription id - * - * @return The subscription option form - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws 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()); - } + /** + * Get the options for configuring the specified subscription. + * + * @param jid JID the subscription is registered under + * @param subscriptionId The subscription id + * + * @return The subscription option form + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws 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()); + } - /** - * Register a listener for item publication events. This - * listener will get called whenever an item is published to - * this node. - * - * @param listener The handler for the event - */ - @SuppressWarnings("unchecked") + /** + * Register a listener for item publication events. This + * listener will get called whenever an item is published to + * this node. + * + * @param listener The handler for the event + */ + @SuppressWarnings("unchecked") 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")); - } + { + StanzaListener conListener = new ItemEventTranslator(listener); + itemEventToListenerMap.put(listener, conListener); + pubSubManager.getConnection().addSyncStanzaListener(conListener, new EventContentFilter(EventElementType.items.toString(), "item")); + } - /** - * Unregister a listener for publication events. - * - * @param listener The handler to unregister - */ - public void removeItemEventListener(@SuppressWarnings("rawtypes") ItemEventListener listener) - { - StanzaListener conListener = itemEventToListenerMap.remove(listener); + /** + * Unregister a listener for publication events. + * + * @param listener The handler to unregister + */ + public void removeItemEventListener(@SuppressWarnings("rawtypes") ItemEventListener listener) + { + StanzaListener conListener = itemEventToListenerMap.remove(listener); - if (conListener != null) - pubSubManager.getConnection().removeSyncStanzaListener(conListener); - } + if (conListener != null) + pubSubManager.getConnection().removeSyncStanzaListener(conListener); + } - /** - * Register a listener for configuration events. This listener - * will get called whenever the node's configuration changes. - * - * @param listener The handler for the event - */ - public void addConfigurationListener(NodeConfigListener listener) - { - StanzaListener conListener = new NodeConfigTranslator(listener); - configEventToListenerMap.put(listener, conListener); - pubSubManager.getConnection().addSyncStanzaListener(conListener, new EventContentFilter(EventElementType.configuration.toString())); - } + /** + * Register a listener for configuration events. This listener + * will get called whenever the node's configuration changes. + * + * @param listener The handler for the event + */ + public void addConfigurationListener(NodeConfigListener listener) + { + StanzaListener conListener = new NodeConfigTranslator(listener); + configEventToListenerMap.put(listener, conListener); + pubSubManager.getConnection().addSyncStanzaListener(conListener, new EventContentFilter(EventElementType.configuration.toString())); + } - /** - * Unregister a listener for configuration events. - * - * @param listener The handler to unregister - */ - public void removeConfigurationListener(NodeConfigListener listener) - { - StanzaListener conListener = configEventToListenerMap .remove(listener); + /** + * Unregister a listener for configuration events. + * + * @param listener The handler to unregister + */ + public void removeConfigurationListener(NodeConfigListener listener) + { + StanzaListener conListener = configEventToListenerMap .remove(listener); - if (conListener != null) - pubSubManager.getConnection().removeSyncStanzaListener(conListener); - } + if (conListener != null) + pubSubManager.getConnection().removeSyncStanzaListener(conListener); + } - /** - * Register an listener for item delete events. This listener - * gets called whenever an item is deleted from the node. - * - * @param listener The handler for the event - */ - public void addItemDeleteListener(ItemDeleteListener listener) - { - StanzaListener delListener = new ItemDeleteTranslator(listener); - itemDeleteToListenerMap.put(listener, delListener); - EventContentFilter deleteItem = new EventContentFilter(EventElementType.items.toString(), "retract"); - EventContentFilter purge = new EventContentFilter(EventElementType.purge.toString()); + /** + * Register an listener for item delete events. This listener + * gets called whenever an item is deleted from the node. + * + * @param listener The handler for the event + */ + public void addItemDeleteListener(ItemDeleteListener listener) + { + StanzaListener delListener = new ItemDeleteTranslator(listener); + itemDeleteToListenerMap.put(listener, delListener); + EventContentFilter deleteItem = new EventContentFilter(EventElementType.items.toString(), "retract"); + EventContentFilter purge = new EventContentFilter(EventElementType.purge.toString()); - pubSubManager.getConnection().addSyncStanzaListener(delListener, new OrFilter(deleteItem, purge)); - } + pubSubManager.getConnection().addSyncStanzaListener(delListener, new OrFilter(deleteItem, purge)); + } - /** - * Unregister a listener for item delete events. - * - * @param listener The handler to unregister - */ - public void removeItemDeleteListener(ItemDeleteListener listener) - { - StanzaListener conListener = itemDeleteToListenerMap .remove(listener); + /** + * Unregister a listener for item delete events. + * + * @param listener The handler to unregister + */ + public void removeItemDeleteListener(ItemDeleteListener listener) + { + StanzaListener conListener = itemDeleteToListenerMap .remove(listener); - if (conListener != null) - pubSubManager.getConnection().removeSyncStanzaListener(conListener); - } + if (conListener != null) + pubSubManager.getConnection().removeSyncStanzaListener(conListener); + } - @Override - public String toString() - { - return super.toString() + " " + getClass().getName() + " id: " + id; - } + @Override + public String toString() + { + return super.toString() + " " + getClass().getName() + " id: " + id; + } - protected PubSub createPubsubPacket(Type type, ExtensionElement ext) - { - return createPubsubPacket(type, ext, null); - } + 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 - { - return pubSubManager.sendPubsubPacket(packet); - } + protected PubSub sendPubsubPacket(PubSub packet) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + return pubSubManager.sendPubsubPacket(packet); + } - private static List getSubscriptionIds(Stanza packet) - { - HeadersExtension headers = (HeadersExtension)packet.getExtension("headers", "http://jabber.org/protocol/shim"); - List values = null; + private static List getSubscriptionIds(Stanza packet) + { + HeadersExtension headers = (HeadersExtension)packet.getExtension("headers", "http://jabber.org/protocol/shim"); + List values = null; - if (headers != null) - { - values = new ArrayList(headers.getHeaders().size()); + if (headers != null) + { + values = new ArrayList(headers.getHeaders().size()); - for (Header header : headers.getHeaders()) - { - values.add(header.getValue()); - } - } - return values; - } + for (Header header : headers.getHeaders()) + { + values.add(header.getValue()); + } + } + return values; + } - /** - * This class translates low level item publication events into api level objects for - * user consumption. - * - * @author Robin Collier - */ - public class ItemEventTranslator implements StanzaListener - { - @SuppressWarnings("rawtypes") + /** + * This class translates low level item publication events into api level objects for + * user consumption. + * + * @author Robin Collier + */ + public class ItemEventTranslator implements StanzaListener + { + @SuppressWarnings("rawtypes") private ItemEventListener listener; - public ItemEventTranslator(@SuppressWarnings("rawtypes") ItemEventListener eventListener) - { - listener = eventListener; - } + public ItemEventTranslator(@SuppressWarnings("rawtypes") ItemEventListener eventListener) + { + listener = eventListener; + } - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({ "rawtypes", "unchecked" }) public void processStanza(Stanza packet) - { + { // CHECKSTYLE:OFF - EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); + EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); // CHECKSTYLE:ON - ItemsExtension itemsElem = (ItemsExtension)event.getEvent(); + ItemsExtension itemsElem = (ItemsExtension)event.getEvent(); ItemPublishEvent eventItems = new ItemPublishEvent(itemsElem.getNode(), itemsElem.getItems(), getSubscriptionIds(packet), DelayInformationManager.getDelayTimestamp(packet)); - listener.handlePublishedItems(eventItems); - } - } + listener.handlePublishedItems(eventItems); + } + } - /** - * This class translates low level item deletion events into api level objects for - * user consumption. - * - * @author Robin Collier - */ - public class ItemDeleteTranslator implements StanzaListener - { - private ItemDeleteListener listener; + /** + * This class translates low level item deletion events into api level objects for + * user consumption. + * + * @author Robin Collier + */ + public class ItemDeleteTranslator implements StanzaListener + { + private ItemDeleteListener listener; - public ItemDeleteTranslator(ItemDeleteListener eventListener) - { - listener = eventListener; - } + public ItemDeleteTranslator(ItemDeleteListener eventListener) + { + listener = eventListener; + } - public void processStanza(Stanza packet) - { + public void processStanza(Stanza packet) + { // CHECKSTYLE:OFF - EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); + EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); - List extList = event.getExtensions(); + List extList = event.getExtensions(); - if (extList.get(0).getElementName().equals(PubSubElementType.PURGE_EVENT.getElementName())) - { - listener.handlePurge(); - } - else - { - ItemsExtension itemsElem = (ItemsExtension)event.getEvent(); - @SuppressWarnings("unchecked") + if (extList.get(0).getElementName().equals(PubSubElementType.PURGE_EVENT.getElementName())) + { + listener.handlePurge(); + } + else + { + ItemsExtension itemsElem = (ItemsExtension)event.getEvent(); + @SuppressWarnings("unchecked") Collection pubItems = (Collection) itemsElem.getItems(); - List items = new ArrayList(pubItems.size()); + List items = new ArrayList(pubItems.size()); - for (RetractItem item : pubItems) - { - items.add(item.getId()); - } + for (RetractItem item : pubItems) + { + items.add(item.getId()); + } - ItemDeleteEvent eventItems = new ItemDeleteEvent(itemsElem.getNode(), items, getSubscriptionIds(packet)); - listener.handleDeletedItems(eventItems); - } + ItemDeleteEvent eventItems = new ItemDeleteEvent(itemsElem.getNode(), items, getSubscriptionIds(packet)); + listener.handleDeletedItems(eventItems); + } // CHECKSTYLE:ON - } - } + } + } - /** - * This class translates low level node configuration events into api level objects for - * user consumption. - * - * @author Robin Collier - */ - public class NodeConfigTranslator implements StanzaListener - { - private NodeConfigListener listener; + /** + * This class translates low level node configuration events into api level objects for + * user consumption. + * + * @author Robin Collier + */ + public class NodeConfigTranslator implements StanzaListener + { + private NodeConfigListener listener; - public NodeConfigTranslator(NodeConfigListener eventListener) - { - listener = eventListener; - } + public NodeConfigTranslator(NodeConfigListener eventListener) + { + listener = eventListener; + } - public void processStanza(Stanza packet) - { + public void processStanza(Stanza packet) + { // CHECKSTYLE:OFF - EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); - ConfigurationEvent config = (ConfigurationEvent)event.getEvent(); + EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); + ConfigurationEvent config = (ConfigurationEvent)event.getEvent(); // CHECKSTYLE:ON - listener.handleNodeConfiguration(config); - } - } + listener.handleNodeConfiguration(config); + } + } - /** - * Filter for {@link StanzaListener} to filter out events not specific to the - * event type expected for this node. - * - * @author Robin Collier - */ - class EventContentFilter extends FlexibleStanzaTypeFilter - { + /** + * Filter for {@link StanzaListener} to filter out events not specific to the + * event type expected for this node. + * + * @author Robin Collier + */ + class EventContentFilter extends FlexibleStanzaTypeFilter + { private final String firstElement; private final String secondElement; private final boolean allowEmpty; - EventContentFilter(String elementName) - { + EventContentFilter(String elementName) + { this(elementName, null); - } + } - EventContentFilter(String firstLevelEelement, String secondLevelElement) - { - firstElement = firstLevelEelement; - secondElement = secondLevelElement; + EventContentFilter(String firstLevelEelement, String secondLevelElement) + { + firstElement = firstLevelEelement; + secondElement = secondLevelElement; allowEmpty = firstElement.equals(EventElementType.items.toString()) && "item".equals(secondLevelElement); - } + } public boolean acceptSpecific(Message message) { EventElement event = EventElement.from(message); - if (event == null) - return false; + if (event == null) + return false; - NodeExtension embedEvent = event.getEvent(); + NodeExtension embedEvent = event.getEvent(); - if (embedEvent == null) - return false; + if (embedEvent == null) + return false; - if (embedEvent.getElementName().equals(firstElement)) - { - if (!embedEvent.getNode().equals(getId())) - return false; + if (embedEvent.getElementName().equals(firstElement)) + { + if (!embedEvent.getNode().equals(getId())) + return false; - if (secondElement == null) - return true; + if (secondElement == null) + return true; - if (embedEvent instanceof EmbeddedPacketExtension) - { - List secondLevelList = ((EmbeddedPacketExtension)embedEvent).getExtensions(); + if (embedEvent instanceof EmbeddedPacketExtension) + { + List secondLevelList = ((EmbeddedPacketExtension)embedEvent).getExtensions(); // XEP-0060 allows no elements on second level for notifications. See schema or // for example § 4.3: @@ -746,11 +742,11 @@ abstract public class Node return true; } - if (secondLevelList.size() > 0 && secondLevelList.get(0).getElementName().equals(secondElement)) - return true; - } - } - return false; - } - } + if (secondLevelList.size() > 0 && secondLevelList.get(0).getElementName().equals(secondElement)) + return true; + } + } + return false; + } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeEvent.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeEvent.java index 1d92e50be..c75cc41dd 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeEvent.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeEvent.java @@ -18,15 +18,15 @@ package org.jivesoftware.smackx.pubsub; abstract public class NodeEvent { - private String nodeId; + private String nodeId; - protected NodeEvent(String id) - { - nodeId = id; - } + protected NodeEvent(String id) + { + nodeId = id; + } - public String getNodeId() - { - return nodeId; - } + public String getNodeId() + { + return nodeId; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeExtension.java index 58d05da35..5da7ecacf 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeExtension.java @@ -28,61 +28,61 @@ import org.jivesoftware.smack.packet.ExtensionElement; */ public class NodeExtension implements ExtensionElement { - private final PubSubElementType element; - private final String node; + private final PubSubElementType element; + private final String node; - /** - * Constructs a NodeExtension with an element name specified - * by {@link PubSubElementType} and the specified node id. - * - * @param elem Defines the element name and namespace - * @param nodeId Specifies the id of the node - */ - public NodeExtension(PubSubElementType elem, String nodeId) - { - element = elem; - this.node = nodeId; - } + /** + * Constructs a NodeExtension with an element name specified + * by {@link PubSubElementType} and the specified node id. + * + * @param elem Defines the element name and namespace + * @param nodeId Specifies the id of the node + */ + public NodeExtension(PubSubElementType elem, String nodeId) + { + element = elem; + this.node = nodeId; + } - /** - * Constructs a NodeExtension with an element name specified - * by {@link PubSubElementType}. - * - * @param elem Defines the element name and namespace - */ - public NodeExtension(PubSubElementType elem) - { - this(elem, null); - } + /** + * Constructs a NodeExtension with an element name specified + * by {@link PubSubElementType}. + * + * @param elem Defines the element name and namespace + */ + public NodeExtension(PubSubElementType elem) + { + this(elem, null); + } - /** - * Gets the node id. - * - * @return The node id - */ - public String getNode() - { - return node; - } + /** + * Gets the node id. + * + * @return The node id + */ + public String getNode() + { + return node; + } - public String getElementName() - { - return element.getElementName(); - } + public String getElementName() + { + return element.getElementName(); + } - public String getNamespace() - { - return element.getNamespace().getXmlns(); - } + public String getNamespace() + { + return element.getNamespace().getXmlns(); + } - public CharSequence toXML() - { - return '<' + getElementName() + (node == null ? "" : " node='" + node + '\'') + "/>"; - } + public CharSequence toXML() + { + return '<' + getElementName() + (node == null ? "" : " node='" + node + '\'') + "/>"; + } - @Override - public String toString() - { - return getClass().getName() + " - content [" + toXML() + "]"; - } + @Override + public String toString() + { + return getClass().getName() + " - content [" + toXML() + "]"; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeType.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeType.java index bd29f1901..08146d5c4 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeType.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/NodeType.java @@ -23,6 +23,6 @@ package org.jivesoftware.smackx.pubsub; */ public enum NodeType { - leaf, - collection; + leaf, + collection; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/OptionsExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/OptionsExtension.java index 4da9969c1..2c1969876 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/OptionsExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/OptionsExtension.java @@ -25,35 +25,35 @@ import org.jivesoftware.smack.util.XmlStringBuilder; */ public class OptionsExtension extends NodeExtension { - protected String jid; - protected String id; + protected String jid; + protected String id; - public OptionsExtension(String subscriptionJid) - { - this(subscriptionJid, null, null); - } + public OptionsExtension(String subscriptionJid) + { + this(subscriptionJid, null, null); + } - public OptionsExtension(String subscriptionJid, String nodeId) - { - this(subscriptionJid, nodeId, null); - } + public OptionsExtension(String subscriptionJid, String nodeId) + { + this(subscriptionJid, nodeId, null); + } - public OptionsExtension(String jid, String nodeId, String subscriptionId) - { - super(PubSubElementType.OPTIONS, nodeId); - this.jid = jid; - id = subscriptionId; - } + public OptionsExtension(String jid, String nodeId, String subscriptionId) + { + super(PubSubElementType.OPTIONS, nodeId); + this.jid = jid; + id = subscriptionId; + } - public String getJid() - { - return jid; - } + public String getJid() + { + return jid; + } - public String getId() - { - return id; - } + public String getId() + { + return id; + } @Override public XmlStringBuilder toXML() { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PayloadItem.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PayloadItem.java index 40e8e4131..c20c49de3 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PayloadItem.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PayloadItem.java @@ -49,98 +49,98 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider; */ public class PayloadItem extends Item { - private E payload; + private E payload; - /** - * Create an Item with no id and a payload The id will be set by the server. - * - * @param payloadExt A {@link ExtensionElement} which represents the payload data. - */ - public PayloadItem(E payloadExt) - { - super(); + /** + * Create an Item with no id and a payload The id will be set by the server. + * + * @param payloadExt A {@link ExtensionElement} which represents the payload data. + */ + public PayloadItem(E payloadExt) + { + super(); - if (payloadExt == null) - throw new IllegalArgumentException("payload cannot be 'null'"); - payload = payloadExt; - } + if (payloadExt == null) + throw new IllegalArgumentException("payload cannot be 'null'"); + payload = payloadExt; + } - /** - * Create an Item with an id and payload. - * - * @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) - { - super(itemId); + /** + * Create an Item with an id and payload. + * + * @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) + { + super(itemId); - if (payloadExt == null) - throw new IllegalArgumentException("payload cannot be 'null'"); - payload = payloadExt; - } + if (payloadExt == null) + throw new IllegalArgumentException("payload cannot be 'null'"); + payload = payloadExt; + } - /** - * Create an Item with an id, node id and payload. - * - *

- * Note: This is not valid for publishing an item to a node, only receiving from - * one as part of {@link Message}. If used to create an Item to publish - * (via {@link LeafNode#publish(Item)}, the server may return an - * error for an invalid packet. - *

- * - * @param itemId The id of this 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) - { - super(itemId, nodeId); + /** + * Create an Item with an id, node id and payload. + * + *

+ * Note: This is not valid for publishing an item to a node, only receiving from + * one as part of {@link Message}. If used to create an Item to publish + * (via {@link LeafNode#publish(Item)}, the server may return an + * error for an invalid packet. + *

+ * + * @param itemId The id of this 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) + { + super(itemId, nodeId); - if (payloadExt == null) - throw new IllegalArgumentException("payload cannot be 'null'"); - payload = payloadExt; - } + if (payloadExt == null) + throw new IllegalArgumentException("payload cannot be 'null'"); + payload = payloadExt; + } - /** - * Get the payload associated with this Item. Customising the payload - * parsing from the server can be accomplished as described in {@link ItemProvider}. - * - * @return The payload as a {@link ExtensionElement}. - */ - public E getPayload() - { - return payload; - } + /** + * Get the payload associated with this Item. Customising the payload + * parsing from the server can be accomplished as described in {@link ItemProvider}. + * + * @return The payload as a {@link ExtensionElement}. + */ + public E getPayload() + { + return payload; + } - @Override - public String toXML() - { - StringBuilder builder = new StringBuilder("'); - builder.append(payload.toXML()); - builder.append("
"); + builder.append('>'); + builder.append(payload.toXML()); + builder.append("
"); - return builder.toString(); - } + return builder.toString(); + } - @Override - public String toString() - { - return getClass().getName() + " | Content [" + toXML() + "]"; - } + @Override + public String toString() + { + return getClass().getName() + " | Content [" + toXML() + "]"; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PresenceState.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PresenceState.java index 0f4a83d05..f6ca9f928 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PresenceState.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PresenceState.java @@ -24,5 +24,5 @@ package org.jivesoftware.smackx.pubsub; */ public enum PresenceState { - chat, online, away, xa, dnd + chat, online, away, xa, dnd } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubElementType.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubElementType.java index 0f6e32ccc..14b14b0fe 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubElementType.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubElementType.java @@ -28,58 +28,58 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace; */ public enum PubSubElementType { - CREATE("create", PubSubNamespace.BASIC), - DELETE("delete", PubSubNamespace.OWNER), - DELETE_EVENT("delete", PubSubNamespace.EVENT), - CONFIGURE("configure", PubSubNamespace.BASIC), - CONFIGURE_OWNER("configure", PubSubNamespace.OWNER), - CONFIGURATION("configuration", PubSubNamespace.EVENT), - OPTIONS("options", PubSubNamespace.BASIC), - DEFAULT("default", PubSubNamespace.OWNER), - ITEMS("items", PubSubNamespace.BASIC), - ITEMS_EVENT("items", PubSubNamespace.EVENT), - ITEM("item", PubSubNamespace.BASIC), - ITEM_EVENT("item", PubSubNamespace.EVENT), - PUBLISH("publish", PubSubNamespace.BASIC), - PUBLISH_OPTIONS("publish-options", PubSubNamespace.BASIC), - PURGE_OWNER("purge", PubSubNamespace.OWNER), - PURGE_EVENT("purge", PubSubNamespace.EVENT), - RETRACT("retract", PubSubNamespace.BASIC), - AFFILIATIONS("affiliations", PubSubNamespace.BASIC), - SUBSCRIBE("subscribe", PubSubNamespace.BASIC), - SUBSCRIPTION("subscription", PubSubNamespace.BASIC), - SUBSCRIPTIONS("subscriptions", PubSubNamespace.BASIC), - UNSUBSCRIBE("unsubscribe", PubSubNamespace.BASIC); + CREATE("create", PubSubNamespace.BASIC), + DELETE("delete", PubSubNamespace.OWNER), + DELETE_EVENT("delete", PubSubNamespace.EVENT), + CONFIGURE("configure", PubSubNamespace.BASIC), + CONFIGURE_OWNER("configure", PubSubNamespace.OWNER), + CONFIGURATION("configuration", PubSubNamespace.EVENT), + OPTIONS("options", PubSubNamespace.BASIC), + DEFAULT("default", PubSubNamespace.OWNER), + ITEMS("items", PubSubNamespace.BASIC), + ITEMS_EVENT("items", PubSubNamespace.EVENT), + ITEM("item", PubSubNamespace.BASIC), + ITEM_EVENT("item", PubSubNamespace.EVENT), + PUBLISH("publish", PubSubNamespace.BASIC), + PUBLISH_OPTIONS("publish-options", PubSubNamespace.BASIC), + PURGE_OWNER("purge", PubSubNamespace.OWNER), + PURGE_EVENT("purge", PubSubNamespace.EVENT), + RETRACT("retract", PubSubNamespace.BASIC), + AFFILIATIONS("affiliations", PubSubNamespace.BASIC), + SUBSCRIBE("subscribe", PubSubNamespace.BASIC), + SUBSCRIPTION("subscription", PubSubNamespace.BASIC), + SUBSCRIPTIONS("subscriptions", PubSubNamespace.BASIC), + UNSUBSCRIBE("unsubscribe", PubSubNamespace.BASIC); - private String eName; - private PubSubNamespace nSpace; + private String eName; + private PubSubNamespace nSpace; - private PubSubElementType(String elemName, PubSubNamespace ns) - { - eName = elemName; - nSpace = ns; - } + private PubSubElementType(String elemName, PubSubNamespace ns) + { + eName = elemName; + nSpace = ns; + } - public PubSubNamespace getNamespace() - { - return nSpace; - } + public PubSubNamespace getNamespace() + { + return nSpace; + } - public String getElementName() - { - return eName; - } + public String getElementName() + { + return eName; + } - public static PubSubElementType valueOfFromElemName(String elemName, String namespace) - { - int index = namespace.lastIndexOf('#'); - String fragment = (index == -1 ? null : namespace.substring(index+1)); + public static PubSubElementType valueOfFromElemName(String elemName, String namespace) + { + int index = namespace.lastIndexOf('#'); + String fragment = (index == -1 ? null : namespace.substring(index+1)); - if (fragment != null) - { - return valueOf((elemName + '_' + fragment).toUpperCase(Locale.US)); - } - return valueOf(elemName.toUpperCase(Locale.US).replace('-', '_')); - } + if (fragment != null) + { + return valueOf((elemName + '_' + fragment).toUpperCase(Locale.US)); + } + return valueOf(elemName.toUpperCase(Locale.US).replace('-', '_')); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java index 452c8af3a..37a08ba45 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java @@ -127,114 +127,114 @@ public final class PubSubManager extends Manager { return pubSubManager; } - /** - * Create a pubsub manager associated to the specified connection where - * the pubsub requests require a specific to address for packets. - * - * @param connection The XMPP connection - * @param toAddress The pubsub specific to address (required for some servers) - */ - PubSubManager(XMPPConnection connection, BareJid toAddress) - { - super(connection); - pubSubService = toAddress; - } + /** + * Create a pubsub manager associated to the specified connection where + * the pubsub requests require a specific to address for packets. + * + * @param connection The XMPP connection + * @param toAddress The pubsub specific to address (required for some servers) + */ + PubSubManager(XMPPConnection connection, BareJid toAddress) + { + super(connection); + pubSubService = toAddress; + } - /** - * Creates an instant node, if supported. - * - * @return The node that was created - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws 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()); + /** + * Creates an instant node, if supported. + * + * @return The node that was created + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws 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()); - LeafNode newNode = new LeafNode(this, elem.getNode()); - nodeMap.put(newNode.getId(), newNode); + LeafNode newNode = new LeafNode(this, elem.getNode()); + nodeMap.put(newNode.getId(), newNode); - return newNode; - } + return newNode; + } - /** - * Creates a node with default configuration. - * - * @param nodeId The id of the node, which must be unique within the - * pubsub service - * @return The node that was created - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public LeafNode createNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - return (LeafNode) createNode(nodeId, null); - } + /** + * Creates a node with default configuration. + * + * @param nodeId The id of the node, which must be unique within the + * pubsub service + * @return The node that was created + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public LeafNode createNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + return (LeafNode) createNode(nodeId, null); + } - /** - * Creates a node with specified configuration. - * - * Note: This is the only way to create a collection node. - * - * @param nodeId The name of the node, which must be unique within the - * pubsub service - * @param config The configuration for the node - * @return The node that was created - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws 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; + /** + * Creates a node with specified configuration. + * + * Note: This is the only way to create a collection node. + * + * @param nodeId The name of the node, which must be unique within the + * pubsub service + * @param config The configuration for the node + * @return The node that was created + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws 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) - { - request.addExtension(new FormNode(FormNodeType.CONFIGURE, config)); - FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName()); + if (config != null) + { + request.addExtension(new FormNode(FormNodeType.CONFIGURE, config)); + FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName()); - if (nodeTypeField != null) - isLeafNode = nodeTypeField.getValues().get(0).equals(NodeType.leaf.toString()); - } + if (nodeTypeField != null) + isLeafNode = nodeTypeField.getValues().get(0).equals(NodeType.leaf.toString()); + } - // Errors will cause exceptions in getReply, so it only returns - // on success. - sendPubsubPacket(request); - Node newNode = isLeafNode ? new LeafNode(this, nodeId) : new CollectionNode(this, nodeId); - nodeMap.put(newNode.getId(), newNode); + // Errors will cause exceptions in getReply, so it only returns + // on success. + sendPubsubPacket(request); + Node newNode = isLeafNode ? new LeafNode(this, nodeId) : new CollectionNode(this, nodeId); + nodeMap.put(newNode.getId(), newNode); - return newNode; - } + return newNode; + } - /** - * Retrieves the requested node, if it exists. It will throw an - * exception if it does not. - * - * @param id - The unique id of the node - * @return the node - * @throws XMPPErrorException The node does not exist - * @throws NoResponseException if there was no response from the server. - * @throws NotConnectedException - * @throws InterruptedException - */ + /** + * Retrieves the requested node, if it exists. It will throw an + * exception if it does not. + * + * @param id - The unique id of the node + * @return the node + * @throws XMPPErrorException The node does not exist + * @throws NoResponseException if there was no response from the server. + * @throws NotConnectedException + * @throws InterruptedException + */ public T getNode(String id) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - Node node = nodeMap.get(id); + { + Node node = nodeMap.get(id); - if (node == null) - { - DiscoverInfo info = new DiscoverInfo(); - info.setTo(pubSubService); - info.setNode(id); + if (node == null) + { + DiscoverInfo info = new DiscoverInfo(); + info.setTo(pubSubService); + info.setNode(id); - DiscoverInfo infoReply = connection().createStanzaCollectorAndSend(info).nextResultOrThrow(); + DiscoverInfo infoReply = connection().createStanzaCollectorAndSend(info).nextResultOrThrow(); if (infoReply.hasIdentity(PubSub.ELEMENT, "leaf")) { node = new LeafNode(this, id); @@ -253,104 +253,104 @@ public final class PubSubManager extends Manager { + id + "', but it did not contain an Identity of type 'leaf' or 'collection' (and category 'pubsub'), which is not allowed according to XEP-60 5.3."); } - nodeMap.put(id, node); - } - @SuppressWarnings("unchecked") - T res = (T) node; - return res; - } + nodeMap.put(id, node); + } + @SuppressWarnings("unchecked") + T res = (T) node; + return res; + } - /** - * Get all the nodes that currently exist as a child of the specified - * collection node. If the service does not support collection nodes - * then all nodes will be returned. - * - * To retrieve contents of the root collection node (if it exists), - * or there is no root collection node, pass null as the nodeId. - * - * @param nodeId - The id of the collection node for which the child - * nodes will be returned. - * @return {@link DiscoverItems} representing the existing nodes - * @throws XMPPErrorException - * @throws NoResponseException if there was no response from the server. - * @throws NotConnectedException - * @throws InterruptedException - */ - public DiscoverItems discoverNodes(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - DiscoverItems items = new DiscoverItems(); + /** + * Get all the nodes that currently exist as a child of the specified + * collection node. If the service does not support collection nodes + * then all nodes will be returned. + * + * To retrieve contents of the root collection node (if it exists), + * or there is no root collection node, pass null as the nodeId. + * + * @param nodeId - The id of the collection node for which the child + * nodes will be returned. + * @return {@link DiscoverItems} representing the existing nodes + * @throws XMPPErrorException + * @throws NoResponseException if there was no response from the server. + * @throws NotConnectedException + * @throws InterruptedException + */ + public DiscoverItems discoverNodes(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + DiscoverItems items = new DiscoverItems(); - if (nodeId != null) - items.setNode(nodeId); - items.setTo(pubSubService); - DiscoverItems nodeItems = connection().createStanzaCollectorAndSend(items).nextResultOrThrow(); - return nodeItems; - } + if (nodeId != null) + items.setNode(nodeId); + items.setTo(pubSubService); + DiscoverItems nodeItems = connection().createStanzaCollectorAndSend(items).nextResultOrThrow(); + return nodeItems; + } - /** - * Gets the subscriptions on the root node. - * - * @return List of exceptions - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public List 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(); - } + /** + * Gets the subscriptions on the root node. + * + * @return List of exceptions + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public List 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(); + } - /** - * Gets the affiliations on the root node. - * - * @return List of affiliations - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - * - */ - public List 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(); - } + /** + * Gets the affiliations on the root node. + * + * @return List of affiliations + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + * + */ + public List 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(); + } - /** - * Delete the specified node. - * - * @param nodeId - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws 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); - } + /** + * Delete the specified node. + * + * @param nodeId + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws 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); + } - /** - * Returns the default settings for Node configuration. - * - * @return configuration form containing the default settings. - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws 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()); - return NodeUtils.getFormFromPacket(reply, PubSubElementType.DEFAULT); - } + /** + * Returns the default settings for Node configuration. + * + * @return configuration form containing the default settings. + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws 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()); + return NodeUtils.getFormFromPacket(reply, PubSubElementType.DEFAULT); + } /** * Get the JID of the PubSub service managed by this manager. @@ -361,21 +361,21 @@ public final class PubSubManager extends Manager { return pubSubService; } - /** - * Gets the supported features of the servers pubsub implementation - * as a standard {@link DiscoverInfo} instance. - * - * @return The supported features - * @throws XMPPErrorException - * @throws NoResponseException - * @throws NotConnectedException - * @throws InterruptedException - */ - public DiscoverInfo getSupportedFeatures() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException - { - ServiceDiscoveryManager mgr = ServiceDiscoveryManager.getInstanceFor(connection()); - return mgr.discoverInfo(pubSubService); - } + /** + * Gets the supported features of the servers pubsub implementation + * as a standard {@link DiscoverInfo} instance. + * + * @return The supported features + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + */ + public DiscoverInfo getSupportedFeatures() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException + { + ServiceDiscoveryManager mgr = ServiceDiscoveryManager.getInstanceFor(connection()); + return mgr.discoverInfo(pubSubService); + } /** * Check if it is possible to create PubSub nodes on this service. It could be possible that the @@ -424,13 +424,13 @@ public final class PubSubManager extends Manager { throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { // CHECKSTYLE:OFF - PubSub pubSub = new PubSub(to, type, ns); - for (ExtensionElement pe : extList) { - pubSub.addExtension(pe); - } + PubSub pubSub = new PubSub(to, type, ns); + for (ExtensionElement pe : extList) { + pubSub.addExtension(pe); + } // CHECKSTYLE:ON return sendPubsubPacket(pubSub); - } + } PubSub sendPubsubPacket(PubSub packet) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { @@ -439,7 +439,7 @@ public final class PubSubManager extends Manager { return null; } return (PubSub) resultIQ; - } + } /** * Get the "default" PubSub service for a given XMPP connection. The default PubSub service is diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PublishItem.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PublishItem.java index 8eb63c723..7229fb8a4 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PublishItem.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PublishItem.java @@ -26,48 +26,48 @@ import java.util.Collection; */ public class PublishItem extends NodeExtension { - protected Collection items; + protected Collection items; - /** - * Construct a request to publish an item to a node. - * - * @param nodeId The node to publish to - * @param toPublish The {@link Item} to publish - */ - public PublishItem(String nodeId, T toPublish) - { - super(PubSubElementType.PUBLISH, nodeId); - items = new ArrayList(1); - items.add(toPublish); - } + /** + * Construct a request to publish an item to a node. + * + * @param nodeId The node to publish to + * @param toPublish The {@link Item} to publish + */ + public PublishItem(String nodeId, T toPublish) + { + super(PubSubElementType.PUBLISH, nodeId); + items = new ArrayList(1); + items.add(toPublish); + } - /** - * Construct a request to publish multiple items to a node. - * - * @param nodeId The node to publish to - * @param toPublish The list of {@link Item} to publish - */ - public PublishItem(String nodeId, Collection toPublish) - { - super(PubSubElementType.PUBLISH, nodeId); - items = toPublish; - } + /** + * Construct a request to publish multiple items to a node. + * + * @param nodeId The node to publish to + * @param toPublish The list of {@link Item} to publish + */ + public PublishItem(String nodeId, Collection toPublish) + { + super(PubSubElementType.PUBLISH, nodeId); + items = toPublish; + } - @Override - public String toXML() - { - StringBuilder builder = new StringBuilder("<"); - builder.append(getElementName()); - builder.append(" node='"); - builder.append(getNode()); - builder.append("'>"); + @Override + public String toXML() + { + StringBuilder builder = new StringBuilder("<"); + builder.append(getElementName()); + builder.append(" node='"); + builder.append(getNode()); + builder.append("'>"); - for (Item item : items) - { - builder.append(item.toXML()); - } - builder.append(""); + for (Item item : items) + { + builder.append(item.toXML()); + } + builder.append(""); - return builder.toString(); - } + return builder.toString(); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PublishModel.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PublishModel.java index 5e26ac7f9..4e207ddb1 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PublishModel.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/PublishModel.java @@ -24,12 +24,12 @@ package org.jivesoftware.smackx.pubsub; */ public enum PublishModel { - /** Only publishers may publish. */ - publishers, + /** Only publishers may publish. */ + publishers, - /** Only subscribers may publish. */ - subscribers, + /** Only subscribers may publish. */ + subscribers, - /** Anyone may publish. */ - open; + /** Anyone may publish. */ + open; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/RetractItem.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/RetractItem.java index 8d21e93ce..e26bfbac7 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/RetractItem.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/RetractItem.java @@ -26,37 +26,37 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace; */ public class RetractItem implements ExtensionElement { - private String id; + private String id; - /** - * Construct a RetractItem with the specified id. - * - * @param itemId The id if the item deleted - */ - public RetractItem(String itemId) - { - if (itemId == null) - throw new IllegalArgumentException("itemId must not be 'null'"); - id = itemId; - } + /** + * Construct a RetractItem with the specified id. + * + * @param itemId The id if the item deleted + */ + public RetractItem(String itemId) + { + if (itemId == null) + throw new IllegalArgumentException("itemId must not be 'null'"); + id = itemId; + } - public String getId() - { - return id; - } + public String getId() + { + return id; + } - public String getElementName() - { - return "retract"; - } + public String getElementName() + { + return "retract"; + } - public String getNamespace() - { - return PubSubNamespace.EVENT.getXmlns(); - } + public String getNamespace() + { + return PubSubNamespace.EVENT.getXmlns(); + } - public String toXML() - { - return ""; - } + public String toXML() + { + return ""; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SimplePayload.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SimplePayload.java index a142b49db..9e92949e2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SimplePayload.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SimplePayload.java @@ -26,44 +26,44 @@ import org.jivesoftware.smack.packet.ExtensionElement; */ public class SimplePayload implements ExtensionElement { - private final String elemName; - private final String ns; - private final CharSequence payload; + private final String elemName; + private final String ns; + private final CharSequence payload; - /** - * Construct a SimplePayload object with the specified element name, - * namespace and content. The content must be well formed XML. - * - * @param elementName The root element name (of the payload) - * @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) - { - elemName = elementName; - payload = xmlPayload; - ns = namespace; - } + /** + * Construct a SimplePayload object with the specified element name, + * namespace and content. The content must be well formed XML. + * + * @param elementName The root element name (of the payload) + * @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) + { + elemName = elementName; + payload = xmlPayload; + ns = namespace; + } - public String getElementName() - { - return elemName; - } + public String getElementName() + { + return elemName; + } - public String getNamespace() - { - return ns; - } + public String getNamespace() + { + return ns; + } - @Override - public CharSequence toXML() - { - return payload; - } + @Override + public CharSequence toXML() + { + return payload; + } - @Override - public String toString() - { - return getClass().getName() + "payload [" + toXML() + "]"; - } + @Override + public String toString() + { + return getClass().getName() + "payload [" + toXML() + "]"; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeExtension.java index 08485ab7d..ca4f82b6a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeExtension.java @@ -23,41 +23,41 @@ package org.jivesoftware.smackx.pubsub; */ public class SubscribeExtension extends NodeExtension { - protected String jid; + protected String jid; - public SubscribeExtension(String subscribeJid) - { - super(PubSubElementType.SUBSCRIBE); - jid = subscribeJid; - } + public SubscribeExtension(String subscribeJid) + { + super(PubSubElementType.SUBSCRIBE); + jid = subscribeJid; + } - public SubscribeExtension(String subscribeJid, String nodeId) - { - super(PubSubElementType.SUBSCRIBE, nodeId); - jid = subscribeJid; - } + public SubscribeExtension(String subscribeJid, String nodeId) + { + super(PubSubElementType.SUBSCRIBE, nodeId); + jid = subscribeJid; + } - public String getJid() - { - return jid; - } + public String getJid() + { + return jid; + } - @Override - public String toXML() - { - StringBuilder builder = new StringBuilder("<"); - builder.append(getElementName()); + @Override + public String toXML() + { + StringBuilder builder = new StringBuilder("<"); + builder.append(getElementName()); - if (getNode() != null) - { - builder.append(" node='"); - builder.append(getNode()); - builder.append('\''); - } - builder.append(" jid='"); - builder.append(getJid()); - builder.append("'/>"); + if (getNode() != null) + { + builder.append(" node='"); + builder.append(getNode()); + builder.append('\''); + } + builder.append(" jid='"); + builder.append(getJid()); + builder.append("'/>"); - return builder.toString(); - } + return builder.toString(); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java index 00397dc62..d6a1ff84d 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java @@ -40,202 +40,202 @@ import org.jivesoftware.smackx.xdata.packet.DataForm; */ public class SubscribeForm extends Form { - public SubscribeForm(DataForm configDataForm) - { - super(configDataForm); - } + public SubscribeForm(DataForm configDataForm) + { + super(configDataForm); + } - public SubscribeForm(Form subscribeOptionsForm) - { - super(subscribeOptionsForm.getDataFormToSend()); - } + public SubscribeForm(Form subscribeOptionsForm) + { + super(subscribeOptionsForm.getDataFormToSend()); + } - public SubscribeForm(DataForm.Type formType) - { - super(formType); - } + public SubscribeForm(DataForm.Type formType) + { + super(formType); + } - /** - * Determines if an entity wants to receive notifications. - * - * @return true if want to receive, false otherwise - */ - public boolean isDeliverOn() - { - return parseBoolean(getFieldValue(SubscribeOptionFields.deliver)); - } + /** + * Determines if an entity wants to receive notifications. + * + * @return true if want to receive, false otherwise + */ + public boolean isDeliverOn() + { + return parseBoolean(getFieldValue(SubscribeOptionFields.deliver)); + } - /** - * Sets whether an entity wants to receive notifications. - * - * @param deliverNotifications - */ - public void setDeliverOn(boolean deliverNotifications) - { - addField(SubscribeOptionFields.deliver, FormField.Type.bool); - setAnswer(SubscribeOptionFields.deliver.getFieldName(), deliverNotifications); - } + /** + * Sets whether an entity wants to receive notifications. + * + * @param deliverNotifications + */ + public void setDeliverOn(boolean deliverNotifications) + { + addField(SubscribeOptionFields.deliver, FormField.Type.bool); + setAnswer(SubscribeOptionFields.deliver.getFieldName(), deliverNotifications); + } - /** - * Determines if notifications should be delivered as aggregations or not. - * - * @return true to aggregate, false otherwise - */ - public boolean isDigestOn() - { - return parseBoolean(getFieldValue(SubscribeOptionFields.digest)); - } + /** + * Determines if notifications should be delivered as aggregations or not. + * + * @return true to aggregate, false otherwise + */ + public boolean isDigestOn() + { + return parseBoolean(getFieldValue(SubscribeOptionFields.digest)); + } - /** - * Sets whether notifications should be delivered as aggregations or not. - * - * @param digestOn true to aggregate, false otherwise - */ - public void setDigestOn(boolean digestOn) - { - addField(SubscribeOptionFields.deliver, FormField.Type.bool); - setAnswer(SubscribeOptionFields.deliver.getFieldName(), digestOn); - } + /** + * Sets whether notifications should be delivered as aggregations or not. + * + * @param digestOn true to aggregate, false otherwise + */ + public void setDigestOn(boolean digestOn) + { + addField(SubscribeOptionFields.deliver, FormField.Type.bool); + setAnswer(SubscribeOptionFields.deliver.getFieldName(), digestOn); + } - /** - * Gets the minimum number of milliseconds between sending notification digests. - * - * @return The frequency in milliseconds - */ - public int getDigestFrequency() - { - return Integer.parseInt(getFieldValue(SubscribeOptionFields.digest_frequency)); - } + /** + * Gets the minimum number of milliseconds between sending notification digests. + * + * @return The frequency in milliseconds + */ + public int getDigestFrequency() + { + return Integer.parseInt(getFieldValue(SubscribeOptionFields.digest_frequency)); + } - /** - * Sets the minimum number of milliseconds between sending notification digests. - * - * @param frequency The frequency in milliseconds - */ - public void setDigestFrequency(int frequency) - { - addField(SubscribeOptionFields.digest_frequency, FormField.Type.text_single); - setAnswer(SubscribeOptionFields.digest_frequency.getFieldName(), frequency); - } + /** + * Sets the minimum number of milliseconds between sending notification digests. + * + * @param frequency The frequency in milliseconds + */ + public void setDigestFrequency(int frequency) + { + addField(SubscribeOptionFields.digest_frequency, FormField.Type.text_single); + setAnswer(SubscribeOptionFields.digest_frequency.getFieldName(), frequency); + } - /** - * Get the time at which the leased subscription will expire, or has expired. - * - * @return The expiry date - */ - public Date getExpiry() - { - String dateTime = getFieldValue(SubscribeOptionFields.expire); - try - { - return XmppDateTime.parseDate(dateTime); - } - catch (ParseException e) - { - UnknownFormatConversionException exc = new UnknownFormatConversionException(dateTime); - exc.initCause(e); - throw exc; - } - } + /** + * Get the time at which the leased subscription will expire, or has expired. + * + * @return The expiry date + */ + public Date getExpiry() + { + String dateTime = getFieldValue(SubscribeOptionFields.expire); + try + { + return XmppDateTime.parseDate(dateTime); + } + catch (ParseException e) + { + UnknownFormatConversionException exc = new UnknownFormatConversionException(dateTime); + exc.initCause(e); + throw exc; + } + } - /** - * Sets the time at which the leased subscription will expire, or has expired. - * - * @param expire The expiry date - */ - public void setExpiry(Date expire) - { - addField(SubscribeOptionFields.expire, FormField.Type.text_single); - setAnswer(SubscribeOptionFields.expire.getFieldName(), XmppDateTime.formatXEP0082Date(expire)); - } + /** + * Sets the time at which the leased subscription will expire, or has expired. + * + * @param expire The expiry date + */ + public void setExpiry(Date expire) + { + addField(SubscribeOptionFields.expire, FormField.Type.text_single); + setAnswer(SubscribeOptionFields.expire.getFieldName(), XmppDateTime.formatXEP0082Date(expire)); + } - /** - * Determines whether the entity wants to receive an XMPP message body in - * addition to the payload format. - * - * @return true to receive the message body, false otherwise - */ - public boolean isIncludeBody() - { - return parseBoolean(getFieldValue(SubscribeOptionFields.include_body)); - } + /** + * Determines whether the entity wants to receive an XMPP message body in + * addition to the payload format. + * + * @return true to receive the message body, false otherwise + */ + public boolean isIncludeBody() + { + return parseBoolean(getFieldValue(SubscribeOptionFields.include_body)); + } - /** - * Sets whether the entity wants to receive an XMPP message body in - * addition to the payload format. - * - * @param include true to receive the message body, false otherwise - */ - public void setIncludeBody(boolean include) - { - addField(SubscribeOptionFields.include_body, FormField.Type.bool); - setAnswer(SubscribeOptionFields.include_body.getFieldName(), include); - } + /** + * Sets whether the entity wants to receive an XMPP message body in + * addition to the payload format. + * + * @param include true to receive the message body, false otherwise + */ + public void setIncludeBody(boolean include) + { + addField(SubscribeOptionFields.include_body, FormField.Type.bool); + setAnswer(SubscribeOptionFields.include_body.getFieldName(), include); + } - /** - * Gets the {@link PresenceState} for which an entity wants to receive - * notifications. - * - * @return the list of states - */ - public List getShowValues() - { - ArrayList result = new ArrayList(5); + /** + * Gets the {@link PresenceState} for which an entity wants to receive + * notifications. + * + * @return the list of states + */ + public List getShowValues() + { + ArrayList result = new ArrayList(5); - for (String state : getFieldValues(SubscribeOptionFields.show_values)) - { - result.add(PresenceState.valueOf(state)); - } - return result; - } + for (String state : getFieldValues(SubscribeOptionFields.show_values)) + { + result.add(PresenceState.valueOf(state)); + } + return result; + } - /** - * Sets the list of {@link PresenceState} for which an entity wants - * to receive notifications. - * - * @param stateValues The list of states - */ - public void setShowValues(Collection stateValues) - { - ArrayList values = new ArrayList(stateValues.size()); + /** + * Sets the list of {@link PresenceState} for which an entity wants + * to receive notifications. + * + * @param stateValues The list of states + */ + public void setShowValues(Collection stateValues) + { + ArrayList values = new ArrayList(stateValues.size()); - for (PresenceState state : stateValues) - { - values.add(state.toString()); - } - addField(SubscribeOptionFields.show_values, FormField.Type.list_multi); - setAnswer(SubscribeOptionFields.show_values.getFieldName(), values); - } + for (PresenceState state : stateValues) + { + values.add(state.toString()); + } + addField(SubscribeOptionFields.show_values, FormField.Type.list_multi); + setAnswer(SubscribeOptionFields.show_values.getFieldName(), values); + } - static private boolean parseBoolean(String fieldValue) - { - return ("1".equals(fieldValue) || "true".equals(fieldValue)); - } + static private boolean parseBoolean(String fieldValue) + { + return ("1".equals(fieldValue) || "true".equals(fieldValue)); + } - private String getFieldValue(SubscribeOptionFields field) - { - FormField formField = getField(field.getFieldName()); + private String getFieldValue(SubscribeOptionFields field) + { + FormField formField = getField(field.getFieldName()); - return formField.getValues().get(0); - } + return formField.getValues().get(0); + } - private List getFieldValues(SubscribeOptionFields field) - { - FormField formField = getField(field.getFieldName()); + private List getFieldValues(SubscribeOptionFields field) + { + FormField formField = getField(field.getFieldName()); - return formField.getValues(); - } + return formField.getValues(); + } - private void addField(SubscribeOptionFields nodeField, FormField.Type type) - { - String fieldName = nodeField.getFieldName(); + private void addField(SubscribeOptionFields nodeField, FormField.Type type) + { + String fieldName = nodeField.getFieldName(); - if (getField(fieldName) == null) - { - FormField field = new FormField(fieldName); - field.setType(type); - addField(field); - } - } + if (getField(fieldName) == null) + { + FormField field = new FormField(fieldName); + field.setType(type); + addField(field); + } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeOptionFields.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeOptionFields.java index e1c2f84bd..c3ba4a6a2 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeOptionFields.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeOptionFields.java @@ -26,77 +26,77 @@ import java.util.Calendar; */ public enum SubscribeOptionFields { - /** - * Whether an entity wants to receive or disable notifications. - * - *

Value: boolean

- */ - deliver, + /** + * Whether an entity wants to receive or disable notifications. + * + *

Value: boolean

+ */ + deliver, - /** - * Whether an entity wants to receive digests (aggregations) of - * notifications or all notifications individually. - * - *

Value: boolean

- */ - digest, + /** + * Whether an entity wants to receive digests (aggregations) of + * notifications or all notifications individually. + * + *

Value: boolean

+ */ + digest, - /** - * The minimum number of seconds between sending any two notifications digests. - * - *

Value: int

- */ - digest_frequency, + /** + * The minimum number of seconds between sending any two notifications digests. + * + *

Value: int

+ */ + digest_frequency, - /** - * Expire. - *

Value: {@link Calendar}

- */ - expire, + /** + * Expire. + *

Value: {@link Calendar}

+ */ + expire, - /** - * Whether an entity wants to receive an XMPP message body in addition to - * the payload format. - * - *

Value: boolean

- */ - include_body, + /** + * Whether an entity wants to receive an XMPP message body in addition to + * the payload format. + * + *

Value: boolean

+ */ + include_body, - /** - * The presence states for which an entity wants to receive notifications. - * - *

Value: {@link PresenceState}

- */ - show_values, + /** + * The presence states for which an entity wants to receive notifications. + * + *

Value: {@link PresenceState}

+ */ + show_values, - /** - * Subscription type. - * - *

Value:

- */ - subscription_type, + /** + * Subscription type. + * + *

Value:

+ */ + subscription_type, - /** - * Subscription depth. - * - *

Value:

- */ - subscription_depth; + /** + * Subscription depth. + * + *

Value:

+ */ + subscription_depth; - public String getFieldName() - { - if (this == show_values) - return "pubsub#" + toString().replace('_', '-'); - return "pubsub#" + toString(); - } + public String getFieldName() + { + if (this == show_values) + return "pubsub#" + toString().replace('_', '-'); + return "pubsub#" + toString(); + } - static public SubscribeOptionFields valueOfFromElement(String elementName) - { - String portion = elementName.substring(elementName.lastIndexOf('#' + 1)); + static public SubscribeOptionFields valueOfFromElement(String elementName) + { + String portion = elementName.substring(elementName.lastIndexOf('#' + 1)); - if ("show-values".equals(portion)) - return show_values; - else - return valueOf(portion); - } + if ("show-values".equals(portion)) + return show_values; + else + return valueOf(portion); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Subscription.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Subscription.java index 4308639bc..cf349e6f8 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Subscription.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/Subscription.java @@ -23,141 +23,141 @@ package org.jivesoftware.smackx.pubsub; */ public class Subscription extends NodeExtension { - protected String jid; - protected String id; - protected State state; - protected boolean configRequired = false; + protected String jid; + protected String id; + protected State state; + protected boolean configRequired = false; - public enum State - { - subscribed, unconfigured, pending, none - } + public enum State + { + subscribed, unconfigured, pending, none + } - /** - * Used to constructs a subscription request to the root node with the specified - * JID. - * - * @param subscriptionJid The subscriber JID - */ - public Subscription(String subscriptionJid) - { - this(subscriptionJid, null, null, null); - } + /** + * Used to constructs a subscription request to the root node with the specified + * JID. + * + * @param subscriptionJid The subscriber JID + */ + public Subscription(String subscriptionJid) + { + this(subscriptionJid, null, null, null); + } - /** - * Used to constructs a subscription request to the specified node with the specified - * JID. - * - * @param subscriptionJid The subscriber JID - * @param nodeId The node id - */ - public Subscription(String subscriptionJid, String nodeId) - { - this(subscriptionJid, nodeId, null, null); - } + /** + * Used to constructs a subscription request to the specified node with the specified + * JID. + * + * @param subscriptionJid The subscriber JID + * @param nodeId The node id + */ + public Subscription(String subscriptionJid, String nodeId) + { + this(subscriptionJid, nodeId, null, null); + } - /** - * Constructs a representation of a subscription reply to the specified node - * and JID. The server will have supplied the subscription id and current state. - * - * @param jid The JID the request was made under - * @param nodeId The node subscribed to - * @param subscriptionId The id of this subscription - * @param state The current state of the subscription - */ - public Subscription(String jid, String nodeId, String subscriptionId, State state) - { - super(PubSubElementType.SUBSCRIPTION, nodeId); - this.jid = jid; - id = subscriptionId; - this.state = state; - } + /** + * Constructs a representation of a subscription reply to the specified node + * and JID. The server will have supplied the subscription id and current state. + * + * @param jid The JID the request was made under + * @param nodeId The node subscribed to + * @param subscriptionId The id of this subscription + * @param state The current state of the subscription + */ + public Subscription(String jid, String nodeId, String subscriptionId, State state) + { + super(PubSubElementType.SUBSCRIPTION, nodeId); + this.jid = jid; + id = subscriptionId; + this.state = state; + } - /** - * Constructs a representation of a subscription reply to the specified node - * and JID. The server will have supplied the subscription id and current state - * and whether the subscription need to be configured. - * - * @param jid The JID the request was made under - * @param nodeId The node subscribed to - * @param subscriptionId The id of this subscription - * @param state The current state of the subscription - * @param configRequired Is configuration required to complete the subscription - */ - public Subscription(String jid, String nodeId, String subscriptionId, State state, boolean configRequired) - { - super(PubSubElementType.SUBSCRIPTION, nodeId); - this.jid = jid; - id = subscriptionId; - this.state = state; - this.configRequired = configRequired; - } + /** + * Constructs a representation of a subscription reply to the specified node + * and JID. The server will have supplied the subscription id and current state + * and whether the subscription need to be configured. + * + * @param jid The JID the request was made under + * @param nodeId The node subscribed to + * @param subscriptionId The id of this subscription + * @param state The current state of the subscription + * @param configRequired Is configuration required to complete the subscription + */ + public Subscription(String jid, String nodeId, String subscriptionId, State state, boolean configRequired) + { + super(PubSubElementType.SUBSCRIPTION, nodeId); + this.jid = jid; + id = subscriptionId; + this.state = state; + this.configRequired = configRequired; + } - /** - * Gets the JID the subscription is created for. - * - * @return The JID - */ - public String getJid() - { - return jid; - } + /** + * Gets the JID the subscription is created for. + * + * @return The JID + */ + public String getJid() + { + return jid; + } - /** - * Gets the subscription id. - * - * @return The subscription id - */ - public String getId() - { - return id; - } + /** + * Gets the subscription id. + * + * @return The subscription id + */ + public String getId() + { + return id; + } - /** - * Gets the current subscription state. - * - * @return Current subscription state - */ - public State getState() - { - return state; - } + /** + * Gets the current subscription state. + * + * @return Current subscription state + */ + public State getState() + { + return state; + } - /** - * This value is only relevant when the {@link #getState()} is {@link State#unconfigured}. - * - * @return true if configuration is required, false otherwise - */ - public boolean isConfigRequired() - { - return configRequired; - } + /** + * This value is only relevant when the {@link #getState()} is {@link State#unconfigured}. + * + * @return true if configuration is required, false otherwise + */ + public boolean isConfigRequired() + { + return configRequired; + } - public String toXML() - { - StringBuilder builder = new StringBuilder(""); - return builder.toString(); - } + builder.append("/>"); + return builder.toString(); + } - private static void appendAttribute(StringBuilder builder, String att, String value) - { - builder.append(' '); - builder.append(att); - builder.append("='"); - builder.append(value); - builder.append('\''); - } + private static void appendAttribute(StringBuilder builder, String att, String value) + { + builder.append(' '); + builder.append(att); + builder.append("='"); + builder.append(value); + builder.append('\''); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscriptionEvent.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscriptionEvent.java index adcfc3918..2d087847c 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscriptionEvent.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscriptionEvent.java @@ -26,53 +26,53 @@ import java.util.List; */ abstract public class SubscriptionEvent extends NodeEvent { - private List subIds = Collections.emptyList(); + private List subIds = Collections.emptyList(); - /** - * Construct an event with no subscription id's. This can - * occur when there is only one subscription to a node. The - * event may or may not report the subscription id along - * with the event. - * - * @param nodeId The id of the node the event came from - */ - protected SubscriptionEvent(String nodeId) - { - super(nodeId); - } + /** + * Construct an event with no subscription id's. This can + * occur when there is only one subscription to a node. The + * event may or may not report the subscription id along + * with the event. + * + * @param nodeId The id of the node the event came from + */ + protected SubscriptionEvent(String nodeId) + { + super(nodeId); + } - /** - * Construct an event with multiple subscriptions. - * - * @param nodeId The id of the node the event came from - * @param subscriptionIds The list of subscription id's - */ - protected SubscriptionEvent(String nodeId, List subscriptionIds) - { - super(nodeId); + /** + * Construct an event with multiple subscriptions. + * + * @param nodeId The id of the node the event came from + * @param subscriptionIds The list of subscription id's + */ + protected SubscriptionEvent(String nodeId, List subscriptionIds) + { + super(nodeId); - if (subscriptionIds != null) - subIds = subscriptionIds; - } + if (subscriptionIds != null) + subIds = subscriptionIds; + } - /** - * Get the subscriptions this event is associated with. - * - * @return List of subscription id's - */ - public List getSubscriptions() - { - return Collections.unmodifiableList(subIds); - } + /** + * Get the subscriptions this event is associated with. + * + * @return List of subscription id's + */ + public List getSubscriptions() + { + return Collections.unmodifiableList(subIds); + } - /** - * Set the list of subscription id's for this event. - * - * @param subscriptionIds The list of subscription id's - */ - protected void setSubscriptions(List subscriptionIds) - { - if (subscriptionIds != null) - subIds = subscriptionIds; - } + /** + * Set the list of subscription id's for this event. + * + * @param subscriptionIds The list of subscription id's + */ + protected void setSubscriptions(List subscriptionIds) + { + if (subscriptionIds != null) + subIds = subscriptionIds; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscriptionsExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscriptionsExtension.java index dad68e891..59b64f16f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscriptionsExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscriptionsExtension.java @@ -26,74 +26,74 @@ import java.util.List; */ public class SubscriptionsExtension extends NodeExtension { - protected List items = Collections.emptyList(); + protected List items = Collections.emptyList(); - /** - * Subscriptions to the root node. - * - * @param subList The list of subscriptions - */ - public SubscriptionsExtension(List subList) - { - super(PubSubElementType.SUBSCRIPTIONS); + /** + * Subscriptions to the root node. + * + * @param subList The list of subscriptions + */ + public SubscriptionsExtension(List subList) + { + super(PubSubElementType.SUBSCRIPTIONS); - if (subList != null) - items = subList; - } + if (subList != null) + items = subList; + } - /** - * Subscriptions to the specified node. - * - * @param nodeId The node subscribed to - * @param subList The list of subscriptions - */ - public SubscriptionsExtension(String nodeId, List subList) - { - super(PubSubElementType.SUBSCRIPTIONS, nodeId); + /** + * Subscriptions to the specified node. + * + * @param nodeId The node subscribed to + * @param subList The list of subscriptions + */ + public SubscriptionsExtension(String nodeId, List subList) + { + super(PubSubElementType.SUBSCRIPTIONS, nodeId); - if (subList != null) - items = subList; - } + if (subList != null) + items = subList; + } - /** - * Gets the list of subscriptions. - * - * @return List of subscriptions - */ - public List getSubscriptions() - { - return items; - } + /** + * Gets the list of subscriptions. + * + * @return List of subscriptions + */ + public List getSubscriptions() + { + return items; + } - @Override - public CharSequence toXML() - { - if ((items == null) || (items.size() == 0)) - { - return super.toXML(); - } - else - { - StringBuilder builder = new StringBuilder("<"); - builder.append(getElementName()); + @Override + public CharSequence toXML() + { + if ((items == null) || (items.size() == 0)) + { + return super.toXML(); + } + else + { + StringBuilder builder = new StringBuilder("<"); + builder.append(getElementName()); - if (getNode() != null) - { - builder.append(" node='"); - builder.append(getNode()); - builder.append('\''); - } - builder.append('>'); + if (getNode() != null) + { + builder.append(" node='"); + builder.append(getNode()); + builder.append('\''); + } + builder.append('>'); - for (Subscription item : items) - { - builder.append(item.toXML()); - } + for (Subscription item : items) + { + builder.append(item.toXML()); + } - builder.append("'); - return builder.toString(); - } - } + builder.append("'); + return builder.toString(); + } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/UnsubscribeExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/UnsubscribeExtension.java index db9103a6d..0e4d9c009 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/UnsubscribeExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/UnsubscribeExtension.java @@ -26,35 +26,35 @@ import org.jivesoftware.smack.util.XmlStringBuilder; */ public class UnsubscribeExtension extends NodeExtension { - protected String jid; - protected String id; + protected String jid; + protected String id; - public UnsubscribeExtension(String subscriptionJid) - { - this(subscriptionJid, null, null); - } + public UnsubscribeExtension(String subscriptionJid) + { + this(subscriptionJid, null, null); + } - public UnsubscribeExtension(String subscriptionJid, String nodeId) - { - this(subscriptionJid, nodeId, null); - } + public UnsubscribeExtension(String subscriptionJid, String nodeId) + { + this(subscriptionJid, nodeId, null); + } - public UnsubscribeExtension(String jid, String nodeId, String subscriptionId) - { - super(PubSubElementType.UNSUBSCRIBE, nodeId); - this.jid = jid; - id = subscriptionId; - } + public UnsubscribeExtension(String jid, String nodeId, String subscriptionId) + { + super(PubSubElementType.UNSUBSCRIBE, nodeId); + this.jid = jid; + id = subscriptionId; + } - public String getJid() - { - return jid; - } + public String getJid() + { + return jid; + } - public String getId() - { - return id; - } + public String getId() + { + return id; + } @Override public XmlStringBuilder toXML() { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/ItemDeleteListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/ItemDeleteListener.java index 24b9faef8..7b72ae52e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/ItemDeleteListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/ItemDeleteListener.java @@ -28,17 +28,17 @@ import org.jivesoftware.smackx.pubsub.LeafNode; */ public interface ItemDeleteListener { - /** - * Called when items are deleted from a node the listener is - * registered with. - * - * @param items The event with item deletion details - */ - void handleDeletedItems(ItemDeleteEvent items); + /** + * Called when items are deleted from a node the listener is + * registered with. + * + * @param items The event with item deletion details + */ + void handleDeletedItems(ItemDeleteEvent items); - /** - * Called when all items are deleted from a node the listener is - * registered with. - */ - void handlePurge(); + /** + * Called when all items are deleted from a node the listener is + * registered with. + */ + void handlePurge(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/ItemEventListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/ItemEventListener.java index 9724de58d..6d4c6a9a4 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/ItemEventListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/ItemEventListener.java @@ -29,11 +29,11 @@ import org.jivesoftware.smackx.pubsub.LeafNode; */ public interface ItemEventListener { - /** - * Called whenever an item is published to the node the listener - * is registered with. - * - * @param items The publishing details. - */ - void handlePublishedItems(ItemPublishEvent items); + /** + * Called whenever an item is published to the node the listener + * is registered with. + * + * @param items The publishing details. + */ + void handlePublishedItems(ItemPublishEvent items); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/NodeConfigListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/NodeConfigListener.java index 55a97d05c..03bd71d9a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/NodeConfigListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/listener/NodeConfigListener.java @@ -28,11 +28,11 @@ import org.jivesoftware.smackx.pubsub.LeafNode; */ public interface NodeConfigListener { - /** - * Called whenever the node the listener - * is registered with is configured. - * - * @param config The configuration details. - */ - void handleNodeConfiguration(ConfigurationEvent config); + /** + * Called whenever the node the listener + * is registered with is configured. + * + * @param config The configuration details. + */ + void handleNodeConfiguration(ConfigurationEvent config); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java index cf6e97efc..79bd54fbd 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSub.java @@ -33,11 +33,11 @@ public class PubSub extends IQ public static final String ELEMENT = "pubsub"; public static final String NAMESPACE = "http://jabber.org/protocol/pubsub"; - public PubSub() { + public PubSub() { super(ELEMENT, NAMESPACE); - } + } - public PubSub(PubSubNamespace ns) { + public PubSub(PubSubNamespace ns) { super(ELEMENT, ns.getXmlns()); } @@ -49,9 +49,9 @@ public class PubSub extends IQ @SuppressWarnings("unchecked") public PE getExtension(PubSubElementType elem) - { - return (PE) getExtension(elem.getElementName(), elem.getNamespace().getXmlns()); - } + { + return (PE) getExtension(elem.getElementName(), elem.getNamespace().getXmlns()); + } /** * Returns the XML representation of a pubsub element according the specification. diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSubNamespace.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSubNamespace.java index b8a16db83..da8822447 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSubNamespace.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/packet/PubSubNamespace.java @@ -26,45 +26,45 @@ import java.util.Locale; */ public enum PubSubNamespace { - BASIC(null), - ERROR("errors"), - EVENT("event"), - OWNER("owner"); + BASIC(null), + ERROR("errors"), + EVENT("event"), + OWNER("owner"); private final String fragment; private final String fullNamespace; - private PubSubNamespace(String fragment) - { - this.fragment = fragment; + private PubSubNamespace(String fragment) + { + this.fragment = fragment; if (fragment != null) { fullNamespace = PubSub.NAMESPACE + '#' + fragment; } else { fullNamespace = PubSub.NAMESPACE; } - } + } - public String getXmlns() - { + public String getXmlns() + { return fullNamespace; - } + } - public String getFragment() - { - return fragment; - } + public String getFragment() + { + return fragment; + } - public static PubSubNamespace valueOfFromXmlns(String ns) - { - int index = ns.lastIndexOf('#'); + public static PubSubNamespace valueOfFromXmlns(String ns) + { + int index = ns.lastIndexOf('#'); - if (index != -1) - { - String suffix = ns.substring(ns.lastIndexOf('#')+1); - return valueOf(suffix.toUpperCase(Locale.US)); - } - else - return BASIC; - } + if (index != -1) + { + String suffix = ns.substring(ns.lastIndexOf('#')+1); + return valueOf(suffix.toUpperCase(Locale.US)); + } + else + return BASIC; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/AffiliationsProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/AffiliationsProvider.java index 195cbc8a7..f1ba37f67 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/AffiliationsProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/AffiliationsProvider.java @@ -31,11 +31,11 @@ import org.jivesoftware.smackx.pubsub.AffiliationsExtension; * @author Robin Collier */public class AffiliationsProvider extends EmbeddedExtensionProvider { - @SuppressWarnings("unchecked") - @Override - protected AffiliationsExtension createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content) - { + @SuppressWarnings("unchecked") + @Override + protected AffiliationsExtension createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content) + { return new AffiliationsExtension((List)content); - } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/ConfigEventProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/ConfigEventProvider.java index e6cb6f7ca..bd3da7331 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/ConfigEventProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/ConfigEventProvider.java @@ -33,12 +33,12 @@ import org.jivesoftware.smackx.xdata.packet.DataForm; */ public class ConfigEventProvider extends EmbeddedExtensionProvider { - @Override - protected ConfigurationEvent createReturnExtension(String currentElement, String currentNamespace, Map attMap, List content) - { - if (content.size() == 0) - return new ConfigurationEvent(attMap.get("node")); - else - return new ConfigurationEvent(attMap.get("node"), new ConfigureForm((DataForm)content.iterator().next())); - } + @Override + protected ConfigurationEvent createReturnExtension(String currentElement, String currentNamespace, Map attMap, List content) + { + if (content.size() == 0) + return new ConfigurationEvent(attMap.get("node")); + else + return new ConfigurationEvent(attMap.get("node"), new ConfigureForm((DataForm)content.iterator().next())); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/EventProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/EventProvider.java index d4a237e57..2e252c2a0 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/EventProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/EventProvider.java @@ -33,11 +33,9 @@ import org.jivesoftware.smackx.pubsub.NodeExtension; */ public class EventProvider extends EmbeddedExtensionProvider { - @Override - protected EventElement createReturnExtension(String currentElement, String currentNamespace, Map attMap, List content) - { -// CHECKSTYLE:OFF - return new EventElement(EventElementType.valueOf(content.get(0).getElementName()), (NodeExtension)content.get(0)); -// CHECKSTYLE:ON - } + @Override + protected EventElement createReturnExtension(String currentElement, String currentNamespace, Map attMap, List content) + { + return new EventElement(EventElementType.valueOf(content.get(0).getElementName()), (NodeExtension)content.get(0)); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/FormNodeProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/FormNodeProvider.java index 86f16bd6e..2766d9334 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/FormNodeProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/FormNodeProvider.java @@ -34,9 +34,9 @@ import org.jivesoftware.smackx.xdata.packet.DataForm; */ public class FormNodeProvider extends EmbeddedExtensionProvider { - @Override - protected FormNode createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content) - { + @Override + protected FormNode createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content) + { return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form((DataForm)content.iterator().next())); - } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/ItemsProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/ItemsProvider.java index 6c52862d3..4e1f4c167 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/ItemsProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/ItemsProvider.java @@ -32,10 +32,10 @@ import org.jivesoftware.smackx.pubsub.ItemsExtension; public class ItemsProvider extends EmbeddedExtensionProvider { - @Override - protected ItemsExtension createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content) - { + @Override + protected ItemsExtension createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content) + { return new ItemsExtension(ItemsExtension.ItemsElementType.items, attributeMap.get("node"), content); - } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/PubSubProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/PubSubProvider.java index b23fd5ec1..e5938c63e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/PubSubProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/PubSubProvider.java @@ -53,5 +53,5 @@ public class PubSubProvider extends IQProvider } } return pubsub; - } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/RetractEventProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/RetractEventProvider.java index f329caf0d..c3d14fa70 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/RetractEventProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/RetractEventProvider.java @@ -32,10 +32,10 @@ import org.jivesoftware.smackx.pubsub.RetractItem; */ public class RetractEventProvider extends EmbeddedExtensionProvider { - @Override - protected RetractItem createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content) - { - return new RetractItem(attributeMap.get("id")); - } + @Override + protected RetractItem createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content) + { + return new RetractItem(attributeMap.get("id")); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SimpleNodeProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SimpleNodeProvider.java index 31782fa11..b2d853eca 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SimpleNodeProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SimpleNodeProvider.java @@ -32,9 +32,9 @@ import org.jivesoftware.smackx.pubsub.PubSubElementType; */ public class SimpleNodeProvider extends EmbeddedExtensionProvider { - @Override - protected NodeExtension createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content) - { + @Override + protected NodeExtension createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content) + { return new NodeExtension(PubSubElementType.valueOfFromElemName(currentElement, currentNamespace), attributeMap.get("node")); - } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionProvider.java index fd6ca04e0..afc7dfc57 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionProvider.java @@ -34,25 +34,25 @@ public class SubscriptionProvider extends ExtensionElementProvider @Override public Subscription parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { - String jid = parser.getAttributeValue(null, "jid"); - String nodeId = parser.getAttributeValue(null, "node"); - String subId = parser.getAttributeValue(null, "subid"); - String state = parser.getAttributeValue(null, "subscription"); - boolean isRequired = false; + String jid = parser.getAttributeValue(null, "jid"); + String nodeId = parser.getAttributeValue(null, "node"); + String subId = parser.getAttributeValue(null, "subid"); + String state = parser.getAttributeValue(null, "subscription"); + boolean isRequired = false; - int tag = parser.next(); + int tag = parser.next(); - if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("subscribe-options")) - { - tag = parser.next(); + if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("subscribe-options")) + { + tag = parser.next(); - if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("required")) - isRequired = true; + if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("required")) + isRequired = true; - while (tag != XmlPullParser.END_TAG && !parser.getName().equals("subscribe-options")) tag = parser.next(); - } - while (parser.getEventType() != XmlPullParser.END_TAG) parser.next(); - return new Subscription(jid, nodeId, subId, (state == null ? null : Subscription.State.valueOf(state)), isRequired); - } + while (tag != XmlPullParser.END_TAG && !parser.getName().equals("subscribe-options")) tag = parser.next(); + } + while (parser.getEventType() != XmlPullParser.END_TAG) parser.next(); + return new Subscription(jid, nodeId, subId, (state == null ? null : Subscription.State.valueOf(state)), isRequired); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionsProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionsProvider.java index 69e4fb183..d642df63b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionsProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/provider/SubscriptionsProvider.java @@ -32,11 +32,11 @@ import org.jivesoftware.smackx.pubsub.SubscriptionsExtension; */ public class SubscriptionsProvider extends EmbeddedExtensionProvider { - @SuppressWarnings("unchecked") - @Override - protected SubscriptionsExtension createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content) - { - return new SubscriptionsExtension(attributeMap.get("node"), (List)content); - } + @SuppressWarnings("unchecked") + @Override + protected SubscriptionsExtension createReturnExtension(String currentElement, String currentNamespace, Map attributeMap, List content) + { + return new SubscriptionsExtension(attributeMap.get("node"), (List)content); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/util/NodeUtils.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/util/NodeUtils.java index 0c7687c2d..acf67c68c 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/util/NodeUtils.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/util/NodeUtils.java @@ -29,17 +29,17 @@ import org.jivesoftware.smackx.xdata.Form; */ public class NodeUtils { - /** - * Get a {@link ConfigureForm} from a packet. - * - * @param packet - * @param elem - * @return The configuration form - */ - 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); - } + /** + * Get a {@link ConfigureForm} from a packet. + * + * @param packet + * @param elem + * @return The configuration form + */ + 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); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/si/packet/StreamInitiation.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/si/packet/StreamInitiation.java index d6879a580..097953d9e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/si/packet/StreamInitiation.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/si/packet/StreamInitiation.java @@ -404,9 +404,9 @@ public class StreamInitiation extends IQ { StringBuilder buf = new StringBuilder(); buf .append(""); - buf.append(data.toXML()); - buf.append(""); - return buf.toString(); - } - } + buf.append(data.toXML()); + buf.append(""); + return buf.toString(); + } + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/si/provider/StreamInitiationProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/si/provider/StreamInitiationProvider.java index 8563ebe0e..f19b458f3 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/si/provider/StreamInitiationProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/si/provider/StreamInitiationProvider.java @@ -41,51 +41,51 @@ public class StreamInitiationProvider extends IQProvider { @Override public StreamInitiation parse(XmlPullParser parser, int initialDepth) throws Exception { - boolean done = false; + boolean done = false; - // si - String id = parser.getAttributeValue("", "id"); - String mimeType = parser.getAttributeValue("", "mime-type"); + // si + String id = parser.getAttributeValue("", "id"); + String mimeType = parser.getAttributeValue("", "mime-type"); - StreamInitiation initiation = new StreamInitiation(); + StreamInitiation initiation = new StreamInitiation(); - // file - String name = null; - String size = null; - String hash = null; - String date = null; - String desc = null; - boolean isRanged = false; + // file + String name = null; + String size = null; + String hash = null; + String date = null; + String desc = null; + boolean isRanged = false; - // feature - DataForm form = null; - DataFormProvider dataFormProvider = new DataFormProvider(); + // feature + DataForm form = null; + DataFormProvider dataFormProvider = new DataFormProvider(); - int eventType; - String elementName; - String namespace; - while (!done) { - eventType = parser.next(); - elementName = parser.getName(); - namespace = parser.getNamespace(); - if (eventType == XmlPullParser.START_TAG) { - if (elementName.equals("file")) { - name = parser.getAttributeValue("", "name"); - size = parser.getAttributeValue("", "size"); - hash = parser.getAttributeValue("", "hash"); - date = parser.getAttributeValue("", "date"); - } else if (elementName.equals("desc")) { - desc = parser.nextText(); - } else if (elementName.equals("range")) { - isRanged = true; - } else if (elementName.equals("x") - && namespace.equals("jabber:x:data")) { - form = dataFormProvider.parse(parser); - } - } else if (eventType == XmlPullParser.END_TAG) { - if (elementName.equals("si")) { - done = true; - } else if (elementName.equals("file")) { + int eventType; + String elementName; + String namespace; + while (!done) { + eventType = parser.next(); + elementName = parser.getName(); + namespace = parser.getNamespace(); + if (eventType == XmlPullParser.START_TAG) { + if (elementName.equals("file")) { + name = parser.getAttributeValue("", "name"); + size = parser.getAttributeValue("", "size"); + hash = parser.getAttributeValue("", "hash"); + date = parser.getAttributeValue("", "date"); + } else if (elementName.equals("desc")) { + desc = parser.nextText(); + } else if (elementName.equals("range")) { + isRanged = true; + } else if (elementName.equals("x") + && namespace.equals("jabber:x:data")) { + form = dataFormProvider.parse(parser); + } + } else if (eventType == XmlPullParser.END_TAG) { + if (elementName.equals("si")) { + done = true; + } else if (elementName.equals("file")) { long fileSize = 0; if(size != null && size.trim().length() !=0){ try { @@ -106,21 +106,21 @@ public class StreamInitiationProvider extends IQProvider { } File file = new File(name, fileSize); - file.setHash(hash); - file.setDate(fileDate); - file.setDesc(desc); - file.setRanged(isRanged); - initiation.setFile(file); - } - } - } + file.setHash(hash); + file.setDate(fileDate); + file.setDesc(desc); + file.setRanged(isRanged); + initiation.setFile(file); + } + } + } - initiation.setSessionID(id); - initiation.setMimeType(mimeType); + initiation.setSessionID(id); + initiation.setMimeType(mimeType); - initiation.setFeatureNegotiationForm(form); + initiation.setFeatureNegotiationForm(form); - return initiation; - } + return initiation; + } } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java index a3686b1a8..1197aaa7b 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java @@ -41,56 +41,56 @@ import org.junit.Test; */ public class ConfigureFormTest { - @Test - public void checkChildrenAssocPolicy() - { - ConfigureForm form = new ConfigureForm(DataForm.Type.submit); - form.setChildrenAssociationPolicy(ChildrenAssociationPolicy.owners); - assertEquals(ChildrenAssociationPolicy.owners, form.getChildrenAssociationPolicy()); - } + @Test + public void checkChildrenAssocPolicy() + { + ConfigureForm form = new ConfigureForm(DataForm.Type.submit); + form.setChildrenAssociationPolicy(ChildrenAssociationPolicy.owners); + assertEquals(ChildrenAssociationPolicy.owners, form.getChildrenAssociationPolicy()); + } - @Test - public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException, InterruptedException - { - ThreadedDummyConnection con = ThreadedDummyConnection.newInstance(); - PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE); - DiscoverInfo info = new DiscoverInfo(); - Identity ident = new Identity("pubsub", null, "leaf"); - info.addIdentity(ident); - con.addIQReply(info); + @Test + public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException, InterruptedException + { + ThreadedDummyConnection con = ThreadedDummyConnection.newInstance(); + PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE); + DiscoverInfo info = new DiscoverInfo(); + Identity ident = new Identity("pubsub", null, "leaf"); + info.addIdentity(ident); + con.addIQReply(info); - Node node = mgr.getNode("princely_musings"); + Node node = mgr.getNode("princely_musings"); - PubSub errorIq = new PubSub(); - XMPPError.Builder error = XMPPError.getBuilder(Condition.forbidden); - errorIq.setError(error); - con.addIQReply(errorIq); + PubSub errorIq = new PubSub(); + XMPPError.Builder error = XMPPError.getBuilder(Condition.forbidden); + errorIq.setError(error); + con.addIQReply(errorIq); - try - { - node.getNodeConfiguration(); - } - catch (XMPPErrorException e) - { - Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType()); - } - } + try + { + node.getNodeConfiguration(); + } + catch (XMPPErrorException e) + { + Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType()); + } + } - @Test (expected=SmackException.class) - public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException - { - ThreadedDummyConnection con = new ThreadedDummyConnection(); - PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE); - DiscoverInfo info = new DiscoverInfo(); - Identity ident = new Identity("pubsub", null, "leaf"); - info.addIdentity(ident); - con.addIQReply(info); + @Test (expected=SmackException.class) + public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException + { + ThreadedDummyConnection con = new ThreadedDummyConnection(); + PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE); + DiscoverInfo info = new DiscoverInfo(); + Identity ident = new Identity("pubsub", null, "leaf"); + info.addIdentity(ident); + con.addIQReply(info); - Node node = mgr.getNode("princely_musings"); + Node node = mgr.getNode("princely_musings"); - SmackConfiguration.setDefaultReplyTimeout(100); - con.setTimeout(); + SmackConfiguration.setDefaultReplyTimeout(100); + con.setTimeout(); - node.getNodeConfiguration(); - } + node.getNodeConfiguration(); + } } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ItemValidationTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ItemValidationTest.java index c870f139d..2ef6cb4b0 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ItemValidationTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/pubsub/ItemValidationTest.java @@ -37,63 +37,63 @@ import org.xmlpull.v1.XmlPullParser; * */ public class ItemValidationTest extends InitExtensions { - private ThreadedDummyConnection connection; + private ThreadedDummyConnection connection; - @Before - public void setUp() throws Exception - { - // Uncomment this to enable debug output - // SmackConfiguration.DEBUG = true; + @Before + public void setUp() throws Exception + { + // Uncomment this to enable debug output + // SmackConfiguration.DEBUG = true; - connection = new ThreadedDummyConnection(); - connection.connect(); - connection.login(); - } + connection = new ThreadedDummyConnection(); + connection.connect(); + connection.login(); + } - @After - public void tearDown() throws Exception - { - if (connection != null) - connection.disconnect(); - } + @After + public void tearDown() throws Exception + { + if (connection != null) + connection.disconnect(); + } - @Test - public void verifyBasicItem() throws Exception - { - Item simpleItem = new Item(); - String simpleCtrl = ""; - assertXMLEqual(simpleCtrl, simpleItem.toXML()); + @Test + public void verifyBasicItem() throws Exception + { + Item simpleItem = new Item(); + String simpleCtrl = ""; + assertXMLEqual(simpleCtrl, simpleItem.toXML()); - Item idItem = new Item("uniqueid"); - String idCtrl = ""; - assertXMLEqual(idCtrl, idItem.toXML()); + Item idItem = new Item("uniqueid"); + String idCtrl = ""; + assertXMLEqual(idCtrl, idItem.toXML()); - Item itemWithNodeId = new Item("testId", "testNode"); - String nodeIdCtrl = ""; - assertXMLEqual(nodeIdCtrl, itemWithNodeId.toXML()); - } + Item itemWithNodeId = new Item("testId", "testNode"); + String nodeIdCtrl = ""; + assertXMLEqual(nodeIdCtrl, itemWithNodeId.toXML()); + } - @Test - public void verifyPayloadItem() throws Exception - { - SimplePayload payload = new SimplePayload(null, null, "This is the payload"); + @Test + public void verifyPayloadItem() throws Exception + { + SimplePayload payload = new SimplePayload(null, null, "This is the payload"); - PayloadItem simpleItem = new PayloadItem(payload); - String simpleCtrl = "" + payload.toXML() + ""; - assertXMLEqual(simpleCtrl, simpleItem.toXML()); + PayloadItem simpleItem = new PayloadItem(payload); + String simpleCtrl = "" + payload.toXML() + ""; + assertXMLEqual(simpleCtrl, simpleItem.toXML()); - PayloadItem idItem = new PayloadItem("uniqueid", payload); - String idCtrl = "" + payload.toXML() + ""; - assertXMLEqual(idCtrl, idItem.toXML()); + PayloadItem idItem = new PayloadItem("uniqueid", payload); + String idCtrl = "" + payload.toXML() + ""; + assertXMLEqual(idCtrl, idItem.toXML()); - PayloadItem itemWithNodeId = new PayloadItem("testId", "testNode", payload); - String nodeIdCtrl = "" + payload.toXML() + ""; - assertXMLEqual(nodeIdCtrl, itemWithNodeId.toXML()); - } + PayloadItem itemWithNodeId = new PayloadItem("testId", "testNode", payload); + String nodeIdCtrl = "" + payload.toXML() + ""; + assertXMLEqual(nodeIdCtrl, itemWithNodeId.toXML()); + } - @Test - public void parseBasicItem() throws Exception - { + @Test + public void parseBasicItem() throws Exception + { XmlPullParser parser = PacketParserUtils.getParserFor( "" + "" + @@ -116,7 +116,7 @@ public class ItemValidationTest extends InitExtensions { ExtensionElement itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0); assertTrue(itemExt instanceof Item); assertEquals("testid1", ((Item)itemExt).getId()); - } + } @Test public void parseSimplePayloadItem() throws Exception diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java index 5cf88e6d4..a2f128125 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java @@ -119,7 +119,7 @@ public class DeliveryReceiptTest extends InitExtensions { c.processStanza(m); Stanza reply = c.getSentPacket(); - DeliveryReceipt r = DeliveryReceipt.from((Message) reply); + DeliveryReceipt r = DeliveryReceipt.from((Message) reply); assertThat("romeo@montague.com", equalsCharSequence(reply.getTo())); assertEquals("test-receipt-request", r.getId()); } diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntries.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntries.java index 18f114df7..267277009 100644 --- a/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntries.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntries.java @@ -20,6 +20,6 @@ import java.util.Collection; public interface RosterEntries { - public void rosterEntries(Collection rosterEntries); + public void rosterEntries(Collection rosterEntries); } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleException.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleException.java index 6406ff7a4..48a08e678 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleException.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleException.java @@ -26,9 +26,9 @@ import org.jivesoftware.smackx.jingleold.packet.JingleError; * @author Alvaro Saurin */ public class JingleException extends XMPPException { - private static final long serialVersionUID = -1521230401958103382L; + private static final long serialVersionUID = -1521230401958103382L; - private final JingleError error; + private final JingleError error; /** * Default constructor. diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java index 74dbe6b01..402d12479 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java @@ -186,9 +186,9 @@ import org.jxmpp.jid.Jid; @SuppressWarnings("SynchronizeOnNonFinalField") public class JingleManager implements JingleSessionListener { - private static final Logger LOGGER = Logger.getLogger(JingleManager.class.getName()); + private static final Logger LOGGER = Logger.getLogger(JingleManager.class.getName()); - // non-static + // non-static final List jingleSessions = new ArrayList(); diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleNegotiator.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleNegotiator.java index 0cb75fd45..255d12cbc 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleNegotiator.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleNegotiator.java @@ -42,9 +42,9 @@ import org.jivesoftware.smackx.jingleold.listeners.JingleListener; */ public abstract class JingleNegotiator { - private static final Logger LOGGER = Logger.getLogger(JingleNegotiator.class.getName()); + private static final Logger LOGGER = Logger.getLogger(JingleNegotiator.class.getName()); - //private XMPPConnection connection; // The connection associated + //private XMPPConnection connection; // The connection associated protected JingleSession session; @@ -238,12 +238,12 @@ public abstract class JingleNegotiator { // CHECKSTYLE:OFF public void start() { - isStarted = true; - doStart(); + isStarted = true; + doStart(); } public boolean isStarted() { - return isStarted; + return isStarted; } // CHECKSTYLE:ON diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java index a26b5a98d..24cd429b2 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSession.java @@ -62,9 +62,9 @@ import org.jxmpp.jid.Jid; */ public class JingleSession extends JingleNegotiator implements MediaReceivedListener { - private static final Logger LOGGER = Logger.getLogger(JingleSession.class.getName()); + private static final Logger LOGGER = Logger.getLogger(JingleSession.class.getName()); - // static + // static private static final HashMap sessions = new HashMap(); private static final Random randomGenerator = new Random(); @@ -299,13 +299,13 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList // Each content negotiator may pass back a list of JingleContent for addition to the response packet. // CHECKSTYLE:OFF for (ContentNegotiator contentNegotiator : contentNegotiators) { - // If at this point the content negotiator isn't started, it's because we sent a session-init jingle - // packet from startOutgoing() and we're waiting for the other side to let us know they're ready - // to take jingle packets. (This packet might be a session-terminate, but that will get handled - // later. - if (!contentNegotiator.isStarted()) { - contentNegotiator.start(); - } + // If at this point the content negotiator isn't started, it's because we sent a session-init jingle + // packet from startOutgoing() and we're waiting for the other side to let us know they're ready + // to take jingle packets. (This packet might be a session-terminate, but that will get handled + // later. + if (!contentNegotiator.isStarted()) { + contentNegotiator.start(); + } responses.addAll(contentNegotiator.dispatchIncomingPacket(iq, responseId)); } // CHECKSTYLE:ON @@ -475,7 +475,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList // The the packet. // CHECKSTYLE:OFF if ((getConnection() != null) && (getConnection().isConnected())) - getConnection().sendStanza(jout); + getConnection().sendStanza(jout); // CHECKSTYLE:ON } return jout; @@ -649,11 +649,11 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList private void removeConnectionListener() { // CHECKSTYLE:OFF - if (connectionListener != null) { - getConnection().removeConnectionListener(connectionListener); + if (connectionListener != null) { + getConnection().removeConnectionListener(connectionListener); - LOGGER.fine("JINGLE SESSION: REMOVE CONNECTION LISTENER"); - } + LOGGER.fine("JINGLE SESSION: REMOVE CONNECTION LISTENER"); + } // CHECKSTYLE:ON } @@ -830,10 +830,10 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList public void transportEstablished(TransportCandidate local, TransportCandidate remote) throws NotConnectedException, InterruptedException { if (isFullyEstablished()) { // CHECKSTYLE:OFF - // Indicate that this session is active. - setSessionState(JingleSessionStateActive.getInstance()); + // Indicate that this session is active. + setSessionState(JingleSessionStateActive.getInstance()); - for (ContentNegotiator contentNegotiator : contentNegotiators) { + for (ContentNegotiator contentNegotiator : contentNegotiators) { // CHECKSTYLE:ON if (contentNegotiator.getNegotiatorState() == JingleNegotiatorState.SUCCEEDED) contentNegotiator.triggerContentEstablished(); diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionRequest.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionRequest.java index f6bfb3256..cc703960e 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionRequest.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionRequest.java @@ -35,9 +35,9 @@ import org.jxmpp.jid.Jid; */ public class JingleSessionRequest { - private static final Logger LOGGER = Logger.getLogger(JingleSessionRequest.class.getName()); + private static final Logger LOGGER = Logger.getLogger(JingleSessionRequest.class.getName()); - private final Jingle jingle; // The Jingle packet + private final Jingle jingle; // The Jingle packet private final JingleManager manager; // The manager associated to this @@ -130,15 +130,15 @@ public class JingleSessionRequest { JingleSession session = null; synchronized (manager) { try { - session = manager.createIncomingJingleSession(this); - // Acknowledge the IQ reception - session.setSid(this.getSessionID()); - //session.sendAck(this.getJingle()); - session.updatePacketListener(); - session.terminate("Declined"); - } catch (Exception e) { - LOGGER.log(Level.SEVERE, "Exception in reject", e); - } + session = manager.createIncomingJingleSession(this); + // Acknowledge the IQ reception + session.setSid(this.getSessionID()); + //session.sendAck(this.getJingle()); + session.updatePacketListener(); + session.terminate("Declined"); + } catch (Exception e) { + LOGGER.log(Level.SEVERE, "Exception in reject", e); + } } } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionStateEnded.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionStateEnded.java index c632bcb4a..caa138cb6 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionStateEnded.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleSessionStateEnded.java @@ -29,9 +29,9 @@ import org.jivesoftware.smackx.jingleold.packet.JingleError; */ public class JingleSessionStateEnded extends JingleSessionState { - private static final Logger LOGGER = Logger.getLogger(JingleSessionStateEnded.class.getName()); + private static final Logger LOGGER = Logger.getLogger(JingleSessionStateEnded.class.getName()); - private static JingleSessionStateEnded INSTANCE = null; + private static JingleSessionStateEnded INSTANCE = null; protected JingleSessionStateEnded() { // Prevent instantiation of the class. diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/media/MediaNegotiator.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/media/MediaNegotiator.java index 807a58484..8ea4cda4a 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/media/MediaNegotiator.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/media/MediaNegotiator.java @@ -46,9 +46,9 @@ import org.jivesoftware.smackx.jingleold.packet.JingleError; */ public class MediaNegotiator extends JingleNegotiator { - private static final Logger LOGGER = Logger.getLogger(MediaNegotiator.class.getName()); + private static final Logger LOGGER = Logger.getLogger(MediaNegotiator.class.getName()); - //private JingleSession session; // The session this negotiation + //private JingleSession session; // The session this negotiation private final JingleMediaManager mediaManager; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/JMFInit.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/JMFInit.java index 04c17de02..5f9b00df8 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/JMFInit.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/JMFInit.java @@ -32,11 +32,11 @@ import com.sun.media.util.Registry; public class JMFInit extends Frame implements Runnable { - private static final long serialVersionUID = 6476412003260641680L; + private static final long serialVersionUID = 6476412003260641680L; - private static final Logger LOGGER = Logger.getLogger(JMFInit.class.getName()); + private static final Logger LOGGER = Logger.getLogger(JMFInit.class.getName()); - private String tempDir = "/tmp"; + private String tempDir = "/tmp"; private boolean done = false; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioChannel.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioChannel.java index 20e134b64..9779e9315 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioChannel.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioChannel.java @@ -69,9 +69,9 @@ import org.jivesoftware.smackx.jingleold.media.JingleMediaSession; */ public class AudioChannel { - private static final Logger LOGGER = Logger.getLogger(AudioChannel.class.getName()); + private static final Logger LOGGER = Logger.getLogger(AudioChannel.class.getName()); - private MediaLocator locator; + private MediaLocator locator; private String localIpAddress; private String remoteIpAddress; private int localPort; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioMediaSession.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioMediaSession.java index 0347ee9d9..ee785a4cc 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioMediaSession.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioMediaSession.java @@ -40,9 +40,9 @@ import org.jivesoftware.smackx.jingleold.nat.TransportCandidate; */ public class AudioMediaSession extends JingleMediaSession { - private static final Logger LOGGER = Logger.getLogger(AudioMediaSession.class.getName()); + private static final Logger LOGGER = Logger.getLogger(AudioMediaSession.class.getName()); - private AudioChannel audioChannel; + private AudioChannel audioChannel; /** * Creates a org.jivesoftware.jingleaudio.jmf.AudioMediaSession with defined payload type, remote and local candidates. diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioReceiver.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioReceiver.java index d19a3bb9f..6262bc75e 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioReceiver.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/AudioReceiver.java @@ -47,9 +47,9 @@ import org.jivesoftware.smackx.jingleold.media.JingleMediaSession; public class AudioReceiver implements ReceiveStreamListener, SessionListener, ControllerListener { - private static final Logger LOGGER = Logger.getLogger(AudioReceiver.class.getName()); + private static final Logger LOGGER = Logger.getLogger(AudioReceiver.class.getName()); - boolean dataReceived = false; + boolean dataReceived = false; final Object dataSync; JingleMediaSession jingleMediaSession; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/JmfMediaManager.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/JmfMediaManager.java index af4b99493..c3c5f88b7 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/JmfMediaManager.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jmf/JmfMediaManager.java @@ -40,9 +40,9 @@ import org.jivesoftware.smackx.jingleold.nat.TransportCandidate; */ public class JmfMediaManager extends JingleMediaManager { - private static final Logger LOGGER = Logger.getLogger(JmfMediaManager.class.getName()); + private static final Logger LOGGER = Logger.getLogger(JmfMediaManager.class.getName()); - public static final String MEDIA_NAME = "JMF"; + public static final String MEDIA_NAME = "JMF"; private List payloads = new ArrayList(); diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jspeex/AudioMediaSession.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jspeex/AudioMediaSession.java index 51d95fa7b..69f2fd52b 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jspeex/AudioMediaSession.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jspeex/AudioMediaSession.java @@ -52,9 +52,9 @@ import org.jivesoftware.smackx.jingleold.nat.TransportCandidate; public class AudioMediaSession extends JingleMediaSession implements MediaSessionListener { - private static final Logger LOGGER = Logger.getLogger(AudioMediaSession.class.getName()); + private static final Logger LOGGER = Logger.getLogger(AudioMediaSession.class.getName()); - private MediaSession mediaSession; + private MediaSession mediaSession; /** * Create a Session using Speex Codec. diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jspeex/SpeexMediaManager.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jspeex/SpeexMediaManager.java index 50ec237c6..c4a44a365 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jspeex/SpeexMediaManager.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/jspeex/SpeexMediaManager.java @@ -40,9 +40,9 @@ import org.jivesoftware.smackx.jingleold.nat.TransportCandidate; */ public class SpeexMediaManager extends JingleMediaManager { - private static final Logger LOGGER = Logger.getLogger(SpeexMediaManager.class.getName()); + private static final Logger LOGGER = Logger.getLogger(SpeexMediaManager.class.getName()); - public static final String MEDIA_NAME = "Speex"; + public static final String MEDIA_NAME = "Speex"; private List payloads = new ArrayList(); diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/ScreenShareSession.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/ScreenShareSession.java index 4b0bcce45..48c3d72c7 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/ScreenShareSession.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/ScreenShareSession.java @@ -50,9 +50,9 @@ import org.jivesoftware.smackx.jingleold.nat.TransportCandidate; */ public class ScreenShareSession extends JingleMediaSession { - private static final Logger LOGGER = Logger.getLogger(ScreenShareSession.class.getName()); + private static final Logger LOGGER = Logger.getLogger(ScreenShareSession.class.getName()); - private ImageTransmitter transmitter = null; + private ImageTransmitter transmitter = null; private ImageReceiver receiver = null; private int width = 600; private int height = 600; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/AbstractBufferedImageOp.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/AbstractBufferedImageOp.java index 3c2165d36..840022717 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/AbstractBufferedImageOp.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/AbstractBufferedImageOp.java @@ -50,9 +50,9 @@ public abstract class AbstractBufferedImageOp implements BufferedImageOp, Clonea return null; } - /** - * A convenience method for getting ARGB pixels from an image. This tries to avoid the performance - * penalty of BufferedImage.getRGB unmanaging the image. + /** + * A convenience method for getting ARGB pixels from an image. This tries to avoid the performance + * penalty of BufferedImage.getRGB unmanaging the image. * @param image a BufferedImage object * @param x the left edge of the pixel block * @param y the right edge of the pixel block @@ -62,16 +62,16 @@ public abstract class AbstractBufferedImageOp implements BufferedImageOp, Clonea * @return the pixels * @see #setRGB */ - public int[] getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) { - int type = image.getType(); - if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) - return (int [])image.getRaster().getDataElements(x, y, width, height, pixels); - return image.getRGB(x, y, width, height, pixels, 0, width); + public int[] getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) { + int type = image.getType(); + if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) + return (int [])image.getRaster().getDataElements(x, y, width, height, pixels); + return image.getRGB(x, y, width, height, pixels, 0, width); } - /** - * A convenience method for setting ARGB pixels in an image. This tries to avoid the performance - * penalty of BufferedImage.setRGB unmanaging the image. + /** + * A convenience method for setting ARGB pixels in an image. This tries to avoid the performance + * penalty of BufferedImage.setRGB unmanaging the image. * @param image a BufferedImage object * @param x the left edge of the pixel block * @param y the right edge of the pixel block @@ -79,21 +79,21 @@ public abstract class AbstractBufferedImageOp implements BufferedImageOp, Clonea * @param height the height of the pixel arry * @param pixels the array of pixels to set * @see #getRGB - */ - public void setRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) { - int type = image.getType(); - if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) - image.getRaster().setDataElements(x, y, width, height, pixels); - else - image.setRGB(x, y, width, height, pixels, 0, width); + */ + public void setRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) { + int type = image.getType(); + if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) + image.getRaster().setDataElements(x, y, width, height, pixels); + else + image.setRGB(x, y, width, height, pixels, 0, width); } - public Object clone() { - try { - return super.clone(); - } - catch (CloneNotSupportedException e) { - return null; - } - } + public Object clone() { + try { + return super.clone(); + } + catch (CloneNotSupportedException e) { + return null; + } + } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/ImageReceiver.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/ImageReceiver.java index a6d9682d5..8ed52515c 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/ImageReceiver.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/ImageReceiver.java @@ -37,8 +37,8 @@ import java.util.logging.Logger; public class ImageReceiver extends Canvas { private static final Logger LOGGER = Logger.getLogger(ImageReceiver.class.getName()); - private static final long serialVersionUID = -7000112305305269025L; - private boolean on = true; + private static final long serialVersionUID = -7000112305305269025L; + private boolean on = true; private DatagramSocket socket; private BufferedImage[][] tiles; private static final int tileWidth = ImageTransmitter.tileWidth; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/ImageTransmitter.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/ImageTransmitter.java index 0f1392e29..f0540b07c 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/ImageTransmitter.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/ImageTransmitter.java @@ -38,9 +38,9 @@ import java.util.logging.Logger; */ public class ImageTransmitter implements Runnable { - private static final Logger LOGGER = Logger.getLogger(ImageTransmitter.class.getName()); + private static final Logger LOGGER = Logger.getLogger(ImageTransmitter.class.getName()); - private Robot robot; + private Robot robot; private InetAddress localHost; private InetAddress remoteHost; private int localPort; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/OctTreeQuantizer.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/OctTreeQuantizer.java index 3f5755d80..ec2c868d7 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/OctTreeQuantizer.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/OctTreeQuantizer.java @@ -29,260 +29,260 @@ import java.util.logging.Logger; */ public class OctTreeQuantizer implements Quantizer { - private static final Logger LOGGER = Logger.getLogger(OctTreeQuantizer.class.getName()); + private static final Logger LOGGER = Logger.getLogger(OctTreeQuantizer.class.getName()); - /** - * The greatest depth the tree is allowed to reach - */ - final static int MAX_LEVEL = 5; + /** + * The greatest depth the tree is allowed to reach + */ + final static int MAX_LEVEL = 5; - /** - * An Octtree node. - */ - class OctTreeNode { - int children; - int level; - OctTreeNode parent; - OctTreeNode[] leaf = new OctTreeNode[8]; - boolean isLeaf; - int count; - int totalRed; - int totalGreen; - int totalBlue; - int index; + /** + * An Octtree node. + */ + class OctTreeNode { + int children; + int level; + OctTreeNode parent; + OctTreeNode[] leaf = new OctTreeNode[8]; + boolean isLeaf; + int count; + int totalRed; + int totalGreen; + int totalBlue; + int index; - /** - * A debugging method which prints the tree out. - */ - public void list(PrintStream s, int level) { - String indentStr = ""; - for (int i = 0; i < level; i++) - indentStr += " "; - if (count == 0) - LOGGER.fine(indentStr + index + ": count=" + count); - else - LOGGER.fine(indentStr + index + ": count=" + count + " red=" + (totalRed/count) + " green=" + (totalGreen / count) + " blue=" + (totalBlue / count)); - for (int i = 0; i < 8; i++) - if (leaf[i] != null) - leaf[i].list(s, level+2); - } - } + /** + * A debugging method which prints the tree out. + */ + public void list(PrintStream s, int level) { + String indentStr = ""; + for (int i = 0; i < level; i++) + indentStr += " "; + if (count == 0) + LOGGER.fine(indentStr + index + ": count=" + count); + else + LOGGER.fine(indentStr + index + ": count=" + count + " red=" + (totalRed/count) + " green=" + (totalGreen / count) + " blue=" + (totalBlue / count)); + for (int i = 0; i < 8; i++) + if (leaf[i] != null) + leaf[i].list(s, level+2); + } + } - private int nodes = 0; - private OctTreeNode root; - private int reduceColors; - private int maximumColors; - private int colors = 0; - private List> colorList; + private int nodes = 0; + private OctTreeNode root; + private int reduceColors; + private int maximumColors; + private int colors = 0; + private List> colorList; public OctTreeQuantizer() { - setup(256); - colorList = new ArrayList<>(MAX_LEVEL+1); - for (int i = 0; i < MAX_LEVEL+1; i++) - colorList.add(i, new Vector()); - root = new OctTreeNode(); - } + setup(256); + colorList = new ArrayList<>(MAX_LEVEL+1); + for (int i = 0; i < MAX_LEVEL+1; i++) + colorList.add(i, new Vector()); + root = new OctTreeNode(); + } - /** - * Initialize the quantizer. This should be called before adding any pixels. - * @param numColors the number of colors we're quantizing to. - */ - public void setup(int numColors) { - maximumColors = numColors; - reduceColors = Math.max(512, numColors * 2); - } + /** + * Initialize the quantizer. This should be called before adding any pixels. + * @param numColors the number of colors we're quantizing to. + */ + public void setup(int numColors) { + maximumColors = numColors; + reduceColors = Math.max(512, numColors * 2); + } - /** - * Add pixels to the quantizer. - * @param pixels the array of ARGB pixels - * @param offset the offset into the array - * @param count the count of pixels - */ - public void addPixels(int[] pixels, int offset, int count) { - for (int i = 0; i < count; i++) { - insertColor(pixels[i+offset]); - if (colors > reduceColors) - reduceTree(reduceColors); - } - } + /** + * Add pixels to the quantizer. + * @param pixels the array of ARGB pixels + * @param offset the offset into the array + * @param count the count of pixels + */ + public void addPixels(int[] pixels, int offset, int count) { + for (int i = 0; i < count; i++) { + insertColor(pixels[i+offset]); + if (colors > reduceColors) + reduceTree(reduceColors); + } + } /** * Get the color table index for a color. * @param rgb the color * @return the index */ - public int getIndexForColor(int rgb) { - int red = (rgb >> 16) & 0xff; - int green = (rgb >> 8) & 0xff; - int blue = rgb & 0xff; + public int getIndexForColor(int rgb) { + int red = (rgb >> 16) & 0xff; + int green = (rgb >> 8) & 0xff; + int blue = rgb & 0xff; - OctTreeNode node = root; + OctTreeNode node = root; - for (int level = 0; level <= MAX_LEVEL; level++) { - OctTreeNode child; - int bit = 0x80 >> level; + for (int level = 0; level <= MAX_LEVEL; level++) { + OctTreeNode child; + int bit = 0x80 >> level; - int index = 0; - if ((red & bit) != 0) - index += 4; - if ((green & bit) != 0) - index += 2; - if ((blue & bit) != 0) - index += 1; + int index = 0; + if ((red & bit) != 0) + index += 4; + if ((green & bit) != 0) + index += 2; + if ((blue & bit) != 0) + index += 1; - child = node.leaf[index]; + child = node.leaf[index]; - if (child == null) - return node.index; - else if (child.isLeaf) - return child.index; - else - node = child; - } - LOGGER.fine("getIndexForColor failed"); - return 0; - } + if (child == null) + return node.index; + else if (child.isLeaf) + return child.index; + else + node = child; + } + LOGGER.fine("getIndexForColor failed"); + return 0; + } - private void insertColor(int rgb) { - int red = (rgb >> 16) & 0xff; - int green = (rgb >> 8) & 0xff; - int blue = rgb & 0xff; + private void insertColor(int rgb) { + int red = (rgb >> 16) & 0xff; + int green = (rgb >> 8) & 0xff; + int blue = rgb & 0xff; - OctTreeNode node = root; + OctTreeNode node = root; -// LOGGER.fine("insertColor="+Integer.toHexString(rgb)); - for (int level = 0; level <= MAX_LEVEL; level++) { - OctTreeNode child; - int bit = 0x80 >> level; +// LOGGER.fine("insertColor="+Integer.toHexString(rgb)); + for (int level = 0; level <= MAX_LEVEL; level++) { + OctTreeNode child; + int bit = 0x80 >> level; - int index = 0; - if ((red & bit) != 0) - index += 4; - if ((green & bit) != 0) - index += 2; - if ((blue & bit) != 0) - index += 1; + int index = 0; + if ((red & bit) != 0) + index += 4; + if ((green & bit) != 0) + index += 2; + if ((blue & bit) != 0) + index += 1; - child = node.leaf[index]; + child = node.leaf[index]; - if (child == null) { - node.children++; + if (child == null) { + node.children++; - child = new OctTreeNode(); - child.parent = node; - node.leaf[index] = child; - node.isLeaf = false; - nodes++; - colorList.get(level).addElement(child); + child = new OctTreeNode(); + child.parent = node; + node.leaf[index] = child; + node.isLeaf = false; + nodes++; + colorList.get(level).addElement(child); - if (level == MAX_LEVEL) { - child.isLeaf = true; - child.count = 1; - child.totalRed = red; - child.totalGreen = green; - child.totalBlue = blue; - child.level = level; - colors++; - return; - } + if (level == MAX_LEVEL) { + child.isLeaf = true; + child.count = 1; + child.totalRed = red; + child.totalGreen = green; + child.totalBlue = blue; + child.level = level; + colors++; + return; + } - node = child; - } else if (child.isLeaf) { - child.count++; - child.totalRed += red; - child.totalGreen += green; - child.totalBlue += blue; - return; - } else - node = child; - } - LOGGER.fine("insertColor failed"); - } + node = child; + } else if (child.isLeaf) { + child.count++; + child.totalRed += red; + child.totalGreen += green; + child.totalBlue += blue; + return; + } else + node = child; + } + LOGGER.fine("insertColor failed"); + } - private void reduceTree(int numColors) { - for (int level = MAX_LEVEL-1; level >= 0; level--) { - Vector v = colorList.get(level); - if (v != null && v.size() > 0) { - for (int j = 0; j < v.size(); j++) { - OctTreeNode node = v.elementAt(j); - if (node.children > 0) { - for (int i = 0; i < 8; i++) { - OctTreeNode child = node.leaf[i]; - if (child != null) { - if (!child.isLeaf) - LOGGER.fine("not a leaf!"); - node.count += child.count; - node.totalRed += child.totalRed; - node.totalGreen += child.totalGreen; - node.totalBlue += child.totalBlue; - node.leaf[i] = null; - node.children--; - colors--; - nodes--; - colorList.get(level+1).removeElement(child); - } - } - node.isLeaf = true; - colors++; - if (colors <= numColors) - return; - } - } - } - } + private void reduceTree(int numColors) { + for (int level = MAX_LEVEL-1; level >= 0; level--) { + Vector v = colorList.get(level); + if (v != null && v.size() > 0) { + for (int j = 0; j < v.size(); j++) { + OctTreeNode node = v.elementAt(j); + if (node.children > 0) { + for (int i = 0; i < 8; i++) { + OctTreeNode child = node.leaf[i]; + if (child != null) { + if (!child.isLeaf) + LOGGER.fine("not a leaf!"); + node.count += child.count; + node.totalRed += child.totalRed; + node.totalGreen += child.totalGreen; + node.totalBlue += child.totalBlue; + node.leaf[i] = null; + node.children--; + colors--; + nodes--; + colorList.get(level+1).removeElement(child); + } + } + node.isLeaf = true; + colors++; + if (colors <= numColors) + return; + } + } + } + } - LOGGER.fine("Unable to reduce the OctTree"); - } + LOGGER.fine("Unable to reduce the OctTree"); + } /** * Build the color table. * @return the color table */ - public int[] buildColorTable() { - int[] table = new int[colors]; - buildColorTable(root, table, 0); - return table; - } + public int[] buildColorTable() { + int[] table = new int[colors]; + buildColorTable(root, table, 0); + return table; + } - /** - * A quick way to use the quantizer. Just create a table the right size and pass in the pixels. + /** + * A quick way to use the quantizer. Just create a table the right size and pass in the pixels. * @param inPixels the input colors * @param table the output color table */ - public void buildColorTable(int[] inPixels, int[] table) { - int count = inPixels.length; - maximumColors = table.length; - for (int i = 0; i < count; i++) { - insertColor(inPixels[i]); - if (colors > reduceColors) - reduceTree(reduceColors); - } - if (colors > maximumColors) - reduceTree(maximumColors); - buildColorTable(root, table, 0); - } + public void buildColorTable(int[] inPixels, int[] table) { + int count = inPixels.length; + maximumColors = table.length; + for (int i = 0; i < count; i++) { + insertColor(inPixels[i]); + if (colors > reduceColors) + reduceTree(reduceColors); + } + if (colors > maximumColors) + reduceTree(maximumColors); + buildColorTable(root, table, 0); + } - private int buildColorTable(OctTreeNode node, int[] table, int index) { - if (colors > maximumColors) - reduceTree(maximumColors); + private int buildColorTable(OctTreeNode node, int[] table, int index) { + if (colors > maximumColors) + reduceTree(maximumColors); - if (node.isLeaf) { - int count = node.count; - table[index] = 0xff000000 | - ((node.totalRed/count) << 16) | - ((node.totalGreen/count) << 8) | - node.totalBlue/count; - node.index = index++; - } else { - for (int i = 0; i < 8; i++) { - if (node.leaf[i] != null) { - node.index = index; - index = buildColorTable(node.leaf[i], table, index); - } - } - } - return index; - } + if (node.isLeaf) { + int count = node.count; + table[index] = 0xff000000 | + ((node.totalRed/count) << 16) | + ((node.totalGreen/count) << 8) | + node.totalBlue/count; + node.index = index++; + } else { + for (int i = 0; i < 8; i++) { + if (node.leaf[i] != null) { + node.index = index; + index = buildColorTable(node.leaf[i], table, index); + } + } + } + return index; + } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/PixelUtils.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/PixelUtils.java index 20946dd66..525997ef0 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/PixelUtils.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/PixelUtils.java @@ -26,199 +26,199 @@ import java.util.Random; */ public class PixelUtils { - public final static int REPLACE = 0; - public final static int NORMAL = 1; - public final static int MIN = 2; - public final static int MAX = 3; - public final static int ADD = 4; - public final static int SUBTRACT = 5; - public final static int DIFFERENCE = 6; - public final static int MULTIPLY = 7; - public final static int HUE = 8; - public final static int SATURATION = 9; - public final static int VALUE = 10; - public final static int COLOR = 11; - public final static int SCREEN = 12; - public final static int AVERAGE = 13; - public final static int OVERLAY = 14; - public final static int CLEAR = 15; - public final static int EXCHANGE = 16; - public final static int DISSOLVE = 17; - public final static int DST_IN = 18; - public final static int ALPHA = 19; - public final static int ALPHA_TO_GRAY = 20; + public final static int REPLACE = 0; + public final static int NORMAL = 1; + public final static int MIN = 2; + public final static int MAX = 3; + public final static int ADD = 4; + public final static int SUBTRACT = 5; + public final static int DIFFERENCE = 6; + public final static int MULTIPLY = 7; + public final static int HUE = 8; + public final static int SATURATION = 9; + public final static int VALUE = 10; + public final static int COLOR = 11; + public final static int SCREEN = 12; + public final static int AVERAGE = 13; + public final static int OVERLAY = 14; + public final static int CLEAR = 15; + public final static int EXCHANGE = 16; + public final static int DISSOLVE = 17; + public final static int DST_IN = 18; + public final static int ALPHA = 19; + public final static int ALPHA_TO_GRAY = 20; - private static Random randomGenerator = new Random(); + private static Random randomGenerator = new Random(); - /** - * Clamp a value to the range 0..255. - */ - public static int clamp(int c) { - if (c < 0) - return 0; - if (c > 255) - return 255; - return c; - } + /** + * Clamp a value to the range 0..255. + */ + public static int clamp(int c) { + if (c < 0) + return 0; + if (c > 255) + return 255; + return c; + } - public static int interpolate(int v1, int v2, float f) { - return clamp((int)(v1+f*(v2-v1))); - } + public static int interpolate(int v1, int v2, float f) { + return clamp((int)(v1+f*(v2-v1))); + } - public static int brightness(int rgb) { - int r = (rgb >> 16) & 0xff; - int g = (rgb >> 8) & 0xff; - int b = rgb & 0xff; - return (r+g+b)/3; - } + public static int brightness(int rgb) { + int r = (rgb >> 16) & 0xff; + int g = (rgb >> 8) & 0xff; + int b = rgb & 0xff; + return (r+g+b)/3; + } - public static boolean nearColors(int rgb1, int rgb2, int tolerance) { - int r1 = (rgb1 >> 16) & 0xff; - int g1 = (rgb1 >> 8) & 0xff; - int b1 = rgb1 & 0xff; - int r2 = (rgb2 >> 16) & 0xff; - int g2 = (rgb2 >> 8) & 0xff; - int b2 = rgb2 & 0xff; - return Math.abs(r1-r2) <= tolerance && Math.abs(g1-g2) <= tolerance && Math.abs(b1-b2) <= tolerance; - } + public static boolean nearColors(int rgb1, int rgb2, int tolerance) { + int r1 = (rgb1 >> 16) & 0xff; + int g1 = (rgb1 >> 8) & 0xff; + int b1 = rgb1 & 0xff; + int r2 = (rgb2 >> 16) & 0xff; + int g2 = (rgb2 >> 8) & 0xff; + int b2 = rgb2 & 0xff; + return Math.abs(r1-r2) <= tolerance && Math.abs(g1-g2) <= tolerance && Math.abs(b1-b2) <= tolerance; + } - private final static float[] hsb1 = new float[3];//FIXME-not thread safe - private final static float[] hsb2 = new float[3];//FIXME-not thread safe + private final static float[] hsb1 = new float[3];//FIXME-not thread safe + private final static float[] hsb2 = new float[3];//FIXME-not thread safe - // Return rgb1 painted onto rgb2 - public static int combinePixels(int rgb1, int rgb2, int op) { - return combinePixels(rgb1, rgb2, op, 0xff); - } + // Return rgb1 painted onto rgb2 + public static int combinePixels(int rgb1, int rgb2, int op) { + return combinePixels(rgb1, rgb2, op, 0xff); + } - public static int combinePixels(int rgb1, int rgb2, int op, int extraAlpha, int channelMask) { - return (rgb2 & ~channelMask) | combinePixels(rgb1 & channelMask, rgb2, op, extraAlpha); - } + public static int combinePixels(int rgb1, int rgb2, int op, int extraAlpha, int channelMask) { + return (rgb2 & ~channelMask) | combinePixels(rgb1 & channelMask, rgb2, op, extraAlpha); + } - public static int combinePixels(int rgb1, int rgb2, int op, int extraAlpha) { - if (op == REPLACE) - return rgb1; - int a1 = (rgb1 >> 24) & 0xff; - int r1 = (rgb1 >> 16) & 0xff; - int g1 = (rgb1 >> 8) & 0xff; - int b1 = rgb1 & 0xff; - int a2 = (rgb2 >> 24) & 0xff; - int r2 = (rgb2 >> 16) & 0xff; - int g2 = (rgb2 >> 8) & 0xff; - int b2 = rgb2 & 0xff; + public static int combinePixels(int rgb1, int rgb2, int op, int extraAlpha) { + if (op == REPLACE) + return rgb1; + int a1 = (rgb1 >> 24) & 0xff; + int r1 = (rgb1 >> 16) & 0xff; + int g1 = (rgb1 >> 8) & 0xff; + int b1 = rgb1 & 0xff; + int a2 = (rgb2 >> 24) & 0xff; + int r2 = (rgb2 >> 16) & 0xff; + int g2 = (rgb2 >> 8) & 0xff; + int b2 = rgb2 & 0xff; - switch (op) { - case NORMAL: - break; - case MIN: - r1 = Math.min(r1, r2); - g1 = Math.min(g1, g2); - b1 = Math.min(b1, b2); - break; - case MAX: - r1 = Math.max(r1, r2); - g1 = Math.max(g1, g2); - b1 = Math.max(b1, b2); - break; - case ADD: - r1 = clamp(r1+r2); - g1 = clamp(g1+g2); - b1 = clamp(b1+b2); - break; - case SUBTRACT: - r1 = clamp(r2-r1); - g1 = clamp(g2-g1); - b1 = clamp(b2-b1); - break; - case DIFFERENCE: - r1 = clamp(Math.abs(r1-r2)); - g1 = clamp(Math.abs(g1-g2)); - b1 = clamp(Math.abs(b1-b2)); - break; - case MULTIPLY: - r1 = clamp(r1*r2/255); - g1 = clamp(g1*g2/255); - b1 = clamp(b1*b2/255); - break; - case DISSOLVE: - if ((randomGenerator.nextInt() & 0xff) <= a1) { - r1 = r2; - g1 = g2; - b1 = b2; - } - break; - case AVERAGE: - r1 = (r1+r2)/2; - g1 = (g1+g2)/2; - b1 = (b1+b2)/2; - break; - case HUE: - case SATURATION: - case VALUE: - case COLOR: - Color.RGBtoHSB(r1, g1, b1, hsb1); - Color.RGBtoHSB(r2, g2, b2, hsb2); - switch (op) { - case HUE: - hsb2[0] = hsb1[0]; - break; - case SATURATION: - hsb2[1] = hsb1[1]; - break; - case VALUE: - hsb2[2] = hsb1[2]; - break; - case COLOR: - hsb2[0] = hsb1[0]; - hsb2[1] = hsb1[1]; - break; - } - rgb1 = Color.HSBtoRGB(hsb2[0], hsb2[1], hsb2[2]); - r1 = (rgb1 >> 16) & 0xff; - g1 = (rgb1 >> 8) & 0xff; - b1 = rgb1 & 0xff; - break; - case SCREEN: - r1 = 255 - ((255 - r1) * (255 - r2)) / 255; - g1 = 255 - ((255 - g1) * (255 - g2)) / 255; - b1 = 255 - ((255 - b1) * (255 - b2)) / 255; - break; - case OVERLAY: - int m, s; - s = 255 - ((255 - r1) * (255 - r2)) / 255; - m = r1 * r2 / 255; - r1 = (s * r1 + m * (255 - r1)) / 255; - s = 255 - ((255 - g1) * (255 - g2)) / 255; - m = g1 * g2 / 255; - g1 = (s * g1 + m * (255 - g1)) / 255; - s = 255 - ((255 - b1) * (255 - b2)) / 255; - m = b1 * b2 / 255; - b1 = (s * b1 + m * (255 - b1)) / 255; - break; - case CLEAR: - r1 = g1 = b1 = 0xff; - break; - case DST_IN: - r1 = clamp((r2*a1)/255); - g1 = clamp((g2*a1)/255); - b1 = clamp((b2*a1)/255); - a1 = clamp((a2*a1)/255); - return (a1 << 24) | (r1 << 16) | (g1 << 8) | b1; - case ALPHA: - a1 = a1*a2/255; - return (a1 << 24) | (r2 << 16) | (g2 << 8) | b2; - case ALPHA_TO_GRAY: - int na = 255-a1; - return (a1 << 24) | (na << 16) | (na << 8) | na; - } - if (extraAlpha != 0xff || a1 != 0xff) { - a1 = a1*extraAlpha/255; - int a3 = (255-a1)*a2/255; - r1 = clamp((r1*a1+r2*a3)/255); - g1 = clamp((g1*a1+g2*a3)/255); - b1 = clamp((b1*a1+b2*a3)/255); - a1 = clamp(a1+a3); - } - return (a1 << 24) | (r1 << 16) | (g1 << 8) | b1; - } + switch (op) { + case NORMAL: + break; + case MIN: + r1 = Math.min(r1, r2); + g1 = Math.min(g1, g2); + b1 = Math.min(b1, b2); + break; + case MAX: + r1 = Math.max(r1, r2); + g1 = Math.max(g1, g2); + b1 = Math.max(b1, b2); + break; + case ADD: + r1 = clamp(r1+r2); + g1 = clamp(g1+g2); + b1 = clamp(b1+b2); + break; + case SUBTRACT: + r1 = clamp(r2-r1); + g1 = clamp(g2-g1); + b1 = clamp(b2-b1); + break; + case DIFFERENCE: + r1 = clamp(Math.abs(r1-r2)); + g1 = clamp(Math.abs(g1-g2)); + b1 = clamp(Math.abs(b1-b2)); + break; + case MULTIPLY: + r1 = clamp(r1*r2/255); + g1 = clamp(g1*g2/255); + b1 = clamp(b1*b2/255); + break; + case DISSOLVE: + if ((randomGenerator.nextInt() & 0xff) <= a1) { + r1 = r2; + g1 = g2; + b1 = b2; + } + break; + case AVERAGE: + r1 = (r1+r2)/2; + g1 = (g1+g2)/2; + b1 = (b1+b2)/2; + break; + case HUE: + case SATURATION: + case VALUE: + case COLOR: + Color.RGBtoHSB(r1, g1, b1, hsb1); + Color.RGBtoHSB(r2, g2, b2, hsb2); + switch (op) { + case HUE: + hsb2[0] = hsb1[0]; + break; + case SATURATION: + hsb2[1] = hsb1[1]; + break; + case VALUE: + hsb2[2] = hsb1[2]; + break; + case COLOR: + hsb2[0] = hsb1[0]; + hsb2[1] = hsb1[1]; + break; + } + rgb1 = Color.HSBtoRGB(hsb2[0], hsb2[1], hsb2[2]); + r1 = (rgb1 >> 16) & 0xff; + g1 = (rgb1 >> 8) & 0xff; + b1 = rgb1 & 0xff; + break; + case SCREEN: + r1 = 255 - ((255 - r1) * (255 - r2)) / 255; + g1 = 255 - ((255 - g1) * (255 - g2)) / 255; + b1 = 255 - ((255 - b1) * (255 - b2)) / 255; + break; + case OVERLAY: + int m, s; + s = 255 - ((255 - r1) * (255 - r2)) / 255; + m = r1 * r2 / 255; + r1 = (s * r1 + m * (255 - r1)) / 255; + s = 255 - ((255 - g1) * (255 - g2)) / 255; + m = g1 * g2 / 255; + g1 = (s * g1 + m * (255 - g1)) / 255; + s = 255 - ((255 - b1) * (255 - b2)) / 255; + m = b1 * b2 / 255; + b1 = (s * b1 + m * (255 - b1)) / 255; + break; + case CLEAR: + r1 = g1 = b1 = 0xff; + break; + case DST_IN: + r1 = clamp((r2*a1)/255); + g1 = clamp((g2*a1)/255); + b1 = clamp((b2*a1)/255); + a1 = clamp((a2*a1)/255); + return (a1 << 24) | (r1 << 16) | (g1 << 8) | b1; + case ALPHA: + a1 = a1*a2/255; + return (a1 << 24) | (r2 << 16) | (g2 << 8) | b2; + case ALPHA_TO_GRAY: + int na = 255-a1; + return (a1 << 24) | (na << 16) | (na << 8) | na; + } + if (extraAlpha != 0xff || a1 != 0xff) { + a1 = a1*extraAlpha/255; + int a3 = (255-a1)*a2/255; + r1 = clamp((r1*a1+r2*a3)/255); + g1 = clamp((g1*a1+g2*a3)/255); + b1 = clamp((b1*a1+b2*a3)/255); + a1 = clamp(a1+a3); + } + return (a1 << 24) | (r1 << 16) | (g1 << 8) | b1; + } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/QuantizeFilter.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/QuantizeFilter.java index c2e181eac..4fa3bfcf5 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/QuantizeFilter.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/QuantizeFilter.java @@ -29,150 +29,150 @@ import java.awt.Rectangle; */ public class QuantizeFilter extends WholeImageFilter { - /** - * Floyd-Steinberg dithering matrix. - */ - protected final static int[] matrix = { - 0, 0, 0, - 0, 0, 7, - 3, 5, 1, - }; - private int sum = 3+5+7+1; + /** + * Floyd-Steinberg dithering matrix. + */ + protected final static int[] matrix = { + 0, 0, 0, + 0, 0, 7, + 3, 5, 1, + }; + private int sum = 3+5+7+1; - private boolean dither; - private int numColors = 256; - private boolean serpentine = true; + private boolean dither; + private int numColors = 256; + private boolean serpentine = true; - /** - * Set the number of colors to quantize to. - * @param numColors the number of colors. The default is 256. - */ - public void setNumColors(int numColors) { - this.numColors = Math.min(Math.max(numColors, 8), 256); - } + /** + * Set the number of colors to quantize to. + * @param numColors the number of colors. The default is 256. + */ + public void setNumColors(int numColors) { + this.numColors = Math.min(Math.max(numColors, 8), 256); + } - /** - * Get the number of colors to quantize to. - * @return the number of colors. - */ - public int getNumColors() { - return numColors; - } + /** + * Get the number of colors to quantize to. + * @return the number of colors. + */ + public int getNumColors() { + return numColors; + } - /** - * Set whether to use dithering or not. If not, the image is posterized. - * @param dither true to use dithering - */ - public void setDither(boolean dither) { - this.dither = dither; - } + /** + * Set whether to use dithering or not. If not, the image is posterized. + * @param dither true to use dithering + */ + public void setDither(boolean dither) { + this.dither = dither; + } - /** - * Return the dithering setting. - * @return the current setting - */ - public boolean getDither() { - return dither; - } + /** + * Return the dithering setting. + * @return the current setting + */ + public boolean getDither() { + return dither; + } - /** - * Set whether to use a serpentine pattern for return or not. This can reduce 'avalanche' artifacts in the output. - * @param serpentine true to use serpentine pattern - */ - public void setSerpentine(boolean serpentine) { - this.serpentine = serpentine; - } + /** + * Set whether to use a serpentine pattern for return or not. This can reduce 'avalanche' artifacts in the output. + * @param serpentine true to use serpentine pattern + */ + public void setSerpentine(boolean serpentine) { + this.serpentine = serpentine; + } - /** - * Return the serpentine setting. - * @return the current setting - */ - public boolean getSerpentine() { - return serpentine; - } + /** + * Return the serpentine setting. + * @return the current setting + */ + public boolean getSerpentine() { + return serpentine; + } - public void quantize(int[] inPixels, int[] outPixels, int width, int height, int numColors, boolean dither, boolean serpentine) { - int count = width*height; - Quantizer quantizer = new OctTreeQuantizer(); - quantizer.setup(numColors); - quantizer.addPixels(inPixels, 0, count); - int[] table = quantizer.buildColorTable(); + public void quantize(int[] inPixels, int[] outPixels, int width, int height, int numColors, boolean dither, boolean serpentine) { + int count = width*height; + Quantizer quantizer = new OctTreeQuantizer(); + quantizer.setup(numColors); + quantizer.addPixels(inPixels, 0, count); + int[] table = quantizer.buildColorTable(); - if (!dither) { - for (int i = 0; i < count; i++) - outPixels[i] = table[quantizer.getIndexForColor(inPixels[i])]; - } else { - int index = 0; - for (int y = 0; y < height; y++) { - boolean reverse = serpentine && (y & 1) == 1; - int direction; - if (reverse) { - index = y*width+width-1; - direction = -1; - } else { - index = y*width; - direction = 1; - } - for (int x = 0; x < width; x++) { - int rgb1 = inPixels[index]; - int rgb2 = table[quantizer.getIndexForColor(rgb1)]; + if (!dither) { + for (int i = 0; i < count; i++) + outPixels[i] = table[quantizer.getIndexForColor(inPixels[i])]; + } else { + int index = 0; + for (int y = 0; y < height; y++) { + boolean reverse = serpentine && (y & 1) == 1; + int direction; + if (reverse) { + index = y*width+width-1; + direction = -1; + } else { + index = y*width; + direction = 1; + } + for (int x = 0; x < width; x++) { + int rgb1 = inPixels[index]; + int rgb2 = table[quantizer.getIndexForColor(rgb1)]; - outPixels[index] = rgb2; + outPixels[index] = rgb2; - int r1 = (rgb1 >> 16) & 0xff; - int g1 = (rgb1 >> 8) & 0xff; - int b1 = rgb1 & 0xff; + int r1 = (rgb1 >> 16) & 0xff; + int g1 = (rgb1 >> 8) & 0xff; + int b1 = rgb1 & 0xff; - int r2 = (rgb2 >> 16) & 0xff; - int g2 = (rgb2 >> 8) & 0xff; - int b2 = rgb2 & 0xff; + int r2 = (rgb2 >> 16) & 0xff; + int g2 = (rgb2 >> 8) & 0xff; + int b2 = rgb2 & 0xff; - int er = r1-r2; - int eg = g1-g2; - int eb = b1-b2; + int er = r1-r2; + int eg = g1-g2; + int eb = b1-b2; - for (int i = -1; i <= 1; i++) { - int iy = i+y; - if (0 <= iy && iy < height) { - for (int j = -1; j <= 1; j++) { - int jx = j+x; - if (0 <= jx && jx < width) { - int w; - if (reverse) - w = matrix[(i+1)*3-j+1]; - else - w = matrix[(i+1)*3+j+1]; - if (w != 0) { - int k = reverse ? index - j : index + j; - rgb1 = inPixels[k]; - r1 = (rgb1 >> 16) & 0xff; - g1 = (rgb1 >> 8) & 0xff; - b1 = rgb1 & 0xff; - r1 += er * w/sum; - g1 += eg * w/sum; - b1 += eb * w/sum; - inPixels[k] = (PixelUtils.clamp(r1) << 16) | (PixelUtils.clamp(g1) << 8) | PixelUtils.clamp(b1); - } - } - } - } - } - index += direction; - } - } - } - } + for (int i = -1; i <= 1; i++) { + int iy = i+y; + if (0 <= iy && iy < height) { + for (int j = -1; j <= 1; j++) { + int jx = j+x; + if (0 <= jx && jx < width) { + int w; + if (reverse) + w = matrix[(i+1)*3-j+1]; + else + w = matrix[(i+1)*3+j+1]; + if (w != 0) { + int k = reverse ? index - j : index + j; + rgb1 = inPixels[k]; + r1 = (rgb1 >> 16) & 0xff; + g1 = (rgb1 >> 8) & 0xff; + b1 = rgb1 & 0xff; + r1 += er * w/sum; + g1 += eg * w/sum; + b1 += eb * w/sum; + inPixels[k] = (PixelUtils.clamp(r1) << 16) | (PixelUtils.clamp(g1) << 8) | PixelUtils.clamp(b1); + } + } + } + } + } + index += direction; + } + } + } + } - protected int[] filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace) { - int[] outPixels = new int[width*height]; + protected int[] filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace) { + int[] outPixels = new int[width*height]; - quantize(inPixels, outPixels, width, height, numColors, dither, serpentine); + quantize(inPixels, outPixels, width, height, numColors, dither, serpentine); - return outPixels; - } + return outPixels; + } - public String toString() { - return "Colors/Quantize..."; - } + public String toString() { + return "Colors/Quantize..."; + } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/Quantizer.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/Quantizer.java index d5eb36cc6..2aa6233d6 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/Quantizer.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/Quantizer.java @@ -22,32 +22,32 @@ package org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api; * calling the buildColorTable method. */ public interface Quantizer { - /** - * Initialize the quantizer. This should be called before adding any pixels. - * @param numColors the number of colors we're quantizing to. - */ - public void setup(int numColors); + /** + * Initialize the quantizer. This should be called before adding any pixels. + * @param numColors the number of colors we're quantizing to. + */ + public void setup(int numColors); - /** - * Add pixels to the quantizer. - * @param pixels the array of ARGB pixels - * @param offset the offset into the array - * @param count the count of pixels - */ - public void addPixels(int[] pixels, int offset, int count); + /** + * Add pixels to the quantizer. + * @param pixels the array of ARGB pixels + * @param offset the offset into the array + * @param count the count of pixels + */ + public void addPixels(int[] pixels, int offset, int count); - /** - * Build a color table from the added pixels. - * @return an array of ARGB pixels representing a color table - */ - public int[] buildColorTable(); + /** + * Build a color table from the added pixels. + * @return an array of ARGB pixels representing a color table + */ + public int[] buildColorTable(); - /** - * Using the previously-built color table, return the index into that table for a pixel. - * This is guaranteed to return a valid index - returning the index of a color closer - * to that requested if necessary. - * @param rgb the pixel to find - * @return the pixel's index in the color table - */ - public int getIndexForColor(int rgb); + /** + * Using the previously-built color table, return the index into that table for a pixel. + * This is guaranteed to return a valid index - returning the index of a color closer + * to that requested if necessary. + * @param rgb the pixel to find + * @return the pixel's index in the color table + */ + public int getIndexForColor(int rgb); } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/WholeImageFilter.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/WholeImageFilter.java index eb90e676a..d150f2527 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/WholeImageFilter.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/mediaimpl/sshare/api/WholeImageFilter.java @@ -27,53 +27,53 @@ import java.awt.image.WritableRaster; */ public abstract class WholeImageFilter extends AbstractBufferedImageOp { - /** + /** * The output image bounds. */ protected Rectangle transformedSpace; - /** + /** * The input image bounds. */ - protected Rectangle originalSpace; + protected Rectangle originalSpace; - /** - * Construct a WholeImageFilter. - */ - public WholeImageFilter() { - } + /** + * Construct a WholeImageFilter. + */ + public WholeImageFilter() { + } public BufferedImage filter(BufferedImage src, BufferedImage dst) { int width = src.getWidth(); int height = src.getHeight(); - int type = src.getType(); - WritableRaster srcRaster = src.getRaster(); + int type = src.getType(); + WritableRaster srcRaster = src.getRaster(); - originalSpace = new Rectangle(0, 0, width, height); - transformedSpace = new Rectangle(0, 0, width, height); - transformSpace(transformedSpace); + originalSpace = new Rectangle(0, 0, width, height); + transformedSpace = new Rectangle(0, 0, width, height); + transformSpace(transformedSpace); if (dst == null) { ColorModel dstCM = src.getColorModel(); - dst = new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height), dstCM.isAlphaPremultiplied(), null); - } - WritableRaster dstRaster = dst.getRaster(); + dst = new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height), dstCM.isAlphaPremultiplied(), null); + } + WritableRaster dstRaster = dst.getRaster(); - int[] inPixels = getRGB(src, 0, 0, width, height, null); - inPixels = filterPixels(width, height, inPixels, transformedSpace); - setRGB(dst, 0, 0, transformedSpace.width, transformedSpace.height, inPixels); + int[] inPixels = getRGB(src, 0, 0, width, height, null); + inPixels = filterPixels(width, height, inPixels, transformedSpace); + setRGB(dst, 0, 0, transformedSpace.width, transformedSpace.height, inPixels); return dst; } - /** + /** * Calculate output bounds for given input bounds. * @param rect input and output rectangle */ - protected void transformSpace(Rectangle rect) { - } + protected void transformSpace(Rectangle rect) { + } - /** + /** * Actually filter the pixels. * @param width the image width * @param height the image height @@ -81,6 +81,6 @@ public abstract class WholeImageFilter extends AbstractBufferedImageOp { * @param transformedSpace the output bounds * @return the output pixels */ - protected abstract int[] filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace); + protected abstract int[] filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace); } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/HttpServer.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/HttpServer.java index a4207fb99..e040d92a2 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/HttpServer.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/HttpServer.java @@ -32,9 +32,9 @@ import java.util.logging.Logger; */ public class HttpServer { - private static final Logger LOGGER = Logger.getLogger(HttpServer.class.getName()); + private static final Logger LOGGER = Logger.getLogger(HttpServer.class.getName()); - public HttpServer(int port) { + public HttpServer(int port) { ServerSocket server_socket; try { diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/ICECandidate.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/ICECandidate.java index 20b37e068..f4f670fcd 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/ICECandidate.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/ICECandidate.java @@ -32,9 +32,9 @@ import java.util.logging.Logger; */ public class ICECandidate extends TransportCandidate implements Comparable { - private static final Logger LOGGER = Logger.getLogger(ICECandidate.class.getName()); + private static final Logger LOGGER = Logger.getLogger(ICECandidate.class.getName()); - private String id; // An identification + private String id; // An identification private String username; @@ -415,14 +415,14 @@ public class ICECandidate extends TransportCandidate implements Comparable arg.getPreference()) { - return 1; - } - return 0; - } + public int compareTo(ICECandidate arg) { + if (getPreference() < arg.getPreference()) { + return -1; + } else if (getPreference() > arg.getPreference()) { + return 1; + } + return 0; + } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/ICEResolver.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/ICEResolver.java index 7d001ca67..933ed639a 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/ICEResolver.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/ICEResolver.java @@ -45,7 +45,7 @@ import de.javawi.jstun.util.UtilityException; */ public class ICEResolver extends TransportResolver { - private static final Logger LOGGER = Logger.getLogger(ICEResolver.class.getName()); + private static final Logger LOGGER = Logger.getLogger(ICEResolver.class.getName()); XMPPConnection connection; Random random = new Random(); @@ -73,13 +73,13 @@ public class ICEResolver extends TransportResolver { // of the STUN server are much, much faster. if (negociatorsMap.get(server) == null) { // CHECKSTYLE:OFF - ICENegociator iceNegociator = new ICENegociator(server, port, (short) 1); - negociatorsMap.put(server, iceNegociator); + ICENegociator iceNegociator = new ICENegociator(server, port, (short) 1); + negociatorsMap.put(server, iceNegociator); - // gather candidates - iceNegociator.gatherCandidateAddresses(); - // priorize candidates - iceNegociator.prioritizeCandidates(); + // gather candidates + iceNegociator.gatherCandidateAddresses(); + // priorize candidates + iceNegociator.prioritizeCandidates(); // CHECKSTYLE:ON } @@ -125,21 +125,21 @@ public class ICEResolver extends TransportResolver { // JBW/GW - 17JUL08: Figure out the zero-based NIC number for this candidate. short nicNum = 0; - try { - Enumeration nics = NetworkInterface.getNetworkInterfaces(); - short i = 0; - NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress()); - while(nics.hasMoreElements()) { - NetworkInterface checkNIC = nics.nextElement(); - if (checkNIC.equals(nic)) { - nicNum = i; - break; - } - i++; - } - } catch (SocketException e1) { - LOGGER.log(Level.WARNING, "exeption", e1); - } + try { + Enumeration nics = NetworkInterface.getNetworkInterfaces(); + short i = 0; + NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress()); + while(nics.hasMoreElements()) { + NetworkInterface checkNIC = nics.nextElement(); + if (checkNIC.equals(nic)) { + nicNum = i; + break; + } + i++; + } + } catch (SocketException e1) { + LOGGER.log(Level.WARNING, "exeption", e1); + } TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, nicNum, String.valueOf(Math.abs(random.nextLong())), candidate.getPort(), "1", candidate.getPriority(), iceType); transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress()); diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/RTPBridge.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/RTPBridge.java index 92028b613..fb5c19caa 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/RTPBridge.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/RTPBridge.java @@ -52,9 +52,9 @@ import org.xmlpull.v1.XmlPullParserException; */ public class RTPBridge extends IQ { - private static final Logger LOGGER = Logger.getLogger(RTPBridge.class.getName()); + private static final Logger LOGGER = Logger.getLogger(RTPBridge.class.getName()); - private String sid; + private String sid; private String pass; private String ip; private String name; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/STUN.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/STUN.java index 51dee98ef..005c1a42a 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/STUN.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/STUN.java @@ -46,9 +46,9 @@ import org.xmlpull.v1.XmlPullParserException; */ public class STUN extends SimpleIQ { - private static final Logger LOGGER = Logger.getLogger(STUN.class.getName()); + private static final Logger LOGGER = Logger.getLogger(STUN.class.getName()); - private List servers = new ArrayList(); + private List servers = new ArrayList(); private String publicIp = null; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/STUNResolver.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/STUNResolver.java index a55e3f43e..8eef4aca8 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/STUNResolver.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/STUNResolver.java @@ -46,9 +46,9 @@ import de.javawi.jstun.test.DiscoveryTest; */ public class STUNResolver extends TransportResolver { - private static final Logger LOGGER = Logger.getLogger(STUNResolver.class.getName()); + private static final Logger LOGGER = Logger.getLogger(STUNResolver.class.getName()); - // The filename where the STUN servers are stored. + // The filename where the STUN servers are stored. public final static String STUNSERVERS_FILENAME = "META-INF/stun-config.xml"; // Current STUN server we are using diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TcpUdpBridgeClient.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TcpUdpBridgeClient.java index fa9c11502..fbaebd5ff 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TcpUdpBridgeClient.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TcpUdpBridgeClient.java @@ -33,9 +33,9 @@ import java.util.logging.Logger; */ public class TcpUdpBridgeClient { - private static final Logger LOGGER = Logger.getLogger(TcpUdpBridgeClient.class.getName()); + private static final Logger LOGGER = Logger.getLogger(TcpUdpBridgeClient.class.getName()); - private String remoteTcpHost = null; + private String remoteTcpHost = null; private String remoteUdpHost = null; private int remoteTcpPort = -1; private int remoteUdpPort = -1; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TcpUdpBridgeServer.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TcpUdpBridgeServer.java index 79e72febb..233c0a25a 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TcpUdpBridgeServer.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TcpUdpBridgeServer.java @@ -35,9 +35,9 @@ import java.util.logging.Logger; */ public class TcpUdpBridgeServer { - private static final Logger LOGGER = Logger.getLogger(TcpUdpBridgeServer.class.getName()); + private static final Logger LOGGER = Logger.getLogger(TcpUdpBridgeServer.class.getName()); - private String remoteTcpHost = null; + private String remoteTcpHost = null; private String remoteUdpHost = null; private int remoteTcpPort = -1; private int remoteUdpPort = -1; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportCandidate.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportCandidate.java index 9f5d4a94c..58fb8a8bb 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportCandidate.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportCandidate.java @@ -47,9 +47,9 @@ import org.jxmpp.jid.Jid; @SuppressWarnings("EqualsHashCode") public abstract class TransportCandidate { - private static final Logger LOGGER = Logger.getLogger(TransportCandidate.class.getName()); + private static final Logger LOGGER = Logger.getLogger(TransportCandidate.class.getName()); - private String name; + private String name; private String ip; // IP address @@ -359,7 +359,7 @@ public abstract class TransportCandidate { try { // CHECKSTYLE:OFF - InetAddress candAddress = InetAddress.getByName(getIp()); + InetAddress candAddress = InetAddress.getByName(getIp()); // CHECKSTYLE:ON isUsable = true;//candAddress.isReachable(TransportResolver.CHECK_TIMEOUT); } @@ -771,8 +771,8 @@ public abstract class TransportCandidate { // CHECKSTYLE:OFF if (pass.equals(password) - && transportCandidate.getIp().indexOf(ip) != -1 - && transportCandidate.getPort() == Integer.parseInt(pt)) { + && transportCandidate.getIp().indexOf(ip) != -1 + && transportCandidate.getPort() == Integer.parseInt(pt)) { // CHECKSTYLE:ON LOGGER.fine("ECHO OK: " + candidate.getIp() + ":" + candidate.getPort() + " <-> " + transportCandidate.getIp() + ":" + transportCandidate.getPort()); TestResult testResult = new TestResult(); diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportNegotiator.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportNegotiator.java index 731e527b0..1530313fc 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportNegotiator.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportNegotiator.java @@ -52,9 +52,9 @@ import org.jivesoftware.smackx.jingleold.packet.JingleTransport.JingleTransportC */ public abstract class TransportNegotiator extends JingleNegotiator { - private static final Logger LOGGER = Logger.getLogger(TransportNegotiator.class.getName()); + private static final Logger LOGGER = Logger.getLogger(TransportNegotiator.class.getName()); - // The time we give to the candidates check before we accept or decline the + // The time we give to the candidates check before we accept or decline the // transport (in milliseconds) public final static int CANDIDATES_ACCEPT_PERIOD = 4000; @@ -911,12 +911,12 @@ public abstract class TransportNegotiator extends JingleNegotiator { int highest = -1; ICECandidate chose = null; for (TransportCandidate transportCandidate : cands) { - if (transportCandidate instanceof ICECandidate) { - ICECandidate icecandidate = (ICECandidate) transportCandidate; - if (icecandidate.getPreference() > highest) { - chose = icecandidate; - highest = icecandidate.getPreference(); - } + if (transportCandidate instanceof ICECandidate) { + ICECandidate icecandidate = (ICECandidate) transportCandidate; + if (icecandidate.getPreference() > highest) { + chose = icecandidate; + highest = icecandidate.getPreference(); + } } } result = chose; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportResolver.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportResolver.java index 3ce8370e6..99fef19dd 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportResolver.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/nat/TransportResolver.java @@ -40,9 +40,9 @@ import org.jivesoftware.smackx.jingleold.JingleSession; */ public abstract class TransportResolver { - private static final Logger LOGGER = Logger.getLogger(TransportResolver.class.getName()); + private static final Logger LOGGER = Logger.getLogger(TransportResolver.class.getName()); - public enum Type { + public enum Type { rawupd, ice } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleContentDescription.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleContentDescription.java index e9759404b..554a11d7a 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleContentDescription.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleContentDescription.java @@ -283,12 +283,12 @@ public abstract class JingleContentDescription implements ExtensionElement { StringBuilder buf = new StringBuilder(); PayloadType pt = getPayloadType(); if (pt instanceof PayloadType.Audio) { - PayloadType.Audio pta = (PayloadType.Audio) pt; + PayloadType.Audio pta = (PayloadType.Audio) pt; - buf.append(" clockrate=\"").append(pta.getClockRate()).append("\" "); - } - return buf.toString(); - } - } - } + buf.append(" clockrate=\"").append(pta.getClockRate()).append("\" "); + } + return buf.toString(); + } + } + } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleContentInfo.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleContentInfo.java index b37ee5831..6c39a19a7 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleContentInfo.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleContentInfo.java @@ -148,7 +148,7 @@ public class JingleContentInfo implements ExtensionElement { public static class Ringing extends Audio { public Ringing() { super(ContentInfo.Audio.RINGING); - } - } - } + } + } + } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleDescription.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleDescription.java index aedc1a7b3..82f1bfc03 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleDescription.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleDescription.java @@ -32,9 +32,9 @@ import org.jivesoftware.smackx.jingleold.media.PayloadType; */ public abstract class JingleDescription implements ExtensionElement { - private static final Logger LOGGER = Logger.getLogger(JingleDescription.class.getName()); + private static final Logger LOGGER = Logger.getLogger(JingleDescription.class.getName()); - // static + // static public static final String NODENAME = "description"; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleError.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleError.java index e7b22110b..0b0e84e76 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleError.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/packet/JingleError.java @@ -119,8 +119,8 @@ public class JingleError implements ExtensionElement { } public String getNamespace() { - return NAMESPACE; - } + return NAMESPACE; + } public static class Provider extends ExtensionElementProvider { diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleContentDescriptionProvider.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleContentDescriptionProvider.java index 51b1b6d43..b636fd9d4 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleContentDescriptionProvider.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleContentDescriptionProvider.java @@ -127,6 +127,6 @@ public abstract class JingleContentDescriptionProvider extends ExtensionElementP */ protected JingleContentDescription getInstance() { return new JingleContentDescription.Audio(); - } - } + } + } } diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleContentInfoProvider.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleContentInfoProvider.java index 72c9d8681..6c5bed356 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleContentInfoProvider.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/provider/JingleContentInfoProvider.java @@ -103,7 +103,7 @@ public class JingleContentInfoProvider { public static class Ringing extends Audio { public Ringing() { super(new JingleContentInfo.Audio.Ringing()); - } - } - } + } + } + } } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RemoteRosterEntry.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RemoteRosterEntry.java index a84c8b2fa..fb2eda00a 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RemoteRosterEntry.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RemoteRosterEntry.java @@ -51,9 +51,9 @@ public class RemoteRosterEntry { public RemoteRosterEntry(Jid user, String name, String [] groups) { this.user = user; this.name = name; - if (groups != null) { + if (groups != null) { groupNames.addAll(Arrays.asList(groups)); - } + } } /** diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/packet/RosterExchange.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/packet/RosterExchange.java index 3cec05ebd..1b579d8f8 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/packet/RosterExchange.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/packet/RosterExchange.java @@ -78,13 +78,13 @@ public class RosterExchange implements ExtensionElement { * @param rosterEntry a roster entry to add. */ public void addRosterEntry(RosterEntry rosterEntry) { - // Obtain a String[] from the roster entry groups name - List groupNamesList = new ArrayList(); - String[] groupNames; - for (RosterGroup group : rosterEntry.getGroups()) { - groupNamesList.add(group.getName()); - } - groupNames = groupNamesList.toArray(new String[groupNamesList.size()]); + // Obtain a String[] from the roster entry groups name + List groupNamesList = new ArrayList(); + String[] groupNames; + for (RosterGroup group : rosterEntry.getGroups()) { + groupNamesList.add(group.getName()); + } + groupNames = groupNamesList.toArray(new String[groupNamesList.size()]); // Create a new Entry based on the rosterEntry and add it to the packet RemoteRosterEntry remoteRosterEntry = new RemoteRosterEntry(rosterEntry.getJid(), diff --git a/smack-sasl-provided/src/main/java/org/jivesoftware/smack/sasl/provided/SASLProvidedSmackInitializer.java b/smack-sasl-provided/src/main/java/org/jivesoftware/smack/sasl/provided/SASLProvidedSmackInitializer.java index 849ccbc15..ad30919a5 100644 --- a/smack-sasl-provided/src/main/java/org/jivesoftware/smack/sasl/provided/SASLProvidedSmackInitializer.java +++ b/smack-sasl-provided/src/main/java/org/jivesoftware/smack/sasl/provided/SASLProvidedSmackInitializer.java @@ -23,12 +23,12 @@ import org.jivesoftware.smack.initializer.SmackInitializer; public class SASLProvidedSmackInitializer implements SmackInitializer { - @Override - public List initialize() { - SASLAuthentication.registerSASLMechanism(new SASLDigestMD5Mechanism()); - SASLAuthentication.registerSASLMechanism(new SASLExternalMechanism()); - SASLAuthentication.registerSASLMechanism(new SASLPlainMechanism()); - return null; - } + @Override + public List initialize() { + SASLAuthentication.registerSASLMechanism(new SASLDigestMD5Mechanism()); + SASLAuthentication.registerSASLMechanism(new SASLExternalMechanism()); + SASLAuthentication.registerSASLMechanism(new SASLPlainMechanism()); + return null; + } }