« Return to Thread: [gatewiki-commits] SF.net SVN: gatewiki:[1459] trunk/cow

[gatewiki-commits] SF.net SVN: gatewiki:[1459] trunk/cow

by hcunningham-2 :: Rate this Message:

Reply to Author | View in Thread

Revision: 1459
          http://gatewiki.svn.sourceforge.net/gatewiki/?rev=1459&view=rev
Author:   hcunningham
Date:     2009-07-06 15:44:26 +0000 (Mon, 06 Jul 2009)

Log Message:
-----------
added a method to search out navigation files in wiki trees

added a test for it

Modified Paths:
--------------
    trunk/cow/doc/cow-backlog.yam
    trunk/cow/grails-app/conf/Config.groovy
    trunk/cow/grails-app/controllers/PageController.groovy
    trunk/cow/grails-app/utils/gate/util/FileUtils.groovy
    trunk/cow/test/unit/FileUtilsTests.groovy

Added Paths:
-----------
    trunk/cow/test/unit/gate/navigation.html

Modified: trunk/cow/doc/cow-backlog.yam
===================================================================
--- trunk/cow/doc/cow-backlog.yam 2009-07-06 11:52:19 UTC (rev 1458)
+++ trunk/cow/doc/cow-backlog.yam 2009-07-06 15:44:26 UTC (rev 1459)
@@ -22,8 +22,11 @@
     - PC.show, line 90:
       - pageBody = FileUtils.getBody(pageFile)
       - change this to be PageService.getBody(pageFile, wiki)
-      - this then does an FU.getBody on the page itself and adds in FU.getBody
-        called over any available layout info from the wiki
+        - this then does an FU.getBody on the page itself and adds in
+          FU.getBody called over any available layout info from the wiki
+        - for each layout file in conf.navigation.files
+          - find the nearest one to current dir, up the tree to wiki top
+            
   - layouts for whole wiki-areas
     - add a "areaLayoutName" to Wiki, which would reference a layout GSP in
       the site-specific plugin; PageLinkTabLib would then use this for the

Modified: trunk/cow/grails-app/conf/Config.groovy
===================================================================
--- trunk/cow/grails-app/conf/Config.groovy 2009-07-06 11:52:19 UTC (rev 1458)
+++ trunk/cow/grails-app/conf/Config.groovy 2009-07-06 15:44:26 UTC (rev 1459)
@@ -105,6 +105,9 @@
       layout.present    = false // ditto
       controller        = "gate.cow.GuestLayoutController"
     }
+    navigation {
+      files             = [ "cow:nav.html" ]
+    }
     page { // note: this has to be serialisable to support the edit flow
       bibURI            = "http://gate.ac.uk/sale/bib/main.html"
       bibAnchorPrefix   = "X"
@@ -200,24 +203,24 @@
     // cow
     gate {
       cow {
-        DataArea="debug, logfile"
+        DataArea="info, logfile"
         CowUtils="info, logfile"
         CowPermission="info, logfile"
       }
       yam {
         YamFile="info, logfile"
-        YamTest="debug, logfile"
+        YamTest="info, logfile"
         parse.YamParser="info, logfile"
         translate.AbstractTranslator="info, logfile"
         depend.Dependencies="info, logfile"
       }
       util.FileUtils="info, logfile"
-      versioning.svnkit="debug, logfile"
-      versioning="debug, logfile"
+      versioning.svnkit="info, logfile"
+      versioning="info, logfile"
     }
     grails {
       app {
-        controller.WikiController="debug, logfile"
+        controller.WikiController="info, logfile"
         controller.PageController="debug, logfile"
         controller.SvnAuthController="debug, logfile"
         service.PageService="debug, logfile"

Modified: trunk/cow/grails-app/controllers/PageController.groovy
===================================================================
--- trunk/cow/grails-app/controllers/PageController.groovy 2009-07-06 11:52:19 UTC (rev 1458)
+++ trunk/cow/grails-app/controllers/PageController.groovy 2009-07-06 15:44:26 UTC (rev 1459)
@@ -124,6 +124,7 @@
    * params.unzip == 'on' -> try to unzip the file whatever its type
    * params.overwrite == 'on' -> overwrite any existing file
    */
+// TODO use i18n messages
   def upload = {
     log.debug("\n\n=== ${actionName}: ${request.forwardURI} ===")
     Map thisPage = pageService.analyse(params) ?: [ : ]
@@ -296,7 +297,7 @@
     } else {
       flash.message = "Upload failed.<br><br>" + messages;
     }
-  }
+  } // upload (GWT)
 
   /** Edit action. Handles edits on HTML (YAM and non-YAM) and TXT files. */
   def editFlow = {
@@ -632,6 +633,8 @@
     } // normalExit
   } // newpageFlow
 
+// this is the non-gwt version of upload, which was broken because of an
+// interaction between jsec and webflow iirr...
 //  /** Action for uploading new files and directories. */
 //  def uploadFlow = {
 //    /** Validate and triage the request. */
@@ -766,7 +769,6 @@
     // element for home with special anchor text
     pathelems << new PathElement(string:basePath, path:basePath)
     
-    
     if(id.equals("1")) {
       basePath = basePath + "help/"
       pathelems << new PathElement(string: "help", path:basePath)

Modified: trunk/cow/grails-app/utils/gate/util/FileUtils.groovy
===================================================================
--- trunk/cow/grails-app/utils/gate/util/FileUtils.groovy 2009-07-06 11:52:19 UTC (rev 1458)
+++ trunk/cow/grails-app/utils/gate/util/FileUtils.groovy 2009-07-06 15:44:26 UTC (rev 1459)
@@ -24,7 +24,28 @@
  * @author Hamish Cunningham
  */
 class FileUtils {
+  /**
+   * Find the first occurence of a file above a location in a directory tree
+   * up to and including a particular top directory.
+   */
+  static File findFileInTree(String fileName, File topDir, File startDir) {
+    File currentDir = startDir
+      log.debug("\ntopDir: ${topDir}")
+    while(true) {
+      log.debug("currentDir: ${currentDir}")
+      File possibleFile = new File((File) currentDir, (String) fileName)
+      if(possibleFile.exists())
+        return possibleFile
 
+      if(currentDir == null || topDir == null) // should never...
+        return null
+      else if(currentDir.getCanonicalPath() == topDir.getCanonicalPath())
+        return null
+      else
+        currentDir = currentDir.parentFile;
+    }
+  } // findFileInTree
+
   /**
    * Get the body of an HTML file. Tries to use Sitemesh (HTMLPageParser);
    * if that fails uses some imperfect string matching on body tags.
@@ -185,7 +206,6 @@
   static Pattern META_ENCODING_PATTERN =
        ~/(?i)<meta\s+http-equiv="Content-type"[^>]*?charset=(.+?)"/
 
-
   /**
    * Return the String contents of an html file, decoded according to the
    * encodings given in any xml declaration or meta tag. In order to overcome

Modified: trunk/cow/test/unit/FileUtilsTests.groovy
===================================================================
--- trunk/cow/test/unit/FileUtilsTests.groovy 2009-07-06 11:52:19 UTC (rev 1458)
+++ trunk/cow/test/unit/FileUtilsTests.groovy 2009-07-06 15:44:26 UTC (rev 1459)
@@ -22,6 +22,45 @@
     // this.getClass().classLoader.rootLoader.URLs.each{ println it }
   }
 
+  void testFindFileInTree() {
+    log.debug("doing testFileFileInTree")
+
+    // get a couple of directories from the test resource tree
+    String pageFileDirPath =
+      this.getClass().getResource("/gate/yam/resources").getFile()
+    File wikiTopDir =
+      new File(
+        this.getClass().getResource("/gate/yam/resources").getFile()
+      ).parentFile.parentFile
+    File pageFileDir = new File(pageFileDirPath)
+    log.debug("pageFileDir: ${pageFileDir}")
+
+    // find a file two directories up
+    File foundFile =
+      FileUtils.findFileInTree("navigation.html", wikiTopDir, pageFileDir)
+    assertTrue(
+      "wrong name found: ${foundFile.path}",
+      foundFile.path.endsWith("/gate/navigation.html")
+    )
+
+    // non-existant file
+    foundFile =
+      FileUtils.findFileInTree("xxx.html", wikiTopDir, pageFileDir)
+    assertTrue(
+      "name should not be found but was", foundFile == null
+    )
+
+    // file in the starting dir
+    foundFile =
+      FileUtils.findFileInTree("yam-minimal.html", wikiTopDir, pageFileDir)
+    assertTrue(
+      "wrong name found (2): ${foundFile.path}",
+      foundFile.path.endsWith("/gate/yam/resources/yam-minimal.html")
+    )
+
+    log.debug("finished testFileFileInTree test")
+  } // testFindFileInTree()
+
   void testReplaceFileSuffix() {
     log.debug("doing testReplaceFileSuffix")
     

Added: trunk/cow/test/unit/gate/navigation.html
===================================================================
--- trunk/cow/test/unit/gate/navigation.html                        (rev 0)
+++ trunk/cow/test/unit/gate/navigation.html 2009-07-06 15:44:26 UTC (rev 1459)
@@ -0,0 +1,2 @@
+
+<p>dummy file for FileUtilsTests</p>


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
gatewiki-commits mailing list
gatewiki-commits@...
https://lists.sourceforge.net/lists/listinfo/gatewiki-commits

 « Return to Thread: [gatewiki-commits] SF.net SVN: gatewiki:[1459] trunk/cow