Skip to content

Commit f02e8e7

Browse files
author
Lloyd Watkin
committed
Allow overriding of default configuration key on a per-node basis
1 parent 1b4e91b commit f02e8e7

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

  • src/main/java/org/buddycloud/channelserver/channel

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ public static String formatDate(Date date) {
5151
}
5252

5353
public static HashMap<String, String> getDefaultChannelConf(JID channelJID, JID ownerJID) {
54-
HashMap<String, String> conf = getDefaultConf(channelJID);
54+
HashMap<String, String> conf = getDefaultConf(channelJID, null);
5555
conf.put(TITLE, channelJID.toBareJID() + "'s title");
5656
conf.put(DESCRIPTION, channelJID.toBareJID() + "'s description");
5757
conf.put(OWNER, ownerJID.toBareJID());
5858
return conf;
5959
}
6060

6161
public static HashMap<String, String> getDefaultPostChannelConf(JID channelJID) {
62-
HashMap<String, String> conf = getDefaultConf(channelJID);
62+
HashMap<String, String> conf = getDefaultConf(channelJID, "posts");
6363
conf.put(TITLE, channelJID.toBareJID() + "'s very own buddycloud channel!");
6464
conf.put(DESCRIPTION, "This channel belongs to " + channelJID.toBareJID() + ". To nobody else!");
6565
conf.put(CHANNEL_TYPE, "personal");
@@ -71,7 +71,7 @@ public static String getStatusChannelNodename(JID channelJID) {
7171
}
7272

7373
public static HashMap<String, String> getDefaultStatusChannelConf(JID channelJID) {
74-
HashMap<String, String> conf = getDefaultConf(channelJID);
74+
HashMap<String, String> conf = getDefaultConf(channelJID, "status");
7575
conf.put(TITLE, channelJID.toBareJID() + "'s very own buddycloud status!");
7676
conf.put(DESCRIPTION, "This is " + channelJID.toBareJID() + "'s mood a.k.a status -channel. Depends how geek you are.");
7777
return conf;
@@ -82,7 +82,7 @@ public static String getGeoPreviousChannelNodename(JID channelJID) {
8282
}
8383

8484
public static HashMap<String, String> getDefaultGeoPreviousChannelConf(JID channelJID) {
85-
HashMap<String, String> conf = getDefaultConf(channelJID);
85+
HashMap<String, String> conf = getDefaultConf(channelJID, "geo/previous");
8686
conf.put(TITLE, channelJID.toBareJID() + "'s previous location.");
8787
conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " has been before.");
8888
return conf;
@@ -93,7 +93,7 @@ public static String getGeoCurrentChannelNodename(JID channelJID) {
9393
}
9494

9595
public static HashMap<String, String> getDefaultGeoCurrentChannelConf(JID channelJID) {
96-
HashMap<String, String> conf = getDefaultConf(channelJID);
96+
HashMap<String, String> conf = getDefaultConf(channelJID, "geo/current");
9797
conf.put(TITLE, channelJID.toBareJID() + "'s current location.");
9898
conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " is now.");
9999
return conf;
@@ -104,7 +104,7 @@ public static String getGeoNextChannelNodename(JID channelJID) {
104104
}
105105

106106
public static HashMap<String, String> getDefaultGeoNextChannelConf(JID channelJID) {
107-
HashMap<String, String> conf = getDefaultConf(channelJID);
107+
HashMap<String, String> conf = getDefaultConf(channelJID, "geo/next");
108108
conf.put(TITLE, channelJID.toBareJID() + "'s next location.");
109109
conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " is going to go.");
110110
return conf;
@@ -115,13 +115,14 @@ public static String getSubscriptionsChannelNodename(JID channelJID) {
115115
}
116116

117117
public static HashMap<String, String> getDefaultSubscriptionsChannelConf(JID channelJID) {
118-
HashMap<String, String> conf = getDefaultConf(channelJID);
118+
HashMap<String, String> conf = getDefaultConf(channelJID, "subscriptions");
119119
conf.put(TITLE, channelJID.toBareJID() + "'s susbcriptions.");
120120
conf.put(DESCRIPTION, channelJID.toBareJID() + "'s subscriptions. ");
121121
return conf;
122122
}
123123

124-
private static HashMap<String, String> getDefaultConf(JID channelJID) {
124+
private static HashMap<String, String> getDefaultConf(JID channelJID, String node) {
125+
125126
HashMap<String, String> conf = new HashMap<String, String>();
126127
Configuration projectConf = Configuration.getInstance();
127128
conf.put(TYPE, "http://www.w3.org/2005/Atom");
@@ -131,10 +132,24 @@ private static HashMap<String, String> getDefaultConf(JID channelJID) {
131132
conf.put(ACCESS_MODEL, AccessModels.createFromString(projectConf.getProperty(
132133
Configuration.CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL, AccessModels.authorize.toString())).toString());
133134
conf.put(DEFAULT_AFFILIATION, Affiliations.createFromString(
134-
projectConf.getProperty(Configuration.CONFIGURATION_CHANNELS_DEFAULT_ROLE, Affiliations.member.toString()))
135+
projectConf.getProperty(Configuration.CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION, Affiliations.member.toString()))
135136
.toString());
136137
conf.put(NUM_SUBSCRIBERS, "1");
137138
conf.put(NOTIFY_CONFIG, "1");
139+
140+
if (null != node) {
141+
String accessModelKey = Configuration.CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL.replace("default", node.replace("/", "."));
142+
if (null != projectConf.getProperty(accessModelKey)) {
143+
conf.put(ACCESS_MODEL, AccessModels.createFromString(projectConf.getProperty(
144+
accessModelKey)).toString());
145+
}
146+
147+
String affiliationKey = Configuration.CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION.replace("default", node.replace("/", "."));
148+
if (null != projectConf.getProperty(affiliationKey)) {
149+
conf.put(DEFAULT_AFFILIATION, Affiliations.createFromString(projectConf.getProperty(
150+
affiliationKey)).toString());
151+
}
152+
}
138153
return conf;
139154
}
140155
}

0 commit comments

Comments
 (0)