fixes to the rss thing
authorzapata <zapata>
Sat, 24 May 2003 15:33:11 +0000 (15:33 +0000)
committerzapata <zapata>
Sat, 24 May 2003 15:33:11 +0000 (15:33 +0000)
source/mir/entity/Entity.java
source/mir/producer/EntityModifyingProducerNode.java
source/mir/rss/RDFResource.java
source/mir/rss/RSSReader.java
source/mir/rss/RSSTest.java
source/mir/storage/Database.java
source/mir/util/DateTimeFunctions.java
source/mir/util/JDBCStringRoutines.java
source/mir/util/ParameterExpander.java

index 14014e1..54317b6 100755 (executable)
@@ -51,7 +51,7 @@ import freemarker.template.TemplateModelRoot;
  * an entity. Entities are used to represent rows of a database table.<p>
  * 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 {
index ecbf595..766565a 100755 (executable)
@@ -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);
     }
index 254f099..dbc3ddd 100755 (executable)
@@ -63,6 +63,6 @@ public class RDFResource {
   }
 
   public String toString() {
-    return rdfClass + " ("+identifier+")";
+    return rdfClass + " ("+identifier+") + ["+properties+"]";
   }
 }
\ No newline at end of file
index 2c54eed..1544c89 100755 (executable)
@@ -394,6 +394,7 @@ public class RSSReader {
     public Object getValue() {
       try {
         String expression = data.toString().trim();
+
         return DateTimeFunctions.parseW3CDTFString(expression);
       }
       catch (Throwable t) {
index f9bbb52..7370900 100755 (executable)
 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());
index 4c4ac94..5a3f445 100755 (executable)
@@ -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)) + "'";
               }
             }
           }
index 4328fa0..e77e227 100755 (executable)
@@ -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);
     }
index fcf2bca..136c94a 100755 (executable)
  * 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
index fa60689..70ac8b4 100755 (executable)
@@ -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;
     }