KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > ra > raadmin > AdminPreference


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  
14 package org.ejbca.core.model.ra.raadmin;
15
16 import java.util.HashMap JavaDoc;
17 import java.util.Iterator JavaDoc;
18
19 import org.ejbca.core.model.UpgradeableDataHashMap;
20
21
22 /**
23  * A class representing a admins personal preferenses.
24  *
25  * @author Philip Vendil
26  * @version $Id: AdminPreference.java,v 1.2 2006/05/28 14:21:11 anatom Exp $
27  */

28 public class AdminPreference extends UpgradeableDataHashMap implements java.io.Serializable JavaDoc, Cloneable JavaDoc {
29     
30     public static final float LATEST_VERSION = 0;
31     
32     
33     // Public constants
34
public static final int FILTERMODE_BASIC = 0;
35     public static final int FILTERMODE_ADVANCED = 1;
36
37     /** Creates a new instance of AdminPreference */
38     public AdminPreference() {
39       super();
40       
41       // Set default values.
42
data.put(PREFEREDLANGUAGE, new Integer JavaDoc(GlobalConfiguration.EN));
43       data.put(SECONDARYLANGUAGE, new Integer JavaDoc(GlobalConfiguration.EN));
44       data.put(ENTRIESPERPAGE, new Integer JavaDoc(25));
45       data.put(LOGENTRIESPERPAGE, new Integer JavaDoc(25));
46       data.put(THEME, "default_theme");
47       data.put(LASTPROFILE, new Integer JavaDoc(0));
48       data.put(LASTFILTERMODE, new Integer JavaDoc(FILTERMODE_BASIC));
49       data.put(LASTLOGFILTERMODE, new Integer JavaDoc(FILTERMODE_BASIC));
50     }
51
52     public int getPreferedLanguage() {return ((Integer JavaDoc) data.get(PREFEREDLANGUAGE)).intValue();}
53     public void setPreferedLanguage(int language){ data.put(PREFEREDLANGUAGE, new Integer JavaDoc(language));}
54     /** Method taking a string, needs as input the available languages.
55      *
56      * @param languages available languages as retrieved from EjbcaWebBean.getAvailableLanguages
57      * @param languagecode two letter language code, ex SE
58      * @see org.ejbca.ui.web.admin.configuration.EjbcaWebBean#getAvailableLanguages()
59      */

60     public void setPreferedLanguage(String JavaDoc[] languages, String JavaDoc languagecode) {
61         if(languages != null){
62             for(int i=0; i < languages.length; i++){
63                 if(languages[i].toUpperCase().equals(languagecode.toUpperCase()))
64                     data.put(PREFEREDLANGUAGE, new Integer JavaDoc(i));
65             }
66         }
67     }
68     
69     public int getSecondaryLanguage() {return ((Integer JavaDoc) data.get(SECONDARYLANGUAGE)).intValue();}
70     public void setSecondaryLanguage(int language){ data.put(SECONDARYLANGUAGE, new Integer JavaDoc(language));}
71     /** Method taking a string, needs as input the available languages.
72      *
73      * @param languages available languages as retrieved from EjbcaWebBean.getAvailableLanguages
74      * @param languagecode two letter language code, ex SE
75      * @see org.ejbca.ui.web.admin.configuration.EjbcaWebBean#getAvailableLanguages()
76      */

77     public void setSecondaryLanguage(String JavaDoc[] languages, String JavaDoc languagecode){
78         if(languages != null){
79             for(int i=0; i < languages.length; i++){
80                 if(languages[i].toUpperCase().equals(languagecode.toUpperCase()))
81                     data.put(SECONDARYLANGUAGE, new Integer JavaDoc(i));
82             }
83         }
84     }
85
86     public int getEntriesPerPage(){return ((Integer JavaDoc) data.get(ENTRIESPERPAGE)).intValue();}
87     public void setEntriesPerPage(int entriesperpage){ data.put(ENTRIESPERPAGE, new Integer JavaDoc(entriesperpage));}
88     
89     public int getLogEntriesPerPage(){return ((Integer JavaDoc) data.get(LOGENTRIESPERPAGE)).intValue();}
90     public void setLogEntriesPerPage(int logentriesperpage){ data.put(LOGENTRIESPERPAGE, new Integer JavaDoc(logentriesperpage));}
91     
92     public String JavaDoc getTheme() {return (String JavaDoc) data.get(THEME); }
93     public void setTheme(String JavaDoc theme){ data.put(THEME, theme);}
94
95     public int getLastProfile(){return ((Integer JavaDoc) data.get(LASTPROFILE)).intValue();}
96     public void setLastProfile(int lastprofile){data.put(LASTPROFILE, new Integer JavaDoc(lastprofile));}
97     
98     /** Last filter mode is the admins last mode in the list end entities jsp page. */
99     public int getLastFilterMode(){ return ((Integer JavaDoc) data.get(LASTFILTERMODE)).intValue();}
100     public void setLastFilterMode(int lastfiltermode){data.put(LASTFILTERMODE, new Integer JavaDoc(lastfiltermode));}
101     
102     public int getLastLogFilterMode() {return ((Integer JavaDoc) data.get(LASTLOGFILTERMODE)).intValue();}
103     public void setLastLogFilterMode(int lastlogfiltermode) {data.put(LASTLOGFILTERMODE, new Integer JavaDoc(lastlogfiltermode));}
104     
105     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
106       AdminPreference clone = new AdminPreference();
107       HashMap JavaDoc clonedata = (HashMap JavaDoc) clone.saveData();
108       
109       Iterator JavaDoc i = (data.keySet()).iterator();
110       while(i.hasNext()){
111         Object JavaDoc key = i.next();
112         clonedata.put(key, data.get(key));
113       }
114       
115       clone.loadData(clonedata);
116       return clone;
117     }
118     
119     /** Implemtation of UpgradableDataHashMap function getLatestVersion */
120     public float getLatestVersion(){
121        return LATEST_VERSION;
122     }
123     
124     /** Implemtation of UpgradableDataHashMap function upgrade. */
125     
126     public void upgrade(){
127         if(Float.compare(LATEST_VERSION, getVersion()) != 0) {
128             // New version of the class, upgrade
129

130             data.put(VERSION, new Float JavaDoc(LATEST_VERSION));
131         }
132     }
133     
134
135     // Private fields
136
private static final String JavaDoc PREFEREDLANGUAGE = "preferedlanguage";
137     private static final String JavaDoc SECONDARYLANGUAGE = "secondarylanguage";
138     private static final String JavaDoc ENTRIESPERPAGE = "entriesperpage";
139     private static final String JavaDoc LOGENTRIESPERPAGE = "logentriesperpage";
140     private static final String JavaDoc THEME = "theme";
141     private static final String JavaDoc LASTPROFILE = "lastprofile";
142     private static final String JavaDoc LASTFILTERMODE = "lastfiltermode";
143     private static final String JavaDoc LASTLOGFILTERMODE = "lastlogfiltermode";
144     
145 }
146
Popular Tags