1
16package org.tp23.antinstaller.util;
17
18import java.io.BufferedReader;
19import java.io.File;
20import java.io.IOException;
21import java.io.InputStreamReader;
22
23import javax.swing.JDialog;
24import javax.swing.JFileChooser;
25import javax.swing.JFrame;
26import javax.swing.JOptionPane;
27import javax.swing.filechooser.FileFilter;
28
29import org.tp23.antinstaller.InstallException;
30import org.tp23.antinstaller.Installer;
31import org.tp23.antinstaller.InstallerContext;
32import org.tp23.antinstaller.runtime.exe.LoadConfigFilter;
33
34public class CreateLanguagePack {
35
36
37 public static void main(String[] args) {
38 try {
39 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
40
41 System.out.println("Create LanguagePack for antinstall-config.xml in the current directory?");
42 br.readLine();
43
44 System.out.println("Enter Locale to create e.g. es_EU");
45 String locale = br.readLine().trim();
46
47 createLanguagePack(loadConfigFile(new File("."), "antinstall-config.xml" ), locale, new File("."));
48
49 System.out.println("done.");
50 } catch (IOException e) {
51 e.printStackTrace();
52 } catch (InstallException e) {
53 e.printStackTrace();
54 }
55 }
56
57 public static File guiMain(JFrame root) {
58 try {
59 JFileChooser chooser = new JFileChooser();
60 chooser.setDialogTitle("Select antinstall-config.xml file");
61 chooser.setApproveButtonText("Select file");
62 FileFilter ff = new FileFilter(){
63 public boolean accept(File file){
64 return file.getName().equals("antinstall-config.xml") || file.isDirectory();
65 }
66 public String getDescription() {
67 return "antinstall-config.xml files";
68 }
69 };
70 chooser.setFileFilter(ff);
71 chooser.showOpenDialog(root);
72 File chosen = chooser.getSelectedFile();
73 if(chosen != null){
74 chooser = new JFileChooser();
75 chooser.setDialogTitle("Select output directory");
76 chooser.setApproveButtonText("Internationalise file");
77 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
78 chooser.setCurrentDirectory(chosen.getParentFile());
79 chooser.showOpenDialog(root);
80 File dir = chooser.getSelectedFile();
81 if(dir != null){
82 createLanguagePack(loadConfigFile(chosen.getParentFile(), chosen.getName()), null, dir);
83 if(! dir.getName().equals("resources")){
84 JOptionPane.showMessageDialog(root, "When the resources files are added to the installer jar\n the parent directory must be /resources/");
85 }
86 return new File(dir, "LanguagePack.properties");
87 }
88 }
89
90 } catch (IOException e) {
91 e.printStackTrace();
92 } catch (InstallException e) {
93 e.printStackTrace();
94 }
95 return null;
96 }
97
98 private static Installer loadConfigFile(File rootDir, String configName) throws InstallException{
99 InstallerContext ctx = new InstallerContext();
00 ctx.setFileRoot(rootDir);
01 ctx.setInstallerConfigFile(configName);
02 LoadConfigFilter configLoader = new LoadConfigFilter();
03 configLoader.exec(ctx);
04 Installer installer = ctx.getInstaller();
05 return installer;
06 }
07
08 private static void createLanguagePack(Installer installer, String locale, File outputDir) throws IOException{
09 LangPackFileRenderer renderer = new LangPackFileRenderer();
10 renderer.renderProperties(installer, outputDir, locale);
11 }
12}
13