@@ -28,8 +28,13 @@ public class Conf {
2828 public static final String NOTIFY_CONFIG = "pubsub#notify_config" ;
2929 public static final String CHANNEL_TYPE = "buddycloud#channel_type" ;
3030 private static final String PUBLISHERS = "publishers" ;
31- public static final DateTimeFormatter ISO_8601_PARSER = ISODateTimeFormat .dateTimeParser ();
32- public static final DateTimeFormatter ISO_8601_FORMATTER = ISODateTimeFormat .dateTime ();
31+ public static final DateTimeFormatter ISO_8601_PARSER = ISODateTimeFormat
32+ .dateTimeParser ();
33+ public static final DateTimeFormatter ISO_8601_FORMATTER = ISODateTimeFormat
34+ .dateTime ();
35+
36+ private static Configuration projectConf ;
37+ private static HashMap <String , String > conf ;
3338
3439 public static String getPostChannelNodename (JID channelJID ) {
3540 return "/user/" + channelJID .toBareJID () + "/posts" ;
@@ -50,18 +55,16 @@ public static String formatDate(Date date) {
5055 return ISO_8601_FORMATTER .print (date .getTime ());
5156 }
5257
53- public static HashMap <String , String > getDefaultChannelConf (JID channelJID , JID ownerJID ) {
58+ public static HashMap <String , String > getDefaultChannelConf (JID channelJID ,
59+ JID ownerJID ) {
5460 HashMap <String , String > conf = getDefaultConf (channelJID , null );
55- conf .put (TITLE , channelJID .toBareJID () + "'s title" );
56- conf .put (DESCRIPTION , channelJID .toBareJID () + "'s description" );
5761 conf .put (OWNER , ownerJID .toBareJID ());
5862 return conf ;
5963 }
6064
61- public static HashMap <String , String > getDefaultPostChannelConf (JID channelJID ) {
65+ public static HashMap <String , String > getDefaultPostChannelConf (
66+ JID channelJID ) {
6267 HashMap <String , String > conf = getDefaultConf (channelJID , "posts" );
63- conf .put (TITLE , channelJID .toBareJID () + "'s very own buddycloud channel!" );
64- conf .put (DESCRIPTION , "This channel belongs to " + channelJID .toBareJID () + ". To nobody else!" );
6568 conf .put (CHANNEL_TYPE , "personal" );
6669 return conf ;
6770 }
@@ -70,87 +73,141 @@ public static String getStatusChannelNodename(JID channelJID) {
7073 return "/user/" + channelJID .toBareJID () + "/status" ;
7174 }
7275
73- public static HashMap <String , String > getDefaultStatusChannelConf (JID channelJID ) {
76+ public static HashMap <String , String > getDefaultStatusChannelConf (
77+ JID channelJID ) {
7478 HashMap <String , String > conf = getDefaultConf (channelJID , "status" );
75- conf .put (TITLE , channelJID .toBareJID () + "'s very own buddycloud status!" );
76- conf .put (DESCRIPTION , "This is " + channelJID .toBareJID () + "'s mood a.k.a status -channel. Depends how geek you are." );
7779 return conf ;
7880 }
7981
8082 public static String getGeoPreviousChannelNodename (JID channelJID ) {
8183 return "/user/" + channelJID .toBareJID () + "/geo/previous" ;
8284 }
8385
84- public static HashMap <String , String > getDefaultGeoPreviousChannelConf (JID channelJID ) {
85- HashMap < String , String > conf = getDefaultConf ( channelJID , "geo/previous" );
86- conf . put ( TITLE , channelJID . toBareJID () + "'s previous location." );
87- conf . put ( DESCRIPTION , "Where " + channelJID . toBareJID () + " has been before. " );
86+ public static HashMap <String , String > getDefaultGeoPreviousChannelConf (
87+ JID channelJID ) {
88+ HashMap < String , String > conf = getDefaultConf ( channelJID ,
89+ "geo/previous " );
8890 return conf ;
8991 }
9092
9193 public static String getGeoCurrentChannelNodename (JID channelJID ) {
9294 return "/user/" + channelJID .toBareJID () + "/geo/current" ;
9395 }
9496
95- public static HashMap <String , String > getDefaultGeoCurrentChannelConf (JID channelJID ) {
97+ public static HashMap <String , String > getDefaultGeoCurrentChannelConf (
98+ JID channelJID ) {
9699 HashMap <String , String > conf = getDefaultConf (channelJID , "geo/current" );
97- conf .put (TITLE , channelJID .toBareJID () + "'s current location." );
98- conf .put (DESCRIPTION , "Where " + channelJID .toBareJID () + " is now." );
99100 return conf ;
100101 }
101102
102103 public static String getGeoNextChannelNodename (JID channelJID ) {
103104 return "/user/" + channelJID .toBareJID () + "/geo/next" ;
104105 }
105106
106- public static HashMap <String , String > getDefaultGeoNextChannelConf (JID channelJID ) {
107+ public static HashMap <String , String > getDefaultGeoNextChannelConf (
108+ JID channelJID ) {
107109 HashMap <String , String > conf = getDefaultConf (channelJID , "geo/next" );
108- conf .put (TITLE , channelJID .toBareJID () + "'s next location." );
109- conf .put (DESCRIPTION , "Where " + channelJID .toBareJID () + " is going to go." );
110110 return conf ;
111111 }
112112
113113 public static String getSubscriptionsChannelNodename (JID channelJID ) {
114114 return "/user/" + channelJID .toBareJID () + "/subscriptions" ;
115115 }
116116
117- public static HashMap <String , String > getDefaultSubscriptionsChannelConf (JID channelJID ) {
118- HashMap < String , String > conf = getDefaultConf ( channelJID , "subscriptions" );
119- conf . put ( TITLE , channelJID . toBareJID () + "'s susbcriptions." );
120- conf . put ( DESCRIPTION , channelJID . toBareJID () + "'s subscriptions. " );
117+ public static HashMap <String , String > getDefaultSubscriptionsChannelConf (
118+ JID channelJID ) {
119+ HashMap < String , String > conf = getDefaultConf ( channelJID ,
120+ " subscriptions" );
121121 return conf ;
122122 }
123123
124- private static HashMap <String , String > getDefaultConf (JID channelJID , String node ) {
125-
126- HashMap <String , String > conf = new HashMap <String , String >();
127- Configuration projectConf = Configuration .getInstance ();
124+ private static HashMap <String , String > getDefaultConf (JID channelJID ,
125+ String node ) {
126+
127+ conf = new HashMap <String , String >();
128+ projectConf = Configuration .getInstance ();
129+ conf .put (
130+ TITLE ,
131+ projectConf .getProperty (
132+ Configuration .CONFIGURATION_CHANNELS_DEFAULT_TITLE ,
133+ "%jid%'s very own buddycloud channel" ).replace ("%jid%" ,
134+ channelJID .toBareJID ()));
135+
136+ conf .put (
137+ DESCRIPTION ,
138+ projectConf
139+ .getProperty (
140+ Configuration .CONFIGURATION_CHANNELS_DEFAULT_DESCRIPTION ,
141+ "%jid%'s very own buddycloud channel" ).replace (
142+ "%jid%" , channelJID .toBareJID ()));
143+
128144 conf .put (TYPE , "http://www.w3.org/2005/Atom" );
129145 conf .put (PUBLISH_MODEL , PUBLISHERS );
130146 conf .put (CREATION_DATE , formatDate (new Date ()));
131147 conf .put (OWNER , channelJID .toBareJID ());
132148
133- conf .put (ACCESS_MODEL , AccessModels .createFromString (projectConf .getProperty (
134- Configuration .CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL , AccessModels .open .toString ())).toString ());
135- conf .put (DEFAULT_AFFILIATION , Affiliations .createFromString (
136- projectConf .getProperty (Configuration .CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION , Affiliations .member .toString ()))
137- .toString ());
149+ conf .put (
150+ ACCESS_MODEL ,
151+ AccessModels
152+ .createFromString (
153+ projectConf
154+ .getProperty (
155+ Configuration .CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL ,
156+ AccessModels .open .toString ()))
157+ .toString ());
158+ conf .put (
159+ DEFAULT_AFFILIATION ,
160+ Affiliations
161+ .createFromString (
162+ projectConf
163+ .getProperty (
164+ Configuration .CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION ,
165+ Affiliations .member .toString ()))
166+ .toString ());
138167 conf .put (NUM_SUBSCRIBERS , "1" );
139168 conf .put (NOTIFY_CONFIG , "1" );
140-
141- if (null != node ) {
142- String accessModelKey = Configuration .CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL .replace ("default" , node .replace ("/" , "." ));
143- if (null != projectConf .getProperty (accessModelKey )) {
144- conf .put (ACCESS_MODEL , AccessModels .createFromString (projectConf .getProperty (
145- accessModelKey )).toString ());
146- }
147-
148- String affiliationKey = Configuration .CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION .replace ("default" , node .replace ("/" , "." ));
149- if (null != projectConf .getProperty (affiliationKey )) {
150- conf .put (DEFAULT_AFFILIATION , Affiliations .createFromString (projectConf .getProperty (
151- affiliationKey )).toString ());
152- }
153- }
169+
170+ getConfigurationOverrides (channelJID , node );
154171 return conf ;
155172 }
173+
174+ private static void getConfigurationOverrides (JID channelJID , String node ) {
175+
176+ if (null == node )
177+ return ;
178+
179+ String accessModelKey = Configuration .CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL
180+ .replace ("default" , node .replace ("/" , "." ));
181+ if (null != projectConf .getProperty (accessModelKey )) {
182+ conf .put (
183+ ACCESS_MODEL ,
184+ AccessModels .createFromString (
185+ projectConf .getProperty (accessModelKey )).toString ());
186+ }
187+
188+ String affiliationKey = Configuration .CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION
189+ .replace ("default" , node .replace ("/" , "." ));
190+ if (null != projectConf .getProperty (affiliationKey )) {
191+ conf .put (
192+ DEFAULT_AFFILIATION ,
193+ Affiliations .createFromString (
194+ projectConf .getProperty (affiliationKey )).toString ());
195+ }
196+ String titleKey = Configuration .CONFIGURATION_CHANNELS_DEFAULT_TITLE
197+ .replace ("default" , node .replace ("/" , "." ));
198+
199+ if (null != projectConf .getProperty (titleKey )) {
200+ String title = projectConf .getProperty (titleKey ).replace ("%jid%" ,
201+ channelJID .toBareJID ());
202+ conf .put (TITLE , title );
203+ }
204+ String descriptionKey = Configuration .CONFIGURATION_CHANNELS_DEFAULT_DESCRIPTION
205+ .replace ("default" , node .replace ("/" , "." ));
206+ if (null != projectConf .getProperty (descriptionKey )) {
207+ String description = projectConf .getProperty (descriptionKey )
208+ .replace ("%jid%" , channelJID .toBareJID ());
209+ conf .put (DESCRIPTION , description );
210+ }
211+
212+ }
156213}
0 commit comments