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

josias at wyona.com josias at wyona.com
Thu Mar 15 15:56:30 CET 2007


Author: josias
Date: 2007-03-15 15:56:28 +0100 (Thu, 15 Mar 2007)
New Revision: 23277

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:
applied/merged patch for bug 5231 (hide form fields which already have a default value). thanks to jonathan

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-15 13:19:38 UTC (rev 23276)
+++ public/yanel/trunk/src/resources/add-realm/src/java/org/wyona/yanel/impl/resources/AddRealmResource.java	2007-03-15 14:56:28 UTC (rev 23277)
@@ -59,7 +59,6 @@
  */
 public class AddRealmResource extends Resource implements ViewableV2 {
 
-    private static final String CRAWLER_JAR = "yanel-crawler.jar";
     private static Category log = Category.getInstance(AddRealmResource.class);
     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";
@@ -73,10 +72,6 @@
     private String parameterErrorName = null;
     private String parameterError = null;
     
-    private File CrawlerJarLocation;
-    private File tmpResultDir;
-    private String errorMessage;
-    
     private HashMap parameters = new HashMap();
 
     /**
@@ -100,22 +95,6 @@
         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");
@@ -157,13 +136,11 @@
             	boolean propertyExists = getConfiguration().containsKey(parameterNames[i]);
             	
             	if (propertyExists == true) {
-            		if (property == null || ("").equals(property)) {
-            			parameters.put(parameterNames[i], "default");
-            		} else {
-            			parameters.put(parameterNames[i], property);
-            		}
+            		parameters.put(parameterNames[i], property);
+            		transformer.setParameter(parameterNames[i] + "-prop-exists", "true");
             	} else {
             		parameters.put(parameterNames[i], "");
+            		transformer.setParameter(parameterNames[i] + "-prop-exists", "false");
         		}
             }
             
@@ -178,7 +155,7 @@
                     parameterName = (String) keysIterator.next();
                     parameter = HttpServletRequestHelper.getParameter(request, parameterName);
                     
-                    if (("fslocation").equals(parameterName)) {
+                    if (parameterName == "fslocation" || ("fslocation").equals(parameterName)) {
                     	parameters.put(parameterName, parameter);
                         transformer.setParameter(parameterName, parameters.get(parameterName).toString());
                     } else if (parameter == null || ("").equals(parameter)) {
@@ -192,11 +169,11 @@
                 }
                 
                 if (parameterError == null || ("").equals(parameterError)) {
+                	// Explicitly check whether fslocation is null and set to null (rather than the empty string).
+                	// File() (and copyRealm()) needs null to be passed.
                 	File fslocationValue = null;
                 	if (parameters.get("fslocation").toString() == null || ("").equals(parameters.get("fslocation").toString())) {
                 		fslocationValue = null;
-                	} else if (parameters.get("fslocation").toString().equals("default")) {
-                		fslocationValue = null;
                 	} else {
                 		fslocationValue = new File(parameters.get("fslocation").toString());
                 	}
@@ -228,17 +205,17 @@
                 }
                 
                 transformer.transform(new javax.xml.transform.stream.StreamSource(statusXMLFile), new StreamResult(byteArrayOutputStream));
-                
+            
             } else if (session.getAttribute(SESSION_ATTR_EVENT_LOG) != null) {
+            	
                 // the crawler is running
-                
-                if (stop) {
-                    DumpingCrawler crawler = (DumpingCrawler)session.getAttribute(SESSION_ATTR_CRAWLER);
-                    if (crawler != null) {
-                        crawler.stop();
+            	if (stop) {
+            	    DumpingCrawler crawler = (DumpingCrawler)session.getAttribute(SESSION_ATTR_CRAWLER);
+            	    if (crawler != null) {
+            	        crawler.stop();
                     }
                 }
-                
+
                 // show progress
                 EventLog eventLog = (EventLog)session.getAttribute(SESSION_ATTR_EVENT_LOG);
                 if (eventLog != null) {
@@ -247,11 +224,11 @@
                     transformer.setParameter("nofdownloads", String.valueOf(eventLog.getNofDownloads()));
                     transformer.setParameter("submitted", "true");
                     transformer.setParameter("isdone", String.valueOf(eventLog.isDone()));
-
+                    
                     transformer.setParameter("yanel.back2context", PathUtil.backToContext(realm, getPath()));
                     transformer.setParameter("realmid", session.getAttribute(SESSION_ATTR_REALM_ID));
                     transformer.setParameter("realmname", session.getAttribute(SESSION_ATTR_REALM_NAME));
-
+                    
                     if (eventLog.isDone()) {
                         session.removeAttribute(SESSION_ATTR_EVENT_LOG);
                         session.removeAttribute(SESSION_ATTR_CRAWLER);
@@ -259,7 +236,7 @@
                         session.removeAttribute(SESSION_ATTR_REALM_NAME);
                     }
                 }
-                transformer.transform(new javax.xml.transform.stream.StreamSource(statusXMLFile), new StreamResult(byteArrayOutputStream));
+                transformer.transform(new javax.xml.transform.stream.StreamSource(statusXMLFile), new StreamResult(byteArrayOutputStream));              
                 
             } else {
             	
@@ -309,9 +286,9 @@
         EventLog eventLog = new EventLog();
         crawler.addLinkListener(eventLog);
         crawler.addCrawlListener(eventLog);
-       
-        Realm realm = getYanel().getRealmConfiguration().getRealm(realmID);
         
+        Realm realm = getYanel().getRealmConfiguration().getRealm(realmID);
+       
         HttpSession session = getRequest().getSession(true); 
         session.setAttribute(SESSION_ATTR_EVENT_LOG, eventLog);
         session.setAttribute(SESSION_ATTR_CRAWLER, crawler);
@@ -322,7 +299,8 @@
         ImportSiteThread thread = new ImportSiteThread(crawler, realm, dumpDir, crawlStartURL);
         thread.start();
     }
-        
+    
+   
     /**
      * 
      */

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-15 13:19:38 UTC (rev 23276)
+++ public/yanel/trunk/src/resources/add-realm/xslt/add-realm.xsl	2007-03-15 14:56:28 UTC (rev 23277)
@@ -17,6 +17,14 @@
   <xsl:param name="fslocation" select="''" />
   <xsl:param name="crawldepth" select="''" />
   <xsl:param name="crawlmaxpages" select="''" />
+
+  <xsl:param name="realmid-prop-exists" select="''" />
+  <xsl:param name="realmname-prop-exists" select="''" />
+  <xsl:param name="url-prop-exists" select="''" />
+  <xsl:param name="fslocation-prop-exists" select="''" />
+  <xsl:param name="crawldepth-prop-exists" select="''" />
+  <xsl:param name="crawlmaxpages-prop-exists" select="''" />
+  
   <xsl:param name="downloadevents" select="''" />
   <xsl:param name="errorevents" select="''" />
   <xsl:param name="nofdownloads" select="''" />
@@ -24,6 +32,7 @@
 
   <xsl:param name="submitted" select="'false'" />
 
+
   <xsl:template match="/">
     <html xmlns="http://www.w3.org/1999/xhtml">
       <head>
@@ -62,7 +71,6 @@
                   </form>
                 </xsl:otherwise>
               </xsl:choose>
-              
               <p>[<xsl:value-of select="$nofdownloads"/>] pages have been imported.</p>
               <p>Downloaded Pages:</p>
               <p style="font-size: small"><pre><xsl:value-of select="$downloadevents"/></pre></p>
@@ -74,8 +82,31 @@
               <form method="post">
                   <table cellpadding="0" cellspacing="0" border="0">
                     <xsl:for-each select="form/inputfields/input">
+                      <div>
+                        <xsl:choose>
+                          <xsl:when test="position()='1' and $realmid-prop-exists = 'true'">
+                            <xsl:call-template name="style-display-none"/>
+                          </xsl:when>
+                          <xsl:when test="position()='2' and $realmname-prop-exists = 'true'">
+                            <xsl:call-template name="style-display-none"/>
+                          </xsl:when>
+                          <xsl:when test="position()='3' and $url-prop-exists = 'true'">
+                            <xsl:call-template name="style-display-none"/>
+                          </xsl:when>
+                          <xsl:when test="position()='4' and $fslocation-prop-exists = 'true'">
+                            <xsl:call-template name="style-display-none"/>
+                          </xsl:when>
+                          <xsl:when test="position()='5' and $crawldepth-prop-exists = 'true'">
+                            <xsl:call-template name="style-display-none"/>
+                          </xsl:when>
+                          <xsl:when test="position()='6' and $crawlmaxpages-prop-exists = 'true'">
+                            <xsl:call-template name="style-display-none"/>
+                          </xsl:when>
+                          <xsl:otherwise/>
+                        </xsl:choose>
+                        
                       <tr>
-                        <td align="right" valign="top" class="contentfield" width="150">
+                        <td align="left" valign="top" class="contentfield" width="120">
                           <i18n:message key="{.}"/>:&#0160;
                         </td>
                         <td>
@@ -109,32 +140,75 @@
                               </xsl:choose>
                               </input>
                             </xsl:when>
+                            <!-- Show the input fields if there are no default values set, and hide them otherwise -->
                             <xsl:otherwise>
-                              <input type="text" name="{.}" class="box" size="30">
+                              <input name="{.}" class="box" size="30">
                               <xsl:choose>
                                 <xsl:when test="position()='1'">
                                   <xsl:attribute name="value"><xsl:value-of select="$realmid" /></xsl:attribute>
-                                  <xsl:if test="$realmid != ''"><xsl:attribute name="readonly">readonly</xsl:attribute></xsl:if>
+                                  <xsl:choose>
+                                    <xsl:when test="$realmid-prop-exists != 'false'">
+                                      <xsl:attribute name="type">hidden</xsl:attribute>
+                                    </xsl:when>
+                                    <xsl:otherwise>
+                                      <xsl:attribute name="type">text</xsl:attribute>
+                                    </xsl:otherwise>
+                                  </xsl:choose>
                                 </xsl:when>
                                 <xsl:when test="position()='2'">
                                   <xsl:attribute name="value"><xsl:value-of select="$realmname" /></xsl:attribute>
-                                  <xsl:if test="$realmname != ''"><xsl:attribute name="readonly">readonly</xsl:attribute></xsl:if>
+                                  <xsl:choose>
+                                    <xsl:when test="$realmname-prop-exists != 'false'">
+                                      <xsl:attribute name="type">hidden</xsl:attribute>
+                                    </xsl:when>
+                                    <xsl:otherwise>
+                                      <xsl:attribute name="type">text</xsl:attribute>
+                                    </xsl:otherwise>
+                                  </xsl:choose>
                                 </xsl:when>
                                 <xsl:when test="position()='3'">
                                   <xsl:attribute name="value"><xsl:value-of select="$url" /></xsl:attribute>
-                                  <xsl:if test="$url != ''"><xsl:attribute name="readonly">readonly</xsl:attribute></xsl:if>
+                                  <xsl:choose>
+                                    <xsl:when test="$url-prop-exists != 'false'">
+                                      <xsl:attribute name="type">hidden</xsl:attribute>
+                                    </xsl:when>
+                                    <xsl:otherwise>
+                                      <xsl:attribute name="type">text</xsl:attribute>
+                                    </xsl:otherwise>
+                                  </xsl:choose>
                                 </xsl:when>
                                 <xsl:when test="position()='4'">
                                   <xsl:attribute name="value"><xsl:value-of select="$fslocation" /></xsl:attribute>
-                                  <xsl:if test="$fslocation != ''"><xsl:attribute name="readonly">readonly</xsl:attribute></xsl:if>
+                                  <xsl:choose>
+                                    <xsl:when test="$fslocation-prop-exists != 'false'">
+                                      <xsl:attribute name="type">hidden</xsl:attribute>
+                                    </xsl:when>
+                                    <xsl:otherwise>
+                                      <xsl:attribute name="type">text</xsl:attribute>
+                                    </xsl:otherwise>
+                                  </xsl:choose>
                                 </xsl:when>
                                 <xsl:when test="position()='5'">
                                   <xsl:attribute name="value"><xsl:value-of select="$crawldepth" /></xsl:attribute>
-                                  <xsl:if test="$crawldepth != ''"><xsl:attribute name="readonly">readonly</xsl:attribute></xsl:if>
+                                  <xsl:choose>
+                                    <xsl:when test="$crawldepth-prop-exists != 'false'">
+                                      <xsl:attribute name="type">hidden</xsl:attribute>
+                                    </xsl:when>
+                                    <xsl:otherwise>
+                                      <xsl:attribute name="type">text</xsl:attribute>
+                                    </xsl:otherwise>
+                                  </xsl:choose>
                                 </xsl:when>
                                 <xsl:when test="position()='6'">
                                   <xsl:attribute name="value"><xsl:value-of select="$crawlmaxpages" /></xsl:attribute>
-                                  <xsl:if test="$crawlmaxpages != ''"><xsl:attribute name="readonly">readonly</xsl:attribute></xsl:if>
+                                  <xsl:choose>
+                                    <xsl:when test="$crawlmaxpages-prop-exists != 'false'">
+                                      <xsl:attribute name="type">hidden</xsl:attribute>
+                                    </xsl:when>
+                                    <xsl:otherwise>
+                                      <xsl:attribute name="type">text</xsl:attribute>
+                                    </xsl:otherwise>
+                                  </xsl:choose>
                                 </xsl:when>
                                 <xsl:otherwise>
                                   <xsl:attribute name="value"></xsl:attribute>
@@ -231,11 +305,10 @@
                         </td>
                         <td>&#160;</td>
                       </tr>
+                      </div>
                     </xsl:for-each>
                     
                     <tr>
-                      <td>&#160;
-                      </td>
                       <td align="right">
                         <input type="submit" name="submit" value="i18n:attr key=add-realm"/>
                       </td>
@@ -253,5 +326,10 @@
       </body>
     </html>
   </xsl:template>
+  
+  
+  <xsl:template name="style-display-none">
+    <xsl:attribute name="style">display:none;</xsl:attribute>
+  </xsl:template>
     
 </xsl:stylesheet>




More information about the Yanel-commits mailing list