diff --git a/webcal/src/main/java/com/onixbyte/icalendar/CalendarUtil.java b/webcal/src/main/java/com/onixbyte/icalendar/CalendarUtil.java new file mode 100644 index 0000000..a94d8c2 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/CalendarUtil.java @@ -0,0 +1,15 @@ +package com.onixbyte.icalendar; + +/** + * CalendarUtil + * + * @author Zihlu WANG + */ +public final class CalendarUtil { + + private CalendarUtil() { + } + + + +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/Calendar.java b/webcal/src/main/java/com/onixbyte/icalendar/component/Calendar.java new file mode 100644 index 0000000..40e6eed --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/Calendar.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2023-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; + +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 java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * {@code WebCalendar} class represents a web calendar in iCalendar format. + *

+ * It allows users to create and customise calendar components and events and + * generate an iCalendar string containing all the calendar information. + *

+ * Usage Example: + *

+ * WebCalendar calendar = new WebCalendar()
+ *         .setName("My Web Calendar")
+ *         .setCompanyName("CodeCrafters Inc.")
+ *         .setProductName("WebCal")
+ *         .setDomainName("codecrafters.org.cn")
+ *         .setMethod("PUBLISH")
+ *         .addEvent(event1)
+ *         .addEvent(event2);
+ * String iCalendarString = calendar.resolve();
+ * 
+ *

+ * The {@code WebCalendar} class is designed to generate an iCalendar string + * conforming to the iCalendar specification, which can be used to share + * calendar data with other calendar applications or services. + * + * @author Zihlu Wang + * @version 1.1.0 + * @since 1.0.0 + */ +public final class Calendar { + + private static final String COMPONENT_NAME = "VCALENDAR"; + + /** + * This property are OPTIONAL, but MUST NOT occur more than once. + */ + private CalendarScale scale; + + /** + * This property are OPTIONAL, but MUST NOT occur more than once. + */ + private Method method; + + /** + * This property are REQUIRED, but MUST NOT occur more than once. + */ + private ProductIdentifier productIdentifier; + + /** + * This property are REQUIRED, but MUST NOT occur more than once. + */ + private final Version version = Version.VERSION_2_0; + + private String calendarName; + + private final List components = new ArrayList<>(); + + /** + * Generate and resolve the iCalendar string for the web calendar. + * + * @return the resolved iCalendar string + */ + public String resolve() { + var calendarBuilder = new StringBuilder(); + calendarBuilder.append("BEGIN:").append(COMPONENT_NAME).append('\n'); + + calendarBuilder.append(version.resolve()).append('\n'); + calendarBuilder.append(productIdentifier.resolve()).append('\n'); + calendarBuilder.append("X-WR-CALNAME:").append(calendarName).append('\n'); + + Optional.ofNullable(scale) + .ifPresent((_scale) -> calendarBuilder.append(_scale.resolve()).append('\n')); + Optional.ofNullable(method) + .ifPresent((_method) -> calendarBuilder.append(_method.resolve()).append('\n')); + + if (!components.isEmpty()) { + for (var component : components) { + calendarBuilder.append(component.resolve()).append('\n'); + } + } + + calendarBuilder.append("END:").append(COMPONENT_NAME).append('\n'); + return calendarBuilder.toString(); + } + +} + diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/CalendarComponent.java b/webcal/src/main/java/com/onixbyte/icalendar/component/CalendarComponent.java new file mode 100644 index 0000000..f3c8610 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/CalendarComponent.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2023 CodeCraftersCN. + * + * 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; + +/** + * 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. + * + * @author Zihlu Wang + * @version 1.1.0 + * @since 1.0.0 + */ +public abstract class CalendarComponent { + + public abstract String resolve(); + +} + diff --git a/webcal/src/main/java/com/onixbyte/icalendar/component/Event.java b/webcal/src/main/java/com/onixbyte/icalendar/component/Event.java new file mode 100644 index 0000000..3ef6848 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/component/Event.java @@ -0,0 +1,23 @@ +package com.onixbyte.icalendar.component; + +import com.onixbyte.icalendar.property.component.DateTimeStamp; +import com.onixbyte.icalendar.property.component.UniqueIdentifier; + +/** + * Event + * + * @author Zihlu WANG + */ +public class Event extends CalendarComponent { + + private DateTimeStamp dtStamp; + + private UniqueIdentifier uid; + + + + @Override + public String resolve() { + return ""; + } +} diff --git a/webcal/src/main/java/com/onixbyte/webcal/config/Formatters.java b/webcal/src/main/java/com/onixbyte/icalendar/config/Formatters.java similarity index 97% rename from webcal/src/main/java/com/onixbyte/webcal/config/Formatters.java rename to webcal/src/main/java/com/onixbyte/icalendar/config/Formatters.java index 89c1d31..4668723 100644 --- a/webcal/src/main/java/com/onixbyte/webcal/config/Formatters.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/config/Formatters.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package com.onixbyte.webcal.config; +package com.onixbyte.icalendar.config; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; diff --git a/webcal/src/main/java/com/onixbyte/webcal/config/package-info.java b/webcal/src/main/java/com/onixbyte/icalendar/config/package-info.java similarity index 90% rename from webcal/src/main/java/com/onixbyte/webcal/config/package-info.java rename to webcal/src/main/java/com/onixbyte/icalendar/config/package-info.java index de753b5..f02aab7 100644 --- a/webcal/src/main/java/com/onixbyte/webcal/config/package-info.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/config/package-info.java @@ -23,11 +23,11 @@ *

The classes in this package include:

* * * @since 1.0.0 */ -package com.onixbyte.webcal.config; \ No newline at end of file +package com.onixbyte.icalendar.config; \ No newline at end of file diff --git a/webcal/src/main/java/com/onixbyte/icalendar/constant/CalendarUserType.java b/webcal/src/main/java/com/onixbyte/icalendar/constant/CalendarUserType.java new file mode 100644 index 0000000..5b9b554 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/constant/CalendarUserType.java @@ -0,0 +1,16 @@ +package com.onixbyte.icalendar.constant; + +public enum CalendarUserType { + + INDIVIDUAL, + GROUP, + RESOURCE, + ROOM, + UNKNOWN, + ; + + @Override + public String toString() { + return name(); + } +} diff --git a/webcal/src/main/java/com/onixbyte/icalendar/constant/Classification.java b/webcal/src/main/java/com/onixbyte/icalendar/constant/Classification.java new file mode 100644 index 0000000..3828e94 --- /dev/null +++ b/webcal/src/main/java/com/onixbyte/icalendar/constant/Classification.java @@ -0,0 +1,36 @@ +package com.onixbyte.icalendar.constant; + +/** + * This property defines the access classification for a calendar component. + *

+ * The property can be specified once in a {@link CalendarEvent CalEvent}, {@link + * com.onixbyte.icalendar.impl.CalTodo CalTodo}, or {@link com.onixbyte.icalendar.impl.CalJournal CalJournal} + * calendar properties. + */ +public enum Classification { + + /** + * Public events mean that anyone can view and access their detailed information. These events are typically used + * in public calendars such as holiday calendars or company-wide event calendars. For public events, anyone with + * access to the calendar can see all the event details. + */ + PUBLIC, + /** + * Private events mean that only invited or specifically authorized individuals can view and access their detailed + * information. Private events are visible to the owner of the calendar but not to others. This classification is + * commonly used for personal appointments, private meetings, etc. + */ + PRIVATE, + /** + * Confidential events have detailed information that is not visible to anyone, including the owner of the calendar. + * Only individuals who have been granted specific permissions can access the detailed information of confidential + * events. This classification is typically used for sensitive business meetings, personal privacy matters, etc. + */ + CONFIDENTIAL, + ; + + @Override + public String toString() { + return name(); + } +} diff --git a/webcal/src/main/java/com/onixbyte/webcal/package-info.java b/webcal/src/main/java/com/onixbyte/icalendar/package-info.java similarity index 84% rename from webcal/src/main/java/com/onixbyte/webcal/package-info.java rename to webcal/src/main/java/com/onixbyte/icalendar/package-info.java index c15787d..3f87d13 100644 --- a/webcal/src/main/java/com/onixbyte/webcal/package-info.java +++ b/webcal/src/main/java/com/onixbyte/icalendar/package-info.java @@ -23,16 +23,16 @@ * The main classes and modules in this package include: *