--- /dev/null
+/*
+ * 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 mir.producer;
+
+import java.util.*;
+
+import mir.log.LoggerWrapper;
+import mir.rss.RSSData;
+import mir.rss.*;
+import mir.util.ExceptionFunctions;
+import mir.util.ParameterExpander;
+
+public class RDFAggregatorProducerNode implements ProducerNode {
+ private String key;
+ private String source;
+ private String order;
+ private String filter;
+
+ public RDFAggregatorProducerNode(String aKey, String aSource, String anOrder, String aFilter) {
+ key = aKey;
+ source=aSource;
+ order=anOrder;
+ filter=aFilter;
+ }
+
+ public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure {
+ try {
+ aLogger.debug(source);
+ String evaluatedKey = ParameterExpander.expandExpression( aValueMap, key );
+ String evaluatedOrder = ParameterExpander.expandExpression( aValueMap, order );
+ Object evaluatedSource = ParameterExpander.evaluateExpression( aValueMap, source );
+
+ Object aggregator = aValueMap.get(evaluatedKey);
+
+ if (aggregator == null) {
+ aLogger.debug("creating");
+ aggregator = new RSSAggregator(100, "dc:date", true, null, null);
+ aValueMap.put(evaluatedKey, aggregator);
+ }
+
+ if (aggregator instanceof RSSAggregator) {
+ RSSAggregator agg = (RSSAggregator) aggregator;
+
+ if (evaluatedSource instanceof List) {
+ aLogger.debug("appending");
+ agg.appendItems( (List) evaluatedSource);
+ aLogger.debug("now: " + agg.getItems().size());
+ }
+ else
+ throw new ProducerExc("List expected, " + evaluatedSource.toString() + " found");
+ }
+ else
+ throw new ProducerExc("RSSAggregator expected, " + aggregator.toString() + " found");
+ }
+ catch (Throwable t) {
+ Throwable s = ExceptionFunctions.traceCauseException(t);
+ aLogger.error("Error while aggregating RDF data: " + s.getClass().getName()+","+ s.getMessage());
+ }
+ };
+}
--- /dev/null
+/*
+ * 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 mir.rss;
+
+import java.util.*;
+
+public class RDFResource {
+ private String identifier;
+ private String rdfClass;
+ private Map properties;
+
+ protected RDFResource(String anRdfClass, String anIdentifier) {
+ rdfClass=anRdfClass;
+ identifier = anIdentifier;
+ properties = new HashMap();
+ }
+
+ protected RDFResource(String anRdfClass) {
+ this(anRdfClass, null);
+ }
+
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ public String getRdfClass() {
+ return rdfClass;
+ }
+
+ public Object get(String aProperty) {
+ return properties.get(aProperty);
+ }
+
+ public void set(String aProperty, Object aValue) {
+ properties.put(aProperty, aValue);
+ }
+
+ public String toString() {
+ return rdfClass + " ("+identifier+")";
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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 RSSAggregator {
+ private String orderBy;
+ private boolean orderReversed;
+ private int capacity;
+ private List items;
+ private String selectionField;
+ private Object selectionValue;
+
+ public RSSAggregator(int aCapacity, String anOrderBy, boolean anOrderReversed, String aSelectionField, Object aSelectionValue) {
+ orderBy = anOrderBy;
+ orderReversed = anOrderReversed;
+ capacity = aCapacity;
+ items = new Vector();
+ selectionValue = aSelectionValue;
+ selectionField = aSelectionField;
+ }
+
+ public void appendItems(List anItems) {
+ Iterator i = anItems.iterator();
+
+ while (i.hasNext()) {
+ Object item = i.next();
+
+ if (item instanceof RDFResource)
+ appendItem((RDFResource) item);
+ }
+ }
+
+ public int compareItems(RDFResource anItem1, RDFResource anItem2) {
+ int result = 0;
+
+ Object value1 = anItem1.get(orderBy);
+ Object value2 = anItem2.get(orderBy);
+
+ if (value1 instanceof Comparable && value2 instanceof Comparable) {
+ result = ((Comparable) value1).compareTo(value2);
+
+ if (orderReversed)
+ result = -result;
+ }
+
+ return result;
+ }
+
+ public void appendItem(RDFResource anItem) {
+ if (selectionField!=null && selectionValue!=null) {
+ if (!selectionValue.equals(anItem.get(selectionField)))
+ return;
+ }
+
+ int i = items.size();
+
+ if (orderBy!=null) {
+ if (anItem.get(orderBy) == null)
+ return;
+
+ while (i > 0 && compareItems(anItem, (RDFResource) items.get(i-1)) < 0) {
+ i--;
+ }
+ }
+
+ items.add(i, anItem);
+ while (items.size()>0 && items.size()>capacity)
+ items.remove(items.size()-1);
+ }
+
+ public List getItems() {
+ return items;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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 mir.rss;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+public class RSSBasicModule implements RSSModule {
+ private Map properties;
+ private String namespaceURI;
+ private String name;
+
+ public RSSBasicModule(String aNamespaceURI, String aName) {
+ properties = new HashMap();
+ namespaceURI = aNamespaceURI;
+ name = aName;
+ }
+
+ public String getNamespaceURI() {
+ return namespaceURI;
+ }
+
+ public RSSModuleProperty getPropertyForName(String aName) {
+ return (RSSModuleProperty) properties.get(aName);
+ }
+
+ public List getAllProperties() {
+ return new Vector(properties.values());
+ }
+
+ public void addProperty(String aName, int aType) {
+ properties.put(aName, new RSSBasicModuleProperty(aName, aType));
+ }
+
+ private class RSSBasicModuleProperty implements RSSModuleProperty {
+ private String name;
+ private int type;
+
+ public RSSBasicModuleProperty(String aName, int aType) {
+ name = aName;
+ type = aType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getType() {
+ return type;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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 mir.rss;
+
+import java.util.List;
+
+public interface RSSModule {
+ public static final int PCDATA_PROPERTY_TYPE = 0;
+ public static final int W3CDTF_PROPERTY_TYPE = 1;
+ public static final int RDFCOLLECTION_PROPERTY_TYPE = 2;
+
+ public interface RSSModuleProperty {
+ String getName();
+ int getType();
+ }
+
+ public String getNamespaceURI();
+
+ public RSSModuleProperty getPropertyForName(String aName);
+
+ public List getAllProperties();
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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 RSSTest {
+
+ public static void main(String[] args) {
+ System.out.println("Testing...");
+
+ RSSReader reader = new RSSReader();
+ try {
+ RSSData wvl = reader.parseUrl("http://wvl.indymedia.org/features.rdf");
+ RSSData be = reader.parseUrl("http://belgium.indymedia.org/features.rdf");
+
+ RSSAggregator agg = new RSSAggregator(10, "dc:date", true, null, null);
+
+ agg.appendItems(wvl.getResourcesForRdfClass("rss:item"));
+ agg.appendItems(be.getResourcesForRdfClass("rss:item"));
+
+ Iterator i = agg.getItems().iterator();
+
+ while (i.hasNext())
+ System.out.println(i.next().toString());
+
+ System.out.println(agg.getItems());
+ }
+ catch (Throwable t) {
+ System.out.println("Exception: " + t.toString());
+ t.printStackTrace(System.out);
+ }
+ }
+}