X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Foutput%2FCertificateValiditySelector.java;fp=src%2Forg%2Fcacert%2Fgigi%2Foutput%2FCertificateValiditySelector.java;h=0000000000000000000000000000000000000000;hp=d0f0c124a38cfc135fe276218094284bb2fbd5b7;hb=bccd4cc0dba0f89aa045b113bac46eb8cc1dab4e;hpb=c9ed09f0007fc2c813815be927a5a24b23dab83c diff --git a/src/org/cacert/gigi/output/CertificateValiditySelector.java b/src/org/cacert/gigi/output/CertificateValiditySelector.java deleted file mode 100644 index d0f0c124..00000000 --- a/src/org/cacert/gigi/output/CertificateValiditySelector.java +++ /dev/null @@ -1,141 +0,0 @@ -package org.cacert.gigi.output; - -import java.io.PrintWriter; -import java.sql.Date; -import java.text.ParseException; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.cacert.gigi.GigiApiException; -import org.cacert.gigi.localisation.Language; -import org.cacert.gigi.output.template.Outputable; -import org.cacert.gigi.util.HTMLEncoder; - -public class CertificateValiditySelector implements Outputable { - - private static final long DAY = 1000 * 60 * 60 * 24; - - private Date from; - - private String val = "2y"; - - public CertificateValiditySelector() { - - } - - @Override - public void output(PrintWriter out, Language l, Map vars) { - out.print(""); - - out.print(""); - out.print(""); - - if (from == null) { - return; - } - - } - - private long getCurrentDayBase() { - long base = System.currentTimeMillis(); - base -= base % DAY; - base += DAY; - return base; - } - - public void update(HttpServletRequest r) throws GigiApiException { - String from = r.getParameter("validFrom"); - - GigiApiException gae = new GigiApiException(); - try { - saveStartDate(from); - } catch (GigiApiException e) { - gae.mergeInto(e); - } - try { - String validity = r.getParameter("validity"); - if (validity != null) { - checkValidityLength(validity); - val = validity; - } - } catch (GigiApiException e) { - gae.mergeInto(e); - } - if ( !gae.isEmpty()) { - throw gae; - } - - } - - public static void checkValidityLength(String newval) throws GigiApiException { - if (newval.endsWith("y") || newval.endsWith("m")) { - if (newval.length() > 10) { // for database - throw new GigiApiException("The validity interval entered is invalid."); - } - String num = newval.substring(0, newval.length() - 1); - try { - int len = Integer.parseInt(num); - if (len <= 0) { - throw new GigiApiException("The validity interval entered is invalid."); - } - } catch (NumberFormatException e) { - throw new GigiApiException("The validity interval entered is invalid."); - } - } else { - try { - DateSelector.getDateFormat().parse(newval); - } catch (ParseException e) { - throw new GigiApiException("The validity interval entered is invalid."); - } - } - } - - private void saveStartDate(String from) throws GigiApiException { - if (from == null || "now".equals(from)) { - this.from = null; - } else { - try { - this.from = new Date(DateSelector.getDateFormat().parse(from).getTime()); - } catch (ParseException e) { - throw new GigiApiException("The validity start date entered is invalid."); - } - } - } - - public Date getFrom() { - return from; - } - - public String getTo() { - return val; - } - -}