Changeset 5570
- Timestamp:
- Feb 16, 2011, 2:49:40 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/config/dist/base.config
r5537 r5570 221 221 # locale.country = 222 222 # locacle.variant = 223 224 # The default character set that will be used to parse text files that 225 # hasn't specified a character set. The default value for this setting 226 # is ISO-8859-1. 227 # 228 # defaultCharset = ISO-8859-1 229 230 # A comma-separated list of the most commonly used character sets for text 231 # files. This list is used to order selection lists so that the common values 232 # are listed at the top of the list. 233 # 234 # commonCharsets = UTF-8,US-ASCII,ISO-8859-1 235 236 # A regular expression that used to filter character sets that are not used 237 # in order to keep the selection list shorter. If no value is specified all 238 # character sets are included. The standard setting will filter out all 239 # character sets starting with 'x-' or 'IBM'. Character sets that are specified 240 # in the commonCharsets setting are never filtered. 241 # 242 ignoreCharsets = ((x|X)\-|IBM).* 243 223 244 224 245 # =============== -
trunk/src/core/net/sf/basedb/core/Config.java
r5409 r5570 23 23 package net.sf.basedb.core; 24 24 25 import java.util.Arrays; 26 import java.util.Collections; 25 27 import java.util.Locale; 26 28 import java.util.Properties; 29 import java.util.SortedSet; 30 import java.util.TreeSet; 31 import java.util.regex.Pattern; 32 import java.util.regex.PatternSyntaxException; 27 33 import java.io.FileNotFoundException; 28 34 import java.io.InputStream; 29 35 import java.net.URL; 30 36 import java.nio.charset.Charset; 37 38 import org.apache.commons.collections.CollectionUtils; 39 import org.apache.commons.collections.Predicate; 40 41 import net.sf.basedb.util.ComparableComparator; 31 42 import net.sf.basedb.util.FileUtil; 43 import net.sf.basedb.util.PriorityComparator; 32 44 33 45 /** … … 60 72 private static Locale locale = Locale.getDefault(); 61 73 74 private static SortedSet<String> commonCharsets; 75 76 private static SortedSet<String> allCharsets; 77 62 78 /** 63 79 Loads the settings from the configuration file. … … 93 109 if (is != null) FileUtil.close(is); 94 110 } 111 95 112 isInitialised = true; 96 113 97 114 // Load locale 98 115 String language = getString("locale.language", ""); … … 107 124 locale = Locale.getDefault(); 108 125 } 126 127 // Load character sets 128 String charsets = getString("commonCharsets", "UTF-8,US-ASCII,ISO-8859-1").trim(); 129 commonCharsets = Collections.unmodifiableSortedSet(new TreeSet<String>(Arrays.asList(charsets.split("\\s*,\\s*")))); 130 131 SortedSet<String> tmp = new TreeSet<String>( 132 new PriorityComparator<String>(commonCharsets, 133 new ComparableComparator<String>())); 134 tmp.addAll(Charset.availableCharsets().keySet()); 135 String filter = getString("ignoreCharsets", null); 136 if (filter != null) 137 { 138 try 139 { 140 final Pattern p = Pattern.compile(filter); 141 CollectionUtils.filter(tmp, new Predicate() 142 { 143 @Override 144 public boolean evaluate(Object o) 145 { 146 return !p.matcher((String)o).matches() || commonCharsets.contains(o); 147 } 148 }); 149 } 150 catch (PatternSyntaxException ex) 151 { 152 isInitialised = false; 153 throw new ConfigurationException("Invalid pattern for 'ignoreCharsets' property in '/base.config'. ", ex); 154 } 155 } 156 allCharsets = Collections.unmodifiableSortedSet(tmp); 109 157 } 110 158 … … 274 322 275 323 /** 324 Get a set containing the most common character sets used by text files. 325 The set is sorted by name. 326 @return A sorted set 327 @since 2.17 328 */ 329 public static SortedSet<String> getCommonCharsets() 330 { 331 return commonCharsets; 332 } 333 334 /** 335 Get a set containing all character sets known to the current java virtual machine. 336 The set is sorted by name with the most common character sets first. 337 @return A sorted set 338 @since 2.17 339 */ 340 public static SortedSet<String> getAllCharsets() 341 { 342 return allCharsets; 343 } 344 345 /** 276 346 Get the default locale configured for the server. 277 347 @since 2.16 -
trunk/src/plugins/core/net/sf/basedb/plugins/util/Parameters.java
r5430 r5570 22 22 package net.sf.basedb.plugins.util; 23 23 24 import java.nio.charset.Charset;25 24 import java.text.SimpleDateFormat; 26 25 import java.util.ArrayList; … … 307 306 private static final StringParameterType charsetType = 308 307 new StringParameterType(255, Config.getCharset(), false, 1, 0, 0, 309 new ArrayList<String>(C harset.availableCharsets().keySet()));308 new ArrayList<String>(Config.getAllCharsets())); 310 309 311 310 -
trunk/www/common/import/select_file.jsp
r5558 r5570 217 217 <% 218 218 String defaultCharset = Config.getCharset(); 219 for (String charset : Charset.availableCharsets().keySet()) 219 int numCommon = Config.getCommonCharsets().size(); 220 int i = 0; 221 for (String charset : Config.getAllCharsets()) 220 222 { 221 223 %> 222 224 <option value="<%=charset%>" 223 <%=defaultCharset.equalsIgnoreCase(charset) ? "selected" : ""%>><%=charset%> 225 <%=defaultCharset.equalsIgnoreCase(charset) ? "selected" : ""%> 226 <%=i==numCommon ? "style=\"border-top: 1px solid #666666;\"" : "" %>><%=charset%> 224 227 <% 228 i++; 225 229 } 226 230 %> -
trunk/www/common/plugin/test_with_file.jsp
r5558 r5570 339 339 <% 340 340 String defaultCharset = Config.getCharset(); 341 for (String charset : Charset.availableCharsets().keySet()) 341 int numCommon = Config.getCommonCharsets().size(); 342 int i = 0; 343 for (String charset : Config.getAllCharsets()) 342 344 { 343 345 %> 344 346 <option value="<%=charset%>" 345 <%=defaultCharset.equalsIgnoreCase(charset) ? "selected" : ""%>><%=charset%> 347 <%=defaultCharset.equalsIgnoreCase(charset) ? "selected" : ""%> 348 <%=i==numCommon ? "style=\"border-top: 1px solid #666666;\"" : "" %>><%=charset%> 346 349 <% 350 i++; 347 351 } 348 352 %> -
trunk/www/filemanager/files/edit_file.jsp
r5569 r5570 29 29 import="net.sf.basedb.core.DbControl" 30 30 import="net.sf.basedb.core.Item" 31 import="net.sf.basedb.core.Config" 31 32 import="net.sf.basedb.core.SystemItems" 32 33 import="net.sf.basedb.core.ItemContext" … … 340 341 String currentCharset = file == null ? 341 342 Values.getString(cc.getPropertyValue("characterSet")) : file.getCharacterSet(); 343 int numCommon = Config.getCommonCharsets().size(); 344 int i = 0; 342 345 boolean hasMatched = false; 343 for (String charset : C harset.availableCharsets().keySet())346 for (String charset : Config.getAllCharsets()) 344 347 { 345 boolean selected = charset.equalsIgnoreCase(currentCharset); 346 hasMatched |= selected; 348 boolean selected = false; 349 if (!hasMatched) 350 { 351 selected = charset.equalsIgnoreCase(currentCharset); 352 hasMatched |= selected; 353 } 347 354 %> 348 <option value="<%=charset%>" <%=selected ? "selected" : ""%>><%=charset%> 355 <option value="<%=charset%>" <%=selected ? "selected" : ""%> 356 <%=i==numCommon ? "style=\"border-top: 1px solid #666666;\"" : "" %>><%=charset%> 349 357 <% 358 i++; 350 359 } 351 360 if (!hasMatched && currentCharset != null) -
trunk/www/filemanager/files/edit_multiple_file.jsp
r5569 r5570 29 29 import="net.sf.basedb.core.DbControl" 30 30 import="net.sf.basedb.core.Item" 31 import="net.sf.basedb.core.Config" 31 32 import="net.sf.basedb.core.SystemItems" 32 33 import="net.sf.basedb.core.ItemContext" … … 182 183 <option value="">- n/a - 183 184 <% 184 for (String charset : Charset.availableCharsets().keySet()) 185 int numCommon = Config.getCommonCharsets().size(); 186 int i = 0; 187 for (String charset : Config.getAllCharsets()) 185 188 { 186 189 %> 187 <option value="<%=charset%>" ><%=charset%>190 <option value="<%=charset%>" <%=i==numCommon ? "style=\"border-top: 1px solid #666666;\"" : "" %>><%=charset%> 188 191 <% 192 i++; 189 193 } 190 194 %> -
trunk/www/filemanager/upload/select.jsp
r5554 r5570 30 30 import="net.sf.basedb.core.SessionControl" 31 31 import="net.sf.basedb.core.DbControl" 32 import="net.sf.basedb.core.Config" 32 33 import="net.sf.basedb.core.Item" 33 34 import="net.sf.basedb.core.SystemItems" … … 486 487 <% 487 488 String currentCharset = file == null ? null : file.getCharacterSet(); 489 int numCommon = Config.getCommonCharsets().size(); 490 int i = 0; 488 491 boolean hasSelected = false; 489 for (String charset : C harset.availableCharsets().keySet())492 for (String charset : Config.getAllCharsets()) 490 493 { 491 boolean selected = charset.equalsIgnoreCase(currentCharset); 492 hasSelected |= selected; 494 boolean selected = false; 495 if (!hasSelected) 496 { 497 selected = charset.equalsIgnoreCase(currentCharset); 498 hasSelected |= selected; 499 } 493 500 %> 494 <option value="<%=charset%>" <%=selected ? "selected" : ""%>><%=charset%> 501 <option value="<%=charset%>" <%=selected ? "selected" : ""%> 502 <%=i==numCommon ? "style=\"border-top: 1px solid #666666;\"" : "" %>><%=charset%> 495 503 <% 504 i++; 496 505 } 497 506 if (!hasSelected && currentCharset != null)
Note: See TracChangeset
for help on using the changeset viewer.