Author: batosai
Date: 2008-08-10 14:09:53 +0000 (Sun, 10 Aug 2008)
New Revision: 21711
Modified:
trunk/apps/WoT/src/plugins/WoT/IdentityParser.java
Log:
Get the identity's properties from the XML file.
Modified: trunk/apps/WoT/src/plugins/WoT/IdentityParser.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/IdentityParser.java 2008-08-10 13:51:47 UTC
(rev 21710)
+++ trunk/apps/WoT/src/plugins/WoT/IdentityParser.java 2008-08-10 14:09:53 UTC
(rev 21711)
@@ -7,6 +7,7 @@
package plugins.WoT;
import java.io.InputStream;
+import java.util.Date;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
@@ -17,7 +18,10 @@
import org.xml.sax.helpers.DefaultHandler;
import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+import freenet.keys.FreenetURI;
+
/**
* @author Julien Cornuwel (batosai at freenetproject.org)
*
@@ -27,6 +31,7 @@
ObjectContainer db;
WoT wot;
SAXParser saxParser;
+ Identity identity;
public IdentityParser(ObjectContainer db, WoT wot) throws
ParserConfigurationException, SAXException {
@@ -36,8 +41,23 @@
saxParser = factory.newSAXParser();
}
- public void parse (InputStream is) throws Exception {
+ public void parse (InputStream is, FreenetURI fetchedURI) throws
Exception {
+ // Find the identity we just fetched
+ // This is ugly, I could not find a request able to find the
good identity
+ ObjectSet<Identity> result = db.queryByExample(Identity.class);
+ while (result.hasNext()) {
+ Identity id = result.next();
+
if(id.getRequestURI().getRoutingKey().equals(fetchedURI.getRoutingKey()))
+ identity = id;
+ }
+ if (identity == null) {
+ System.out.println("Error, identity not found");
+ return;
+ }
+
+ identity.setLastChange(new Date());
+
try {
saxParser.parse(is, new IdentityHandler() );
is.close();
@@ -45,6 +65,10 @@
err.printStackTrace ();
throw new Exception("Could not parse XML:
"+err.toString());
}
+
+ db.store(identity);
+ db.commit();
+
}
public class IdentityHandler extends DefaultHandler {
@@ -59,7 +83,9 @@
if (rawName == null) elt_name = localName;
else elt_name = rawName;
- // It works. Now, let's try to insert something in
order to parse it...
+ if (elt_name.equals("prop")) {
+ identity.setProp(attrs.getValue("key"),
attrs.getValue("value"));
+ }
}
}
}