svn commit: r1227072 - in /cocoon/cocoon3/trunk/cocoon-optional/src: main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/ test/java/org/apache/cocoon/optional/pipeline/components/sax/directory/ test/resources/org/apache/cocoon/option...

[email protected]
Newsgroups gmane.text.xml.cocoon.cvs
Message-ID <[email protected]>
Author: reinhard
Date: Wed Jan  4 08:22:23 2012
New Revision: 1227072

URL: http://svn.apache.org/viewvc?rev=1227072&view=rev
Log:
correctly deal with the passed source URL: toString() doesn't work correctly with encoded URL characters (like spaces)
provide a test case that verifies that encoded characters are handled correctly

Added:
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/directory/test directory/
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/directory/test directory/test.txt   (with props)
Modified:
    cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGenerator.java
    cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGeneratorTestCase.java

Modified: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGenerator.java?rev=1227072&r1=1227071&r2=1227072&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGenerator.java (original)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGenerator.java Wed Jan  4 08:22:23 2012
@@ -17,6 +17,7 @@
 package org.apache.cocoon.optional.pipeline.components.sax.directory;
 
 import java.io.File;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -144,7 +145,11 @@ public class DirectoryGenerator extends 
     @Override
     public void setConfiguration(final Map<String, ? extends Object> configuration) {
         final URL url = (URL) configuration.get("source");
-        this.setDirectorySource(new File(url.getFile()));
+        try {
+            this.setDirectorySource(new File(url.toURI()));
+        } catch (URISyntaxException e) {
+            throw new SetupException("Can't parse source URL: " + url, e);
+        }
 
         final Parameters parameters = new Parameters(configuration);
         this.depth = parameters.getAsInteger("depth", 1);

Modified: cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGeneratorTestCase.java?rev=1227072&r1=1227071&r2=1227072&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGeneratorTestCase.java (original)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGeneratorTestCase.java Wed Jan  4 08:22:23 2012
@@ -20,6 +20,8 @@ import static org.custommonkey.xmlunit.X
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
@@ -35,32 +37,46 @@ import org.w3c.dom.Node;
 public final class DirectoryGeneratorTestCase {
 
     @Test
-    public void testPipelineWithDirectoryGGenerator() throws Exception {
+    public void testPipelineWithDirectoryGenerator() throws Exception {
+        ByteArrayOutputStream baos = getPipelineResult(this.getClass().getResource("test.txt"));
+        /*
+         * we have 4 files and 1 directory in the test dir and one directory (.svn). Makes a total of 7 nodes (incl.
+         * root)!
+         *
+         * However since we pass the exclude parameter and do no list .svn we should have 6 nodes.
+         */
+        CountingNodeTester countingNodeTester = new CountingNodeTester(6);
+        assertNodeTestPasses(new String(baos.toByteArray()), countingNodeTester, Node.ELEMENT_NODE);
+    }
+
+    @Test
+    public void testDirectoryWithSpaceCharacter() throws Exception {
+        ByteArrayOutputStream baos = getPipelineResult(this.getClass().getResource("test directory/test.txt"));
+        /*
+         * we have 1 file and in the test dir and one directory (.svn). Makes a total of 3 nodes (incl.
+         * root)!
+         *
+         * However since we pass the exclude parameter and do no list .svn we should have 2 nodes.
+         */
+        CountingNodeTester countingNodeTester = new CountingNodeTester(2);
+        assertNodeTestPasses(new String(baos.toByteArray()), countingNodeTester, Node.ELEMENT_NODE);
+    }
+
+    private ByteArrayOutputStream getPipelineResult(URL testResource) throws URISyntaxException, MalformedURLException, Exception {
         Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
-        URL testResource = this.getClass().getResource("test.txt");
+
         File parentFile = (new File(testResource.toURI())).getParentFile();
         DirectoryGenerator generator = new DirectoryGenerator();
         Map<String, Object> parameters = new HashMap<String, Object>();
         parameters.put("exclude", new String("^.svn"));
         parameters.put("source", parentFile.toURI().toURL());
-        generator.setConfiguration(parameters );
+        generator.setConfiguration(parameters);
         pipeline.addComponent(generator);
         pipeline.addComponent(new XMLSerializer());
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         pipeline.setup(baos);
         pipeline.execute();
-
-        /*
-         * we have 4 files in the test dir and one directory (.svn). 
-         * Makes a total of 6 nodes (incl. root)! 
-         * 
-         * However since we pass the exclude parameter and do no
-         * list .svn we should have 5 nodes.
-         */
-        CountingNodeTester countingNodeTester = new CountingNodeTester(5);
-
-        String string = new String(baos.toByteArray());
-        assertNodeTestPasses(string, countingNodeTester, Node.ELEMENT_NODE);
+        return baos;
     }
 }

Added: cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/directory/test directory/test.txt
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/directory/test%20directory/test.txt?rev=1227072&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/directory/test directory/test.txt (added)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/directory/test directory/test.txt Wed Jan  4 08:22:23 2012
@@ -0,0 +1,17 @@
+/*
+ * 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.
+ */
+test
\ No newline at end of file

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/directory/test directory/test.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/directory/test directory/test.txt
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/optional/pipeline/components/sax/directory/test directory/test.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.