Skip to content

Commit

Permalink
Added calext draft parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Sep 11, 2015
1 parent ab3c8d1 commit 955e63e
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 1 deletion.
97 changes: 97 additions & 0 deletions 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;

/**
* <pre>
* 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
* </pre>
*/
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);
}
}
}
Expand Up @@ -12,7 +12,7 @@
* From specification:
*
* <pre>
* Parameter Name: EMAIL
* Parameter Name: EMAIL
*
* Purpose: To specify an email address that is used to identify or
* contact an organizer or attendee.
Expand Down
89 changes: 89 additions & 0 deletions 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;

/**
* <pre>
* 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
* </pre>
*/
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);
}
}
}
65 changes: 65 additions & 0 deletions 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;

/**
* <pre>
* 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
* </pre>
*/
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);
}
}
}
@@ -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
@@ -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'
}
}
@@ -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'
}
}
@@ -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'
}
}

0 comments on commit 955e63e

Please sign in to comment.