Revision 39248

View differences:

tags/v2_0_0_Build_2058/libraries/libInternationalization/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4

  
5
    <modelVersion>4.0.0</modelVersion>
6
    <artifactId>org.gvsig.i18n</artifactId>
7
    <packaging>jar</packaging>
8
    <version>2.0.1-SNAPSHOT</version>
9
    <name>libInternationalization</name>
10
    <description>Management of texts related to a locale: 
11
    loading from resource bundles and getting the text value for the current locale</description>
12
    <parent>
13
        <groupId>org.gvsig</groupId>
14
        <artifactId>org.gvsig.maven.base.pom</artifactId>
15
        <version>1.0.8-SNAPSHOT</version>
16
    </parent>
17
    <scm>
18
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/branches/v2_0_0_prep/libraries/libInternationalization</connection>
19
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-desktop/branches/v2_0_0_prep/libraries/libInternationalization</developerConnection>
20
        <url>https://devel.gvsig.org/redmine/projects/gvsig-desktop/repository/show/branches/v2_0_0_prep/libraries/libInternationalization</url>
21
    </scm>
22
    <repositories>
23
        <repository>
24
            <id>gvsig-public-http-repository</id>
25
            <name>gvSIG maven public HTTP repository</name>
26
            <url>http://devel.gvsig.org/m2repo/j2se</url>
27
            <releases>
28
                <enabled>true</enabled>
29
                <updatePolicy>daily</updatePolicy>
30
                <checksumPolicy>warn</checksumPolicy>
31
            </releases>
32
            <snapshots>
33
                <enabled>true</enabled>
34
                <updatePolicy>daily</updatePolicy>
35
                <checksumPolicy>warn</checksumPolicy>
36
            </snapshots>
37
        </repository>
38
    </repositories>
39
    <dependencyManagement>
40
        <dependencies>
41
            <dependency>
42
                <groupId>org.gvsig</groupId>
43
                <artifactId>org.gvsig.core.maven.dependencies</artifactId>
44
                <version>2.0.1-SNAPSHOT</version>
45
                <type>pom</type>
46
                <scope>import</scope>
47
            </dependency>
48
        </dependencies>
49
    </dependencyManagement>
50
            
51
    <dependencies>
52
        <dependency>
53
            <groupId>org.slf4j</groupId>
54
            <artifactId>slf4j-api</artifactId>
55
            <scope>compile</scope>
56
        </dependency>
57
        <dependency>
58
            <groupId>org.slf4j</groupId>
59
            <artifactId>slf4j-log4j12</artifactId>
60
            <scope>runtime</scope>
61
        </dependency>
62
        <dependency>
63
			<groupId>org.gvsig</groupId>
64
			<artifactId>org.gvsig.tools.lib</artifactId>
65
            <scope>compile</scope>	
66
		</dependency>
67
    </dependencies>
68
    <build>
69
        <sourceDirectory>src</sourceDirectory>
70
        <testSourceDirectory>src-test</testSourceDirectory>
71
        <resources>
72
            <resource>
73
                <targetPath>org/gvsig/i18n/resources/translations</targetPath>
74
                <filtering>false</filtering>
75
                <directory>${basedir}/config</directory>
76
                <includes>
77
                    <include>*.properties</include>
78
                </includes>
79
            </resource>
80
            <resource>
81
                <directory>${basedir}/resources</directory>
82
            </resource>
83
        </resources>
84
        <plugins>
85
            <plugin>
86
                <groupId>org.apache.maven.plugins</groupId>
87
                <artifactId>maven-compiler-plugin</artifactId>
88
                <configuration>
89
                    <source>1.4</source>
90
                    <target>1.4</target>
91
                    <encoding>ISO-8859-1</encoding>
92
                </configuration>
93
            </plugin>
94
        </plugins>
95
    </build>
96
    
97
    <profiles>
98
        <profile>
99
            <id>eclipse-project</id>
100
            <build>
101
                <plugins>
102
                    <plugin>
103
                        <artifactId>maven-antrun-plugin</artifactId>
104
                        <configuration>
105
                            <tasks>
106
                                <ant antfile="${basedir}/../build/ant-tasks/eclipse-tasks.xml" target="eclipse.eclipse" />
107
                            </tasks>
108
                        </configuration>
109
                        <dependencies>
110
                            <dependency>
111
                                <groupId>org.apache.ant</groupId>
112
                                <artifactId>ant-trax</artifactId>
113
                                <version>1.7.1</version>
114
                            </dependency>
115
                            <dependency>
116
                                <groupId>xalan</groupId>
117
                                <artifactId>xalan</artifactId>
118
                                <version>2.6.0</version>
119
                            </dependency>
120
                        </dependencies>
121
                    </plugin>
122
                </plugins>
123
            </build>
124
        </profile>
125
        <profile>
126
            <id>gvsig-install</id>
127
            <activation>
128
                <activeByDefault>true</activeByDefault>
129
            </activation>
130
            <properties>
131
                <!--  gvSIG installation folder -->
132
                <gvsig.install.dir>${basedir}/../build/product</gvsig.install.dir>
133
            </properties>
134
        </profile>
135
    </profiles>
136
    <properties>
137
        <eclipse.project.name>libInternationalization</eclipse.project.name>
138
    </properties>
139
</project>
tags/v2_0_0_Build_2058/libraries/libInternationalization/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.i18n.MessagesLibrary
tags/v2_0_0_Build_2058/libraries/libInternationalization/.cvsignore
1
bin
2
bin-test
3
bin-utils
4
doc
0 5

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-utils-test/org/gvsig/i18n/utils/TestUtils.java
1
package org.gvsig.i18n.utils;
2

  
3
import java.io.File;
4
import java.io.IOException;
5

  
6
import junit.framework.TestCase;
7

  
8
/**
9
 * @author cesar
10
 *
11
 */
12
public class TestUtils extends TestCase {
13
	
14
	public ConfigOptions loadConfig() {
15
		ConfigOptions config = new ConfigOptions();
16
		config.setConfigFile("src-test"+File.separator+"org"+File.separator+"gvsig"+File.separator+"i18n"+File.separator+"utils"+File.separator+"config.xml");
17
		config.load();
18
		return config;
19
	}
20
	
21
	public void testConfigOptions() {
22
		ConfigOptions config = loadConfig();
23
		
24
		String databaseDir=null, basedir=null;
25
		try {
26
			databaseDir = new File("test-data/database").getCanonicalPath();
27
			basedir =  new File("test-data").getCanonicalPath();
28
		} catch (IOException e) {
29
			// TODO Auto-generated catch block
30
			e.printStackTrace();
31
		}
32
		
33
		// the values of the projects. They are pairs (dir, basename).
34
		String projectValues[]={"src/appgvSIG", "otro", "sources", "src/_fwAndami", "text", "sources"};
35
		for (int i=0; i<projectValues.length; i=i+3) {
36
			try {
37
				// set the canonical path
38
				projectValues[i]= new File(basedir+File.separator+projectValues[i]).getCanonicalPath();
39
			} catch (IOException e) {
40
				// TODO Auto-generated catch block
41
				e.printStackTrace();
42
			}
43
		}
44
		
45
		TestCase.assertEquals(databaseDir, config.databaseDir);
46
		TestCase.assertEquals(basedir, config.defaultBaseDir);
47
		TestCase.assertEquals("text", config.defaultBaseName);
48
		
49
		String languages = config.languages[0];
50
		for (int i=1; i<config.languages.length; i++) {
51
			languages=languages+";"+config.languages[i];
52
		}
53
		TestCase.assertEquals("ca;cs;de;en;es;eu;fr;gl;it;pt", languages);
54
		
55
		for (int i=0; i<config.projects.size(); i=i+3) {
56
			Project project = (Project) config.projects.get(i);
57
			TestCase.assertEquals(projectValues[i], project.dir);
58
			TestCase.assertEquals(projectValues[i+1], project.basename);
59
			TestCase.assertEquals(projectValues[i+2], project.sourceKeys);
60
		}
61
	}
62
	
63
	public void testTranslationDatabase() {
64
		ConfigOptions config = loadConfig();
65
		TranslationDatabase database = new TranslationDatabase(config);
66
		database.load();
67
		TestCase.assertEquals("A?adir Capa" , database.getTranslation("es", "Anadir_Capa"));
68
		TestCase.assertEquals("Add Layer" , database.getTranslation("en", "Anadir_Capa"));
69
		TestCase.assertEquals("Afegir Capa" , database.getTranslation("ca", "Anadir_Capa"));
70
		TestCase.assertEquals("Layer hinzuf?gen" , database.getTranslation("de", "Anadir_Capa"));
71
		TestCase.assertEquals("Ayuda" , database.getTranslation("es", "Ayuda"));
72
		TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe"));
73
		
74
		// add a translation
75
		database.setTranslation("es", "test_case.clave_que_no_existe", "Clave que no existe");
76
		// is it present now?
77
		TestCase.assertEquals("Clave que no existe" , database.getTranslation("es", "test_case.clave_que_no_existe"));
78
		
79
		// remove the translation
80
		database.removeTranslation("es", "test_case.clave_que_no_existe");
81
		// was really removed?
82
		TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe"));
83
		
84
		// add the translation again
85
		database.setTranslation("es", "test_case.clave_que_no_existe", "Clave que no existe");
86
		// save to disk
87
		database.save();
88
		// load from disk
89
		database.load();
90
		// is the translation still there?
91
		TestCase.assertEquals("Clave que no existe" , database.getTranslation("es", "test_case.clave_que_no_existe"));
92
		
93
		// remove the translation again and save to disk
94
		database.removeTranslation("es", "test_case.clave_que_no_existe");
95
		TestCase.assertEquals(null , database.getTranslation("es", "test_case.clave_que_no_existe"));
96
		TestCase.assertEquals("", database.getTranslation("es", "prueba"));
97
		database.save();
98
	}
99

  
100
	public void testKeys() {
101
		ConfigOptions config = loadConfig();
102
		Keys keys = new Keys(config);
103
		keys.load();
104
	}
105

  
106
}
0 107

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-utils-test/org/gvsig/i18n/utils/config.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<config>
3
	<!-- Aquí especificamos algunas variables de configuración -->
4
	<!-- En este fichero se muestran todas las opciones posibles, en sus valores por defecto -->
5

  
6
	<!-- Nombre base por defecto de los ficheros con las traducciones. En nuestro caso suele ser "text",
7
		de forma que los ficheros toman nombres como "text.properties", "text_en.properties". Nótese
8
		que sólo es el nombre por defecto. Cada proyecto puede especificar un baseName distinto -->
9
	<variable name="basename" value="text" />
10

  
11
	<!-- Directorio base. Las rutas relativas especificadas en otras variables (databaseDir, directorios
12
		de proyecto) tomarán este directorio como directorio base.  Por defecto es el directorio
13
		desde el que se llama a la aplicación -->
14
	<variable name="basedir" value="test-data" />
15

  
16
	<!-- Lista de idiomas que se tendrán en cuenta  -->
17
	<variable name="languages" value="ca;cs;de;en;es;eu;fr;gl;it;pt" />
18
	
19
	<!-- El directorio que contendrá la base de datos de traducciones por idioma. Por defecto es el
20
		directorio "database", relativo al directorio especificado en la variable "basedir".  -->
21
	<variable name="databaseDir" value="database" />
22
	
23
		<!-- El directorio por defecto que contendrá los property files que almacenan las claves de cada
24
	 proyecto". Esto se usa en los proyectos que no especifican un atributo "propertyDir". Si el
25
	 directorio no es absoluto, entonces es relativo al directorio de cada proyecto. -->
26
	<variable name="defaultPropertyDir" value="config" />
27
	
28
	<variable name="sourceKeys" value="sources" />
29
</config>
30
<projects>
31
	<!-- Los proyectos que se van a leer. Es necesario especificar un directorio (relativo o absoluto),
32
		y opcionalmente se puede incluir un atributo "basename" para especificar un nombre base
33
		distinto del nombre base por defecto -->
34
	<!-- The projects which are going to be read. An absolute or relative directory name must be specified,
35
		in which the property files are located. An optional "basename" attribute is also accepted,
36
		to override the default basename -->
37
	<project dir="src/appgvSIG" basename="otro"  sourceKeys="sources" propertyDir="config" />
38
	<project dir="src/_fwAndami" />
39
</projects>
0 40

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-utils-test/org/gvsig/i18n/utils/TestProperties.java
1
package org.gvsig.i18n.utils;
2

  
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileNotFoundException;
6
import java.io.FileOutputStream;
7
import java.io.IOException;
8
import java.io.InputStream;
9
import java.io.OutputStream;
10

  
11
import junit.framework.TestCase;
12

  
13
/**
14
 * @author cesar
15
 *
16
 */
17
public class TestProperties extends TestCase {
18
	static final String fileName = "TestProperties-file";
19
	InputStream is;
20
	OutputStream os;
21
	
22
	public void initOutputStream() {
23
		try {
24
			os = new FileOutputStream(fileName);
25
		} catch (FileNotFoundException e) {
26
			TestCase.fail(e.getLocalizedMessage());
27
		}
28
	}
29
	
30
	public void discardOutputStream() {
31
		try {
32
			os.close();
33
			File file = new File(fileName);
34
			file.delete();
35
		} catch (IOException e) {
36
			TestCase.fail(e.getLocalizedMessage());
37
		}
38
	}
39
	
40
	public void initInputStream() {
41
		try {
42
			is = new FileInputStream(fileName);
43
		} catch (FileNotFoundException e) {
44
			TestCase.fail(e.getLocalizedMessage());
45
		}
46
	}
47
	
48
	public void discardInputStream() {
49
		try {
50
			is.close();
51
		} catch (IOException e) {
52
			TestCase.fail(e.getLocalizedMessage());
53
		}
54
	}
55
	
56
	public void testOrderedPropertiesBasic() {
57
		// write file
58
		OrderedProperties props1 = new OrderedProperties();
59
		props1.setProperty("prueba", "hola");
60
		props1.setProperty("prueba2", "holas");
61
		props1.setProperty("abrir", "cerrar");
62
		props1.setProperty("puerta", "hembrilla");
63
		props1.setProperty("12libros", "quijote");
64
		props1.setProperty("ca?uto", "\u20acuropeo");
65
		props1.setProperty("confli=cto", "amigo");
66
		props1.setProperty("  confli =  :cto mayor ", " peque?o conflicto");
67
		initOutputStream();
68
		try {
69
			props1.store(os, "header");
70
		} catch (IOException e) {
71
			TestCase.fail(e.getLocalizedMessage());
72
		}
73
		
74
		// read file
75
		OrderedProperties props2 = new OrderedProperties();
76
		initInputStream();
77
		try {
78
			props2.load(is);
79
		} catch (IOException e) {
80
			TestCase.fail(e.getLocalizedMessage());
81
		}
82
		TestCase.assertEquals("\u20acuropeo", props2.getProperty("ca?uto"));
83
		TestCase.assertEquals("amigo", props2.getProperty("confli=cto"));
84
		TestCase.assertEquals(" peque?o conflicto", props2.getProperty("  confli =  :cto mayor "));
85
		TestCase.assertEquals("hola", props2.getProperty("prueba"));
86
		TestCase.assertEquals("holas", props2.getProperty("prueba2"));
87
		TestCase.assertEquals("cerrar", props2.getProperty("abrir"));
88
		TestCase.assertEquals("hembrilla", props2.getProperty("puerta"));
89
		TestCase.assertEquals("quijote", props2.getProperty("12libros"));
90
		discardInputStream();
91
		discardOutputStream();
92
	}
93

  
94
	
95
	public void testOrderedProperties() {
96
		// write file
97
		OrderedProperties props1 = new OrderedProperties();
98
		props1.setProperty("prueba", "hola");
99
		props1.setProperty("prueba2", "holas");
100
		props1.setProperty("ca?uto", "\u20acuropeo");
101
		props1.setProperty("confli=cto", "amigo");
102
		props1.setProperty("  conflis =  :cto mayor ", " peque?o conflicto");
103
		props1.setProperty("abrir", "cerrar");
104
		props1.setProperty("puerta", "hembrilla");
105
		props1.setProperty("12libros", "quijote");
106
		initOutputStream();
107
		try {
108
			props1.store(os, "header", "8859_15");
109
		} catch (IOException e) {
110
			TestCase.fail(e.getLocalizedMessage());
111
		}
112
		
113
		// read file
114
		OrderedProperties props2 = new OrderedProperties();
115
		initInputStream();
116
		try {
117
			props2.load(is, "8859_15");
118
		} catch (IOException e) {
119
			TestCase.fail(e.getLocalizedMessage());
120
		}
121
		// estos deber?an salir igual
122
		TestCase.assertEquals("hola", props2.getProperty("prueba"));
123
		TestCase.assertEquals("holas", props2.getProperty("prueba2"));
124
		TestCase.assertEquals("cerrar", props2.getProperty("abrir"));
125
		TestCase.assertEquals("hembrilla", props2.getProperty("puerta"));
126
		TestCase.assertEquals("quijote", props2.getProperty("12libros"));
127
		// con estos en cambio no obtenemos los mismos valores que escribimos anteriormente. Es normal, porque incluimos
128
		// caracteres especiales como ":" y "=". Para manejarlos correctamente necesitamos usas los m?todos load/store
129
		// sin encoding, los cuales s? escapan los caracteres especiales
130
		TestCase.assertEquals("\u20acuropeo", props2.getProperty("ca?uto"));
131
		TestCase.assertEquals("cto=amigo", props2.getProperty("confli"));
132
		TestCase.assertEquals(":cto mayor = peque?o conflicto", props2.getProperty("conflis"));
133

  
134
		discardInputStream();
135
		discardOutputStream();
136
		
137
		// write file
138
		props1 = new OrderedProperties();
139
		props1.setProperty("Prueba", "hola");
140
		props1.setProperty("prueba2", "holas");
141
		props1.setProperty("ca?uto", "\u20acuropeo");
142
		props1.setProperty("confli=cto", "amigo");
143
		props1.setProperty("  conflis =  :cto mayor ", " peque?o conflicto");
144
		props1.setProperty("abrir", "cerrar");
145
		props1.setProperty("puerta", "hembrilla");
146
		props1.setProperty("12libros", "quijote");
147
		initOutputStream();
148
		try {
149
			props1.store(os, "header", "UTF8");
150
		} catch (IOException e) {
151
			TestCase.fail(e.getLocalizedMessage());
152
		}
153
		
154
		// read file
155
		props2 = new OrderedProperties();
156
		initInputStream();
157
		try {
158
			props2.load(is, "UTF8");
159
		} catch (IOException e) {
160
			TestCase.fail(e.getLocalizedMessage());
161
		}
162
		// estos deber?an salir igual
163
		TestCase.assertEquals("hola", props2.getProperty("Prueba"));
164
		TestCase.assertEquals("holas", props2.getProperty("prueba2"));
165
		TestCase.assertEquals("cerrar", props2.getProperty("abrir"));
166
		TestCase.assertEquals("hembrilla", props2.getProperty("puerta"));
167
		TestCase.assertEquals("quijote", props2.getProperty("12libros"));
168
		// con estos en cambio no obtenemos los mismos valores que escribimos anteriormente. Es normal, porque incluimos
169
		// caracteres especiales como ":" y "=". Para manejarlos correctamente necesitamos usas los m?todos load/store
170
		// sin encoding, los cuales s? escapan los caracteres especiales
171
		TestCase.assertEquals("\u20acuropeo", props2.getProperty("ca?uto"));
172
		TestCase.assertEquals("cto=amigo", props2.getProperty("confli"));
173
		TestCase.assertEquals(":cto mayor = peque?o conflicto", props2.getProperty("conflis"));
174

  
175
		discardInputStream();
176
		discardOutputStream();
177
	}
178
	
179
}
0 180

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-test/org/gvsig/i18n/dataset1/text.properties
1
#text.properties
2
aceptar=Aceptar
3
cancelar=Cancelar
4
Cascada=Cascada
5
cascada_enable=Debe haber al menos una ventana abierta
0 6

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-test/org/gvsig/i18n/dataset1/text_en.properties
1
#text_en.properties
2
aceptar=OK
3
cancelar=Cancel
4
Cascada=Cascade
5
ventana=Window
6
otro=other
0 7

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-test/org/gvsig/i18n/dataset1/text_fr.properties
1
#text_fr.properties
2
aceptar=Accepter
3
Cascada=Cascade
4
Configurar=Configurer
0 5

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-test/org/gvsig/i18n/TestMessages.java
1
/**
2
 * 
3
 */
4
package org.gvsig.i18n;
5

  
6
import java.io.File;
7
import java.net.MalformedURLException;
8
import java.util.ArrayList;
9
import java.util.Locale;
10

  
11
import junit.framework.TestCase;
12

  
13
/**
14
 * @author cesar
15
 *
16
 */
17
public class TestMessages extends TestCase {
18

  
19
	/*
20
	 * @see TestCase#setUp()
21
	 */
22
	protected void setUp() throws Exception {
23
		super.setUp();
24
	}
25

  
26
	/*
27
	 * @see TestCase#tearDown()
28
	 */
29
	protected void tearDown() throws Exception {
30
		super.tearDown();
31
	}
32
	
33
	public void testSetPreferredLocales() {
34
		setPreferredLocales();
35
		removeLocales();
36
	}
37
	
38
	private void setPreferredLocales() {
39
		ArrayList preferred = new ArrayList();
40
		preferred.add(new Locale("en"));
41
		preferred.add(new Locale("es"));
42
		Messages.setPreferredLocales(preferred);
43
		ArrayList resultPref = Messages.getPreferredLocales();
44
		
45
		TestCase.assertEquals(resultPref.size(), 2);
46
		
47
		Locale lang1 = (Locale) resultPref.get(0);		
48
		TestCase.assertEquals(lang1.getLanguage(), "en");
49
		Locale lang2 = (Locale) resultPref.get(1);		
50
		TestCase.assertEquals(lang2.getLanguage(), "es");
51
	}
52

  
53
	private void removeLocales() {	
54
		Locale lang1 = new Locale("en");
55
		Locale lang2 = new Locale("es");	
56
		ArrayList resultPref = Messages.getPreferredLocales();
57
		Messages.removeLocale(lang1);
58
		TestCase.assertEquals(resultPref.size(), 1);
59
		Messages.removeLocale(lang2);		
60
		TestCase.assertEquals(resultPref.size(), 0);
61
	}
62
	
63
	public void testAddResourceFamily() {
64
		setPreferredLocales();
65
		//this.getClass().getClassLoader().getResource("text_en.properties");
66

  
67
		try {
68
			Messages.addResourceFamily("text", new File("src-test/org/gvsig/i18n/dataset1/"));
69
		} catch (MalformedURLException e) {
70
			TestCase.fail("Fichero de recursos no encontrado");
71
		}
72
		TestCase.assertEquals(5, Messages.size(new Locale("en")));
73
		TestCase.assertEquals(4,Messages.size(new Locale("es")));
74
		TestCase.assertEquals(0,Messages.size(new Locale("fr")));
75
		
76
		TestCase.assertEquals("OK", Messages.getText("aceptar"));
77
		TestCase.assertEquals("Cancel", Messages.getText("cancelar"));
78
		TestCase.assertEquals("Cascade", Messages.getText("Cascada"));
79
		TestCase.assertEquals("Window", Messages.getText("ventana"));
80
		TestCase.assertEquals("Debe haber al menos una ventana abierta", Messages.getText("cascada_enable"));
81
		TestCase.assertEquals("Configurar", Messages.getText("Configurar"));
82
		TestCase.assertEquals(null, Messages.getText("Configurar", false));
83

  
84
		// load another file now
85
		try {
86
			Messages.addResourceFamily("text", new File(
87
                    "src-test/org/gvsig/i18n/dataset2/"));
88
		} catch (MalformedURLException e) {
89
			TestCase.fail("Fichero de recursos no encontrado");
90
		}
91
		// check that the right amount of translations was loaded
92
		TestCase.assertEquals(7, Messages.size(new Locale("en")));
93
		TestCase.assertEquals(6, Messages.size(new Locale("es")));
94
		TestCase.assertEquals(0, Messages.size(new Locale("fr")));
95

  
96
		// test that keys didn't get overwritten by the new files
97
		// (only new keys should have been added for each language)
98
		TestCase.assertEquals("OK", Messages.getText("aceptar"));
99
		TestCase.assertEquals("Cancel", Messages.getText("cancelar"));
100
		TestCase.assertEquals("Cascade", Messages.getText("Cascada"));
101
		// check the new keys
102
		TestCase.assertEquals("At least one window should be open", Messages.getText("cascada_enable"));
103
		TestCase.assertEquals("Insert first corner point", Messages.getText("insert_first_point_corner"));
104
		TestCase.assertEquals("Capa exportada", Messages.getText("capa_exportada"));
105
		TestCase.assertEquals("Circunscrito", Messages.getText("circumscribed"));
106
		
107
		Messages.removeResources();
108
		TestCase.assertEquals(0, Messages.size(new Locale("en")));
109
		TestCase.assertEquals(0, Messages.size(new Locale("es")));
110
		TestCase.assertEquals(0, Messages.size(new Locale("fr")));
111
		
112
		removeLocales();
113
	}
114
}
0 115

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-test/org/gvsig/i18n/dataset2/text_fr.properties
1
#text_fr.properties
2
aceptar=Accepter
3
Cascada=Cascade
4
Configurar=Configurer
0 5

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-test/org/gvsig/i18n/dataset2/text.properties
1
#text.properties
2
aceptar=baceptar
3
cancelar=amancebar
4
capa_exportada=Capa exportada
5
circumscribed=Circunscrito
0 6

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-test/org/gvsig/i18n/dataset2/text_en.properties
1
#text_en.properties
2
insert_first_point_corner=Insert first corner point
3
cascada_enable=At least one window should be open
4
cancelar=arancelar
0 5

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-test/org/gvsig/i18n/AllTests.java
1
package org.gvsig.i18n;
2

  
3
import junit.framework.Test;
4
import junit.framework.TestSuite;
5

  
6
public class AllTests {
7

  
8
	public static Test suite() {
9
		TestSuite suite = new TestSuite("Test for org.gvsig.i18n");
10
		//$JUnit-BEGIN$
11
		suite.addTestSuite(TestMessages.class);
12
		//$JUnit-END$
13
		return suite;
14
	}
15

  
16
}
0 17

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/config/text_en.properties
1
#Translations for language [en]
2
#Wed Nov 08 12:31:46 CET 2006
3
=\=\=\=\=\=\=
4
<<<<<<<=text_en.properties
5
>>>>>>>=1.6
6
aceptar=Accept
7
Las_traducciones_no_pudieron_ser_cargadas=Translations couldn't be loaded
8
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase=There is no list of favorite languages probably you forgot initialice the class
9
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=There is not preferred languages list. Maybe the Messages class was not initiated
10
No_se_encontro_la_traduccion_para=Cannot find translation for
0 11

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/config/text_gl.properties
1
#Translations for language [gl]
2
#Mon Oct 30 09:38:21 CET 2006
3
aceptar=Aceptar
4
Las_traducciones_no_pudieron_ser_cargadas=As traducci\u00f3ns non se puideron cargar
5
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase=
6
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=Non se atopou a lista de idiomas preferidos.Quiz\u00e1s non se lembrou de inicializar a clase
7
No_se_encontro_la_traduccion_para=Non se atopou a traducci\u00f3n para
0 8

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/config/text_ca.properties
1
#Translations for language [ca]
2
#Mon Oct 30 09:38:21 CET 2006
3
aceptar=Acceptar
4
Las_traducciones_no_pudieron_ser_cargadas=Les traduccions no s'han pogut carregar
5
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase=
6
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=No s'ha trobat la llista d'idiomes preferits. Potser ha oblidat inicialitzar la classe
7
No_se_encontro_la_traduccion_para=No s'ha trobat la traducci\u00f3 per a
0 8

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/config/text_pt.properties
1
#Translations for language [pt]
2
#Mon Oct 30 09:38:21 CET 2006
3
aceptar=Aceitar
4
Las_traducciones_no_pudieron_ser_cargadas=
5
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase=
6
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=
7
No_se_encontro_la_traduccion_para=N\u00e3o se encontrou a tradu\u00e7\u00e3o de
0 8

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/config/text_cs.properties
1
#Translations for language [cs]
2
#Mon Oct 30 09:38:21 CET 2006
3
aceptar=Budi\u017e
4
Las_traducciones_no_pudieron_ser_cargadas=
5
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase=
6
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=
7
No_se_encontro_la_traduccion_para=Nelze nal\u00e9zt p\u0159eklad pro
0 8

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/config/text_fr.properties
1
#Translations for language [fr]
2
#Mon Oct 30 09:38:21 CET 2006
3
aceptar=Accepter
4
Las_traducciones_no_pudieron_ser_cargadas=Les traductions ne peuvent pas \u00eatre charg\u00e9es.
5
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase=
6
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=Impossible de trouver la liste des langues pr\u00e9f\u00e9r\u00e9es. Vous avez peut-\u00eatre oubli\u00e9 d'installer la classe.
7
No_se_encontro_la_traduccion_para=Impossible de trouver les traductions pour
0 8

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/config/text_de.properties
1
#Translations for language [de]
2
#Mon Oct 30 09:38:21 CET 2006
3
aceptar=OK
4
Las_traducciones_no_pudieron_ser_cargadas=
5
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase=
6
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=
7
No_se_encontro_la_traduccion_para=Konnte \u00dcbersetzung nicht finden f\u00fcr\:
0 8

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/config/text_eu.properties
1
#Translations for language [eu]
2
#Mon Oct 30 09:38:21 CET 2006
3
aceptar=Ados
4
Las_traducciones_no_pudieron_ser_cargadas=Itzulpenak ezin izan dira kargatu
5
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase=
6
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=\=Ez da hobetsitako hizkuntzen zerrenda aurkitu. Agian klasea hasieratzea ahaztu zaizu
7
No_se_encontro_la_traduccion_para=Ez da itzulpenik aurkitu honetarako\:
0 8

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/config/text_it.properties
1
#Translations for language [it]
2
#Tue Nov 07 12:30:01 CET 2006
3
aceptar=Accetta
4
Las_traducciones_no_pudieron_ser_cargadas=
5
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase=
6
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=
7
No_se_encontro_la_traduccion_para=Non si \u00e9 incontrata la traduzione per
0 8

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/config/text.properties
1
#Translations for language [es]
2
#Mon Oct 30 09:38:21 CET 2006
3
aceptar=Aceptar
4
Las_traducciones_no_pudieron_ser_cargadas=Las traducciones no pudieron ser cargadas
5
No.hay.lista.de.idiomas.preferidos.quiza.olvido.inicializar.clase=No hay lista de idiomas preferidos. Quiza olvido inicializar la clase
6
No_hay_lista_de_idiomas_preferidos_quiza_olvido_inicializar_clase=No hay lista de idiomas preferidos. Quiz\u00e1 olvid\u00f3 inicializar la clase.
7
No_se_encontro_la_traduccion_para=No se encontr\u00f3 la traducci\u00f3n para
0 8

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-utils/org/gvsig/i18n/utils/ConfigOptions.java
1
package org.gvsig.i18n.utils;
2

  
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileNotFoundException;
6
import java.io.IOException;
7
import java.util.ArrayList;
8

  
9
import org.kxml2.io.KXmlParser;
10
import org.xmlpull.v1.XmlPullParserException;
11

  
12
public class ConfigOptions {
13
	// Default values
14
	public String defaultBaseName = "text";
15
	public String defaultBaseDir = ".";
16
	public String databaseDir = "database";
17
	private String configFileName = "config.xml";
18
	public String[] languages;
19
	public ArrayList projects = new ArrayList();
20
	private String defaultLangList="ca;cs;de;en;es;eu;fr;gl;it;pt";
21
	public String sourceKeys = "sources";
22
	private String defaultPropertyDir = "config";
23
	public String[] outputLanguages={"en", "es"};
24
	public String outputDir="output";
25
	public String inputDir="input";
26
	public String[] defaultSrcDirs={"src"};
27
	
28
	
29
	/**
30
	 * The character encoding of the Java source files, used to search keys in the sources.
31
	 */
32
	public String sourcesEncoding = "ISO8859_1";
33
	/**
34
	 * The character encoding of the generated output files for missing keys.
35
	 */
36
	public String outputEncoding = "UTF8";
37
	
38
	/**
39
	 * Creates a new ConfigOptions object.
40
	 */
41
	public ConfigOptions() {
42
		// Now we transform all directories to absolute canonical paths, so
43
		// that the are easier to manage afterwards.
44
		// It's also done at the end of parseVars method, but we must also do
45
		// it here, because parseVars() might not get executed.
46
		try {
47
			this.defaultBaseDir = getAbsolutePath(".", this.defaultBaseDir);
48
			this.databaseDir = getAbsolutePath(this.defaultBaseDir, this.databaseDir);
49
			this.outputDir = getAbsolutePath(this.defaultBaseDir, this.outputDir);
50
			this.inputDir = getAbsolutePath(this.defaultBaseDir, this.inputDir);
51
			
52
			/*
53
			 * 
54
			 File baseDirFile = new File(this.defaultBaseDir);
55
			this.defaultBaseDir = baseDirFile.getCanonicalPath();
56
			File databaseDirFile = new File(this.databaseDir);
57
			if (databaseDirFile.isAbsolute()) {
58
				this.databaseDir = databaseDirFile.getCanonicalPath();
59
			}
60
			else {
61
				this.databaseDir = (new File(this.defaultBaseDir+File.separator+this.databaseDir)).getCanonicalPath();
62
			}
63
			File outputDirFile = new File(this.outputDir);
64
			if (outputDirFile.isAbsolute()) {
65
				this.outputDir = outputDirFile.getCanonicalPath();
66
			}
67
			else {
68
				this.outputDir = (new File(this.defaultBaseDir+File.separator+this.outputDir)).getCanonicalPath();
69
			}
70
			File inputDirFile = new File(this.inputDir);
71
			if (inputDirFile.isAbsolute()) {
72
				this.inputDir = inputDirFile.getCanonicalPath();
73
			}
74
			else {
75
				this.inputDir = (new File(this.defaultBaseDir+File.separator+this.inputDir)).getCanonicalPath();
76
			}
77
			*/
78
		} catch (IOException e) {
79
			System.err.println("Error accediendo a los directorios de las traducciones: "+e.getLocalizedMessage());
80
		}
81
	}
82
	
83
	/**
84
	 *  Creates a new ConfigOptions object, defining the config file to use.
85
	 *  
86
	 * @param configFileName The file name of the config file to use.
87
	 */
88
	public ConfigOptions(String configFileName) {
89
		this.configFileName = configFileName;
90
		
91
		// Now we transform all directories to absolute canonical paths, so
92
		// that the are easier to manage afterwards.
93
		// It's also done at the end of parseVars method, but we must also do
94
		// it here, because parseVars() might not get executed.
95
		try {
96
			this.defaultBaseDir = getAbsolutePath(".", this.defaultBaseDir);
97
			this.databaseDir = getAbsolutePath(this.defaultBaseDir, this.databaseDir);
98
			this.outputDir = getAbsolutePath(this.defaultBaseDir, this.outputDir);
99
			this.inputDir = getAbsolutePath(this.defaultBaseDir, this.inputDir);
100
			
101
			/*File baseDirFile = new File(this.defaultBaseDir);
102
			this.defaultBaseDir = baseDirFile.getCanonicalPath();
103
			File databaseDirFile = new File(this.databaseDir);
104
			if (databaseDirFile.isAbsolute()) {
105
				this.databaseDir = databaseDirFile.getCanonicalPath();
106
			}
107
			else {
108
				this.databaseDir = (new File(this.defaultBaseDir+File.separator+this.databaseDir)).getCanonicalPath();
109
			}
110
			File outputDirFile = new File(this.outputDir);
111
			if (outputDirFile.isAbsolute()) {
112
				this.outputDir = outputDirFile.getCanonicalPath();
113
			}
114
			else {
115
				this.outputDir = (new File(this.defaultBaseDir+File.separator+this.outputDir)).getCanonicalPath();
116
			}
117
			File inputDirFile = new File(this.inputDir);
118
			if (inputDirFile.isAbsolute()) {
119
				this.inputDir = inputDirFile.getCanonicalPath();
120
			}
121
			else {
122
				this.inputDir = (new File(this.defaultBaseDir+File.separator+this.inputDir)).getCanonicalPath();
123
			}*/
124
		} catch (IOException e) {
125
			System.err.println("Error accediendo a los directorios de las traducciones: "+e.getLocalizedMessage());
126
		}
127
	}
128
	
129
	/**
130
	 * Sets the name of the config file to use.
131
	 * 
132
	 * @param configFileName
133
	 */
134
	public void setConfigFile(String configFileName) {
135
		this.configFileName = configFileName;
136
	}
137
	
138
	/**
139
	 * Gets the name of the config file in use.
140
	 * 
141
	 * @return The name of the config file in use.
142
	 */
143
	public String getConfigFile() {
144
		return configFileName;
145
	}
146
	
147
	/**
148
	 *  Loads the config parameters and the projects to consider from the XML
149
	 * config file */
150
	public boolean load() {
151
		KXmlParser parser = new KXmlParser();
152
		
153
		// we use null encoding, in this way kxml2 tries to detect the encoding
154
		try {
155
			parser.setInput(new FileInputStream(configFileName), null);
156
		} catch (FileNotFoundException e1) {
157
			System.err.println(e1.getLocalizedMessage());
158
			return false;
159
		} catch (XmlPullParserException e1) {
160
			// No podemos leer el fichero de configuraci?n. Usamos valores por defecto
161
			System.err.println("Aviso: no se pudo leer correctamente el fichero de configuraci?n. Se usar?n los valores por defecto.");
162
			return false;
163
		}
164
		
165
		try {
166
			for (parser.next(); parser.getEventType()!=KXmlParser.END_DOCUMENT; parser.next()) {
167
				// este bucle externo recorre las etiquetas de primer y segundo nivel
168
				if (parser.getEventType()==KXmlParser.START_TAG) {
169
					if (parser.getName().equals("config")) {
170
						parseVars(parser);
171
					}
172
					else if (parser.getName().equals("projects")) {
173
						parseProjects(parser);
174
					}
175
				}
176
			}	
177
		} catch (XmlPullParserException e1) {
178
			e1.getLocalizedMessage();
179
		} catch (IOException e1) {
180
			e1.getLocalizedMessage();
181
		}
182
		
183
		File outputDirFile = new File(outputDir);
184
		outputDirFile.mkdirs();
185
		File databaseDirFile = new File(databaseDir);
186
		databaseDirFile.mkdirs();
187
		return true;
188
	}
189

  
190
	private void parseVars(KXmlParser parser) throws XmlPullParserException, IOException {
191
		// recorremos todas las etiquetas 'variable' dentro de config
192
		int state;
193
		String name, value;
194
		
195
		for (state = parser.next(); state!=KXmlParser.END_TAG || !parser.getName().equals("config") ; state=parser.next()) {
196
			if (state==KXmlParser.START_TAG) {
197
				if (parser.getName().equals("variable")) {
198
					name = parser.getAttributeValue(null, "name");
199
					value = parser.getAttributeValue(null, "value");
200
					if (name!=null && value!=null) {
201
						value = parser.getAttributeValue(null, "value");
202
						if (parser.getAttributeValue(null, "name").equals("basename")) {
203
							defaultBaseName = parser.getAttributeValue(null, "value");
204
						}
205
						else if (parser.getAttributeValue(null, "name").equals("basedir")) {
206
							defaultBaseDir = parser.getAttributeValue(null, "value");
207
						}
208
						else if (parser.getAttributeValue(null, "name").equals("databaseDir")) {
209
							databaseDir = parser.getAttributeValue(null, "value");
210
						}
211
						else if (parser.getAttributeValue(null, "name").equals("defaultPropertyDir")) {
212
							defaultPropertyDir = parser.getAttributeValue(null, "value");
213
						}
214
						else if (parser.getAttributeValue(null, "name").equals("outputDir")) {
215
							outputDir = parser.getAttributeValue(null, "value");
216
						}
217
						else if (parser.getAttributeValue(null, "name").equals("inputDir")) {
218
							inputDir = parser.getAttributeValue(null, "value");
219
						}
220
						else if (parser.getAttributeValue(null, "name").equals("sourceKeys")) {
221
							sourceKeys = parser.getAttributeValue(null, "value");
222
						}
223
						else if (parser.getAttributeValue(null, "name").equals("srcDirs")) {
224
							String srcDirs = parser.getAttributeValue(null, "value");
225
							this.defaultSrcDirs = srcDirs.split(";");
226
						}
227
						else if (parser.getAttributeValue(null, "name").equals("languages")) {
228
							languages = parser.getAttributeValue(null, "value").split(";");
229
							if (languages.length==0) {
230
								System.err.println("Aviso: No se definieron idiomas a considerar. Se usar? la lista de idiomas\n por defecto: "+defaultLangList);
231
								languages = defaultLangList.split(";");
232
							}
233
						}
234
					}
235
					else {
236
						if (name==null)
237
							System.err.println("Error leyendo el fichero de configuraci?n. No se encontr? el atributo 'name'\nrequerido en la etiqueta <variable>. La etiqueta ser? ignorada.");
238
						if (value==null)
239
							System.err.println("Error leyendo el fichero de configuraci?n. No se encontr? el atributo 'value'\nrequerido en la etiqueta <variable>. La etiqueta ser? ignorada.");
240
					}
241
				}
242
				else {
243
					System.err.println("Aviso: se ignor? una etiqueta desconocida o inesperada: " + parser.getName());
244
				}
245
			}
246
		}
247
		
248
		// Now we transform all directories to absolute canonical paths, so
249
		// that they are easier to manage afterwards.
250
		try {
251
			this.defaultBaseDir = getAbsolutePath(".", this.defaultBaseDir);
252
			this.databaseDir = getAbsolutePath(this.defaultBaseDir, this.databaseDir);
253
			this.outputDir = getAbsolutePath(this.defaultBaseDir, this.outputDir);
254
			this.inputDir = getAbsolutePath(this.defaultBaseDir, this.inputDir);
255
			/**
256
			File baseDirFile = new File(this.defaultBaseDir);
257
			this.defaultBaseDir = baseDirFile.getCanonicalPath();
258
			System.out.println(this.defaultBaseDir);
259
			File databaseDirFile = new File(this.databaseDir);
260
			if (databaseDirFile.isAbsolute()) {
261
				this.databaseDir = databaseDirFile.getCanonicalPath();
262
			}
263
			else {
264
				this.databaseDir = (new File(this.defaultBaseDir+File.separator+this.databaseDir)).getCanonicalPath();
265
			}
266
			File outputDirFile = new File(this.outputDir);
267
			if (outputDirFile.isAbsolute()) {
268
				this.outputDir = outputDirFile.getCanonicalPath();
269
			}
270
			else {
271
				this.outputDir = (new File(this.defaultBaseDir+File.separator+this.outputDir)).getCanonicalPath();
272
			}
273
			File inputDirFile = new File(this.inputDir);
274
			if (inputDirFile.isAbsolute()) {
275
				this.inputDir = inputDirFile.getCanonicalPath();
276
			}
277
			else {
278
				this.inputDir = (new File(this.defaultBaseDir+File.separator+this.inputDir)).getCanonicalPath();
279
			}
280
			*/
281
		} catch (IOException e) {
282
			System.err.println("Error accediendo a los directorios de las traducciones: "+e.getLocalizedMessage());
283
		}
284
	}
285
	
286
	/**
287
	 * Parse the lines containing <project /> tags (between <projects> and </projects>).
288
	 * 
289
	 * @param parser The KXmlParser, pointing to the next <project /> tag (if any)
290
	 * @throws XmlPullParserException
291
	 * @throws IOException
292
	 */
293
	private void parseProjects(KXmlParser parser) throws XmlPullParserException, IOException {
294
		// recorremos todos los proyectos dentro de 'projects'
295
		int state;
296
		String dir;
297
		File dirFile;
298
		Project project;
299
		
300
		for (state = parser.next(); state!=KXmlParser.END_TAG || !parser.getName().equals("projects") ; state=parser.next()) {
301
			if (state==KXmlParser.START_TAG) {
302
				if (parser.getName().equals("project")) {
303
					if (parser.getAttributeValue(null, "dir")!=null) {
304
						dir = parser.getAttributeValue(null,  "dir");
305
						if (dir!=null) {
306
							// we transform it to absolute canonical paths, so
307
							// that it is easier to manage afterwards.
308
							dirFile = new File(dir);
309
							try {
310
								if (dirFile.isAbsolute()) {
311
									dir = dirFile.getCanonicalPath();
312
								}
313
								else {
314
									dir = new File(this.defaultBaseDir+File.separator+dir).getCanonicalPath();
315
								}
316
							} catch (IOException e) {
317
								System.err.println("Error accediendo a los directorios de las traducciones: "+e.getLocalizedMessage());
318
							}
319
							project = new Project();
320
							project.dir = dir;
321
							project.basename = parser.getAttributeValue(null, "basename");
322
							if (project.basename==null)
323
								project.basename = this.defaultBaseName;
324
							
325
							project.propertyDir = parser.getAttributeValue(null, "propertyDir");
326
							if (project.propertyDir==null) {
327
								project.propertyDir = this.defaultPropertyDir;
328
							}
329
							// we transform it to absolute canonical paths, so
330
							// that it is easier to manage afterwards.
331
							File propDirFile = new File(project.propertyDir);
332
							try {
333
								if (propDirFile.isAbsolute()) {
334
									project.propertyDir = propDirFile.getCanonicalPath();
335
								}
336
								else {
337
									project.propertyDir = new File(dir+File.separator+project.propertyDir).getCanonicalPath();
338
								}
339
							} catch (IOException e) {
340
								System.err.println("Error accediendo a los directorios de las traducciones: "+e.getLocalizedMessage());
341
							}
342

  
343
							String srcDirs = parser.getAttributeValue(null, "srcDirs");
344
							if (srcDirs!=null) {
345
								project.srcDirs = srcDirs.split(";");
346
							}
347
							else {
348
								project.srcDirs = this.defaultSrcDirs;
349
							}
350

  
351
							project.sourceKeys = parser.getAttributeValue(null, "sourceKeys");
352
							if (project.sourceKeys==null)
353
								project.sourceKeys = this.sourceKeys;
354
							projects.add(project);
355
						}
356
						else
357
							System.err.println("Error leyendo el fichero de configuraci?n. No se encontr? el atributo 'dir'\nrequerido en la etiqueta <project>. La etiqueta ser? ignorada.");
358
					}
359
				}
360
				else {
361
					System.err.println("Aviso: se ignorar? una etiqueta desconocida o inesperada: " + parser.getName());
362
				}
363
			}
364
		}
365

  
366
	}
367
	
368
	public void setLanguages(String[] languages) {
369
		this.languages = languages; 
370
	}
371
	
372
	public void setProjects(ArrayList projectList) {
373
		this.projects = projectList;
374
	}
375
	
376
	/**
377
	 * Calculates the canonical path for the given path.
378
	 * If the given path is relative, it is calculated from
379
	 * the given baseDir.
380
	 * The 'path' parameter uses the '/' character to as path
381
	 * separator. The returned value uses the default system
382
	 * separator as path separator.  
383
	 * 
384
	 * @param baseDir
385
	 * @param path
386
	 * @return
387
	 * @throws IOException 
388
	 */
389
	public static String getAbsolutePath(String baseDir, String path) throws IOException {
390
		if ('/'!=File.separatorChar)
391
			path = path.replace('/', File.separatorChar);
392
		File pathFile = new File(path);
393
		if (pathFile.isAbsolute())
394
			path = pathFile.getCanonicalPath();
395
		else {
396
			File newFile = new File(baseDir+File.separator+path);
397
			path = newFile.getAbsolutePath();
398
		}
399
		return path;
400
	}
401
}
0 402

  
tags/v2_0_0_Build_2058/libraries/libInternationalization/src-utils/org/gvsig/i18n/utils/OrderedProperties.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 * 
3
 * This class is based on GNU Classpath's Properties.java
4
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
5
 * Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
20
 *
21
 * For more information, contact:
22
 *
23
 *  Generalitat Valenciana
24
 *   Conselleria d'Infraestructures i Transport
25
 *   Av. Blasco Ib??ez, 50
26
 *   46010 VALENCIA
27
 *   SPAIN
28
 *
29
 *      +34 963862235
30
 *   gvsig@gva.es
31
 *      www.gvsig.gva.es
32
 *
33
 *    or
34
 *
35
 *   IVER T.I. S.A
36
 *   Salamanca 50
37
 *   46005 Valencia
38
 *   Spain
39
 *
40
 *   +34 963163400
41
 *   dac@iver.es
42
 */
43

  
44

  
45
package org.gvsig.i18n.utils;
46

  
47
import java.io.BufferedReader;
48
import java.io.IOException;
49
import java.io.InputStream;
50
import java.io.InputStreamReader;
51
import java.io.OutputStream;
52
import java.io.OutputStreamWriter;
53
import java.io.PrintStream;
54
import java.io.PrintWriter;
55
import java.util.Calendar;
56
import java.util.Collections;
57
import java.util.Comparator;
58
import java.util.Enumeration;
59
import java.util.HashSet;
60
import java.util.Iterator;
61
import java.util.PropertyResourceBundle;
62
import java.util.Set;
63
import java.util.TreeMap;
64
import java.util.Map.Entry;
65

  
66
/**
67
* A set of persistent properties, which can be saved or loaded from a stream.
68
* A property list may also contain defaults, searched if the main list
69
* does not contain a property for a given key.
70
*
71
* An example of a properties file for the german language is given
72
* here.  This extends the example given in ListResourceBundle.
73
* Create a file MyResource_de.properties with the following contents
74
* and put it in the CLASSPATH.  (The character
75
* <code>\</code><code>u00e4</code> is the german umlaut)
76
*
77
* 
78
<pre>s1=3
79
s2=MeineDisk
80
s3=3. M\<code></code>u00e4rz 96
81
s4=Die Diskette ''{1}'' enth\<code></code>u00e4lt {0} in {2}.
82
s5=0
83
s6=keine Dateien
84
s7=1
85
s8=eine Datei
86
s9=2
87
s10={0,number} Dateien
88
s11=Das Formatieren schlug fehl mit folgender Exception: {0}
89
s12=FEHLER
90
s13=Ergebnis
91
s14=Dialog
92
s15=Auswahlkriterium
93
s16=1,3</pre>
94
*
95
* <p>Although this is a sub class of a hash table, you should never
96
* insert anything other than strings to this property, or several
97
* methods, that need string keys and values, will fail.  To ensure
98
* this, you should use the <code>get/setProperty</code> method instead
99
* of <code>get/put</code>.
100
*
101
* Properties are saved in the specified encoding. If no encoding is
102
* specified, then the ISO 8859-1 encoding is used, with Unicode escapes with
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff