[freenet-cvs] r20117 - trunk/apps/WoT/src/plugins/WoT

batosai at freenetproject.org batosai at freenetproject.org
Wed May 28 20:18:24 UTC 2008


Author: batosai
Date: 2008-05-28 20:18:24 +0000 (Wed, 28 May 2008)
New Revision: 20117

Modified:
   trunk/apps/WoT/src/plugins/WoT/Identity.java
   trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java
   trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java
   trunk/apps/WoT/src/plugins/WoT/WoT.java
Log:
Handling of own identities (ugly) inserts.

Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Identity.java	2008-05-28 20:09:11 UTC (rev 20116)
+++ trunk/apps/WoT/src/plugins/WoT/Identity.java	2008-05-28 20:18:24 UTC (rev 20117)
@@ -18,6 +18,7 @@
 public class Identity {
 
 	String requestURI;
+	int edition = 0;
 	Date lastChange;
 	boolean publishTrustList;
 

Modified: trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java	2008-05-28 20:09:11 UTC (rev 20116)
+++ trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java	2008-05-28 20:18:24 UTC (rev 20117)
@@ -5,9 +5,12 @@
  */
 package plugins.WoT;
 
+import java.io.File;
+import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 
+import net.pterodactylus.fcp.ClientPutDiskDir;
 import net.pterodactylus.fcp.FcpConnection;
 
 import com.db4o.ObjectContainer;
@@ -41,6 +44,13 @@
 
 		while(Thread.currentThread() == inserter) {
 			
+			try {
+				Thread.sleep(1000);
+			}
+			catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			
 			List<OwnIdentity> identitiesToInsert = db.query(new Predicate<OwnIdentity> () {
 				public boolean match (OwnIdentity identity) {
 					return (identity.needsInsert());
@@ -51,15 +61,11 @@
 			
 			while(it.hasNext()) {
 				OwnIdentity identityToInsert = it.next();
-				identityToInsert.insert(fcp);
+				insert(db, fcp, identityToInsert);
+				identityToInsert.setLastInsert(new Date());
 			}
 			
-			try {
-				Thread.sleep(1000);
-			}
-			catch (InterruptedException e) {
-				e.printStackTrace();
-			}
+
 			
 		}
 	}
@@ -81,4 +87,25 @@
 		inserter = null;
 	}
 
+	public void insert(ObjectContainer db, FcpConnection fcp, OwnIdentity identity) {
+		
+		ClientPutDiskDir clientPut;
+		
+		/* This is ugly ! There is certainly a way to avoid creating a file on disk but
+		 * I can't find it at the moment.  
+		 */
+		File exportFile;
+
+		try {
+			exportFile = identity.exportToXML(db, new File("exportWOT"));
+			clientPut = new ClientPutDiskDir(identity.getFullInsertURI(), "WoTinserter", exportFile.getParent());
+			fcp.sendMessage(clientPut);
+			//TODO Cleanly handle errors. ATM, we don't even listen to them !
+		}
+		catch (Exception e) {
+			System.out.println("Export failed !");
+			e.printStackTrace();
+			return;
+		}		
+	}
 }

Modified: trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java	2008-05-28 20:09:11 UTC (rev 20116)
+++ trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java	2008-05-28 20:18:24 UTC (rev 20117)
@@ -7,9 +7,12 @@
 
 import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
 import java.util.Date;
 
 import javax.xml.parsers.DocumentBuilder;
@@ -23,10 +26,12 @@
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
+import net.pterodactylus.fcp.ClientPut;
 import net.pterodactylus.fcp.FcpAdapter;
 import net.pterodactylus.fcp.FcpConnection;
 import net.pterodactylus.fcp.GenerateSSK;
 import net.pterodactylus.fcp.SSKKeypair;
+import net.pterodactylus.fcp.UploadFrom;
 
 import org.w3c.dom.DOMImplementation;
 import org.w3c.dom.Document;
@@ -104,10 +109,10 @@
 	 * @throws FileNotFoundException
 	 * @throws IOException
 	 */
-	public void exportToXML(ObjectContainer db, File dir ) throws ParserConfigurationException, TransformerConfigurationException, TransformerException, FileNotFoundException, IOException {
+	public File exportToXML(ObjectContainer db, File dir ) throws ParserConfigurationException, TransformerConfigurationException, TransformerException, FileNotFoundException, IOException {
 		
 		// Create the output file
-		File outputFile = new File(dir, "identity.xml");
+		File outputFile = new File(dir, "export.xml");
 		BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(outputFile));
 		StreamResult resultStream = new StreamResult(fos);
 		
@@ -139,12 +144,11 @@
 		serializer.transform(domSource, resultStream);
 		
 		fos.close();
+		
+		return outputFile.getAbsoluteFile();
+		
 	}
 	
-	public void insert(FcpConnection fcp) {
-		//TODO Export and insert the identity
-	}
-	
 	/**
 	 *  
 	 * @return Whether the identity has been updated since the last insert
@@ -161,6 +165,15 @@
 	}
 
 	/**
+	 * Returns the full insert URI (with edition number and path)
+	 */
+	public String getFullInsertURI() {
+		return getInsertURI() + "wot/" + edition + "/identity.xml";
+		//return getInsertURI() + "wot-" + edition + "/identity.xml";
+	}
+	
+	
+	/**
 	 * @param insertURI InsertURI of the Identity
 	 */
 	public void setInsertURI(String insertURI) {

Modified: trunk/apps/WoT/src/plugins/WoT/WoT.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoT.java	2008-05-28 20:09:11 UTC (rev 20116)
+++ trunk/apps/WoT/src/plugins/WoT/WoT.java	2008-05-28 20:18:24 UTC (rev 20117)
@@ -114,13 +114,13 @@
 	/**
 	 * Testing code goes here, nevermind what horrors you see below ;)
 	 */
-	public void testDrive() throws ParserConfigurationException, TransformerException, IOException {
+	public void testDrive() throws ParserConfigurationException, TransformerException, IOException,InterruptedException {
 		
 		//Empty the database
 		ObjectSet<Object> result = db.queryByExample(new Object());
 		while (result.hasNext()) { db.delete(result.next()); }
 		
-		OwnIdentity root = new OwnIdentity("root", "root", new Timestamp(0), new Timestamp(new Date().getTime()), true);
+		OwnIdentity root = new OwnIdentity(fcp);
 		Identity a = new Identity("a", new Date(), true);
 		Identity b = new Identity("b", new Date(), true);
 		
@@ -145,7 +145,7 @@
 			
 			Thread.sleep(5000);
 			
-			wot.close();
+			//wot.close();
 			
 		}
 		catch (Exception e) {




More information about the cvs mailing list