11package org .buddycloud .channelserver .channel ;
22
3- import java .text .SimpleDateFormat ;
43import java .util .Date ;
54import java .util .HashMap ;
6- import java .util .TimeZone ;
7- import org .buddycloud .channelserver .pubsub .affiliation .Affiliations ;
8- import org .buddycloud .channelserver .pubsub .publishmodel .PublishModels ;
5+
96import org .buddycloud .channelserver .pubsub .accessmodel .AccessModels ;
7+ import org .buddycloud .channelserver .pubsub .affiliation .Affiliations ;
8+ import org .joda .time .format .DateTimeFormatter ;
9+ import org .joda .time .format .ISODateTimeFormat ;
1010import org .xmpp .packet .JID ;
1111
1212//TODO! Refactor this!
@@ -27,28 +27,57 @@ public class Conf {
2727
2828 private static final String PUBLISHERS = "publishers" ;
2929
30- public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.S'Z'" ;
31-
32-
30+ public static final DateTimeFormatter ISO_8601_PARSER = ISODateTimeFormat . dateTimeParser () ;
31+ public static final DateTimeFormatter ISO_8601_FORMATTER = ISODateTimeFormat . dateTime ();
32+
3333 // Most of these are copied from here
3434 // https://github.com/buddycloud/buddycloud-server/blob/master/src/local/operations.coffee#L14
3535
3636 public static String getPostChannelNodename (JID channelJID ) {
3737 return "/user/" + channelJID .toBareJID () + "/posts" ;
3838 }
39+
40+ /**
41+ * Parses a ISO 8601 to a string
42+ *
43+ * @param iso8601Str
44+ * @return
45+ * @throws IllegalArgumentException if the provided string is not ISO 8601
46+ */
47+ public static Date parseDate (String iso8601Str ) throws IllegalArgumentException {
48+ return ISO_8601_PARSER .parseDateTime (iso8601Str ).toDate ();
49+ }
50+
51+ public static String formatDate (Date date ) {
52+ return ISO_8601_FORMATTER .print (date .getTime ());
53+ }
3954
40- public static HashMap <String , String > getDefaultPostChannelConf (JID channelJID ) {
41- SimpleDateFormat sdf = new SimpleDateFormat (DATE_FORMAT );
42- sdf .setTimeZone (TimeZone .getTimeZone ("UTC" ));
55+ public static HashMap <String , String > getDefaultChannelConf (JID channelJID , JID ownerJID ) {
56+ HashMap <String , String > conf = new HashMap <String , String >();
57+
58+ conf .put (TYPE , "http://www.w3.org/2005/Atom" );
59+ conf .put (TITLE , channelJID .toBareJID () + "'s title" );
60+ conf .put (DESCRIPTION , channelJID .toBareJID () + "'s description" );
61+ conf .put (PUBLISH_MODEL , PUBLISHERS );
62+ conf .put (ACCESS_MODEL , AccessModels .open .toString ());
63+ conf .put (CREATION_DATE , formatDate (new Date ()));
64+ conf .put (OWNER , ownerJID .toBareJID ());
65+ conf .put (DEFAULT_AFFILIATION , Affiliations .member .toString ());
66+ conf .put (NUM_SUBSCRIBERS , "1" );
67+ conf .put (NOTIFY_CONFIG , "1" );
4368
69+ return conf ;
70+ }
71+
72+ public static HashMap <String , String > getDefaultPostChannelConf (JID channelJID ) {
4473 HashMap <String , String > conf = new HashMap <String , String >();
4574
4675 conf .put (TYPE , "http://www.w3.org/2005/Atom" );
4776 conf .put (TITLE , channelJID .toBareJID () + "'s very own buddycloud channel!" );
4877 conf .put (DESCRIPTION , "This channel belongs to " + channelJID .toBareJID () + ". To nobody else!" );
4978 conf .put (PUBLISH_MODEL , PUBLISHERS );
5079 conf .put (ACCESS_MODEL , AccessModels .open .toString ());
51- conf .put (CREATION_DATE , sdf . format (new Date ()));
80+ conf .put (CREATION_DATE , formatDate (new Date ()));
5281 conf .put (OWNER , channelJID .toBareJID ());
5382 conf .put (DEFAULT_AFFILIATION , Affiliations .member .toString ());
5483 conf .put (NUM_SUBSCRIBERS , "1" );
@@ -63,17 +92,14 @@ public static String getStatusChannelNodename(JID channelJID) {
6392 }
6493
6594 public static HashMap <String , String > getDefaultStatusChannelConf (JID channelJID ) {
66- SimpleDateFormat sdf = new SimpleDateFormat (DATE_FORMAT );
67- sdf .setTimeZone (TimeZone .getTimeZone ("UTC" ));
68-
6995 HashMap <String , String > conf = new HashMap <String , String >();
7096
7197 conf .put (TYPE , "http://www.w3.org/2005/Atom" );
7298 conf .put (TITLE , channelJID .toBareJID () + "'s very own buddycloud status!" );
7399 conf .put (DESCRIPTION , "This is " + channelJID .toBareJID () + "'s mood a.k.a status -channel. Depends how geek you are." );
74100 conf .put (PUBLISH_MODEL , PUBLISHERS );
75101 conf .put (ACCESS_MODEL , AccessModels .open .toString ());
76- conf .put (CREATION_DATE , sdf . format (new Date ()));
102+ conf .put (CREATION_DATE , formatDate (new Date ()));
77103 conf .put (OWNER , channelJID .toBareJID ());
78104 conf .put (DEFAULT_AFFILIATION , Affiliations .member .toString ());
79105 conf .put (NUM_SUBSCRIBERS , "1" );
@@ -87,17 +113,14 @@ public static String getGeoPreviousChannelNodename(JID channelJID) {
87113 }
88114
89115 public static HashMap <String , String > getDefaultGeoPreviousChannelConf (JID channelJID ) {
90- SimpleDateFormat sdf = new SimpleDateFormat (DATE_FORMAT );
91- sdf .setTimeZone (TimeZone .getTimeZone ("UTC" ));
92-
93116 HashMap <String , String > conf = new HashMap <String , String >();
94117
95118 conf .put (TYPE , "http://www.w3.org/2005/Atom" );
96119 conf .put (TITLE , channelJID .toBareJID () + "'s previous location." );
97120 conf .put (DESCRIPTION , "Where " + channelJID .toBareJID () + " has been before." );
98121 conf .put (PUBLISH_MODEL , PUBLISHERS );
99122 conf .put (ACCESS_MODEL , AccessModels .open .toString ());
100- conf .put (CREATION_DATE , sdf . format (new Date ()));
123+ conf .put (CREATION_DATE , formatDate (new Date ()));
101124 conf .put (OWNER , channelJID .toBareJID ());
102125 conf .put (DEFAULT_AFFILIATION , Affiliations .member .toString ());
103126 conf .put (NUM_SUBSCRIBERS , "1" );
@@ -111,17 +134,14 @@ public static String getGeoCurrentChannelNodename(JID channelJID) {
111134 }
112135
113136 public static HashMap <String , String > getDefaultGeoCurrentChannelConf (JID channelJID ) {
114- SimpleDateFormat sdf = new SimpleDateFormat (DATE_FORMAT );
115- sdf .setTimeZone (TimeZone .getTimeZone ("UTC" ));
116-
117137 HashMap <String , String > conf = new HashMap <String , String >();
118138
119139 conf .put (TYPE , "http://www.w3.org/2005/Atom" );
120140 conf .put (TITLE , channelJID .toBareJID () + "'s current location." );
121141 conf .put (DESCRIPTION , "Where " + channelJID .toBareJID () + " is now." );
122142 conf .put (PUBLISH_MODEL , PUBLISHERS );
123143 conf .put (ACCESS_MODEL , AccessModels .open .toString ());
124- conf .put (CREATION_DATE , sdf . format (new Date ()));
144+ conf .put (CREATION_DATE , formatDate (new Date ()));
125145 conf .put (OWNER , channelJID .toBareJID ());
126146 conf .put (DEFAULT_AFFILIATION , Affiliations .member .toString ());
127147 conf .put (NUM_SUBSCRIBERS , "1" );
@@ -135,17 +155,14 @@ public static String getGeoNextChannelNodename(JID channelJID) {
135155 }
136156
137157 public static HashMap <String , String > getDefaultGeoNextChannelConf (JID channelJID ) {
138- SimpleDateFormat sdf = new SimpleDateFormat (DATE_FORMAT );
139- sdf .setTimeZone (TimeZone .getTimeZone ("UTC" ));
140-
141158 HashMap <String , String > conf = new HashMap <String , String >();
142159
143160 conf .put (TYPE , "http://www.w3.org/2005/Atom" );
144161 conf .put (TITLE , channelJID .toBareJID () + "'s next location." );
145162 conf .put (DESCRIPTION , "Where " + channelJID .toBareJID () + " is going to go." );
146163 conf .put (PUBLISH_MODEL , PUBLISHERS );
147164 conf .put (ACCESS_MODEL , AccessModels .open .toString ());
148- conf .put (CREATION_DATE , sdf . format (new Date ()));
165+ conf .put (CREATION_DATE , formatDate (new Date ()));
149166 conf .put (OWNER , channelJID .toBareJID ());
150167 conf .put (DEFAULT_AFFILIATION , Affiliations .member .toString ());
151168 conf .put (NUM_SUBSCRIBERS , "1" );
@@ -159,17 +176,14 @@ public static String getSubscriptionsChannelNodename(JID channelJID) {
159176 }
160177
161178 public static HashMap <String , String > getDefaultSubscriptionsChannelConf (JID channelJID ) {
162- SimpleDateFormat sdf = new SimpleDateFormat (DATE_FORMAT );
163- sdf .setTimeZone (TimeZone .getTimeZone ("UTC" ));
164-
165179 HashMap <String , String > conf = new HashMap <String , String >();
166180
167181 conf .put (TYPE , "http://www.w3.org/2005/Atom" );
168182 conf .put (TITLE , channelJID .toBareJID () + "'s susbcriptions." );
169183 conf .put (DESCRIPTION , channelJID .toBareJID () + "'s subscriptions. " );
170184 conf .put (PUBLISH_MODEL , PUBLISHERS );
171185 conf .put (ACCESS_MODEL , AccessModels .open .toString ());
172- conf .put (CREATION_DATE , sdf . format (new Date ()));
186+ conf .put (CREATION_DATE , formatDate (new Date ()));
173187 conf .put (OWNER , channelJID .toBareJID ());
174188 conf .put (DEFAULT_AFFILIATION , Affiliations .member .toString ());
175189 conf .put (NUM_SUBSCRIBERS , "1" );
0 commit comments