diff --git a/src/main/java/net/fortuna/ical4j/extensions/parameter/Display.java b/src/main/java/net/fortuna/ical4j/extensions/parameter/Display.java new file mode 100644 index 0000000..ecd8fc1 --- /dev/null +++ b/src/main/java/net/fortuna/ical4j/extensions/parameter/Display.java @@ -0,0 +1,97 @@ +package net.fortuna.ical4j.extensions.parameter; + +import net.fortuna.ical4j.model.Content; +import net.fortuna.ical4j.model.Parameter; +import net.fortuna.ical4j.model.ParameterFactory; +import net.fortuna.ical4j.model.ParameterFactoryImpl; +import org.apache.commons.lang3.StringUtils; + +/** + *
+ * Parameter Name:  DISPLAY
+ *
+ * Purpose:  To specify different ways in which an image for a calendar
+ * or component can be displayed.
+ *
+ * Format Definition:  This property parameter is defined by the
+ * following notation:
+ *
+ * displayparam = "DISPLAY" "=" displayval *("," displayval)
+ *
+ * displayval =   ("BADGE" /    ; image inline with the title of the
+ *                              ; event
+ *                 "GRAPHIC" /  ; a full image replacement for the event
+ *                              ; itself
+ *                 "FULLSIZE /  ; an image that is used to enhance the
+ *                              ; event
+ *                 "THUMBNAIL / ; a smaller variant of "FULLSIZE" to be
+ *                              ; used when space for the image is
+ *                              ; constrained
+ *                 x-name /     ; Experimental type
+ *                 iana-token)  ; Other IANA registered type
+ *                              ;
+ *                              ; Default is BADGE
+ *
+ * Description:  This property parameter MAY be specified on "IMAGE"
+ * properties.  In the absence of this parameter, the value "BADGE"
+ * MUST be used for the default behavior.  The value determines how a
+ * client ought to present an image supplied in iCalendar data to the
+ * user.
+ *
+ * Values for this parameter are registered with IANA as per
+ * Section 8.3.  New values can be added to this registry following
+ * the procedure outlined in Section 8.2.1 of [RFC5545].
+ *
+ * Servers and clients MUST handle x-name and iana-token values they
+ * don't recognize by not displaying any image at all.
+ *
+ * Example:
+ *
+ * IMAGE;VALUE=URI;DISPLAY=BADGE,THUMBNAIL,;FMTTYPE=image/png:http://exa
+ * mple.com/images/weather-cloudy.png
+ * 
+ */ +public class Display extends Parameter { + + private static final long serialVersionUID = 1L; + + private static final String PARAMETER_NAME = "DISPLAY"; + + public enum Value { + BADGE, GRAPHIC, FULLSIZE, THUMBNAIL; + } + + private final String[] values; + + public Display(String value) { + super(PARAMETER_NAME, ParameterFactoryImpl.getInstance()); + String[] valueStrings = value.split(","); + for (String valueString : valueStrings) { + try { + Value.valueOf(valueString); + } catch (IllegalArgumentException iae) { + if (!valueString.startsWith(Parameter.EXPERIMENTAL_PREFIX)) { + throw iae; + } + } + } + this.values = valueStrings; + } + + @Override + public String getValue() { + return StringUtils.join(values, ","); + } + + public static class Factory extends Content.Factory implements ParameterFactory { + private static final long serialVersionUID = 1L; + + public Factory() { + super(PARAMETER_NAME); + } + + public Parameter createParameter(final String value) { + return new Display(value); + } + } +} diff --git a/src/main/java/net/fortuna/ical4j/extensions/parameter/Email.java b/src/main/java/net/fortuna/ical4j/extensions/parameter/Email.java index d8c52ed..8891ce7 100644 --- a/src/main/java/net/fortuna/ical4j/extensions/parameter/Email.java +++ b/src/main/java/net/fortuna/ical4j/extensions/parameter/Email.java @@ -12,7 +12,7 @@ * From specification: * *
- *     Parameter Name:  EMAIL
+ *  Parameter Name:  EMAIL
  *
  *  Purpose:  To specify an email address that is used to identify or
  *  contact an organizer or attendee.
diff --git a/src/main/java/net/fortuna/ical4j/extensions/parameter/Feature.java b/src/main/java/net/fortuna/ical4j/extensions/parameter/Feature.java
new file mode 100644
index 0000000..30f7d36
--- /dev/null
+++ b/src/main/java/net/fortuna/ical4j/extensions/parameter/Feature.java
@@ -0,0 +1,89 @@
+package net.fortuna.ical4j.extensions.parameter;
+
+import net.fortuna.ical4j.model.Content;
+import net.fortuna.ical4j.model.Parameter;
+import net.fortuna.ical4j.model.ParameterFactory;
+import net.fortuna.ical4j.model.ParameterFactoryImpl;
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * 
+ * Parameter Name:  FEATURE
+ *
+ *  Purpose:  To specify a feature or features of a conference or
+ *  broadcast system.
+ *
+ *  Format Definition:  This property parameter is defined by the
+ *  following notation:
+ *
+ *  featureparam = "FEATURE" "=" featuretext *("," featuretext)
+ *  featuretext  =  ("AUDIO" /     ; Audio capability
+ *  "CHAT" /      ; Chat or instant messaging
+ *  "FEED" /      ; Blog or Atom feed
+ *  "MODERATOR" / ; Moderator dial-in code
+ *  "PHONE" /     ; Phone conference
+ *  "SCREEN" /    ; Screen sharing
+ *  "VIDEO" /     ; Video capability
+ *  x-name /      ; Experimental type
+ *  iana-token)   ; Other IANA registered type
+ *
+ *  Description:  This property parameter MAY be specified on the
+ *  "CONFERENCE" property.  Multiple values can be specified.  The
+ *  "MODERATOR" value is used to indicate that the property value is
+ *  specific to the owner/initiator of the conference and contains a
+ *  URI that "activates" the system (e.g., a "moderator" access code
+ *  for a phone conference system that is different from the "regular"
+ *  access code).
+ *
+ *  Example:
+ *
+ *  CONFERENCE;VALUE=URI;FEATURE=AUDIO:rtsp://audio.example.com/
+ *  event
+ *  CONFERENCE;VALUE=URI;FEATURE=AUDIO,VIDEO:http://video-chat.exam
+ *  ple.com/;group-id=1234
+ *  
+ */ +public class Feature extends Parameter { + + private static final long serialVersionUID = 1L; + + private static final String PARAMETER_NAME = "FEATURE"; + + public enum Value { + AUDIO, CHAT, FEED, MODERATOR, PHONE, SCREEN, VIDEO; + } + + private final String[] values; + + public Feature(String value) { + super(PARAMETER_NAME, ParameterFactoryImpl.getInstance()); + String[] valueStrings = value.split(","); + for (String valueString : valueStrings) { + try { + Value.valueOf(valueString); + } catch (IllegalArgumentException iae) { + if (!valueString.startsWith(Parameter.EXPERIMENTAL_PREFIX)) { + throw iae; + } + } + } + this.values = valueStrings; + } + + @Override + public String getValue() { + return StringUtils.join(values, ","); + } + + public static class Factory extends Content.Factory implements ParameterFactory { + private static final long serialVersionUID = 1L; + + public Factory() { + super(PARAMETER_NAME); + } + + public Parameter createParameter(final String value) { + return new Feature(value); + } + } +} diff --git a/src/main/java/net/fortuna/ical4j/extensions/parameter/Label.java b/src/main/java/net/fortuna/ical4j/extensions/parameter/Label.java new file mode 100644 index 0000000..d8e32fc --- /dev/null +++ b/src/main/java/net/fortuna/ical4j/extensions/parameter/Label.java @@ -0,0 +1,65 @@ +package net.fortuna.ical4j.extensions.parameter; + +import net.fortuna.ical4j.model.Content; +import net.fortuna.ical4j.model.Parameter; +import net.fortuna.ical4j.model.ParameterFactory; +import net.fortuna.ical4j.model.ParameterFactoryImpl; + +/** + *
+ * Parameter Name:  LABEL
+ *
+ *  Purpose:  To provide a human readable label.
+ *
+ *  Format Definition:  This property parameter is defined by the
+ *  following notation:
+ *
+ *  infoparam = "LABEL" "=" param-value
+ *
+ *  Description:  This property parameter MAY be specified on the
+ *  "CONFERENCE" property.  It is anticipated that other extensions to
+ *  iCalendar will re-use this property parameter on new properties
+ *  that they define.  As a result, clients SHOULD expect to find this
+ *  property parameter present on many different properties.  It
+ *  provides a human readable label that can be presented to calendar
+ *  users to allow them to discriminate between properties which might
+ *  be similar, or provide additional information for properties that
+ *  are not self-describing.
+ *
+ *  Example:
+ *
+ *  CONFERENCE;VALUE=URI;FEATURE=VIDEO;
+ *  LABEL="Web video chat, access code=76543";
+ *  :http://video-chat.example.com/;group-id=1234
+ *  
+ */ +public class Label extends Parameter { + + private static final long serialVersionUID = 1L; + + private static final String PARAMETER_NAME = "LABEL"; + + private final String value; + + public Label(String value) { + super(PARAMETER_NAME, ParameterFactoryImpl.getInstance()); + this.value = value; + } + + @Override + public String getValue() { + return value; + } + + public static class Factory extends Content.Factory implements ParameterFactory { + private static final long serialVersionUID = 1L; + + public Factory() { + super(PARAMETER_NAME); + } + + public Parameter createParameter(final String value) { + return new Label(value); + } + } +} diff --git a/src/main/resources/META-INF/services/net.fortuna.ical4j.model.ParameterFactory b/src/main/resources/META-INF/services/net.fortuna.ical4j.model.ParameterFactory index 821419c..2b43f94 100644 --- a/src/main/resources/META-INF/services/net.fortuna.ical4j.model.ParameterFactory +++ b/src/main/resources/META-INF/services/net.fortuna.ical4j.model.ParameterFactory @@ -1,2 +1,5 @@ # calext extensions net.fortuna.ical4j.extensions.parameter.Email$Factory +net.fortuna.ical4j.extensions.parameter.Display$Factory +net.fortuna.ical4j.extensions.parameter.Label$Factory +net.fortuna.ical4j.extensions.parameter.Feature$Factory diff --git a/src/test/groovy/net/fortuna/ical4j/extensions/parameter/DisplayTest.groovy b/src/test/groovy/net/fortuna/ical4j/extensions/parameter/DisplayTest.groovy new file mode 100644 index 0000000..92657af --- /dev/null +++ b/src/test/groovy/net/fortuna/ical4j/extensions/parameter/DisplayTest.groovy @@ -0,0 +1,41 @@ +package net.fortuna.ical4j.extensions.parameter + +import net.fortuna.ical4j.data.CalendarBuilder +import net.fortuna.ical4j.model.Calendar +import spock.lang.Specification + +/** + * Created by fortuna on 6/09/15. + */ +class DisplayTest extends Specification { + + def 'assert value stored correctly'() { + given: 'a display value' + String displayValue = 'GRAPHIC,THUMBNAIL' + + when: 'a display object is constructed' + Display display = [displayValue] + + then: 'the object value matches the original address' + display.value == displayValue + } + + def 'assert factory is located correctly'() { + given: 'a sample calendar input' + String calendarString = ''' +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +BEGIN:VTODO +IMAGE;VALUE=URI;DISPLAY=BADGE,THUMBNAIL,;FMTTYPE=image/png:http://exa + mple.com/images/weather-cloudy.png +END:VCALENDAR +''' + + when: 'the input is parsed' + Calendar calendar = new CalendarBuilder().build(new StringReader(calendarString)) + + then: 'a valid calendar is realised' + calendar?.components[0].properties[0].getParameter('DISPLAY').value == 'BADGE,THUMBNAIL' + } +} diff --git a/src/test/groovy/net/fortuna/ical4j/extensions/parameter/FeatureTest.groovy b/src/test/groovy/net/fortuna/ical4j/extensions/parameter/FeatureTest.groovy new file mode 100644 index 0000000..4a539d8 --- /dev/null +++ b/src/test/groovy/net/fortuna/ical4j/extensions/parameter/FeatureTest.groovy @@ -0,0 +1,41 @@ +package net.fortuna.ical4j.extensions.parameter + +import net.fortuna.ical4j.data.CalendarBuilder +import net.fortuna.ical4j.model.Calendar +import spock.lang.Specification + +/** + * Created by fortuna on 6/09/15. + */ +class FeatureTest extends Specification { + + def 'assert value stored correctly'() { + given: 'a feature value' + String featureValue = 'GRAPHIC,THUMBNAIL' + + when: 'a feature object is constructed' + Feature feature = [featureValue] + + then: 'the object value matches the original value' + feature.value == featureValue + } + + def 'assert factory is located correctly'() { + given: 'a sample calendar input' + String calendarString = ''' +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +BEGIN:VTODO +CONFERENCE;VALUE=URI;FEATURE=AUDIO:rtsp://audio.example.com/ + event +END:VCALENDAR +''' + + when: 'the input is parsed' + Calendar calendar = new CalendarBuilder().build(new StringReader(calendarString)) + + then: 'a valid calendar is realised' + calendar?.components[0].properties[0].getParameter('FEATURE').value == 'AUDIO' + } +} diff --git a/src/test/groovy/net/fortuna/ical4j/extensions/parameter/LabelTest.groovy b/src/test/groovy/net/fortuna/ical4j/extensions/parameter/LabelTest.groovy new file mode 100644 index 0000000..a16f62f --- /dev/null +++ b/src/test/groovy/net/fortuna/ical4j/extensions/parameter/LabelTest.groovy @@ -0,0 +1,42 @@ +package net.fortuna.ical4j.extensions.parameter + +import net.fortuna.ical4j.data.CalendarBuilder +import net.fortuna.ical4j.model.Calendar +import spock.lang.Specification + +/** + * Created by fortuna on 6/09/15. + */ +class LabelTest extends Specification { + + def 'assert value stored correctly'() { + given: 'a label value' + String labelValue = 'Chat room:xmpp:chat-123@conference.example.com' + + when: 'a label object is constructed' + Label label = [labelValue] + + then: 'the object value matches the original address' + label.value == labelValue + } + + def 'assert factory is located correctly'() { + given: 'a sample calendar input' + String calendarString = ''' +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +BEGIN:VTODO +CONFERENCE;VALUE=URI;FEATURE=VIDEO; + LABEL="Web video chat, access code=76543"; + :http://video-chat.example.com/;group-id=1234END:VTODO +END:VCALENDAR +''' + + when: 'the input is parsed' + Calendar calendar = new CalendarBuilder().build(new StringReader(calendarString)) + + then: 'a valid calendar is realised' + calendar?.components[0].properties[0].getParameter('LABEL').value == 'Web video chat, access code=76543' + } +}