Merge pull request #17 from CodeCraftersCN/dev/v1.1.1
Upgrade to v1.1.1
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.org.codecrafters</groupId>
|
<groupId>cn.org.codecrafters</groupId>
|
||||||
<artifactId>jdevkit</artifactId>
|
<artifactId>jdevkit</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.1.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>devkit-core</artifactId>
|
<artifactId>devkit-core</artifactId>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.org.codecrafters</groupId>
|
<groupId>cn.org.codecrafters</groupId>
|
||||||
<artifactId>jdevkit</artifactId>
|
<artifactId>jdevkit</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.1.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>devkit-utils</artifactId>
|
<artifactId>devkit-utils</artifactId>
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.org.codecrafters</groupId>
|
<groupId>cn.org.codecrafters</groupId>
|
||||||
<artifactId>jdevkit</artifactId>
|
<artifactId>jdevkit</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.1.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>guid</artifactId>
|
<artifactId>guid</artifactId>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
<groupId>cn.org.codecrafters</groupId>
|
<groupId>cn.org.codecrafters</groupId>
|
||||||
<artifactId>jdevkit</artifactId>
|
<artifactId>jdevkit</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.1.1</version>
|
||||||
<inceptionYear>2023</inceptionYear>
|
<inceptionYear>2023</inceptionYear>
|
||||||
|
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.org.codecrafters</groupId>
|
<groupId>cn.org.codecrafters</groupId>
|
||||||
<artifactId>jdevkit</artifactId>
|
<artifactId>jdevkit</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.1.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>property-guard-spring-boot-starter</artifactId>
|
<artifactId>property-guard-spring-boot-starter</artifactId>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.org.codecrafters</groupId>
|
<groupId>cn.org.codecrafters</groupId>
|
||||||
<artifactId>jdevkit</artifactId>
|
<artifactId>jdevkit</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.1.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>simple-jwt-authzero</artifactId>
|
<artifactId>simple-jwt-authzero</artifactId>
|
||||||
|
|||||||
+2
-7
@@ -45,11 +45,6 @@ import java.util.*;
|
|||||||
* resolver provides functionality to create, extract, verify, and renew JWT
|
* resolver provides functionality to create, extract, verify, and renew JWT
|
||||||
* tokens using various algorithms and custom payload data.
|
* tokens using various algorithms and custom payload data.
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Dependencies:</b>
|
|
||||||
* This implementation relies on the {@code com.auth0:java-jwt} library. Please
|
|
||||||
* ensure you have added this library as a dependency to your project before
|
|
||||||
* using this resolver.
|
|
||||||
* <p>
|
|
||||||
* <b>Usage:</b>
|
* <b>Usage:</b>
|
||||||
* To use the {@code AuthzeroTokenResolver}, first, create an instance of this
|
* To use the {@code AuthzeroTokenResolver}, first, create an instance of this
|
||||||
* class:
|
* class:
|
||||||
@@ -87,7 +82,7 @@ import java.util.*;
|
|||||||
* correctly configured in your project's dependencies.
|
* correctly configured in your project's dependencies.
|
||||||
*
|
*
|
||||||
* @author Zihlu Wang
|
* @author Zihlu Wang
|
||||||
* @version 1.1.0
|
* @version 1.1.1
|
||||||
* @see GuidCreator
|
* @see GuidCreator
|
||||||
* @see Algorithm
|
* @see Algorithm
|
||||||
* @see JWTVerifier
|
* @see JWTVerifier
|
||||||
@@ -279,7 +274,7 @@ public class AuthzeroTokenResolver implements TokenResolver<DecodedJWT> {
|
|||||||
builder.withClaim(name, v);
|
builder.withClaim(name, v);
|
||||||
} else {
|
} else {
|
||||||
log.warn("""
|
log.warn("""
|
||||||
Unable to determine the type of field {}, converting it to a string now.""", name);
|
Unable to determine the type of field {}, we will handle it as a String.""", name);
|
||||||
builder.withClaim(name, value.toString());
|
builder.withClaim(name, value.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+10
-9
@@ -35,19 +35,20 @@ import java.util.function.Function;
|
|||||||
* the {@link AuthzeroTokenResolver}.
|
* the {@link AuthzeroTokenResolver}.
|
||||||
* <p>
|
* <p>
|
||||||
* This configuration is used to establish the mapping between the standard
|
* This configuration is used to establish the mapping between the standard
|
||||||
* {@link TokenAlgorithm} defined within the {@link AuthzeroTokenResolver}
|
* {@link TokenAlgorithm} defined in the
|
||||||
* facade and the specific algorithms used by the {@code com.auth0:java-jwt}
|
* {@code cn.org.codecrafters:simple-jwt-facade} and the specific algorithms
|
||||||
* library, which is the underlying library used by {@link
|
* used by the {@code com.auth0:java-jwt} library, which is the underlying
|
||||||
* AuthzeroTokenResolver} to handle JSON Web Tokens (JWTs).
|
* library used by {@link AuthzeroTokenResolver} to handle JSON Web Tokens
|
||||||
|
* (JWTs).
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Algorithm Mapping:</b>
|
* <b>Algorithm Mapping:</b>
|
||||||
* The {@code AuthzeroTokenResolverConfig} allows specifying the relationship
|
* The {@code AuthzeroTokenResolverConfig} allows specifying the relationships
|
||||||
* between the standard {@link TokenAlgorithm} instances supported by
|
* between the standard {@link TokenAlgorithm} instances supported by
|
||||||
* {@link AuthzeroTokenResolver} and the corresponding algorithms used by the
|
* {@link AuthzeroTokenResolver} and the corresponding algorithms used by the
|
||||||
* {@code com.auth0:java-jwt} library. The mapping is achieved using a Map,
|
* {@code com.auth0:java-jwt} library. The mapping is achieved using a Map,
|
||||||
* where the keys are the standard TokenAlgorithm instances, and the values
|
* where the keys are the standard {@link TokenAlgorithm} instances, and the
|
||||||
* represent the algorithm functions used by Auth0 Java JWT library for each
|
* values represent the algorithm functions used by {@code com.auth0:java-jwt}
|
||||||
* corresponding key.
|
* library for each corresponding key.
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Note:</b>
|
* <b>Note:</b>
|
||||||
* The provided algorithm mapping should be consistent with the actual
|
* The provided algorithm mapping should be consistent with the actual
|
||||||
@@ -56,7 +57,7 @@ import java.util.function.Function;
|
|||||||
* validation and processing within the {@link AuthzeroTokenResolver}.
|
* validation and processing within the {@link AuthzeroTokenResolver}.
|
||||||
*
|
*
|
||||||
* @author Zihlu Wang
|
* @author Zihlu Wang
|
||||||
* @version 1.1.0
|
* @version 1.1.1
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public final class AuthzeroTokenResolverConfig implements TokenResolverConfig<Function<String, Algorithm>> {
|
public final class AuthzeroTokenResolverConfig implements TokenResolverConfig<Function<String, Algorithm>> {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.org.codecrafters</groupId>
|
<groupId>cn.org.codecrafters</groupId>
|
||||||
<artifactId>jdevkit</artifactId>
|
<artifactId>jdevkit</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.1.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>simple-jwt-facade</artifactId>
|
<artifactId>simple-jwt-facade</artifactId>
|
||||||
|
|||||||
+2
-2
@@ -21,8 +21,8 @@ import cn.org.codecrafters.simplejwt.TokenResolver;
|
|||||||
import cn.org.codecrafters.simplejwt.constants.TokenAlgorithm;
|
import cn.org.codecrafters.simplejwt.constants.TokenAlgorithm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@code TokenResolverConfig} provides a mechanism to configure a
|
* The {@code TokenResolverConfig} provides a mechanism to configure an
|
||||||
* {@link TokenResolver} with algorithm functions.
|
* implementation of {@link TokenResolver} with algorithm functions.
|
||||||
* <p>
|
* <p>
|
||||||
* This generic interface is used to define the configuration details for a
|
* This generic interface is used to define the configuration details for a
|
||||||
* {@link TokenResolver} that utilizes algorithm functions. The interface
|
* {@link TokenResolver} that utilizes algorithm functions. The interface
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.org.codecrafters</groupId>
|
<groupId>cn.org.codecrafters</groupId>
|
||||||
<artifactId>jdevkit</artifactId>
|
<artifactId>jdevkit</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.1.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>simple-jwt-jjwt</artifactId>
|
<artifactId>simple-jwt-jjwt</artifactId>
|
||||||
|
|||||||
+5
-12
@@ -40,6 +40,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,11 +50,6 @@ import java.util.UUID;
|
|||||||
* This resolver provides functionality to create, extract, verify, and renew
|
* This resolver provides functionality to create, extract, verify, and renew
|
||||||
* JWT tokens using various algorithms and custom payload data.
|
* JWT tokens using various algorithms and custom payload data.
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Dependencies:</b>
|
|
||||||
* This implementation relies on the {@code io.jsonwebtoken:jjwt} library. Please
|
|
||||||
* ensure you have added this library as a dependency to your project before
|
|
||||||
* using this resolver.
|
|
||||||
* <p>
|
|
||||||
* <b>Usage:</b>
|
* <b>Usage:</b>
|
||||||
* To use the {@code JjwtTokenResolver}, first, create an instance of this
|
* To use the {@code JjwtTokenResolver}, first, create an instance of this
|
||||||
* class:
|
* class:
|
||||||
@@ -113,7 +109,7 @@ public class JjwtTokenResolver implements TokenResolver<Jws<Claims>> {
|
|||||||
private final JjwtTokenResolverConfig config = JjwtTokenResolverConfig.getInstance();
|
private final JjwtTokenResolverConfig config = JjwtTokenResolverConfig.getInstance();
|
||||||
|
|
||||||
public JjwtTokenResolver(GuidCreator<?> jtiCreator, TokenAlgorithm algorithm, String issuer, String secret) {
|
public JjwtTokenResolver(GuidCreator<?> jtiCreator, TokenAlgorithm algorithm, String issuer, String secret) {
|
||||||
if (secret == null || secret.isBlank()) {
|
if (Objects.isNull(secret) || secret.isBlank()) {
|
||||||
throw new IllegalArgumentException("A secret is required to build a JSON Web Token.");
|
throw new IllegalArgumentException("A secret is required to build a JSON Web Token.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,8 +205,7 @@ public class JjwtTokenResolver implements TokenResolver<Jws<Claims>> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String createToken(Duration expireAfter, String audience, String subject) {
|
public String createToken(Duration expireAfter, String audience, String subject) {
|
||||||
var now = LocalDateTime.now();
|
return buildToken(expireAfter, audience, subject, LocalDateTime.now(), null);
|
||||||
return buildToken(expireAfter, audience, subject, now, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -225,8 +220,7 @@ public class JjwtTokenResolver implements TokenResolver<Jws<Claims>> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String createToken(Duration expireAfter, String audience, String subject, Map<String, Object> payload) {
|
public String createToken(Duration expireAfter, String audience, String subject, Map<String, Object> payload) {
|
||||||
var now = LocalDateTime.now();
|
return buildToken(expireAfter, audience, subject, LocalDateTime.now(), payload);
|
||||||
return buildToken(expireAfter, audience, subject, now, payload);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -244,10 +238,9 @@ public class JjwtTokenResolver implements TokenResolver<Jws<Claims>> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T extends TokenPayload> String createToken(Duration expireAfter, String audience, String subject, T payload) {
|
public <T extends TokenPayload> String createToken(Duration expireAfter, String audience, String subject, T payload) {
|
||||||
var now = LocalDateTime.now();
|
|
||||||
try {
|
try {
|
||||||
var claims = MapUtil.objectToMap(payload);
|
var claims = MapUtil.objectToMap(payload);
|
||||||
return buildToken(expireAfter, audience, subject, now, claims);
|
return buildToken(expireAfter, audience, subject, LocalDateTime.now(), claims);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
log.error("An error occurs while accessing the fields of the object");
|
log.error("An error occurs while accessing the fields of the object");
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-11
@@ -28,19 +28,20 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@code JjwtTokenResolverConfig} class provides the configuration for the
|
* The {@code JjwtTokenResolverConfig} class provides the configuration for
|
||||||
* {@link JjwtTokenResolver}.
|
* the {@link JjwtTokenResolver}.
|
||||||
* <p>
|
* <p>
|
||||||
* This configuration class is used to establish the mapping between the
|
* This configuration is used to establish the mapping between the standard
|
||||||
* standard {@link TokenAlgorithm} defined within the
|
* {@link TokenAlgorithm} defined in the
|
||||||
* {@code JjwtTokenResolverConfig} and the specific algorithms used by the
|
* {@code cn.org.codecrafters:simple-jwt-facade} and the specific algorithms
|
||||||
* {@code io.jsonwebtoken:jjwt} library, which is the underlying library used
|
* used by the {@code io.jsonwebtoken:jjwt} library, which is the underlying
|
||||||
* by {@code JjwtTokenResolver} to handle JSON Web Tokens (JWTs).
|
* library used by {@link JjwtTokenResolver} to handle JSON Web Tokens
|
||||||
|
* (JWTs).
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Algorithm Mapping:</b>
|
* <b>Algorithm Mapping:</b>
|
||||||
* The {@code JjwtTokenResolverConfig} allows specifying the relationship
|
* The {@code JjwtTokenResolverConfig} allows specifying the relationships
|
||||||
* between the standard {@link TokenAlgorithm} instances supported by {@link
|
* between the standard {@link TokenAlgorithm} instances supported by
|
||||||
* JjwtTokenResolver} and the corresponding algorithms used by the
|
* {@link JjwtTokenResolver} and the corresponding algorithms used by the
|
||||||
* {@code io.jsonwebtoken:jjwt} library. The mapping is achieved using a Map,
|
* {@code io.jsonwebtoken:jjwt} library. The mapping is achieved using a Map,
|
||||||
* where the keys are the standard {@link TokenAlgorithm} instances, and the
|
* where the keys are the standard {@link TokenAlgorithm} instances, and the
|
||||||
* values represent the algorithm functions used by
|
* values represent the algorithm functions used by
|
||||||
@@ -53,7 +54,7 @@ import java.util.Map;
|
|||||||
* validation and processing within the {@link JjwtTokenResolver}.
|
* validation and processing within the {@link JjwtTokenResolver}.
|
||||||
*
|
*
|
||||||
* @author Zihlu Wang
|
* @author Zihlu Wang
|
||||||
* @version 1.1.0
|
* @version 1.1.1
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public final class JjwtTokenResolverConfig implements TokenResolverConfig<SignatureAlgorithm> {
|
public final class JjwtTokenResolverConfig implements TokenResolverConfig<SignatureAlgorithm> {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.org.codecrafters</groupId>
|
<groupId>cn.org.codecrafters</groupId>
|
||||||
<artifactId>jdevkit</artifactId>
|
<artifactId>jdevkit</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.1.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>simple-jwt-spring-boot-starter</artifactId>
|
<artifactId>simple-jwt-spring-boot-starter</artifactId>
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>cn.org.codecrafters</groupId>
|
<groupId>cn.org.codecrafters</groupId>
|
||||||
<artifactId>jdevkit</artifactId>
|
<artifactId>jdevkit</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.1.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>webcal</artifactId>
|
<artifactId>webcal</artifactId>
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package cn.org.codecrafters.webcal;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code WebCalendar} class represents a web calendar in iCalendar format.
|
* {@code WebCalendar} class represents a web calendar in iCalendar format.
|
||||||
@@ -189,18 +190,22 @@ public final class WebCalendar {
|
|||||||
* @return the resolved iCalendar string
|
* @return the resolved iCalendar string
|
||||||
*/
|
*/
|
||||||
public String resolve() {
|
public String resolve() {
|
||||||
var events = new StringBuilder();
|
var eventBuilder = new StringBuilder();
|
||||||
if (!nodes.isEmpty()) {
|
if (!nodes.isEmpty()) {
|
||||||
nodes.forEach(item ->
|
for (var node : nodes) {
|
||||||
events.append(item.setDomainName(domainName)
|
if (Objects.isNull(node.getDomainName()) || node.getDomainName().isBlank()) {
|
||||||
.resolve()));
|
node.setDomainName(this.domainName);
|
||||||
|
}
|
||||||
|
|
||||||
|
eventBuilder.append(node.resolve());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "BEGIN:" + TAG + "\n" +
|
return "BEGIN:" + TAG + "\n" +
|
||||||
"PRODID:-//" + companyName + "//" + productName + "//EN\n" +
|
"PRODID:-//" + companyName + "//" + productName + "//EN\n" +
|
||||||
"VERSION:" + version + "\n" +
|
"VERSION:" + version + "\n" +
|
||||||
"X-WR-CALNAME:" + name + "\n" +
|
"X-WR-CALNAME:" + name + "\n" +
|
||||||
events + "\n" +
|
eventBuilder + "\n" +
|
||||||
"END:" + TAG;
|
"END:" + TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,10 +18,12 @@
|
|||||||
package cn.org.codecrafters.webcal;
|
package cn.org.codecrafters.webcal;
|
||||||
|
|
||||||
import cn.org.codecrafters.webcal.config.Classification;
|
import cn.org.codecrafters.webcal.config.Classification;
|
||||||
|
import cn.org.codecrafters.webcal.config.Formatter;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.ZoneId;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -257,30 +259,34 @@ public final class WebCalendarEvent extends WebCalendarNode {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String resolve() {
|
public String resolve() {
|
||||||
return "\nBEGIN:" + TAG + "\n" +
|
var now = LocalDateTime.now().atZone(ZoneId.systemDefault());
|
||||||
"UID:" + Optional.ofNullable(uid).orElse(UUID.randomUUID().toString()) + "@" + domainName + "\n" +
|
return MessageFormat.format("""
|
||||||
Optional.ofNullable(summary).map((item) -> "SUMMARY:" + item + "\n").orElse("") +
|
BEGIN:{0}
|
||||||
"DTSTART" + Optional.ofNullable(timezone).map(item -> ";TZID=" + item).orElse("") + ":" + start.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + "\n" +
|
UID:{1}
|
||||||
|
DTSTAMP:{2}
|
||||||
|
DTSTART:{3}
|
||||||
|
DURATION:PT{6}S
|
||||||
|
{4}{5}{7}{8}{9}{10}{11}{12}
|
||||||
|
END:{0}""",
|
||||||
|
TAG, // 0 - tag
|
||||||
|
Optional.ofNullable(uid).orElse(UUID.randomUUID().toString()) + "@" + domainName, // 1 - uid
|
||||||
|
now.format(Formatter.getUtcDatetimeFormatter()), // 2 - dtstamp
|
||||||
|
start.atZone(ZoneId.systemDefault()).format(Formatter.getUtcDatetimeFormatter()), // 3 - start time
|
||||||
|
Optional.ofNullable(summary).map((item) -> "\nSUMMARY:" + item).orElse(""), // 4 - summary
|
||||||
Optional.ofNullable(categories)
|
Optional.ofNullable(categories)
|
||||||
.map((item) -> {
|
.map((item) -> !item.isEmpty() ? "\nCATEGORIES:" + resolveCategories() : null).orElse(""), // 5 - categories
|
||||||
if (!item.isEmpty()) {
|
|
||||||
return "CATEGORIES:" + resolveCategories() + "\n";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}).orElse("") +
|
|
||||||
Optional.ofNullable(duration)
|
Optional.ofNullable(duration)
|
||||||
.map((item) -> "DURATION:PT" + item.getSeconds() + "S\n").orElse("") +
|
.map((_duration) -> String.valueOf(_duration.getSeconds()))
|
||||||
Optional.ofNullable(end)
|
.orElse(Optional.ofNullable(end)
|
||||||
.map((item) -> "DTEND" + Optional.ofNullable(timezone).map(tz -> ";TZID=" + tz).orElse("") + ":" +
|
.map((_end) -> String.valueOf(Duration.between(_end, start).getSeconds()))
|
||||||
end.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + "\n").orElse("") +
|
.orElse("0")), // 6 - duration
|
||||||
Optional.ofNullable(classification)
|
Optional.ofNullable(classification).map((_classification) -> "\nCLASS:" + _classification + "\n").orElse(""), /* 7 - classification */
|
||||||
.map((item) -> "CLASS:" + item.name() + "\n").orElse("") +
|
Optional.ofNullable(comment).map((_comment) -> "\nCOMMENT:" + _comment + "\n").orElse(""), /* 8 - comment */
|
||||||
Optional.ofNullable(comment).map((item) -> "COMMENT:" + item + "\n").orElse("") +
|
Optional.ofNullable(location).map((_location) -> "\nLOCATION:" + _location).orElse("") /* 9 - location */,
|
||||||
Optional.ofNullable(description).map((item) -> "DESCRIPTION:" + item + "\n").orElse("") +
|
Optional.ofNullable(percentComplete).map((_percentComplete) -> "\nPERCENT-COMPLETE:" + _percentComplete).orElse("") /* 10 = percentComplete */,
|
||||||
Optional.ofNullable(location).map((item) -> "LOCATION:" + item + "\n").orElse("") +
|
Optional.ofNullable(description).map((_description) -> "\nDESCRIPTION:" + _description).orElse("") /* 11 - description */,
|
||||||
Optional.ofNullable(percentComplete).map((item) -> "PERCENT-COMPLETE:" + item + "\n").orElse("") +
|
Optional.ofNullable(priority).map((_priority) -> "\nPRIORITY:" + _priority).orElse("") /* 12 - priority */
|
||||||
Optional.ofNullable(priority).map((item) -> "PRIORITY:" + item + "\n").orElse("") +
|
);
|
||||||
"END:" + TAG + "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,6 +90,15 @@ public abstract sealed class WebCalendarNode
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the domain name.
|
||||||
|
*
|
||||||
|
* @return the domain name of this event
|
||||||
|
*/
|
||||||
|
public String getDomainName() {
|
||||||
|
return this.domainName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve the list of categories into a comma-separated string.
|
* Resolve the list of categories into a comma-separated string.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* 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 cn.org.codecrafters.webcal.config;
|
||||||
|
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DatetimeFormatters
|
||||||
|
*
|
||||||
|
* @author Zihlu Wang
|
||||||
|
* @since 21 Sept, 2023
|
||||||
|
*/
|
||||||
|
public final class Formatter {
|
||||||
|
|
||||||
|
public static DateTimeFormatter getUtcDatetimeFormatter() {
|
||||||
|
if (Objects.isNull(utcDateTimeFormatter)) {
|
||||||
|
utcDateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'").withZone(ZoneOffset.UTC);
|
||||||
|
}
|
||||||
|
|
||||||
|
return utcDateTimeFormatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static DateTimeFormatter getLocalDatetimeFormatter() {
|
||||||
|
// if (Objects.isNull(localDatetimeFormatter)) {
|
||||||
|
// localDatetimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return localDatetimeFormatter;
|
||||||
|
// }
|
||||||
|
|
||||||
|
private static DateTimeFormatter utcDateTimeFormatter;
|
||||||
|
|
||||||
|
// private static DateTimeFormatter localDatetimeFormatter;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user