cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r1142139 - in /cocoon/cocoon3/trunk/cocoon-optional/src: main/java/org/apache/cocoon/generation/ main/java/org/apache/cocoon/pipeline/ main/java/org/apache/cocoon/pipeline/components/ main/java/org/apache/cocoon/pipeline/components/paramete...
Date Sat, 02 Jul 2011 01:01:03 GMT
Author: thorsten
Date: Sat Jul  2 01:01:03 2011
New Revision: 1142139

URL: http://svn.apache.org/viewvc?rev=1142139&view=rev
Log:
Migrating the DirectoryGenerator to c3. Includes test case.

Added:
    cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/
    cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/
    cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/
    cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/Parameters.java
  (with props)
    cocoon/cocoon3/trunk/cocoon-optional/src/main/resources/META-INF/cocoon/spring-optional/cocoon-optional-generators.xml
  (with props)
    cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/generation/
    cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/generation/DirectoryGeneratorTestCase.java
  (with props)
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test.txt
  (with props)
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test.xml
  (with props)
    cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test2.txt
  (with props)
Modified:
    cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/generation/DirectoryGenerator.java

Modified: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/generation/DirectoryGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/generation/DirectoryGenerator.java?rev=1142139&r1=1142138&r2=1142139&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/generation/DirectoryGenerator.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/generation/DirectoryGenerator.java
Sat Jul  2 01:01:03 2011
@@ -5,9 +5,9 @@
  * 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
- * 
+ *
+ *     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.
@@ -16,9 +16,19 @@
  */
 package org.apache.cocoon.generation;
 
+import org.apache.cocoon.pipeline.ProcessingException;
+import org.apache.cocoon.pipeline.SetupException;
+import org.apache.cocoon.pipeline.caching.CacheKey;
+import org.apache.cocoon.pipeline.caching.CompoundCacheKey;
+import org.apache.cocoon.pipeline.caching.TimestampCacheKey;
+import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
+import org.apache.cocoon.pipeline.components.parameters.Parameters;
+import org.apache.cocoon.sax.AbstractSAXGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.regexp.RE;
+import org.apache.regexp.RESyntaxException;
 import java.io.File;
-import java.io.IOException;
-import java.io.Serializable;
 import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -28,46 +38,12 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Stack;
-
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceException;
-import org.apache.excalibur.source.SourceValidity;
-import org.apache.regexp.RE;
-import org.apache.regexp.RESyntaxException;
-
-import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.ResourceNotFoundException;
-import org.apache.cocoon.caching.CacheableProcessingComponent;
-import org.apache.cocoon.components.source.util.SourceUtil;
-import org.apache.cocoon.environment.SourceResolver;
-
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
-/**
- * Generates an XML directory listing. A more general approach is implemented by
- * the {@link TraversableGenerator}.
- * 
- * @cocoon.sitemap.component.documentation Generates an XML directory listing. A
- *                                         more general approach is implemented
- *                                         by the {@link TraversableGenerator}.
- * @cocoon.sitemap.component.name directory
- * @cocoon.sitemap.component.label content
- * @cocoon.sitemap.component.documentation.caching Yes. Uses the last
- *                                                 modification date of the
- *                                                 directory and the contained
- *                                                 files.
- * @cocoon.sitemap.component.pooling.max 16
- * 
- * @version $Id: DirectoryGenerator.java 605689 2007-12-19 20:48:43Z vgritsenko
- *          $
- */
-public class DirectoryGenerator extends ServiceableGenerator implements
-        CacheableProcessingComponent {
-
-    /** Constant for the file protocol. */
-    private static final String FILE = "file:";
+public class DirectoryGenerator extends AbstractSAXGenerator implements
+        CachingPipelineComponent {
+    private final Log logger = LogFactory.getLog(this.getClass());
 
     /** The URI of the namespace of this generator. */
     protected static final String URI = "http://apache.org/cocoon/directory/2.0";
@@ -84,35 +60,24 @@ public class DirectoryGenerator extends 
     protected static final String DATE_ATTR_NAME = "date";
     protected static final String SIZE_ATTR_NAME = "size";
 
-    /** The validity that is being built */
-    protected DirValidity validity;
-
     /**
      * Convenience object, so we don't need to create an AttributesImpl for
      * every element.
      */
-    protected AttributesImpl attributes;
-
-    /**
-     * The cache key needs to be generated for the configuration of this
-     * generator, so storing the parameters for generateKey(). Using the member
-     * variables after setup() would not work I guess. I don't know a way from
-     * the regular expressions back to the pattern or at least a useful string.
-     */
-    protected List cacheKeyParList;
+    protected AttributesImpl attributes  = new AttributesImpl();
 
     /**
      * The depth parameter determines how deep the DirectoryGenerator should
      * delve.
      */
-    protected int depth;
+    protected int depth = 1;
 
     /**
      * The dateFormatter determines into which date format the lastModified time
      * should be converted. FIXME: SimpleDateFormat is not supported by all
      * locales!
      */
-    protected SimpleDateFormat dateFormatter;
+    protected SimpleDateFormat dateFormatter = new SimpleDateFormat();;
 
     /** The delay between checks on updates to the filesystem. */
     protected long refreshDelay;
@@ -123,7 +88,7 @@ public class DirectoryGenerator extends 
      * "lastmodified" and "directory", where "directory" is the same as "name",
      * except that directory entries are listed first.
      */
-    protected String sort;
+    protected String sort ="name";
 
     /**
      * The reverse parameter reverses the sort order. <code>false</code> is
@@ -144,114 +109,76 @@ public class DirectoryGenerator extends 
      * This is only set to true for the requested directory specified by the
      * <code>src</code> attribute on the generator's configuration.
      */
-    protected boolean isRequestedDirectory;
+    protected boolean isRequestedDirectory = false;
 
     /** The source object for the directory. */
-    protected Source directorySource;
+    private File directorySource;
 
-    /**
-     * Set the request parameters. Must be called before the generate method.
-     * 
-     * @param resolver
-     *            the SourceResolver object
-     * @param objectModel
-     *            a <code>Map</code> containing model object
-     * @param src
-     *            the directory to be XMLized specified as src attribute on
-     *            &lt;map:generate/>
-     * @param par
-     *            configuration parameters
-     */
-    public void setup(SourceResolver resolver, Map objectModel, String src,
-            Parameters par) throws ProcessingException, SAXException,
-            IOException {
-        if (src == null) {
-            throw new ProcessingException(
-                    "No src attribute pointing to a directory to be XMLized specified.");
-        }
-        super.setup(resolver, objectModel, src, par);
+    private List<File> validity = new ArrayList<File>();
 
-        try {
-            this.directorySource = this.resolver.resolveURI(src);
-        } catch (SourceException se) {
-            throw SourceUtil.handle(se);
-        }
+    public void setDirectorySource(File directorySource) {
+        this.directorySource = directorySource;
+    }
+
+    public DirectoryGenerator() {
+    }
 
-        this.cacheKeyParList = new ArrayList();
-        this.cacheKeyParList.add(this.directorySource.getURI());
+    public DirectoryGenerator(File file) {
+        if (file == null) {
+            throw new SetupException("A file has to be passed.");
+        }
+        this.directorySource = file;
+        
+    }
 
-        this.depth = par.getParameterAsInteger("depth", 1);
-        this.cacheKeyParList.add(String.valueOf(this.depth));
+    @Override
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
+        URL url = (URL) configuration.get("source");
+        this.setDirectorySource(new File(url.getFile()));
+        Parameters parameters = new Parameters(configuration);
+        this.depth = parameters.getAsInteger("depth", 1);
 
-        String dateFormatString = par.getParameter("dateFormat", null);
-        this.cacheKeyParList.add(dateFormatString);
+        String dateFormatString = parameters.get("dateFormat", null);
         if (dateFormatString != null) {
             this.dateFormatter = new SimpleDateFormat(dateFormatString);
-        } else {
-            this.dateFormatter = new SimpleDateFormat();
         }
 
-        this.sort = par.getParameter("sort", "name");
-        this.cacheKeyParList.add(this.sort);
-
-        this.reverse = par.getParameterAsBoolean("reverse", false);
-        this.cacheKeyParList.add(String.valueOf(this.reverse));
+        this.sort = parameters.get("sort", "name");
 
-        this.refreshDelay = par.getParameterAsLong("refreshDelay", 1L) * 1000L;
-        this.cacheKeyParList.add(String.valueOf(this.refreshDelay));
+        this.reverse = parameters.getAsBoolean("reverse", false);
 
-        if (this.getLogger().isDebugEnabled()) {
-            this.getLogger().debug("depth: " + this.depth);
-            this.getLogger().debug(
-                    "dateFormat: " + this.dateFormatter.toPattern());
-            this.getLogger().debug("sort: " + this.sort);
-            this.getLogger().debug("reverse: " + this.reverse);
-            this.getLogger().debug("refreshDelay: " + this.refreshDelay);
+        this.refreshDelay = parameters.getAsLong("refreshDelay", 1L) * 1000L;
+        if (this.logger.isDebugEnabled()) {
+            this.logger.debug("depth: " + this.depth);
+            this.logger.debug("dateFormat: " + this.dateFormatter.toPattern());
+            this.logger.debug("sort: " + this.sort);
+            this.logger.debug("reverse: " + this.reverse);
+            this.logger.debug("refreshDelay: " + this.refreshDelay);
         }
 
         String rePattern = null;
         try {
-            rePattern = par.getParameter("root", null);
-            this.cacheKeyParList.add(rePattern);
+            rePattern = parameters.get("root", null);
             this.rootRE = (rePattern == null) ? null : new RE(rePattern);
-            if (this.getLogger().isDebugEnabled()) {
-                this.getLogger().debug("root pattern: " + rePattern);
+            if (this.logger.isDebugEnabled()) {
+                this.logger.debug("root pattern: " + rePattern);
             }
 
-            rePattern = par.getParameter("include", null);
-            this.cacheKeyParList.add(rePattern);
+            rePattern = parameters.get("include", null);
             this.includeRE = (rePattern == null) ? null : new RE(rePattern);
-            if (this.getLogger().isDebugEnabled()) {
-                this.getLogger().debug("include pattern: " + rePattern);
+            if (this.logger.isDebugEnabled()) {
+                this.logger.debug("include pattern: " + rePattern);
             }
 
-            rePattern = par.getParameter("exclude", null);
-            this.cacheKeyParList.add(rePattern);
+            rePattern = parameters.get("exclude", null);
             this.excludeRE = (rePattern == null) ? null : new RE(rePattern);
-            if (this.getLogger().isDebugEnabled()) {
-                this.getLogger().debug("exclude pattern: " + rePattern);
+            if (this.logger.isDebugEnabled()) {
+                this.logger.debug("exclude pattern: " + rePattern);
             }
         } catch (RESyntaxException rese) {
             throw new ProcessingException("Syntax error in regexp pattern '"
                     + rePattern + "'", rese);
         }
-
-        this.isRequestedDirectory = false;
-        this.attributes = new AttributesImpl();
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.cocoon.caching.CacheableProcessingComponent#getKey()
-     */
-    public Serializable getKey() {
-        StringBuffer buffer = new StringBuffer();
-        int len = this.cacheKeyParList.size();
-        for (int i = 0; i < len; i++) {
-            buffer.append(this.cacheKeyParList.get(i)).append(":");
-        }
-        return buffer.toString();
     }
 
     /**
@@ -261,47 +188,37 @@ public class DirectoryGenerator extends 
      * and filled with each of the files that are traversed.
      * 
      * @see DirectoryGenerator.DirValidity
-     */
-    public SourceValidity getValidity() {
-        if (this.validity == null) {
-            this.validity = new DirValidity(this.refreshDelay);
-        }
-        return this.validity;
-    }
-
-    /**
-     * Generate XML data.
+     * 
+     *      public SourceValidity getValidity() { if (this.validity == null) {
+     *      this.validity = new DirValidity(this.refreshDelay); } return
+     *      this.validity; }/
+     * 
+     *      /** Generate XML data.
      * 
      * @throws SAXException
      *             if an error occurs while outputting the document
      * @throws ProcessingException
      *             if the requsted URI isn't a directory on the local filesystem
      */
-    public void generate() throws SAXException, ProcessingException {
+    public void execute() throws ProcessingException {
         try {
-            String systemId = this.directorySource.getURI();
-            if (!systemId.startsWith(FILE)) {
-                throw new ResourceNotFoundException(systemId
-                        + " does not denote a directory");
-            }
             // This relies on systemId being of the form "file://..."
-            File directoryFile = new File(new URL(systemId).getFile());
-            if (!directoryFile.isDirectory()) {
-                throw new ResourceNotFoundException(super.source
+            if (!directorySource.isDirectory()) {
+                throw new ProcessingException(directorySource
                         + " is not a directory.");
             }
 
-            this.contentHandler.startDocument();
-            this.contentHandler.startPrefixMapping(PREFIX, URI);
+            this.getSAXConsumer().startDocument();
+            this.getSAXConsumer().startPrefixMapping(PREFIX, URI);
 
-            Stack ancestors = getAncestors(directoryFile);
-            addAncestorPath(directoryFile, ancestors);
+            Stack<File> ancestors = getAncestors(directorySource);
+            addAncestorPath(directorySource, ancestors);
 
-            this.contentHandler.endPrefixMapping(PREFIX);
-            this.contentHandler.endDocument();
-        } catch (IOException ioe) {
-            throw new ResourceNotFoundException("Could not read directory "
-                    + super.source, ioe);
+            this.getSAXConsumer().endPrefixMapping(PREFIX);
+            this.getSAXConsumer().endDocument();
+        } catch (Exception ioe) {
+            throw new ProcessingException("Could not read directory "
+                    + directorySource, ioe);
         }
     }
 
@@ -313,9 +230,9 @@ public class DirectoryGenerator extends 
      *            the File whose ancestors shall be retrieved
      * @return a Stack containing the ancestors.
      */
-    protected Stack getAncestors(File path) {
+    protected Stack<File> getAncestors(File path) {
         File parent = path;
-        Stack ancestors = new Stack();
+        Stack<File> ancestors = new Stack<File>();
 
         while ((parent != null) && !isRoot(parent)) {
             parent = parent.getParentFile();
@@ -340,7 +257,7 @@ public class DirectoryGenerator extends 
      *            the stack of the ancestors.
      * @throws SAXException
      */
-    protected void addAncestorPath(File path, Stack ancestors)
+    protected void addAncestorPath(File path, Stack<File> ancestors)
             throws SAXException {
         if (ancestors.empty()) {
             this.isRequestedDirectory = true;
@@ -371,7 +288,7 @@ public class DirectoryGenerator extends 
                 File contents[] = path.listFiles();
 
                 if (sort.equals("name")) {
-                    Arrays.sort(contents, new Comparator() {
+                    Arrays.sort(contents, new Comparator<Object>() {
                         public int compare(Object o1, Object o2) {
                             if (reverse) {
                                 return ((File) o2).getName().compareTo(
@@ -382,7 +299,7 @@ public class DirectoryGenerator extends 
                         }
                     });
                 } else if (sort.equals("size")) {
-                    Arrays.sort(contents, new Comparator() {
+                    Arrays.sort(contents, new Comparator<Object>() {
                         public int compare(Object o1, Object o2) {
                             if (reverse) {
                                 return new Long(((File) o2).length())
@@ -394,7 +311,7 @@ public class DirectoryGenerator extends 
                         }
                     });
                 } else if (sort.equals("lastmodified")) {
-                    Arrays.sort(contents, new Comparator() {
+                    Arrays.sort(contents, new Comparator<Object>() {
                         public int compare(Object o1, Object o2) {
                             if (reverse) {
                                 return new Long(((File) o2).lastModified())
@@ -407,7 +324,7 @@ public class DirectoryGenerator extends 
                         }
                     });
                 } else if (sort.equals("directory")) {
-                    Arrays.sort(contents, new Comparator() {
+                    Arrays.sort(contents, new Comparator<Object>() {
                         public int compare(Object o1, Object o2) {
                             File f1 = (File) o1;
                             File f2 = (File) o2;
@@ -454,12 +371,10 @@ public class DirectoryGenerator extends 
      *             if an error occurs while creating the node
      */
     protected void startNode(String nodeName, File path) throws SAXException {
-        if (this.validity != null) {
-            this.validity.addFile(path);
-        }
+        this.validity.add(path);
         setNodeAttributes(path);
-        super.contentHandler.startElement(URI, nodeName, PREFIX + ':'
-                + nodeName, attributes);
+        this.getSAXConsumer().startElement(URI, nodeName,
+                PREFIX + ':' + nodeName, attributes);
     }
 
     /**
@@ -502,7 +417,8 @@ public class DirectoryGenerator extends 
      *             if an error occurs while closing the node
      */
     protected void endNode(String nodeName) throws SAXException {
-        super.contentHandler.endElement(URI, nodeName, PREFIX + ':' + nodeName);
+        this.getSAXConsumer()
+                .endElement(URI, nodeName, PREFIX + ':' + nodeName);
     }
 
     /**
@@ -541,72 +457,31 @@ public class DirectoryGenerator extends 
         return this.excludeRE != null && this.excludeRE.match(path.getName());
     }
 
-    /**
-     * Recycle resources
-     */
-    public void recycle() {
-        if (this.resolver != null) {
-            this.resolver.release(this.directorySource);
-            this.directorySource = null;
-        }
-        this.cacheKeyParList = null;
-        this.attributes = null;
-        this.dateFormatter = null;
-        this.rootRE = null;
-        this.includeRE = null;
-        this.excludeRE = null;
-        this.validity = null;
-        super.recycle();
-    }
-
-    /** Specific validity class, that holds all files that have been generated */
-    public static class DirValidity implements SourceValidity {
-
-        private long expiry;
-        private long delay;
-        List files = new ArrayList();
-        List fileDates = new ArrayList();
-
-        public DirValidity(long delay) {
-            expiry = System.currentTimeMillis() + delay;
-            this.delay = delay;
-        }
-
-        public int isValid() {
-            if (System.currentTimeMillis() <= expiry) {
-                return SourceValidity.VALID;
-            }
-
-            int len = files.size();
-            for (int i = 0; i < len; i++) {
-                File f = (File) files.get(i);
-                if (!f.exists()) {
-                    return SourceValidity.INVALID; // File was removed
-                }
-
-                long oldDate = ((Long) fileDates.get(i)).longValue();
-                long newDate = f.lastModified();
-
-                if (oldDate != newDate) {
-                    // File's last modified date has changed since last check
-                    // NOTE: this occurs on directories as well when a file is
-                    // added
-                    return SourceValidity.INVALID;
-                }
-            }
-
-            // all content is up to date: update the expiry date
-            expiry = System.currentTimeMillis() + delay;
-            return SourceValidity.VALID;
-        }
-
-        public int isValid(SourceValidity newValidity) {
-            return isValid();
+    @SuppressWarnings("deprecation")
+    public CacheKey constructCacheKey() {
+        if (this.directorySource == null) {
+            throw new SetupException(this.getClass().getSimpleName()
+                    + " has no source.");
         }
-
-        public void addFile(File f) {
-            files.add(f);
-            fileDates.add(new Long(f.lastModified()));
+        try {
+            CompoundCacheKey key = new CompoundCacheKey();
+            TimestampCacheKey timestampCacheKey = new TimestampCacheKey(
+                    this.directorySource.toURL(),
+                    directorySource.lastModified());
+            key.addCacheKey(timestampCacheKey);
+            for (File file : validity) {
+                timestampCacheKey = new TimestampCacheKey(
+                        file.toURL(),
+                        file.lastModified());
+                key.addCacheKey(timestampCacheKey);
+            }
+            return key;
+        } catch (Exception e) {
+            this.logger.error(
+                    "Can't construct cache key. Error while connecting to "
+                            + this.directorySource, e);
         }
+        return null;
     }
+
 }

Added: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/Parameters.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/Parameters.java?rev=1142139&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/Parameters.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/Parameters.java
Sat Jul  2 01:01:03 2011
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.pipeline.components.parameters;
+
+import java.util.Map;
+
+public class Parameters {
+
+    private Map<String, ? extends Object> param;
+
+    public Parameters(Map<String, ? extends Object> configuration) {
+        this.param = configuration;
+    }
+
+    public int getAsInteger(String key, int i) {
+        boolean hasValue = param.containsKey(key);
+        if (hasValue){
+            return new Integer((String) param.get(key));
+        }
+        return i;
+    }
+
+    public String get(String key, Object object) {
+        boolean hasValue = param.containsKey(key);
+        if (hasValue){
+            return  (String) param.get(key);
+        }
+        return (String) object;
+    }
+
+    public boolean getAsBoolean(String key, boolean b) {
+        boolean hasValue = param.containsKey(key);
+        if (hasValue){
+            return  new Boolean((String) param.get(key));
+        }
+        return b;
+    }
+
+    public long getAsLong(String key, long l) {
+        boolean hasValue = param.containsKey(key);
+        if (hasValue){
+            return new Long((String) param.get(key));
+        }
+        return l;
+    }
+
+}

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/Parameters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/cocoon3/trunk/cocoon-optional/src/main/resources/META-INF/cocoon/spring-optional/cocoon-optional-generators.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/main/resources/META-INF/cocoon/spring-optional/cocoon-optional-generators.xml?rev=1142139&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/main/resources/META-INF/cocoon/spring-optional/cocoon-optional-generators.xml
(added)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/main/resources/META-INF/cocoon/spring-optional/cocoon-optional-generators.xml
Sat Jul  2 01:01:03 2011
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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: cocoon-optional-fop.xml 712183 2008-11-07 16:24:12Z reinhard $ -->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+  <bean name="generator:dir" class="org.apache.cocoon.generation.DirectoryGenerator" scope="prototype"
/>
+  
+</beans>

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/main/resources/META-INF/cocoon/spring-optional/cocoon-optional-generators.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/main/resources/META-INF/cocoon/spring-optional/cocoon-optional-generators.xml
------------------------------------------------------------------------------
    svn:executable = *

Added: cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/generation/DirectoryGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/generation/DirectoryGeneratorTestCase.java?rev=1142139&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/generation/DirectoryGeneratorTestCase.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/generation/DirectoryGeneratorTestCase.java
Sat Jul  2 01:01:03 2011
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.generation;
+
+import static org.custommonkey.xmlunit.XMLAssert.assertNodeTestPasses;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+import org.apache.cocoon.pipeline.NonCachingPipeline;
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.sax.SAXPipelineComponent;
+import org.apache.cocoon.sax.component.XMLSerializer;
+import org.custommonkey.xmlunit.examples.CountingNodeTester;
+import org.junit.Test;
+import org.w3c.dom.Node;
+
+public final class DirectoryGeneratorTestCase {
+
+    @Test
+    public void testPipelineWithDirectoryGGenerator() throws Exception {
+        Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
+        pipeline.addComponent(new DirectoryGenerator((new File(this.getClass().getResource("test.txt").getFile())).getParentFile()));
+        pipeline.addComponent(new XMLSerializer());
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        pipeline.setup(baos);
+        pipeline.execute();
+
+        // we have 4 files in the test dir. Makes a total of 5 nodes (incl. root)!
+        CountingNodeTester countingNodeTester = new CountingNodeTester(5);
+
+        String string = new String(baos.toByteArray());
+        assertNodeTestPasses(string, countingNodeTester, Node.ELEMENT_NODE);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/generation/DirectoryGeneratorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/test/java/org/apache/cocoon/generation/DirectoryGeneratorTestCase.java
------------------------------------------------------------------------------
    svn:executable = *

Added: cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test.txt
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test.txt?rev=1142139&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test.txt
(added)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test.txt
Sat Jul  2 01:01:03 2011
@@ -0,0 +1 @@
+test
\ No newline at end of file

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

Added: cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test.xml?rev=1142139&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test.xml
(added)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test.xml
Sat Jul  2 01:01:03 2011
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test/>
\ No newline at end of file

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test2.txt
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test2.txt?rev=1142139&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test2.txt
(added)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test2.txt
Sat Jul  2 01:01:03 2011
@@ -0,0 +1 @@
+test
\ No newline at end of file

Propchange: cocoon/cocoon3/trunk/cocoon-optional/src/test/resources/org/apache/cocoon/generation/test2.txt
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message