[Yanel-commits] rev 22688 - in public/yanel/trunk/src/resources/importsite: config resources src/java/org/wyona/yanel/impl/resources xml xslt

josias at wyona.com josias at wyona.com
Thu Feb 15 20:06:08 CET 2007


Author: josias
Date: 2007-02-15 20:06:06 +0100 (Thu, 15 Feb 2007)
New Revision: 22688

Removed:
   public/yanel/trunk/src/resources/importsite/resources/realms/
Modified:
   public/yanel/trunk/src/resources/importsite/config/importsite_de.properties
   public/yanel/trunk/src/resources/importsite/config/importsite_en.properties
   public/yanel/trunk/src/resources/importsite/src/java/org/wyona/yanel/impl/resources/ImportSiteResource.java
   public/yanel/trunk/src/resources/importsite/xml/input-screen.xml
   public/yanel/trunk/src/resources/importsite/xml/status-screen.xml
   public/yanel/trunk/src/resources/importsite/xslt/importsite.xsl
Log:
improved importsite resource (create new realm and improved parameter handling). see bug #4991, thanks to Jonathan

Modified: public/yanel/trunk/src/resources/importsite/config/importsite_de.properties
===================================================================
--- public/yanel/trunk/src/resources/importsite/config/importsite_de.properties	2007-02-15 18:56:53 UTC (rev 22687)
+++ public/yanel/trunk/src/resources/importsite/config/importsite_de.properties	2007-02-15 19:06:06 UTC (rev 22688)
@@ -4,7 +4,7 @@
 url = URL
 fs-location = Filesystem Pfad
 crawldepth = Crawl Tiefe
-maxpages = Max # der Seiten to Crawl
+crawlmaxpages = Max # der Seiten to Crawl
 message = Message
 thankYou = Vielen Dank!
 requiredFields = Felder markiert mit (*) sind zwingend

Modified: public/yanel/trunk/src/resources/importsite/config/importsite_en.properties
===================================================================
--- public/yanel/trunk/src/resources/importsite/config/importsite_en.properties	2007-02-15 18:56:53 UTC (rev 22687)
+++ public/yanel/trunk/src/resources/importsite/config/importsite_en.properties	2007-02-15 19:06:06 UTC (rev 22688)
@@ -4,7 +4,7 @@
 url = URL
 fs-location = Filesystem Path where Realm will be located
 crawldepth = Crawl Depth
-maxpages = Max # of Pages to Crawl
+crawlmaxpages = Max # of Pages to Crawl
 message = Message
 thankYou = Thank you!
 requiredFields = fields marked with (*) are required

Modified: public/yanel/trunk/src/resources/importsite/src/java/org/wyona/yanel/impl/resources/ImportSiteResource.java
===================================================================
--- public/yanel/trunk/src/resources/importsite/src/java/org/wyona/yanel/impl/resources/ImportSiteResource.java	2007-02-15 18:56:53 UTC (rev 22687)
+++ public/yanel/trunk/src/resources/importsite/src/java/org/wyona/yanel/impl/resources/ImportSiteResource.java	2007-02-15 19:06:06 UTC (rev 22688)
@@ -19,7 +19,11 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
 import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.xml.parsers.SAXParser;
@@ -38,9 +42,20 @@
  */
 public class ImportSiteResource extends Resource implements ViewableV2 {
 
+    private static final String CRAWLER_JAR = "yanel-crawler.jar";
     private static Category log = Category.getInstance(ImportSiteResource.class);
     private String defaultLanguage = "en";
     private String language = null;
+    private String parameterName = null;
+    private String parameter = null;
+    private String parameterErrorName = null;
+    private String parameterError = null;
+    
+    private File CrawlerJarLocation;
+    private File tmpResultDir;
+    private String errorMessage;
+    
+    private HashMap parameters = new HashMap();
 
     /**
      *
@@ -63,6 +78,22 @@
         String path = getPath();
         HttpServletRequest request = getRequest();
         
+        // the crawler jar
+        String WEBINFPath = request.getSession().getServletContext().getRealPath("WEB-INF");
+        CrawlerJarLocation = new File(WEBINFPath + File.separator + "lib" + File.separator
+                + CRAWLER_JAR);
+        
+        if (!CrawlerJarLocation.exists()) {
+            errorMessage = errorMessage + "\n Crawler not found.";
+        }
+        
+        // create tmp status file
+        if (!new File(request.getSession().getServletContext().getRealPath("tmp")).exists()) {
+            if (!new File(request.getSession().getServletContext().getRealPath("tmp")).mkdir()) {
+                errorMessage = errorMessage + "\n Creation of tmp directory faild.";
+            }
+        }
+        
         // Get language
         try {
             language = request.getParameter("yanel.meta.language");
@@ -74,13 +105,6 @@
             log.debug("language param is empty or null : " + language);
             language = defaultLanguage;
         }
-        
-        /* create tmp status file
-        if (!new File(request.getSession().getServletContext().getRealPath("tmp")).exists()) {
-            if (!new File(request.getSession().getServletContext().getRealPath("tmp")).mkdir()) {
-                errorMessage = errorMessage + "\n Creation of tmp directory faild.";
-            }
-        }*/
 
         Transformer transformer = null;
         I18nTransformer i18nTransformer = new I18nTransformer("importsite", language);
@@ -101,24 +125,35 @@
                 File statusXMLFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile().getParentFile().getAbsolutePath(), "xml" + File.separator + "status-screen.xml");
                 transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(statusXSLTFile));
                 
-                String parameterName = "";
-                String parameter = "";
-                String parameterErrorName = "";
-                String parameterError = "";
-                String[] parameters = { "realmid", "realmname", "url", "fs-location", "crawldepth", "maxpages" };
-                for (int i=0; i<parameters.length; i++){
-                    parameterName = parameters[i];
+                //Add HashMap keys with dummy values for form fields
+                parameters.put("realmid", null);
+                parameters.put("realmname", null);
+                parameters.put("url", null);
+                parameters.put("fs-location", null);
+                parameters.put("crawldepth", null);
+                parameters.put("crawlmaxpages", null);
+                
+                Set keys = parameters.keySet();
+                Iterator keysIterator = keys.iterator();
+                while (keysIterator.hasNext()) {
+                    parameterName = (String) keysIterator.next();
                     parameter = HttpServletRequestHelper.getParameter(request, parameterName);
-                    transformer.setParameter(parameterName, parameter);
                     
                     if (parameter == null || ("").equals(parameter)) {
                         parameterErrorName = "error-" + parameterName;
                         parameterError = "Please enter correct value for '" + parameterName + "'";
-                        transformer.setParameter(parameterErrorName, parameterError);
+                        transformer.setParameter(parameterName, "ERROR:" + parameterError);
+                    } else {
+                        parameters.put(parameterName, parameter);
+                        transformer.setParameter(parameterName, parameters.get(parameterName).toString());
                     }
                 }
                 
                 if (parameterError == null || ("").equals(parameterError)) {
+                    getYanel().getRealmConfiguration().copyRealm("from-scratch-realm-template", 
+                            parameters.get("realmid").toString(), 
+                            parameters.get("realmname").toString(),
+                            "/" + parameters.get("realmid").toString() + "/");
                     transformer.setParameter("submitted", "true");
                 }
                 
@@ -142,16 +177,39 @@
         defaultView.setMimeType("application/xhtml+xml");
         defaultView.setInputStream(i18nTransformer.getInputStream());
         return defaultView;
-   }
+    }
+    
+    /* TODO: add showProgress
+    private View showProgress(Path path, View defaultView) throws Exception {
+        
+        //get tmpResultDir from session
+        tmpResultDir = (File) request.getSession().getAttribute("tmpResultDir");
+        
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+        Transformer transformer = null;
+        transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(inputXSLTFile));
+        // TODO: Is this the best way to generate an InputStream from an
+        // OutputStream?
+        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
+        transformer.transform(new StreamSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())),
+                new StreamResult(baos));
+        defaultView.setMimeType("application/xhtml+xml");
+        defaultView.setInputStream(new java.io.ByteArrayInputStream(baos.toByteArray()));
+        return defaultView;
+    }*/
    
-   public boolean exists() throws Exception {
+    /**
+     * 
+     */
+    public boolean exists() throws Exception {
        log.warn("Not implemented yet!");
        return true; 
-   }
+    }
 
-   /**
-    * 
-    */
+    /**
+     * 
+     */
     public long getSize() throws Exception {
         return getRealm().getRepository().getSize(new Path(getPath()));
     }

Modified: public/yanel/trunk/src/resources/importsite/xml/input-screen.xml
===================================================================
--- public/yanel/trunk/src/resources/importsite/xml/input-screen.xml	2007-02-15 18:56:53 UTC (rev 22687)
+++ public/yanel/trunk/src/resources/importsite/xml/input-screen.xml	2007-02-15 19:06:06 UTC (rev 22688)
@@ -6,6 +6,6 @@
     <input required="true" samplevalue="http://www.foo.bar">url</input>
     <input required="true" samplevalue="D:/realms">fs-location</input>
     <input required="true" samplevalue="3">crawldepth</input>
-    <input required="true" samplevalue="100">maxpages</input>
+    <input required="true" samplevalue="100">crawlmaxpages</input>
   </inputfields>
 </form>

Modified: public/yanel/trunk/src/resources/importsite/xml/status-screen.xml
===================================================================
--- public/yanel/trunk/src/resources/importsite/xml/status-screen.xml	2007-02-15 18:56:53 UTC (rev 22687)
+++ public/yanel/trunk/src/resources/importsite/xml/status-screen.xml	2007-02-15 19:06:06 UTC (rev 22688)
@@ -6,6 +6,6 @@
     <input required="true" samplevalue="http://www.foo.bar">url</input>
     <input required="true" samplevalue="D:/realms">fs-location</input>
     <input required="true" samplevalue="3">crawldepth</input>
-    <input required="true" samplevalue="100">maxpages</input>
+    <input required="true" samplevalue="100">crawlmaxpages</input>
   </inputfields>
 </form>

Modified: public/yanel/trunk/src/resources/importsite/xslt/importsite.xsl
===================================================================
--- public/yanel/trunk/src/resources/importsite/xslt/importsite.xsl	2007-02-15 18:56:53 UTC (rev 22687)
+++ public/yanel/trunk/src/resources/importsite/xslt/importsite.xsl	2007-02-15 19:06:06 UTC (rev 22688)
@@ -14,14 +14,7 @@
   <xsl:param name="url" select="''" />
   <xsl:param name="fs-location" select="''" />
   <xsl:param name="crawldepth" select="''" />
-  <xsl:param name="maxpages" select="''" />
-  
-  <xsl:param name="error-realmid" select="''" />
-  <xsl:param name="error-realmname" select="''" />
-  <xsl:param name="error-url" select="''" />
-  <xsl:param name="error-fs-location" select="''" />
-  <xsl:param name="error-crawldepth" select="''" />
-  <xsl:param name="error-maxpages" select="''" />
+  <xsl:param name="crawlmaxpages" select="''" />
 
   <xsl:param name="submitted" select="'false'" />
 
@@ -56,29 +49,31 @@
                         </td>
                         <td>
                           <xsl:choose>
-                            <xsl:when test="$error-realmid != '' or $error-realmname != '' 
-                                            or $error-url != '' or $error-fs-location != ''
-                                            or $error-crawldepth != '' or $error-maxpages != ''">
+                            <xsl:when test="contains($realmid, 'ERROR:') or contains($realmname, 'ERROR:') 
+                                            or contains($url, 'ERROR:') or contains($fs-location, 'ERROR:')
+                                            or contains($crawldepth, 'ERROR:') or contains($crawlmaxpages, 'ERROR:')">
                               <xsl:choose>
-                                <xsl:when test="position()='1'">
+                                <xsl:when test="position()='1' and not(contains($realmid, 'ERROR:'))">
                                   <input type="text" name="{.}" class="box" size="30" value="{$realmid}" />
                                 </xsl:when>
-                                <xsl:when test="position()='2'">
+                                <xsl:when test="position()='2' and not(contains($realmname, 'ERROR:'))">
                                   <input type="text" name="{.}" class="box" size="30" value="{$realmname}" />
                                 </xsl:when>
-                                <xsl:when test="position()='3'">
+                                <xsl:when test="position()='3' and not(contains($url, 'ERROR:'))">
                                   <input type="text" name="{.}" class="box" size="30" value="{$url}" />
                                 </xsl:when>
-                                <xsl:when test="position()='4'">
+                                <xsl:when test="position()='4' and not(contains($fs-location, 'ERROR:'))">
                                   <input type="text" name="{.}" class="box" size="30" value="{$fs-location}" />
                                 </xsl:when>
-                                <xsl:when test="position()='5'">
+                                <xsl:when test="position()='5' and not(contains($crawldepth, 'ERROR:'))">
                                   <input type="text" name="{.}" class="box" size="30" value="{$crawldepth}" />
                                 </xsl:when>
-                                <xsl:when test="position()='6'">
-                                  <input type="text" name="{.}" class="box" size="30" value="{$maxpages}" />
+                                <xsl:when test="position()='6' and not(contains($crawlmaxpages, 'ERROR:'))">
+                                  <input type="text" name="{.}" class="box" size="30" value="{$crawlmaxpages}" />
                                 </xsl:when>
-                                <xsl:otherwise/>
+                                <xsl:otherwise>
+                                  <input type="text" name="{.}" class="box" size="30" value="" />
+                                </xsl:otherwise>
                               </xsl:choose>
                             </xsl:when>
                             <xsl:otherwise>
@@ -88,34 +83,70 @@
                         </td>
                         <td><xsl:if test="@required = 'true'">*</xsl:if></td>
                         <xsl:choose>
-                          <xsl:when test="position()='1' and $error-realmid != ''">
+                          <xsl:when test="position()='1' and contains($realmid, 'ERROR:')">
                             <td>
-                              &#160;<font color="red"><i18n:message key="{$error-realmid}"/></font>
+                              &#160;<font color="red">
+                                <i18n:message>
+                                  <xsl:attribute name="key">
+                                    <xsl:value-of select="substring-after($realmid, 'ERROR:')"/>
+                                  </xsl:attribute>
+                                </i18n:message>
+                              </font>
                             </td>
                           </xsl:when>
-                          <xsl:when test="position()='2' and $error-realmname != ''">
+                          <xsl:when test="position()='2' and contains($realmname, 'ERROR:')">
                             <td>
-                              &#160;<font color="red"><i18n:message key="{$error-realmname}"/></font>
+                              &#160;<font color="red">
+                                <i18n:message>
+                                  <xsl:attribute name="key">
+                                    <xsl:value-of select="substring-after($realmname, 'ERROR:')"/>
+                                  </xsl:attribute>
+                                </i18n:message>
+                              </font>
                             </td>
                           </xsl:when>
-                          <xsl:when test="position()='3' and $error-url != ''">
+                          <xsl:when test="position()='3' and contains($url, 'ERROR:')">
                             <td>
-                              &#160;<font color="red"><i18n:message key="{$error-url}"/></font>
+                              &#160;<font color="red">
+                                <i18n:message>
+                                  <xsl:attribute name="key">
+                                    <xsl:value-of select="substring-after($url, 'ERROR:')"/>
+                                  </xsl:attribute>
+                                </i18n:message>
+                              </font>
                             </td>
                           </xsl:when>
-                          <xsl:when test="position()='4' and $error-fs-location != ''">
+                          <xsl:when test="position()='4' and contains($fs-location, 'ERROR:')">
                             <td>
-                              &#160;<font color="red"><i18n:message key="{$error-fs-location}"/></font>
+                              &#160;<font color="red">
+                                <i18n:message>
+                                  <xsl:attribute name="key">
+                                    <xsl:value-of select="substring-after($fs-location, 'ERROR:')"/>
+                                  </xsl:attribute>
+                                </i18n:message>
+                              </font>
                             </td>
                           </xsl:when>
-                          <xsl:when test="position()='5' and $error-crawldepth != ''">
+                          <xsl:when test="position()='5' and contains($crawldepth, 'ERROR:')">
                             <td>
-                              &#160;<font color="red"><i18n:message key="{$error-crawldepth}"/></font>
+                              &#160;<font color="red">
+                                <i18n:message>
+                                  <xsl:attribute name="key">
+                                    <xsl:value-of select="substring-after($crawldepth, 'ERROR:')"/>
+                                  </xsl:attribute>
+                                </i18n:message>
+                              </font>
                             </td>
                           </xsl:when>
-                          <xsl:when test="position()='6' and $error-maxpages != ''">
+                          <xsl:when test="position()='6' and contains($crawlmaxpages, 'ERROR:')">
                             <td>
-                              &#160;<font color="red"><i18n:message key="{$error-maxpages}"/></font>
+                              &#160;<font color="red">
+                                <i18n:message>
+                                  <xsl:attribute name="key">
+                                    <xsl:value-of select="substring-after($crawlmaxpages, 'ERROR:')"/>
+                                  </xsl:attribute>
+                                </i18n:message>
+                              </font>
                             </td>
                           </xsl:when>
                           <xsl:otherwise>




More information about the Yanel-commits mailing list