-package mir.producer;
-
+package mir.producer;\r
+\r
import java.util.Map;\r
\r
import mir.log.LoggerWrapper;\r
import mir.rss.RSSData;\r
import mir.rss.RSSReader;\r
import mir.rss.RSSToMapConverter;\r
-import mir.util.ParameterExpander;
-
-public class RSSProducerNode implements ProducerNode {
- private String key;
- private String url;
-
- public RSSProducerNode(String aKey, String anURL) {
- key = aKey;
- url = anURL;
- }
-
- public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure {
- try {
- String expandedKey = ParameterExpander.expandExpression( aValueMap, key );
- String expandedUrl = ParameterExpander.expandExpression( aValueMap, url );
-
- RSSReader reader = new RSSReader();
- RSSData rssData = reader.parseUrl(url);
- ParameterExpander.setValueForKey(aValueMap, expandedKey, RSSToMapConverter.convertRSSData(rssData));
- }
- catch (Throwable t) {
- aLogger.error("Error while processing RSS data: " + t.toString());
- }
- };
+import mir.util.ParameterExpander;\r
+import mir.util.ExceptionFunctions;\r
+\r
+public class RSSProducerNode implements ProducerNode {\r
+ private String key;\r
+ private String url;\r
+\r
+ public RSSProducerNode(String aKey, String anURL) {\r
+ key = aKey;\r
+ url = anURL;\r
+ }\r
+\r
+ public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure {\r
+ try {\r
+ String expandedKey = ParameterExpander.expandExpression( aValueMap, key );\r
+ String expandedUrl = ParameterExpander.expandExpression( aValueMap, url );\r
+\r
+ ParameterExpander.setValueForKey(aValueMap, expandedKey, null);\r
+ RSSReader reader = new RSSReader();\r
+ RSSData rssData = reader.parseUrl(expandedUrl);\r
+ ParameterExpander.setValueForKey(aValueMap, expandedKey, RSSToMapConverter.convertRSSData(rssData));\r
+ }\r
+ catch (Throwable t) {\r
+ Throwable s = ExceptionFunctions.traceCauseException(t);\r
+ aLogger.error("Error while processing RSS data: " + s.getClass().getName()+","+ s.getMessage());\r
+ }\r
+ };\r
}
\ No newline at end of file
--- /dev/null
+package mir.util;\r
+\r
+import java.io.InputStream;\r
+import java.io.InputStreamReader;\r
+import java.io.LineNumberReader;\r
+import java.io.OutputStream;\r
+import java.io.*;\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Vector;\r
+\r
+import multex.Exc;\r
+import multex.Failure;\r
+\r
+public class PropertiesManipulator {\r
+ private List entries;\r
+ private Map values;\r
+\r
+ public PropertiesManipulator() {\r
+ entries = new Vector();\r
+ values = new HashMap();\r
+ }\r
+\r
+ public void addEmptyLine() {\r
+ entries.add(new EmptyLine());\r
+ }\r
+\r
+ public void addComment(String aComment) {\r
+ entries.add(new Comment(aComment));\r
+ }\r
+\r
+ public void addEntry(String aKey, String aValue) {\r
+ entries.add(new Entry(aKey, aValue));\r
+ values.put(aKey, aValue);\r
+ }\r
+\r
+ public Iterator getEntries() {\r
+ return entries.iterator();\r
+ }\r
+\r
+ public String get(String aKey) {\r
+ return (String) values.get(aKey);\r
+ }\r
+\r
+ public static class Comment {\r
+ private String comment;\r
+\r
+ public Comment(String aComment) {\r
+ comment = aComment;\r
+ }\r
+\r
+ public String getComment() {\r
+ return comment;\r
+ }\r
+ }\r
+\r
+ public static class EmptyLine {\r
+ public EmptyLine() {\r
+ }\r
+ }\r
+\r
+ public static class Entry {\r
+ private String key;\r
+ private String value;\r
+\r
+ public Entry(String aKey, String aValue) {\r
+ key = aKey;\r
+ value = aValue;\r
+ }\r
+\r
+ public String getKey() {\r
+ return key;\r
+ }\r
+\r
+ public String getValue() {\r
+ return value;\r
+ }\r
+ }\r
+\r
+ private final static String PLAIN= "[^\\\\]*";\r
+ private final static String ESCAPE= "\\\\[ tn]";\r
+ private final static String UNICODE= "\\\\u[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]";\r
+\r
+\r
+ private static String decode(String aValue) {\r
+ try {\r
+ SimpleParser parser = new SimpleParser(aValue);\r
+ StringBuffer result = new StringBuffer();\r
+\r
+ while (!parser.isAtEnd()) {\r
+ result.append(parser.parse(PLAIN));\r
+\r
+ if (!parser.isAtEnd()) {\r
+ if (parser.parses(UNICODE)) {\r
+ String unicode = parser.parse(UNICODE);\r
+\r
+ result.append((char) Integer.parseInt(unicode.substring(2,6), 16));\r
+ }\r
+ else if (parser.parses(ESCAPE)) {\r
+ String escape = parser.parse(ESCAPE);\r
+ result.append(escape.substring(1));\r
+ }\r
+ else\r
+ throw new PropertiesManipulatorExc("Invalid escape code: " + parser.remainingData());\r
+ }\r
+ }\r
+\r
+ return result.toString();\r
+ }\r
+ catch (Throwable t) {\r
+ throw new PropertiesManipulatorFailure(t);\r
+ }\r
+ }\r
+\r
+ private static String encode(String aValue) {\r
+ try {\r
+ StringBuffer result = new StringBuffer();\r
+ boolean leadingspace=true;\r
+\r
+ for (int i = 0; i<aValue.length(); i++) {\r
+ char c = aValue.charAt(i);\r
+\r
+ if (c<0x20 || c>0x7e) {\r
+ String code=Integer.toHexString(c);\r
+ result.append("\\u");\r
+ for (int j=0; j<4-code.length(); j++)\r
+ result.append("0");\r
+ result.append(code);\r
+ }\r
+ else if (c=='\\')\r
+ {\r
+ result.append("\\\\");\r
+ }\r
+ else if (c=='\n')\r
+ {\r
+ result.append("\\n");\r
+ }\r
+ else if (c=='\r')\r
+ {\r
+ result.append("\\r");\r
+ }\r
+ else if (c=='\t')\r
+ {\r
+ result.append("\\t");\r
+ }\r
+ else if (c==' ' && leadingspace) {\r
+ result.append("\\ ");\r
+ }\r
+ else {\r
+ result.append(c);\r
+ }\r
+\r
+ leadingspace = leadingspace && c ==' ';\r
+ }\r
+\r
+ return result.toString();\r
+ }\r
+ catch (Throwable t) {\r
+ throw new PropertiesManipulatorFailure(t);\r
+ }\r
+ }\r
+\r
+ // ML: to be fixed\r
+ private final static String SPACE = "[\t\n\r ]*";\r
+ private final static String KEY = "(([\\\\].)|([^\\\\=: \t\n\r]))*";\r
+ private final static String SEPARATOR = "[\t\n\r ]*[:=]?[\t\n\r ]*";\r
+ private final static String VALUE = "(([\\\\].)|([^\\\\]))*";\r
+\r
+ public static PropertiesManipulator readProperties(InputStream anInputStream) throws PropertiesManipulatorExc, PropertiesManipulatorFailure {\r
+ try {\r
+ PropertiesManipulator result = new PropertiesManipulator();\r
+ LineNumberReader reader = new LineNumberReader(new InputStreamReader(anInputStream, "ISO-8859-1"));\r
+\r
+ String line = reader.readLine();\r
+\r
+ while (line != null) {\r
+ String trimmedLine = line.trim();\r
+\r
+ if (trimmedLine.length() == 0) {\r
+ result.addEmptyLine();\r
+ }\r
+ else if (trimmedLine.startsWith("!") || trimmedLine.startsWith("#")) {\r
+ result.addComment(line);\r
+ }\r
+ else {\r
+ SimpleParser parser = new SimpleParser(line);\r
+ parser.skip(SPACE);\r
+ String key = parser.parse(KEY);\r
+ parser.skip(SEPARATOR);\r
+ String value = parser.parse(VALUE);\r
+ while (parser.remainingData().length()>0) {\r
+ if (!parser.remainingData().equals("\\"))\r
+ throw new PropertiesManipulatorExc("internal error: remainingData = " + parser.remainingData());\r
+\r
+ line = reader.readLine();\r
+ if (line==null) {\r
+ throw new PropertiesManipulatorExc("Unexpected end of file");\r
+ }\r
+ parser = new SimpleParser(line);\r
+ parser.skip(SPACE);\r
+ value = value + parser.parse(VALUE);\r
+ }\r
+\r
+ result.addEntry(decode(key), decode(value));\r
+ }\r
+ line = reader.readLine();\r
+ }\r
+\r
+ reader.close();\r
+\r
+ return result;\r
+ }\r
+ catch (PropertiesManipulatorExc t) {\r
+ throw t;\r
+ }\r
+ catch (Throwable t) {\r
+ throw new PropertiesManipulatorFailure(t);\r
+ }\r
+ }\r
+\r
+ public static void writeProperties(PropertiesManipulator aProperties, OutputStream anOutputStream) throws PropertiesManipulatorExc, PropertiesManipulatorFailure {\r
+ try {\r
+ PrintWriter p = new PrintWriter(new OutputStreamWriter(anOutputStream, "ISO-8859-1"));\r
+\r
+ try {\r
+ Iterator i = aProperties.getEntries();\r
+\r
+ while (i.hasNext()) {\r
+ Object entry = i.next();\r
+\r
+ if (entry instanceof EmptyLine) {\r
+ p.println();\r
+ }\r
+ else if (entry instanceof Comment) {\r
+ p.println(((Comment) entry).getComment());\r
+ }\r
+ else if (entry instanceof Entry) {\r
+ String key = encode( ( (Entry) entry).getKey());\r
+ String value = "";\r
+ if ( ( (Entry) entry).getValue() != null)\r
+ value = encode( ( (Entry) entry).getValue());\r
+\r
+ String line = key + " = " + value;\r
+\r
+ p.println(line);\r
+\r
+ }\r
+ else throw new PropertiesManipulatorExc("Unknown entry class: " +entry.getClass().getName());\r
+ }\r
+ }\r
+ finally {\r
+ p.close();\r
+ }\r
+ }\r
+ catch (Throwable t) {\r
+ throw new PropertiesManipulatorFailure(t);\r
+ }\r
+ }\r
+\r
+ public static class PropertiesManipulatorFailure extends Failure {\r
+ public PropertiesManipulatorFailure(Throwable aThrowable) {\r
+ super(aThrowable.getMessage(), aThrowable);\r
+ }\r
+\r
+ public PropertiesManipulatorFailure(String aMessage, Throwable aThrowable) {\r
+ super(aMessage, aThrowable);\r
+ }\r
+ }\r
+\r
+ public static class PropertiesManipulatorExc extends Exc {\r
+ public PropertiesManipulatorExc(String aMessage) {\r
+ super(aMessage);\r
+ }\r
+ }\r
+}
\ No newline at end of file
-/*
- * 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 the com.oreilly.servlet library, 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 mir.util;
-
-import gnu.regexp.RE;
-import gnu.regexp.REException;
-import gnu.regexp.REMatch;
-import multex.Exc;
-import multex.Failure;
-
-public class SimpleParser {
- private String data;
- private int position;
-
- public SimpleParser(String aData) {
- data=aData;
- position=0;
- }
-
- public boolean parses(RE aRegularExpression) throws SimpleParserExc {
- REMatch match = aRegularExpression.getMatch(data, position);
-
- return (match!=null && match.getStartIndex()==position) ;
- }
-
- public String parse(RE aRegularExpression, String aMessage) throws SimpleParserExc {
- REMatch match = aRegularExpression.getMatch(data, position);
-
- if (match==null || match.getStartIndex()!=position)
- throw new SimpleParserExc(aMessage+" at position "+position+" in '"+data+"'");
-
- position=match.getEndIndex();
-
- return match.toString();
- }
-
- public String parse(RE aRegularExpression) throws SimpleParserExc {
- return parse( aRegularExpression, "No match found for '"+aRegularExpression.toString()+"'");
- }
-
- public void skip(RE aRegularExpression) throws SimpleParserExc {
- REMatch match = aRegularExpression.getMatch(data, position);
-
- if (match!=null && match.getStartIndex()==position)
- position=match.getEndIndex();
- }
-
- public boolean parses(String anExpression) throws SimpleParserExc {
- try {
- return parses(new RE(anExpression));
- }
- catch (SimpleParserExc e) {
- throw e;
- }
- catch (REException e) {
- throw new SimpleParserFailure( "Error compiling regular expression '" + anExpression + "': " + e.getMessage(), e);
- }
- catch (Throwable t) {
- throw new SimpleParserFailure( t );
- }
- }
-
- public String parse(String anExpression) throws SimpleParserExc, SimpleParserFailure {
- try {
- return parse(new RE(anExpression));
- }
- catch (SimpleParserExc e) {
- throw e;
- }
- catch (REException e) {
- throw new SimpleParserFailure( "Error compiling regular expression '" + anExpression + "': " + e.getMessage(), e);
- }
- catch (Throwable t) {
- throw new SimpleParserFailure( t );
- }
- }
-
- public String parse(String anExpression, String aMessage) throws SimpleParserExc, SimpleParserFailure {
- try {
- return parse(new RE(anExpression), aMessage);
- }
- catch (SimpleParserExc e) {
- throw e;
- }
- catch (REException e) {
- throw new SimpleParserFailure( "Error compiling regular expression '" + anExpression + "': " + e.getMessage(), e);
- }
- catch (Throwable t) {
- throw new SimpleParserFailure( t );
- }
- }
-
- public void skip(String anExpression) throws SimpleParserExc, SimpleParserFailure {
- try {
- skip(new RE(anExpression));
- }
- catch (SimpleParserExc e) {
- throw e;
- }
- catch (REException e) {
- throw new SimpleParserFailure( "Error compiling regular expression '" + anExpression + "': " + e.getMessage(), e);
- }
- catch (Throwable t) {
- throw new SimpleParserFailure( t );
- }
- }
- public boolean isAtEnd() {
- return position>=data.length();
- }
-
- public static class SimpleParserFailure extends Failure {
- public SimpleParserFailure(Throwable aThrowable) {
- super(aThrowable.getMessage(), aThrowable);
- }
-
- public SimpleParserFailure(String aMessage, Throwable aThrowable) {
- super(aMessage, aThrowable);
- }
- }
-
- public static class SimpleParserExc extends Exc {
- public SimpleParserExc(String aMessage) {
- super(aMessage);
- }
- }
+/*\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 mir.util;\r
+\r
+import gnu.regexp.RE;\r
+import gnu.regexp.REException;\r
+import gnu.regexp.REMatch;\r
+import multex.Exc;\r
+import multex.Failure;\r
+\r
+/**\r
+ * a class to do some basic, regexp based parsing of character data\r
+ *\r
+ * <p>Title: </p>\r
+ * <p>Description: </p>\r
+ * <p>Copyright: Copyright (c) 2003</p>\r
+ * <p>Company: </p>\r
+ * @author not attributable\r
+ * @version 1.0\r
+ */\r
+\r
+public class SimpleParser {\r
+ private String data;\r
+ private int position;\r
+\r
+ /**\r
+ *\r
+ * @param aData\r
+ */\r
+\r
+ public SimpleParser(String aData) {\r
+ data=aData;\r
+ position=0;\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param aRegularExpression\r
+ * @return\r
+ * @throws SimpleParserExc\r
+ */\r
+\r
+ public boolean parses(RE aRegularExpression) throws SimpleParserExc {\r
+ REMatch match = aRegularExpression.getMatch(data, position);\r
+\r
+ return (match!=null && match.getStartIndex()==position) ;\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param aRegularExpression\r
+ * @param aMessage\r
+ * @return\r
+ * @throws SimpleParserExc\r
+ */\r
+\r
+ public String parse(RE aRegularExpression, String aMessage) throws SimpleParserExc {\r
+ REMatch match = aRegularExpression.getMatch(data, position);\r
+\r
+ if (match==null || match.getStartIndex()!=position)\r
+ throw new SimpleParserExc(aMessage+" at position "+position+" in '"+data+"'");\r
+\r
+ position=match.getEndIndex();\r
+\r
+ return match.toString();\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param aRegularExpression\r
+ * @return\r
+ * @throws SimpleParserExc\r
+ */\r
+\r
+ public String parse(RE aRegularExpression) throws SimpleParserExc {\r
+ return parse( aRegularExpression, "No match found for '"+aRegularExpression.toString()+"'");\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param aRegularExpression\r
+ * @throws SimpleParserExc\r
+ */\r
+\r
+ public void skip(RE aRegularExpression) throws SimpleParserExc {\r
+ REMatch match = aRegularExpression.getMatch(data, position);\r
+\r
+ if (match!=null && match.getStartIndex()==position)\r
+ position=match.getEndIndex();\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param anExpression\r
+ * @return\r
+ * @throws SimpleParserExc\r
+ */\r
+\r
+ public boolean parses(String anExpression) throws SimpleParserExc {\r
+ try {\r
+ return parses(new RE(anExpression));\r
+ }\r
+ catch (SimpleParserExc e) {\r
+ throw e;\r
+ }\r
+ catch (REException e) {\r
+ throw new SimpleParserFailure( "Error compiling regular expression '" + anExpression + "': " + e.getMessage(), e);\r
+ }\r
+ catch (Throwable t) {\r
+ throw new SimpleParserFailure( t );\r
+ }\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param anExpression\r
+ * @return\r
+ * @throws SimpleParserExc\r
+ * @throws SimpleParserFailure\r
+ */\r
+\r
+ public String parse(String anExpression) throws SimpleParserExc, SimpleParserFailure {\r
+ try {\r
+ return parse(new RE(anExpression));\r
+ }\r
+ catch (SimpleParserExc e) {\r
+ throw e;\r
+ }\r
+ catch (REException e) {\r
+ throw new SimpleParserFailure( "Error compiling regular expression '" + anExpression + "': " + e.getMessage(), e);\r
+ }\r
+ catch (Throwable t) {\r
+ throw new SimpleParserFailure( t );\r
+ }\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param anExpression\r
+ * @param aMessage\r
+ * @return\r
+ * @throws SimpleParserExc\r
+ * @throws SimpleParserFailure\r
+ */\r
+\r
+ public String parse(String anExpression, String aMessage) throws SimpleParserExc, SimpleParserFailure {\r
+ try {\r
+ return parse(new RE(anExpression), aMessage);\r
+ }\r
+ catch (SimpleParserExc e) {\r
+ throw e;\r
+ }\r
+ catch (REException e) {\r
+ throw new SimpleParserFailure( "Error compiling regular expression '" + anExpression + "': " + e.getMessage(), e);\r
+ }\r
+ catch (Throwable t) {\r
+ throw new SimpleParserFailure( t );\r
+ }\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @param anExpression\r
+ * @throws SimpleParserExc\r
+ * @throws SimpleParserFailure\r
+ */\r
+\r
+ public void skip(String anExpression) throws SimpleParserExc, SimpleParserFailure {\r
+ try {\r
+ skip(new RE(anExpression));\r
+ }\r
+ catch (SimpleParserExc e) {\r
+ throw e;\r
+ }\r
+ catch (REException e) {\r
+ throw new SimpleParserFailure( "Error compiling regular expression '" + anExpression + "': " + e.getMessage(), e);\r
+ }\r
+ catch (Throwable t) {\r
+ throw new SimpleParserFailure( t );\r
+ }\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @return true if the parser is at the end of the data\r
+ */\r
+\r
+ public boolean isAtEnd() {\r
+ return position>=data.length();\r
+ }\r
+\r
+ /**\r
+ *\r
+ * @return\r
+ */\r
+ public String remainingData() {\r
+ return data.substring(position);\r
+ }\r
+\r
+ /**\r
+ *\r
+ * <p>Title: </p>\r
+ * <p>Description: </p>\r
+ * <p>Copyright: Copyright (c) 2003</p>\r
+ * <p>Company: </p>\r
+ * @author not attributable\r
+ * @version 1.0\r
+ */\r
+\r
+ public static class SimpleParserFailure extends Failure {\r
+ public SimpleParserFailure(Throwable aThrowable) {\r
+ super(aThrowable.getMessage(), aThrowable);\r
+ }\r
+\r
+ public SimpleParserFailure(String aMessage, Throwable aThrowable) {\r
+ super(aMessage, aThrowable);\r
+ }\r
+ }\r
+\r
+ public static class SimpleParserExc extends Exc {\r
+ public SimpleParserExc(String aMessage) {\r
+ super(aMessage);\r
+ }\r
+ }\r
}
\ No newline at end of file
package mircoders.global;\r
\r
+import java.io.File;\r
import java.io.FileNotFoundException;\r
+import java.io.FileOutputStream;\r
import java.util.Arrays;\r
import java.util.Date;\r
import java.util.HashMap;\r
import java.util.Iterator;\r
import java.util.List;\r
import java.util.Map;\r
-import java.util.Vector;\r
import java.util.Random;\r
-import java.io.*;\r
-import javax.servlet.http.*;\r
+import java.util.Vector;\r
+import javax.servlet.http.Cookie;\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
+\r
+import org.apache.commons.collections.ExtendedProperties;\r
\r
-import org.apache.commons.collections.*;\r
import gnu.regexp.RE;\r
\r
+import mir.entity.Entity;\r
import mir.log.LoggerWrapper;\r
import mir.util.DateToMapAdapter;\r
+import mir.util.InternetFunctions;\r
import mir.util.StringRoutines;\r
-import mir.util.*;\r
-import mir.entity.*;\r
-\r
import mircoders.entity.EntityComment;\r
import mircoders.entity.EntityContent;\r
import mircoders.localizer.MirAdminInterfaceLocalizer;\r
--- /dev/null
+package tool;\r
+\r
+import java.util.*;\r
+import java.io.*;\r
+import org.apache.commons.collections.*;\r
+\r
+import mir.util.*;\r
+\r
+public class BundleTool {\r
+ public static void main(String[] anArguments) {\r
+\r
+ if (anArguments.length!=3) {\r
+ System.out.println("Usage:");\r
+\r
+ System.out.println(" BundleTool <bundle base> <master locale> <slave locale>");\r
+ System.out.println("");\r
+ System.out.println("Description:");\r
+ System.out.println(" Reorders keys/values from a slave bundle according to a master bundle.");\r
+\r
+ return;\r
+ }\r
+\r
+ PropertiesManipulator master;\r
+ PropertiesManipulator slave;\r
+ PropertiesManipulator result;\r
+\r
+ try {\r
+ master = PropertiesManipulator.readProperties(new FileInputStream(new File(anArguments[0] + "_" + anArguments[1] + ".properties")));\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(anArguments[0] + "_" + anArguments[2] + ".properties")));\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
+ result = new PropertiesManipulator();\r
+\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
+ result.addEntry(key,value);\r
+ }\r
+\r
+ insideHeader = insideHeader && (e instanceof PropertiesManipulator.Comment);\r
+ }\r
+ try {\r
+ PropertiesManipulator.writeProperties(result, new FileOutputStream(new File(anArguments[0] + "_" + anArguments[2] + ".properties")));\r
+ }\r
+ catch (Throwable t) {\r
+ System.out.println("Unable to write slave properties: " + t.getMessage());\r
+ return;\r
+ }\r
+ }\r
+}
\ No newline at end of file