com.clickntap.developers.MessageSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of click_framework Show documentation
Show all versions of click_framework Show documentation
Java Framework based on Spring Framework, Freemarker and Simplicity
package com.clickntap.developers;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import com.clickntap.utils.ConstUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class MessageSource {
private Map> languages;
public MessageSource() {
languages = new HashMap>();
}
public MessageSource(String messageProperties, String locale) throws Exception {
Properties p = new Properties();
InputStream in = new FileInputStream(messageProperties);
p.load(in);
in.close();
HashMap values = new HashMap();
for (Object key : p.keySet()) {
values.put(key.toString(), p.getProperty(key.toString()));
}
languages = new HashMap>();
languages.put(locale, values);
}
public Map> getLanguages() {
return languages;
}
public void setLanguages(Map> languages) {
this.languages = languages;
}
public void export(String messagesJson) throws IOException {
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
String json = gson.toJson(this);
FileUtils.writeStringToFile(new File(messagesJson), json, ConstUtils.UTF_8);
}
}