1 13 package org.ejbca.ui.web.admin.services.servicetypes; 14 15 import java.io.IOException ; 16 import java.util.ArrayList ; 17 import java.util.List ; 18 import java.util.Properties ; 19 20 import javax.faces.model.SelectItem; 21 22 import org.ejbca.core.model.services.intervals.PeriodicalInterval; 23 import org.ejbca.ui.web.admin.configuration.EjbcaJSFHelper; 24 25 32 public class PeriodicalIntervalType extends IntervalType { 33 34 public static final String NAME = "PERIODICALINTERVAL"; 35 36 public static final String DEFAULT_UNIT = PeriodicalInterval.UNIT_MINUTES; 37 public static final String DEFAULT_VALUE = "5"; 38 39 public PeriodicalIntervalType() { 40 super("periodicalinterval.jsp", NAME, true); 41 unit = DEFAULT_UNIT; 42 value = DEFAULT_VALUE; 43 } 44 45 String unit; 46 String value; 47 48 49 public String getClassPath() { 50 return "org.ejbca.core.model.services.intervals.PeriodicalInterval"; 51 } 52 53 public Properties getProperties(ArrayList errorMessages) throws IOException { 54 Properties retval = new Properties (); 55 56 57 try{ 58 int val = Integer.parseInt(value); 59 if(val < 1){ 60 throw new NumberFormatException (); 61 } 62 }catch(NumberFormatException e){ 63 errorMessages.add("PERIODICALVALUEERROR"); 64 } 65 retval.setProperty(PeriodicalInterval.PROP_VALUE, value); 66 retval.setProperty(PeriodicalInterval.PROP_UNIT, unit); 67 return retval; 68 } 69 70 public void setProperties(Properties properties) throws IOException { 71 value = properties.getProperty(PeriodicalInterval.PROP_VALUE,DEFAULT_VALUE); 72 unit = properties.getProperty(PeriodicalInterval.PROP_UNIT,DEFAULT_UNIT); 73 } 74 75 public boolean isCustom() { 76 return false; 77 } 78 79 public String getUnit() { 80 return unit; 81 } 82 83 public void setUnit(String unit) { 84 this.unit = unit; 85 } 86 87 public List getAvailableUnits(){ 88 ArrayList retval = new ArrayList (); 89 for(int i = 0 ; i<PeriodicalInterval.AVAILABLE_UNITS.length; i++){ 90 retval.add(new SelectItem(PeriodicalInterval.AVAILABLE_UNITS[i],(String ) EjbcaJSFHelper.getBean().getText().get(PeriodicalInterval.AVAILABLE_UNITS[i]))); 91 } 92 93 return retval; 94 } 95 96 public String getValue() { 97 return value; 98 } 99 100 public void setValue(String value) { 101 this.value = value; 102 } 103 104 105 } 106 | Popular Tags |