Author: batosai
Date: 2008-08-09 12:08:46 +0000 (Sat, 09 Aug 2008)
New Revision: 21683

Added:
   trunk/apps/WoT/src/plugins/WoT/IdentityParser.java
Modified:
   trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
Log:
First step to parsing Identities' XML files.
Have to create/insert it first.

Added: trunk/apps/WoT/src/plugins/WoT/IdentityParser.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/IdentityParser.java                          
(rev 0)
+++ trunk/apps/WoT/src/plugins/WoT/IdentityParser.java  2008-08-09 12:08:46 UTC 
(rev 21683)
@@ -0,0 +1,65 @@
+/**
+ * This code is part of WoT, a plugin for Freenet. It is distributed 
+ * under the GNU General Public License, version 2 (or at your option
+ * any later version). See http://www.gnu.org/ for details of the GPL.
+ */
+
+package plugins.WoT;
+
+import java.io.InputStream;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import com.db4o.ObjectContainer;
+
+/**
+ * @author Julien Cornuwel (batosai at freenetproject.org)
+ *
+ */
+public class IdentityParser {
+       
+       ObjectContainer db;
+       WoT wot;
+       SAXParser saxParser;
+
+       public IdentityParser(ObjectContainer db, WoT wot) throws 
ParserConfigurationException, SAXException {
+
+               this.db = db;
+               this.wot = wot;
+               SAXParserFactory factory = SAXParserFactory.newInstance();
+               saxParser = factory.newSAXParser();
+       }
+       
+       public void parse (InputStream is) throws Exception {
+               
+               try {
+                       saxParser.parse(is, new IdentityHandler() );
+                       is.close();
+               } catch (Throwable err) {
+                       err.printStackTrace ();
+                       throw new Exception("Could not parse XML: 
"+err.toString());
+               }
+       }
+       
+       public class IdentityHandler extends DefaultHandler {
+               
+               public IdentityHandler() {
+                       
+               }
+               
+               public void startElement(String nameSpaceURI, String localName, 
String rawName, Attributes attrs) throws SAXException {
+                       
+                       String elt_name;
+                       if (rawName == null) elt_name = localName;
+                       else elt_name = rawName;
+                       
+                       // It works. Now, let's try to insert something in 
order to parse it...
+               }
+       }
+}

Modified: trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoTplugin.java       2008-08-09 10:15:10 UTC 
(rev 21682)
+++ trunk/apps/WoT/src/plugins/WoT/WoTplugin.java       2008-08-09 12:08:46 UTC 
(rev 21683)
@@ -6,7 +6,6 @@

 package plugins.WoT;

-import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.util.Date;
@@ -49,8 +48,10 @@
        private PageMaker pm;
        private HighLevelSimpleClient client;
        private FCPServer fcp;
+       
        private ObjectContainer db;
        private WoT wot;
+       private IdentityParser parser;

        public void runPlugin(PluginRespirator pr) {

@@ -60,6 +61,12 @@
                db = Db4o.openFile("WoT.db4o");
                wot = new WoT(db);

+               try {
+                       parser = new IdentityParser(db, wot);
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+               
                Config nc = pr.getNode().config;
                SubConfig fc = nc.get("fproxy");
                String cssName = fc.getString("css");
@@ -319,9 +326,9 @@

                try {
                        InputStream is = result.asBucket().getInputStream();
-                       //TODO Write a TrustListParser class to handle this
+                       parser.parse(is);

-               } catch (IOException e) {
+               } catch (Exception e) {
                        e.printStackTrace();
                }



Reply via email to