source: other-projects/trunk/realistic-books/packages/AntInstaller/src_ext/org/tp23/antinstaller/util/CreateLanguagePack.java@ 19253

Last change on this file since 19253 was 19253, checked in by davidb, 15 years ago

Establishing a source code repository for Veronica's Realistic Book's software

File size: 3.7 KB
Line 
1/*
2 * Copyright 2005 Paul Hinds
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
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();
100 ctx.setFileRoot(rootDir);
101 ctx.setInstallerConfigFile(configName);
102 LoadConfigFilter configLoader = new LoadConfigFilter();
103 configLoader.exec(ctx);
104 Installer installer = ctx.getInstaller();
105 return installer;
106 }
107
108 private static void createLanguagePack(Installer installer, String locale, File outputDir) throws IOException{
109 LangPackFileRenderer renderer = new LangPackFileRenderer();
110 renderer.renderProperties(installer, outputDir, locale);
111 }
112}
Note: See TracBrowser for help on using the repository browser.