Skip to content

Commit 77cc934

Browse files
committed
refactor: refactor the iCalendar tools
BREAKING CHANGES: The java classes just created, but not implemented yet, DO NOT USE THIS COMMIT TO BUILD! [skip ci]
1 parent 163d8d3 commit 77cc934

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+921
-769
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.onixbyte.icalendar;
2+
3+
/**
4+
* CalendarUtil
5+
*
6+
* @author Zihlu WANG
7+
*/
8+
public final class CalendarUtil {
9+
10+
private CalendarUtil() {
11+
}
12+
13+
14+
15+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (C) 2023-2024 OnixByte.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
*
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.onixbyte.icalendar.component;
19+
20+
import com.onixbyte.icalendar.property.calendar.CalendarScale;
21+
import com.onixbyte.icalendar.property.calendar.Method;
22+
import com.onixbyte.icalendar.property.calendar.ProductIdentifier;
23+
import com.onixbyte.icalendar.property.calendar.Version;
24+
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
import java.util.Optional;
28+
29+
/**
30+
* {@code WebCalendar} class represents a web calendar in iCalendar format.
31+
* <p>
32+
* It allows users to create and customise calendar components and events and
33+
* generate an <b>iCalendar</b> string containing all the calendar information.
34+
* <p>
35+
* Usage Example:
36+
* <pre>
37+
* WebCalendar calendar = new WebCalendar()
38+
* .setName("My Web Calendar")
39+
* .setCompanyName("CodeCrafters Inc.")
40+
* .setProductName("WebCal")
41+
* .setDomainName("codecrafters.org.cn")
42+
* .setMethod("PUBLISH")
43+
* .addEvent(event1)
44+
* .addEvent(event2);
45+
* String iCalendarString = calendar.resolve();
46+
* </pre>
47+
* <p>
48+
* The {@code WebCalendar} class is designed to generate an iCalendar string
49+
* conforming to the iCalendar specification, which can be used to share
50+
* calendar data with other calendar applications or services.
51+
*
52+
* @author Zihlu Wang
53+
* @version 1.1.0
54+
* @since 1.0.0
55+
*/
56+
public final class Calendar {
57+
58+
private static final String COMPONENT_NAME = "VCALENDAR";
59+
60+
/**
61+
* This property are OPTIONAL, but MUST NOT occur more than once.
62+
*/
63+
private CalendarScale scale;
64+
65+
/**
66+
* This property are OPTIONAL, but MUST NOT occur more than once.
67+
*/
68+
private Method method;
69+
70+
/**
71+
* This property are REQUIRED, but MUST NOT occur more than once.
72+
*/
73+
private ProductIdentifier productIdentifier;
74+
75+
/**
76+
* This property are REQUIRED, but MUST NOT occur more than once.
77+
*/
78+
private final Version version = Version.VERSION_2_0;
79+
80+
private String calendarName;
81+
82+
private final List<CalendarComponent> components = new ArrayList<>();
83+
84+
/**
85+
* Generate and resolve the iCalendar string for the web calendar.
86+
*
87+
* @return the resolved iCalendar string
88+
*/
89+
public String resolve() {
90+
var calendarBuilder = new StringBuilder();
91+
calendarBuilder.append("BEGIN:").append(COMPONENT_NAME).append('\n');
92+
93+
calendarBuilder.append(version.resolve()).append('\n');
94+
calendarBuilder.append(productIdentifier.resolve()).append('\n');
95+
calendarBuilder.append("X-WR-CALNAME:").append(calendarName).append('\n');
96+
97+
Optional.ofNullable(scale)
98+
.ifPresent((_scale) -> calendarBuilder.append(_scale.resolve()).append('\n'));
99+
Optional.ofNullable(method)
100+
.ifPresent((_method) -> calendarBuilder.append(_method.resolve()).append('\n'));
101+
102+
if (!components.isEmpty()) {
103+
for (var component : components) {
104+
calendarBuilder.append(component.resolve()).append('\n');
105+
}
106+
}
107+
108+
calendarBuilder.append("END:").append(COMPONENT_NAME).append('\n');
109+
return calendarBuilder.toString();
110+
}
111+
112+
}
113+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2023 CodeCraftersCN.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
*
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.onixbyte.icalendar.component;
19+
20+
/**
21+
* The abstract sealed class {@code WebCalendarNode} represents a node in a web calendar, such as an <a href="">event</a>, a to-do
22+
* item, or an alarm. It provides common properties and methods for all calendar components and events.
23+
* <p>
24+
* Subclasses of {@code WebCalendarNode} should implement the {@link #resolve()} method to generate the corresponding iCalendar content for the specific calendar component or event.
25+
*
26+
* @author Zihlu Wang
27+
* @version 1.1.0
28+
* @since 1.0.0
29+
*/
30+
public abstract class CalendarComponent {
31+
32+
public abstract String resolve();
33+
34+
}
35+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.onixbyte.icalendar.component;
2+
3+
import com.onixbyte.icalendar.property.component.DateTimeStamp;
4+
import com.onixbyte.icalendar.property.component.UniqueIdentifier;
5+
6+
/**
7+
* Event
8+
*
9+
* @author Zihlu WANG
10+
*/
11+
public class Event extends CalendarComponent {
12+
13+
private DateTimeStamp dtStamp;
14+
15+
private UniqueIdentifier uid;
16+
17+
18+
19+
@Override
20+
public String resolve() {
21+
return "";
22+
}
23+
}

webcal/src/main/java/com/onixbyte/webcal/config/Formatters.java renamed to webcal/src/main/java/com/onixbyte/icalendar/config/Formatters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
package com.onixbyte.webcal.config;
18+
package com.onixbyte.icalendar.config;
1919

2020
import java.time.ZoneOffset;
2121
import java.time.format.DateTimeFormatter;

webcal/src/main/java/com/onixbyte/webcal/config/package-info.java renamed to webcal/src/main/java/com/onixbyte/icalendar/config/package-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
* <p>The classes in this package include:</p>
2424
* <ul>
2525
* <li>
26-
* {@link com.onixbyte.webcal.config.Classification}: An enum
26+
* {@link com.onixbyte.icalendar.config.Classification}: An enum
2727
* representing the classification of events in the web calendar.
2828
* </li>
2929
* </ul>
3030
*
3131
* @since 1.0.0
3232
*/
33-
package com.onixbyte.webcal.config;
33+
package com.onixbyte.icalendar.config;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.onixbyte.icalendar.constant;
2+
3+
public enum CalendarUserType {
4+
5+
INDIVIDUAL,
6+
GROUP,
7+
RESOURCE,
8+
ROOM,
9+
UNKNOWN,
10+
;
11+
12+
@Override
13+
public String toString() {
14+
return name();
15+
}
16+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.onixbyte.icalendar.constant;
2+
3+
/**
4+
* This property defines the access classification for a calendar component.
5+
* <p>
6+
* The property can be specified once in a {@link CalendarEvent CalEvent}, {@link
7+
* com.onixbyte.icalendar.impl.CalTodo CalTodo}, or {@link com.onixbyte.icalendar.impl.CalJournal CalJournal}
8+
* calendar properties.
9+
*/
10+
public enum Classification {
11+
12+
/**
13+
* Public events mean that anyone can view and access their detailed information. These events are typically used
14+
* in public calendars such as holiday calendars or company-wide event calendars. For public events, anyone with
15+
* access to the calendar can see all the event details.
16+
*/
17+
PUBLIC,
18+
/**
19+
* Private events mean that only invited or specifically authorized individuals can view and access their detailed
20+
* information. Private events are visible to the owner of the calendar but not to others. This classification is
21+
* commonly used for personal appointments, private meetings, etc.
22+
*/
23+
PRIVATE,
24+
/**
25+
* Confidential events have detailed information that is not visible to anyone, including the owner of the calendar.
26+
* Only individuals who have been granted specific permissions can access the detailed information of confidential
27+
* events. This classification is typically used for sensitive business meetings, personal privacy matters, etc.
28+
*/
29+
CONFIDENTIAL,
30+
;
31+
32+
@Override
33+
public String toString() {
34+
return name();
35+
}
36+
}

webcal/src/main/java/com/onixbyte/webcal/package-info.java renamed to webcal/src/main/java/com/onixbyte/icalendar/package-info.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323
* The main classes and modules in this package include:
2424
* <ul>
2525
* <li>
26-
* {@link com.onixbyte.webcal.WebCalendar}: A class for
26+
* {@link com.onixbyte.icalendar.component.Calendar}: A class for
2727
* generating web calendars with customisable settings and events.
2828
* </li>
2929
* <li>
30-
* {@link com.onixbyte.webcal.impl.WebCalendarEvent}: A class
30+
* {@link com.onixbyte.icalendar.impl.CalendarEvent}: A class
3131
* representing a single event in a web calendar with various
3232
* attributes and options.
3333
* </li>
3434
* <li>
35-
* {@link com.onixbyte.webcal.WebCalendarNode}: An abstract
35+
* {@link com.onixbyte.icalendar.component.CalendarComponent}: An abstract
3636
* class serving as the base class for web calendar nodes, providing
3737
* common attributes and functionality for events.
3838
* </li>
3939
* </ul>
4040
*
4141
* @since 1.0.0
4242
*/
43-
package com.onixbyte.webcal;
43+
package com.onixbyte.icalendar;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.onixbyte.icalendar.property;
2+
3+
public interface Prop {
4+
5+
String resolve();
6+
7+
}

0 commit comments

Comments
 (0)