* 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
*
*/
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");
-*/
}
/**
* @param id
*/
public void setId(String id) {
-
setValueForProperty(theStorageObject.getIdName(), id);
-/*
- theValuesHash.put(theStorageObject.getIdName(), id);
- */
}
/**
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;
*/
public void setValueForProperty(String theProp, String theValue) throws StorageObjectFailure {
try {
- logger.info("setting " + theProp + " to (" + theValue + ")");
if (isField(theProp))
values.put(theProp, theValue);
else {
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 {
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);
}
}
public String toString() {
- return rdfClass + " ("+identifier+")";
+ return rdfClass + " ("+identifier+") + ["+properties+"]";
}
}
\ No newline at end of file
public Object getValue() {
try {
String expression = data.toString().trim();
+
return DateTimeFunctions.parseW3CDTFString(expression);
}
catch (Throwable t) {
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());
* 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
*
*/
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)) + "'";
}
}
}
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() {
}
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);
}
* 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;
* @version 1.0
*/
+import java.util.*;
+import java.text.*;
+
public class JDBCStringRoutines {
private 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
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();
}
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;
}