001: /*
002: * Copyright 2005 Paul Hinds
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.tp23.antinstaller.util;
017:
018: import java.io.BufferedReader;
019: import java.io.File;
020: import java.io.IOException;
021: import java.io.InputStreamReader;
022:
023: import javax.swing.JFileChooser;
024: import javax.swing.JFrame;
025: import javax.swing.JOptionPane;
026: import javax.swing.filechooser.FileFilter;
027:
028: import org.tp23.antinstaller.InstallException;
029: import org.tp23.antinstaller.Installer;
030: import org.tp23.antinstaller.InstallerContext;
031: import org.tp23.antinstaller.runtime.exe.LoadConfigFilter;
032:
033: public class CreateLanguagePack {
034:
035: public static void main(String[] args) {
036: try {
037: BufferedReader br = new BufferedReader(
038: new InputStreamReader(System.in));
039:
040: System.out
041: .println("Create LanguagePack for antinstall-config.xml in the current directory?");
042: br.readLine();
043:
044: System.out.println("Enter Locale to create e.g. es_EU");
045: String locale = br.readLine().trim();
046:
047: createLanguagePack(loadConfigFile(new File("."),
048: "antinstall-config.xml"), locale, new File("."));
049:
050: System.out.println("done.");
051: } catch (IOException e) {
052: e.printStackTrace();
053: } catch (InstallException e) {
054: e.printStackTrace();
055: }
056: }
057:
058: public static File guiMain(JFrame root) {
059: try {
060: JFileChooser chooser = new JFileChooser();
061: chooser.setDialogTitle("Select antinstall-config.xml file");
062: chooser.setApproveButtonText("Select file");
063: FileFilter ff = new FileFilter() {
064: public boolean accept(File file) {
065: return file.getName().equals(
066: "antinstall-config.xml")
067: || file.isDirectory();
068: }
069:
070: public String getDescription() {
071: return "antinstall-config.xml files";
072: }
073: };
074: chooser.setFileFilter(ff);
075: chooser.showOpenDialog(root);
076: File chosen = chooser.getSelectedFile();
077: if (chosen != null) {
078: chooser = new JFileChooser();
079: chooser.setDialogTitle("Select output directory");
080: chooser.setApproveButtonText("Internationalise file");
081: chooser
082: .setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
083: chooser.setCurrentDirectory(chosen.getParentFile());
084: chooser.showOpenDialog(root);
085: File dir = chooser.getSelectedFile();
086: if (dir != null) {
087: createLanguagePack(loadConfigFile(chosen
088: .getParentFile(), chosen.getName()), null,
089: dir);
090: if (!dir.getName().equals("resources")) {
091: JOptionPane
092: .showMessageDialog(
093: root,
094: "When the resources files are added to the installer jar\n the parent directory must be /resources/");
095: }
096: return new File(dir, "LanguagePack.properties");
097: }
098: }
099:
100: } catch (IOException e) {
101: e.printStackTrace();
102: } catch (InstallException e) {
103: e.printStackTrace();
104: }
105: return null;
106: }
107:
108: private static Installer loadConfigFile(File rootDir,
109: String configName) throws InstallException {
110: InstallerContext ctx = new InstallerContext();
111: ctx.setFileRoot(rootDir);
112: ctx.setInstallerConfigFile(configName);
113: LoadConfigFilter configLoader = new LoadConfigFilter();
114: configLoader.exec(ctx);
115: Installer installer = ctx.getInstaller();
116: return installer;
117: }
118:
119: private static void createLanguagePack(Installer installer,
120: String locale, File outputDir) throws IOException {
121: LangPackFileRenderer renderer = new LangPackFileRenderer();
122: renderer.renderProperties(installer, outputDir, locale);
123: }
124: }
|