[Yanel-commits] rev 23217 - in public/yanel/trunk/src/resources/add-realm: src/java/org/wyona/yanel/impl/resources xslt

josias at wyona.com josias at wyona.com
Sat Mar 10 00:21:06 CET 2007


Author: josias
Date: 2007-03-10 00:21:05 +0100 (Sat, 10 Mar 2007)
New Revision: 23217

Added:
   public/yanel/trunk/src/resources/add-realm/src/java/org/wyona/yanel/impl/resources/EventLog.java
Modified:
   public/yanel/trunk/src/resources/add-realm/src/java/org/wyona/yanel/impl/resources/AddRealmResource.java
   public/yanel/trunk/src/resources/add-realm/xslt/add-realm.xsl
Log:
show number of downloaded pages, urls of downloaded pages, and errors after the import

Modified: public/yanel/trunk/src/resources/add-realm/src/java/org/wyona/yanel/impl/resources/AddRealmResource.java
===================================================================
--- public/yanel/trunk/src/resources/add-realm/src/java/org/wyona/yanel/impl/resources/AddRealmResource.java	2007-03-09 20:11:01 UTC (rev 23216)
+++ public/yanel/trunk/src/resources/add-realm/src/java/org/wyona/yanel/impl/resources/AddRealmResource.java	2007-03-09 23:21:05 UTC (rev 23217)
@@ -23,8 +23,6 @@
 import org.apache.lenya.search.crawler.DumpingCrawler;
 import org.apache.log4j.Category;
 
-import websphinx.EventLog;
-
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -44,6 +42,7 @@
 import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.transform.Transformer;
@@ -64,6 +63,8 @@
     private static Category log = Category.getInstance(AddRealmResource.class);
     private final static int INSIDE_TAG = 0;
     private final static int OUTSIDE_TAG = 1;
+    private final static String SESSION_ATTR_EVENT_LOG = "org.wyona.yanel.addrealm.eventlog";
+    private final static String SESSION_ATTR_CRAWLER = "org.wyona.yanel.addrealm.crawler";
     
     private String defaultLanguage = "en";
     private String language = null;
@@ -210,6 +211,15 @@
                         String realmID = parameters.get("realmid").toString();
                         
                         importSite(crawlStartURL, maxPages, maxDepth, realmID);
+                        
+                        HttpSession session = getRequest().getSession(true); 
+                        EventLog eventLog = (EventLog)session.getAttribute(SESSION_ATTR_EVENT_LOG);
+                        if (eventLog != null) {
+                            transformer.setParameter("downloadevents", eventLog.getDownloadEvents());
+                            transformer.setParameter("errorevents", eventLog.getErrorEvents());
+                            transformer.setParameter("nofdownloads", String.valueOf(eventLog.getNofDownloads()));
+                        }
+
                     }
                 }
                 
@@ -260,10 +270,13 @@
         crawler.setMaxPages(maxPages);
         crawler.setMaxDepth(maxDepth);
         
-        EventLog eventLog = new EventLog(System.out);
-        crawler.addCrawlListener(eventLog);
+        EventLog eventLog = new EventLog();
         crawler.addLinkListener(eventLog);
        
+        HttpSession session = getRequest().getSession(true); 
+        session.setAttribute(SESSION_ATTR_EVENT_LOG, eventLog);
+        //session.setAttribute(SESSION_ATTR_CRAWLER, crawler);
+        
         // create dump:
         // TODO: start crawler in thread and show progress
         crawler.run();

Added: public/yanel/trunk/src/resources/add-realm/src/java/org/wyona/yanel/impl/resources/EventLog.java
===================================================================
--- public/yanel/trunk/src/resources/add-realm/src/java/org/wyona/yanel/impl/resources/EventLog.java	2007-03-09 20:11:01 UTC (rev 23216)
+++ public/yanel/trunk/src/resources/add-realm/src/java/org/wyona/yanel/impl/resources/EventLog.java	2007-03-09 23:21:05 UTC (rev 23217)
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2006 Wyona
+ */
+
+package org.wyona.yanel.impl.resources;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+import websphinx.LinkEvent;
+import websphinx.LinkListener;
+
+/**
+ * 
+ */
+public class EventLog implements LinkListener, Serializable {
+
+    ArrayList downloadEvents;
+    ArrayList errorEvents;
+    
+    public EventLog() {
+        this.downloadEvents = new ArrayList();
+        this.errorEvents = new ArrayList();
+    }
+    
+    /**
+     * Notify that a link event occured.
+     */
+    public void crawled (LinkEvent event) {
+        if (event.getID() == LinkEvent.DOWNLOADED) {
+            this.downloadEvents.add(event);
+        } else if (event.getID() == LinkEvent.ERROR) {
+            this.errorEvents.add(event);
+        }
+    }
+    
+    /**
+     * Returns all download events.
+     * @return
+     */
+    public String getDownloadEvents() {
+        StringBuffer buf = new StringBuffer();
+        for (int i=0; i<this.downloadEvents.size(); i++) {
+            buf.append(this.downloadEvents.get(i) + "\n");
+        }
+        return buf.toString();
+    }
+    
+    /**
+     * Returns all error events.
+     * @return
+     */
+    public String getErrorEvents() {
+        StringBuffer buf = new StringBuffer();
+        for (int i=0; i<this.errorEvents.size(); i++) {
+            buf.append(this.errorEvents.get(i) + "\n");
+        }
+        return buf.toString();
+    }
+    
+    /**
+     * Returns the number of downloaded pages.
+     * @return
+     */
+    public int getNofDownloads() {
+        return this.downloadEvents.size();
+    }
+}


Property changes on: public/yanel/trunk/src/resources/add-realm/src/java/org/wyona/yanel/impl/resources/EventLog.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: public/yanel/trunk/src/resources/add-realm/xslt/add-realm.xsl
===================================================================
--- public/yanel/trunk/src/resources/add-realm/xslt/add-realm.xsl	2007-03-09 20:11:01 UTC (rev 23216)
+++ public/yanel/trunk/src/resources/add-realm/xslt/add-realm.xsl	2007-03-09 23:21:05 UTC (rev 23217)
@@ -17,6 +17,9 @@
   <xsl:param name="fslocation" select="''" />
   <xsl:param name="crawldepth" select="''" />
   <xsl:param name="crawlmaxpages" select="''" />
+  <xsl:param name="downloadevents" select="''" />
+  <xsl:param name="errorevents" select="''" />
+  <xsl:param name="nofdownloads" select="''" />
 
   <xsl:param name="submitted" select="'false'" />
 
@@ -37,8 +40,12 @@
         <div id="contentBody">
           <xsl:choose>
             <xsl:when test="$submitted != 'false'">
-              <p>[X] pages have been imported.</p>
+              <p>[<xsl:value-of select="$nofdownloads"/>] pages have been imported.</p>
               <p>[X]% complete.</p>
+              <p>Downloaded Pages:</p>
+              <p style="font-size: small"><pre><xsl:value-of select="$downloadevents"/></pre></p>
+              <p>Errors:</p>
+              <p style="font-size: small"><pre><xsl:value-of select="$errorevents"/></pre></p>
               <p>
                 <a>
                   <xsl:attribute name="href">




More information about the Yanel-commits mailing list