Text file encoding

If your plug-in reads text files, it should honor the text file encoding preference in the workbench. 

Text files are encoded differently depending on the platform and the locale.  Most of the time, using the default text file encoding for the locale of the host operating system is good enough.  However, a user may want to work with text files that originate from another source.  Given the ability to use Eclipse in a networked team environment, it's certainly possible that users will want to work with text files that use a different encoding scheme than their native encoding scheme so that they can easily interchange files with another team.

For this reason, the workbench defines its own encoding profile that is specified by the user in the Preferences dialog.  Plug-ins that interpret text files, such as editors and builders, should consult the workbench encoding preference rather than assume that the installed operating system encoding is in use.

The current encoding preference can be obtained from the resources plug-in using ResourcesPlugin.getEncoding().  This encoding should be passed to java.io readers instead of using the default system encoding.

If you need to track changes to this preference, you can hook a listener on the ResourcesPlugin preferences and react to changes in ResourcesPlugin.PREF_ENCODING.  The following example comes from the default text editor:

public void initialize(StatusTextEditor textEditor) {
	
	fTextEditor= textEditor;
	
	fPropertyChangeListener= new Preferences.IPropertyChangeListener() {
		public void propertyChange(Preferences.PropertyChangeEvent e) {
			if (ResourcesPlugin.PREF_ENCODING.equals(e.getProperty()))
				setEncoding(null, false);
		}
	};
		
	Preferences p= ResourcesPlugin.getPlugin().getPluginPreferences();
	p.addPropertyChangeListener(fPropertyChangeListener);
	
	fEncodingActionGroup= new EncodingActionGroup(fTextEditor);
	fEncodingActionGroup.update();
}

 

Copyright IBM Corp. and others 2000,2002.