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 Stripecube Show documentation
Show all versions of Stripecube Show documentation
Stripecube is an open source Java framework for Web Applications
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.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class MessageSource {
private Map> languages;
public Map> getLanguages() {
return languages;
}
public void setLanguages(Map> languages) {
this.languages = languages;
}
public MessageSource() {
}
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 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);
}
}