diff --git a/webcal/src/main/java/com/onixbyte/icalendar/CalendarUtil.java b/webcal/src/main/java/com/onixbyte/icalendar/CalendarUtil.java index 4802c99..7427203 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/CalendarUtil.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/CalendarUtil.java @@ -17,6 +17,14 @@ package com.onixbyte.icalendar; +import com.onixbyte.icalendar.property.parameter.AlternateRepresentation; +import com.onixbyte.icalendar.property.parameter.Language; + +import java.time.format.DateTimeFormatter; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Supplier; + /** * CalendarUtil * diff --git a/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Method.java b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Method.java index 8f7c422..297e1d4 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Method.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Method.java @@ -17,7 +17,7 @@ package com.onixbyte.icalendar.calendar.property; -public enum Method implements CalendarProperty { +public enum Method implements Property { PUBLISH("PUBLISH"), REQUEST("REQUEST"), diff --git a/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/ProductIdentifier.java b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/ProductIdentifier.java index 999308c..e44e29e 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/ProductIdentifier.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/ProductIdentifier.java @@ -22,7 +22,7 @@ package com.onixbyte.icalendar.calendar.property; * * @author Zihlu WANG */ -public final class ProductIdentifier implements CalendarProperty { +public final class ProductIdentifier implements Property { private final String value; diff --git a/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarProperty.java b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Property.java similarity index 84% rename from webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarProperty.java rename to webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Property.java index 5744014..b5e2196 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarProperty.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Property.java @@ -17,7 +17,7 @@ package com.onixbyte.icalendar.calendar.property; -import com.onixbyte.icalendar.property.CalendarResolvable; +import com.onixbyte.icalendar.property.Resolvable; -public interface CalendarProperty extends CalendarResolvable { +public interface Property extends Resolvable { } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarScale.java b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Scale.java similarity index 92% rename from webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarScale.java rename to webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Scale.java index dc95f73..4fd3b71 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarScale.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Scale.java @@ -18,11 +18,11 @@ package com.onixbyte.icalendar.calendar.property; /** - * CalendarScale + * Scale * * @author Zihlu WANG */ -public enum CalendarScale implements CalendarProperty { +public enum Scale implements Property { GREGORIAN, ; diff --git a/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Version.java b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Version.java index 7c4784a..77fd2e9 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Version.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Version.java @@ -22,7 +22,7 @@ package com.onixbyte.icalendar.calendar.property; * * @author Zihlu WANG */ -public enum Version implements CalendarProperty { +public enum Version implements Property { VERSION_2_0, ; diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/Calendar.java b/webcal/src/main/java/com/onixbyte/icalendar/component/Calendar.java index ba7213a..032f347 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/Calendar.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/Calendar.java @@ -17,7 +17,7 @@ package com.onixbyte.icalendar.component; -import com.onixbyte.icalendar.calendar.property.CalendarScale; +import com.onixbyte.icalendar.calendar.property.Scale; import com.onixbyte.icalendar.calendar.property.Method; import com.onixbyte.icalendar.calendar.property.ProductIdentifier; import com.onixbyte.icalendar.calendar.property.Version; @@ -60,7 +60,7 @@ public final class Calendar { /** * This property are OPTIONAL, but MUST NOT occur more than once. */ - private CalendarScale scale; + private Scale scale; /** * This property are OPTIONAL, but MUST NOT occur more than once. diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Attachment.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Attachment.java index b37f999..4acfda0 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Attachment.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Attachment.java @@ -20,6 +20,7 @@ package com.onixbyte.icalendar.component.property; import com.onixbyte.icalendar.property.parameter.FormatType; import java.net.URI; +import java.util.Objects; import java.util.Optional; /** @@ -27,21 +28,27 @@ import java.util.Optional; * * @author Zihlu WANG */ -public final class Attachment implements ComponentProperty { +public record Attachment(FormatType formatType, + URI uri, + String content) implements ComponentProperty { - private FormatType formatType; - - private URI uri; + private static final String PROPERTY_NAME = "ATTACH"; @Override public String resolve() { - final var attachmentBuilder = new StringBuilder("ATTACH"); + if (Objects.isNull(uri) && (Objects.isNull(content) || content.isBlank())) { + return null; + } + + final var attachmentBuilder = new StringBuilder(PROPERTY_NAME); Optional.ofNullable(formatType) - .ifPresent((fmtType) -> attachmentBuilder.append(fmtType.resolve())); + .ifPresent((fmtType) -> attachmentBuilder.append(";").append(fmtType.resolve())); - attachmentBuilder.append(":") - .append(uri.toString()); + Optional.ofNullable(uri).ifPresentOrElse( + (_uri) -> attachmentBuilder.append(":").append(_uri), + () -> attachmentBuilder.append(";ENCODING=BASE64;VALUE=BINARY:").append(content)); + attachmentBuilder.append("\n"); return attachmentBuilder.toString(); } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/CalendarDuration.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/CalendarDuration.java new file mode 100644 index 0000000..0026b82 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/CalendarDuration.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import java.time.Duration; + +public record CalendarDuration(Duration duration) implements ComponentProperty { + + private static final String PROPERTY_NAME = "DURATION"; + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + duration.toString() + "\n"; + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Categories.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Categories.java index b0ff2d9..1c4aace 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Categories.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Categories.java @@ -17,5 +17,49 @@ package com.onixbyte.icalendar.component.property; -public class Categories { +import java.util.ArrayList; +import java.util.List; + +public final class Categories implements ComponentProperty { + + private static final String PROPERTY_NAME = "CATEGORIES"; + + private final List value; + + private Categories(List value) { + this.value = value; + } + + public static class Builder { + private List categories; + + private Builder() { + categories = new ArrayList<>(); + } + + public Builder addCategory(String category) { + if (!categories.contains(category)) { + categories.add(category); + } + return this; + } + + public Builder addCategories(List categories) { + categories.forEach(this::addCategory); + return this; + } + + public Categories build() { + return new Categories(categories); + } + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + String.join(",", value) + "\n"; + } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Classification.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Classification.java index 2770a93..c7e501e 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Classification.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Classification.java @@ -17,5 +17,17 @@ package com.onixbyte.icalendar.component.property; -public enum Classification { +public enum Classification implements ComponentProperty { + + PUBLIC, + PRIVATE, + CONFIDENTIAL, + ; + + private static final String PROPERTY_NAME = "CLASS"; + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + name() + "\n"; + } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Comment.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Comment.java new file mode 100644 index 0000000..e13bd62 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Comment.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.CalendarUtil; +import com.onixbyte.icalendar.property.parameter.AlternateRepresentation; +import com.onixbyte.icalendar.property.parameter.Language; + +import java.util.Objects; +import java.util.Optional; + +public record Comment(AlternateRepresentation altRep, + Language language, + String value) implements TextProperty, ComponentProperty { + + private static final String PROPERTY_NAME = "COMMENT"; + + @Override + public String resolve() { + return composeResolution(PROPERTY_NAME, altRep, language, value); + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/ComponentProperty.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/ComponentProperty.java index ae2f910..bd83694 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/ComponentProperty.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/ComponentProperty.java @@ -17,7 +17,7 @@ package com.onixbyte.icalendar.component.property; -import com.onixbyte.icalendar.property.CalendarResolvable; +import com.onixbyte.icalendar.property.Resolvable; -public interface ComponentProperty extends CalendarResolvable { +public interface ComponentProperty extends Resolvable { } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCompleted.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCompleted.java new file mode 100644 index 0000000..7fb6bd2 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCompleted.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.CalendarUtil; + +import java.time.LocalDateTime; +import java.time.ZoneId; + +public record DateTimeCompleted(LocalDateTime value) implements DateTimeProperty, ComponentProperty { + + private static final String PROPERTY_NAME = "COMPLETED"; + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + value + .atZone(ZoneId.systemDefault()) + .withZoneSameInstant(ZoneId.of("UTC")) + .format(DateTimeProperty.utcDateTimeFormatter()); + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeDue.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeDue.java new file mode 100644 index 0000000..fb56b8a --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeDue.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.CalendarUtil; +import com.onixbyte.icalendar.property.parameter.ValueDataType; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +public record DateTimeDue(ValueDataType valueDataType, + LocalDateTime localDateTime) implements DateTimeProperty, ComponentProperty { + + private static final String PROPERTY_NAME = "DUE"; + + public DateTimeDue { + if (Objects.nonNull(valueDataType) && !SUPPORTED_VALUES.contains(valueDataType)) { + throw new IllegalArgumentException("ValueDateType only accepts DATE and DATE-TIME"); + } + } + + @Override + public String resolve() { + return DateTimeProperty.composeResolution(PROPERTY_NAME, valueDataType, localDateTime); + } + +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeEnd.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeEnd.java new file mode 100644 index 0000000..f3b991d --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeEnd.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.property.parameter.ValueDataType; + +import java.time.LocalDateTime; +import java.util.Objects; +import java.util.Optional; + +public record DateTimeEnd(ValueDataType valueDataType, + LocalDateTime localDateTime) implements DateTimeProperty, ComponentProperty { + + private static final String PROPERTY_NAME = "DTEND"; + + public DateTimeEnd { + if (Objects.nonNull(valueDataType) && !SUPPORTED_VALUES.contains(valueDataType)) { + throw new IllegalArgumentException("ValueDateType only accepts DATE and DATE-TIME"); + } + } + + @Override + public String resolve() { + return DateTimeProperty.composeResolution(PROPERTY_NAME, valueDataType, localDateTime); + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeProperty.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeProperty.java new file mode 100644 index 0000000..0d019d6 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeProperty.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.CalendarUtil; +import com.onixbyte.icalendar.property.parameter.ValueDataType; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +public interface DateTimeProperty { + + List SUPPORTED_VALUES = List.of( + ValueDataType.DATE, + ValueDataType.DATE_TIME + ); + + DateTimeFormatter utcDateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"); + + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); + + static DateTimeFormatter utcDateTimeFormatter() { + return utcDateTimeFormatter; + } + + static DateTimeFormatter dateFormatter() { + return dateFormatter; + } + + static String composeResolution(String propertyName, + ValueDataType valueDataType, + LocalDateTime localDateTime) { + var dateTimeEndBuilder = new StringBuilder(propertyName); + + Optional.ofNullable(valueDataType) + .filter(SUPPORTED_VALUES::contains) + .ifPresent((value) -> dateTimeEndBuilder.append(";").append(value.resolve())); + + var dateTimeFormatter = switch (Optional.ofNullable(valueDataType) + .filter(SUPPORTED_VALUES::contains) + .orElse(ValueDataType.DATE_TIME)) { + case DATE -> dateFormatter; + case BINARY, UTC_OFFSET, BOOLEAN, CAL_ADDRESS, DURATION, FLOAT, INTEGER, PERIOD, + RECURRENCE_RULE, TEXT, URI, DATE_TIME -> utcDateTimeFormatter; + }; + + dateTimeEndBuilder.append(":").append(localDateTime.format(dateTimeFormatter)).append("\n"); + return dateTimeEndBuilder.toString(); + } + +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStamp.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStamp.java index 21f902f..9dd7ba0 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStamp.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStamp.java @@ -23,65 +23,34 @@ import com.onixbyte.icalendar.config.Formatters; import java.time.LocalDateTime; /** - * In the case of an {@link com.onixbyte.icalendar.component.Calendar iCalendar} object that specifies a "{@link - * Method Method}" property, this property specifies the date and time that - * the instance of the {@link com.onixbyte.icalendar.component.Calendar iCalendar} object was created. In the case of - * an {@link com.onixbyte.icalendar.component.Calendar iCalendar} object that doesn't specify a "{@link - * Method Method}" property, this property specifies the date and time that + * In the case of an {@link com.onixbyte.icalendar.component.Calendar iCalendar} object that + * specifies a "{@link Method Method}" property, this property specifies the date and time that the + * instance of the {@link com.onixbyte.icalendar.component.Calendar iCalendar} object was created. + * In the case of an {@link com.onixbyte.icalendar.component.Calendar iCalendar} object that doesn't + * specify a "{@link Method Method}" property, this property specifies the date and time that * the information associated with the calendar component was last revised in the calendar store. *

* The value MUST be specified in the UTC time format. *

- * This property is also useful to protocols such as [2447bis] that have inherent latency issues with the delivery of - * content. This property will assist in the proper sequencing of messages containing {@link - * com.onixbyte.icalendar.component.Calendar iCalendar} objects. + * This property is also useful to protocols such as [2447bis] that have inherent latency issues + * with the delivery of content. This property will assist in the proper sequencing of messages + * containing {@link com.onixbyte.icalendar.component.Calendar iCalendar} objects. *

- * In the case of an {@link com.onixbyte.icalendar.component.Calendar iCalendar} object that specifies a "{@link - * Method Method}" property, this property differs from the "{@link - * DateTimeCreated CREATED}" and "{@link LastModified LAST-MODIFIED}" properties. These two properties are used to - * specify when the particular calendar data in the calendar store was created and last modified. This is different - * from when the {@link com.onixbyte.icalendar.component.Calendar iCalendar} object representation of the calendar + * In the case of an {@link com.onixbyte.icalendar.component.Calendar iCalendar} object that + * specifies a "{@link Method Method}" property, this property differs from the + * "{@link DateTimeCreated CREATED}" and "{@link LastModified LAST-MODIFIED}" properties. These two + * properties are used to specify when the particular calendar data in the calendar store was + * created and last modified. This is different from when the {@link + * com.onixbyte.icalendar.component.Calendar iCalendar} object representation of the calendar * service information was created or last modified. *

- * In the case of an {@link com.onixbyte.icalendar.component.Calendar iCalendar} object that specifies a "{@link - * Method METHOD}" property, this property is equivalent to the "{@link + * In the case of an {@link com.onixbyte.icalendar.component.Calendar iCalendar} object that + * specifies a "{@link Method METHOD}" property, this property is equivalent to the "{@link * LastModified LAST-MODIFIED}" property. * * @author Zihlu WANG */ -public final class DateTimeStamp implements ComponentProperty { - - private static final String PROPERTY_NAME = "DTSTAMP"; - - private LocalDateTime value; - - public DateTimeStamp(LocalDateTime value) { - this.value = value; - } - - public DateTimeStamp() { - this.value = LocalDateTime.now(); - } - - @Override - public String resolve() { - return PROPERTY_NAME + ":" + Formatters.getUtcDatetimeFormatter().format(value) + '\n'; - } - - public static class Builder { - private final DateTimeStamp dateTimeStamp = new DateTimeStamp(); - - public Builder dateTimeStamp(LocalDateTime dateTime) { - this.dateTimeStamp.value = dateTime; - return this; - } - - public DateTimeStamp build() { - return dateTimeStamp; - } - } - - public static Builder builder() { - return new Builder(); - } -} +// public final class DateTimeStamp implements DateTimeProperty, ComponentProperty { +// +// +// } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStart.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStart.java new file mode 100644 index 0000000..0807bbd --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStart.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.property.parameter.ValueDataType; + +import java.time.LocalDateTime; +import java.util.Objects; + +public record DateTimeStart(ValueDataType valueDataType, + LocalDateTime localDateTime) implements DateTimeProperty, ComponentProperty { + + private static final String PROPERTY_NAME = "DTSTART"; + + public DateTimeStart { + if (Objects.nonNull(valueDataType) && !SUPPORTED_VALUES.contains(valueDataType)) { + throw new IllegalArgumentException("ValueDateType only accepts DATE and DATE-TIME"); + } + } + + @Override + public String resolve() { + return DateTimeProperty.composeResolution(PROPERTY_NAME, valueDataType, localDateTime); + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Description.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Description.java new file mode 100644 index 0000000..317c07b --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Description.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.CalendarUtil; +import com.onixbyte.icalendar.property.parameter.AlternateRepresentation; +import com.onixbyte.icalendar.property.parameter.Language; + +public record Description(AlternateRepresentation altRep, + Language language, + String value) implements TextProperty, ComponentProperty { + + private static final String PROPERTY_NAME = "DESCRIPTION"; + + @Override + public String resolve() { + return composeResolution(PROPERTY_NAME, altRep, language, value); + } + +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/FreeBusyTime.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/FreeBusyTime.java new file mode 100644 index 0000000..027e400 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/FreeBusyTime.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.datatype.Period; +import com.onixbyte.icalendar.property.parameter.FreeBusyTimeType; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public final class FreeBusyTime implements ComponentProperty { + + private static final String PROPERTY_NAME = "FREEBUSY"; + + private final FreeBusyTimeType freeBusyType; + + private final List freeBusyValue; + + public static class Builder { + public Builder freeBusyType(FreeBusyTimeType freeBusyType) { + this.freeBusyType = freeBusyType; + return this; + } + + public Builder addFreeBusyValue(Period period) { + this.freeBusyValue.add(period); + return this; + } + + public FreeBusyTime build() { + return new FreeBusyTime(freeBusyType, freeBusyValue); + } + + private FreeBusyTimeType freeBusyType; + + private List freeBusyValue; + + private Builder() { + this.freeBusyValue = new ArrayList<>(); + } + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public String resolve() { + var freeBusyBuilder = new StringBuilder(PROPERTY_NAME); + + Optional.ofNullable(freeBusyType) + .ifPresent((type) -> freeBusyBuilder.append(";").append(type.resolve())); + + freeBusyBuilder.append(":").append(String.join(",", freeBusyValue + .stream() + .map(Period::resolve) + .toList())); + + return freeBusyBuilder.toString(); + } + + private FreeBusyTime(FreeBusyTimeType freeBusyType, List freeBusyValue) { + this.freeBusyType = freeBusyType; + this.freeBusyValue = freeBusyValue; + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/GeoPosition.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/GeoPosition.java new file mode 100644 index 0000000..0952337 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/GeoPosition.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +public record GeoPosition(double latitude, + double longitude) implements ComponentProperty { + + public GeoPosition { + if (latitude < -90 || latitude > 90) { + throw new IllegalArgumentException( + "Latitude (%f) should greater than -90 and less than 90.".formatted(latitude)); + } + + if (longitude < -180 || longitude > 180) { + throw new IllegalArgumentException( + "Longitude (%f) should greater than -180 and less than 180." + .formatted(longitude)); + } + } + + private static final String PROPERTY_NAME = "GEO"; + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + latitude + ";" + longitude + "\n"; + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Location.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Location.java new file mode 100644 index 0000000..d50f0d4 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Location.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.CalendarUtil; +import com.onixbyte.icalendar.property.parameter.AlternateRepresentation; +import com.onixbyte.icalendar.property.parameter.Language; + +public record Location(AlternateRepresentation altRep, + Language language, + String value) implements TextProperty, ComponentProperty { + + private static final String PROPERTY_NAME = "LOCATION"; + + @Override + public String resolve() { + return composeResolution(PROPERTY_NAME, altRep, language, value); + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/PercentComplete.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/PercentComplete.java new file mode 100644 index 0000000..57748a6 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/PercentComplete.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +public record PercentComplete(int value) implements ComponentProperty { + + public PercentComplete { + if (value < 0 || value > 100) { + throw new IllegalArgumentException("PercentComplete only accept value from 0 to 100, the given value %d is not acceptable." + .formatted(value)); + } + } + + private static final String PROPERTY_NAME = "PERCENT-COMPLETE"; + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + value + "\n"; + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Priority.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Priority.java new file mode 100644 index 0000000..8caeb61 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Priority.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +public record Priority(int value) implements ComponentProperty { + + private static final String PROPERTY_NAME = "PRIORITY"; + + public Priority { + if (value < 0 || value > 9) { + throw new IllegalArgumentException("Priority %d is exceeded the range of 0-9.".formatted(value)); + } + } + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + value + "\n"; + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Resources.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Resources.java new file mode 100644 index 0000000..ddc05a5 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Resources.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.property.parameter.AlternateRepresentation; +import com.onixbyte.icalendar.property.parameter.Language; + +import java.util.ArrayList; +import java.util.List; + +public final class Resources implements TextProperty, ComponentProperty { + + private static final String PROPERTY_NAME = "RESOURCES"; + + private final AlternateRepresentation altRep; + + private final Language language; + + private final List value; + + private Resources(AlternateRepresentation altRep, Language language, List value) { + this.altRep = altRep; + this.language = language; + this.value = value; + } + + public static class Builder { + private List value; + + private AlternateRepresentation altRep; + + private Language language; + + private Builder() { + this.value = new ArrayList<>(); + } + + public Builder altRep(AlternateRepresentation altRep) { + this.altRep = altRep; + return this; + } + + public Builder language(Language language) { + this.language = language; + return this; + } + + public Builder addResource(String resource) { + value.add(resource); + return this; + } + + public Builder addResources(List resources) { + value.addAll(resources); + return this; + } + + public Resources build() { + return new Resources(altRep, language, value); + } + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public String resolve() { + return composeResolution(PROPERTY_NAME, altRep, language, () -> String.join(",", value)); + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Status.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Status.java new file mode 100644 index 0000000..e3379b1 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Status.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import java.util.List; + +public enum Status implements ComponentProperty { + + TENTATIVE("TENTATIVE"), + CONFIRMED("CONFIRMED"), + CANCELLED("CANCELLED"), + NEEDS_ACTION("NEEDS-ACTION"), + COMPLETED("COMPLETED"), + IN_PROGRESS("IN-PROGRESS"), + DRAFT("DRAFT"), + FINAL("FINAL"), + ; + + private static final String PROPERTY_NAME = "STATUS"; + + private final String tag; + + Status(String tag) { + this.tag = tag; + } + + @Override + public String resolve() { + return PROPERTY_NAME + ":" + tag + "\n"; + } + + public static List eventStatus() { + return List.of(TENTATIVE, CONFIRMED, CANCELLED); + } + + public static List todoStatus() { + return List.of(NEEDS_ACTION, COMPLETED, IN_PROGRESS, CANCELLED); + } + + public static List journalStatus() { + return List.of(DRAFT, FINAL, CANCELLED); + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/Summary.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Summary.java new file mode 100644 index 0000000..04e8d71 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Summary.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.property.parameter.AlternateRepresentation; +import com.onixbyte.icalendar.property.parameter.Language; + +public record Summary(AlternateRepresentation altRep, + Language language, + String value) implements TextProperty, ComponentProperty { + + private static final String PROPERTY_NAME = "SUMMARY"; + + @Override + public String resolve() { + return composeResolution(PROPERTY_NAME, altRep, language, value); + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/TextProperty.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/TextProperty.java new file mode 100644 index 0000000..50d12f8 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/TextProperty.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.component.property; + +import com.onixbyte.icalendar.property.parameter.AlternateRepresentation; +import com.onixbyte.icalendar.property.parameter.Language; + +import java.util.Objects; +import java.util.Optional; +import java.util.function.Supplier; + +public interface TextProperty { + + default String composeResolution(String propertyName, + AlternateRepresentation altRep, + Language language, + String value) { + if (Objects.isNull(value) || value.isBlank()) { + return null; + } + + var resolutionBuilder = new StringBuilder(propertyName); + + Optional.ofNullable(altRep) + .ifPresent((_altRep) -> resolutionBuilder.append(";").append(_altRep.resolve())); + + Optional.ofNullable(language) + .ifPresent((lang) -> resolutionBuilder.append(";").append(lang.resolve())); + + resolutionBuilder.append(":") + .append(value) + .append("\n"); + + return resolutionBuilder.toString(); + } + + default String composeResolution(String propertyName, + AlternateRepresentation altRep, + Language language, + Supplier valueSupplier) { + return composeResolution(propertyName, altRep, language, valueSupplier.get()); + } + +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/property/UniqueIdentifier.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/UniqueIdentifier.java index b27ab46..607e6ab 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/property/UniqueIdentifier.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/UniqueIdentifier.java @@ -22,42 +22,7 @@ package com.onixbyte.icalendar.component.property; * * @author Zihlu WANG */ -public final class UniqueIdentifier implements ComponentProperty { - - private String value; - - private UniqueIdentifier() { - } - - private void setValue(String value) { - this.value = value; - } - - public static class Builder { - private final UniqueIdentifier uniqueIdentifier; - - private Builder() { - this.uniqueIdentifier = new UniqueIdentifier(); - } - - public Builder uniqueIdentifier(String uniqueIdentifier) { - this.uniqueIdentifier.value = uniqueIdentifier; - return this; - } - - public Builder uniqueIdentifier(String uniqueIdentifier, String domainName) { - this.uniqueIdentifier.value = uniqueIdentifier + "@" + domainName; - return this; - } - - public UniqueIdentifier build() { - return uniqueIdentifier; - } - } - - public static Builder builder() { - return new Builder(); - } +public record UniqueIdentifier(String value) implements ComponentProperty { @Override public String resolve() { diff --git a/webcal/src/main/java/com/onixbyte/icalendar/datatype/CalendarUserAddress.java b/webcal/src/main/java/com/onixbyte/icalendar/datatype/CalendarUserAddress.java index 3625bab..8204876 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/datatype/CalendarUserAddress.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/datatype/CalendarUserAddress.java @@ -17,9 +17,11 @@ package com.onixbyte.icalendar.datatype; +import com.onixbyte.icalendar.property.Resolvable; + import java.net.URI; -public final class CalendarUserAddress { +public final class CalendarUserAddress implements Resolvable { private URI value; @@ -38,6 +40,11 @@ public final class CalendarUserAddress { this.value = uri; } + @Override + public String resolve() { + return toString(); + } + @Override public String toString() { return value.toString(); diff --git a/webcal/src/main/java/com/onixbyte/icalendar/datatype/Period.java b/webcal/src/main/java/com/onixbyte/icalendar/datatype/Period.java new file mode 100644 index 0000000..218e410 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/datatype/Period.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.datatype; + +import com.onixbyte.icalendar.property.Resolvable; + +public interface Period extends Resolvable { + +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodExplicit.java b/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodExplicit.java new file mode 100644 index 0000000..a1c829e --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodExplicit.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.datatype; + +import com.onixbyte.icalendar.component.property.DateTimeProperty; +import com.onixbyte.icalendar.property.Resolvable; + +import java.time.LocalDateTime; + +public final class PeriodExplicit implements Period { + + private final LocalDateTime startTime; + + private final LocalDateTime endTime; + + public PeriodExplicit(LocalDateTime startTime, LocalDateTime endTime) { + if (startTime.isAfter(endTime)) { + throw new IllegalArgumentException("Period start must not after than period end."); + } + this.startTime = startTime; + this.endTime = endTime; + } + + @Override + public String resolve() { + return startTime.format(DateTimeProperty.utcDateTimeFormatter()) + "/" + + endTime.format(DateTimeProperty.utcDateTimeFormatter()); + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodStart.java b/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodStart.java new file mode 100644 index 0000000..3f02ace --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/datatype/PeriodStart.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024-2024 OnixByte. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.onixbyte.icalendar.datatype; + +import com.onixbyte.icalendar.component.property.DateTimeProperty; + +import java.time.Duration; +import java.time.LocalDateTime; + +public final class PeriodStart implements Period { + + private LocalDateTime start; + + private Duration duration; + + @Override + public String resolve() { + return start.format(DateTimeProperty.utcDateTimeFormatter()) + "/" + duration; + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/CalendarResolvable.java b/webcal/src/main/java/com/onixbyte/icalendar/property/Resolvable.java similarity index 94% rename from webcal/src/main/java/com/onixbyte/icalendar/property/CalendarResolvable.java rename to webcal/src/main/java/com/onixbyte/icalendar/property/Resolvable.java index b8f2fd2..08e95a1 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/CalendarResolvable.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/Resolvable.java @@ -17,7 +17,7 @@ package com.onixbyte.icalendar.property; -public interface CalendarResolvable { +public interface Resolvable { String resolve(); diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/AlarmTriggerRelationship.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/AlarmTriggerRelationship.java index 5687d3e..d1b5afc 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/AlarmTriggerRelationship.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/AlarmTriggerRelationship.java @@ -28,10 +28,10 @@ public enum AlarmTriggerRelationship implements PropertyParameter { END ; - private static final String PROPERTY_NAME = "RELATED"; + private static final String PARAMETER_NAME = "RELATED"; @Override public String resolve() { - return PROPERTY_NAME + "=" + name(); + return PARAMETER_NAME + "=" + name(); } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/AlternateRepresentation.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/AlternateRepresentation.java index c396992..ed64831 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/AlternateRepresentation.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/AlternateRepresentation.java @@ -17,8 +17,6 @@ package com.onixbyte.icalendar.property.parameter; -import com.onixbyte.icalendar.property.CalendarResolvable; - import java.net.URI; /** @@ -35,7 +33,7 @@ import java.net.URI; */ public final class AlternateRepresentation implements PropertyParameter { - private static final String PROPERTY_NAME = "ALTREP"; + private static final String PARAMETER_NAME = "ALTREP"; private final URI value; @@ -45,7 +43,7 @@ public final class AlternateRepresentation implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=\"" + value.toString() + "\""; + return PARAMETER_NAME + "=\"" + value.toString() + "\""; } public static class Builder { diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/CommonName.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/CommonName.java index e4fc7b4..61d33da 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/CommonName.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/CommonName.java @@ -17,8 +17,6 @@ package com.onixbyte.icalendar.property.parameter; -import com.onixbyte.icalendar.property.CalendarResolvable; - /** * Common Name can be specified on properties with a CAL-ADDRESS value type. The parameter * specifies the common name to be associated with the calendar user specified by the property. @@ -29,7 +27,7 @@ import com.onixbyte.icalendar.property.CalendarResolvable; */ public final class CommonName implements PropertyParameter { - private static final String PROPERTY_NAME = "CN"; + private static final String PARAMETER_NAME = "CN"; private final String value; @@ -59,6 +57,6 @@ public final class CommonName implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=\"" + this.value + "\""; + return PARAMETER_NAME + "=\"" + this.value + "\""; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Delegatee.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Delegatee.java index 51d8755..efcf09f 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Delegatee.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Delegatee.java @@ -31,7 +31,7 @@ import java.util.function.Supplier; */ public final class Delegatee implements PropertyParameter { - private static final String PROPERTY_NAME = "DELEGATED-TO"; + private static final String PARAMETER_NAME = "DELEGATED-TO"; private final List value; @@ -82,7 +82,7 @@ public final class Delegatee implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=" + String.join(",", value.stream() + return PARAMETER_NAME + "=" + String.join(",", value.stream() .map((_value) -> "\"" + _value + "\"") .toList()); } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Delegator.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Delegator.java index 96e9e99..74a9342 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Delegator.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Delegator.java @@ -18,7 +18,6 @@ package com.onixbyte.icalendar.property.parameter; import com.onixbyte.icalendar.datatype.CalendarUserAddress; -import com.onixbyte.icalendar.property.CalendarResolvable; import java.net.URI; import java.util.ArrayList; @@ -32,7 +31,7 @@ import java.util.function.Supplier; */ public final class Delegator implements PropertyParameter { - private static final String PROPERTY_NAME = "DELEGATED-FROM"; + private static final String PARAMETER_NAME = "DELEGATED-FROM"; private List value; @@ -83,7 +82,7 @@ public final class Delegator implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=\"" + String.join(",", value.stream() + return PARAMETER_NAME + "=\"" + String.join(",", value.stream() .map((_value) -> "\"" + _value + "\"") .toList()) + "\""; } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/DirectoryEntryReference.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/DirectoryEntryReference.java index 3560151..49fb0ff 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/DirectoryEntryReference.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/DirectoryEntryReference.java @@ -26,7 +26,7 @@ import java.net.URI; */ public final class DirectoryEntryReference implements PropertyParameter { - private static final String PROPERTY_NAME = "DIR"; + private static final String PARAMETER_NAME = "DIR"; private final URI value; @@ -61,6 +61,6 @@ public final class DirectoryEntryReference implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=\"" + value + "\""; + return PARAMETER_NAME + "=\"" + value + "\""; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/FormatType.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/FormatType.java index 7bc18f0..112732b 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/FormatType.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/FormatType.java @@ -17,8 +17,6 @@ package com.onixbyte.icalendar.property.parameter; -import com.onixbyte.icalendar.property.CalendarResolvable; - /** * FormatType * @@ -30,7 +28,7 @@ public enum FormatType implements PropertyParameter { ; - private static final String PROPERTY_NAME = "FMTTYPE"; + private static final String PARAMETER_NAME = "FMTTYPE"; private final String ianaRegistry; @@ -40,6 +38,6 @@ public enum FormatType implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=" + this.ianaRegistry; + return PARAMETER_NAME + "=" + this.ianaRegistry; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/FreeBusyTimeType.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/FreeBusyTimeType.java index f571e4b..874ff51 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/FreeBusyTimeType.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/FreeBusyTimeType.java @@ -30,7 +30,7 @@ public enum FreeBusyTimeType implements PropertyParameter { BUSY_TENTATIVE("BUSY-TENTATIVE") ; - private static final String PROPERTY_NAME = "FBTYPE"; + private static final String PARAMETER_NAME = "FBTYPE"; private final String tag; @@ -40,6 +40,6 @@ public enum FreeBusyTimeType implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=" + tag; + return PARAMETER_NAME + "=" + tag; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/GroupOrListMembership.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/GroupOrListMembership.java index 8aae46f..9b8f798 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/GroupOrListMembership.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/GroupOrListMembership.java @@ -31,7 +31,7 @@ import java.util.function.Supplier; */ public final class GroupOrListMembership implements PropertyParameter { - private static final String PROPERTY_NAME = "MEMBER"; + private static final String PARAMETER_NAME = "MEMBER"; private final List value; @@ -82,7 +82,7 @@ public final class GroupOrListMembership implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=" + String.join(",", value.stream() + return PARAMETER_NAME + "=" + String.join(",", value.stream() .map((_value) -> "\"" + _value + "\"") .toList()); } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/InlineEncoding.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/InlineEncoding.java index 4205e6b..c2a7dcc 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/InlineEncoding.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/InlineEncoding.java @@ -35,10 +35,10 @@ public enum InlineEncoding implements PropertyParameter { this.tag = tag; } - private static final String PROPERTY_NAME = "ENCODING"; + private static final String PARAMETER_NAME = "ENCODING"; @Override public String resolve() { - return PROPERTY_NAME + "=" + tag; + return PARAMETER_NAME + "=" + tag; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Language.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Language.java index 6b53e55..ce08efc 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Language.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/Language.java @@ -17,8 +17,6 @@ package com.onixbyte.icalendar.property.parameter; -import com.onixbyte.icalendar.property.CalendarResolvable; - /** * Language * @@ -260,7 +258,7 @@ public enum Language implements PropertyParameter { SOUTH_AFRICA_ZULU("zu-ZA") ; - private static final String PROPERTY_NAME = "LANGUAGE"; + private static final String PARAMETER_NAME = "LANGUAGE"; private final String value; @@ -270,6 +268,6 @@ public enum Language implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=" + value; + return PARAMETER_NAME + "=" + value; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/ParticipationRole.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/ParticipationRole.java index 98ebd96..7ce0e82 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/ParticipationRole.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/ParticipationRole.java @@ -30,7 +30,7 @@ public enum ParticipationRole implements PropertyParameter { NON_PARTICIPANT("NON-PARTICIPANT"), ; - private static final String PROPERTY_NAME = "ROLE"; + private static final String PARAMETER_NAME = "ROLE"; private final String tag; @@ -40,6 +40,6 @@ public enum ParticipationRole implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=" + tag; + return PARAMETER_NAME + "=" + tag; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/ParticipationStatus.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/ParticipationStatus.java index 35edafa..edc4ac5 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/ParticipationStatus.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/ParticipationStatus.java @@ -47,7 +47,7 @@ public enum ParticipationStatus implements PropertyParameter { return List.of(NEEDS_ACTION, ACCEPTED, DECLINED); } - private static final String PROPERTY_NAME = "PARTSTAT"; + private static final String PARAMETER_NAME = "PARTSTAT"; private final String tag; @@ -57,6 +57,6 @@ public enum ParticipationStatus implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=" + tag; + return PARAMETER_NAME + "=" + tag; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/PropertyParameter.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/PropertyParameter.java index c1cbb4d..ef5c6e5 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/PropertyParameter.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/PropertyParameter.java @@ -17,7 +17,7 @@ package com.onixbyte.icalendar.property.parameter; -import com.onixbyte.icalendar.property.CalendarResolvable; +import com.onixbyte.icalendar.property.Resolvable; -public interface PropertyParameter extends CalendarResolvable { +public interface PropertyParameter extends Resolvable { } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/RecurrenceIdentifierRange.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/RecurrenceIdentifierRange.java index 56e32dc..d4d46b7 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/RecurrenceIdentifierRange.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/RecurrenceIdentifierRange.java @@ -27,7 +27,7 @@ public enum RecurrenceIdentifierRange implements PropertyParameter { THIS_AND_FUTURE("THISANDFUTURE") ; - private static final String PROPERTY_NAME = "RANGE"; + private static final String PARAMETER_NAME = "RANGE"; private final String tag; @@ -37,6 +37,6 @@ public enum RecurrenceIdentifierRange implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=" + tag; + return PARAMETER_NAME + "=" + tag; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/RelationshipType.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/RelationshipType.java index 88a78d5..e146b89 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/RelationshipType.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/RelationshipType.java @@ -39,7 +39,7 @@ public enum RelationshipType implements PropertyParameter { START_TO_START("STARTTOSTART") ; - private static final String PROPERTY_NAME = "RELTYPE"; + private static final String PARAMETER_NAME = "RELTYPE"; private final String tag; @@ -49,6 +49,6 @@ public enum RelationshipType implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=" + tag; + return PARAMETER_NAME + "=" + tag; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/RsvpExpectation.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/RsvpExpectation.java index 83b27e3..59cb763 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/RsvpExpectation.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/RsvpExpectation.java @@ -24,7 +24,7 @@ package com.onixbyte.icalendar.property.parameter; */ public final class RsvpExpectation implements PropertyParameter { - private static final String PROPERTY_NAME = "RSVP"; + private static final String PARAMETER_NAME = "RSVP"; private final boolean value; @@ -34,6 +34,6 @@ public final class RsvpExpectation implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=" + String.valueOf(value).toUpperCase(); + return PARAMETER_NAME + "=" + String.valueOf(value).toUpperCase(); } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/SentBy.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/SentBy.java index 1e2be1b..42a0cb5 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/SentBy.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/SentBy.java @@ -28,7 +28,7 @@ import java.net.URI; */ public final class SentBy implements PropertyParameter { - private static final String PROPERTY_NAME = "SENT-BY"; + private static final String PARAMETER_NAME = "SENT-BY"; private final CalendarUserAddress value; @@ -68,6 +68,6 @@ public final class SentBy implements PropertyParameter { @Override public String resolve() { - return PROPERTY_NAME + "=\"" + value + "\""; + return PARAMETER_NAME + "=\"" + value + "\""; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/CalendarUserType.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/UserType.java similarity index 80% rename from webcal/src/main/java/com/onixbyte/icalendar/property/parameter/CalendarUserType.java rename to webcal/src/main/java/com/onixbyte/icalendar/property/parameter/UserType.java index a0dda83..dc182a3 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/CalendarUserType.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/UserType.java @@ -17,14 +17,12 @@ package com.onixbyte.icalendar.property.parameter; -import com.onixbyte.icalendar.property.CalendarResolvable; - /** - * CalendarUserType + * UserType * * @author Zihlu WANG */ -public enum CalendarUserType implements PropertyParameter { +public enum UserType implements PropertyParameter { /** * An individual. @@ -52,10 +50,10 @@ public enum CalendarUserType implements PropertyParameter { UNKNOWN, ; - private static final String PROPERTY_NAME = "CUTYPE"; + private static final String PARAMETER_NAME = "CUTYPE"; @Override public String resolve() { - return PROPERTY_NAME + "=" + this.name(); + return PARAMETER_NAME + "=" + this.name(); } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/ValueDataType.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/ValueDataType.java index a38dd20..bdc27e2 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/ValueDataType.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/ValueDataType.java @@ -22,5 +22,33 @@ package com.onixbyte.icalendar.property.parameter; * * @author Zihlu WANG */ -public class ValueDataType { +public enum ValueDataType implements PropertyParameter { + + BINARY("BINARY"), + BOOLEAN("BOOLEAN"), + CAL_ADDRESS("CAL-ADDRESS"), + DATE("DATE"), + DATE_TIME("DATE-TIME"), + DURATION("DURATION"), + FLOAT("FLOAT"), + INTEGER("INTEGER"), + PERIOD("PERIOD"), + RECURRENCE_RULE("RECUR"), + TEXT("TEXT"), + URI("URI"), + UTC_OFFSET("UTC-OFFSET"), + ; + + private static final String PARAMETER_NAME = "VALUE"; + + private final String tag; + + ValueDataType(String tag) { + this.tag = tag; + } + + @Override + public String resolve() { + return PARAMETER_NAME + "=" + tag; + } }