geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r515537 - in /geronimo/sandbox/hokeypokey/trunk: pom.xml src/main/groovy/hokeypokey/exporter/SpaceExporter.groovy
Date Wed, 07 Mar 2007 11:33:43 GMT
Author: jdillon
Date: Wed Mar  7 03:33:41 2007
New Revision: 515537

URL: http://svn.apache.org/viewvc?view=rev&rev=515537
Log:
Hook up attachment export

Modified:
    geronimo/sandbox/hokeypokey/trunk/pom.xml
    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=515537&r1=515536&r2=515537
==============================================================================
--- geronimo/sandbox/hokeypokey/trunk/pom.xml (original)
+++ geronimo/sandbox/hokeypokey/trunk/pom.xml Wed Mar  7 03:33:41 2007
@@ -59,6 +59,12 @@
             <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/exporter/SpaceExporter.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/SpaceExporter.groovy?view=diff&rev=515537&r1=515536&r2=515537
==============================================================================
--- 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 03:33:41 2007
@@ -25,6 +25,8 @@
 
 import hokeypokey.Client
 
+import org.apache.commons.io.IOUtils
+
 /**
  * Do the Hokey Pokey!
  */
@@ -69,10 +71,39 @@
                     return page
                 }
             }
+            
+            throw new Exception("No such page for title: $title")
+        }
+        
+        def pageHref = { page ->
+            assert page
+            
+            //
+            // FIXME: This is probably not correct... but kinda close to what AE does.
+            //
+            
+            return page.title.toLowerCase().replace(' ', '-') + '.html'
+        }
+        
+        def pageAttachDir = { page ->
+            assert page
+            
+            //
+            // FIXME: This is probably not correct... but kinda close to what AE does.
+            //
+            
+            return new File(outputDirectory, page.title.toLowerCase().replace(' ', '-') +
'.attach')
         }
         
+        println "Exporting space: ${space.name} (${space.key})"
+        
         pages.each { page ->
-            println page
+            println "    ${page.title}"
+            
+            //
+            // TODO: Generalize this, the same basic thing (except the filename)
+            //       is used for news posts too
+            //
             
             def body = renderPage(page)
             
@@ -83,24 +114,41 @@
             template.params.findPage = findPage
             template.params.renderPage = renderPage
             
-            def fileName = page.title.toLowerCase().replace(' ', '-') + '.html'
-            def file = new File(outputDirectory, fileName)
-            template.render(file)
+            def writer = new StringWriter()
+            template.render(writer)
+            writer.close()
             
             //
-            // TODO: Hookup filters so we can inline content massaging (w/ happy ending)
+            // TODO: Hook up massaging filters...
             //
             
+            def file = new File(outputDirectory, pageHref(page))
+            file.write(writer.buffer.toString())
+            
             // Handle attachements
-            /*
             def attachements = client.getAttachments(page.id)
             if (attachements) {
-                println 'Attachements:'
+                def dir = pageAttachDir(page)
+                dir.mkdirs()
                 attachements.each { attachment ->
-                    println "    ${attachment.title}"
+                    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()
+                    
+                    try {
+                        IOUtils.copy(input, output)
+                    }
+                    finally {
+                        IOUtils.closeQuietly(output)
+                        IOUtils.closeQuietly(input)
+                    }
+                    
+                    println " (${_file.length()} bytes)"
                 }
             }
-            */
         }
         
         /*



Mime
View raw message