Skip to content

Commit

Permalink
Added initial support for new components from draft eventpub specific…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
benfortuna committed Jul 21, 2021
1 parent cf7a29f commit 50f0456
Show file tree
Hide file tree
Showing 14 changed files with 424 additions and 17 deletions.
Expand Up @@ -31,6 +31,7 @@
*/
package net.fortuna.ical4j.model

import net.fortuna.ical4j.model.LocationType
import net.fortuna.ical4j.model.component.*
import net.fortuna.ical4j.model.parameter.*
import net.fortuna.ical4j.model.property.*
Expand Down Expand Up @@ -67,6 +68,9 @@ class ContentBuilder extends FactoryBuilderSupport {
registerFactory('vtimezone', new VTimeZoneFactory())
registerFactory('vtodo', new VToDoFactory())
registerFactory('vvenue', new VVenueFactory())
registerFactory('vlocation', new VLocationFactory())
registerFactory('vresource', new VResourceFactory())
registerFactory('participant', new ParticipantFactory())
registerFactory('xcomponent', new XComponentFactory())
}

Expand Down
@@ -0,0 +1,62 @@
/**
* Copyright (c) 2012, Ben Fortuna
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* o Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* o Neither the name of Ben Fortuna nor the names of any other contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.fortuna.ical4j.model.component

import net.fortuna.ical4j.model.PropertyList

class ParticipantFactory extends AbstractComponentFactory{

Object newInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes) throws InstantiationException, IllegalAccessException {
Participant participant
if (FactoryBuilderSupport.checkValueIsType(value, name, Participant)) {
participant = (Participant) value
}
else {
participant = (Participant) super.newInstance(builder, name, value, attributes)
}
return participant
}

protected Object newInstance(PropertyList properties) {
return new Participant(properties)
}

void setChild(FactoryBuilderSupport build, Object parent, Object child) {
if (child instanceof VLocation) {
parent.locations.add child
} else if (child instanceof VResource) {
parent.resources.add child
} else {
super.setChild(build, parent, child)
}
}
}
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2012, Ben Fortuna
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* o Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* o Neither the name of Ben Fortuna nor the names of any other contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.fortuna.ical4j.model.component

import net.fortuna.ical4j.model.PropertyList

class VLocationFactory extends AbstractComponentFactory{

Object newInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes)
throws InstantiationException, IllegalAccessException {

VLocation location
if (FactoryBuilderSupport.checkValueIsType(value, name, VLocation)) {
location = (VLocation) value
} else {
location = (VLocation) super.newInstance(builder, name, value, attributes)
}
return location
}

protected Object newInstance(PropertyList properties) {
return new VLocation(properties)
}
}

@@ -0,0 +1,53 @@
/**
* Copyright (c) 2012, Ben Fortuna
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* o Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* o Neither the name of Ben Fortuna nor the names of any other contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.fortuna.ical4j.model.component

import net.fortuna.ical4j.model.PropertyList

class VResourceFactory extends AbstractComponentFactory{

Object newInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes)
throws InstantiationException, IllegalAccessException {

VResource resource
if (FactoryBuilderSupport.checkValueIsType(value, name, VResource)) {
resource = (VResource) value
} else {
resource = (VResource) super.newInstance(builder, name, value, attributes)
}
return resource
}

protected Object newInstance(PropertyList properties) {
return new VResource(properties)
}
}
27 changes: 13 additions & 14 deletions src/main/java/net/fortuna/ical4j/model/Component.java
Expand Up @@ -31,6 +31,13 @@
*/
package net.fortuna.ical4j.model;

import net.fortuna.ical4j.model.parameter.Value;
import net.fortuna.ical4j.model.property.*;
import net.fortuna.ical4j.util.Strings;
import net.fortuna.ical4j.validate.ValidationException;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.io.IOException;
import java.io.Serializable;
import java.net.URISyntaxException;
Expand All @@ -39,20 +46,6 @@
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import net.fortuna.ical4j.model.parameter.Value;
import net.fortuna.ical4j.model.property.DateProperty;
import net.fortuna.ical4j.model.property.DtStart;
import net.fortuna.ical4j.model.property.Duration;
import net.fortuna.ical4j.model.property.ExDate;
import net.fortuna.ical4j.model.property.ExRule;
import net.fortuna.ical4j.model.property.RDate;
import net.fortuna.ical4j.model.property.RRule;
import net.fortuna.ical4j.util.Strings;
import net.fortuna.ical4j.validate.ValidationException;

/**
* $Id$ [Apr 5, 2004]
* <p/>
Expand Down Expand Up @@ -120,6 +113,12 @@ public abstract class Component implements Serializable {
*/
public static final String AVAILABLE = "AVAILABLE";

public static final String VLOCATION = "VLOCATION";

public static final String VRESOURCE = "VRESOURCE";

public static final String PARTICIPANT = "PARTICIPANT";

/**
* Prefix for non-standard components.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/fortuna/ical4j/model/ComponentFactory.java
Expand Up @@ -7,9 +7,9 @@ public interface ComponentFactory<T extends Component> {

T createComponent();

T createComponent(PropertyList properties);
T createComponent(PropertyList<Property> properties);

T createComponent(PropertyList properties, ComponentList subComponents);
T createComponent(PropertyList<Property> properties, ComponentList<Component> subComponents);

boolean supports(String name);
}
78 changes: 78 additions & 0 deletions src/main/java/net/fortuna/ical4j/model/component/Participant.java
@@ -0,0 +1,78 @@
package net.fortuna.ical4j.model.component;

import net.fortuna.ical4j.model.*;
import net.fortuna.ical4j.util.Strings;
import net.fortuna.ical4j.validate.ValidationException;

import java.util.stream.Collectors;

public class Participant extends Component {

private final ComponentList<VLocation> locations;

private final ComponentList<VResource> resources;

public Participant() {
this(new PropertyList<>());
}

public Participant(PropertyList<Property> p) {
super(PARTICIPANT, p);
this.locations = new ComponentList<>();
this.resources = new ComponentList<>();
}

public Participant(PropertyList<Property> p, final ComponentList<Component> subComponents) {
super(PARTICIPANT, p);
this.locations = new ComponentList<>(subComponents.stream()
.filter(c -> c.getName().equals(VLOCATION)).map(c -> (VLocation) c)
.collect(Collectors.toList()));
this.resources = new ComponentList<>(subComponents.stream()
.filter(c -> c.getName().equals(VRESOURCE)).map(c -> (VResource) c)
.collect(Collectors.toList()));
}

public ComponentList<VLocation> getLocations() {
return locations;
}

public ComponentList<VResource> getResources() {
return resources;
}

@Override
public void validate(boolean recurse) throws ValidationException {

}

@Override
public final String toString() {
return BEGIN + ':' + getName() + Strings.LINE_SEPARATOR +
getProperties() +
getLocations() +
getResources() +
END + ':' + getName() + Strings.LINE_SEPARATOR;
}

public static class Factory extends Content.Factory implements ComponentFactory<Participant> {

public Factory() {
super(PARTICIPANT);
}

@Override
public Participant createComponent() {
return new Participant();
}

@Override
public Participant createComponent(PropertyList<Property> properties) {
return new Participant(properties);
}

@Override
public Participant createComponent(PropertyList<Property> properties, ComponentList<Component> subComponents) {
return new Participant(properties, subComponents);
}
}
}
42 changes: 42 additions & 0 deletions src/main/java/net/fortuna/ical4j/model/component/VLocation.java
@@ -0,0 +1,42 @@
package net.fortuna.ical4j.model.component;

import net.fortuna.ical4j.model.*;
import net.fortuna.ical4j.validate.ValidationException;

public class VLocation extends Component {

public VLocation() {
super(VLOCATION);
}

public VLocation(PropertyList<Property> p) {
super(VLOCATION, p);
}

@Override
public void validate(boolean recurse) throws ValidationException {

}

public static class Factory extends Content.Factory implements ComponentFactory<VLocation> {

public Factory() {
super(VLOCATION);
}

@Override
public VLocation createComponent() {
return new VLocation();
}

@Override
public VLocation createComponent(PropertyList<Property> properties) {
return new VLocation(properties);
}

@Override
public VLocation createComponent(PropertyList<Property> properties, ComponentList<Component> subComponents) {
throw new UnsupportedOperationException(String.format("%s does not support sub-components", VLOCATION));
}
}
}

0 comments on commit 50f0456

Please sign in to comment.