Skip to content

Commit 75e858c

Browse files
committed
feat: added some component properties
1 parent b42ab4f commit 75e858c

Some content is hidden

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

55 files changed

+1089
-162
lines changed

webcal/src/main/java/com/onixbyte/icalendar/CalendarUtil.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717

1818
package com.onixbyte.icalendar;
1919

20+
import com.onixbyte.icalendar.property.parameter.AlternateRepresentation;
21+
import com.onixbyte.icalendar.property.parameter.Language;
22+
23+
import java.time.format.DateTimeFormatter;
24+
import java.util.Objects;
25+
import java.util.Optional;
26+
import java.util.function.Supplier;
27+
2028
/**
2129
* CalendarUtil
2230
*

webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Method.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.onixbyte.icalendar.calendar.property;
1919

20-
public enum Method implements CalendarProperty {
20+
public enum Method implements Property {
2121

2222
PUBLISH("PUBLISH"),
2323
REQUEST("REQUEST"),

webcal/src/main/java/com/onixbyte/icalendar/calendar/property/ProductIdentifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* @author Zihlu WANG
2424
*/
25-
public final class ProductIdentifier implements CalendarProperty {
25+
public final class ProductIdentifier implements Property {
2626

2727
private final String value;
2828

webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarProperty.java renamed to webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Property.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.onixbyte.icalendar.calendar.property;
1919

20-
import com.onixbyte.icalendar.property.CalendarResolvable;
20+
import com.onixbyte.icalendar.property.Resolvable;
2121

22-
public interface CalendarProperty extends CalendarResolvable {
22+
public interface Property extends Resolvable {
2323
}

webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarScale.java renamed to webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Scale.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
package com.onixbyte.icalendar.calendar.property;
1919

2020
/**
21-
* CalendarScale
21+
* Scale
2222
*
2323
* @author Zihlu WANG
2424
*/
25-
public enum CalendarScale implements CalendarProperty {
25+
public enum Scale implements Property {
2626

2727
GREGORIAN,
2828
;

webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* @author Zihlu WANG
2424
*/
25-
public enum Version implements CalendarProperty {
25+
public enum Version implements Property {
2626

2727
VERSION_2_0,
2828
;

webcal/src/main/java/com/onixbyte/icalendar/component/Calendar.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.onixbyte.icalendar.component;
1919

20-
import com.onixbyte.icalendar.calendar.property.CalendarScale;
20+
import com.onixbyte.icalendar.calendar.property.Scale;
2121
import com.onixbyte.icalendar.calendar.property.Method;
2222
import com.onixbyte.icalendar.calendar.property.ProductIdentifier;
2323
import com.onixbyte.icalendar.calendar.property.Version;
@@ -60,7 +60,7 @@ public final class Calendar {
6060
/**
6161
* This property are OPTIONAL, but MUST NOT occur more than once.
6262
*/
63-
private CalendarScale scale;
63+
private Scale scale;
6464

6565
/**
6666
* This property are OPTIONAL, but MUST NOT occur more than once.

webcal/src/main/java/com/onixbyte/icalendar/component/property/Attachment.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,35 @@
2020
import com.onixbyte.icalendar.property.parameter.FormatType;
2121

2222
import java.net.URI;
23+
import java.util.Objects;
2324
import java.util.Optional;
2425

2526
/**
2627
* Attachment
2728
*
2829
* @author Zihlu WANG
2930
*/
30-
public final class Attachment implements ComponentProperty {
31+
public record Attachment(FormatType formatType,
32+
URI uri,
33+
String content) implements ComponentProperty {
3134

32-
private FormatType formatType;
33-
34-
private URI uri;
35+
private static final String PROPERTY_NAME = "ATTACH";
3536

3637
@Override
3738
public String resolve() {
38-
final var attachmentBuilder = new StringBuilder("ATTACH");
39+
if (Objects.isNull(uri) && (Objects.isNull(content) || content.isBlank())) {
40+
return null;
41+
}
42+
43+
final var attachmentBuilder = new StringBuilder(PROPERTY_NAME);
3944

4045
Optional.ofNullable(formatType)
41-
.ifPresent((fmtType) -> attachmentBuilder.append(fmtType.resolve()));
46+
.ifPresent((fmtType) -> attachmentBuilder.append(";").append(fmtType.resolve()));
4247

43-
attachmentBuilder.append(":")
44-
.append(uri.toString());
48+
Optional.ofNullable(uri).ifPresentOrElse(
49+
(_uri) -> attachmentBuilder.append(":").append(_uri),
50+
() -> attachmentBuilder.append(";ENCODING=BASE64;VALUE=BINARY:").append(content));
51+
attachmentBuilder.append("\n");
4552

4653
return attachmentBuilder.toString();
4754
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2024-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.property;
19+
20+
import java.time.Duration;
21+
22+
public record CalendarDuration(Duration duration) implements ComponentProperty {
23+
24+
private static final String PROPERTY_NAME = "DURATION";
25+
26+
@Override
27+
public String resolve() {
28+
return PROPERTY_NAME + ":" + duration.toString() + "\n";
29+
}
30+
}

webcal/src/main/java/com/onixbyte/icalendar/component/property/Categories.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,49 @@
1717

1818
package com.onixbyte.icalendar.component.property;
1919

20-
public class Categories {
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
23+
public final class Categories implements ComponentProperty {
24+
25+
private static final String PROPERTY_NAME = "CATEGORIES";
26+
27+
private final List<String> value;
28+
29+
private Categories(List<String> value) {
30+
this.value = value;
31+
}
32+
33+
public static class Builder {
34+
private List<String> categories;
35+
36+
private Builder() {
37+
categories = new ArrayList<>();
38+
}
39+
40+
public Builder addCategory(String category) {
41+
if (!categories.contains(category)) {
42+
categories.add(category);
43+
}
44+
return this;
45+
}
46+
47+
public Builder addCategories(List<String> categories) {
48+
categories.forEach(this::addCategory);
49+
return this;
50+
}
51+
52+
public Categories build() {
53+
return new Categories(categories);
54+
}
55+
}
56+
57+
public static Builder builder() {
58+
return new Builder();
59+
}
60+
61+
@Override
62+
public String resolve() {
63+
return PROPERTY_NAME + ":" + String.join(",", value) + "\n";
64+
}
2165
}

0 commit comments

Comments
 (0)