From d3a9a3226fae0f4d3f51c3f013f72f701142c846 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 17 Oct 2019 21:28:40 +0000 Subject: [PATCH] Replace deprecated Date by Calendar Apparently, Date.setYear and Date.getYear are deprecated in favour of Calendar, since Java6! Source: https://docs.oracle.com/javase/6/docs/api/java/util/Date.html --- .../org/airsonic/player/controller/JAXBWriter.java | 9 +++++++++ .../player/controller/SubsonicRESTController.java | 11 ++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/airsonic-main/src/main/java/org/airsonic/player/controller/JAXBWriter.java b/airsonic-main/src/main/java/org/airsonic/player/controller/JAXBWriter.java index 5e0bd122..f6ccb2b4 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/controller/JAXBWriter.java +++ b/airsonic-main/src/main/java/org/airsonic/player/controller/JAXBWriter.java @@ -42,6 +42,7 @@ import javax.xml.datatype.XMLGregorianCalendar; import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; +import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; @@ -175,4 +176,12 @@ public class JAXBWriter { c.setTime(date); return datatypeFactory.newXMLGregorianCalendar(c).normalize(); } + + public XMLGregorianCalendar convertCalendar(Calendar calendar) { + if (calendar == null) { + return null; + } + + return datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)calendar).normalize(); + } } diff --git a/airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java b/airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java index cde759ee..daddb4ce 100644 --- a/airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java +++ b/airsonic-main/src/main/java/org/airsonic/player/controller/SubsonicRESTController.java @@ -53,6 +53,7 @@ import org.subsonic.restapi.PodcastStatus; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; +import javax.xml.datatype.XMLGregorianCalendar; import java.util.*; @@ -164,13 +165,13 @@ public class SubsonicRESTController { request = wrapRequest(request); License license = new License(); - license.setEmail("airsonic@github.com"); license.setValid(true); - Date farFuture = new Date(); - farFuture.setYear(farFuture.getYear() + 100); - license.setLicenseExpires(jaxbWriter.convertDate(farFuture)); - license.setTrialExpires(jaxbWriter.convertDate(farFuture)); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.YEAR, 100); + XMLGregorianCalendar farFuture = jaxbWriter.convertCalendar(calendar); + license.setLicenseExpires(farFuture); + license.setTrialExpires(farFuture); Response res = createResponse(); res.setLicense(license);