Project

General

Profile

« Previous | Next » 

Revision 86cc5c9a

Added by Alexander Oppermann over 9 years ago

refactored default language selection methods.

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.preference;
11 11

  
12
import java.io.File;
13
import java.io.FileInputStream;
14
import java.io.FileOutputStream;
15
import java.io.IOException;
12 16
import java.util.Arrays;
13 17
import java.util.HashMap;
14 18
import java.util.List;
15 19
import java.util.Map;
20
import java.util.Properties;
16 21
import java.util.Set;
17 22
import java.util.UUID;
18 23

  
......
595 600
		return configurator;
596 601
	}
597 602

  
603
	/**
604
	 * This method will write language properties to the config.ini located in the configuration folder
605
	 * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
606
	 *
607
	 * @param setLanguage 0 is for german and 1 for english.
608
	 * @throws IOException
609
	 */
610
    public void writePropertyToConfigFile(int setLanguage) throws IOException {
611
        File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile();
612
        Properties properties = load(file.getAbsolutePath()+"/config.ini");
613
        switch(setLanguage){
614
        case 0:
615
            properties.setProperty("osgi.nl", "de");
616
            PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de");
617
            break;
618
        case 1:
619
            properties.setProperty("osgi.nl", "en");
620
            PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en");
621
            break;
622
        default:
623
            break;
624
        }
625
        save(file+"/config.ini", properties);
626
    }
627

  
628
    /**
629
     * This method loads a property from a given file and returns it.
630
     *
631
     * @param filename
632
     * @return
633
     * @throws IOException
634
     */
635
    private Properties load(String filename) throws IOException {
636
        FileInputStream in = new FileInputStream(filename);
637
        Properties prop = new Properties();
638
        prop.load(in);
639
        in.close();
640
        return prop;
641
    }
642

  
643
    /**
644
     * This method saves a property to the specified file.
645
     *
646
     * @param filename
647
     * @param properties
648
     * @throws IOException
649
     */
650
    private void save(String filename, Properties properties) throws IOException{
651
        FileOutputStream fos =  new FileOutputStream(filename);
652
        properties.store(fos, "");
653
        fos.close();
654
    }
655

  
598 656
}

Also available in: Unified diff