Revision 1228

tmp/org.txm.utils/src/org/txm/utils/BiHashMap.java (revision 1228)
3 3
import java.util.Set;
4 4
import java.util.concurrent.ConcurrentHashMap;
5 5

  
6
/**
7
 * Bi directionnal hashmap : keys <-> values
8
 * 
9
 * @author mdecorde
10
 *
11
 * @param <KeyType>
12
 * @param <ValueType>
13
 */
6 14
public class BiHashMap<KeyType, ValueType>{
7 15
    private ConcurrentHashMap<KeyType, ValueType> keyToValueMap = new ConcurrentHashMap<KeyType, ValueType>();
8 16
    private ConcurrentHashMap<ValueType, KeyType> valueToKeyMap = new ConcurrentHashMap<ValueType, KeyType>();
tmp/org.txm.searchengine.core/.classpath (revision 1228)
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<classpath>
3 3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
5
		<accessrules>
6
			<accessrule kind="accessible" pattern="**"/>
7
		</accessrules>
8
	</classpathentry>
5 9
	<classpathentry kind="src" path="src"/>
6 10
	<classpathentry kind="output" path="bin"/>
7 11
</classpath>
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/ExportToOneFile.java (revision 1228)
1 1
package org.txm.rcp.translate.devtools;
2 2

  
3
import java.io.File;
4
import java.util.HashMap;
5
import java.util.Properties;
6

  
7
import org.txm.rcp.translate.i18n.PluginMessages;
8
import org.txm.utils.BiHashMap;
9

  
3 10
public class ExportToOneFile {
4 11

  
12
	public static void main(String[] args) {
13
		File workspace = new File("/home/mdecorde/workspace047");
14

  
15
		HashMap<String, Properties> mergedProps = new HashMap<String, Properties>();
16
		String langs[] = {"", "_fr", "_ru"};
17

  
18
		for (String lang : langs) {
19
			mergedProps.put(lang, new Properties());
20
		}
21
		
22
		for (File project : workspace.listFiles()) {
23
			if (!project.isDirectory()) continue;
24
			if (project.isHidden()) continue;
25
			if (!project.getName().startsWith("org.txm")) continue;
26

  
27
			File messagesPackageDir = new File(project, "src/"+project.getName().replaceAll("\\.", "/")+"/messages");
28
			//System.out.println(messagesPackageDir.getAbsolutePath());
29

  
30

  
31

  
32
			if (messagesPackageDir.exists()) {
33

  
34
				for (File messagesJavaFile : messagesPackageDir.listFiles()) {
35
					if (messagesJavaFile.isDirectory()) continue;
36
					if (!messagesJavaFile.getName().endsWith("Messages.java")) continue;
37

  
38
					PluginMessages messages = new PluginMessages(messagesJavaFile);
39
					System.out.println(messagesJavaFile.getName()+" -> "+messages.getMessageKeys().size());
40
					
41
					for (String lang : langs) {
42
						File propFile = messages.getFile2lang().getKey(lang);
43
						if (propFile != null) {
44
							BiHashMap<String, String> lmessages = messages.getLangs().get(propFile);
45
							for (String key : lmessages.getKeys()) {
46
								String merged_key = messagesJavaFile.getName()+"."+key;
47
								if (mergedProps.get(lang).containsKey(merged_key)) {
48
									System.out.println("WARNING: duplicated key ? "+merged_key);
49
								} else {
50
									mergedProps.get(lang).put(merged_key, lmessages.get(key));
51
								}
52
							}
53
						}
54
					}
55
				}
56
			}
57
		}
58
		
59
		System.out.println(mergedProps.size());
60

  
61
	}
5 62
}
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/ReverseI18nDict.groovy (revision 1228)
1
package org.txm.rcp.translate.i18n
2

  
3
import org.txm.utils.BiHashMap
4

  
5
/**
6
 * Bihashmap 
7
 * Check any missing key in both of messages.properties and Message.java files
8
 * @author mdecorde
9
 *
10
 */
11
class ReverseI18nDict extends BiHashMap<String, String> {
12
	File propFile;
13
	File messageFile;
14
	
15
	def messageKeys = new HashSet<String>()
16
	
17
	public ReverseI18nDict(File propFile) {
18
		this(propFile, null)
19
	}
20
	
21
	public ReverseI18nDict(File propFile, File messageFile) {
22
		this.propFile = propFile
23
		this.messageFile = messageFile
24
		BufferedReader reader = new BufferedReader(new InputStreamReader(
25
				new FileInputStream(propFile), "iso-8859-1"));
26
		String line = reader.readLine();
27
		while (line != null) {
28
			if (!line.startsWith("#")) {
29
				String[] split = line.split("=", 2);
30
				if (split.length == 2) {
31
					this.put(split[0], split[1]);
32
				}
33
			}
34
			line = reader.readLine();
35
		}
36
		
37
		if (messageFile != null) {
38
			BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(messageFile), "iso-8859-1"));
39
			String line2 = reader2.readLine();
40
			while (line2 != null) {
41
				line2 = line2.trim();
42
				if (line2.startsWith("public static String")) {
43
					line2 = line2.substring(21, line2.length() -1);
44
					messageKeys << line2
45
				}
46
				line2 = reader2.readLine();
47
			}
48
		}
49
	}
50
	
51
	public def getMissingsMessageKeys() {
52
		def missing = []
53
		for (String pKey : this.getKeys())
54
			if (!messageKeys.contains(pKey))
55
				missing << pKey
56
				
57
		return missing
58
	}
59
	
60
	public getMissingPropKeys() {
61
		def missing = []
62
		def pKeys = this.getKeys()
63
		for (String mKey : messageKeys)
64
			if (!pKeys.contains(mKey))
65
				missing << mKey
66
				
67
		return missing
68
	}
69
	
70
	public void saveChanges() {
71

  
72
		//Write prop File
73
		File oldFile = new File(propFile.getParentFile(), propFile.getName()+".cpy");
74
		propFile.renameTo(oldFile);
75
		propFile.withWriter("iso-8859-1") { out ->
76
			for(String key : this.getKeys().sort()) {
77
				out.println(key+"="+this.get(key))
78
			}
79
		}
80
		
81
		// write message File
82
		if (messageFile == null) return;
83
		
84
		File oldFile2 = new File(messageFile.getParentFile(), messageFile.getName()+".cpy");
85
		messageFile.renameTo(oldFile2); // back up
86
		messageFile.withWriter("iso-8859-1") { out ->
87
			// write start
88
			out.println('''package org.txm;
89

  
90
import org.eclipse.osgi.util.NLS;
91

  
92
public class Messages extends NLS {
93
	
94
	// The Constant BUNDLE_NAME. 
95
	private static final String BUNDLE_NAME = "org.txm.messages"; //$NON-NLS-1$
96
				''')
97
			
98
			//write keys
99
			for(String key : this.getKeys().sort())
100
				out.println("\tpublic static String $key;");
101
			
102
			// write end
103
			out.println('''
104
	static {
105
		// initialize resource bundle
106
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
107
	}
108

  
109
	private Messages() {
110
	}
111
}
112
				''')
113
		}
114
	}
115
	
116
	public static void main(String[] args) {
117
		File propFile = new File("/home/mdecorde/workspace43/org.txm.core/src/java/org/txm/messages.properties")
118
		File messageFile = new File("/home/mdecorde/workspace43/org.txm.core/src/java/org/txm/Messages.java")
119
		ReverseI18nDict dict = new ReverseI18nDict(propFile, messageFile);
120
		println dict.getMissingsMessageKeys()
121
		println dict.getMissingPropKeys();
122
		println dict.toString();
123
		//dict.saveChanges();
124
	}
125
}
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/ExternalizeStringFile.groovy (revision 1228)
16 16
	File propFile;
17 17
	File messageFile
18 18

  
19
	ReverseI18nDict dict
19
	PluginMessages dict
20 20

  
21 21
	String prefix
22 22
	int iprefix = 0;
......
24 24
	boolean mustSaveChanges = false;
25 25

  
26 26
	public ExternalizeStringFile(File propFile, File messageFile) {
27
		dict = new ReverseI18nDict(propFile, messageFile);		
27
		dict = new PluginMessages(propFile, messageFile);		
28 28
	}
29 29
	
30 30
	private ArrayList<String> getLineStrings(String l) {
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessages.groovy (revision 1228)
1
package org.txm.rcp.translate.i18n;
2

  
3
import org.txm.utils.BiHashMap
4

  
5
/**
6
 *  
7
 * Check any missing key in both of messages.properties and Message.java files
8
 *
9
 * @author mdecorde
10
 *
11
 */
12
class PluginMessages {
13
	
14
	File messageFile;
15
	String encoding = "UTF-8"
16
	
17
	LinkedHashSet messageKeys = new LinkedHashSet<String>()
18
	HashMap<File, BiHashMap<String, String>> langs = new HashMap<File, BiHashMap<String, String>>();
19
	BiHashMap<File, String> file2lang = new BiHashMap<File, String>()
20
		
21
	public PluginMessages(File messageFile) {
22
		this.messageFile = messageFile
23
		
24
		def propFiles = messageFile.getParentFile().listFiles()
25
		for (File propFile : propFiles) {
26
			String name = propFile.getName();
27
			if (!name.endsWith(".properties")) continue;
28
			//messages.properties
29
			//messages_xx.properties
30
			String lang = name.substring(8, name.indexOf(".properties"))
31
			langs.put(propFile, new BiHashMap<String, String>());
32
			file2lang.put(propFile, lang)
33
			
34
			def hash = langs[propFile]
35
			
36
			Properties props1 = new Properties()
37
			props1.load(propFile.newReader(encoding))
38
			for (String k : props1.keySet()) {
39
				hash.put(k, props1.get(k))
40
			}
41
		}
42
	
43
		if (messageFile != null) {
44
			BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(messageFile), encoding));
45
			String line2 = reader2.readLine();
46
			while (line2 != null) {
47
				line2 = line2.trim();
48
				if (line2.startsWith("public static String") && line2.endsWith(";") && !line2.contains("=")) {
49
					line2 = line2.substring(21, line2.length() -1);
50
					messageKeys << line2
51
				}
52
				line2 = reader2.readLine();
53
			}
54
		}
55
	}
56
	
57
	public LinkedHashSet getMessageKeys() {
58
		return messageKeys;
59
	}
60
	
61
	public File getMessageFile() {
62
		return messageFile;
63
	}
64
	
65
	public String getMessageFileName() {
66
		return messageFile.getName().substring(0, messageFile.getName().length()-5);
67
	}
68
	
69
//	public def getMissingsMessageKeys(String lang) {
70
//		def missing = []
71
//		for (String pKey : this.getKeys())
72
//			if (!messageKeys.contains(pKey))
73
//				missing << pKey
74
//				
75
//		return missing
76
//	}
77
//	
78
//	public getMissingPropKeys(String lang) {
79
//		def missing = []
80
//		def pKeys = this.getKeys()
81
//		for (String mKey : messageKeys)
82
//			if (!pKeys.contains(mKey))
83
//				missing << mKey
84
//				
85
//		return missing
86
//	}
87
	
88
	public void saveChanges() {
89

  
90
		//Write prop File
91
		for (File propFile : langs.keySet()) {
92
			String name = propFile.getName();
93
			if (!name.endsWith(".properties")) continue;
94
			String lang = name.substring(8, name.indexOf(".properties"))
95
			
96
			File oldFile = new File(propFile.getParentFile(), propFile.getName()+".cpy");
97
			propFile.renameTo(oldFile);
98
			
99
			Properties props = new Properties()
100
		}
101
		
102
		
103
		// write message File
104
		if (messageFile == null) return;
105
		
106
		File oldFile2 = new File(messageFile.getParentFile(), messageFile.getName()+".cpy");
107
		messageFile.renameTo(oldFile2); // back up
108
		messageFile.withWriter(encoding) { out ->
109
			// write start
110
			out.println('''package org.txm;
111

  
112
import org.eclipse.osgi.util.NLS;
113

  
114
public class Messages extends NLS {
115
	
116
	// The Constant BUNDLE_NAME. 
117
	private static final String BUNDLE_NAME = "org.txm.messages"; //$NON-NLS-1$
118
				''')
119
			
120
			//write keys
121
			for(String key : this.getKeys().sort())
122
				out.println("\tpublic static String $key;");
123
			
124
			// write end
125
			out.println('''
126
	static {
127
		// initialize resource bundle
128
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
129
	}
130

  
131
	private Messages() {
132
	}
133
}
134
				''')
135
		}
136
	}
137
	
138
	public void summary() {
139
		println getMessageFileName()
140
		println "Messages keys"
141
		for (def key : messageKeys) {
142
			println " $key"
143
		}
144
		
145
		println "Langs"
146
		for (def lang : langs.keySet()) {
147
			println " '$lang'"
148
			def hash = langs[lang]
149
			println " keys="+ hash.getKeys()
150
			for (def key : hash.getKeys()) {
151
				println "  $key="+hash.get(key)
152
			}
153
		}
154
	}
155
	
156
	public static void main(String[] args) {
157
		File messageFile = new File("/home/mdecorde/workspace047/org.txm.core/src/java/org/txm/core/messages/TXMCoreMessages.java")
158
		PluginMessages dict = new PluginMessages(messageFile);
159
		
160
		println dict.summary()
161
		//dict.saveChanges();
162
	}
163
}
tmp/org.txm.jodconverter.core/target/classes/document-formats.js (revision 1228)
1
[
2
  {
3
    "name": "Portable Document Format",
4
    "extension": "pdf",
5
    "mediaType": "application/pdf",
6
    "storePropertiesByFamily": {
7
      "DRAWING": {"FilterName": "draw_pdf_Export"},
8
      "SPREADSHEET": {"FilterName": "calc_pdf_Export"},
9
      "PRESENTATION": {"FilterName": "impress_pdf_Export"},
10
      "TEXT": {"FilterName": "writer_pdf_Export"}
11
    }
12
  },
13
  {
14
    "name": "Macromedia Flash",
15
    "extension": "swf",
16
    "mediaType": "application/x-shockwave-flash",
17
    "storePropertiesByFamily": {
18
      "DRAWING": {"FilterName": "draw_flash_Export"},
19
      "PRESENTATION": {"FilterName": "impress_flash_Export"}
20
    }
21
  },
22
  {
23
    "name": "HTML",
24
    "extension": "html",
25
    "mediaType": "text/html",
26
    "inputFamily": "TEXT",
27
    "storePropertiesByFamily": {
28
      "SPREADSHEET": {"FilterName": "HTML (StarCalc)"},
29
      "PRESENTATION": {"FilterName": "impress_html_Export"},
30
      "TEXT": {"FilterName": "HTML (StarWriter)"}
31
    }
32
  },
33
  {
34
    "name": "OpenDocument Text",
35
    "extension": "odt",
36
    "mediaType": "application/vnd.oasis.opendocument.text",
37
    "inputFamily": "TEXT",
38
    "storePropertiesByFamily": {"TEXT": {"FilterName": "writer8"}}
39
  },
40
  {
41
    "name": "OpenOffice.org 1.0 Text Document",
42
    "extension": "sxw",
43
    "mediaType": "application/vnd.sun.xml.writer",
44
    "inputFamily": "TEXT",
45
    "storePropertiesByFamily": {"TEXT": {"FilterName": "StarOffice XML (Writer)"}}
46
  },
47
  {
48
    "name": "Microsoft Word",
49
    "extension": "doc",
50
    "mediaType": "application/msword",
51
    "inputFamily": "TEXT",
52
    "storePropertiesByFamily": {"TEXT": {"FilterName": "MS Word 97"}}
53
  },
54
  {
55
    "name": "Microsoft Word 2007 XML",
56
    "extension": "docx",
57
    "mediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
58
    "inputFamily": "TEXT"
59
  },
60
  {
61
    "name": "Rich Text Format",
62
    "extension": "rtf",
63
    "mediaType": "text/rtf",
64
    "inputFamily": "TEXT",
65
    "storePropertiesByFamily": {"TEXT": {"FilterName": "Rich Text Format"}}
66
  },
67
  {
68
    "name": "WordPerfect",
69
    "extension": "wpd",
70
    "mediaType": "application/wordperfect",
71
    "inputFamily": "TEXT"
72
  },
73
  {
74
    "name": "Plain Text",
75
    "extension": "txt",
76
    "mediaType": "text/plain",
77
    "inputFamily": "TEXT",
78
    "loadProperties": {
79
      "FilterName": "Text (encoded)",
80
      "FilterOptions": "utf8"
81
    },
82
    "storePropertiesByFamily": {"TEXT": {
83
      "FilterName": "Text (encoded)",
84
      "FilterOptions": "utf8"
85
    }}
86
  },
87
  {
88
    "name": "MediaWiki wikitext",
89
    "extension": "wiki",
90
    "mediaType": "text/x-wiki",
91
    "storePropertiesByFamily": {"TEXT": {"FilterName": "MediaWiki"}}
92
  },
93
  {
94
    "name": "OpenDocument Spreadsheet",
95
    "extension": "ods",
96
    "mediaType": "application/vnd.oasis.opendocument.spreadsheet",
97
    "inputFamily": "SPREADSHEET",
98
    "storePropertiesByFamily": {"SPREADSHEET": {"FilterName": "calc8"}}
99
  },
100
  {
101
    "name": "OpenOffice.org 1.0 Spreadsheet",
102
    "extension": "sxc",
103
    "mediaType": "application/vnd.sun.xml.calc",
104
    "inputFamily": "SPREADSHEET",
105
    "storePropertiesByFamily": {"SPREADSHEET": {"FilterName": "StarOffice XML (Calc)"}}
106
  },
107
  {
108
    "name": "Microsoft Excel",
109
    "extension": "xls",
110
    "mediaType": "application/vnd.ms-excel",
111
    "inputFamily": "SPREADSHEET",
112
    "storePropertiesByFamily": {"SPREADSHEET": {"FilterName": "MS Excel 97"}}
113
  },
114
  {
115
    "name": "Microsoft Excel 2007 XML",
116
    "extension": "xlsx",
117
    "mediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
118
    "inputFamily": "SPREADSHEET"
119
  },
120
  {
121
    "name": "Comma Separated Values",
122
    "extension": "csv",
123
    "mediaType": "text/csv",
124
    "inputFamily": "SPREADSHEET",
125
    "loadProperties": {
126
      "FilterName": "Text - txt - csv (StarCalc)",
127
      "FilterOptions": "44,34,0"
128
    },
129
    "storePropertiesByFamily": {"SPREADSHEET": {
130
      "FilterName": "Text - txt - csv (StarCalc)",
131
      "FilterOptions": "44,34,0"
132
    }}
133
  },
134
  {
135
    "name": "Tab Separated Values",
136
    "extension": "tsv",
137
    "mediaType": "text/tab-separated-values",
138
    "inputFamily": "SPREADSHEET",
139
    "loadProperties": {
140
      "FilterName": "Text - txt - csv (StarCalc)",
141
      "FilterOptions": "9,34,0"
142
    },
143
    "storePropertiesByFamily": {"SPREADSHEET": {
144
      "FilterName": "Text - txt - csv (StarCalc)",
145
      "FilterOptions": "9,34,0"
146
    }}
147
  },
148
  {
149
    "name": "OpenDocument Presentation",
150
    "extension": "odp",
151
    "mediaType": "application/vnd.oasis.opendocument.presentation",
152
    "inputFamily": "PRESENTATION",
153
    "storePropertiesByFamily": {"PRESENTATION": {"FilterName": "impress8"}}
154
  },
155
  {
156
    "name": "OpenOffice.org 1.0 Presentation",
157
    "extension": "sxi",
158
    "mediaType": "application/vnd.sun.xml.impress",
159
    "inputFamily": "PRESENTATION",
160
    "storePropertiesByFamily": {"PRESENTATION": {"FilterName": "StarOffice XML (Impress)"}}
161
  },
162
  {
163
    "name": "Microsoft PowerPoint",
164
    "extension": "ppt",
165
    "mediaType": "application/vnd.ms-powerpoint",
166
    "inputFamily": "PRESENTATION",
167
    "storePropertiesByFamily": {"PRESENTATION": {"FilterName": "MS PowerPoint 97"}}
168
  },
169
  {
170
    "name": "Microsoft PowerPoint 2007 XML",
171
    "extension": "pptx",
172
    "mediaType": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
173
    "inputFamily": "PRESENTATION"
174
  },
175
  {
176
    "name": "OpenDocument Drawing",
177
    "extension": "odg",
178
    "mediaType": "application/vnd.oasis.opendocument.graphics",
179
    "inputFamily": "DRAWING",
180
    "storePropertiesByFamily": {"DRAWING": {"FilterName": "draw8"}}
181
  },
182
  {
183
    "name": "Scalable Vector Graphics",
184
    "extension": "svg",
185
    "mediaType": "image/svg+xml",
186
    "storePropertiesByFamily": {"DRAWING": {"FilterName": "draw_svg_Export"}}
187
  }
188
]

Also available in: Unified diff