@@ -28,40 +28,45 @@ 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" ;
3641 }
3742
3843 /**
3944 * Parses a ISO 8601 to a string
40- *
45+ *
4146 * @param iso8601Str
4247 * @return
43- * @throws IllegalArgumentException if the provided string is not ISO 8601
48+ * @throws IllegalArgumentException
49+ * if the provided string is not ISO 8601
4450 */
45- public static Date parseDate (String iso8601Str ) throws IllegalArgumentException {
51+ public static Date parseDate (String iso8601Str )
52+ throws IllegalArgumentException {
4653 return ISO_8601_PARSER .parseDateTime (iso8601Str ).toDate ();
4754 }
4855
4956 public static String formatDate (Date date ) {
5057 return ISO_8601_FORMATTER .print (date .getTime ());
5158 }
5259
53- public static HashMap <String , String > getDefaultChannelConf (JID channelJID , JID ownerJID ) {
54- HashMap <String , String > conf = getDefaultConf (channelJID );
55- conf .put (TITLE , channelJID .toBareJID () + "'s title" );
56- conf .put (DESCRIPTION , channelJID .toBareJID () + "'s description" );
60+ public static HashMap <String , String > getDefaultChannelConf (JID channelJID ,
61+ JID ownerJID ) {
62+ HashMap <String , String > conf = getDefaultConf (channelJID , null );
5763 conf .put (OWNER , ownerJID .toBareJID ());
5864 return conf ;
5965 }
6066
61- public static HashMap <String , String > getDefaultPostChannelConf (JID channelJID ) {
62- HashMap <String , String > conf = getDefaultConf (channelJID );
63- conf .put (TITLE , channelJID .toBareJID () + "'s very own buddycloud channel!" );
64- conf .put (DESCRIPTION , "This channel belongs to " + channelJID .toBareJID () + ". To nobody else!" );
67+ public static HashMap <String , String > getDefaultPostChannelConf (
68+ JID channelJID ) {
69+ HashMap <String , String > conf = getDefaultConf (channelJID , "posts" );
6570 conf .put (CHANNEL_TYPE , "personal" );
6671 return conf ;
6772 }
@@ -70,71 +75,141 @@ public static String getStatusChannelNodename(JID channelJID) {
7075 return "/user/" + channelJID .toBareJID () + "/status" ;
7176 }
7277
73- public static HashMap <String , String > getDefaultStatusChannelConf (JID channelJID ) {
74- HashMap <String , String > conf = getDefaultConf (channelJID );
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." );
78+ public static HashMap <String , String > getDefaultStatusChannelConf (
79+ JID channelJID ) {
80+ HashMap <String , String > conf = getDefaultConf (channelJID , "status" );
7781 return conf ;
7882 }
7983
8084 public static String getGeoPreviousChannelNodename (JID channelJID ) {
8185 return "/user/" + channelJID .toBareJID () + "/geo/previous" ;
8286 }
8387
84- public static HashMap <String , String > getDefaultGeoPreviousChannelConf (JID channelJID ) {
85- HashMap < String , String > conf = getDefaultConf ( channelJID );
86- conf . put ( TITLE , channelJID . toBareJID () + "'s previous location." );
87- conf . put ( DESCRIPTION , "Where " + channelJID . toBareJID () + " has been before. " );
88+ public static HashMap <String , String > getDefaultGeoPreviousChannelConf (
89+ JID channelJID ) {
90+ HashMap < String , String > conf = getDefaultConf ( channelJID ,
91+ "geo/previous " );
8892 return conf ;
8993 }
9094
9195 public static String getGeoCurrentChannelNodename (JID channelJID ) {
9296 return "/user/" + channelJID .toBareJID () + "/geo/current" ;
9397 }
9498
95- public static HashMap <String , String > getDefaultGeoCurrentChannelConf (JID channelJID ) {
96- HashMap <String , String > conf = getDefaultConf (channelJID );
97- conf .put (TITLE , channelJID .toBareJID () + "'s current location." );
98- conf .put (DESCRIPTION , "Where " + channelJID .toBareJID () + " is now." );
99+ public static HashMap <String , String > getDefaultGeoCurrentChannelConf (
100+ JID channelJID ) {
101+ HashMap <String , String > conf = getDefaultConf (channelJID , "geo/current" );
99102 return conf ;
100103 }
101104
102105 public static String getGeoNextChannelNodename (JID channelJID ) {
103106 return "/user/" + channelJID .toBareJID () + "/geo/next" ;
104107 }
105108
106- public static HashMap <String , String > getDefaultGeoNextChannelConf (JID channelJID ) {
107- HashMap <String , String > conf = getDefaultConf (channelJID );
108- conf .put (TITLE , channelJID .toBareJID () + "'s next location." );
109- conf .put (DESCRIPTION , "Where " + channelJID .toBareJID () + " is going to go." );
109+ public static HashMap <String , String > getDefaultGeoNextChannelConf (
110+ JID channelJID ) {
111+ HashMap <String , String > conf = getDefaultConf (channelJID , "geo/next" );
110112 return conf ;
111113 }
112114
113115 public static String getSubscriptionsChannelNodename (JID channelJID ) {
114116 return "/user/" + channelJID .toBareJID () + "/subscriptions" ;
115117 }
116118
117- public static HashMap <String , String > getDefaultSubscriptionsChannelConf (JID channelJID ) {
118- HashMap < String , String > conf = getDefaultConf ( channelJID );
119- conf . put ( TITLE , channelJID . toBareJID () + "'s susbcriptions." );
120- conf . put ( DESCRIPTION , channelJID . toBareJID () + "'s subscriptions. " );
119+ public static HashMap <String , String > getDefaultSubscriptionsChannelConf (
120+ JID channelJID ) {
121+ HashMap < String , String > conf = getDefaultConf ( channelJID ,
122+ " subscriptions" );
121123 return conf ;
122124 }
123125
124- private static HashMap <String , String > getDefaultConf (JID channelJID ) {
125- HashMap <String , String > conf = new HashMap <String , String >();
126- Configuration projectConf = Configuration .getInstance ();
126+ private static HashMap <String , String > getDefaultConf (JID channelJID ,
127+ String node ) {
128+
129+ conf = new HashMap <String , String >();
130+ projectConf = Configuration .getInstance ();
131+ conf .put (
132+ TITLE ,
133+ projectConf .getProperty (
134+ Configuration .CONFIGURATION_CHANNELS_DEFAULT_TITLE ,
135+ "%jid%'s very own buddycloud channel" ).replace ("%jid%" ,
136+ channelJID .toBareJID ()));
137+
138+ conf .put (
139+ DESCRIPTION ,
140+ projectConf
141+ .getProperty (
142+ Configuration .CONFIGURATION_CHANNELS_DEFAULT_DESCRIPTION ,
143+ "%jid%'s very own buddycloud channel" ).replace (
144+ "%jid%" , channelJID .toBareJID ()));
145+
127146 conf .put (TYPE , "http://www.w3.org/2005/Atom" );
128147 conf .put (PUBLISH_MODEL , PUBLISHERS );
129148 conf .put (CREATION_DATE , formatDate (new Date ()));
130149 conf .put (OWNER , channelJID .toBareJID ());
131- conf .put (ACCESS_MODEL , AccessModels .createFromString (projectConf .getProperty (
132- Configuration .CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL )).toString ());
133- conf .put (DEFAULT_AFFILIATION , Affiliations .createFromBuddycloudString (
134- projectConf .getProperty (Configuration .CONFIGURATION_CHANNELS_DEFAULT_ROLE ))
135- .toString ());
150+
151+ conf .put (
152+ ACCESS_MODEL ,
153+ AccessModels
154+ .createFromString (
155+ projectConf
156+ .getProperty (
157+ Configuration .CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL ,
158+ AccessModels .open .toString ()))
159+ .toString ());
160+ conf .put (
161+ DEFAULT_AFFILIATION ,
162+ Affiliations
163+ .createFromString (
164+ projectConf
165+ .getProperty (
166+ Configuration .CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION ,
167+ Affiliations .member .toString ()))
168+ .toString ());
136169 conf .put (NUM_SUBSCRIBERS , "1" );
137170 conf .put (NOTIFY_CONFIG , "1" );
171+
172+ getConfigurationOverrides (channelJID , node );
138173 return conf ;
139174 }
175+
176+ private static void getConfigurationOverrides (JID channelJID , String node ) {
177+
178+ if (null == node )
179+ return ;
180+
181+ String accessModelKey = Configuration .CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL
182+ .replace ("default" , node .replace ("/" , "." ));
183+ if (null != projectConf .getProperty (accessModelKey )) {
184+ conf .put (
185+ ACCESS_MODEL ,
186+ AccessModels .createFromString (
187+ projectConf .getProperty (accessModelKey )).toString ());
188+ }
189+
190+ String affiliationKey = Configuration .CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION
191+ .replace ("default" , node .replace ("/" , "." ));
192+ if (null != projectConf .getProperty (affiliationKey )) {
193+ conf .put (
194+ DEFAULT_AFFILIATION ,
195+ Affiliations .createFromString (
196+ projectConf .getProperty (affiliationKey )).toString ());
197+ }
198+ String titleKey = Configuration .CONFIGURATION_CHANNELS_DEFAULT_TITLE
199+ .replace ("default" , node .replace ("/" , "." ));
200+
201+ if (null != projectConf .getProperty (titleKey )) {
202+ String title = projectConf .getProperty (titleKey ).replace ("%jid%" ,
203+ channelJID .toBareJID ());
204+ conf .put (TITLE , title );
205+ }
206+ String descriptionKey = Configuration .CONFIGURATION_CHANNELS_DEFAULT_DESCRIPTION
207+ .replace ("default" , node .replace ("/" , "." ));
208+ if (null != projectConf .getProperty (descriptionKey )) {
209+ String description = projectConf .getProperty (descriptionKey )
210+ .replace ("%jid%" , channelJID .toBareJID ());
211+ conf .put (DESCRIPTION , description );
212+ }
213+
214+ }
140215}
0 commit comments