From: zapata Date: Sun, 30 Mar 2003 13:16:19 +0000 (+0000) Subject: first preliminary version of support for displaying RSS feeds X-Git-Tag: BEFORE_MERGE_1_1~194 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=3da84ce0196319b33211328515e3ca12b422c95c;p=mir.git first preliminary version of support for displaying RSS feeds --- diff --git a/source/mir/log/Log.java b/source/mir/log/Log.java index 6e0db0c6..2184f76b 100755 --- a/source/mir/log/Log.java +++ b/source/mir/log/Log.java @@ -1,3 +1,34 @@ +/* + * 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.log; import mir.config.MirPropertiesConfiguration; diff --git a/source/mir/log/Logger.java b/source/mir/log/Logger.java index 9f1f4a1b..5152b542 100755 --- a/source/mir/log/Logger.java +++ b/source/mir/log/Logger.java @@ -1,3 +1,35 @@ +/* + * 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.log; diff --git a/source/mir/log/LoggerToWriterAdapter.java b/source/mir/log/LoggerToWriterAdapter.java index a9dc2948..91b57953 100755 --- a/source/mir/log/LoggerToWriterAdapter.java +++ b/source/mir/log/LoggerToWriterAdapter.java @@ -1,3 +1,35 @@ +/* + * 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.log; import java.io.Writer; diff --git a/source/mir/log/LoggerWrapper.java b/source/mir/log/LoggerWrapper.java index bf396ce4..f8316b58 100755 --- a/source/mir/log/LoggerWrapper.java +++ b/source/mir/log/LoggerWrapper.java @@ -1,3 +1,35 @@ +/* + * 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.log; import java.io.PrintWriter; diff --git a/source/mir/log/TestFramework.java b/source/mir/log/TestFramework.java index b7f924dd..dcec4c10 100755 --- a/source/mir/log/TestFramework.java +++ b/source/mir/log/TestFramework.java @@ -1,14 +1,44 @@ -package mir.log; +/* + * 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.log; public class TestFramework { - public static void main(String[] args) { - TestFramework t = new TestFramework(); + public static void main(String[] args) { + TestFramework t = new TestFramework(); - Log.info( TestFramework.class, "class"); - Log.info( t, "object" ); - Log.info( null, "lalala" ); - } + Log.info( TestFramework.class, "class"); + Log.info( t, "object" ); + Log.info( null, "lalala" ); + } } diff --git a/source/mir/log/log4j/LoggerImpl.java b/source/mir/log/log4j/LoggerImpl.java index 3470bff8..ede60697 100755 --- a/source/mir/log/log4j/LoggerImpl.java +++ b/source/mir/log/log4j/LoggerImpl.java @@ -1,3 +1,34 @@ +/* + * 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.log.log4j; import java.util.HashMap; diff --git a/source/mir/misc/FileUtil.java b/source/mir/misc/FileUtil.java index 017be8c3..0d78ff78 100755 --- a/source/mir/misc/FileUtil.java +++ b/source/mir/misc/FileUtil.java @@ -1,189 +1,191 @@ -/* - * 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.misc; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; - -import mir.config.MirPropertiesConfiguration; -import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; - -/** - * Hilfsklasse zum Mergen von Template und Daten - */ -public final class FileUtil { - - private static String producerStorageRoot; - - // - // Initialisierung - - static { - try { - producerStorageRoot = - MirPropertiesConfiguration.instance().getString("Producer.StorageRoot"); - } catch (PropertiesConfigExc e) { - e.printStackTrace(); - } - } - - /** - * Privater Konstruktor, um versehentliche Instantiierung zu verhindern - */ - private FileUtil () { - } - - public static File getFile(String filename) - throws IOException { - - try { - File f = null; - f = new File(filename); - File dir = new File(f.getParent()); - dir.mkdirs(); - - return f; - } catch(Exception e) { - throw new IOException(e.toString()); - } - - } - - public static long write(File f, InputStream in) - throws IOException { - - long size = 0; - - if (in!=null) { - try { - FileOutputStream out = new FileOutputStream(f); - - int read; - byte[] buf = new byte[8 * 1024]; - while((read = in.read(buf)) != -1) { - out.write(buf, 0, read); - size += read; - } - - in.close(); - out.close(); - } catch(IOException e) { - throw new IOException(e.toString()); - } - } - return size; - } - - public static long write(String filename, InputStream in) - throws IOException { - - long size = 0; - - if (in!=null) { - try { - File f = getFile(filename); - size = write(f, in); - } catch(IOException e) { - throw new IOException(e.toString()); - } - } - return size; - } - - public static long write(String filename, Reader in, String encoding) - throws IOException { - - long size = 0; - - if (in!=null) { - try { - File f = getFile(filename); - FileOutputStream fOut = new FileOutputStream(f); - OutputStreamWriter out = new OutputStreamWriter(fOut, encoding); - int read; - char[] cbuf = new char[8*1024]; - while((read = in.read(cbuf)) != -1) { - out.write(cbuf, 0, read); - size += read; - } - - out.close(); - in.close(); - } catch(IOException e) { - throw new IOException(e.toString()); - } - } - return size; - } - - public static boolean read(String filename, byte out[]) - throws IOException { - - File f = null; - f = new File(filename); - - if (f.exists()) { - try { - if (out.length != f.length()) - return false; - FileInputStream inStream; - inStream = new FileInputStream(f); - inStream.read(out); - inStream.close(); - } catch(IOException e) { - throw new IOException(e.toString()); - } - } else { - return false; - } - return true; - } - - public static long getSize(String filename) { - File f = null; - f = new File(filename); - long l=0; - - if (f.exists()) { - return f.length(); - } else { - return -1; - } - } - - -} +/* + * 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.misc; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; + +import mir.config.MirPropertiesConfiguration; +import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; + +/** + * Hilfsklasse zum Mergen von Template und Daten + */ +public final class FileUtil { + + private static String producerStorageRoot; + + // + // Initialisierung + + static { + try { + producerStorageRoot = + MirPropertiesConfiguration.instance().getString("Producer.StorageRoot"); + } + catch (PropertiesConfigExc e) { + e.printStackTrace(); + } + } + + /** + * Privater Konstruktor, um versehentliche Instantiierung zu verhindern + */ + private FileUtil() { + } + + public static File getFile(String filename) throws IOException { + + try { + File f = null; + f = new File(filename); + File dir = new File(f.getParent()); + dir.mkdirs(); + + return f; + } + catch (Exception e) { + throw new IOException(e.toString()); + } + + } + + public static long write(File f, InputStream in) throws IOException { + + long size = 0; + + if (in != null) { + try { + FileOutputStream out = new FileOutputStream(f); + + int read; + byte[] buf = new byte[8 * 1024]; + while ( (read = in.read(buf)) != -1) { + out.write(buf, 0, read); + size += read; + } + + in.close(); + out.close(); + } + catch (IOException e) { + throw new IOException(e.toString()); + } + } + return size; + } + + public static long write(String filename, InputStream in) throws IOException { + + long size = 0; + + if (in != null) { + try { + File f = getFile(filename); + size = write(f, in); + } + catch (IOException e) { + throw new IOException(e.toString()); + } + } + return size; + } + + public static long write(String filename, Reader in, String encoding) throws IOException { + + long size = 0; + + if (in != null) { + try { + File f = getFile(filename); + FileOutputStream fOut = new FileOutputStream(f); + OutputStreamWriter out = new OutputStreamWriter(fOut, encoding); + int read; + char[] cbuf = new char[8 * 1024]; + while ( (read = in.read(cbuf)) != -1) { + out.write(cbuf, 0, read); + size += read; + } + + out.close(); + in.close(); + } + catch (IOException e) { + throw new IOException(e.toString()); + } + } + return size; + } + + public static boolean read(String filename, byte out[]) throws IOException { + + File f = null; + f = new File(filename); + + if (f.exists()) { + try { + if (out.length != f.length()) + return false; + FileInputStream inStream; + inStream = new FileInputStream(f); + inStream.read(out); + inStream.close(); + } + catch (IOException e) { + throw new IOException(e.toString()); + } + } + else { + return false; + } + return true; + } + + public static long getSize(String filename) { + File f = null; + f = new File(filename); + long l = 0; + + if (f.exists()) { + return f.length(); + } + else { + return -1; + } + } + +} diff --git a/source/mir/producer/ExpandedAssignmentProducerNode.java b/source/mir/producer/ExpandedAssignmentProducerNode.java index de00c447..2e0b628f 100755 --- a/source/mir/producer/ExpandedAssignmentProducerNode.java +++ b/source/mir/producer/ExpandedAssignmentProducerNode.java @@ -31,9 +31,9 @@ package mir.producer; -import java.util.Map; - -import mir.log.LoggerWrapper; +import java.util.Map; + +import mir.log.LoggerWrapper; import mir.util.ParameterExpander; public class ExpandedAssignmentProducerNode implements ProducerNode { diff --git a/source/mir/producer/RSSProducerNode.java b/source/mir/producer/RSSProducerNode.java new file mode 100755 index 00000000..fc1c442b --- /dev/null +++ b/source/mir/producer/RSSProducerNode.java @@ -0,0 +1,33 @@ +package mir.producer; + +import java.util.Map; + +import mir.log.LoggerWrapper; +import mir.rss.RSSData; +import mir.rss.RSSReader; +import mir.rss.RSSToMapConverter; +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()); + } + }; +} \ No newline at end of file diff --git a/source/mir/producer/reader/DefaultProducerNodeBuilders.java b/source/mir/producer/reader/DefaultProducerNodeBuilders.java index fcfc3b3a..62524025 100755 --- a/source/mir/producer/reader/DefaultProducerNodeBuilders.java +++ b/source/mir/producer/reader/DefaultProducerNodeBuilders.java @@ -31,33 +31,34 @@ package mir.producer.reader; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import mir.entity.adapter.EntityAdapterModel; -import mir.generator.Generator; -import mir.generator.WriterEngine; -import mir.log.LoggerWrapper; -import mir.producer.ConditionalProducerNode; -import mir.producer.DirCopyingProducerNode; -import mir.producer.EntityBatchingProducerNode; -import mir.producer.EntityEnumeratingProducerNode; -import mir.producer.EntityListProducerNode; -import mir.producer.EvaluatedAssignmentProducerNode; -import mir.producer.ExpandedAssignmentProducerNode; -import mir.producer.FileDateSettingProducerNode; -import mir.producer.FileDeletingProducerNode; -import mir.producer.GeneratingProducerNode; -import mir.producer.LoggingProducerNode; -import mir.producer.LoopProducerNode; -import mir.producer.ProducerNode; -import mir.producer.ResourceBundleProducerNode; -import mir.producer.ScriptCallingProducerNode; -import mir.util.XMLReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import mir.entity.adapter.EntityAdapterModel; +import mir.generator.Generator; +import mir.generator.WriterEngine; +import mir.log.LoggerWrapper; +import mir.producer.ConditionalProducerNode; +import mir.producer.DirCopyingProducerNode; +import mir.producer.EntityBatchingProducerNode; +import mir.producer.EntityEnumeratingProducerNode; +import mir.producer.EntityListProducerNode; +import mir.producer.EvaluatedAssignmentProducerNode; +import mir.producer.ExpandedAssignmentProducerNode; +import mir.producer.FileDateSettingProducerNode; +import mir.producer.FileDeletingProducerNode; +import mir.producer.GeneratingProducerNode; +import mir.producer.LoggingProducerNode; +import mir.producer.LoopProducerNode; +import mir.producer.ProducerNode; +import mir.producer.RSSProducerNode; +import mir.producer.ResourceBundleProducerNode; +import mir.producer.ScriptCallingProducerNode; +import mir.util.XMLReader; import mir.util.XMLReaderTool; public class DefaultProducerNodeBuilders { @@ -78,6 +79,8 @@ public class DefaultProducerNodeBuilders { aBuilderLibrary.registerBuilder("If", ConditionalProducerNodeBuilder.class); aBuilderLibrary.registerBuilder("While", LoopProducerNodeBuilder.class); + aBuilderLibrary.registerBuilder("RSS", RSSProducerNodeBuilder.class); + aBuilderLibrary.registerFactory("Enumerate", new EnumeratingProducerNodeBuilder.factory(aModel)); aBuilderLibrary.registerFactory("List", new ListProducerNodeBuilder.factory(aModel)); aBuilderLibrary.registerFactory("Batch", new BatchingProducerNodeBuilder.factory(aModel)); @@ -121,6 +124,7 @@ public class DefaultProducerNodeBuilders { public final static String SKIP_ATTRIBUTE = "skip"; public final static String KEY_ATTRIBUTE = "key"; public final static String LIMIT_ATTRIBUTE = "limit"; + public final static String URL_ATTRIBUTE = "url"; //////////////////////////////////////////////////////////////////////////////// @@ -690,6 +694,35 @@ public class DefaultProducerNodeBuilders { //////////////////////////////////////////////////////////////////////////////// + public static class RSSProducerNodeBuilder extends AbstractProducerNodeBuilder { + private final static String RSS_KEY_ATTRIBUTE = KEY_ATTRIBUTE; + private final static String RSS_URL_ATTRIBUTE = URL_ATTRIBUTE; + + private final static String[] RSS_REQUIRED_ATTRIBUTES = { RSS_KEY_ATTRIBUTE, RSS_URL_ATTRIBUTE }; + private final static String[] RSS_OPTIONAL_ATTRIBUTES = { }; + private final static String[] RSS_SUBNODES = { }; + + private String key; + private String url; + + public RSSProducerNodeBuilder() { + super(RSS_SUBNODES); + } + + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { + XMLReaderTool.checkAttributes(anAttributes, RSS_REQUIRED_ATTRIBUTES, RSS_OPTIONAL_ATTRIBUTES); + + key = (String) anAttributes.get( RSS_KEY_ATTRIBUTE ); + url = (String) anAttributes.get( RSS_URL_ATTRIBUTE ); + }; + + public ProducerNode constructNode() { + return new RSSProducerNode(key, url); + }; + } + +//////////////////////////////////////////////////////////////////////////////// + public static class ScriptedProducerParameterNodeBuilder implements ProducerNodeBuilder { private String parameterName; private String scriptedNodeName; diff --git a/source/mir/producer/reader/ProducerConfigReader.java b/source/mir/producer/reader/ProducerConfigReader.java index 5e2d1249..46249ef5 100755 --- a/source/mir/producer/reader/ProducerConfigReader.java +++ b/source/mir/producer/reader/ProducerConfigReader.java @@ -31,6 +31,7 @@ package mir.producer.reader; +import java.io.File; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -61,11 +62,13 @@ public class ProducerConfigReader { public void parseFile(String aFileName, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories, List aUsedFiles) throws ProducerConfigFailure { try { XMLReader reader = new XMLReader(); + aUsedFiles.add(new File(aFileName)); builderLibrary = aBuilderLibrary; scriptedNodeBuilderLibrary = new ProducerNodeBuilderLibrary(); - reader.parseFile(aFileName, new RootSectionHandler(aProducerFactories), aUsedFiles); + reader.parseFile(aFileName, new RootSectionHandler(aProducerFactories)); + } catch (Throwable e) { if ((e instanceof XMLReader.XMLReaderExc) && ((XMLReader.XMLReaderExc) e).getHasLocation()) { diff --git a/source/mir/rss/RSSChannel.java b/source/mir/rss/RSSChannel.java new file mode 100755 index 00000000..54e1decb --- /dev/null +++ b/source/mir/rss/RSSChannel.java @@ -0,0 +1,85 @@ +/* + * 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.rss; + +import java.util.*; + +public class RSSChannel { + private String title; + private String link; + private String description; + private String identifier; + private List items; + + protected RSSChannel(String anIdentifier) { + items = new Vector(); + identifier = anIdentifier; + } + + protected void addItem(RSSItem anItem) { + items.add(anItem); + }; + + protected void setItems(List anItems) { + items.clear(); + items.addAll(anItems); + }; + + public List getItems() { + return items; + } + + public String getTitle() { + return title; + } + + public void setTitle(String aTitle) { + title = aTitle; + } + + public String getLink() { + return link; + } + + public void setLink(String aLink) { + link = aLink; + } + + public String getDescription() { + return description; + } + + public void setDescription(String aDescription) { + description = aDescription; + } + +} diff --git a/source/mir/rss/RSSData.java b/source/mir/rss/RSSData.java new file mode 100755 index 00000000..5f243996 --- /dev/null +++ b/source/mir/rss/RSSData.java @@ -0,0 +1,70 @@ +/* + * 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.rss; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +public class RSSData { + private List items; + private Map item; + private RSSChannel channel; + + protected RSSData() { + items = new Vector(); + item = new HashMap(); + channel = null; + } + + protected void addItem(RSSItem anItem) { + items.add(anItem); + item.put(anItem.getIdentifier(), anItem); + }; + + public void setChannel(RSSChannel aChannel) { + channel = aChannel; + } + + public RSSChannel getChannel() { + return channel; + } + + public List getItems() { + return items; + } + + public Map getItem() { + return item; + } +} diff --git a/source/mir/rss/RSSExc.java b/source/mir/rss/RSSExc.java new file mode 100755 index 00000000..ee304ea5 --- /dev/null +++ b/source/mir/rss/RSSExc.java @@ -0,0 +1,40 @@ +/* + * 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.rss; + +import multex.Exc; + +public class RSSExc extends Exc { + public RSSExc(String aMessage) { + super(aMessage); + } +} diff --git a/source/mir/rss/RSSFailure.java b/source/mir/rss/RSSFailure.java new file mode 100755 index 00000000..1fae9795 --- /dev/null +++ b/source/mir/rss/RSSFailure.java @@ -0,0 +1,44 @@ +/* + * 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.rss; + +import multex.Failure; + +public class RSSFailure extends Failure { + public RSSFailure(String aMessage,Throwable aCause) { + super(aMessage, aCause); + } + + public RSSFailure(Throwable aCause) { + this (aCause.getMessage(), aCause); + } +} diff --git a/source/mir/rss/RSSItem.java b/source/mir/rss/RSSItem.java new file mode 100755 index 00000000..eaf5c03f --- /dev/null +++ b/source/mir/rss/RSSItem.java @@ -0,0 +1,75 @@ +/* + * 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.rss; + +import java.util.*; + +public class RSSItem { + private String title; + private String link; + private String description; + private String identifier; + + protected RSSItem(String anIdentifier) { + identifier = anIdentifier; + } + + public String getIdentifier() { + return identifier; + } + + public String getTitle() { + return title; + } + + public void setTitle(String aTitle) { + title = aTitle; + } + + public String getLink() { + return link; + } + + public void setLink(String aLink) { + link = aLink; + } + + public String getDescription() { + return description; + } + + public void setDescription(String aDescription) { + description = aDescription; + } + +} + diff --git a/source/mir/rss/RSSReader.java b/source/mir/rss/RSSReader.java new file mode 100755 index 00000000..45fbe4f3 --- /dev/null +++ b/source/mir/rss/RSSReader.java @@ -0,0 +1,389 @@ +/* + * 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.rss; + +import java.io.InputStream; +import java.net.URL; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import mir.util.XMLReader; +import mir.util.XMLReaderTool; + +/** + * + *

Title:

+ *

Description:

+ *

Copyright: Copyright (c) 2003

+ *

Company:

+ * @author not attributable + * @version 1.0 + */ + +public class RSSReader { + public RSSReader() { + } + + public RSSData parseInputStream(InputStream aStream) throws RSSExc, RSSFailure { + try { + XMLReader xmlReader = new XMLReader(); + RSSData result = new RSSData(); + xmlReader.parseInputStream(aStream, new RootSectionHandler(result)); + + return result; + } + catch (Throwable t) { + throw new RSSFailure(t); + } + } + + public RSSData parseUrl(String anUrl) throws RSSExc, RSSFailure { + try { + InputStream inputStream = (InputStream) new URL(anUrl).getContent(new Class[] {InputStream.class}); + + if (inputStream==null) + throw new RSSExc("RSSChannel.parseUrl: Can't get url content"); + + return parseInputStream(inputStream); + } + catch (Throwable t) { + throw new RSSFailure(t); + } + } + + private static class RootSectionHandler extends XMLReader.AbstractSectionHandler { + private RSSData data; + + public RootSectionHandler(RSSData aData) { + data = aData; + } + + public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + if (XMLReaderTool.getLocalNameFromQualifiedName(aTag).equals("RDF")) { + return new RDFSectionHandler(data); + } + else + throw new XMLReader.XMLReaderFailure(new RSSExc("'RDF' tag expected")); + }; + + public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + }; + + public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + if (aCharacters.trim().length()>0) + throw new XMLReader.XMLReaderExc("No character data allowed here"); + }; + + public void finishSection() throws XMLReader.XMLReaderExc { + }; + } + + private static class RDFSectionHandler extends XMLReader.AbstractSectionHandler { + private RSSData data; + + public RDFSectionHandler(RSSData aData) { + data = aData; + } + + public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + String identifier = (String) anAttributes.get("rdf:about"); + + if (aTag.equals("channel")) { + if (identifier==null) + throw new XMLReader.XMLReaderFailure(new RSSExc("Missing rdf:about")); + else + return new ChannelSectionHandler(identifier); + } + else if (aTag.equals("item")) { + if (identifier==null) + throw new XMLReader.XMLReaderFailure(new RSSExc("Missing rdf:about")); + else + return new ItemSectionHandler(identifier); + } + else + return new DiscardingSectionHandler(); + }; + + public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + if (aHandler instanceof ItemSectionHandler) { + data.addItem(((ItemSectionHandler) aHandler).getItem()); + } + else if (aHandler instanceof ChannelSectionHandler) { + data.setChannel(((ChannelSectionHandler) aHandler).getChannel()); + } + }; + + public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + if (aCharacters.trim().length()>0) + throw new XMLReader.XMLReaderExc("No character data allowed here"); + }; + + public void finishSection() throws XMLReader.XMLReaderExc { + }; + } + + private static class ChannelSectionHandler extends XMLReader.AbstractSectionHandler { + private String image; + private String currentTag; + private RSSChannel channel; + + public ChannelSectionHandler(String anIdentifier) { + channel = new RSSChannel(anIdentifier); + } + + public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + currentTag = aTag; + if (currentTag.equals("items")) { + return new ChannelItemsSectionHandler(); + } + else if (currentTag.equals("description") || + currentTag.equals("link") || + currentTag.equals("title")) { + return new PCDATASectionHandler(); + } + + return new DiscardingSectionHandler(); + }; + + public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + if (currentTag.equals("items")) { + channel.setItems(((ChannelItemsSectionHandler) aHandler).getItems()); + } + if (currentTag.equals("description")) { + channel.setDescription(((PCDATASectionHandler) aHandler).getData()); + } + else if (currentTag.equals("title")) { + channel.setTitle(((PCDATASectionHandler) aHandler).getData()); + } + else if (currentTag.equals("link")) { + channel.setLink(((PCDATASectionHandler) aHandler).getData()); + } + }; + + public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + if (aCharacters.trim().length()>0) + throw new XMLReader.XMLReaderExc("No character data allowed here"); + }; + + public void finishSection() throws XMLReader.XMLReaderExc { + }; + + public RSSChannel getChannel () { + return channel; + } + } + + private static class ChannelItemsSectionHandler extends XMLReader.AbstractSectionHandler { + private List items; + + public ChannelItemsSectionHandler() { + items = new Vector(); + } + + public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + if (aTag.equals("rdf:Seq")) + return new RDFSequenceSectionHandler(); + else + return new DiscardingSectionHandler(); + }; + + public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + if (aHandler instanceof RDFSequenceSectionHandler) { + items.addAll(((RDFSequenceSectionHandler) aHandler).getItems()); + } + }; + + public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + if (aCharacters.trim().length()>0) + throw new XMLReader.XMLReaderExc("No character data allowed here"); + }; + + public void finishSection() throws XMLReader.XMLReaderExc { + }; + + public List getItems() { + return items; + } + } + + private static class ItemSectionHandler extends XMLReader.AbstractSectionHandler { + private String currentTag; + private RSSItem item; + + public ItemSectionHandler(String anIdentifier) { + item = new RSSItem(anIdentifier); + } + + public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + currentTag = aTag; + + if (currentTag.equals("description") || + currentTag.equals("link") || + currentTag.equals("title")) { + return new PCDATASectionHandler(); + } + + return new DiscardingSectionHandler(); + }; + + public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + if (currentTag.equals("description")) { + item.setDescription(((PCDATASectionHandler) aHandler).getData()); + } + else if (currentTag.equals("title")) { + item.setTitle(((PCDATASectionHandler) aHandler).getData()); + } + else if (currentTag.equals("link")) { + item.setLink(((PCDATASectionHandler) aHandler).getData()); + } + }; + + public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + if (aCharacters.trim().length()>0) + throw new XMLReader.XMLReaderExc("No character data allowed here"); + }; + + public void finishSection() throws XMLReader.XMLReaderExc { + }; + + public RSSItem getItem() { + return item; + }; + } + + private static class PCDATASectionHandler extends XMLReader.AbstractSectionHandler { + private StringBuffer data; + + public PCDATASectionHandler() { + data = new StringBuffer(); + } + + public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + throw new XMLReader.XMLReaderFailure(new RSSExc("No subtags allowed here")); + }; + + public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + }; + + public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + data.append(aCharacters); + }; + + public void finishSection() throws XMLReader.XMLReaderExc { + }; + + public String getData() { + return data.toString(); + } + } + + + private static class RDFSequenceSectionHandler extends XMLReader.AbstractSectionHandler { + private List items; + + public RDFSequenceSectionHandler() { + items = new Vector(); + } + + public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + if (aTag.equals("rdf:li")) { + String item = (String) anAttributes.get("rdf:resource"); + + if (item!=null) + items.add(item); + } + + return new DiscardingSectionHandler(); + }; + + public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + }; + + public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + }; + + public void finishSection() throws XMLReader.XMLReaderExc { + }; + + public List getItems() { + return items; + } + } + + private static class RDFLiteralSectionHandler extends XMLReader.AbstractSectionHandler { + private StringBuffer data; + private String tag; + + public RDFLiteralSectionHandler() { + data = new StringBuffer(); + } + + protected StringBuffer getData() { + return data; + } + + public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + tag=aTag; + data.append("<"+tag+">"); + + return new RDFLiteralSectionHandler(); + }; + + public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + data.append(((RDFLiteralSectionHandler) aHandler).getData()); + data.append(""); + }; + + public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + data.append(aCharacters); + }; + + public void finishSection() throws XMLReader.XMLReaderExc { + }; + } + + private static class DiscardingSectionHandler extends XMLReader.AbstractSectionHandler { + public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + return this; + }; + + public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + }; + + public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + }; + + public void finishSection() throws XMLReader.XMLReaderExc { + }; + } +} diff --git a/source/mir/rss/RSSToMapConverter.java b/source/mir/rss/RSSToMapConverter.java new file mode 100755 index 00000000..36b8461a --- /dev/null +++ b/source/mir/rss/RSSToMapConverter.java @@ -0,0 +1,77 @@ +/* + * 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.rss; + +import java.util.*; + +public class RSSToMapConverter { + private RSSToMapConverter() { + } + + public static Map convertRSSItem(RSSItem anItem) { + Map result = new HashMap(); + + result.put("title", anItem.getTitle()); + result.put("description", anItem.getDescription()); + result.put("link", anItem.getLink()); + + return result; + } + + public static Map convertRSSData(RSSData anRSSData) { + Map result = new HashMap(); + + Map channel = null; + if (anRSSData.getChannel()!=null) { + channel = new HashMap(); + channel.put("title", anRSSData.getChannel().getTitle()); + channel.put("description", anRSSData.getChannel().getDescription()); + channel.put("link", anRSSData.getChannel().getLink()); + + List items = new Vector(); + Iterator i = anRSSData.getChannel().getItems().iterator(); + + while (i.hasNext()) { + RSSItem item = (RSSItem) anRSSData.getItem().get(i.next()); + if (item!=null) { + items.add(convertRSSItem(item)); + } + } + + channel.put("items", items); + } + result.put("channel", channel); + result.put("data", anRSSData); + + return result; + } +} \ No newline at end of file diff --git a/source/mir/util/XMLReader.java b/source/mir/util/XMLReader.java index 6f77dcae..b8bc9e35 100755 --- a/source/mir/util/XMLReader.java +++ b/source/mir/util/XMLReader.java @@ -33,8 +33,11 @@ package mir.util; import java.io.File; import java.io.FileInputStream; +import java.io.StringReader; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; + import java.util.HashMap; import java.util.List; import java.util.Map; @@ -57,23 +60,44 @@ import org.xml.sax.helpers.DefaultHandler; public class XMLReader { private Locator locator; private String filename; + private boolean namespaceAware; + + public XMLReader() { + this(false); + } + + public XMLReader(boolean aNameSpaceAware) { + namespaceAware = aNameSpaceAware; + filename=""; + } - public void parseFile(String aFileName, SectionHandler aRootHandler, List aUsedFiles) throws XMLReaderFailure, XMLReaderExc { + public void parseFile(String aFileName, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc { + filename= aFileName; + try { + parseInputStream(new FileInputStream(aFileName), aRootHandler); + } + catch (Throwable t) { + throw new XMLReaderFailure(t); + } + } + + public void parseInputStream(InputStream anInputStream, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc { try { SAXParserFactory parserFactory = SAXParserFactory.newInstance(); - parserFactory.setNamespaceAware(false); + parserFactory.setNamespaceAware(namespaceAware); parserFactory.setValidating(true); - XMLReaderHandler handler = new XMLReaderHandler(parserFactory, aRootHandler, aUsedFiles); + XMLReaderHandler handler = new XMLReaderHandler(parserFactory, aRootHandler); - handler.includeFile(aFileName); + handler.processInputStream(anInputStream); } catch (Throwable e) { - Throwable t = getRootCause(e); + Throwable t = ExceptionFunctions.traceCauseException(e); if (t instanceof XMLReaderExc) { - ((XMLReaderExc) t).setLocation(filename, locator.getLineNumber(), locator.getColumnNumber()); + if (locator!=null && filename!=null) + ((XMLReaderExc) t).setLocation(filename, locator.getLineNumber(), locator.getColumnNumber()); throw (XMLReaderExc) t; } @@ -85,88 +109,35 @@ public class XMLReader { } } - private Throwable getRootCause(Throwable t) { - if (t instanceof SAXParseException && ((SAXParseException) t).getException()!=null) { - return getRootCause(((SAXParseException) t).getException()); - } - else if (t instanceof Failure && ((Failure) t).getCause()!=null) { - return getRootCause(((Failure) t).getCause()); - } - else return t; - } - private class XMLReaderHandler extends DefaultHandler { - private Stack includeFileStack; private SAXParserFactory parserFactory; private SectionsManager manager; - private List usedFiles; private InputSource inputSource; - public XMLReaderHandler(SAXParserFactory aParserFactory, SectionHandler aRootHandler, List aUsedFiles) { + public XMLReaderHandler(SAXParserFactory aParserFactory, SectionHandler aRootHandler) { super(); - includeFileStack=new Stack(); parserFactory=aParserFactory; - includeFileStack = new Stack(); manager = new SectionsManager(); - usedFiles = aUsedFiles; manager.pushHandler(aRootHandler); } - public String getLocatorDescription(Locator aLocator) { - return aLocator.getPublicId()+" ("+aLocator.getLineNumber()+")"; - } - public void setDocumentLocator(Locator aLocator) { locator=aLocator; } - private void includeFile(String aFileName) throws XMLReaderExc, XMLReaderFailure, SAXParseException, SAXException { - File file; - SAXParser parser; - + private void processInputStream(InputStream anInputStream) throws XMLReaderExc, XMLReaderFailure { try { - if (!includeFileStack.empty()) - file = new File(new File((String) includeFileStack.peek()).getParent(), aFileName); - else - file = new File(aFileName); - - if (includeFileStack.contains(file.getCanonicalPath())) { - throw new XMLReaderExc("recursive inclusion of file "+file.getCanonicalPath()); - } - - usedFiles.add(file); + SAXParser parser=parserFactory.newSAXParser(); - parser=parserFactory.newSAXParser(); - - inputSource = new InputSource(new FileInputStream(file)); - inputSource.setPublicId(file.getCanonicalPath()); - - includeFileStack.push(file.getCanonicalPath()); - filename = file.getCanonicalPath(); - try { - parser.parse(inputSource, this); - } - finally { - includeFileStack.pop(); - } - if (!includeFileStack.empty()) - filename = (String) includeFileStack.peek(); + inputSource = new InputSource(anInputStream); + parser.parse(inputSource, this); } catch (ParserConfigurationException e) { - throw new XMLReaderExc("Internal exception while including \""+aFileName+"\": "+e.getMessage()); + throw new XMLReaderExc("Internal exception: "+e.getMessage()); } - catch (SAXParseException e) { - throw e; - } - catch (XMLReaderFailure e) { - throw e; - } - catch (FileNotFoundException e) { - throw new XMLReaderExc("Include file \""+aFileName+"\" not found: "+e.getMessage()); - } - catch (IOException e) { - throw new XMLReaderExc("unable to open include file \""+aFileName+"\": "+e.getMessage()); + catch (Throwable e) { + throw new XMLReaderFailure(e); } } @@ -175,24 +146,13 @@ public class XMLReader { int i; try { - if (aQualifiedName.equals("include")) { - String fileName=anAttributes.getValue("file"); - - if (fileName==null) { - throw new XMLReaderExc("include has no file attribute"); - } - - includeFile(fileName); - } - else { - attributesMap = new HashMap(); - for (i=0; i + * Example:
+ * getNameSpaceFromQualifiedName("dc:creator");
+ * will return "dc" + * + * @param aQualifiedName + * @return + */ + + public static String getNameSpaceFromQualifiedName(String aQualifiedName) { + List parts = StringRoutines.splitString(aQualifiedName, ":"); + + if (parts.size()<=1) + return null; + else + return (String) parts.get(0); + } + + /** + * Returns the localname part of a qualified XML Tag name
+ * Example:
+ * getLocalNameFromQualifiedName("dc:creator");
+ * will return "creator" + * + * @param aQualifiedName + * @return + */ + + public static String getLocalNameFromQualifiedName(String aQualifiedName) { + List parts = StringRoutines.splitString(aQualifiedName, ":"); + + if (parts.size()<1) + return null; + if (parts.size()==1) + return (String) parts.get(0); + else + return (String) parts.get(1); + } + } diff --git a/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java b/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java index ad0be4cb..423fe65e 100755 --- a/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java @@ -105,6 +105,7 @@ public class MirBasicProducerLocalizer implements MirProducerLocalizer { } catch (Throwable t) { logger.error("MirBasicProducerLocalizer.factories(): Unable to setup factories: "+t.getMessage()); + t.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); } }