feat: added some component properties
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.onixbyte.icalendar.calendar.property;
|
||||
|
||||
public enum Method implements CalendarProperty {
|
||||
public enum Method implements Property {
|
||||
|
||||
PUBLISH("PUBLISH"),
|
||||
REQUEST("REQUEST"),
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
}
|
||||
+2
-2
@@ -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,
|
||||
;
|
||||
@@ -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,
|
||||
;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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<String> value;
|
||||
|
||||
private Categories(List<String> value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private List<String> categories;
|
||||
|
||||
private Builder() {
|
||||
categories = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Builder addCategory(String category) {
|
||||
if (!categories.contains(category)) {
|
||||
categories.add(category);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addCategories(List<String> 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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -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 {
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<ValueDataType> 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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.
|
||||
* <p>
|
||||
* The value MUST be specified in the UTC time format.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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 {
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Period> 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<Period> 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<Period> freeBusyValue) {
|
||||
this.freeBusyType = freeBusyType;
|
||||
this.freeBusyValue = freeBusyValue;
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
@@ -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<String> value;
|
||||
|
||||
private Resources(AlternateRepresentation altRep, Language language, List<String> value) {
|
||||
this.altRep = altRep;
|
||||
this.language = language;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private List<String> 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<String> 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));
|
||||
}
|
||||
}
|
||||
@@ -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<Status> eventStatus() {
|
||||
return List.of(TENTATIVE, CONFIRMED, CANCELLED);
|
||||
}
|
||||
|
||||
public static List<Status> todoStatus() {
|
||||
return List.of(NEEDS_ACTION, COMPLETED, IN_PROGRESS, CANCELLED);
|
||||
}
|
||||
|
||||
public static List<Status> journalStatus() {
|
||||
return List.of(DRAFT, FINAL, CANCELLED);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<String> valueSupplier) {
|
||||
return composeResolution(propertyName, altRep, language, valueSupplier.get());
|
||||
}
|
||||
|
||||
}
|
||||
+1
-36
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.onixbyte.icalendar.property;
|
||||
|
||||
public interface CalendarResolvable {
|
||||
public interface Resolvable {
|
||||
|
||||
String resolve();
|
||||
|
||||
+2
-2
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -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 {
|
||||
|
||||
@@ -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 + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<CalendarUserAddress> 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());
|
||||
}
|
||||
|
||||
@@ -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<CalendarUserAddress> 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()) + "\"";
|
||||
}
|
||||
|
||||
+2
-2
@@ -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 + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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<CalendarUserAddress> 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());
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
}
|
||||
|
||||
+2
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
+4
-6
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user