KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > services > servicetypes > PeriodicalIntervalType


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13 package org.ejbca.ui.web.admin.services.servicetypes;
14
15 import java.io.IOException JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Properties JavaDoc;
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 /**
26  * Class used to populate the fields in the custominterval.jsp subview page.
27  *
28  * @author Philip Vendil 2006 sep 30
29  *
30  * @version $Id: PeriodicalIntervalType.java,v 1.2 2006/10/26 11:02:17 herrvendil Exp $
31  */

32 public class PeriodicalIntervalType extends IntervalType {
33     
34     public static final String JavaDoc NAME = "PERIODICALINTERVAL";
35     
36     public static final String JavaDoc DEFAULT_UNIT = PeriodicalInterval.UNIT_MINUTES;
37     public static final String JavaDoc 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 JavaDoc unit;
46     String JavaDoc value;
47
48
49     public String JavaDoc getClassPath() {
50         return "org.ejbca.core.model.services.intervals.PeriodicalInterval";
51     }
52
53     public Properties JavaDoc getProperties(ArrayList JavaDoc errorMessages) throws IOException JavaDoc{
54         Properties JavaDoc retval = new Properties JavaDoc();
55         
56         
57         try{
58             int val = Integer.parseInt(value);
59             if(val < 1){
60                 throw new NumberFormatException JavaDoc();
61             }
62         }catch(NumberFormatException JavaDoc 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 JavaDoc properties) throws IOException JavaDoc{
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 JavaDoc getUnit() {
80         return unit;
81     }
82
83     public void setUnit(String JavaDoc unit) {
84         this.unit = unit;
85     }
86     
87     public List JavaDoc getAvailableUnits(){
88         ArrayList JavaDoc retval = new ArrayList JavaDoc();
89         for(int i = 0 ; i<PeriodicalInterval.AVAILABLE_UNITS.length; i++){
90             retval.add(new SelectItem(PeriodicalInterval.AVAILABLE_UNITS[i],(String JavaDoc) EjbcaJSFHelper.getBean().getText().get(PeriodicalInterval.AVAILABLE_UNITS[i])));
91         }
92         
93         return retval;
94     }
95
96     public String JavaDoc getValue() {
97         return value;
98     }
99
100     public void setValue(String JavaDoc value) {
101         this.value = value;
102     }
103     
104     
105 }
106
Popular Tags