Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 12584 #1164

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
113 changes: 86 additions & 27 deletions core-api/src/main/java/org/silverpeas/core/date/TemporalFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
import java.time.temporal.Temporal;
import java.util.Objects;

import static java.time.temporal.ChronoField.HOUR_OF_DAY;
import static java.time.temporal.ChronoField.MINUTE_OF_HOUR;
import static java.time.temporal.ChronoField.*;
import static org.silverpeas.core.date.TemporalConverter.asZonedDateTime;
import static org.silverpeas.core.util.ResourceLocator.getLocalizationBundle;

Expand Down Expand Up @@ -104,8 +103,10 @@ public static java.time.temporal.Temporal toTemporal(final String iso8601DateTim

/**
* <p>
* Formats the specified temporal into an ISO-8601 string representation. The rules of formatting
* are based upon the {@link DateTimeFormatter} that fully follows the ISO-8601 specification.
* Formats the specified temporal into the extended ISO-8601 String representation. The rules of
* formatting are based upon the {@link DateTimeFormatter} that fully follows the extended format
* of the ISO-8601 specification. The extended format is about the representation of the offset of
* the time.
* </p>
* <p>
* If the temporal is a date, then the ISO-8601 representation will be of an ISO local date.
Expand Down Expand Up @@ -136,34 +137,56 @@ public static java.time.temporal.Temporal toTemporal(final String iso8601DateTim
* </p>
* @param temporal a {@link Temporal} object to convert.
* @param withSeconds if in the ISO-8601 string the seconds have to be represented (seconds
* following by nanoseconds can be optional an part according to the ISO 8601 specification).
* following by nanoseconds can be optional a part according to the ISO 8601 specification).
* For displaying, usually the seconds aren't meaningful whereas for the datetime transport from
* one source to a target point this can be important.
* @return an ISO-8601 string representation of the temporal.
* @return a String representation of the temporal in the extended format of the ISO-8601
* specification.
*/
public static String toIso8601(final Temporal temporal, final boolean withSeconds) {
Objects.requireNonNull(temporal);

if (!temporal.isSupported(ChronoUnit.HOURS)) {
return DateTimeFormatter.ISO_LOCAL_DATE.format(temporal);
}
return toIso8601(temporal, withSeconds, true);
}

if (withSeconds) {
if (temporal.isSupported(ChronoField.OFFSET_SECONDS)) {
return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(temporal);
}
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(temporal);
}
final DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().parseCaseInsensitive()
.append(DateTimeFormatter.ISO_LOCAL_DATE)
.appendLiteral('T')
.appendValue(HOUR_OF_DAY, 2)
.appendLiteral(':')
.appendValue(MINUTE_OF_HOUR, 2);
if (temporal.isSupported(ChronoField.OFFSET_SECONDS)) {
builder.appendOffsetId();
}
return builder.toFormatter().format(temporal);
/**
* <p>
* Formats the specified temporal into the base ISO-8601 String representation.
* </p>
* <p>
* If the temporal is a date, then the ISO-8601 representation will be of an ISO local date.
* If the temporal is a local datetime, it will be converted without any Zone Offset indication,
* otherwise the offset will be printed out.
* </p>
* <p>
* Examples:
* <pre>
* {@code TemporalConverter.toIso8601(OffsetDateTime.now(), false)}
* {@code Result: 2018-03-13T15:11+0100}
*
* {@code TemporalConverter.toIso8601(OffsetDateTime.now(), true)}
* {@code Result: 2018-03-13T15:11:14.971+0100}
*
* {@code TemporalConverter.toIso8601(LocalDateTime.now(), false)}
* {@code Result: 2018-03-13T15:11}
*
* {@code TemporalConverter.toIso8601(LocalDateTime.now(), true)}
* {@code Result: 2018-03-13T15:11:14.971}
*
* {@code TemporalConverter.toIso8601(LocalDate, false)}
* {@code Result: 2018-03-13}
*
* {@code TemporalConverter.toIso8601(LocalDate, true)}
* {@code Result: 2018-03-13}
* </pre>
* </p>
* @param withSeconds if in the ISO-8601 string the seconds have to be represented (seconds
* following by nanoseconds can be optional a part according to the ISO 8601 specification).
* For displaying, usually the seconds aren't meaningful whereas for the datetime
* transport from one source to a target point this can be important.
* @return a String representation of the temporal in the base format of the ISO-8601
* specification.
*/
public static String toBaseIso8601(final Temporal temporal, boolean withSeconds) {
return toIso8601(temporal, withSeconds, false);
}

/**
Expand Down Expand Up @@ -355,6 +378,42 @@ public static String toLocalizedTime(final Temporal temporal, final ZoneId zoneI
}
}

private static String toIso8601(final Temporal temporal, final boolean withSeconds,
final boolean extended) {
Objects.requireNonNull(temporal);

if (!temporal.isSupported(ChronoUnit.HOURS)) {
return DateTimeFormatter.ISO_LOCAL_DATE.format(temporal);
}

// add hour and minute field
final DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().parseCaseInsensitive()
.append(DateTimeFormatter.ISO_LOCAL_DATE)
.appendLiteral('T')
.appendValue(HOUR_OF_DAY, 2)
.appendLiteral(':')
.appendValue(MINUTE_OF_HOUR, 2);
if (withSeconds) {
// add seconds and nano of second fields
builder.optionalStart()
.appendLiteral(':')
.appendValue(SECOND_OF_MINUTE, 2)
.optionalStart()
.appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true);
}
if (temporal.isSupported(ChronoField.OFFSET_SECONDS)) {
// offset is supported, then add the field according to the kind of format (extended or base)
builder.parseLenient();
if (extended) {
builder.appendOffsetId();
} else {
builder.appendOffset("+HHMM", "Z");
}
builder.parseStrict();
}
return builder.toFormatter().format(temporal);
}

private static String toZonedFormat(final String pattern, final Temporal temporal,
final ZoneId actualZoneId) {
return new DateTimeFormatterBuilder().appendPattern(pattern).appendLiteral(" (")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ zkg5B9f1r5H8Utt8D+IG5IGn3B9/9W1fWjNyRgYr4/8AGDbfAHiFupGl3J/8hNRP4Tvp/Ej4v+Ei
kfCXQgM8xMf/ACI1frSCvzAtgDk5P86/K74UjHwn0AZxm3PfH8bV+qgJKkbxxnn1r6Lqz46PwR9C
mNvU8k4x6Grij88HkHGKohsqWDdOTt5q453REqwJ9fQ10nUW1wHXjIAxgVpR4yFPHfjp1qgMqcZJ
GM9Dmt5T87AHJHoMV5zMDrBgitGsxetaVfLs+piOr8o/GX3IuOtfq5X5N+MDzEP6V2x6mM+h7x4S
GNGb/rs/9K+7K+HfCYxog95X/nX3FXE9z0FsFFFFYHQFFFFABRRRQAUUUUAfzV/HT/knYXP3r+3G
GNGb/javax.ws.rs/9K+7K+HfCYxog95X/nX3FXE9z0FsFFFFYHQFFFFABRRRQAUUUUAfzV/HT/knYXP3r+3G
PX5q/pUr+ZL46knwNZoM/Pqluv8A6F1/Kv6ba6Ps/P8AyOb7Xy/zCiiiuc6RKKSlpkC0UlUQiq7O
B8zYz+FMC/RRRUlhRRRQAUUlLQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAU
UUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABSUtFABRRX5C/EbxjJ4N8OLdWsccl9cSiKB
Expand Down
75 changes: 75 additions & 0 deletions core-rs/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2000 - 2021 Silverpeas
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as
~ published by the Free Software Foundation, either version 3 of the
~ License, or (at your option) any later version.
~
~ As a special exception to the terms and conditions of version 3.0 of
~ the GPL, you may redistribute this Program in connection with Free/Lib
~ Open Source Software ("FLOSS") applications as described in Silverpeas
~ FLOSS exception. You should have received a copy of the text describin
~ the FLOSS exception, and it is also available here:
~ "https://www.silverpeas.org/legal/floss_exception.html"
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public Licen
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
~
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>core</artifactId>
<groupId>org.silverpeas</groupId>
<version>6.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>org.silverpeas.core</groupId>
<artifactId>silverpeas-core-rs</artifactId>
<packaging>jar</packaging>
<name>Silverpeas Core Web ${project.version}</name>
<description>Providing web foundation bases of Web REST-based services.</description>

<dependencies>
<dependency>
<groupId>org.silverpeas.core</groupId>
<artifactId>silverpeas-core-api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.silverpeas.core</groupId>
<artifactId>silverpeas-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>edu.psu.swe.commons</groupId>
<artifactId>commons-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* License, or (at your option) any later version.
*
* As a special exception to the terms and conditions of version 3.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* Open Source Software ("FLOSS") applications as described in Silverpeas's
* FLOSS exception. You should have received a copy of the text describing
* the GPL, you may redistribute this Program in connection with Free/Lib
* Open Source Software ("FLOSS") applications as described in Silverpeas
* FLOSS exception. You should have received a copy of the text describin
* the FLOSS exception, and it is also available here:
* "https://www.silverpeas.org/legal/floss_exception.html"
*
Expand All @@ -18,8 +18,9 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* You should have received a copy of the GNU Affero General Public Licen
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package javax.ws.rs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,9 @@
* License, or (at your option) any later version.
*
* As a special exception to the terms and conditions of version 3.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* Open Source Software ("FLOSS") applications as described in Silverpeas's
* FLOSS exception. You should have received a copy of the text describing
* the FLOSS exception, and it is also available here:
* "http://www.silverpeas.org/legal/licensing"
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* Copyright (C) 2000 - 2021 Silverpeas
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* As a special exception to the terms and conditions of version 3.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* Open Source Software ("FLOSS") applications as described in Silverpeas's
* FLOSS exception. You should have received a copy of the text describing
* the GPL, you may redistribute this Program in connection with Free/Lib
* Open Source Software ("FLOSS") applications as described in Silverpeas
* FLOSS exception. You should have received a copy of the text describin
* the FLOSS exception, and it is also available here:
* "https://www.silverpeas.org/legal/floss_exception.html"
*
Expand All @@ -42,9 +18,11 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* You should have received a copy of the GNU Affero General Public Licen
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package org.silverpeas.core.web;

import org.silverpeas.core.util.URLUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* License, or (at your option) any later version.
*
* As a special exception to the terms and conditions of version 3.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* Open Source Software ("FLOSS") applications as described in Silverpeas's
* FLOSS exception. You should have received a copy of the text describing
* the GPL, you may redistribute this Program in connection with Free/Lib
* Open Source Software ("FLOSS") applications as described in Silverpeas
* FLOSS exception. You should have received a copy of the text describin
* the FLOSS exception, and it is also available here:
* "https://www.silverpeas.org/legal/floss_exception.html"
*
Expand All @@ -18,12 +18,11 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* You should have received a copy of the GNU Affero General Public Licen
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.silverpeas.core.webapi.base;

import org.silverpeas.core.web.SilverpeasWebResource;
package org.silverpeas.core.web;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
Expand Down