From: zapata Date: Sat, 24 May 2003 15:33:11 +0000 (+0000) Subject: fixes to the rss thing X-Git-Tag: LATEST_MERGED_1_1~395 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=1aa9edcc67faeea38c5e2f2003c84ec1566d4fc5;p=mir.git fixes to the rss thing --- diff --git a/source/mir/entity/Entity.java b/source/mir/entity/Entity.java index 14014e1a..54317b60 100755 --- a/source/mir/entity/Entity.java +++ b/source/mir/entity/Entity.java @@ -51,7 +51,7 @@ import freemarker.template.TemplateModelRoot; * an entity. Entities are used to represent rows of a database table.

* Interfacing TemplateHashModel and TemplateModelRoot to be freemarker compliant * - * @version $Id: Entity.java,v 1.21.2.2 2003/05/22 19:45:06 zapata Exp $ + * @version $Id: Entity.java,v 1.21.2.3 2003/05/24 15:33:11 zapata Exp $ * @author rk * */ @@ -110,26 +110,14 @@ public class Entity implements TemplateHashModel, TemplateModelRoot public void setValues(Map aMap) { if (aMap!=null) { Iterator i = aMap.entrySet().iterator(); - logger.info("aMap = " + aMap.toString()); - synchronized(this) { while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); - logger.info("setting " + entry.getKey()); - setValueForProperty( (String) entry.getKey(), (String) entry.getValue()); } } } -/* - if (theStringValues != null) { - theValuesHash = new HashMap(); - theValuesHash.putAll(theStringValues); - } - else - logger.warn("Entity.setValues called with null Map"); -*/ } /** @@ -145,11 +133,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @param id */ public void setId(String id) { - setValueForProperty(theStorageObject.getIdName(), id); -/* - theValuesHash.put(theStorageObject.getIdName(), id); - */ } /** @@ -161,17 +145,6 @@ public class Entity implements TemplateHashModel, TemplateModelRoot String returnValue = null; if (field != null) { -/* - if (field.equals("webdb_create_formatted")) { - if (hasValueForField("webdb_create")) - returnValue = StringUtil.dateToReadableDate(getValue("webdb_create")); - } - else if (field.equals("webdb_lastchange_formatted")) { - if (hasValueForField("webdb_lastchange")) - returnValue = StringUtil.dateToReadableDate(getValue( - "webdb_lastchange")); - } - else */ returnValue = (String) values.get(field); } return returnValue; @@ -213,7 +186,6 @@ public class Entity implements TemplateHashModel, TemplateModelRoot */ public void setValueForProperty(String theProp, String theValue) throws StorageObjectFailure { try { - logger.info("setting " + theProp + " to (" + theValue + ")"); if (isField(theProp)) values.put(theProp, theValue); else { diff --git a/source/mir/producer/EntityModifyingProducerNode.java b/source/mir/producer/EntityModifyingProducerNode.java index ecbf5954..766565a0 100755 --- a/source/mir/producer/EntityModifyingProducerNode.java +++ b/source/mir/producer/EntityModifyingProducerNode.java @@ -32,13 +32,14 @@ package mir.producer; import java.util.HashMap; import java.util.Iterator; -import java.util.Map; +import java.util.*; import mir.entity.Entity; import mir.entity.adapter.EntityAdapter; import mir.entity.adapter.EntityAdapterModel; import mir.log.LoggerWrapper; import mir.util.ParameterExpander; +import mir.util.*; public class EntityModifyingProducerNode implements ProducerNode { @@ -83,20 +84,32 @@ public class EntityModifyingProducerNode implements ProducerNode { Object value = ParameterExpander.evaluateExpression(aValueMap, valueExpression); + aLogger.debug(" setting " + entityField + " to " + valueExpression+ " ("+ value + ")"); + +// if (value==null) +// entity.setValueForProperty(entityField, ""); if (value instanceof String) entity.setValueForProperty(entityField, (String) value); else if (value instanceof EntityAdapter) entity.setValueForProperty(entityField, ((EntityAdapter) value).getEntity().getId()); + else if (value instanceof Date) { + entity.setValueForProperty(entityField, JDBCStringRoutines.formatDate((Date) value)); + } else - aLogger.warn("Can't set value " + value.toString() + " for field " + entityField); + aLogger.warn("Can't set value " + value + " for field " + entityField); } - entity.update(); + + if (create) + entity.insert(); + else + entity.update(); } else throw new ProducerExc( entityExpression + " does not evaluate to an entity"); } catch (Throwable t) { aLogger.error("Error while performing entity modification operation: " + t.getMessage()); + t.printStackTrace(aLogger.asPrintWriter(aLogger.DEBUG_MESSAGE)); throw new ProducerFailure(t.getMessage(), t); } diff --git a/source/mir/rss/RDFResource.java b/source/mir/rss/RDFResource.java index 254f099e..dbc3ddd8 100755 --- a/source/mir/rss/RDFResource.java +++ b/source/mir/rss/RDFResource.java @@ -63,6 +63,6 @@ public class RDFResource { } public String toString() { - return rdfClass + " ("+identifier+")"; + return rdfClass + " ("+identifier+") + ["+properties+"]"; } } \ No newline at end of file diff --git a/source/mir/rss/RSSReader.java b/source/mir/rss/RSSReader.java index 2c54eed9..1544c89c 100755 --- a/source/mir/rss/RSSReader.java +++ b/source/mir/rss/RSSReader.java @@ -394,6 +394,7 @@ public class RSSReader { public Object getValue() { try { String expression = data.toString().trim(); + return DateTimeFunctions.parseW3CDTFString(expression); } catch (Throwable t) { diff --git a/source/mir/rss/RSSTest.java b/source/mir/rss/RSSTest.java index f9bbb526..73709000 100755 --- a/source/mir/rss/RSSTest.java +++ b/source/mir/rss/RSSTest.java @@ -31,26 +31,26 @@ package mir.rss; import java.util.*; +import mir.util.*; public class RSSTest { public static void main(String[] args) { 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"); + RSSData wvl = reader.parseUrl("http://euskalherria.indymedia.org/g8.1-0.rdf"); +// RSSData be = reader.parseUrl("http://belgium.indymedia.org/features.rdf"); - RSSAggregator agg = new RSSAggregator(10, "dc:date", true, null, null); +// 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(); +// agg.appendItems(wvl.getResourcesForRdfClass("rss:item")); +// agg.appendItems(be.getResourcesForRdfClass("rss:item")); + Iterator i = wvl.getResourcesForRdfClass("rss:item").iterator(); while (i.hasNext()) - System.out.println(i.next().toString()); + System.out.println(ParameterExpander.evaluateExpression((RDFResource) i.next(), "['dc:date']")); - System.out.println(agg.getItems()); +// System.out.println(agg.getItems()); } catch (Throwable t) { System.out.println("Exception: " + t.toString()); diff --git a/source/mir/storage/Database.java b/source/mir/storage/Database.java index 4c4ac94d..5a3f445b 100755 --- a/source/mir/storage/Database.java +++ b/source/mir/storage/Database.java @@ -76,7 +76,7 @@ import mir.util.JDBCStringRoutines; * Treiber, Host, User und Passwort, ueber den der Zugriff auf die * Datenbank erfolgt. * - * @version $Id: Database.java,v 1.44.2.1 2003/05/22 19:45:06 zapata Exp $ + * @version $Id: Database.java,v 1.44.2.2 2003/05/24 15:33:12 zapata Exp $ * @author rk * */ @@ -792,19 +792,20 @@ public class Database implements StorageObject { aValue = null; // exceptions - if (aField.equals("webdb_create") || - aField.equals("webdb_lastchange")) { + if (!theEntity.hasValueForField(aField) && ( + aField.equals("webdb_create") || + aField.equals("webdb_lastchange"))) { aValue = "NOW()"; } else { if ((streamedInput != null) && streamedInput.contains(aField)) { aValue = "?"; - } else { + } + else { if (theEntity.hasValueForField(aField)) { aValue = "'" + - JDBCStringRoutines.escapeStringLiteral((String) theEntity.getValue( - aField)) + "'"; + JDBCStringRoutines.escapeStringLiteral((String) theEntity.getValue(aField)) + "'"; } } } diff --git a/source/mir/util/DateTimeFunctions.java b/source/mir/util/DateTimeFunctions.java index 4328fa0c..e77e2278 100755 --- a/source/mir/util/DateTimeFunctions.java +++ b/source/mir/util/DateTimeFunctions.java @@ -36,10 +36,15 @@ import java.util.GregorianCalendar; import java.util.SimpleTimeZone; import java.util.TimeZone; +import mir.log.*; + public class DateTimeFunctions { /** * private parameter-less constructor to prevent construction */ + private static LoggerWrapper logger = new LoggerWrapper("Utility.DatTimeFunctions"); + + private DateTimeFunctions() { } @@ -136,15 +141,13 @@ public class DateTimeFunctions { SimpleTimeZone pdt = new SimpleTimeZone((houroffset * 60 + minuteoffset) * 60 * 1000, timeZoneID); Calendar calendar = new GregorianCalendar(pdt); - calendar.set(year, month, day, hour, minute, second); + calendar.set(year, month-1, day, hour, minute, second); calendar.set(Calendar.MILLISECOND, millisecond); - System.out.println(aString + " -> " + new SimpleDateFormat("yyyy-dd-MM HH:mm Z").format(calendar.getTime())); - return calendar.getTime(); } catch (Throwable t) { - System.out.println(aString + " -> " + t.toString()); + logger.error("DateTimeFunctions.parseW3CDTFString: error parsing " + aString + ": " + t.toString()); throw new UtilFailure(t); } diff --git a/source/mir/util/JDBCStringRoutines.java b/source/mir/util/JDBCStringRoutines.java index fcf2bcab..136c94ac 100755 --- a/source/mir/util/JDBCStringRoutines.java +++ b/source/mir/util/JDBCStringRoutines.java @@ -18,13 +18,13 @@ * 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. + * 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.util; @@ -38,6 +38,9 @@ package mir.util; * @version 1.0 */ +import java.util.*; +import java.text.*; + public class JDBCStringRoutines { private JDBCStringRoutines() { } @@ -49,4 +52,7 @@ public class JDBCStringRoutines { return StringRoutines.replaceStringCharacters(aText, CHARACTERS_TO_ESCAPE, ESCAPE_CODES); } + public static String formatDate(Date aDate) { + return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(aDate); + } } \ No newline at end of file diff --git a/source/mir/util/ParameterExpander.java b/source/mir/util/ParameterExpander.java index fa60689e..70ac8b4c 100755 --- a/source/mir/util/ParameterExpander.java +++ b/source/mir/util/ParameterExpander.java @@ -193,8 +193,8 @@ public class ParameterExpander { return parser.parseInteger(); } - public static Object evaluateExpression(Map aMap, String anExpression) throws Exception { - Parser parser = new Parser(anExpression, aMap); + public static Object evaluateExpression(Object aRoot, String anExpression) throws Exception { + Parser parser = new Parser(anExpression, aRoot); return parser.parseWhole(); } @@ -490,9 +490,9 @@ public class ParameterExpander { private static class Parser { private Scanner scanner; - private Map valueMap; + private Object valueMap; - public Parser(String anExpression, Map aValueMap) { + public Parser(String anExpression, Object aValueMap) { scanner = new Scanner(new Reader(anExpression)); valueMap = aValueMap; }