From d91a117ded0aa4e46883a6d421bbcd9492f44416 Mon Sep 17 00:00:00 2001 From: Zihlu Wang Date: Fri, 24 May 2024 11:30:35 +0800 Subject: [PATCH] feat: added classes --- .../calendar/property/CalendarProperty.java | 23 ++ .../property}/CalendarScale.java | 6 +- .../property}/Method.java | 6 +- .../property}/ProductIdentifier.java | 22 +- .../property}/Version.java | 6 +- .../icalendar/component/Calendar.java | 12 +- .../component/CalendarComponent.java | 8 +- .../onixbyte/icalendar/component/Event.java | 33 ++- .../property/Attachment.java} | 18 +- .../component/property/Categories.java | 21 ++ .../component/property/Classification.java | 21 ++ .../component/property/ComponentProperty.java | 23 ++ .../property}/DateTimeCreated.java | 2 +- .../property}/DateTimeStamp.java | 14 +- .../property}/LastModified.java | 2 +- .../property}/UniqueIdentifier.java | 6 +- .../datatype/CalendarUserAddress.java | 37 +++ .../{Prop.java => CalendarResolvable.java} | 2 +- .../parameter/AlternateRepresentation.java | 52 ++-- .../property/parameter/CalendarUserType.java | 4 +- .../property/parameter/CommonName.java | 36 ++- .../property/parameter/Delegatee.java | 41 ++- .../property/parameter/Delegator.java | 4 +- .../property/parameter/FormatType.java | 4 +- .../property/parameter/Language.java | 249 +++++++++++++++++- .../property/parameter/PropertyParameter.java | 23 ++ 26 files changed, 579 insertions(+), 96 deletions(-) create mode 100644 webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarProperty.java rename webcal/src/main/java/com/onixbyte/icalendar/{property/calendar => calendar/property}/CalendarScale.java (85%) rename webcal/src/main/java/com/onixbyte/icalendar/{property/calendar => calendar/property}/Method.java (89%) rename webcal/src/main/java/com/onixbyte/icalendar/{property/calendar => calendar/property}/ProductIdentifier.java (68%) rename webcal/src/main/java/com/onixbyte/icalendar/{property/calendar => calendar/property}/Version.java (85%) rename webcal/src/main/java/com/onixbyte/icalendar/{property/component/Attach.java => component/property/Attachment.java} (63%) create mode 100644 webcal/src/main/java/com/onixbyte/icalendar/component/property/Categories.java create mode 100644 webcal/src/main/java/com/onixbyte/icalendar/component/property/Classification.java create mode 100644 webcal/src/main/java/com/onixbyte/icalendar/component/property/ComponentProperty.java rename webcal/src/main/java/com/onixbyte/icalendar/{property/component => component/property}/DateTimeCreated.java (93%) rename webcal/src/main/java/com/onixbyte/icalendar/{property/component => component/property}/DateTimeStamp.java (83%) rename webcal/src/main/java/com/onixbyte/icalendar/{property/component => component/property}/LastModified.java (93%) rename webcal/src/main/java/com/onixbyte/icalendar/{property/component => component/property}/UniqueIdentifier.java (91%) create mode 100644 webcal/src/main/java/com/onixbyte/icalendar/datatype/CalendarUserAddress.java rename webcal/src/main/java/com/onixbyte/icalendar/property/{Prop.java => CalendarResolvable.java} (94%) create mode 100644 webcal/src/main/java/com/onixbyte/icalendar/property/parameter/PropertyParameter.java diff --git a/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarProperty.java b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarProperty.java new file mode 100644 index 0000000..5744014 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarProperty.java @@ -0,0 +1,23 @@ +/* + * 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.calendar.property; + +import com.onixbyte.icalendar.property.CalendarResolvable; + +public interface CalendarProperty extends CalendarResolvable { +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/calendar/CalendarScale.java b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarScale.java similarity index 85% rename from webcal/src/main/java/com/onixbyte/icalendar/property/calendar/CalendarScale.java rename to webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarScale.java index ab07b53..dc95f73 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/calendar/CalendarScale.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarScale.java @@ -15,16 +15,14 @@ * limitations under the License. */ -package com.onixbyte.icalendar.property.calendar; - -import com.onixbyte.icalendar.property.Prop; +package com.onixbyte.icalendar.calendar.property; /** * CalendarScale * * @author Zihlu WANG */ -public enum CalendarScale implements Prop { +public enum CalendarScale implements CalendarProperty { GREGORIAN, ; diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/calendar/Method.java b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Method.java similarity index 89% rename from webcal/src/main/java/com/onixbyte/icalendar/property/calendar/Method.java rename to webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Method.java index a141e58..8f7c422 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/calendar/Method.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Method.java @@ -15,11 +15,9 @@ * limitations under the License. */ -package com.onixbyte.icalendar.property.calendar; +package com.onixbyte.icalendar.calendar.property; -import com.onixbyte.icalendar.property.Prop; - -public enum Method implements Prop { +public enum Method implements CalendarProperty { PUBLISH("PUBLISH"), REQUEST("REQUEST"), diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/calendar/ProductIdentifier.java b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/ProductIdentifier.java similarity index 68% rename from webcal/src/main/java/com/onixbyte/icalendar/property/calendar/ProductIdentifier.java rename to webcal/src/main/java/com/onixbyte/icalendar/calendar/property/ProductIdentifier.java index 2ebbd96..999308c 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/calendar/ProductIdentifier.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/ProductIdentifier.java @@ -15,18 +15,16 @@ * limitations under the License. */ -package com.onixbyte.icalendar.property.calendar; - -import com.onixbyte.icalendar.property.Prop; +package com.onixbyte.icalendar.calendar.property; /** * ProductIdentifier * * @author Zihlu WANG */ -public final class ProductIdentifier implements Prop { +public final class ProductIdentifier implements CalendarProperty { - private String value; + private final String value; @Override public String resolve() { @@ -34,29 +32,28 @@ public final class ProductIdentifier implements Prop { } public static class Builder { - private final ProductIdentifier productIdentifier; + private String productIdentifier; private Builder() { - this.productIdentifier = new ProductIdentifier(); } public Builder productIdentifier(String productIdentifier) { - this.productIdentifier.value = productIdentifier; + this.productIdentifier = productIdentifier; return this; } public Builder productIdentifier(String companyName, String productName) { - this.productIdentifier.value = "-//" + companyName + "//" + productName + "//EN"; + this.productIdentifier = "-//" + companyName + "//" + productName + "//EN"; return this; } public Builder productIdentifier(String companyName, String productName, String languageTag) { - this.productIdentifier.value = "-//" + companyName + "//" + productName + "//" + languageTag; + this.productIdentifier = "-//" + companyName + "//" + productName + "//" + languageTag; return this; } public ProductIdentifier build() { - return productIdentifier; + return new ProductIdentifier(productIdentifier); } } @@ -66,6 +63,7 @@ public final class ProductIdentifier implements Prop { private static final String PROPERTY_NAME = "PRODID"; - private ProductIdentifier() { + private ProductIdentifier(String value) { + this.value = value; } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/calendar/Version.java b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Version.java similarity index 85% rename from webcal/src/main/java/com/onixbyte/icalendar/property/calendar/Version.java rename to webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Version.java index ac4ed00..7c4784a 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/calendar/Version.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Version.java @@ -15,16 +15,14 @@ * limitations under the License. */ -package com.onixbyte.icalendar.property.calendar; - -import com.onixbyte.icalendar.property.Prop; +package com.onixbyte.icalendar.calendar.property; /** * Version * * @author Zihlu WANG */ -public enum Version implements Prop { +public enum Version implements CalendarProperty { 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 dd9d386..ba7213a 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/Calendar.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/Calendar.java @@ -17,10 +17,10 @@ package com.onixbyte.icalendar.component; -import com.onixbyte.icalendar.property.calendar.CalendarScale; -import com.onixbyte.icalendar.property.calendar.Method; -import com.onixbyte.icalendar.property.calendar.ProductIdentifier; -import com.onixbyte.icalendar.property.calendar.Version; +import com.onixbyte.icalendar.calendar.property.CalendarScale; +import com.onixbyte.icalendar.calendar.property.Method; +import com.onixbyte.icalendar.calendar.property.ProductIdentifier; +import com.onixbyte.icalendar.calendar.property.Version; import java.util.ArrayList; import java.util.List; @@ -100,9 +100,7 @@ public final class Calendar { .ifPresent((_method) -> calendarBuilder.append(_method.resolve()).append('\n')); if (!components.isEmpty()) { - for (var component : components) { - calendarBuilder.append(component.resolve()).append('\n'); - } + components.forEach(((component) -> calendarBuilder.append(component.resolve()).append('\n'))); } calendarBuilder.append("END:").append(COMPONENT_NAME).append('\n'); diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/CalendarComponent.java b/webcal/src/main/java/com/onixbyte/icalendar/component/CalendarComponent.java index 3768d32..0b2cf27 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/CalendarComponent.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/CalendarComponent.java @@ -18,10 +18,12 @@ package com.onixbyte.icalendar.component; /** - * The abstract sealed class {@code WebCalendarNode} represents a node in a web calendar, such as an event, a to-do - * item, or an alarm. It provides common properties and methods for all calendar components and events. + * The abstract sealed class {@code WebCalendarNode} represents a node in a web calendar, such as an + * event, a to-do item, or an alarm. It provides common properties and + * methods for all calendar components and events. *

- * Subclasses of {@code WebCalendarNode} should implement the {@link #resolve()} method to generate the corresponding iCalendar content for the specific calendar component or event. + * Subclasses of {@code WebCalendarNode} should implement the {@link #resolve()} method to generate + * the corresponding iCalendar content for the specific calendar component or event. * * @author Zihlu Wang * @version 1.1.0 diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/Event.java b/webcal/src/main/java/com/onixbyte/icalendar/component/Event.java index e6265e4..bf88742 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/component/Event.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/Event.java @@ -17,8 +17,9 @@ package com.onixbyte.icalendar.component; -import com.onixbyte.icalendar.property.component.DateTimeStamp; -import com.onixbyte.icalendar.property.component.UniqueIdentifier; +import com.onixbyte.icalendar.component.property.Classification; +import com.onixbyte.icalendar.component.property.DateTimeStamp; +import com.onixbyte.icalendar.component.property.UniqueIdentifier; /** * Event @@ -27,11 +28,39 @@ import com.onixbyte.icalendar.property.component.UniqueIdentifier; */ public class Event extends CalendarComponent { + /* + * The following properties are REQUIRED, but MUST NOT occur more than once. + */ + + /** + * + */ private DateTimeStamp dtStamp; + /** + * + */ private UniqueIdentifier uid; + /* + * The following property is REQUIRED if the component appears in an iCalendar object that + * doesn't specify the "METHOD" property; otherwise, it is OPTIONAL; in any case, it MUST NOT + * occur more than once. + */ + /** + * + */ + private DateTimeStamp dtStart; + + /* + * The following properties are OPTIONAL, but MUST NOT occur more than once. + */ + + /** + * + */ + private Classification classification; @Override public String resolve() { diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/component/Attach.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Attachment.java similarity index 63% rename from webcal/src/main/java/com/onixbyte/icalendar/property/component/Attach.java rename to webcal/src/main/java/com/onixbyte/icalendar/component/property/Attachment.java index 4ddda6e..b37f999 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/component/Attach.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Attachment.java @@ -15,19 +15,19 @@ * limitations under the License. */ -package com.onixbyte.icalendar.property.component; +package com.onixbyte.icalendar.component.property; -import com.onixbyte.icalendar.property.Prop; import com.onixbyte.icalendar.property.parameter.FormatType; import java.net.URI; +import java.util.Optional; /** - * Attach + * Attachment * * @author Zihlu WANG */ -public final class Attach implements Prop { +public final class Attachment implements ComponentProperty { private FormatType formatType; @@ -35,6 +35,14 @@ public final class Attach implements Prop { @Override public String resolve() { - return ""; + final var attachmentBuilder = new StringBuilder("ATTACH"); + + Optional.ofNullable(formatType) + .ifPresent((fmtType) -> attachmentBuilder.append(fmtType.resolve())); + + attachmentBuilder.append(":") + .append(uri.toString()); + + return attachmentBuilder.toString(); } } 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 new file mode 100644 index 0000000..b0ff2d9 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Categories.java @@ -0,0 +1,21 @@ +/* + * 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 class Categories { +} 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 new file mode 100644 index 0000000..2770a93 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/Classification.java @@ -0,0 +1,21 @@ +/* + * 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 enum Classification { +} 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 new file mode 100644 index 0000000..ae2f910 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/ComponentProperty.java @@ -0,0 +1,23 @@ +/* + * 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.CalendarResolvable; + +public interface ComponentProperty extends CalendarResolvable { +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/component/DateTimeCreated.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCreated.java similarity index 93% rename from webcal/src/main/java/com/onixbyte/icalendar/property/component/DateTimeCreated.java rename to webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCreated.java index 26d2f3a..e2b4e34 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/component/DateTimeCreated.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeCreated.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package com.onixbyte.icalendar.property.component; +package com.onixbyte.icalendar.component.property; /** * DateTimeCreated diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/component/DateTimeStamp.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStamp.java similarity index 83% rename from webcal/src/main/java/com/onixbyte/icalendar/property/component/DateTimeStamp.java rename to webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStamp.java index 743efee..21f902f 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/component/DateTimeStamp.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/DateTimeStamp.java @@ -15,19 +15,19 @@ * limitations under the License. */ -package com.onixbyte.icalendar.property.component; +package com.onixbyte.icalendar.component.property; +import com.onixbyte.icalendar.calendar.property.Method; import com.onixbyte.icalendar.config.Formatters; -import com.onixbyte.icalendar.property.Prop; import java.time.LocalDateTime; /** * In the case of an {@link com.onixbyte.icalendar.component.Calendar iCalendar} object that specifies a "{@link - * com.onixbyte.icalendar.property.calendar.Method Method}" property, this property specifies the date and time that + * 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 - * com.onixbyte.icalendar.property.calendar.Method Method}" property, this property specifies the date and time that + * 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. @@ -37,19 +37,19 @@ import java.time.LocalDateTime; * com.onixbyte.icalendar.component.Calendar iCalendar} objects. *

* In the case of an {@link com.onixbyte.icalendar.component.Calendar iCalendar} object that specifies a "{@link - * com.onixbyte.icalendar.property.calendar.Method Method}" property, this property differs from the "{@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 - * com.onixbyte.icalendar.property.calendar.Method METHOD}" property, this property is equivalent to the "{@link + * Method METHOD}" property, this property is equivalent to the "{@link * LastModified LAST-MODIFIED}" property. * * @author Zihlu WANG */ -public final class DateTimeStamp implements Prop { +public final class DateTimeStamp implements ComponentProperty { private static final String PROPERTY_NAME = "DTSTAMP"; diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/component/LastModified.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/LastModified.java similarity index 93% rename from webcal/src/main/java/com/onixbyte/icalendar/property/component/LastModified.java rename to webcal/src/main/java/com/onixbyte/icalendar/component/property/LastModified.java index 6c2f0bb..21b3ddd 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/component/LastModified.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/LastModified.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package com.onixbyte.icalendar.property.component; +package com.onixbyte.icalendar.component.property; /** * LastModified diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/component/UniqueIdentifier.java b/webcal/src/main/java/com/onixbyte/icalendar/component/property/UniqueIdentifier.java similarity index 91% rename from webcal/src/main/java/com/onixbyte/icalendar/property/component/UniqueIdentifier.java rename to webcal/src/main/java/com/onixbyte/icalendar/component/property/UniqueIdentifier.java index 52af13c..b27ab46 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/component/UniqueIdentifier.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/property/UniqueIdentifier.java @@ -15,16 +15,14 @@ * limitations under the License. */ -package com.onixbyte.icalendar.property.component; - -import com.onixbyte.icalendar.property.Prop; +package com.onixbyte.icalendar.component.property; /** * UniqueIdentifier * * @author Zihlu WANG */ -public final class UniqueIdentifier implements Prop { +public final class UniqueIdentifier implements ComponentProperty { private String value; diff --git a/webcal/src/main/java/com/onixbyte/icalendar/datatype/CalendarUserAddress.java b/webcal/src/main/java/com/onixbyte/icalendar/datatype/CalendarUserAddress.java new file mode 100644 index 0000000..25f7df0 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/datatype/CalendarUserAddress.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.datatype; + +import java.net.URI; + +public final class CalendarUserAddress { + + private URI value; + + public CalendarUserAddress(URI value) { + if (!"mailto".equalsIgnoreCase(value.getScheme())) { + throw new IllegalArgumentException("Calendar User Address (CAL-ADDRESS) only accept mailto URI."); + } + this.value = value; + } + + @Override + public String toString() { + return value.toString(); + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/Prop.java b/webcal/src/main/java/com/onixbyte/icalendar/property/CalendarResolvable.java similarity index 94% rename from webcal/src/main/java/com/onixbyte/icalendar/property/Prop.java rename to webcal/src/main/java/com/onixbyte/icalendar/property/CalendarResolvable.java index ba4b51b..b8f2fd2 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/Prop.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/CalendarResolvable.java @@ -17,7 +17,7 @@ package com.onixbyte.icalendar.property; -public interface Prop { +public interface CalendarResolvable { String resolve(); 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 0a03003..56a35dc 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,7 +17,7 @@ package com.onixbyte.icalendar.property.parameter; -import com.onixbyte.icalendar.property.Prop; +import com.onixbyte.icalendar.property.CalendarResolvable; import java.net.URI; @@ -33,33 +33,43 @@ import java.net.URI; * * @author Zihlu Wang */ -public final class AlternateRepresentation implements Prop { +public final class AlternateRepresentation implements PropertyParameter { private static final String PROPERTY_NAME = "ALTREP"; - private URI uri; + private URI value; - private AlternateRepresentation() { - } - - public AlternateRepresentation setUri(String uri) { - this.uri = URI.create(uri); - return this; - } - - public AlternateRepresentation setUri(URI uri) { - this.uri = uri; - return this; - } - - public static AlternateRepresentation createInstance(String uri) { - var instance = new AlternateRepresentation(); - instance.uri = URI.create(uri); - return instance; + private AlternateRepresentation(URI uri) { + this.value = uri; } @Override public String resolve() { - return PROPERTY_NAME + "=\"" + uri.toString() + "\""; + return PROPERTY_NAME + "=\"" + value.toString() + "\""; + } + + public static class Builder { + private URI uri; + + private Builder() { + } + + public Builder uri(String uri) { + this.uri = URI.create(uri); + return this; + } + + public Builder uri(URI uri) { + this.uri = uri; + return this; + } + + public AlternateRepresentation build() { + return new AlternateRepresentation(uri); + } + } + + public static Builder builder() { + return new Builder(); } } diff --git a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/CalendarUserType.java b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/CalendarUserType.java index 0ab14ae..a0dda83 100644 --- a/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/CalendarUserType.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/CalendarUserType.java @@ -17,14 +17,14 @@ package com.onixbyte.icalendar.property.parameter; -import com.onixbyte.icalendar.property.Prop; +import com.onixbyte.icalendar.property.CalendarResolvable; /** * CalendarUserType * * @author Zihlu WANG */ -public enum CalendarUserType implements Prop { +public enum CalendarUserType implements PropertyParameter { /** * An individual. 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 5b8899c..e4fc7b4 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,7 +17,7 @@ package com.onixbyte.icalendar.property.parameter; -import com.onixbyte.icalendar.property.Prop; +import com.onixbyte.icalendar.property.CalendarResolvable; /** * Common Name can be specified on properties with a CAL-ADDRESS value type. The parameter @@ -27,26 +27,38 @@ import com.onixbyte.icalendar.property.Prop; * * @author Zihlu Wang */ -public final class CommonName implements Prop { +public final class CommonName implements PropertyParameter { - private String value; + private static final String PROPERTY_NAME = "CN"; - private CommonName() { - } + private final String value; - public CommonName setValue(String value) { + private CommonName(String value) { this.value = value; - return this; } - public static CommonName createInstance(String commonName) { - var instance = new CommonName(); - instance.value = commonName; - return instance; + public static class Builder { + private String value; + + private Builder() { + } + + public Builder commonName(String commonName) { + this.value = commonName; + return this; + } + + public CommonName build() { + return new CommonName(value); + } + } + + public static Builder builder() { + return new Builder(); } @Override public String resolve() { - return "CN=\"" + this.value + "\""; + return PROPERTY_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 75d8610..bcfae0e 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 @@ -17,10 +17,49 @@ package com.onixbyte.icalendar.property.parameter; +import com.onixbyte.icalendar.datatype.CalendarUserAddress; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + /** * Delegate * * @author Zihlu WANG */ -public class Delegatee { +public final class Delegatee implements PropertyParameter { + + private static final String PROPERTY_NAME = "DELEGATED-TO"; + + private final List value; + + private Delegatee(List value) { + this.value = value; + } + + public static class Builder { + private List value; + + private Builder() { + this.value = new ArrayList<>(); + } + + public Builder addDelegatee(URI delegateeUri) { + value.add(new CalendarUserAddress(delegateeUri)); + return this; + } + + public Delegatee build() { + return new Delegatee(value); + } + } + + @Override + public String resolve() { + return PROPERTY_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 cad9686..01eb8fe 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 @@ -17,7 +17,7 @@ package com.onixbyte.icalendar.property.parameter; -import com.onixbyte.icalendar.property.Prop; +import com.onixbyte.icalendar.property.CalendarResolvable; import java.net.URI; @@ -26,7 +26,7 @@ import java.net.URI; * * @author Zihlu WANG */ -public final class Delegator implements Prop { +public final class Delegator implements PropertyParameter { private static final String PROPERTY_NAME = "DELEGATED-FROM"; 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 e912b24..2c61ad7 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,14 +17,14 @@ package com.onixbyte.icalendar.property.parameter; -import com.onixbyte.icalendar.property.Prop; +import com.onixbyte.icalendar.property.CalendarResolvable; /** * FormatType * * @author Zihlu WANG */ -public enum FormatType implements Prop { +public enum FormatType implements PropertyParameter { JSON("application/json"), 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 d6d9ae0..29e8d83 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,10 +17,257 @@ package com.onixbyte.icalendar.property.parameter; +import com.onixbyte.icalendar.property.CalendarResolvable; + /** * Language * * @author Zihlu WANG */ -public class Language { +public enum Language implements PropertyParameter { + + AFRIKAANS("af"), + SOUTH_AFRICA_AFRIKAANS("af-ZA"), + ARABIC("ar"), + UAE_ARABIC("ar-AE"), + BAHRAIN_ARABIC("ar-BH"), + ALGERIA_ARABIC("ar-DZ"), + EGYPT_ARABIC("ar-EG"), + IRAQ_ARABIC("ar-IQ"), + JORDAN_ARABIC("ar-JO"), + KUWAIT_ARABIC("ar-KW"), + LEBANON_ARABIC("ar-LB"), + LIBYA_ARABIC("ar-LY"), + MOROCCO_ARABIC("ar-MA"), + OMAN_ARABIC("ar-OM"), + QATAR_ARABIC("ar-QA"), + SAUDI_ARABIA_ARABIC_("ar-SA"), + SYRIA_ARABIC("ar-SY"), + TUNISIA_ARABIC("ar-TN"), + YEMEN_ARABIC("ar-YE"), + LATIN_AZERI("az"), + AZERBAIJAN_LATIN_AZERI("az-AZ"), + AZERBAIJAN_CYRILLIC_AZERI("az-Cyrl-AZ"), + BELARUSIAN("be"), + BELARUS_BELARUSIAN("be-BY"), + BULGARIAN("bg"), + BULGARIA_BULGARIAN("bg-BG"), + BOSNIA_AND_HERZEGOVINA_BOSNIAN("bs-BA"), + CATALAN("ca"), + SPAIN_CATALAN("ca-ES"), + CZECH("cs"), + CZECH_REPUBLIC_CZECH("cs-CZ"), + WELSH("cy"), + UNITED_KINGDOM_WELSH("cy-GB"), + DANISH("da"), + DENMARK_DANISH("da-DK"), + GERMAN("de"), + AUSTRIA_GERMAN("de-AT"), + SWITZERLAND_GERMAN("de-CH"), + GERMANY_GERMAN("de-DE"), + LIECHTENSTEIN_GERMAN("de-LI"), + LUXEMBOURG_GERMAN("de-LU"), + DIVEHI("dv"), + MALDIVES_DIVEHI("dv-MV"), + GREEK("el"), + GREECE_GREEK("el-GR"), + ENGLISH("en"), + AUSTRALIA_ENGLISH("en-AU"), + BELIZE_ENGLISH("en-BZ"), + CANADA_ENGLISH("en-CA"), + CARIBBEAN_ENGLISH("en-CB"), + UNITED_KINGDOM_ENGLISH("en-GB"), + IRELAND_ENGLISH("en-IE"), + JAMAICA_ENGLISH("en-JM"), + NEW_ZEALAND_ENGLISH("en-NZ"), + PHILIPPINES_ENGLISH("en-PH"), + TRINIDAD_AND_TOBAGO_ENGLISH("en-TT"), + UNITED_STATES_ENGLISH("en-US"), + SOUTH_AFRICA_ENGLISH("en-ZA"), + ZIMBABWE_ENGLISH("en-ZW"), + ESPERANTO("eo"), + SPANISH("es"), + ARGENTINA_SPANISH("es-AR"), + BOLIVIA_SPANISH("es-BO"), + CHILE_SPANISH("es-CL"), + COLOMBIA_SPANISH("es-CO"), + COSTA_RICA_SPANISH("es-CR"), + DOMINICAN_REPUBLIC_SPANISH("es-DO"), + ECUADOR_SPANISH("es-EC"), + SPAIN_SPANISH("es-ES"), + GUATEMALA_SPANISH("es-GT"), + HONDURAS_SPANISH("es-HN"), + MEXICO_SPANISH("es-MX"), + NICARAGUA_SPANISH("es-NI"), + PANAMA_SPANISH("es-PA"), + PERU_SPANISH("es-PE"), + PUERTO_RICO_SPANISH("es-PR"), + PARAGUAY_SPANISH("es-PY"), + EL_SALVADOR_SPANISH("es-SV"), + URUGUAY_SPANISH("es-UY"), + VENEZUELA_SPANISH("es-VE"), + ESTONIAN("et"), + ESTONIA_ESTONIAN("et-EE"), + BASQUE("eu"), + SPAIN_BASQUE("eu-ES"), + FARSI("fa"), + IRAN_FARSI("fa-IR"), + FINNISH("fi"), + FINLAND_FINNISH("fi-FI"), + FAROESE("fo"), + FAROE_ISLANDS_FAROESE("fo-FO"), + FRENCH("fr"), + BELGIUM_FRENCH("fr-BE"), + CANADA_FRENCH("fr-CA"), + SWITZERLAND_FRENCH("fr-CH"), + FRANCE_FRENCH("fr-FR"), + LUXEMBOURG_FRENCH("fr-LU"), + MONACO_FRENCH("fr-MC"), + GALICIAN("gl"), + SPAIN_GALICIAN("gl-ES"), + GUJARATI("gu"), + INDIA_GUJARATI("gu-IN"), + HEBREW("he"), + ISRAEL_HEBREW("he-IL"), + HINDI("hi"), + INDIA_HINDI("hi-IN"), + CROATIAN("hr"), + BOSNIA_AND_HERZEGOVINA_CROATIAN("hr-BA"), + CROATIA_CROATIAN("hr-HR"), + HUNGARIAN("hu"), + HUNGARY_HUNGARIAN("hu-HU"), + ARMENIAN("hy"), + ARMENIA_ARMENIAN("hy-AM"), + INDONESIAN("id"), + INDONESIA_INDONESIAN("id-ID"), + ICELANDIC("is"), + ICELAND_ICELANDIC("is-IS"), + ITALIAN("it"), + SWITZERLAND_ITALIAN("it-CH"), + ITALY_ITALIAN("it-IT"), + JAPANESE("ja"), + JAPAN_JAPANESE("ja-JA"), + GEORGIAN("ka"), + GEORGIA_GEORGIAN("ka-GE"), + KAZAKH("kk"), + KAZAKHSTAN_KAZAKH("kk-KZ"), + KANNADA("kn"), + INDIA_KANNADA("kn-IN"), + KOREAN("ko"), + KOREA_KOREAN("ko-KR"), + KONKANI("kok"), + INDIA_KONKANI("kok-IN"), + KYRGYZ("ky"), + KYRGYZSTAN_KYRGYZ("ky-KG"), + LITHUANIAN("lt"), + LITHUANIA_LITHUANIAN("lt-LT"), + LATVIAN("lv"), + LATVIA_LATVIAN("lv-LV"), + MAORI("mi"), + NEW_ZEALAND_MAORI("mi-NZ"), + FYRO_MACEDONIAN("mk"), + MACEDONIA_FYRO_MACEDONIAN("mk-MK"), + MONGOLIAN("mn"), + MONGOLIA_MONGOLIAN("mn-MN"), + MARATHI("mr"), + INDIA_MARATHI("mr-IN"), + MALAY("ms"), + BRUNEI_DARUSSALAM_MALAY("ms-BN"), + MALAYSIA_MALAY("ms-MY"), + MALTESE("mt"), + MALTA_MALTESE("mt-MT"), + NORWEGIAN("nb"), + NORWAY_NORWEGIAN("nb-NO"), + DUTCH("nl"), + BELGIUM_DUTCH("nl-BE"), + NETHERLANDS_DUTCH("nl-NL"), + NORWAY_NYNORSK_NORWEGIAN("nn-NO"), + NORTHERN_SOTHO("ns"), + SOUTH_AFRICA_NORTHERN_SOTHO("ns-ZA"), + PUNJABI("pa"), + INDIA_PUNJABI("pa-IN"), + POLISH("pl"), + POLAND_POLISH("pl-PL"), + PASHTO("pt"), + AFGHANISTAN_PASHTO("ps-AR"), + PORTUGUESE("pt"), + BRAZIL_PORTUGUESE("pt-BR"), + PORTUGAL_PORTUGUESE("pt-PT"), + QUECHUA("qu"), + BOLIVIA_QUECHUA("qu-BO"), + ECUADOR_QUECHUA("qu-EC"), + PERU_QUECHUA("qu-PE"), + ROMANIAN("ro"), + ROMANIA_ROMANIAN("ro-RO"), + RUSSIAN("ru"), + RUSSIA_RUSSIAN("ru-RU"), + SANSKRIT("sa"), + INDIA_SANSKRIT("sa-IN"), + SAMI("se"), + FINLAND_SAMI("se-FI"), + NORWAY_SAMI("se-NO"), + SWEDEN_SAMI("se-SE"), + SLOVAK("sk"), + SLOVAKIA_SLOVAK("sk-SK"), + SLOVENIAN("sl"), + SLOVENIA_SLOVENIAN("sl-SI"), + ALBANIAN("sq"), + ALBANIA_ALBANIAN("sq-AL"), + BOSNIA_AND_HERZEGOVINA_LATIN_SERBIAN("sr-BA"), + BOSNIA_AND_HERZEGOVINA_CYRILLIC_SERBIAN("sr-Cyrl-BA"), + SERBIA_AND_MONTENEGRO_LATIN_SERBIAN("sr-SP"), + SERBIA_AND_MONTENEGRO_CYRILLIC_SERBIAN("sr-Cyrl-SP"), + SWEDISH("sv"), + FINLAND_SWEDISH("sv-FI"), + SWEDEN_SWEDISH("sv-SE"), + SWAHILI("sw"), + KENYA_SWAHILI("sw-KE"), + SYRIAC("syr"), + SYRIA_SYRIAC("syr-SY"), + TAMIL("ta"), + INDIA_TAMIL("ta-IN"), + TELUGU("te"), + INDIA_TELUGU("te-IN"), + THAI("th"), + THAILAND_THAI("th-TH"), + TAGALOG("tl"), + PHILIPPINES_TAGALOG("tl-PH"), + TSWANA("tn"), + SOUTH_AFRICA_TSWANA("tn-ZA"), + TURKISH("tr"), + TURKEY_TURKISH("tr-TR"), + TATAR("tt"), + RUSSIA_TATAR("tt-RU"), + TSONGA("ts"), + UKRAINIAN("uk"), + UKRAINE_UKRAINIAN("uk-UA"), + URDU("ur"), + PAKISTAN_URDU("ur-PK"), + UZBEK("uz"), + UZBEKISTAN_UZBEK("uz-UZ"), + UZBEKISTAN_CYRILLIC_UZBEK("uz-Cyrl-UZ"), + VIETNAMESE("vi"), + VIETNAM_VIETNAMESE("vi-VN"), + XHOSA("xh"), + SOUTH_AFRICA_XHOSA("xh-ZA"), + CHINESE("zh"), + SIMPLIFIED_CHINESE("zh-CN"), + HONG_KONG_CHINESE("zh-HK"), + MACAU_CHINESE("zh-MO"), + SINGAPORE_CHINESE("zh-SG"), + TRADITIONAL_CHINESE("zh-TW"), + ZULU("zu"), + SOUTH_AFRICA_ZULU("zu-ZA") + ; + + private final String value; + + Language(String value) { + this.value = value; + } + + @Override + public String resolve() { + return "LANGUAGE=" + value; + } } 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 new file mode 100644 index 0000000..c1cbb4d --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/property/parameter/PropertyParameter.java @@ -0,0 +1,23 @@ +/* + * 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.property.parameter; + +import com.onixbyte.icalendar.property.CalendarResolvable; + +public interface PropertyParameter extends CalendarResolvable { +}