geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r515572 - in /geronimo/sandbox/hokeypokey/trunk: pom.xml src/main/groovy/hokeypokey/commands/exportspace.groovy src/main/groovy/hokeypokey/exporter/SpaceExporter.groovy
Date Wed, 07 Mar 2007 14:01:32 GMT
Author: jdillon
Date: Wed Mar  7 06:01:31 2007
New Revision: 515572

URL: http://svn.apache.org/viewvc?view=rev&rev=515572
Log:
Hook up uber-primative filtering, pages now have links that work for the same space... cept
for news

Modified:
    geronimo/sandbox/hokeypokey/trunk/pom.xml
    geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/commands/exportspace.groovy
    geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/SpaceExporter.groovy

Modified: geronimo/sandbox/hokeypokey/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/hokeypokey/trunk/pom.xml?view=diff&rev=515572&r1=515571&r2=515572
==============================================================================
--- geronimo/sandbox/hokeypokey/trunk/pom.xml (original)
+++ geronimo/sandbox/hokeypokey/trunk/pom.xml Wed Mar  7 06:01:31 2007
@@ -59,12 +59,6 @@
             <artifactId>commons-lang</artifactId>
             <version>2.3</version>
         </dependency>
-        
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <version>1.3.1</version>
-        </dependency>
     </dependencies>
     
     <build>

Modified: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/commands/exportspace.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/commands/exportspace.groovy?view=diff&rev=515572&r1=515571&r2=515572
==============================================================================
--- geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/commands/exportspace.groovy
(original)
+++ geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/commands/exportspace.groovy
Wed Mar  7 06:01:31 2007
@@ -75,6 +75,32 @@
             
             def exporter = new SpaceExporter(client, engine)
             
+            //
+            // HACK: Hook up a filter to translate links for this space
+            //
+            exporter.filters << { reader, writer ->
+                def q = '"'
+                def baseURI = "/confluence/display/$space/"
+                def pattern = ~/$q$baseURI(.*?)$q/
+                StringBuffer buff = new StringBuffer();
+                
+                reader.eachLine { line ->
+                    buff.length = 0
+                    def m = pattern.matcher(line)
+                    
+                    while (m.find()) {
+                        //
+                        // HACK: Just get something working...
+                        //
+                        def href = m.group(1).replaceAll('\\+','-').toLowerCase() + '.html'
+                        m.appendReplacement(buff, "$q$href$q");
+                    }
+                    m.appendTail(buff);
+                    
+                    writer.println(buff.toString())
+                }
+            }
+            
             exporter.export(space)
         }
         finally {

Modified: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/SpaceExporter.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/SpaceExporter.groovy?view=diff&rev=515572&r1=515571&r2=515572
==============================================================================
--- geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/SpaceExporter.groovy
(original)
+++ geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/SpaceExporter.groovy
Wed Mar  7 06:01:31 2007
@@ -25,7 +25,7 @@
 
 import hokeypokey.Client
 
-import org.apache.commons.io.IOUtils
+import org.apache.commons.lang.time.StopWatch
 
 /**
  * Do the Hokey Pokey!
@@ -38,6 +38,8 @@
     
     File outputDirectory = new File('output')
     
+    List filters = []
+    
     def SpaceExporter(Client client, TemplateEngine engine) {
         assert client
         assert engine
@@ -49,6 +51,9 @@
     def export(String spaceKey) {
         assert spaceKey
         
+        def watch = new StopWatch()
+        watch.start()
+        
         def space = client.getSpace(spaceKey)
         
         println "Exporting space: ${space.name} (${space.key})"
@@ -84,7 +89,15 @@
                 // This is deprecated, but screw it
                 def date = new Date(page.publishDate)
                 
-                baseName = "${date.year + 1900}/${date.month}/${date.date}/${page.title}"
+                def y = date.year + 1900
+                
+                def m = date.month + 1
+                if (m < 10) { m = "0$m" }
+                
+                def d = date.date
+                if (d < 10) { d = "0$d" }
+                
+                baseName = "$y/$m/$d/${page.title}"
             }
             else {
                 baseName = page.title
@@ -97,76 +110,94 @@
             return baseName.toLowerCase().replace(' ', '-')
         }
         
-        def pageHref = { page ->
-            return pageBaseName(page) + '.html'
-        }
-        
-        def pageAttachDir = { page ->
-            return pageBaseName(page) + '.attach'
+        def renderTemplate = {
+            def writer = new StringWriter()
+            try {
+                template.render(writer)
+            }
+            finally {
+                writer.close()
+            }
+            return writer.buffer.toString()
         }
         
         def exportPage = { page ->
             def baseName = pageBaseName(page)
             println "    ${baseName}"
             
+            // Get the content of the page as an html snippet
             def body = renderPage(page)
             
+            // Details about the page
             template.params.body = body
             template.params.space = space
             template.params.page = page
             
+            // Helpers to render
             template.params.findPage = findPage
             template.params.renderPage = renderPage
             
-            def writer = new StringWriter()
-            template.render(writer)
-            writer.close()
+            // Render the page with the space template
+            def buff = renderTemplate()
             
-            //
-            // TODO: Hook up massaging filters...
-            //
+            // Apply filters (if any)
+            if (filters) {
+                filters.each { filter ->
+                    // Each filter is a closure, which takes a reader,writer
+                    def reader = new StringReader(buff)
+                    def writer = new StringWriter()
+                    
+                    filter(reader, new PrintWriter(writer))
+                    
+                    buff = writer.buffer.toString()
+                }
+            }
             
+            // Save the rendered content
             def file = new File(outputDirectory, "${baseName}.html")
             file.parentFile.mkdirs()
+            file.write(buff)
             
-            file.write(writer.buffer.toString())
-            
+            // If there are attachments, then export each attachement (latest version only)
             def attachments = client.getAttachments(page.id)
             if (attachments) {
-                def dir = new File("${baseName}.attach")
+                def dir = new File(outputDirectory, "${baseName}.attach")
                 dir.mkdirs()
                 
-                attachments.each { attachment ->
-                    print "        ${attachment.fileName}"
-                    
-                    def url = new URL(attachment.url)
-                    def input = url.openConnection().inputStream
-                    def _file = new File(dir, attachment.fileName)
-                    def output = _file.newOutputStream()
-                    
+                def download = { url, targetFile ->
+                    def output = targetFile.newOutputStream()
                     try {
-                        IOUtils.copy(input, output)
+                        output << new URL(url).openStream()
                     }
                     finally {
-                        IOUtils.closeQuietly(output)
-                        IOUtils.closeQuietly(input)
+                        output.close()
                     }
                     
-                    println " (${_file.length()} bytes)"
+                    return targetFile.length()
+                }
+                
+                attachments.each { attachment ->
+                    print "        ${attachment.fileName}"
+                    def size = download(attachment.url, new File(dir, attachment.fileName))
+                    println " ($size bytes)"
                 }
             }
         }
         
+        // Export each page
         pages.each { page ->
             exportPage(page)
         }
         
+        // If there is news, then export each news page
         def newsPages = client.getBlogEntries(space.key)
         if (newsPages) {
             newsPages.each { page ->
                 exportPage(page)
             }
         }
+        
+        println "Finished ($watch)"
     }
 }
 



Mime
View raw message