Skip to content

Commit 0663ca0

Browse files
author
Lloyd Watkin
committed
Merge branch 'master' of github.com:buddycloud/buddycloud-server-java into delete-notifications
2 parents 091a17e + 60f0952 commit 0663ca0

87 files changed

Lines changed: 4407 additions & 2351 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/org/buddycloud/channelserver/ChannelsEngine.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ private void setupManagers() throws ComponentException {
110110
throw new ComponentException(e);
111111
}
112112

113-
channelManagerFactory = new ChannelManagerFactoryImpl(configuration, nodeStoreFactory);
114-
federatedQueueManager = new FederatedQueueManager(this, configuration);
113+
channelManagerFactory = new ChannelManagerFactoryImpl(nodeStoreFactory);
114+
federatedQueueManager = new FederatedQueueManager(this,
115+
configuration);
115116
onlineUsers = new OnlineResourceManager(configuration, channelManagerFactory.create());
116117
}
117118

src/main/java/org/buddycloud/channelserver/Configuration.java

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Properties;
1212

1313
import org.apache.log4j.Logger;
14+
import org.buddycloud.channelserver.channel.LocalDomainChecker;
1415
import org.xmpp.packet.JID;
1516

1617
public class Configuration extends Properties {
@@ -19,12 +20,13 @@ public class Configuration extends Properties {
1920
private static final long serialVersionUID = 1L;
2021

2122
private static final String ARRAY_PROPERTY_SEPARATOR = ";";
23+
private static final String INVALID_NODE = "Illegal node format";
2224

2325
public static final String CONFIGURATION_SERVER_DOMAIN = "server.domain";
2426
public static final String CONFIGURATION_SERVER_CHANNELS_DOMAIN = "server.domain.channels";
2527
public static final String CONFIGURATION_SERVER_TOPICS_DOMAIN = "server.domain.topics";
2628
public static final String CONFIGURATION_LOCAL_DOMAIN_CHECKER = "server.domain.checker";
27-
29+
2830
public static final String CONFIGURATION_ADMIN_USERS = "users.admin";
2931

3032
public static final String CONFIGURATION_CHANNELS_AUTOSUBSCRIBE = "channels.autosubscribe";
@@ -33,17 +35,17 @@ public class Configuration extends Properties {
3335
public static final String CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL = "channel.configuration.default.accessmodel";
3436
public static final String CONFIGURATION_CHANNELS_DEFAULT_DESCRIPTION = "channel.configuration.default.description";
3537
public static final String CONFIGURATION_CHANNELS_DEFAULT_TITLE = "channel.configuration.default.title";
36-
38+
3739
public static final String DISCOVERY_USE_DNS = "discovery.dns.enabled";
3840

3941
public static final String PERSIST_PRESENCE_DATA = "users.presence.persist";
40-
42+
4143
public static final String NOTIFICATIONS_SENDTO = "notifications.sendTo";
4244
public static final String NOTIFICATIONS_CONNECTED = "notifications.connected";
43-
45+
4446
private static final String CONFIGURATION_FILE = "configuration.properties";
4547

46-
public static final String PURGE_REMOTE_ON_START = "sync.purge-on-start";
48+
public static final String PURGE_REMOTE_ON_START = "sync.purge-on-start";
4749

4850
public static final String XMPP_PORT = "xmpp.port";
4951

@@ -59,21 +61,23 @@ public class Configuration extends Properties {
5961
private Configuration() {
6062
try {
6163
conf = new Properties();
62-
InputStream confFile = this.getClass().getClassLoader().getResourceAsStream(CONFIGURATION_FILE);
64+
InputStream confFile = this.getClass().getClassLoader()
65+
.getResourceAsStream(CONFIGURATION_FILE);
6366
if (confFile != null) {
6467
load(confFile);
6568
LOGGER.info("Loaded " + CONFIGURATION_FILE + " from classpath.");
6669
} else {
6770
File f = new File(CONFIGURATION_FILE);
6871
load(new FileInputStream(f));
69-
LOGGER.info("Loaded " + CONFIGURATION_FILE + " from working directory.");
72+
LOGGER.info("Loaded " + CONFIGURATION_FILE
73+
+ " from working directory.");
7074
}
7175
} catch (Exception e) {
7276
LOGGER.error("Could not load " + CONFIGURATION_FILE + "!");
7377
System.exit(1);
7478
}
7579
}
76-
80+
7781
private void setupCollections() {
7882
adminUsers = getJIDArrayProperty(CONFIGURATION_ADMIN_USERS);
7983
autosubscribeChannels = getJIDArrayProperty(CONFIGURATION_CHANNELS_AUTOSUBSCRIBE);
@@ -93,18 +97,31 @@ public static Configuration getInstance() {
9397
}
9498
return instance;
9599
}
100+
101+
public static void reset() {
102+
instance = null;
103+
}
96104

97105
public String getProperty(String key) {
98106
return conf.getProperty(key);
99107
}
100-
108+
109+
@Override
110+
public synchronized Object remove(Object key) {
111+
return conf.remove(key);
112+
}
113+
101114
public void clear() {
102115
conf.clear();
103116
}
104117

105118
public String getProperty(String key, String defaultValue) {
106119
return conf.getProperty(key, defaultValue);
107120
}
121+
122+
public void putProperty(String key, String value) {
123+
conf.put(key, value);
124+
}
108125

109126
public void load(InputStream inputStream) throws IOException {
110127
conf.load(inputStream);
@@ -122,7 +139,6 @@ private Collection<String> getStringArrayProperty(String key) {
122139
}
123140

124141
private Collection<JID> getJIDArrayProperty(String key) {
125-
System.out.println(conf.getProperty(CONFIGURATION_CHANNELS_AUTOSUBSCRIBE));
126142
Collection<String> props = getStringArrayProperty(key);
127143

128144
Collection<JID> jids = new ArrayList<JID>(props.size());
@@ -137,7 +153,7 @@ private Collection<JID> getJIDArrayProperty(String key) {
137153

138154
return jids;
139155
}
140-
156+
141157
public ArrayList<JID> getNotificationsList(String event) {
142158
ArrayList<JID> notify = new ArrayList<JID>();
143159
if (!getBooleanProperty(event, false)) {
@@ -168,7 +184,8 @@ public String getServerTopicsDomain() {
168184
return getProperty(CONFIGURATION_SERVER_TOPICS_DOMAIN);
169185
}
170186

171-
public boolean getBooleanProperty(final String key, final boolean defaultValue) {
187+
public boolean getBooleanProperty(final String key,
188+
final boolean defaultValue) {
172189
String value = getProperty(key);
173190

174191
if (value != null) {
@@ -178,17 +195,36 @@ public boolean getBooleanProperty(final String key, final boolean defaultValue)
178195
if (value.equalsIgnoreCase("false")) {
179196
return false;
180197
}
181-
LOGGER.warn("Invalid boolean property value for " + key + ": " + value);
198+
LOGGER.warn("Invalid boolean property value for " + key + ": "
199+
+ value);
182200
}
183201

184202
return defaultValue;
185203
}
186204

187-
public String getComponentPort() {
205+
public String getComponentPort() {
188206
return this.getProperty(XMPP_PORT, "5347");
189207
}
190208

191209
public String getXmppHost() {
192210
return this.getProperty(XMPP_HOST, "127.0.0.1");
193211
}
212+
213+
public boolean isLocalDomain(String domain) {
214+
return LocalDomainChecker.isLocal(domain, this);
215+
}
216+
217+
public boolean isLocalNode(String nodeId) {
218+
if (false == nodeId.matches("/user/.+@.+/.+")) {
219+
LOGGER.debug("Node " + nodeId + " has an invalid format");
220+
throw new IllegalArgumentException(INVALID_NODE);
221+
}
222+
String domain = new JID(nodeId.split("/")[2]).getDomain();
223+
return isLocalDomain(domain);
224+
}
225+
226+
public boolean isLocalJID(JID jid) {
227+
String domain = jid.getDomain();
228+
return isLocalDomain(domain);
229+
}
194230
}

src/main/java/org/buddycloud/channelserver/channel/ChannelManager.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,6 @@ public interface ChannelManager extends NodeStore {
1919
*/
2020
void createPersonalChannel(JID ownerJID) throws NodeStoreException;
2121

22-
/**
23-
* Determines whether the node id given refers to a local node.
24-
*
25-
* @param nodeId the node id
26-
* @return <code>true</code> if the node appears to be local, <code>false</code> otherwise.
27-
* @throws NodeStoreException
28-
*/
29-
boolean isLocalNode(String nodeId) throws NodeStoreException;
30-
31-
/**
32-
* Determines whether the jid refers to a local user.
33-
*
34-
* @param jid the user's jid
35-
* @return <code>true</code> if the jid appears to be local, <code>false</code> otherwise.
36-
* @throws NodeStoreException
37-
*/
38-
boolean isLocalJID(JID jid) throws NodeStoreException;
39-
40-
/**
41-
* Determines whether the domain is served by this server.
42-
*
43-
* @param domain the domain name
44-
* @return <code>true</code> if the domain appears to be local, <code>false</code> otherwise.
45-
* @throws NodeStoreException
46-
*/
47-
boolean isLocalDomain(String domain) throws NodeStoreException;
48-
49-
5022
/**
5123
* Deletes all data from remote nodes
5224
*
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
package org.buddycloud.channelserver.channel;
22

3-
import java.util.Properties;
4-
53
import org.buddycloud.channelserver.db.NodeStoreFactory;
64

75
public class ChannelManagerFactoryImpl implements ChannelManagerFactory {
86

9-
private final Properties configuration;
107
private final NodeStoreFactory nodeStoreFactory;
118

12-
public ChannelManagerFactoryImpl(final Properties configuration, final NodeStoreFactory nodeStoreFactory) {
13-
this.configuration = configuration;
9+
public ChannelManagerFactoryImpl(final NodeStoreFactory nodeStoreFactory) {
1410
this.nodeStoreFactory = nodeStoreFactory;
1511
}
1612

1713
@Override
1814
public ChannelManager create() {
19-
return new ChannelManagerImpl(nodeStoreFactory.create(), configuration);
15+
return new ChannelManagerImpl(nodeStoreFactory.create());
2016
}
2117

2218
}

0 commit comments

Comments
 (0)