-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with the com.oreilly.servlet library, any library\r
- * licensed under the Apache Software License, The Sun (tm) Java Advanced\r
- * Imaging library (JAI), The Sun JIMI library (or with modified versions of\r
- * the above that use the same license as the above), and distribute linked\r
- * combinations including the two. You must obey the GNU General Public\r
- * License in all respects for all of the code used other than the above\r
- * mentioned libraries. If you modify this file, you may extend this exception\r
- * to your version of the file, but you are not obligated to do so. If you do\r
- * not wish to do so, delete this exception statement from your version.\r
- */\r
-\r
-package tool;\r
-\r
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+
+package tool;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.util.Arrays;
import java.util.Iterator;
+import java.util.List;
+
+import mir.util.ExceptionRoutines;
+import mir.util.PropertiesManipulator;
+
+public class BundleTool {
+
+ public static void compare(String aMaster, String aSlave) {
+ PropertiesManipulator master;
+ PropertiesManipulator slave;
+
+ try {
+ master = PropertiesManipulator.readProperties(
+ new BufferedInputStream(
+ new FileInputStream(new File(aMaster)),8192));
+ }
+ catch (Throwable t) {
+ System.out.println("Unable to read master properties: " + t.getMessage());
+ return;
+ }
+
+ try {
+ slave = PropertiesManipulator.readProperties(
+ new BufferedInputStream(
+ new FileInputStream(new File(aSlave)),8192));
+ }
+ catch (FileNotFoundException t) {
+ slave = new PropertiesManipulator();
+ }
+ catch (Throwable t) {
+ System.out.println("Unable to read slave properties: " + t.getMessage());
+ return;
+ }
+
+ int missing=0;
+
+ Iterator i = master.getEntries();
+ while (i.hasNext()) {
+ Object e = i.next();
+
+ if (e instanceof PropertiesManipulator.Entry) {
+ String key = ( (PropertiesManipulator.Entry) e).getKey();
+
+ if (!slave.containsKey(key) || slave.get(key) == null || slave.get(key).length()==0 ) {
+ if (missing==0) {
+ System.out.println(aSlave+" is missing:");
+ }
+ System.out.println(" " + key);
+ missing++;
+ }
+ }
+ }
+
+ if (missing>0)
+ System.out.println("total missing: " +missing);
+
+ missing=0;
+ i = slave.getEntries();
+ while (i.hasNext()) {
+ Object e = i.next();
+
+ if (e instanceof PropertiesManipulator.Entry) {
+ String key = ( (PropertiesManipulator.Entry) e).getKey();
+
+ if (!master.containsKey(key)) {
+ if (missing==0) {
+ System.out.println(aSlave+" has extra:");
+ }
+ System.out.println(" " + key);
+ missing++;
+ }
+ }
+ }
+ if (missing>0)
+ System.out.println("total extra: " +missing);
+ }
+
+ public static void align(String aMaster, String aSlave) {
+ PropertiesManipulator master;
+ PropertiesManipulator slave;
+ PropertiesManipulator result;
+
+ try {
+ master = PropertiesManipulator.readProperties(
+ new BufferedInputStream(
+ new FileInputStream(new File(aMaster)),8192));
+ }
+ catch (Throwable t) {
+ System.out.println("Unable to read master properties: " + t.getMessage());
+ return;
+ }
+
+ try {
+ slave = PropertiesManipulator.readProperties(
+ new BufferedInputStream(
+ new FileInputStream(new File(aSlave)),8192));
+ }
+ catch (FileNotFoundException t) {
+ slave = new PropertiesManipulator();
+ }
+ catch (Throwable t) {
+ System.out.println("Unable to read slave properties: " + t.getMessage());
+ return;
+ }
+
+ result = new PropertiesManipulator();
+
+ // skip past the header in the slave bundle
+ Iterator i = slave.getEntries();
+ while (i.hasNext()) {
+ Object e = i.next();
+
+ if (e instanceof PropertiesManipulator.EmptyLine) {
+ result.addEmptyLine();
+ }
+ else if (e instanceof PropertiesManipulator.Comment) {
+ result.addComment( ( (PropertiesManipulator.Comment) e).getComment());
+ }
+
+ if (! (e instanceof PropertiesManipulator.Comment))
+ break;
+ }
+
+ boolean insideHeader = true;
+ i = master.getEntries();
+ while (i.hasNext()) {
+ Object e = i.next();
+
+ if (!insideHeader && (e instanceof PropertiesManipulator.EmptyLine)) {
+ result.addEmptyLine();
+ }
+ else if (!insideHeader && e instanceof PropertiesManipulator.Comment) {
+ result.addComment( ( (PropertiesManipulator.Comment) e).getComment());
+ }
+ else if (e instanceof PropertiesManipulator.Entry) {
+ String key = ( (PropertiesManipulator.Entry) e).getKey();
+ String value = slave.get(key);
+
+ if (value==null || value.length()==0) {
+ result.addComment("# missing (master value = \"" +master.get(key)+"\")");
+ }
+
+ result.addEntry(key, value);
+ }
+
+ insideHeader = insideHeader && (e instanceof PropertiesManipulator.Comment);
+ }
+
+ try {
+ PropertiesManipulator.writeProperties(result,
+ new BufferedOutputStream(new FileOutputStream(new File(aSlave)),8192));
+ }
+ catch (Throwable t) {
+ System.out.println("Unable to write slave properties: " + t.getMessage());
+ return;
+ }
+ }
+
+ public static void encode(String aBundle, String anEncoding, String anOutputFile) {
+ PropertiesManipulator bundle;
+
+ try {
+ bundle = PropertiesManipulator.readProperties(
+ new BufferedInputStream(
+ new FileInputStream(new File(aBundle)),8192));
+
+ PropertiesManipulator.writeProperties(bundle,
+ new BufferedOutputStream(new FileOutputStream(anOutputFile),8192), anEncoding, false);
+ }
+ catch (Throwable t) {
+ System.out.println("Unable to read master properties: " + t.getMessage());
+ return;
+ }
+ }
+
+ public static void decode(String aBundle, String anEncoding, String aSourceFile) {
+ PropertiesManipulator bundle;
+
+ try {
+ bundle = PropertiesManipulator.readProperties(
+ new BufferedInputStream(
+ new FileInputStream(new File(aSourceFile)),8192), anEncoding);
+ }
+ catch (Throwable t) {
+ Throwable s = ExceptionRoutines.traceCauseException(t);
+
+ System.out.println("Unable to read sourcefile: " + s.toString());
+ return;
+ }
+ try {
+ PropertiesManipulator.writeProperties(bundle,
+ new BufferedOutputStream(new FileOutputStream(aBundle),8192));
+ }
+ catch (Throwable t) {
+ System.out.println("Unable to write bundle: " + t.toString());
+ return;
+ }
+ }
+
+ public static void rename(String anOldKeyName, String aNewKeyName, List aBundles) {
+ /*
+ PropertiesManipulator bundle;
+
+ try {
+ bundle = PropertiesManipulator.readProperties(new FileInputStream(new File(aBundle)));
+
+ PropertiesManipulator.writeProperties(bundle, new FileOutputStream(anOutputFile), anEncoding, false);
+ }
+ catch (Throwable t) {
+ System.out.println("Unable to read master properties: " + t.getMessage());
+ return;
+ }
+*/
+ }
+
+
+ public static void main(String[] anArguments) {
+ String command = "help";
+
+ if (anArguments.length >= 1) {
+ command = anArguments[0];
+
+ if (command.equals("compare")) {
+ if (anArguments.length==3) {
+ compare(anArguments[1], anArguments[2]);
+
+ return;
+ }
+ }
+ else if (command.equals("align")) {
+ if (anArguments.length==3) {
+ align(anArguments[1], anArguments[2]);
+
+ return;
+ }
+ }
+ else if (command.equals("encode")) {
+ if (anArguments.length==4) {
+ encode(anArguments[1], anArguments[2], anArguments[3]);
+
+ return;
+ }
+ }
+ else if (command.equals("decode")) {
+ if (anArguments.length==4) {
+ decode(anArguments[1], anArguments[2], anArguments[3]);
+
+ return;
+ }
+ }
+ else if (command.equals("rename")) {
+ if (anArguments.length>=3) {
+ List arguments = Arrays.asList(anArguments);
+
+ rename(anArguments[0], anArguments[1], arguments.subList(2, arguments.size()));
+
+/*
+ decode(anArguments[1], anArguments[2], anArguments[3]);
+*/
+ return;
+ }
+ }
+ }
+
+ System.out.println("Usage:");
+
+ System.out.println(" BundleTool align <master bundle> <slave bundle>");
+ System.out.println("");
+ System.out.println(" Reorders keys/values in a slave bundle according to a master bundle.");
+ System.out.println("");
+ System.out.println(" BundleTool compare <master bundle> <slave bundle>");
+ System.out.println("");
+ System.out.println(" Compares availability of bundle keys.");
+ System.out.println("");
+ System.out.println(" BundleTool encode <bundle> <encoding> <destinationfile>");
+ System.out.println("");
+ System.out.println(" Encodes the keys/values with a custom encoding.");
+ System.out.println("");
+ System.out.println(" BundleTool decode <bundle> <encoding> <sourcefile>");
+ System.out.println("");
+ System.out.println(" Decodes the keys/values with a custom encoding.");
+ System.out.println(" BundleTool rename <old key> <new key> <bundle> [<bundle> [ ... ]]");
+ System.out.println("");
+ System.out.println(" Decodes the keys/values with a custom encoding.");
+ }
-import mir.util.ExceptionFunctions;
-import mir.util.PropertiesManipulator;\r
-\r
-public class BundleTool {\r
-\r
- public static void compare(String aMaster, String aSlave) {\r
- PropertiesManipulator master;\r
- PropertiesManipulator slave;\r
- PropertiesManipulator result;\r
-\r
- try {\r
- master = PropertiesManipulator.readProperties(new FileInputStream(new File(aMaster)));\r
- }\r
- catch (Throwable t) {\r
- System.out.println("Unable to read master properties: " + t.getMessage());\r
- return;\r
- }\r
-\r
- try {\r
- slave = PropertiesManipulator.readProperties(new FileInputStream(new File(aSlave)));\r
- }\r
- catch (FileNotFoundException t) {\r
- slave = new PropertiesManipulator();\r
- }\r
- catch (Throwable t) {\r
- System.out.println("Unable to read slave properties: " + t.getMessage());\r
- return;\r
- }\r
-\r
- int missing=0;\r
-\r
- Iterator i = master.getEntries();\r
- while (i.hasNext()) {\r
- Object e = i.next();\r
-\r
- if (e instanceof PropertiesManipulator.Entry) {\r
- String key = ( (PropertiesManipulator.Entry) e).getKey();\r
-\r
- if (!slave.containsKey(key) || slave.get(key) == null || slave.get(key).length()==0 ) {\r
- if (missing==0) {\r
- System.out.println(aSlave+" is missing:");\r
- }\r
- System.out.println(" " + key);\r
- missing++;\r
- }\r
- }\r
- }\r
-\r
- if (missing>0)\r
- System.out.println("total missing: " +missing);\r
-\r
- missing=0;\r
- i = slave.getEntries();\r
- while (i.hasNext()) {\r
- Object e = i.next();\r
-\r
- if (e instanceof PropertiesManipulator.Entry) {\r
- String key = ( (PropertiesManipulator.Entry) e).getKey();\r
-\r
- if (!master.containsKey(key)) {\r
- if (missing==0) {\r
- System.out.println(aSlave+" has extra:");\r
- }\r
- System.out.println(" " + key);\r
- missing++;\r
- }\r
- }\r
- }\r
- if (missing>0)\r
- System.out.println("total extra: " +missing);\r
- }\r
-\r
- public static void align(String aMaster, String aSlave) {\r
- PropertiesManipulator master;\r
- PropertiesManipulator slave;\r
- PropertiesManipulator result;\r
-\r
- try {\r
- master = PropertiesManipulator.readProperties(new FileInputStream(new File(aMaster)));\r
- }\r
- catch (Throwable t) {\r
- System.out.println("Unable to read master properties: " + t.getMessage());\r
- return;\r
- }\r
-\r
- try {\r
- slave = PropertiesManipulator.readProperties(new FileInputStream(new File(aSlave)));\r
- }\r
- catch (FileNotFoundException t) {\r
- slave = new PropertiesManipulator();\r
- }\r
- catch (Throwable t) {\r
- System.out.println("Unable to read slave properties: " + t.getMessage());\r
- return;\r
- }\r
-\r
- result = new PropertiesManipulator();\r
-\r
- // skip past the header in the slave bundle\r
- Iterator i = slave.getEntries();\r
- while (i.hasNext()) {\r
- Object e = i.next();\r
-\r
- if (e instanceof PropertiesManipulator.EmptyLine) {\r
- result.addEmptyLine();\r
- }\r
- else if (e instanceof PropertiesManipulator.Comment) {\r
- result.addComment( ( (PropertiesManipulator.Comment) e).getComment());\r
- }\r
-\r
- if (! (e instanceof PropertiesManipulator.Comment))\r
- break;\r
- }\r
-\r
- boolean insideHeader = true;\r
- i = master.getEntries();\r
- while (i.hasNext()) {\r
- Object e = i.next();\r
-\r
- if (!insideHeader && (e instanceof PropertiesManipulator.EmptyLine)) {\r
- result.addEmptyLine();\r
- }\r
- else if (!insideHeader && e instanceof PropertiesManipulator.Comment) {\r
- result.addComment( ( (PropertiesManipulator.Comment) e).getComment());\r
- }\r
- else if (e instanceof PropertiesManipulator.Entry) {\r
- String key = ( (PropertiesManipulator.Entry) e).getKey();\r
- String value = slave.get(key);\r
-\r
- if (value==null || value.length()==0) {\r
- result.addComment("# missing (master value = \"" +master.get(key)+"\")");\r
- }\r
-\r
- result.addEntry(key, value);\r
- }\r
-\r
- insideHeader = insideHeader && (e instanceof PropertiesManipulator.Comment);\r
- }\r
-\r
- try {\r
- PropertiesManipulator.writeProperties(result, new FileOutputStream(new File(aSlave)));\r
- }\r
- catch (Throwable t) {\r
- System.out.println("Unable to write slave properties: " + t.getMessage());\r
- return;\r
- }\r
- }\r
-\r
- public static void encode(String aBundle, String anEncoding, String anOutputFile) {\r
- PropertiesManipulator bundle;\r
-\r
- try {\r
- bundle = PropertiesManipulator.readProperties(new FileInputStream(new File(aBundle)));\r
-\r
- PropertiesManipulator.writeProperties(bundle, new FileOutputStream(anOutputFile), anEncoding, false);\r
- }\r
- catch (Throwable t) {\r
- System.out.println("Unable to read master properties: " + t.getMessage());\r
- return;\r
- }\r
- }\r
-\r
- public static void decode(String aBundle, String anEncoding, String aSourceFile) {\r
- PropertiesManipulator bundle;\r
-\r
- try {\r
- bundle = PropertiesManipulator.readProperties(new FileInputStream(new File(aSourceFile)), anEncoding);\r
- }\r
- catch (Throwable t) {\r
- Throwable s = ExceptionFunctions.traceCauseException(t);\r
-\r
- System.out.println("Unable to read sourcefile: " + s.toString());\r
- return;\r
- }\r
- try {\r
- PropertiesManipulator.writeProperties(bundle, new FileOutputStream(aBundle));\r
- }\r
- catch (Throwable t) {\r
- System.out.println("Unable to write bundle: " + t.toString());\r
- return;\r
- }\r
- }\r
-\r
- public static void main(String[] anArguments) {\r
- String command = "help";\r
-\r
- if (anArguments.length >= 1) {\r
- command = anArguments[0];\r
-\r
- if (command.equals("compare")) {\r
- if (anArguments.length==3) {\r
- compare(anArguments[1], anArguments[2]);\r
-\r
- return;\r
- }\r
- }\r
- else if (command.equals("align")) {\r
- if (anArguments.length==3) {\r
- align(anArguments[1], anArguments[2]);\r
-\r
- return;\r
- }\r
- }\r
- else if (command.equals("encode")) {\r
- if (anArguments.length==4) {\r
- encode(anArguments[1], anArguments[2], anArguments[3]);\r
-\r
- return;\r
- }\r
- }\r
- else if (command.equals("decode")) {\r
- if (anArguments.length==4) {\r
- decode(anArguments[1], anArguments[2], anArguments[3]);\r
-\r
- return;\r
- }\r
- }\r
- }\r
-\r
-\r
-\r
- System.out.println("Usage:");\r
-\r
- System.out.println(" BundleTool align <master bundle> <slave bundle>");\r
- System.out.println("");\r
- System.out.println(" Reorders keys/values in a slave bundle according to a master bundle.");\r
- System.out.println("");\r
- System.out.println(" BundleTool compare <master bundle> <slave bundle>");\r
- System.out.println("");\r
- System.out.println(" Compares availability of bundle keys.");\r
- System.out.println("");\r
- System.out.println(" BundleTool encode <bundle> <encoding> <destinationfile>");\r
- System.out.println("");\r
- System.out.println(" Encodes the keys/values with a custom encoding.");\r
- System.out.println("");\r
- System.out.println(" BundleTool decode <bundle> <encoding> <sourcefile>");\r
- System.out.println("");\r
- System.out.println(" Decodes the keys/values with a custom encoding.");\r
- }\r
-\r
}
\ No newline at end of file