Révision 3479
TXM/trunk/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/TableToProperties.java (revision 3479) | ||
---|---|---|
1 |
package org.txm.rcp.translate.devtools; |
|
2 |
|
|
3 |
import java.io.BufferedReader; |
|
4 |
import java.io.File; |
|
5 |
import java.io.PrintWriter; |
|
6 |
import java.util.Properties; |
|
7 |
|
|
8 |
import org.odftoolkit.simple.TextDocument; |
|
9 |
import org.odftoolkit.simple.table.Cell; |
|
10 |
import org.odftoolkit.simple.table.Row; |
|
11 |
import org.odftoolkit.simple.table.Table; |
|
12 |
import org.txm.utils.io.IOUtils; |
|
13 |
|
|
14 |
public class TableToProperties { |
|
15 |
|
|
16 |
File tableFile; |
|
17 |
String lang; |
|
18 |
|
|
19 |
public TableToProperties(File tableFile, String lang) { |
|
20 |
this.tableFile = tableFile; |
|
21 |
this.lang = lang; |
|
22 |
} |
|
23 |
|
|
24 |
public Properties convert() throws Exception { |
|
25 |
|
|
26 |
Properties slave = new Properties(); |
|
27 |
|
|
28 |
TextDocument doc = TextDocument.loadDocument(tableFile); |
|
29 |
Table table = doc.getTableList().get(0); |
|
30 |
|
|
31 |
Row headerRow = table.getRowList().get(0); |
|
32 |
int ncol = headerRow.getCellCount(); |
|
33 |
int keyIndex = -1; |
|
34 |
int langIndex = -1; |
|
35 |
int defaultIndex = -1; |
|
36 |
for (int c = 0; c < ncol; c++) { |
|
37 |
Cell cell = headerRow.getCellByIndex(c); |
|
38 |
if ("KEY".equals(cell.getDisplayText())) { |
|
39 |
keyIndex = c; |
|
40 |
} |
|
41 |
else if (lang.equals(cell.getDisplayText().toLowerCase())) { |
|
42 |
langIndex = c; |
|
43 |
} |
|
44 |
else if ("DEFAULT".equals(cell.getDisplayText())) { |
|
45 |
defaultIndex = c; |
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
if (keyIndex == -1) { |
|
50 |
System.out.println("KEY columns not found in " + headerRow); |
|
51 |
return null; |
|
52 |
} |
|
53 |
if (langIndex == -1) { |
|
54 |
System.out.println(lang + " columns not found in " + headerRow); |
|
55 |
return null; |
|
56 |
} |
|
57 |
if (defaultIndex == -1) { |
|
58 |
System.out.println("DEFAULT columns not found in " + headerRow); |
|
59 |
return null; |
|
60 |
} |
|
61 |
|
|
62 |
for (Row h : table.getRowList()) { |
|
63 |
|
|
64 |
String key = h.getCellByIndex(keyIndex).getDisplayText(); |
|
65 |
if (key != null) { |
|
66 |
String value = h.getCellByIndex(langIndex).getDisplayText(); |
|
67 |
if (value != null) { |
|
68 |
slave.setProperty(key, value); |
|
69 |
} |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
return slave; |
|
74 |
} |
|
75 |
|
|
76 |
public static void main(String args[]) throws Exception { |
|
77 |
|
|
78 |
// Properties b = new TableToProperties(new File("/home/mdecorde/workspace047/org.txm.translate.rcp/bundles_fr.odt"), "fr").convert(); |
|
79 |
// |
|
80 |
// System.out.println("RESULT: "+b); |
|
81 |
// |
|
82 |
// Properties b2 = new TableToProperties(new File("/home/mdecorde/workspace047/org.txm.translate.rcp/bundle_fr.odt"), "fr").convert(); |
|
83 |
// |
|
84 |
// System.out.println("RESULT: "+b2); |
|
85 |
// |
|
86 |
// Properties newProperties = new Properties(); |
|
87 |
// |
|
88 |
// for (Object k : b.keySet()) { |
|
89 |
// if (!(b.get(k).equals(b2.get(k)))) { |
|
90 |
// newProperties.setProperty(k.toString(), b2.get(k).toString()); |
|
91 |
// } |
|
92 |
// } |
|
93 |
// |
|
94 |
// System.out.println("NEWPROPERTIES: "+newProperties); |
|
95 |
|
|
96 |
// PrintWriter writer = IOUtils.getWriter(new File("/home/mdecorde/TEMP/newvalues.properties"), "iso-8859-1"); |
|
97 |
// newProperties.store(writer, ""); |
|
98 |
// writer.close(); |
|
99 |
|
|
100 |
|
|
101 |
Properties previousOKProperties = new TableToProperties(new File("/home/mdecorde/TEMP/messagespaskc.odt"), "fr").convert(); |
|
102 |
|
|
103 |
File newValuesPropertiesFile = new File("/home/mdecorde/TEMP/newvalues.properties"); |
|
104 |
BufferedReader reader = IOUtils.getReader(newValuesPropertiesFile, "iso-8859-1"); |
|
105 |
Properties newProperties2 = new Properties(); |
|
106 |
newProperties2.load(reader); |
|
107 |
reader.close(); |
|
108 |
|
|
109 |
for (Object k : newProperties2.keySet()) { |
|
110 |
previousOKProperties.setProperty(k.toString(), newProperties2.getProperty(k.toString())); |
|
111 |
} |
|
112 |
|
|
113 |
PrintWriter writer = IOUtils.getWriter(new File("/home/mdecorde/TEMP/messagespaskc.properties"), "iso-8859-1"); |
|
114 |
previousOKProperties.store(writer, ""); |
|
115 |
writer.close(); |
|
116 |
} |
|
117 |
} |
|
0 | 118 |
TXM/trunk/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/TableFileToPropertiesFile.java (revision 3479) | ||
---|---|---|
1 |
package org.txm.rcp.translate.devtools; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.PrintWriter; |
|
5 |
import java.util.Properties; |
|
6 |
|
|
7 |
import org.txm.utils.io.IOUtils; |
|
8 |
|
|
9 |
public class TableFileToPropertiesFile { |
|
10 |
|
|
11 |
File tableFile; |
|
12 |
File propertiesFile; |
|
13 |
String lang; |
|
14 |
|
|
15 |
public TableFileToPropertiesFile(File tableFile, File propertiesFile, String lang) { |
|
16 |
this.tableFile = tableFile; |
|
17 |
this.propertiesFile = propertiesFile; |
|
18 |
this.lang = lang; |
|
19 |
} |
|
20 |
|
|
21 |
public boolean convert() throws Exception { |
|
22 |
|
|
23 |
Properties slave = new TableToProperties(tableFile, lang).convert(); |
|
24 |
|
|
25 |
PrintWriter writer = IOUtils.getWriter(propertiesFile, "iso-8859-1"); |
|
26 |
slave.store(writer, ""); |
|
27 |
writer.close(); |
|
28 |
|
|
29 |
return true; |
|
30 |
} |
|
31 |
|
|
32 |
public static void main(String args[]) throws Exception { |
|
33 |
|
|
34 |
boolean b = new TableFileToPropertiesFile(new File("/home/mdecorde/workspace047/org.txm.translate.rcp/bundles_fr.odt"), new File("/home/mdecorde/TEMP/orig.properties"), "fr").convert(); |
|
35 |
|
|
36 |
System.out.println("RESULT: "+b); |
|
37 |
|
|
38 |
boolean b2 = new TableFileToPropertiesFile(new File("/home/mdecorde/workspace047/org.txm.translate.rcp/bundle_fr.odt"), new File("/home/mdecorde/TEMP/slh.properties"), "fr").convert(); |
|
39 |
|
|
40 |
System.out.println("RESULT: "+b2); |
|
41 |
} |
|
42 |
} |
|
0 | 43 |
TXM/trunk/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/ImportMessagesTable.java (revision 3479) | ||
---|---|---|
118 | 118 |
} |
119 | 119 |
|
120 | 120 |
public static void main(String[] args) throws Exception { |
121 |
String prefix = "messages"; // messages
|
|
122 |
System.out.println(new ImportMessagesTable("fr").run(prefix, new File(prefix + "_fr.odt"))); |
|
121 |
String prefix = "bundle"; // messages
|
|
122 |
System.out.println(new ImportMessagesTable(new File("/home/mdecorde/TEMP"), "fr").run(prefix, new File(prefix + "_fr.odt")));
|
|
123 | 123 |
} |
124 | 124 |
} |
Formats disponibles : Unified diff