1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets; 22 23 24 import java.nio.charset.Charset ; 25 26 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants; 27 28 29 39 public class FileEncodingInput extends OptionsInput 40 { 41 42 48 public FileEncodingInput( String initialRawValue, boolean asGroup ) 49 { 50 super( "File Encoding", getDefaultDisplayValue(), getDefaultRawValue(), getOtherDisplayValues(), 51 getOtherRawValues(), initialRawValue, asGroup, false ); 52 53 } 54 55 56 61 private static String getDefaultDisplayValue() 62 { 63 return getCharsetDisplayValue( getDefaultRawValue() ); 64 } 65 66 67 73 private static String getDefaultRawValue() 74 { 75 return BrowserCoreConstants.DEFAULT_ENCODING; 76 } 77 78 79 84 private static String [] getOtherDisplayValues() 85 { 86 String [] otherEncodingsRawValues = getOtherRawValues(); 87 String [] otherEncodingsDisplayValues = new String [otherEncodingsRawValues.length]; 88 for ( int i = 0; i < otherEncodingsDisplayValues.length; i++ ) 89 { 90 String rawValue = otherEncodingsRawValues[i]; 91 otherEncodingsDisplayValues[i] = getCharsetDisplayValue( rawValue ); 92 } 93 return otherEncodingsDisplayValues; 94 } 95 96 97 103 private static String [] getOtherRawValues() 104 { 105 String [] otherEncodingsRawValues = ( String [] ) Charset.availableCharsets().keySet().toArray( new String [0] ); 106 return otherEncodingsRawValues; 107 } 108 109 110 117 private static String getCharsetDisplayValue( String charsetRawValue ) 118 { 119 try 120 { 121 Charset charset = Charset.forName( charsetRawValue ); 122 return charset.displayName(); 123 } 124 catch ( Exception e ) 125 { 126 return charsetRawValue; 127 } 128 } 129 130 } 131 | Popular Tags |