updated libraries, adapted code to library changes

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-08-31 15:05:21 +02:00
parent e37cbd0e90
commit 80f92263b3
35 changed files with 450 additions and 373 deletions
@@ -1,14 +1,19 @@
/* © SRSoftware 2026 */
package de.srsoftware.cal;
import static de.srsoftware.tools.Error.error;
import static de.srsoftware.tools.Result.transform;
import static de.srsoftware.tools.Tag.STYLE;
import static de.srsoftware.tools.container.Container.transform;
import static de.srsoftware.tools.container.Error.error;
import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.WARNING;
import de.srsoftware.cal.api.Attachment;
import de.srsoftware.cal.api.Coords;
import de.srsoftware.tools.*;
import de.srsoftware.tools.container.Container;
import de.srsoftware.tools.container.Payload;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
@@ -51,7 +56,7 @@ public class Util {
private Util(){}
public static Result<LocalDateTime> combine(Result<LocalDate> date, Result<LocalTime> time) {
public static Container<LocalDateTime> combine(Container<LocalDate> date, Container<LocalTime> time) {
if (date.optional().isEmpty())return transform(date);
if (time.optional().isEmpty())return transform(time);
return Payload.of(LocalDateTime.of(date.optional().get(),time.optional().get()));
@@ -88,7 +93,7 @@ public class Util {
}
}
public static Result<Coords> extractCoords(String coords) {
public static Container<Coords> extractCoords(String coords) {
if (coords == null) return error("Argument is null");
if (coords.isBlank()) return error("Argument is blank");
var parts = coords.split(",");
@@ -102,7 +107,7 @@ public class Util {
}
}
public static Result<InputStream> open(Result<URL> url) {
public static Container<InputStream> open(Container<URL> url) {
var opt = url.optional();
if (opt.isEmpty()) return transform(url);
try {
@@ -125,7 +130,7 @@ public class Util {
.replace(":","/");
}
public static Result<LocalDate> parseGermanDate(String s){
public static Container<LocalDate> parseGermanDate(String s){
var match = GERMAN_DATE_PATTERN.matcher(" "+s.trim()+" ");
if (match.find()){
var day = Integer.parseInt(match.group(1));
@@ -136,7 +141,7 @@ public class Util {
return error("Failed to find date");
}
public static Result<LocalDate> parseLongGermanDate(String s){
public static Container<LocalDate> parseLongGermanDate(String s){
var match = GERMAN_DATE_PATTERN_LONG.matcher(" "+s+" ");
if (match.find()){
var day = Integer.parseInt(match.group(1));
@@ -149,7 +154,7 @@ public class Util {
return error("Failed to find date");
}
public static Result<LocalTime> parseGermanTime(String s){
public static Container<LocalTime> parseGermanTime(String s){
var match = GERMAN_TIME_PATTERN.matcher(" "+s.trim()+" ");
if (match.find()){
var hour = Integer.parseInt(match.group(1));
@@ -161,12 +166,12 @@ public class Util {
return error("Failed to find time");
}
public static Result<Tag> parseXML(Result<InputStream> inputStream) {
public static Container<Tag> parseXML(Container<InputStream> inputStream) {
var opt = inputStream.optional();
return opt.isEmpty() ? transform((inputStream)) : XMLParser.parse(opt.get());
}
public static Result<InputStream> preload(Result<InputStream> inputStream) {
public static Container<InputStream> preload(Container<InputStream> inputStream) {
var opt = inputStream.optional();
if (opt.isEmpty()) return transform(inputStream);
try {
@@ -176,7 +181,7 @@ public class Util {
}
}
public static Result<Integer> toNumericMonth(String month) {
public static Container<Integer> toNumericMonth(String month) {
month = month.toLowerCase();
if (month.startsWith("ja")) return Payload.of(1);
if (month.startsWith("f")) return Payload.of(2);
@@ -199,7 +204,7 @@ public class Util {
* @param prodId the producer id of this icalendar
* @return the completed ical string
*/
public static Result<String> wrapIcal(Result<String> ical, String prodId) {
public static Container<String> wrapIcal(Container<String> ical, String prodId) {
if (ical instanceof Payload<String> payload){
var calendar = new StringBuilder();
calendar.append(contentLine(BEGIN,VCALENDAR));
@@ -212,7 +217,7 @@ public class Util {
return ical;
}
public static Result<String> extractBackgroundImage(Tag tag, String baseUrl) {
public static Container<String> extractBackgroundImage(Tag tag, String baseUrl) {
var style = tag.get(STYLE);
if (style != null){
var matcher = BG_IMAGE_URL.matcher(style);
@@ -224,7 +229,7 @@ public class Util {
return error("Failed to findbackground image url in %s",tag);
}
public static Result<Attachment> toAttachment(Result<URL> urlResult) {
public static Container<Attachment> toAttachment(Container<URL> urlResult) {
var opt = urlResult.optional();
if (opt.isEmpty()) return transform(urlResult);
try {
@@ -236,7 +241,7 @@ public class Util {
}
}
public static Result<Integer> parseInt(String s){
public static Container<Integer> parseInt(String s){
try {
return Payload.of(Integer.parseInt(s));
} catch (NumberFormatException e){
@@ -244,7 +249,7 @@ public class Util {
}
}
public static Result<URL> url(Result<String> urlResult) {
public static Container<URL> url(Container<String> urlResult) {
if (urlResult.optional().isEmpty()) return transform(urlResult);
var url = urlResult.optional().get();
try {
@@ -254,7 +259,7 @@ public class Util {
}
}
public static Result<LocalDate> parseGermanDateWithoutYear(String string) {
public static Container<LocalDate> parseGermanDateWithoutYear(String string) {
var matcher = GERMAN_DATE_WITHOUT_YEAR.matcher(string);
if (matcher.find()){
int day = Integer.parseInt(matcher.group(1));