cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jheym...@apache.org
Subject svn commit: r330548 [46/132] - in /cocoon/whiteboard/maven2/cocoon-flat-layout: ./ cocoon-ajax-block/ cocoon-ajax-block/api/ cocoon-ajax-block/api/src/ cocoon-ajax-block/api/src/main/ cocoon-ajax-block/api/src/main/java/ cocoon-ajax-block/api/src/main/...
Date Thu, 03 Nov 2005 14:00:48 GMT
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ImageDirectoryGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ImageDirectoryGenerator.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ImageDirectoryGenerator.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ImageDirectoryGenerator.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,85 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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 java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.apache.cocoon.util.FileFormatException;
+import org.apache.cocoon.util.ImageProperties;
+import org.apache.cocoon.util.ImageUtils;
+
+import org.xml.sax.SAXException;
+
+/**
+ * @cocoon.sitemap.component.documentation
+ * Generates an XML directory listing. This is an extension of 
+ * the <link href="directory-generator.html">Directory Generator</link> that 
+ * adds extra attributes for image files.
+ * 
+ * @cocoon.sitemap.component.name   imagedirectory
+ * @cocoon.sitemap.component.label  content
+ * @cocoon.sitemap.component.logger sitemap.generator.imagedirectory
+ * @cocoon.sitemap.component.documentation.caching
+ *               Uses the last modification date of the directory and the contained files
+ * 
+ * @cocoon.sitemap.component.pooling.max  16
+ *
+ *
+ * @author <a href="mailto:balld@webslingerZ.com">Donald A. Ball Jr.</a>
+ * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
+ * @version CVS $Id: ImageDirectoryGenerator.java 153227 2005-02-10 15:00:57Z cziegeler $
+ */
+final public class ImageDirectoryGenerator extends DirectoryGenerator {
+
+    protected static String IMAGE_WIDTH_ATTR_NAME = "width";
+    protected static String IMAGE_HEIGHT_ATTR_NAME = "height";
+    protected static String IMAGE_COMMENT_ATTR_NAME = "comment";
+
+    /**
+     * Extends the <code>setNodeAttributes</code> method from the
+     * <code>DirectoryGenerator</code> by adding width, height and comment attributes
+     * if the path is a GIF or a JPEG file.
+     */
+    protected void setNodeAttributes(File path) throws SAXException {
+        super.setNodeAttributes(path);
+        if (path.isDirectory()) {
+            return;
+        }
+        try {
+            ImageProperties p = ImageUtils.getImageProperties(path);
+            if (p != null) {
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug(String.valueOf(path) + " = " + String.valueOf(p));
+                }
+                attributes.addAttribute("", IMAGE_WIDTH_ATTR_NAME, IMAGE_WIDTH_ATTR_NAME, "CDATA", String.valueOf(p.width));
+                attributes.addAttribute("", IMAGE_HEIGHT_ATTR_NAME, IMAGE_HEIGHT_ATTR_NAME, "CDATA", String.valueOf(p.height));
+                if (p.comment != null) attributes.addAttribute("", IMAGE_COMMENT_ATTR_NAME, IMAGE_COMMENT_ATTR_NAME, "CDATA", String.valueOf(p.comment));
+            }
+        }
+        catch (FileFormatException e) {
+            throw new SAXException(e);
+        }
+        catch (FileNotFoundException e) {
+            throw new SAXException(e);
+        }
+        catch (IOException e) {
+            throw new SAXException(e);
+        }
+    }
+
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ImageDirectoryGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/LinkStatusGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/LinkStatusGenerator.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/LinkStatusGenerator.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/LinkStatusGenerator.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,662 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed 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 org.apache.avalon.excalibur.pool.Recyclable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.ResourceNotFoundException;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.Constants;
+import org.apache.commons.lang.StringUtils;
+import org.apache.regexp.RE;
+import org.apache.regexp.RESyntaxException;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URLConnection;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Map;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @cocoon.sitemap.component.documentation
+ * Generates a list of links that are reachable from the src and their status.
+ * 
+ * @cocoon.sitemap.component.name   linkstatus
+ * @cocoon.sitemap.component.label  content
+ * @cocoon.sitemap.component.logger sitemap.generator.linkstatus
+ *
+ * @author Michael Homeijer
+ * @author Nicola Ken Barozzi (nicolaken@apache.org)
+ * @author Bernhard Huber (huber@apache.org)
+ * @version $Id: LinkStatusGenerator.java 164815 2005-04-26 16:43:13Z vgritsenko $
+ */
+public class LinkStatusGenerator extends ServiceableGenerator
+                                 implements Recyclable, Configurable {
+
+    /** The URI of the namespace of this generator. */
+    protected static final String URI =
+            "http://apache.org/cocoon/linkstatus/2.0";
+
+    /** The namespace prefix for this namespace. */
+    protected static final String PREFIX = "linkstatus";
+
+    /* Node and attribute names */
+    protected static final String TOP_NODE_NAME = "linkstatus";
+    protected static final String LINK_NODE_NAME = "link";
+
+    protected static final String HREF_ATTR_NAME = "href";
+    protected static final String REFERRER_ATTR_NAME = "referrer";
+    protected static final String CONTENT_ATTR_NAME = "content";
+    protected static final String STATUS_ATTR_NAME = "status";
+    protected static final String MESSAGE_ATTR_NAME = "message";
+
+    protected AttributesImpl attributes;
+
+    /**
+     * Config element name specifying expected link content-typ.
+     * <p>
+     *   Its value is <code>link-content-type</code>.
+     * </p>
+     *
+     * @since
+     */
+    public final static String LINK_CONTENT_TYPE_CONFIG = "link-content-type";
+
+    /**
+     * Default value of <code>link-content-type</code> configuration value.
+     * <p>
+     *   Its value is <code>application/x-cocoon-links</code>.
+     * </p>
+     *
+     * @since
+     */
+    public final String LINK_CONTENT_TYPE_DEFAULT = "application/x-cocoon-links";
+
+    /**
+     * Config element name specifying query-string appendend for requesting links
+     * of an URL.
+     * <p>
+     *  Its value is <code>link-view-query</code>.
+     * </p>
+     *
+     * @since
+     */
+    public final static String LINK_VIEW_QUERY_CONFIG = "link-view-query";
+    /**
+     * Default value of <code>link-view-query</code> configuration value.
+     * <p>
+     *   Its value is <code>?cocoon-view=links</code>.
+     * </p>
+     *
+     * @since
+     */
+    public final static String LINK_VIEW_QUERY_DEFAULT = "cocoon-view=links";
+
+    /**
+     * Config element name specifying excluding regular expression pattern.
+     * <p>
+     *  Its value is <code>exclude</code>.
+     * </p>
+     *
+     * @since
+     */
+    public final static String EXCLUDE_CONFIG = "exclude";
+
+    /**
+     * Config element name specifying including regular expression pattern.
+     * <p>
+     *  Its value is <code>include</code>.
+     * </p>
+     *
+     * @since
+     */
+    public final static String INCLUDE_CONFIG = "include";
+
+    /**
+     * Config element name specifying http header value for user-Agent.
+     * <p>
+     *  Its value is <code>user-agent</code>.
+     * </p>
+     *
+     * @since
+     */
+    public final static String USER_AGENT_CONFIG = "user-agent";
+    /**
+     * Default value of <code>user-agent</code> configuration value.
+     *
+     * @see org.apache.cocoon.Constants#COMPLETE_NAME
+     * @since
+     */
+    public final static String USER_AGENT_DEFAULT = Constants.COMPLETE_NAME;
+
+    /**
+     * Config element name specifying http header value for accept.
+     * <p>
+     *  Its value is <code>accept</code>.
+     * </p>
+     *
+     * @since
+     */
+    public final static String ACCEPT_CONFIG = "accept";
+    /**
+     * Default value of <code>accept</code> configuration value.
+     * <p>
+     *   Its value is <code>* / *</code>
+     * </p>
+     *
+     * @since
+     */
+    public final static String ACCEPT_DEFAULT = "*/*";
+
+    private String linkViewQuery = LINK_VIEW_QUERY_DEFAULT;
+    private String linkContentType = LINK_CONTENT_TYPE_DEFAULT;
+    private HashSet excludeCrawlingURL;
+    private HashSet includeCrawlingURL;
+    // FIXME - The following two are never read, can we delete them?
+    //private String userAgent = USER_AGENT_DEFAULT;
+    //private String accept = ACCEPT_DEFAULT;
+
+    private HashSet crawled;
+    private HashSet linksToProcess;
+
+    /**
+     * Stores links to process and the referrer links
+     */
+    private class Link {
+        private URL url;
+        private String referrer;
+
+        public Link(URL url, String referrer) {
+            this.url = url;
+            this.referrer = referrer;
+        }
+
+        public URL getURL() {
+            return url;
+        }
+
+        public String getReferrer() {
+            return referrer;
+        }
+
+        public boolean equals(Link l) {
+            return url.equals(l.getURL());
+        }
+    }
+
+    /**
+     * Configure the crawler component.
+     * <p>
+     *  Configure can specify which URI to include, and which URI to exclude
+     *  from crawling. You specify the patterns as regular expressions.
+     * </p>
+     * <p>
+     *  Morover you can configure
+     *  the required content-type of crawling request, and the
+     *  query-string appended to each crawling request.
+     * </p>
+     * <pre><tt>
+     * &lt;include&gt;.*\.html?&lt;/include&gt; or &lt;include&gt;.*\.html?, .*\.xsp&lt;/include&gt;
+     * &lt;exclude&gt;.*\.gif&lt;/exclude&gt; or &lt;exclude&gt;.*\.gif, .*\.jpe?g&lt;/exclude&gt;
+     * &lt;link-content-type&gt; application/x-cocoon-links &lt;/link-content-type&gt;
+     * &lt;link-view-query&gt; ?cocoon-view=links &lt;/link-view-query&gt;
+     * &lt;user-agent&gt; Cocoon &lt;/user-agent&gt;
+     * &lt;accept&gt; text/xml &lt;/accept&gt;
+     * </tt></pre>
+     *
+     * @param  configuration               XML configuration of this avalon component.
+     * @exception  ConfigurationException  is throwing if configuration is invalid.
+     * @since
+     */
+    public void configure(Configuration configuration)
+            throws ConfigurationException {
+
+        Configuration[] children;
+        children = configuration.getChildren(INCLUDE_CONFIG);
+        if (children.length > 0) {
+            includeCrawlingURL = new HashSet();
+            for (int i = 0; i < children.length; i++) {
+                String pattern = children[i].getValue();
+                try {
+                    String params[] = StringUtils.split(pattern, ", ");
+                    for (int index = 0; index < params.length; index++) {
+                        String tokenized_pattern = params[index];
+                        this.includeCrawlingURL.add(new RE(tokenized_pattern));
+                    }
+                } catch (RESyntaxException rese) {
+                    getLogger().error("Cannot create including regular-expression for " +
+                            pattern, rese);
+                }
+            }
+        }
+
+        children = configuration.getChildren(EXCLUDE_CONFIG);
+        if (children.length > 0) {
+            excludeCrawlingURL = new HashSet();
+            for (int i = 0; i < children.length; i++) {
+                String pattern = children[i].getValue();
+                try {
+                    String params[] = StringUtils.split(pattern, ", ");
+                    for (int index = 0; index < params.length; index++) {
+                        String tokenized_pattern = params[index];
+                        this.excludeCrawlingURL.add(new RE(tokenized_pattern));
+                    }
+                } catch (RESyntaxException rese) {
+                    getLogger().error("Cannot create excluding regular-expression for " +
+                            pattern, rese);
+                }
+            }
+        } else {
+            excludeCrawlingURL = new HashSet();
+            setDefaultExcludeFromCrawling();
+        }
+
+        Configuration child;
+        String value;
+        child = configuration.getChild(LINK_CONTENT_TYPE_CONFIG, false);
+        if (child != null) {
+            value = child.getValue();
+            if (value != null && value.length() > 0) {
+                this.linkContentType = value.trim();
+            }
+        }
+        child = configuration.getChild(LINK_VIEW_QUERY_CONFIG, false);
+        if (child != null) {
+            value = child.getValue();
+            if (value != null && value.length() > 0) {
+                this.linkViewQuery = value.trim();
+            }
+        }
+/*      FIXME: Also delete this if you delete the fields above.
+        child = configuration.getChild(USER_AGENT_CONFIG, false);
+        if (child != null) {
+            value = child.getValue();
+            if (value != null && value.length() > 0) {
+                this.userAgent = value;
+            }
+        }
+
+        child = configuration.getChild(ACCEPT_CONFIG, false);
+        if (child != null) {
+            value = child.getValue();
+            if (value != null && value.length() > 0) {
+                this.accept = value;
+            }
+        }
+*/
+    }
+
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
+    throws ProcessingException, SAXException, IOException {
+
+        super.setup(resolver, objectModel, src, par);
+
+        /* Create a reusable attributes for creating nodes */
+        this.attributes = new AttributesImpl();
+
+        // already done in configure...
+        //excludeCrawlingURL = new HashSet();
+        //this.setDefaultExcludeFromCrawling();
+    }
+
+    /**
+     * Generate XML data.
+     *
+     * @throws  SAXException
+     *      if an error occurs while outputting the document
+     * @throws  ProcessingException
+     *      if the requsted URI wasn't found
+     */
+    public void generate()
+    throws SAXException, ProcessingException {
+        try {
+
+            crawled = new HashSet();
+            linksToProcess = new HashSet();
+
+            URL root = new URL(source);
+            linksToProcess.add(new Link(root, ""));
+
+
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("crawl URL " + root);
+            }
+
+            this.contentHandler.startDocument();
+            this.contentHandler.startPrefixMapping(PREFIX, URI);
+
+            attributes.clear();
+            super.contentHandler.startElement(URI, TOP_NODE_NAME, PREFIX + ':' + TOP_NODE_NAME, attributes);
+
+            while (linksToProcess.size() > 0) {
+                Iterator i = linksToProcess.iterator();
+
+                if (i.hasNext()) {
+                    // fetch a URL
+                    Link link = (Link) i.next();
+                    URL url = link.getURL();
+
+                    // remove it from the to-do list
+                    linksToProcess.remove(link);
+
+                    String new_url_link = processURL(url, link.getReferrer());
+
+                    // calc all links from this url
+                    if (new_url_link != null) {
+
+                        List url_links = getLinksFromConnection(new_url_link, url);
+                        if (url_links != null) {
+                            // add links of this url to the to-do list
+                            linksToProcess.addAll(url_links);
+                        }
+                    }
+                }
+            }
+
+            super.contentHandler.endElement(URI, TOP_NODE_NAME, PREFIX + ':' + TOP_NODE_NAME);
+            this.contentHandler.endPrefixMapping(PREFIX);
+            this.contentHandler.endDocument();
+        } catch (IOException ioe) {
+            getLogger().warn("Could not read source ", ioe);
+            throw new ResourceNotFoundException("Could not read source ", ioe);
+        }
+    }
+
+    /**
+     * Default exclude patterns.
+     * <p>
+     *   By default URLs matching following patterns are excluded:
+     * </p>
+     * <ul>
+     *   <li>.*\\.gif(\\?.*)?$ - exclude gif images</li>
+     *   <li>.*\\.png(\\?.*)?$ - exclude png images</li>
+     *   <li>.*\\.jpe?g(\\?.*)?$ - exclude jpeg images</li>
+     *   <li>.*\\.js(\\?.*)?$ - exclude javascript </li>
+     *   <li>.*\\.css(\\?.*)?$ - exclude cascaded stylesheets</li>
+     * </ul>
+     *
+     * @since
+     */
+    private void setDefaultExcludeFromCrawling() {
+        String[] EXCLUDE_FROM_CRAWLING_DEFAULT = {
+            ".*\\.gif(\\?.*)?$",
+            ".*\\.png(\\?.*)?$",
+            ".*\\.jpe?g(\\?.*)?$",
+            ".*\\.js(\\?.*)?$",
+            ".*\\.css(\\?.*)?$"
+        };
+
+        for (int i = 0; i < EXCLUDE_FROM_CRAWLING_DEFAULT.length; i++) {
+            String pattern = EXCLUDE_FROM_CRAWLING_DEFAULT[i];
+            try {
+                excludeCrawlingURL.add(new RE(pattern));
+            } catch (RESyntaxException rese) {
+                getLogger().error("Cannot create excluding regular-expression for " +
+                        pattern, rese);
+            }
+        }
+    }
+
+
+    /**
+     * Retrieve a list of links of a url
+     *
+     * @param url_link_string url for requesting links, it is assumed that
+     *   url_link_string queries the cocoon view links, ie of the form
+     *   <code>http://host/foo/bar?cocoon-view=links</code>
+     * @param url_of_referrer base url of which links are requested, ie of the form
+     *   <code>http://host/foo/bar</code>
+     * @return List of links from url_of_referrer, as result of requesting url
+     *   url_link_string
+     */
+    protected List getLinksFromConnection(String url_link_string, URL url_of_referrer) {
+        List url_links = null;
+        BufferedReader br = null;
+        try {
+            URL url_link = new URL(url_link_string);
+            URLConnection conn = url_link.openConnection();
+            String content_type = conn.getContentType();
+
+            if (content_type == null) {
+                getLogger().warn("No content type available for " + String.valueOf(url_link_string));
+                // caller checks if null
+                return url_links;
+            }
+
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Content-type: " + content_type);
+            }
+
+            if (content_type.equals(linkContentType) ||
+                content_type.startsWith(linkContentType + ";")) {
+                url_links = new ArrayList();
+
+                InputStream is = conn.getInputStream();
+                br = new BufferedReader(new InputStreamReader(is));
+
+                // content is supposed to be a list of links,
+                // relative to current URL
+                String line;
+                String referrer = url_of_referrer.toString();
+
+                while ((line = br.readLine()) != null) {
+                    URL new_url = new URL(url_link, line);
+                    boolean add_url = true;
+                    // don't add new_url twice
+                    if (add_url) {
+                        add_url &= !url_links.contains(new_url);
+                    }
+
+                    // don't add new_url if it has been crawled already
+                    if (add_url) {
+                        add_url &= !crawled.contains(new_url.toString());
+                    }
+
+                    Link new_link = new Link(new_url, referrer);
+                    if (add_url) {
+                        add_url &= !linksToProcess.contains(new_link);
+                    }
+
+                    // don't add if is not matched by existing include definition
+                    if (add_url) {
+                        add_url &= isIncludedURL(new_url.toString());
+                    }
+
+                    if (add_url) {
+                        if (getLogger().isDebugEnabled()) {
+                            getLogger().debug("Add URL: " + new_url.toString());
+                        }
+                        url_links.add(new_link);
+                    }
+                }
+                // now we have a list of URL which should be examined
+            }
+        } catch (IOException ioe) {
+            getLogger().warn("Problems get links of " + url_link_string, ioe);
+        } finally {
+            // explictly close the stream
+            if (br != null) {
+                try {
+                    br.close();
+                    br = null;
+                } catch (IOException ignored) {
+                }
+            }
+        }
+        return url_links;
+    }
+
+    /**
+     * Generate xml attributes of a url, calculate url for retrieving links
+     *
+     * @param url to process
+     * @param referrer of the url
+     * @return String url for retrieving links, or null if url is an excluded-url,
+     *   and not an included-url.
+     */
+    protected String processURL(URL url, String referrer) throws SAXException {
+
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("getLinks URL " + url);
+        }
+
+        String result = null;
+
+        // don't try to investigate a url which has been crawled already
+        if (crawled.contains(url.toString())) {
+            return null;
+        }
+
+        // mark it as crawled
+        crawled.add(url.toString());
+
+        attributes.clear();
+        attributes.addAttribute("", HREF_ATTR_NAME,
+                HREF_ATTR_NAME, "CDATA", url.toString());
+        attributes.addAttribute("", REFERRER_ATTR_NAME,
+                REFERRER_ATTR_NAME, "CDATA", referrer);
+
+        // Output url, referrer, content-type, status, message for traversable url's
+        HttpURLConnection h = null;
+        try {
+
+            URLConnection links_url_connection = url.openConnection();
+            h = (HttpURLConnection) links_url_connection;
+            String content_type = links_url_connection.getContentType();
+
+            attributes.addAttribute("", CONTENT_ATTR_NAME,
+                    CONTENT_ATTR_NAME, "CDATA",
+                    content_type);
+
+            attributes.addAttribute("", MESSAGE_ATTR_NAME,
+                    MESSAGE_ATTR_NAME, "CDATA",
+                    h.getResponseMessage());
+
+            attributes.addAttribute("", STATUS_ATTR_NAME,
+                    STATUS_ATTR_NAME, "CDATA",
+                    String.valueOf(h.getResponseCode()));
+        } catch (IOException ioe) {
+            attributes.addAttribute("", MESSAGE_ATTR_NAME,
+                    MESSAGE_ATTR_NAME, "CDATA",
+                    ioe.getMessage());
+        } finally {
+            if (h != null) {
+                h.disconnect();
+            }
+        }
+
+        // don't try to get links of a url which is excluded from crawling
+        // try to get links of a url which is included for crawling
+        if (!isExcludedURL(url.toString()) && isIncludedURL(url.toString())) {
+            // add prefix and query to get data from the linkserializer.
+            result = url.toExternalForm()
+                    + ((url.toExternalForm().indexOf("?") == -1) ? "?" : "&")
+                    + linkViewQuery;
+        }
+
+        super.contentHandler.startElement(URI, LINK_NODE_NAME, PREFIX + ':' + LINK_NODE_NAME, attributes);
+        super.contentHandler.endElement(URI, LINK_NODE_NAME, PREFIX + ':' + LINK_NODE_NAME);
+
+        return result;
+    }
+
+    /**
+     * check if URL is a candidate for indexing
+     *
+     * @param  url  Description of Parameter
+     * @return      The excludedURL value
+     * @since
+     */
+    private boolean isExcludedURL(String url) {
+        // by default include URL for crawling
+        if (excludeCrawlingURL == null) {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("exclude no URL " + url);
+            }
+            return false;
+        }
+
+        final String s = url.toString();
+        Iterator i = excludeCrawlingURL.iterator();
+        while (i.hasNext()) {
+            RE pattern = (RE) i.next();
+            if (pattern.match(s)) {
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("exclude URL " + url);
+                }
+                return true;
+            }
+        }
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("exclude not URL " + url);
+        }
+        return false;
+    }
+
+
+    /**
+     * check if URL is a candidate for indexing
+     *
+     * @param  url  Description of Parameter
+     * @return      The includedURL value
+     * @since
+     */
+    private boolean isIncludedURL(String url) {
+        // by default include URL for crawling
+        if (includeCrawlingURL == null) {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("include all URL " + url);
+            }
+            return true;
+        }
+
+        final String s = url.toString();
+        Iterator i = includeCrawlingURL.iterator();
+        while (i.hasNext()) {
+            RE pattern = (RE) i.next();
+            if (pattern.match(s)) {
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("include URL " + url);
+                }
+                return true;
+            }
+        }
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("include not URL " + url);
+        }
+        return false;
+    }
+
+    public void recycle() {
+        super.recycle();
+
+        this.attributes = null;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/LinkStatusGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/MP3DirectoryGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/MP3DirectoryGenerator.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/MP3DirectoryGenerator.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/MP3DirectoryGenerator.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,293 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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 org.xml.sax.SAXException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
+/**
+ * @cocoon.sitemap.component.documentation
+ * An extension of DirectoryGenerators that adds extra attributes for MP3
+ * files.
+ * 
+ * @cocoon.sitemap.component.name   mp3directory
+ * @cocoon.sitemap.component.label  content
+ * @cocoon.sitemap.component.logger sitemap.generator.mp3directory
+ * @cocoon.sitemap.component.documentation.caching
+ *               Uses the last modification date of the directory and the contained files
+ * 
+ *
+ * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
+ * @version CVS $Id: MP3DirectoryGenerator.java 225254 2005-07-26 08:02:05Z cziegeler $
+ */
+public class MP3DirectoryGenerator extends DirectoryGenerator
+{
+    // MP3 Constants
+    private static final int VERSION_MPEG1       = 3;
+    // private static final int VERSION_MPEG2       = 2;
+    private static final int MODE_DUAL_CHANNEL   = 2;
+    private static final int MODE_JOINT_STEREO   = 1;
+    private static final int MODE_SINGLE_CHANNEL = 3;
+    private static final int MODE_STEREO         = 0;
+    private static final int VBR_FRAMES_FLAG     = 1;
+    // private static final int VBR_BYTES_FLAG      = 2;
+    // private static final int VBR_TOC_FLAG        = 4;
+    // private static final int VBR_SCALE_FLAG      = 8;
+
+    // Attributes
+    protected static String MP3_FREQUENCY_ATTR_NAME = "frequency";
+    protected static String MP3_BITRATE_ATTR_NAME   = "bitrate";
+    protected static String MP3_MODE_ATTR_NAME      = "mode";
+    protected static String MP3_VBR_ATTR_NAME   = "variable-rate";
+
+    protected static String MP3_TITLE_ATTR_NAME   = "title";
+    protected static String MP3_ARTIST_ATTR_NAME = "artist";
+    protected static String MP3_ALBUM_ATTR_NAME   = "album";
+    protected static String MP3_YEAR_ATTR_NAME    = "year";
+    protected static String MP3_COMMENT_ATTR_NAME = "comment";
+    protected static String MP3_TRACK_ATTR_NAME   = "track";
+    protected static String MP3_GENRE_ATTR_NAME   = "genre";
+
+    /**
+     * Extends the <code>setNodeAttributes</code> method from the
+     * <code>DirectoryGenerator</code> by adding MP3 tag attributes
+     * if the path is a MP3 file with valid tag.
+     */
+    protected void setNodeAttributes(File path) throws SAXException {
+        super.setNodeAttributes(path);
+        if (path.isDirectory()) {
+            return;
+        }
+
+        RandomAccessFile in = null;
+        try {
+            in = new RandomAccessFile(path, "r");
+            setID3HeaderAttributes(in);
+            setID3TagAttributes(in);
+        } catch (IOException e) {
+            getLogger().debug("Could not set attributes for " + path, e);
+        } finally {
+            if(in != null) try{ in.close(); }catch(IOException ignored){}
+        }
+    }
+
+    /**
+     * Read ID3 Tag
+     */
+    private void setID3TagAttributes(RandomAccessFile in) throws IOException  {
+        String s;
+
+        // TAG takes 128 bytes
+        if (in.length() < 128) return;
+        in.seek(in.length() - 128);
+        byte [] buf = new byte[128];
+        // Read TAG
+        if (in.read(buf,0, 128) != 128) return;
+        // Check TAG presence
+        if(buf[0] != 'T' || buf[1] != 'A' || buf[2] != 'G') return;
+
+        s = getID3TagValue(buf, 3, 30);
+        if(s.length() > 0)
+            attributes.addAttribute("", MP3_TITLE_ATTR_NAME, MP3_TITLE_ATTR_NAME, "CDATA", s);
+        s = getID3TagValue(buf, 33,30);
+        if(s.length() > 0)
+            attributes.addAttribute("", MP3_ARTIST_ATTR_NAME, MP3_ARTIST_ATTR_NAME, "CDATA", s);
+        s = getID3TagValue(buf, 63,30);
+        if(s.length() > 0)
+            attributes.addAttribute("", MP3_ALBUM_ATTR_NAME, MP3_ALBUM_ATTR_NAME, "CDATA", s);
+        s = getID3TagValue(buf, 93, 4);
+        if(s.length() > 0)
+            attributes.addAttribute("", MP3_YEAR_ATTR_NAME, MP3_YEAR_ATTR_NAME, "CDATA", s);
+        s = getID3TagValue(buf, 97,29);
+        if(s.length() > 0)
+            attributes.addAttribute("", MP3_COMMENT_ATTR_NAME, MP3_COMMENT_ATTR_NAME, "CDATA", s);
+        if(buf[126] > 0)
+            attributes.addAttribute("", MP3_TRACK_ATTR_NAME, MP3_TRACK_ATTR_NAME, "CDATA",
+                Byte.toString(buf[126]));
+        if(buf[127] > 0)
+            attributes.addAttribute("", MP3_GENRE_ATTR_NAME, MP3_GENRE_ATTR_NAME, "CDATA",
+                Byte.toString(buf[127]));
+    }
+
+    private String getID3TagValue(byte[] buf, int offset, int length) {
+        String s = new String(buf, offset, length);
+        int index = s.indexOf(0x00);
+        if (index != -1) {
+            s = s.substring(0, index);
+        }
+        return s.trim();
+    }
+
+    private void setID3HeaderAttributes(RandomAccessFile in) throws IOException {
+        byte[] buffer = new byte[4];
+
+        // http://floach.pimpin.net/grd/mp3info/frmheader/index.html
+        if (in.read(buffer, 0, 3) != 3) {
+            return;
+        }
+        int header = ((buffer[0] << 16) & 0x00FF0000) | ((buffer[1] << 8) & 0x0000FF00) | ((buffer[2] << 0) & 0x000000FF);
+        do {
+            header <<= 8;
+            if (in.read(buffer, 3, 1) != 1) {
+                return;
+            }
+            header |= (buffer[3] & 0x000000FF);
+        } while (!isSyncMark(header));
+
+        int version = (header >>> 19) & 3;
+        int layer = 4 - (header >>> 17) & 3;
+        // int protection = (header >>> 16) & 1;
+        int bitrate = (header >>> 12) & 0xF;
+        int frequency = (header >>> 10) & 3;
+        // Value 3 is reserved
+        if (frequency == 3) {
+            return;
+        }
+        // int padding = (header >>> 9) & 1;
+        int mode = ((header >>> 6) & 3);
+
+        attributes.addAttribute("", MP3_FREQUENCY_ATTR_NAME, MP3_FREQUENCY_ATTR_NAME, "CDATA",
+            frequencyString(version, frequency));
+        attributes.addAttribute("", MP3_MODE_ATTR_NAME, MP3_MODE_ATTR_NAME, "CDATA",
+            mode(mode));
+
+        int frames = getVBRHeaderFrames(in, version, mode);
+        if (frames != -1) {
+            // get average frame size by deviding fileSize by the number of frames
+            float medFrameSize = (float)in.length() / frames;
+            // This does not work properly: (version == VERSION_MPEG1? 12000.0:144000.0)
+            bitrate = (int)(medFrameSize * frequency(version, frequency) / 144000.0);
+            attributes.addAttribute("", MP3_BITRATE_ATTR_NAME, MP3_BITRATE_ATTR_NAME, "CDATA",
+                Integer.toString(bitrate));
+        } else {
+            attributes.addAttribute("", MP3_BITRATE_ATTR_NAME, MP3_BITRATE_ATTR_NAME, "CDATA",
+                bitrate(version, layer, bitrate));
+        }
+    }
+
+    private static boolean isSyncMark(int header) {
+        boolean sync = ((header & 0xFFF00000) == 0xFFF00000);
+        // filter out invalid sample rate
+        if (sync) sync = ((header >>> 10) & 3) != 3;
+        // filter out invalid layer
+        if (sync) sync = ((header >>> 17) & 3) != 0;
+        // filter out invalid version
+        if (sync) sync = ((header >>> 19) & 3) != 1;
+        return sync;
+    }
+
+    private int getVBRHeaderFrames(RandomAccessFile in, int version, int mode) throws IOException {
+        byte[] buffer = new byte[12];
+
+        // Try to detect VBR header
+        int skip;
+        if (version == VERSION_MPEG1) {
+            if (mode == MODE_SINGLE_CHANNEL) skip = 17;
+            else skip = 32;
+        } else { // mpeg version 2 or 2.5
+            if (mode == MODE_SINGLE_CHANNEL) skip = 9;
+            else skip = 17;
+        }
+        while (skip > 0) {
+            if (in.read() == -1) return -1;
+            skip --;
+        }
+
+        if (in.read(buffer, 0, 12) != 12) {
+            return -1;
+        }
+        if (buffer[0] != 'X' || buffer[1] != 'i' || buffer[2] != 'n' || buffer[3] != 'g'){
+            return -1;
+        }
+
+        attributes.addAttribute("", MP3_VBR_ATTR_NAME, MP3_VBR_ATTR_NAME, "CDATA",
+            "yes");
+
+        int flags =
+            ((buffer[4] & 0xFF) << 24) |
+            ((buffer[5] & 0xFF) << 16) |
+            ((buffer[6] & 0xFF) <<  8) |
+             (buffer[7] & 0xFF);
+
+        if ((flags & VBR_FRAMES_FLAG) == VBR_FRAMES_FLAG){
+            int frames =
+                ((buffer[ 8] & 0xFF) << 24) |
+                ((buffer[ 9] & 0xFF) << 16) |
+                ((buffer[10] & 0xFF) <<  8) |
+                 (buffer[11] & 0xFF);
+            return frames;
+        } else {
+            return -1;
+        }
+    }
+
+    // version - layer - bitrate index
+    private static final String bitrates[][][] = {
+    {
+        // MPEG2 - layer 1
+        {"free format", "32", "48", "56", "64", "80", "96", "112", "128", "144", "160", "176", "192", "224", "256", "forbidden"},
+        // MPEG2 - layer 2
+        {"free format", "8", "16", "24", "32", "40", "48", "56", "64", "80", "96", "112", "128", "144", "160", "forbidden"},
+        // MPEG2 - layer 3
+        {"free format", "8", "16", "24", "32", "40", "48", "56", "64", "80", "96", "112", "128", "144", "160", "forbidden"}
+      },
+      {
+        // MPEG1 - layer 1
+        {"free format", "32", "64", "96", "128", "160", "192", "224", "256", "288", "320", "352", "384", "416", "448", "forbidden"},
+        // MPEG1 - layer 2
+        {"free format", "32", "48", "56", "64", "80", "96", "112", "128", "160", "192", "224", "256", "320", "384", "forbidden"},
+        // MPEG1 - layer 3
+        {"free format", "32", "40", "48", "56", "64", "80" , "96", "112", "128", "160", "192", "224", "256", "320", "forbidden"}
+      }
+    };
+
+    private static String bitrate(int version, int layer, int bitrate_index) {
+        return bitrates[version & 1][layer - 1][bitrate_index];
+    }
+
+    private static String mode(int mode) {
+        switch(mode)
+        {
+        case MODE_STEREO:
+            return "Stereo";
+        case MODE_JOINT_STEREO:
+            return "Joint stereo";
+        case MODE_DUAL_CHANNEL:
+            return "Dual channel";
+        case MODE_SINGLE_CHANNEL:
+            return "Single channel";
+        }
+        return null;
+    }
+
+    private static final int frequencies[][] = {
+        {32000, 16000,  8000}, //MPEG 2.5
+        {    0,     0,     0}, //reserved
+        {22050, 24000, 16000}, //MPEG 2
+        {44100, 48000, 32000}  //MPEG 1
+    };
+
+    private static int frequency(int version, int frequency) {
+        return frequencies[version][frequency];
+    }
+
+    private static String frequencyString(int version, int frequency) {
+        return String.valueOf((float)frequency(version, frequency)/1000);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/MP3DirectoryGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/RequestGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/RequestGenerator.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/RequestGenerator.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/RequestGenerator.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,238 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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 java.io.IOException;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.util.Enumeration;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameterizable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.environment.http.RequestEncodingException;
+import org.apache.cocoon.xml.XMLUtils;
+import org.apache.cocoon.xml.IncludeXMLConsumer;
+import org.apache.excalibur.xml.sax.SAXParser;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * @cocoon.sitemap.component.documentation
+ * Generates an XML representation of the incoming request.
+ * 
+ * @cocoon.sitemap.component.name   request
+ * @cocoon.sitemap.component.label  content
+ * @cocoon.sitemap.component.logger sitemap.generator.request
+ * 
+ * @cocoon.sitemap.component.pooling.max  16
+ * 
+ * <p>
+ * <b>Configuration options:</b>
+ * <dl>
+ * <dt> <i>container-encoding</i> (optional)
+ * <dd> The encoding used by container. Default value is ISO-8859-1.
+ * <dt> <i>form-encoding</i> (optional)
+ * <dd> The supposed encoding of the request parameter. Default is null.
+ * <dt> <i>generate-attributes</i> (optional)
+ * <dd> If true, request attributes were also included. Default is false.
+ * </dl>
+ * These configuration options are supported at both declaration and use time.
+ * The configuration at use time takes priority over declaration time.
+ *
+ * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
+ * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
+ * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @version CVS $Id: RequestGenerator.java 292767 2005-09-30 15:14:46Z bloritsch $
+ */
+public class RequestGenerator extends ServiceableGenerator implements Parameterizable {
+
+    /** The namespace prefix of this generator. */
+    private final static String PREFIX = "h";
+    /** The namespace URI of this generator. */
+    private final static String URI = "http://apache.org/cocoon/request/2.0";
+
+    /** The configured container encoding at declaration time. */
+    private String global_container_encoding;
+    /** The configured container encoding at use time. */
+    private String container_encoding;
+
+    /** The configured form encoding at declaration time. */
+    private String global_form_encoding;
+    /** The configured form encoding at use time. */
+    private String form_encoding;
+
+    /** The configuration for including request attributes at declaration time. */
+    private boolean global_generate_attributes;
+    /** The configuration for including request attributes at use time. */
+    private boolean generate_attributes;
+
+    public void parameterize(Parameters parameters)
+    throws ParameterException {
+        global_container_encoding = parameters.getParameter("container-encoding", "ISO-8859-1");
+        global_form_encoding = parameters.getParameter("form-encoding", null);
+        global_generate_attributes = parameters.getParameterAsBoolean("generate-attributes", false);
+    }
+
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters)
+    throws ProcessingException, SAXException, IOException {
+        super.setup(resolver, objectModel, src, parameters);
+        container_encoding = parameters.getParameter("container-encoding", global_container_encoding);
+        form_encoding = parameters.getParameter("form-encoding", global_form_encoding);
+        generate_attributes = parameters.getParameterAsBoolean("generate-attributes", global_generate_attributes);
+    }
+
+    /**
+     * Generate XML data.
+     */
+    public void generate()
+    throws SAXException {
+        final Request request = ObjectModelHelper.getRequest(objectModel);
+        final AttributesImpl attr = new AttributesImpl();
+
+        this.contentHandler.startDocument();
+        this.contentHandler.startPrefixMapping(PREFIX, URI);
+
+        attribute(attr, "target", request.getRequestURI());
+        attribute(attr, "sitemap", request.getSitemapURI());
+        attribute(attr, "source", (this.source != null ? this.source : ""));
+        start("request", attr);
+
+        start("requestHeaders", attr);
+        Enumeration headers = request.getHeaderNames();
+        if ( headers != null ) {
+            while (headers.hasMoreElements()) {
+                String header = (String)headers.nextElement();
+                attribute(attr, "name", header);
+                start("header", attr);
+                data(request.getHeader(header));
+                end("header");
+            }
+        }
+        end("requestHeaders");
+
+        start("requestParameters", attr);
+        Enumeration parameters = request.getParameterNames();
+        while (parameters.hasMoreElements()) {
+            String parameter = (String)parameters.nextElement();
+            attribute(attr, "name", parameter);
+            start("parameter", attr);
+            String values[] = request.getParameterValues(parameter);
+            if (values != null) {
+                for (int x = 0; x < values.length; x++) {
+                    start("value", attr);
+                    if (form_encoding != null) {
+                        try {
+                            data(values[x], container_encoding, form_encoding);
+                        } catch (UnsupportedEncodingException uee) {
+                            throw new RequestEncodingException("The suggested encoding is not supported.", uee);
+                        }
+                    } else if (parameter.startsWith("xml:")) {
+                        parse(values[x]);
+                    } else {
+                        data(values[x]);
+                    }
+                    end("value");
+                }
+            }
+            end("parameter");
+        }
+        end("requestParameters");
+
+        if (generate_attributes) {
+            start("requestAttributes", attr);
+            Enumeration attributes = request.getAttributeNames();
+            while (attributes.hasMoreElements()) {
+                String attribute = (String)attributes.nextElement();
+                attribute(attr, "name", attribute);
+                start("attribute", attr);
+                Object value = request.getAttribute(attribute);
+                if (value != null) {
+                    start("value", attr);
+                    XMLUtils.valueOf(this.contentHandler, value);
+                    end("value");
+                }
+                end("attribute");
+            }
+            end("requestAttributes");
+        }
+
+        this.start("configurationParameters", attr);
+        String[] confparams = super.parameters.getNames();
+        for (int i = 0; i < confparams.length; i++) {
+            attribute(attr, "name", confparams[i]);
+            start("parameter", attr);
+            data(super.parameters.getParameter(confparams[i], ""));
+            end("parameter");
+        }
+        end("configurationParameters");
+
+        end("request");
+
+        this.contentHandler.endPrefixMapping(PREFIX);
+        this.contentHandler.endDocument();
+    }
+
+    private void attribute(AttributesImpl attr, String name, String value) {
+        attr.addAttribute("", name, name, "CDATA", value);
+    }
+
+    private void start(String name, AttributesImpl attr)
+    throws SAXException {
+        super.contentHandler.startElement(URI, name, PREFIX + ":" + name, attr);
+        attr.clear();
+    }
+
+    private void end(String name)
+    throws SAXException {
+        super.contentHandler.endElement(URI, name, PREFIX + ":" + name);
+    }
+
+    private void data(String data)
+    throws SAXException {
+        super.contentHandler.characters(data.toCharArray(), 0, data.length());
+    }
+    
+    private void data(String data, String container_encoding, String form_encoding) 
+    throws SAXException, UnsupportedEncodingException {
+        this.data(new String(data.getBytes(container_encoding), form_encoding));
+    }
+    
+    private void parse(String data)
+    throws SAXException {
+        SAXParser parser = null;
+        try {
+            parser = (SAXParser) manager.lookup(SAXParser.ROLE);
+            InputSource is = new InputSource(new StringReader(data));
+            parser.parse(is, new IncludeXMLConsumer(super.xmlConsumer));
+	} catch (SAXException se) {
+	    // rethrow sax exceptions
+	    throw se;
+	} catch (Exception e) {
+	    // wrap all others
+	    throw new RequestParseException("Could not parse the parameters.", e);
+        } finally {
+            manager.release(parser);
+        }
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/RequestGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/RequestParseException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/RequestParseException.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/RequestParseException.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/RequestParseException.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,31 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed 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 org.xml.sax.SAXException;
+
+public final class RequestParseException extends SAXException
+{
+    public RequestParseException(String message)
+    {
+        super(message, null);
+    }
+
+    public RequestParseException(String message, Exception cause)
+    {
+        super(message, cause);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/RequestParseException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ServiceableGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ServiceableGenerator.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ServiceableGenerator.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ServiceableGenerator.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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 org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+
+/**
+ * A default implementation that can be used for writing own generators.
+ *  
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @version CVS $Id: ServiceableGenerator.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ * @since 2.1.1
+ */
+public abstract class ServiceableGenerator extends AbstractGenerator
+implements Serviceable, Disposable {
+
+    /** The service manager instance */
+    protected ServiceManager manager;
+
+    /**
+     * Set the current <code>ServiceManager</code> instance used by this
+     * <code>Serviceable</code>.
+     */
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+    }
+
+    /**
+     * Release all resources.
+     */
+    public void dispose() {
+        this.manager = null;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ServiceableGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ServletGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ServletGenerator.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ServletGenerator.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ServletGenerator.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed 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 org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Response;
+import org.apache.cocoon.environment.SourceResolver;
+
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ *
+ * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
+ * @version CVS $Id: ServletGenerator.java 55257 2004-10-21 20:36:33Z cziegeler $
+ */
+public abstract class ServletGenerator extends AbstractGenerator
+implements Serviceable, Disposable {
+
+    protected Request request;
+    protected Response response;
+    protected Context context;
+
+    /** The service manager instance */
+    protected ServiceManager manager;
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+     */
+    public void service(ServiceManager manager) throws ServiceException {
+        this.manager = manager;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
+     */
+    public void dispose() {
+        this.manager = null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+     */
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
+    throws ProcessingException, SAXException, IOException {
+
+        super.setup(resolver, objectModel, src, par);
+        this.request = ObjectModelHelper.getRequest(objectModel);
+        this.response = ObjectModelHelper.getResponse(objectModel);
+        this.context = ObjectModelHelper.getContext(objectModel);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
+     */
+    public void recycle() {
+        super.recycle();
+        this.request = null;
+        this.response = null;
+        this.context = null;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/ServletGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/SessionAttributeGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/SessionAttributeGenerator.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/SessionAttributeGenerator.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/SessionAttributeGenerator.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,160 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed 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 org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.xml.XMLUtils;
+import org.apache.cocoon.xml.IncludeXMLConsumer;
+import org.apache.excalibur.xml.sax.XMLizable;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * @cocoon.sitemap.component.documentation
+ * Generates a document from a session attribute.
+ *
+ * @cocoon.sitemap.component.name   sessionattribute
+ * @cocoon.sitemap.component.label  content
+ * @cocoon.sitemap.component.logger sitemap.generator.sessionattribute
+ *
+ * Generates a document from a session attribute. The attribute may be a DOM
+ * node, an <code>XMLizable</code>, or any other object, and is streamed using
+ * the same rules as for &lt;xsp:expr&gt; in XSPs (see {@link
+ * org.apache.cocoon.components.language.markup.xsp.XSPObjectHelper}).
+ * <p>
+ * Name of the session attribute is specified using src attribute of the generate
+ * tag, or, if no src tag present, using attr-name parameter.
+ * <p>
+ * This generator has 2 parameters:
+ * <ul>
+ * <li><code>attr-name</code> : the session attribute name (mandatory if no src
+ *     attribute specified).
+ * </li>
+ * <li><code>root-element</code> (optional) : the name of the root element of the
+ *     produced document. This parameter is optional if the session attribute is
+ *     a DOM or an <code>XMLizable</code>.
+ * </li>
+ * </ul>
+ * <p>
+ * Example usage :
+ * <pre>
+ *   &lt;map:generator name="session-attr" logger="sitemap.generator.session-attr"
+ *     src="org.apache.cocoon.generation.SessionAttributeGenerator"/&gt;
+ *   ...
+ *   &lt;map:generate type="session-attr"&gt;
+ *     &lt;map:parameter name="attr-name" value="myAttribute"/&gt;
+ *     &lt;map:parameter name="root-element" value="root"/&gt;
+ *   &lt;/map:generate&gt;
+ * </pre>
+ *
+ * @see org.apache.cocoon.transformation.ReadDOMSessionTransformer
+ * @see org.apache.cocoon.transformation.WriteDOMSessionTransformer
+ * @author <a href="mailto:cedric.damioli@anyware-tech.com">C&eacute;dric Damioli</a>
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version $Id: SessionAttributeGenerator.java 171341 2005-05-22 16:35:41Z cziegeler $
+ */
+public class SessionAttributeGenerator extends AbstractGenerator {
+
+    public static final String ATTR_NAME = "attr-name";
+    public static final String ELEMENT_NAME = "root-element";
+
+    /** The object to generate */
+    private Object attrObject;
+
+    /** The element name */
+    private String elementName;
+
+    /**
+     * Setup the file generator :try to retrieve the session attribute given as sitemap parameter
+     */
+    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
+      throws ProcessingException, SAXException, IOException {
+
+        super.setup(resolver, objectModel, src, par);
+
+        // Get the element name (can be null if the object is a DOM or an XMLizable)
+        this.elementName = par.getParameter(ELEMENT_NAME, null);
+
+        // Get the attribute name
+        String attrName = par.getParameter(ATTR_NAME, src);
+        if (attrName == null) {
+            String msg = "SessionAttributeGenerator needs an attribute name !";
+            getLogger().error(msg);
+            throw new ProcessingException(msg);
+        }
+
+        // Get the object to stream
+        Request request = ObjectModelHelper.getRequest(objectModel);
+        Session session = request.getSession(false);
+        if (session != null) {
+            this.attrObject = session.getAttribute(attrName);
+        }
+
+        // Controls
+        if (this.attrObject == null) {
+            if (this.elementName == null) {
+                // Can't generate nothing...
+                String msg = "Session attribute '" + attrName + "' doesn't exist";
+                getLogger().error(msg);
+                throw new ProcessingException(msg);
+            } else {
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("Session attribute '" + attrName +
+                        "' doesn't exist : will generate a single '" + this.elementName +
+                        "' element.");
+                }
+            }
+        } else {
+            // Need an element name for non-xml objects
+            if (this.elementName == null &&
+                ! (this.attrObject instanceof XMLizable) &&
+                ! (this.attrObject instanceof Node)) {
+
+                String msg = "Session attribute '" + attrName + "' needs an enclosing element : class is " +
+                    this.attrObject.getClass().getName();
+
+                getLogger().warn(msg);
+                throw new ProcessingException(msg);
+            }
+        }
+    }
+
+    /**
+     * Generate XML data
+     */
+    public void generate()
+    throws IOException, SAXException, ProcessingException {
+        xmlConsumer.startDocument();
+
+        if (this.elementName != null) {
+            xmlConsumer.startElement("", this.elementName, this.elementName, XMLUtils.EMPTY_ATTRIBUTES);
+            XMLUtils.valueOf(new IncludeXMLConsumer(xmlConsumer), this.attrObject);
+            xmlConsumer.endElement("", this.elementName, this.elementName);
+        } else {
+            XMLUtils.valueOf(new IncludeXMLConsumer(xmlConsumer), this.attrObject);
+        }
+
+        xmlConsumer.endDocument();
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/generation/SessionAttributeGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message