1 13 14 package org.ejbca.core.model.ra.raadmin; 15 16 import java.util.HashMap ; 17 import java.util.Iterator ; 18 19 import org.ejbca.core.model.UpgradeableDataHashMap; 20 21 22 28 public class AdminPreference extends UpgradeableDataHashMap implements java.io.Serializable , Cloneable { 29 30 public static final float LATEST_VERSION = 0; 31 32 33 public static final int FILTERMODE_BASIC = 0; 35 public static final int FILTERMODE_ADVANCED = 1; 36 37 38 public AdminPreference() { 39 super(); 40 41 data.put(PREFEREDLANGUAGE, new Integer (GlobalConfiguration.EN)); 43 data.put(SECONDARYLANGUAGE, new Integer (GlobalConfiguration.EN)); 44 data.put(ENTRIESPERPAGE, new Integer (25)); 45 data.put(LOGENTRIESPERPAGE, new Integer (25)); 46 data.put(THEME, "default_theme"); 47 data.put(LASTPROFILE, new Integer (0)); 48 data.put(LASTFILTERMODE, new Integer (FILTERMODE_BASIC)); 49 data.put(LASTLOGFILTERMODE, new Integer (FILTERMODE_BASIC)); 50 } 51 52 public int getPreferedLanguage() {return ((Integer ) data.get(PREFEREDLANGUAGE)).intValue();} 53 public void setPreferedLanguage(int language){ data.put(PREFEREDLANGUAGE, new Integer (language));} 54 60 public void setPreferedLanguage(String [] languages, String 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 (i)); 65 } 66 } 67 } 68 69 public int getSecondaryLanguage() {return ((Integer ) data.get(SECONDARYLANGUAGE)).intValue();} 70 public void setSecondaryLanguage(int language){ data.put(SECONDARYLANGUAGE, new Integer (language));} 71 77 public void setSecondaryLanguage(String [] languages, String 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 (i)); 82 } 83 } 84 } 85 86 public int getEntriesPerPage(){return ((Integer ) data.get(ENTRIESPERPAGE)).intValue();} 87 public void setEntriesPerPage(int entriesperpage){ data.put(ENTRIESPERPAGE, new Integer (entriesperpage));} 88 89 public int getLogEntriesPerPage(){return ((Integer ) data.get(LOGENTRIESPERPAGE)).intValue();} 90 public void setLogEntriesPerPage(int logentriesperpage){ data.put(LOGENTRIESPERPAGE, new Integer (logentriesperpage));} 91 92 public String getTheme() {return (String ) data.get(THEME); } 93 public void setTheme(String theme){ data.put(THEME, theme);} 94 95 public int getLastProfile(){return ((Integer ) data.get(LASTPROFILE)).intValue();} 96 public void setLastProfile(int lastprofile){data.put(LASTPROFILE, new Integer (lastprofile));} 97 98 99 public int getLastFilterMode(){ return ((Integer ) data.get(LASTFILTERMODE)).intValue();} 100 public void setLastFilterMode(int lastfiltermode){data.put(LASTFILTERMODE, new Integer (lastfiltermode));} 101 102 public int getLastLogFilterMode() {return ((Integer ) data.get(LASTLOGFILTERMODE)).intValue();} 103 public void setLastLogFilterMode(int lastlogfiltermode) {data.put(LASTLOGFILTERMODE, new Integer (lastlogfiltermode));} 104 105 public Object clone() throws CloneNotSupportedException { 106 AdminPreference clone = new AdminPreference(); 107 HashMap clonedata = (HashMap ) clone.saveData(); 108 109 Iterator i = (data.keySet()).iterator(); 110 while(i.hasNext()){ 111 Object key = i.next(); 112 clonedata.put(key, data.get(key)); 113 } 114 115 clone.loadData(clonedata); 116 return clone; 117 } 118 119 120 public float getLatestVersion(){ 121 return LATEST_VERSION; 122 } 123 124 125 126 public void upgrade(){ 127 if(Float.compare(LATEST_VERSION, getVersion()) != 0) { 128 130 data.put(VERSION, new Float (LATEST_VERSION)); 131 } 132 } 133 134 135 private static final String PREFEREDLANGUAGE = "preferedlanguage"; 137 private static final String SECONDARYLANGUAGE = "secondarylanguage"; 138 private static final String ENTRIESPERPAGE = "entriesperpage"; 139 private static final String LOGENTRIESPERPAGE = "logentriesperpage"; 140 private static final String THEME = "theme"; 141 private static final String LASTPROFILE = "lastprofile"; 142 private static final String LASTFILTERMODE = "lastfiltermode"; 143 private static final String LASTLOGFILTERMODE = "lastlogfiltermode"; 144 145 } 146 | Popular Tags |