1 22 23 package org.gjt.sp.jedit; 24 25 import java.io.*; 26 import java.util.*; 27 28 class PropertyManager 29 { 30 Properties getProperties() 32 { 33 Properties total = new Properties(); 34 total.putAll(system); 35 Iterator iter = plugins.iterator(); 36 while(iter.hasNext()) 37 total.putAll((Properties)iter.next()); 38 total.putAll(site); 39 total.putAll(user); 40 return total; 41 } 43 void loadSystemProps(InputStream in) 45 throws IOException 46 { 47 loadProps(system,in); 48 } 50 void loadSiteProps(InputStream in) 52 throws IOException 53 { 54 loadProps(site,in); 55 } 57 void loadUserProps(InputStream in) 59 throws IOException 60 { 61 loadProps(user,in); 62 } 64 void saveUserProps(OutputStream out) 66 throws IOException 67 { 68 user.store(out,"jEdit properties"); 69 out.close(); 70 } 72 Properties loadPluginProps(InputStream in) 74 throws IOException 75 { 76 Properties plugin = new Properties(); 77 loadProps(plugin,in); 78 plugins.add(plugin); 79 return plugin; 80 } 82 void addPluginProps(Properties props) 84 { 85 plugins.add(props); 86 } 88 void removePluginProps(Properties props) 90 { 91 plugins.remove(props); 92 } 94 String getProperty(String name) 96 { 97 String value = user.getProperty(name); 98 if(value != null) 99 return value; 100 else 101 return getDefaultProperty(name); 102 } 104 void setProperty(String name, String value) 106 { 107 String prop = getDefaultProperty(name); 108 109 116 if(value == null) 117 { 118 if(prop == null || prop.length() == 0) 119 user.remove(name); 120 else 121 user.put(name,""); 122 } 123 else 124 { 125 if(value.equals(prop)) 126 user.remove(name); 127 else 128 user.put(name,value); 129 } 130 } 132 public void setTemporaryProperty(String name, String value) 134 { 135 user.remove(name); 136 system.put(name,value); 137 } 139 void unsetProperty(String name) 141 { 142 if(getDefaultProperty(name) != null) 143 user.put(name,""); 144 else 145 user.remove(name); 146 } 148 public void resetProperty(String name) 150 { 151 user.remove(name); 152 } 154 private Properties system = new Properties(); 156 private List plugins = new LinkedList(); 157 private Properties site = new Properties(); 158 private Properties user = new Properties(); 159 160 private String getDefaultProperty(String name) 162 { 163 String value = site.getProperty(name); 164 if(value != null) 165 return value; 166 167 Iterator iter = plugins.iterator(); 168 while(iter.hasNext()) 169 { 170 value = ((Properties)iter.next()).getProperty(name); 171 if(value != null) 172 return value; 173 } 174 175 return system.getProperty(name); 176 } 178 private void loadProps(Properties into, InputStream in) 180 throws IOException 181 { 182 try 183 { 184 into.load(in); 185 } 186 finally 187 { 188 in.close(); 189 } 190 } 192 } 194 | Popular Tags |