geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r515593 - in /geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey: commands/ exporter/ exporter/filters/
Date Wed, 07 Mar 2007 14:50:53 GMT
Author: jdillon
Date: Wed Mar  7 06:50:52 2007
New Revision: 515593

URL: http://svn.apache.org/viewvc?view=rev&rev=515593
Log:
Refactor filters to use base-class and context
News pages now link correctly back to pages in the same space

Added:
    geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/Filter.groovy  
(with props)
    geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/FilterContext.groovy
  (with props)
    geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/filters/
    geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/filters/RegexSearchReplaceFilter.groovy
  (with props)
Modified:
    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/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=515593&r1=515592&r2=515593
==============================================================================
--- 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:50:52 2007
@@ -26,6 +26,7 @@
 import hokeypokey.util.CliBuilder
 import hokeypokey.exporter.SpaceExporter
 import hokeypokey.exporter.TemplateEngine
+import hokeypokey.exporter.filters.RegexSearchReplaceFilter
 
 /**
  * Do the Hokey Pokey!
@@ -78,28 +79,18 @@
             //
             // 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)
+            exporter.filters << new RegexSearchReplaceFilter(
+                '"' + "/confluence/display/$space/(.*?)" + '"',
+                { matcher, ctx ->
+                    def href = matcher.group(1).replaceAll('\\+','-').toLowerCase() + '.html'
                     
-                    while (m.find()) {
-                        //
-                        // HACK: Just get something working...
-                        //
-                        def href = m.group(1).replaceAll('\\+','-').toLowerCase() + '.html'
-                        m.appendReplacement(buff, "$q$href$q");
+                    // Special handling for news pages, link back to export root 3 deep
+                    if (ctx.page.publishDate) {
+                        href = "../../../$href"
                     }
-                    m.appendTail(buff);
                     
-                    writer.println(buff.toString())
-                }
-            }
+                    return '"' + href + '"'
+                })
             
             exporter.export(space)
         }

Added: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/Filter.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/Filter.groovy?view=auto&rev=515593
==============================================================================
--- geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/Filter.groovy (added)
+++ geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/Filter.groovy Wed
Mar  7 06:50:52 2007
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+//
+// $Id$
+//
+
+package hokeypokey.exporter
+
+/**
+ * Do the Hokey Pokey!
+ */
+abstract class Filter
+{
+    String filter(FilterContext ctx, String input) {
+        def reader = new StringReader(input)
+        def writer = new StringWriter()
+        def out = new PrintWriter(writer)
+        
+        filter(ctx, reader, out)
+        
+        return writer.buffer.toString()
+    }
+    
+    abstract def filter(FilterContext ctx, Reader reader, PrintWriter writer)
+}
+

Propchange: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/Filter.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/Filter.groovy
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/Filter.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/FilterContext.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/FilterContext.groovy?view=auto&rev=515593
==============================================================================
--- geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/FilterContext.groovy
(added)
+++ geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/FilterContext.groovy
Wed Mar  7 06:50:52 2007
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+//
+// $Id$
+//
+
+package hokeypokey.exporter
+
+/**
+ * Do the Hokey Pokey!
+ */
+class FilterContext
+{
+    def client
+    
+    def space
+    
+    def page
+}
+

Propchange: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/FilterContext.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/FilterContext.groovy
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/FilterContext.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=515593&r1=515592&r2=515593
==============================================================================
--- 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:50:52 2007
@@ -142,14 +142,14 @@
             
             // Apply filters (if any)
             if (filters) {
+                def ctx = new FilterContext(
+                    client: client,
+                    space: space,
+                    page: page)
+                
                 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()
+                    assert filter instanceof Filter
+                    buff = filter.filter(ctx, buff)
                 }
             }
             

Added: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/filters/RegexSearchReplaceFilter.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/filters/RegexSearchReplaceFilter.groovy?view=auto&rev=515593
==============================================================================
--- geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/filters/RegexSearchReplaceFilter.groovy
(added)
+++ geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/filters/RegexSearchReplaceFilter.groovy
Wed Mar  7 06:50:52 2007
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+//
+// $Id$
+//
+
+package hokeypokey.exporter.filters
+
+import hokeypokey.exporter.Filter
+import hokeypokey.exporter.FilterContext
+
+import java.util.regex.Pattern
+
+/**
+ * Do the Hokey Pokey!
+ */
+class RegexSearchReplaceFilter
+    extends Filter
+{
+    def from
+    
+    def to
+    
+    def RegexSearchReplaceFilter(from, to) {
+        assert from
+        assert to
+        
+        this.from = from
+        this.to = to
+    }
+    
+    def filter(FilterContext ctx, Reader reader, PrintWriter writer) {
+        assert reader
+        assert writer
+        
+        def p = Pattern.compile(from)
+        
+        StringBuffer buff = new StringBuffer()
+        
+        reader.eachLine { line ->
+            buff.length = 0
+            def m = p.matcher(line)
+            
+            while (m.find()) {
+                def tmp
+                if (to instanceof Closure) {
+                    tmp = to(m, ctx)
+                }
+                else {
+                    tmp = "$to"
+                }
+                
+                m.appendReplacement(buff, tmp)
+            }
+            m.appendTail(buff)
+            
+            writer.println(buff.toString())
+        }
+    }
+}
+

Propchange: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/filters/RegexSearchReplaceFilter.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/filters/RegexSearchReplaceFilter.groovy
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/hokeypokey/trunk/src/main/groovy/hokeypokey/exporter/filters/RegexSearchReplaceFilter.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message