Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added extendable support to comply with RFC 5545 for broken calendars.
- Loading branch information
1 parent
155e8be
commit 68844ba
Showing
29 changed files
with
4,921 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/net/fortuna/ical4j/model/Rfc5545ComponentRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package net.fortuna.ical4j.model; | ||
|
||
/** | ||
* Incarnation of RFC5545 rule that applies to <code>Component</code> elements. | ||
* | ||
* @author daniel grigore | ||
* | ||
* @param <T> | ||
* subtype of {@link Component} class | ||
*/ | ||
public interface Rfc5545ComponentRule<T extends Component> extends Rfc5545Rule<T> { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/net/fortuna/ical4j/model/Rfc5545PropertyRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package net.fortuna.ical4j.model; | ||
|
||
/** | ||
* Incarnation of RFC5545 rule that applies to <code>Property</code> elements. | ||
* | ||
* @author daniel grigore | ||
* | ||
* @param <T> | ||
* subtype of {@link Property} class | ||
*/ | ||
public interface Rfc5545PropertyRule<T extends Property> extends Rfc5545Rule<T> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.fortuna.ical4j.model; | ||
|
||
/** | ||
* Incarnation of a RFC5545 rule. | ||
* | ||
* @author daniel grigore | ||
* @author corneliu dobrota | ||
* | ||
* @param <T> | ||
* type of the element this rule can be applied to | ||
*/ | ||
public interface Rfc5545Rule<T> { | ||
|
||
/** | ||
* Applies this rule to the specified element. | ||
* | ||
* @param element | ||
*/ | ||
void applyTo(T element); | ||
|
||
/** | ||
* Gets the class of the elements this rule can be applied to. | ||
* | ||
* @return the class of the elements this rule can be applied to | ||
*/ | ||
Class<T> getSupportedType(); | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/net/fortuna/ical4j/model/rfc5545/AttendeePropertyRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package net.fortuna.ical4j.model.rfc5545; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import net.fortuna.ical4j.model.Rfc5545PropertyRule; | ||
import net.fortuna.ical4j.model.property.Attendee; | ||
|
||
public class AttendeePropertyRule implements Rfc5545PropertyRule<Attendee> { | ||
|
||
private static final String MAILTO = "mailto"; | ||
private static final String APOSTROPHE = "'"; | ||
private static final int MIN_LENGTH = 3; | ||
|
||
@Override | ||
public void applyTo(Attendee element) { | ||
if (element == null) { | ||
return; | ||
} | ||
URI calAddress = element.getCalAddress(); | ||
if (calAddress == null) { | ||
return; | ||
} | ||
String scheme = calAddress.getScheme(); | ||
if (scheme != null && StringUtils.startsWithIgnoreCase(scheme, MAILTO)) { | ||
String part = calAddress.getSchemeSpecificPart(); | ||
if (part != null && part.length() >= MIN_LENGTH && StringUtils.startsWith(part, APOSTROPHE) | ||
&& StringUtils.endsWith(part, APOSTROPHE)) { | ||
String newPart = part.substring(1, part.length() - 1); | ||
safelySetNewValue(element, newPart); | ||
} | ||
} | ||
} | ||
|
||
private static void safelySetNewValue(Attendee element, String newPart) { | ||
try { | ||
element.setValue(MAILTO + ":" + newPart); | ||
} catch (URISyntaxException e) { | ||
|
||
} | ||
} | ||
|
||
@Override | ||
public Class<Attendee> getSupportedType() { | ||
return Attendee.class; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/net/fortuna/ical4j/model/rfc5545/DTStampRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package net.fortuna.ical4j.model.rfc5545; | ||
|
||
import net.fortuna.ical4j.model.Rfc5545PropertyRule; | ||
import net.fortuna.ical4j.model.property.DtStamp; | ||
|
||
/** | ||
* | ||
* @author daniel grigore | ||
* | ||
*/ | ||
public class DTStampRule implements Rfc5545PropertyRule<DtStamp> { | ||
|
||
@Override | ||
public void applyTo(DtStamp element) { | ||
if (element.getValue() != null && !element.isUtc()) { | ||
element.setUtc(true); | ||
} | ||
} | ||
|
||
@Override | ||
public Class<DtStamp> getSupportedType() { | ||
return DtStamp.class; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/net/fortuna/ical4j/model/rfc5545/DateListPropertyRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package net.fortuna.ical4j.model.rfc5545; | ||
|
||
import net.fortuna.ical4j.model.Rfc5545PropertyRule; | ||
import net.fortuna.ical4j.model.property.DateListProperty; | ||
|
||
/** | ||
* | ||
* @author corneliu dobrota | ||
* @author daniel grigore | ||
* | ||
*/ | ||
public class DateListPropertyRule implements Rfc5545PropertyRule<DateListProperty> { | ||
|
||
@Override | ||
public void applyTo(DateListProperty element) { | ||
TzHelper.correctTzParameterFrom(element); | ||
} | ||
|
||
@Override | ||
public Class<DateListProperty> getSupportedType() { | ||
return DateListProperty.class; | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/net/fortuna/ical4j/model/rfc5545/DatePropertyRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.fortuna.ical4j.model.rfc5545; | ||
|
||
import net.fortuna.ical4j.model.Parameter; | ||
import net.fortuna.ical4j.model.Rfc5545PropertyRule; | ||
import net.fortuna.ical4j.model.property.DateProperty; | ||
|
||
/** | ||
* | ||
* @author daniel grigore | ||
* @author corneliu dobrota | ||
*/ | ||
public class DatePropertyRule implements Rfc5545PropertyRule<DateProperty> { | ||
|
||
@Override | ||
public void applyTo(DateProperty element) { | ||
TzHelper.correctTzParameterFrom(element); | ||
if (!element.isUtc() || element.getParameter(Parameter.TZID) == null) { | ||
return; | ||
} | ||
element.getParameters().removeAll(Parameter.TZID); | ||
element.setUtc(true); | ||
} | ||
|
||
@Override | ||
public Class<DateProperty> getSupportedType() { | ||
return DateProperty.class; | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
src/main/java/net/fortuna/ical4j/model/rfc5545/RuleManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Rfc5545RuleManager.java Feb 21, 2014 | ||
* | ||
* Copyright (c) 2014 1&1 Internet AG. All rights reserved. | ||
* | ||
* $Id$ | ||
*/ | ||
package net.fortuna.ical4j.model.rfc5545; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
import net.fortuna.ical4j.model.Component; | ||
import net.fortuna.ical4j.model.Property; | ||
import net.fortuna.ical4j.model.Rfc5545ComponentRule; | ||
import net.fortuna.ical4j.model.Rfc5545PropertyRule; | ||
import net.fortuna.ical4j.model.Rfc5545Rule; | ||
|
||
/** | ||
* Manages the rules that can be applied to ICS elements. New rules can be simply added by creating new implementations | ||
* of {@link Rfc5545PropertyRule} or {@link Rfc5545ComponentRule}. | ||
* | ||
* @author corneliu dobrota | ||
* @author daniel grigore | ||
* @see Property | ||
* @see Component | ||
* | ||
*/ | ||
public class RuleManager { | ||
|
||
private static final Set<Rfc5545PropertyRule<? extends Property>> PROPERTY_RULES = new LinkedHashSet<Rfc5545PropertyRule<? extends Property>>(); | ||
private static final Set<Rfc5545ComponentRule<? extends Component>> COMPONENT_RULES = new LinkedHashSet<Rfc5545ComponentRule<? extends Component>>(); | ||
|
||
static { | ||
register(new VAlarmRule()); | ||
|
||
register(new DatePropertyRule()); | ||
|
||
register(new DateListPropertyRule()); | ||
|
||
register(new VEventRule()); | ||
|
||
register(new TzIdRule()); | ||
|
||
register(new DTStampRule()); | ||
|
||
register(new AttendeePropertyRule()); | ||
} | ||
|
||
private static void register(Rfc5545PropertyRule<? extends Property> rule) { | ||
if (rule.getSupportedType() == null) { | ||
throw new NullPointerException(); | ||
} | ||
PROPERTY_RULES.add(rule); | ||
} | ||
|
||
private static void register(Rfc5545ComponentRule<? extends Component> rule) { | ||
if (rule.getSupportedType() == null) { | ||
throw new NullPointerException(); | ||
} | ||
COMPONENT_RULES.add(rule); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static Set<Rfc5545PropertyRule<Property>> getSupportedRulesFor(Property element) { | ||
if (element == null) { | ||
throw new NullPointerException(); | ||
} | ||
Set<Rfc5545PropertyRule<Property>> rules = new LinkedHashSet<Rfc5545PropertyRule<Property>>(1); | ||
for (Rfc5545Rule<? extends Property> rule : PROPERTY_RULES) { | ||
if (rule.getSupportedType().isInstance(element)) { | ||
rules.add((Rfc5545PropertyRule<Property>) rule); | ||
} | ||
} | ||
return rules; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static Set<Rfc5545ComponentRule<Component>> getSupportedRulesFor(Component element) { | ||
if (element == null) { | ||
throw new NullPointerException(); | ||
} | ||
Set<Rfc5545ComponentRule<Component>> rules = new LinkedHashSet<Rfc5545ComponentRule<Component>>(1); | ||
for (Rfc5545Rule<?> rule : COMPONENT_RULES) { | ||
if (rule.getSupportedType().isInstance(element)) { | ||
rules.add((Rfc5545ComponentRule<Component>) rule); | ||
} | ||
} | ||
return rules; | ||
} | ||
} |
Oops, something went wrong.