cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jheym...@apache.org
Subject svn commit: r330548 [42/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/environment/commandline/CommandLineContext.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineContext.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineContext.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineContext.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,124 @@
+/*
+ * 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.environment.commandline;
+
+import org.apache.commons.collections.iterators.IteratorEnumeration;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.impl.ContextMap;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.InputStream;
+
+/**
+ *
+ * Implements the {@link org.apache.cocoon.environment.Context} interface
+ * @author ?
+ * @version CVS $Id: CommandLineContext.java 170436 2005-05-16 19:50:25Z danielf $
+ */
+
+public class CommandLineContext extends AbstractLogEnabled implements Context {
+
+    /** The context directory path*/
+    private String contextDir;
+
+    /** The context attributes */
+    private Map attributes;
+
+    /**
+     * Constructs a CommandlineContext object from a ServletContext object
+     */
+    public CommandLineContext (String contextDir) {
+        String contextDirPath = new File(contextDir).getAbsolutePath();
+        // store contextDirPath as is don't remove trailing /.
+        this.contextDir = contextDirPath;
+        this.attributes = new HashMap();
+    }
+
+    public Object getAttribute(String name) {
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("CommandlineContext: getAttribute=" + name);
+        }
+        return this.attributes.get(name);
+    }
+
+    public void setAttribute(String name, Object value) {
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("CommandlineContext: setAttribute=" + name);
+        }
+        this.attributes.put(name, value);
+    }
+
+    public void removeAttribute(String name) {
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("CommandlineContext: removeAttribute=" + name);
+        }
+        this.attributes.remove(name);
+    }
+
+    public Enumeration getAttributeNames() {
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("CommandlineContext: getAttributeNames");
+        }
+        return new IteratorEnumeration(this.attributes.keySet().iterator());
+    }
+
+    public Map getAttributes() {
+	return new ContextMap(this);
+    }
+
+    public URL getResource(String path) throws MalformedURLException {
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("CommandlineContext: getResource=" + path);
+        }
+        // rely on File to build correct File and URL
+        File f = new File( contextDir, path );
+        if (!f.exists()) return null;
+        return f.toURL();
+    }
+
+    public String getRealPath(String path) {
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("CommandlineContext: getRealPath=" + path);
+        }
+        // rely on File to build correct File and URL
+        File f = new File( this.contextDir, path );
+        return f.getAbsolutePath();
+    }
+
+    public String getMimeType(String file) {
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("CommandlineContext: getMimeType=" + file);
+        }
+        //return servletContext.getMimeType(file);
+        return null;
+    }
+
+    public String getInitParameter(String name) {
+        getLogger().debug("CommandlineContext: getInitParameter=" + name);
+        return null;
+    }
+
+    public InputStream getResourceAsStream(String path){
+        getLogger().debug("CommandlineContext: getResourceAsStream "+path);
+    return null;
+    }
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineRequest.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineRequest.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineRequest.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineRequest.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,441 @@
+/*
+ * 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.environment.commandline;
+
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Vector;
+
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.environment.Cookie;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.environment.impl.AbstractRequest;
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.lang.SystemUtils;
+import org.apache.commons.lang.NotImplementedException;
+
+/**
+ * Creates a specific servlet request simulation from command line usage.
+ *
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @version $Id: CommandLineRequest.java 292732 2005-09-30 13:45:54Z bloritsch $
+ */
+
+/*
+ * NOTE: method with a non-compliant implementation are marked with FIXME
+ * and should be fixed in the future if required
+ */
+public class CommandLineRequest extends AbstractRequest {
+
+    private class EmptyEnumeration implements Enumeration {
+        public boolean hasMoreElements() {
+            return false;
+        }
+        public Object nextElement() {
+            return null;
+        }
+    }
+
+    private Environment env;
+    private String contextPath;
+    private String servletPath;
+    private String pathInfo;
+    private Map globalAttributes;
+    private Map attributes;
+    private Map parameters;
+    private Map headers;
+    private String characterEncoding;
+
+    public CommandLineRequest(Environment env,
+                              String contextPath,
+                              String servletPath,
+                              String pathInfo) {
+        this(env, contextPath, servletPath, pathInfo, null, null, null);
+    }
+
+    public CommandLineRequest(Environment env,
+                              String contextPath,
+                              String servletPath,
+                              String pathInfo,
+                              Map attributes) {
+        this(env, contextPath, servletPath, pathInfo, attributes, null, null);
+    }
+
+    public CommandLineRequest(Environment env,
+                              String contextPath,
+                              String servletPath,
+                              String pathInfo,
+                              Map attributes,
+                              Map parameters) {
+        this(env, contextPath, servletPath, pathInfo, attributes, parameters, null);
+    }
+
+    public CommandLineRequest(Environment env,
+                              String contextPath,
+                              String servletPath,
+                              String pathInfo,
+                              Map attributes,
+                              Map parameters,
+                              Map headers) {
+        this.env = env;
+        this.contextPath = contextPath;
+        this.servletPath = servletPath;
+        this.pathInfo = pathInfo;
+        this.globalAttributes = (attributes == null ? new HashMap() : attributes);
+        this.attributes = new HashMap();
+        this.parameters = parameters;
+        this.headers = headers;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#get(java.lang.String)
+     */
+    public Object get(String name) {
+        String[] values = this.getParameterValues(name);
+        if (values == null || values.length == 0) {
+            return null;
+        } else if (values.length == 1) {
+            return values[0];
+        } else {
+            Vector vect = new Vector(values.length);
+            for (int i = 0; i < values.length; i++) {
+                vect.add(values[i]);
+            }
+            return vect;
+        }
+    }
+
+    public String getContextPath() { return contextPath; }
+    public String getServletPath() { return servletPath; }
+    public String getPathInfo() { return pathInfo; }
+    public String getRequestURI() {
+        StringBuffer buffer = new StringBuffer();
+        if (servletPath != null) buffer.append(servletPath);
+        if (contextPath != null) buffer.append(contextPath);
+        if (pathInfo != null) buffer.append(pathInfo);
+        return buffer.toString();
+    }
+    // FIXME
+    public String getSitemapURI() {
+        return this.env.getURI();
+    }
+    public String getSitemapURIPrefix() {
+        return this.env.getURIPrefix();
+    }
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getSitemapPath()
+     */
+    public String getSitemapPath() {
+        return this.env.getURIPrefix();
+    }
+
+    public String getQueryString() { return null; } // use parameters instead
+    public String getPathTranslated() { return null; } // FIXME (SM) this is legal but should we do something more?
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getAttribute(java.lang.String)
+     */
+    public Object getAttribute(String name) {
+        return this.getAttribute(name, Request.GLOBAL_SCOPE);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getAttributeNames()
+     */
+    public Enumeration getAttributeNames() {
+        return this.getAttributeNames(Request.GLOBAL_SCOPE);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#setAttribute(java.lang.String, java.lang.Object)
+     */
+    public void setAttribute(String name, Object value) {
+        this.setAttribute(name, value, Request.GLOBAL_SCOPE);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#removeAttribute(java.lang.String)
+     */
+    public void removeAttribute(String name) {
+        this.removeAttribute(name, Request.GLOBAL_SCOPE);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getAttribute(java.lang.String, int)
+     */
+    public Object getAttribute(String name, int scope) {
+        if ( scope == Request.REQUEST_SCOPE ) {
+            return this.attributes.get(name);
+        }
+        return this.globalAttributes.get(name);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getAttributeNames(int)
+     */
+    public Enumeration getAttributeNames(int scope) {
+        if ( scope == Request.REQUEST_SCOPE ) {
+            return IteratorUtils.asEnumeration(this.attributes.keySet().iterator());
+        }
+        return IteratorUtils.asEnumeration(this.globalAttributes.keySet().iterator());
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#setAttribute(java.lang.String, java.lang.Object, int)
+     */
+    public void setAttribute(String name, Object value, int scope) {
+        if ( scope == Request.REQUEST_SCOPE ) {
+            this.attributes.put(name, value);
+        } else {
+            this.globalAttributes.put(name, value);
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#removeAttribute(java.lang.String, int)
+     */
+    public void removeAttribute(String name, int scope) {
+        if ( scope == Request.REQUEST_SCOPE ) {
+            this.attributes.remove(name);
+        } else {
+            this.globalAttributes.remove(name);
+        }
+    }
+
+    public String getParameter(String name) {
+        if (this.parameters == null) {
+            return null;
+        }
+
+        final Object value = this.parameters.get(name);
+        if (value instanceof String) {
+            return (String)value;
+        } else if (value == null) {
+            return null;
+        } else {
+            final String[] values = (String[]) value;
+            if (values.length == 0) {
+                return null;
+            }
+            return values[0];
+        }
+    }
+
+    public Enumeration getParameterNames() {
+        return (this.parameters != null) ? IteratorUtils.asEnumeration(this.parameters.keySet().iterator()) : null;
+    }
+
+    public String[] getParameterValues(String name) {
+        final Object value = this.parameters.get(name);
+        if (value instanceof String) {
+            return new String[] { (String)value };
+        }
+        return (String[]) value;
+    }
+
+    public String getHeader(String name) {
+        return (headers != null) ? (String) headers.get(name.toLowerCase()) : null;
+    }
+
+    public int getIntHeader(String name) {
+        String header = (headers != null) ? (String) headers.get(name.toLowerCase()) : null;
+        return (header != null) ? Integer.parseInt(header) : -1;
+    }
+
+    public long getDateHeader(String name) {
+        //FIXME
+        return 0;
+    }
+
+    public Enumeration getHeaders(String name) {
+        // FIXME
+        return new EmptyEnumeration();
+    }
+
+    public Enumeration getHeaderNames() {
+        if (headers != null) {
+            return IteratorUtils.asEnumeration(headers.keySet().iterator());
+        }
+        return new EmptyEnumeration();
+    }
+
+    public String getCharacterEncoding() { return characterEncoding; }
+    public int getContentLength() { return -1; }
+
+    public String getContentType() { return null; }
+    public String getProtocol()  { return "cli"; }
+    public String getScheme() { return "cli"; }
+    public String getServerName() { return Constants.COMPLETE_NAME; }
+    public int getServerPort() { return -1; }
+    public String getRemoteAddr() { return "127.0.0.1"; }
+    public String getRemoteHost() { return "localhost"; }
+    public String getMethod() { return "get"; }
+    public String getRemoteUser() { return SystemUtils.USER_NAME; }
+
+    public Cookie[] getCookies() { return null; }
+    public Map getCookieMap() {
+        return Collections.unmodifiableMap(new HashMap());
+    }
+
+    /**
+     * Returns the current session associated with this request,
+     * or if the request does not have a session, creates one.
+     *
+     * @return                the <code>Session</code> associated
+     *                        with this request
+     *
+     * @see        #getSession(boolean)
+     */
+    public Session getSession() {
+        return this.getSession(true);
+    }
+
+    /**
+     * Returns the current <code>Session</code>
+     * associated with this request or, if if there is no
+     * current session and <code>create</code> is true, returns
+     * a new session.
+     *
+     * <p>If <code>create</code> is <code>false</code>
+     * and the request has no valid <code>Session</code>,
+     * this method returns <code>null</code>.
+     *
+     * <p>To make sure the session is properly maintained,
+     * you must call this method before
+     * the response is committed.
+     *
+     * @param create  <code>true</code> to create a new session for this request
+     *                if necessary;
+     *                <code>false</code> to return <code>null</code> if there's
+     *                no current session
+     *
+     * @return  the <code>Session</code> associated with this request or
+     *          <code>null</code> if <code>create</code> is <code>false</code>
+     *          and the request has no valid session
+     *
+     * @see  #getSession()
+     */
+    public Session getSession(boolean create) {
+        return CommandLineSession.getSession(create);
+    }
+
+    /**
+     * Returns the session ID specified by the client. This may
+     * not be the same as the ID of the actual session in use.
+     * For example, if the request specified an old (expired)
+     * session ID and the server has started a new session, this
+     * method gets a new session with a new ID. If the request
+     * did not specify a session ID, this method returns
+     * <code>null</code>.
+     *
+     *
+     * @return                a <code>String</code> specifying the session
+     *                        ID, or <code>null</code> if the request did
+     *                        not specify a session ID
+     *
+     * @see                #isRequestedSessionIdValid()
+     */
+    public String getRequestedSessionId() {
+        return (CommandLineSession.getSession(false) != null) ?
+                CommandLineSession.getSession(false).getId() : null;
+    }
+
+    /**
+     * Checks whether the requested session ID is still valid.
+     *
+     * @return                        <code>true</code> if this
+     *                                request has an id for a valid session
+     *                                in the current session context;
+     *                                <code>false</code> otherwise
+     *
+     * @see                        #getRequestedSessionId()
+     * @see                        #getSession()
+     */
+    public boolean isRequestedSessionIdValid() {
+        return (CommandLineSession.getSession(false) != null);
+    }
+
+    /**
+     * Checks whether the requested session ID came in as a cookie.
+     *
+     * @return                        <code>true</code> if the session ID
+     *                                came in as a
+     *                                cookie; otherwise, <code>false</code>
+     *
+     *
+     * @see                        #getSession()
+     */
+    public boolean isRequestedSessionIdFromCookie() {
+        return false;
+    }
+
+    /**
+     * Checks whether the requested session ID came in as part of the
+     * request URL.
+     *
+     * @return                        <code>true</code> if the session ID
+     *                                came in as part of a URL; otherwise,
+     *                                <code>false</code>
+     *
+     *
+     * @see                        #getSession()
+     */
+    public boolean isRequestedSessionIdFromURL() {
+        return false;
+    }
+
+    public Locale getLocale() { return Locale.getDefault(); }
+    public Enumeration getLocales() {
+        // FIXME
+        throw new NotImplementedException (getClass().getName() + ".getLocales() method not yet implemented!");
+    }
+
+    public String getAuthType() { return null; }
+    public boolean isSecure() { return false; }
+    public boolean isUserInRole(String role) { return false; }
+    public java.security.Principal getUserPrincipal() { return null; }
+
+    public java.util.Map getParameterMap() { return parameters; }
+    public void setCharacterEncoding(java.lang.String env)
+                          throws java.io.UnsupportedEncodingException { characterEncoding = env; }
+    public StringBuffer getRequestURL() { return null; }
+
+	/*
+	 * @see org.apache.cocoon.environment.Request#getInputStream()
+	 */
+	public InputStream getInputStream() throws UnsupportedOperationException {
+		throw new UnsupportedOperationException();
+	}
+
+    /**
+     * @see org.apache.cocoon.environment.Request#searchAttribute(java.lang.String)
+     */
+    public Object searchAttribute(String name) {
+        Object result = this.getAttribute(name, REQUEST_SCOPE);
+        if ( result == null ) {
+            result = this.getAttribute(name, GLOBAL_SCOPE);
+        }
+        return result;
+    }
+
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineResponse.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineResponse.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineResponse.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineResponse.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,45 @@
+/*
+ * 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.environment.commandline;
+
+import org.apache.cocoon.environment.Cookie;
+import org.apache.cocoon.environment.Response;
+
+import java.util.Locale;
+
+/**
+ * Creates a specific servlet response simulation from command line usage.
+ *
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @version CVS $Id: CommandLineResponse.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+
+public class CommandLineResponse implements Response {
+
+    public String getCharacterEncoding() { return null; }
+    public Cookie createCookie(String name, String value) { return null; }
+    public void addCookie(Cookie cookie) {}
+    public boolean containsHeader(String name) { return false; }
+    public void setHeader(String name, String value) {}
+    public void setIntHeader(String name, int value) {}
+    public void setDateHeader(String name, long date) {}
+    public String encodeURL (String url) { return url; }
+    public void setLocale(Locale locale) { }
+    public Locale getLocale() { return null; }
+    public void addDateHeader(String name, long date) { }
+    public void addHeader(String name, String value) { }
+    public void addIntHeader(String name, int value) { }
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineSession.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineSession.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineSession.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/CommandLineSession.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,106 @@
+/*
+ * 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.environment.commandline;
+
+import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.environment.impl.AbstractSession;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+/**
+ *
+ * Command-line version of Http Session.
+ *
+ * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
+ * @version CVS $Id: CommandLineSession.java 170436 2005-05-16 19:50:25Z danielf $
+ */
+public final class CommandLineSession
+extends AbstractSession {
+
+    private long creationTime = System.currentTimeMillis();
+
+    private Hashtable attributes = new Hashtable();
+
+    public CommandLineSession() {
+    }
+
+    public long getCreationTime() {
+        return this.creationTime;
+    }
+
+    public String getId() {
+        return "1";
+    }
+
+    public long getLastAccessedTime() {
+        return this.creationTime;
+    }
+
+    public void setMaxInactiveInterval(int interval) {
+        // ignored
+    }
+
+    public int getMaxInactiveInterval() {
+        return -1;
+    }
+
+    public Object getAttribute(String name) {
+        return this.attributes.get(name);
+    }
+
+    public Enumeration getAttributeNames() {
+        return this.attributes.keys();
+    }
+
+    public void setAttribute(String name, Object value) {
+        this.attributes.put(name, value);
+    }
+
+    public void removeAttribute(String name) {
+        this.attributes.remove(name);
+    }
+
+    public void invalidate() {
+        this.attributes.clear();
+        invalidateSession();
+    }
+
+    public boolean isNew() {
+        return false;
+    }
+
+    protected static CommandLineSession session;
+
+    /**
+     * Get the current session object - if available
+     */
+    public static Session getSession(boolean create) {
+        if (create && session == null) {
+            session = new CommandLineSession();
+        }
+        return session;
+    }
+
+    /**
+     * Invalidate the current session
+     */
+    public static void invalidateSession() {
+        session = null;
+    }
+
+}
+

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,106 @@
+/*
+ * 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.environment.commandline;
+
+import org.apache.avalon.framework.logger.Logger;
+
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.environment.ObjectModelHelper;
+
+import java.io.File;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.util.Map;
+import java.util.List;
+
+/**
+ * This environment is used to save the requested file to disk.
+ *
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @author <a href="mailto:uv@upaya.co.uk">Upayavira</a>
+ * @version CVS $Id: FileSavingEnvironment.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class FileSavingEnvironment extends AbstractCommandLineEnvironment {
+
+    protected boolean modified = true;
+    protected long sourceLastModified = 0L;
+
+    public FileSavingEnvironment(String uri,
+                                 long lastModified,
+                                 File context,
+                                 Map attributes,
+                                 Map parameters,
+                                 Map links,
+                                 List gatheredLinks,
+                                 CommandLineContext cliContext,
+                                 OutputStream stream,
+                                 Logger log)
+    throws MalformedURLException {
+        super(uri, null, context, stream, log);
+        this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT,
+                             new CommandLineRequest(this, null, uri, null, attributes, parameters));
+        this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT,
+                             new CommandLineResponse());
+        this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT,
+                             cliContext);
+        this.sourceLastModified = lastModified;
+        if (links != null) {
+            this.objectModel.put(Constants.LINK_OBJECT, links);
+        }
+        if (gatheredLinks != null) {
+            this.objectModel.put(Constants.LINK_COLLECTION_OBJECT, gatheredLinks);
+        }
+    }
+    
+    public FileSavingEnvironment(String uri,
+                                 File context,
+                                 Map attributes,
+                                 Map parameters,
+                                 Map links,
+                                 List gatheredLinks,
+                                 CommandLineContext cliContext,
+                                 OutputStream stream,
+                                 Logger log)
+    throws MalformedURLException {
+        this(uri, 0L, context, attributes, parameters, links, gatheredLinks, cliContext, stream, log);
+    }
+
+    /**
+     * Check if the response has been modified since the same
+     * "resource" was requested.
+     * The caller has to test if it is really the same "resource"
+     * which is requested.
+     * @return true if the response is modified or if the
+     *         environment is not able to test it
+     */
+    public boolean isResponseModified(long cacheLastModified) {
+        if (cacheLastModified != 0) {
+            return cacheLastModified / 1000 > sourceLastModified / 1000;
+        }
+        return true;
+    }
+
+    /**
+     * Mark the response as not modified.
+     */
+    public void setResponseIsNotModified() {
+       this.modified = false;
+    }
+
+    public boolean isModified() {
+        return this.modified;
+    }
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,102 @@
+/*
+ * 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.environment.commandline;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.environment.ObjectModelHelper;
+
+/**
+ * This environment is sample the links of the resource.
+ *
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @version CVS $Id: LinkSamplingEnvironment.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+
+public class LinkSamplingEnvironment extends AbstractCommandLineEnvironment {
+
+    private boolean skip = false;
+
+    public LinkSamplingEnvironment(String uri,
+                                   File contextFile,
+                                   Map attributes,
+                                   Map parameters,
+                                   CommandLineContext cliContext,
+                                   Logger log)
+    throws MalformedURLException, IOException {
+        super(uri, Constants.LINK_VIEW, contextFile, new ByteArrayOutputStream(), log);
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("uri = " + uri);
+        }
+        this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT,
+                             new CommandLineRequest(this, null, uri, null, attributes, parameters));
+        this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT,
+                             new CommandLineResponse());
+        this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT,
+                             cliContext);
+    }
+
+    /**
+     * Set the ContentType
+     */
+    public void setContentType(String contentType) {
+        if (!Constants.LINK_CONTENT_TYPE.equals(contentType)) {
+            this.skip = true;
+        }
+    }
+
+    /**
+     * Indicates if other links are present.
+     */
+    public Collection getLinks() throws IOException {
+        HashSet set = new HashSet();
+        if (!skip) {
+            BufferedReader buffer = null;
+            try {
+                buffer = new BufferedReader(
+                        new InputStreamReader(
+                                new ByteArrayInputStream(
+                                        ((ByteArrayOutputStream) super.outputStream).toByteArray())));
+
+                String line;
+                while ((line = buffer.readLine()) !=null) {
+                    set.add(line);
+                }
+            } finally {
+                // explictly close the input
+                if (buffer != null) {
+                    try {
+                        buffer.close();
+                        buffer = null;
+                    } catch (IOException ignored) {
+                    }
+                }
+            }
+        }
+        return set;
+    }
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/ContextURLException.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/ContextURLException.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/ContextURLException.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/ContextURLException.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.environment.http;
+
+import org.apache.avalon.framework.CascadingRuntimeException;
+
+public final class ContextURLException extends CascadingRuntimeException
+{
+    public ContextURLException(String message)
+    {
+        super(message, null);
+    }
+
+    public ContextURLException(String message, Throwable cause)
+    {
+        super(message, cause);
+    }
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpContext.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpContext.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpContext.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpContext.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,146 @@
+/*
+ * 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.environment.http;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+
+import org.apache.cocoon.environment.impl.AbstractContext;
+
+/**
+ *
+ * Implements the {@link org.apache.cocoon.environment.Context} interface
+ * @author ?
+ * @version CVS $Id: HttpContext.java 292734 2005-09-30 13:55:41Z bloritsch $
+ */
+
+public final class HttpContext extends AbstractContext {
+
+    /** The ServletContext */
+    private final ServletContext servletContext;
+
+    /**
+     * Constructs a HttpContext object from a ServletContext object
+     */
+    public HttpContext (ServletContext servletContext) {
+        this.servletContext = servletContext;
+    }
+
+    public Object getAttribute(String name) {
+        return servletContext.getAttribute(name);
+    }
+
+    public void setAttribute(String name, Object value) {
+        servletContext.setAttribute(name, value);
+    }
+
+    public void removeAttribute(String name) {
+        servletContext.removeAttribute(name);
+    }
+
+    public Enumeration getAttributeNames() {
+        return servletContext.getAttributeNames();
+    }
+
+    public URL getResource(String path)
+       throws MalformedURLException {
+       return servletContext.getResource(path);
+    }
+
+    public InputStream getResourceAsStream(String path) {
+    return servletContext.getResourceAsStream(path);
+    }
+
+    public String getRealPath(String path) {
+        if (path.equals("/")) {
+            String value = servletContext.getRealPath(path);
+            if (value == null) {
+                // Try to figure out the path of the root from that of WEB-INF
+                try {
+                value = this.servletContext.getResource("/WEB-INF/web.xml").toString();
+                } catch (MalformedURLException mue) {
+                    throw new ContextURLException("Cannot determine the base URL for " + path, mue);
+                }
+                value = value.substring(0,value.length()-"WEB-INF/web.xml".length());
+            }
+            return value;
+        }
+        return servletContext.getRealPath(path);
+    }
+
+    public String getMimeType(String file) {
+      return servletContext.getMimeType(file);
+    }
+
+    public String getInitParameter(String name) {
+        return servletContext.getInitParameter(name);
+    }
+
+    /*
+     * These methods are not in Cocoon's Context interface, but in the
+     * ServletContext. To use them you have to downcast Cocoon's Context
+     * to this HttpContext until we decide to add them to the Context
+     * interface too.
+     * 
+     * The following methods are deprecated since Servlet API 2.0 or 2.1
+     * and will not be implemented here:
+     * - public Servlet getServlet(String name)
+     * - public Enumeration getServletNames()
+     * - public Enumeration getServlets()
+     * - public void log(Exception exception, String msg)
+     */
+
+    public ServletContext getContext(String uripath) {
+        return this.servletContext.getContext(uripath);
+    }
+
+    public Enumeration getInitParameterNames() {
+        return this.servletContext.getInitParameterNames();
+    }
+
+    public int getMajorVersion() {
+        return this.servletContext.getMajorVersion();
+    }
+
+    public int getMinorVersion() {
+        return this.servletContext.getMinorVersion();
+    }
+
+    public RequestDispatcher getNamedDispatcher(String name) {
+        return this.servletContext.getNamedDispatcher(name);
+    }
+
+    public RequestDispatcher getRequestDispatcher(String path) {
+        return this.servletContext.getRequestDispatcher(path);
+    }
+
+    public String getServerInfo() {
+        return this.servletContext.getServerInfo();
+    }
+
+    public void log(String msg) {
+        this.servletContext.log(msg);
+    }
+
+    public void log(String msg, Throwable throwable) {
+        this.servletContext.log(msg, throwable);
+    }
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpCookie.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpCookie.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpCookie.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpCookie.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,472 @@
+/*
+ * 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.environment.http;
+
+import org.apache.cocoon.environment.Cookie;
+
+/**
+ *
+ * Creates a cookie, a small amount of information sent by a servlet to
+ * a Web browser, saved by the browser, and later sent back to the server.
+ * A cookie's value can uniquely
+ * identify a client, so cookies are commonly used for session management.
+ *
+ * <p>A cookie has a name, a single value, and optional attributes
+ * such as a comment, path and domain qualifiers, a maximum age, and a
+ * version number. Some Web browsers have bugs in how they handle the
+ * optional attributes, so use them sparingly to improve the interoperability
+ * of your servlets.
+ *
+ * <p>The servlet sends cookies to the browser by using the
+ * {@link HttpResponse#addCookie(Cookie)} method, which adds
+ * fields to HTTP response headers to send cookies to the
+ * browser, one at a time. The browser is expected to
+ * support 20 cookies for each Web server, 300 cookies total, and
+ * may limit cookie size to 4 KB each.
+ *
+ * <p>The browser returns cookies to the servlet by adding
+ * fields to HTTP request headers. Cookies can be retrieved
+ * from a request by using the {@link HttpRequest#getCookies()} method.
+ * Several cookies might have the same name but different path attributes.
+ *
+ * <p>Cookies affect the caching of the Web pages that use them.
+ * HTTP 1.0 does not cache pages that use cookies created with
+ * this class. This class does not support the cache control
+ * defined with HTTP 1.1.
+ *
+ * <p>This class supports both the Version 0 (by Netscape) and Version 1
+ * (by RFC 2109) cookie specifications. By default, cookies are
+ * created using Version 0 to ensure the best interoperability.
+ *
+ *
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @version CVS $Id: HttpCookie.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ *
+ */
+
+public final class HttpCookie
+implements Cookie {
+
+    private javax.servlet.http.Cookie cookie;
+
+    public HttpCookie(String name, String value) {
+        this.cookie = new javax.servlet.http.Cookie(name, value);
+    }
+
+    public HttpCookie(javax.servlet.http.Cookie cookie) {
+        this.cookie = cookie;
+    }
+
+    public javax.servlet.http.Cookie getServletCookie() {
+        this.checkState();
+        return this.cookie;
+    }
+
+    /**
+     * Constructs a cookie with a specified name and value.
+     *
+     * <p>The name must conform to RFC 2109. That means it can contain
+     * only ASCII alphanumeric characters and cannot contain commas,
+     * semicolons, or white space or begin with a $ character. The cookie's
+     * name cannot be changed after creation.
+     *
+     * <p>The value can be anything the server chooses to send. Its
+     * value is probably of interest only to the server. The cookie's
+     * value can be changed after creation with the
+     * <code>setValue</code> method.
+     *
+     * <p>By default, cookies are created according to the Netscape
+     * cookie specification. The version can be changed with the
+     * <code>setVersion</code> method.
+     *
+     *
+     * @param name                         a <code>String</code> specifying the name of the cookie
+     *
+     * @param value                        a <code>String</code> specifying the value of the cookie
+     *
+     * @throws IllegalArgumentException        if the cookie name contains illegal characters
+     *                                        (for example, a comma, space, or semicolon)
+     *                                        or it is one of the tokens reserved for use
+     *                                        by the cookie protocol
+     * @see #setValue(String)
+     * @see #setVersion(int)
+     *
+     */
+
+    public void init(String name, String value) {
+        if (this.cookie == null) {
+            this.cookie = new javax.servlet.http.Cookie(name, value);
+        } else {
+            throw new IllegalStateException("Cookie is already initialised");
+        }
+    }
+
+
+    private void checkState() {
+        if (this.cookie == null) {
+            throw new IllegalStateException("Cookie is not initialised");
+        }
+    }
+
+    /**
+     *
+     * Specifies a comment that describes a cookie's purpose.
+     * The comment is useful if the browser presents the cookie
+     * to the user. Comments
+     * are not supported by Netscape Version 0 cookies.
+     *
+     * @param purpose                a <code>String</code> specifying the comment
+     *                                to display to the user
+     *
+     * @see #getComment()
+     *
+     */
+
+    public void setComment(String purpose) {
+        this.checkState();
+        this.cookie.setComment(purpose);
+    }
+
+
+
+
+    /**
+     * Returns the comment describing the purpose of this cookie, or
+     * <code>null</code> if the cookie has no comment.
+     *
+     * @return                        a <code>String</code> containing the comment,
+     *                                or <code>null</code> if none
+     *
+     * @see #setComment(String)
+     *
+     */
+
+    public String getComment() {
+        this.checkState();
+        return this.cookie.getComment();
+    }
+
+
+
+
+    /**
+     *
+     * Specifies the domain within which this cookie should be presented.
+     *
+     * <p>The form of the domain name is specified by RFC 2109. A domain
+     * name begins with a dot (<code>.foo.com</code>) and means that
+     * the cookie is visible to servers in a specified Domain Name System
+     * (DNS) zone (for example, <code>www.foo.com</code>, but not
+     * <code>a.b.foo.com</code>). By default, cookies are only returned
+     * to the server that sent them.
+     *
+     *
+     * @param pattern                a <code>String</code> containing the domain name
+     *                                within which this cookie is visible;
+     *                                form is according to RFC 2109
+     *
+     * @see #getDomain()
+     *
+     */
+
+    public void setDomain(String pattern) {
+        this.checkState();
+        this.cookie.setDomain(pattern);
+    }
+
+
+
+
+
+    /**
+     * Returns the domain name set for this cookie. The form of
+     * the domain name is set by RFC 2109.
+     *
+     * @return                        a <code>String</code> containing the domain name
+     *
+     * @see #setDomain(String)
+     *
+     */
+
+    public String getDomain() {
+        this.checkState();
+        return this.cookie.getDomain();
+    }
+
+
+
+
+    /**
+     * Sets the maximum age of the cookie in seconds.
+     *
+     * <p>A positive value indicates that the cookie will expire
+     * after that many seconds have passed. Note that the value is
+     * the <i>maximum</i> age when the cookie will expire, not the cookie's
+     * current age.
+     *
+     * <p>A negative value means
+     * that the cookie is not stored persistently and will be deleted
+     * when the Web browser exits. A zero value causes the cookie
+     * to be deleted.
+     *
+     * @param expiry                an integer specifying the maximum age of the
+     *                                 cookie in seconds; if negative, means
+     *                                the cookie is not stored; if zero, deletes
+     *                                the cookie
+     *
+     *
+     * @see #getMaxAge()
+     *
+     */
+
+    public void setMaxAge(int expiry) {
+        this.checkState();
+        this.cookie.setMaxAge(expiry);
+    }
+
+
+
+
+    /**
+     * Returns the maximum age of the cookie, specified in seconds,
+     * By default, <code>-1</code> indicating the cookie will persist
+     * until browser shutdown.
+     *
+     *
+     * @return                        an integer specifying the maximum age of the
+     *                                cookie in seconds; if negative, means
+     *                                the cookie persists until browser shutdown
+     *
+     *
+     * @see #setMaxAge(int)
+     *
+     */
+
+    public int getMaxAge() {
+        this.checkState();
+        return this.cookie.getMaxAge();
+    }
+
+
+
+
+    /**
+     * Specifies a path for the cookie
+     * to which the client should return the cookie.
+     *
+     * <p>The cookie is visible to all the pages in the directory
+     * you specify, and all the pages in that directory's subdirectories.
+     * A cookie's path must include the servlet that set the cookie,
+     * for example, <i>/catalog</i>, which makes the cookie
+     * visible to all directories on the server under <i>/catalog</i>.
+     *
+     * <p>Consult RFC 2109 (available on the Internet) for more
+     * information on setting path names for cookies.
+     *
+     *
+     * @param uri                a <code>String</code> specifying a path
+     *
+     *
+     * @see #getPath()
+     *
+     */
+
+    public void setPath(String uri) {
+        this.checkState();
+        this.cookie.setPath(uri);
+    }
+
+
+
+
+    /**
+     * Returns the path on the server
+     * to which the browser returns this cookie. The
+     * cookie is visible to all subpaths on the server.
+     *
+     *
+     * @return                a <code>String</code> specifying a path that contains
+     *                        a servlet name, for example, <i>/catalog</i>
+     *
+     * @see #setPath(String)
+     *
+     */
+
+    public String getPath() {
+        this.checkState();
+        return this.cookie.getPath();
+    }
+
+
+
+
+
+    /**
+     * Indicates to the browser whether the cookie should only be sent
+     * using a secure protocol, such as HTTPS or SSL.
+     *
+     * <p>The default value is <code>false</code>.
+     *
+     * @param flag        if <code>true</code>, sends the cookie from the browser
+     *                        to the server using only when using a secure protocol;
+     *                        if <code>false</code>, sent on any protocol
+     *
+     * @see #getSecure()
+     *
+     */
+
+    public void setSecure(boolean flag) {
+        this.checkState();
+        this.cookie.setSecure(flag);
+    }
+
+
+
+
+    /**
+     * Returns <code>true</code> if the browser is sending cookies
+     * only over a secure protocol, or <code>false</code> if the
+     * browser can send cookies using any protocol.
+     *
+     * @return                <code>true</code> if the browser can use
+     *                        any standard protocol; otherwise, <code>false</code>
+     *
+     * @see #setSecure(boolean)
+     *
+     */
+
+    public boolean getSecure() {
+        this.checkState();
+        return this.cookie.getSecure();
+    }
+
+
+
+
+
+    /**
+     * Returns the name of the cookie. The name cannot be changed after
+     * creation.
+     *
+     * @return                a <code>String</code> specifying the cookie's name
+     *
+     */
+
+    public String getName() {
+        this.checkState();
+        return this.cookie.getName();
+    }
+
+
+
+
+
+    /**
+     *
+     * Assigns a new value to a cookie after the cookie is created.
+     * If you use a binary value, you may want to use BASE64 encoding.
+     *
+     * <p>With Version 0 cookies, values should not contain white
+     * space, brackets, parentheses, equals signs, commas,
+     * double quotes, slashes, question marks, at signs, colons,
+     * and semicolons. Empty values may not behave the same way
+     * on all browsers.
+     *
+     * @param newValue                a <code>String</code> specifying the new value
+     *
+     *
+     * @see #getValue()
+     * @see Cookie
+     *
+     */
+
+    public void setValue(String newValue) {
+        this.checkState();
+        this.cookie.setValue(newValue);
+    }
+
+
+
+
+    /**
+     * Returns the value of the cookie.
+     *
+     * @return                        a <code>String</code> containing the cookie's
+     *                                present value
+     *
+     * @see #setValue(String)
+     * @see Cookie
+     *
+     */
+
+    public String getValue() {
+        this.checkState();
+        return this.cookie.getValue();
+    }
+
+
+
+
+    /**
+     * Returns the version of the protocol this cookie complies
+     * with. Version 1 complies with RFC 2109,
+     * and version 0 complies with the original
+     * cookie specification drafted by Netscape. Cookies provided
+     * by a browser use and identify the browser's cookie version.
+     *
+     *
+     * @return                        0 if the cookie complies with the
+     *                                original Netscape specification; 1
+     *                                if the cookie complies with RFC 2109
+     *
+     * @see #setVersion(int)
+     *
+     */
+
+    public int getVersion() {
+        this.checkState();
+        return this.cookie.getVersion();
+    }
+
+
+
+
+    /**
+     * Sets the version of the cookie protocol this cookie complies
+     * with. Version 0 complies with the original Netscape cookie
+     * specification. Version 1 complies with RFC 2109.
+     *
+     * <p>Since RFC 2109 is still somewhat new, consider
+     * version 1 as experimental; do not use it yet on production sites.
+     *
+     *
+     * @param v                        0 if the cookie should comply with
+     *                                the original Netscape specification;
+     *                                1 if the cookie should comply with RFC 2109
+     *
+     * @see #getVersion()
+     *
+     */
+
+    public void setVersion(int v) {
+        this.checkState();
+        this.cookie.setVersion(v);
+    }
+
+
+
+}
+

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpEnvironment.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpEnvironment.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpEnvironment.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,223 @@
+/*
+ * 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.environment.http;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cocoon.environment.AbstractEnvironment;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.util.NetUtils;
+
+/**
+ * HTTP Servlet environment.
+ *
+ * @author <a herf="mailto:dev@cocoon.apache.org">Apache Cocoon Team</a>
+ * @version CVS $Id: HttpEnvironment.java 164219 2005-04-22 11:03:32Z cziegeler $
+ */
+public class HttpEnvironment extends AbstractEnvironment {
+
+    public static final String HTTP_REQUEST_OBJECT = "httprequest";
+    public static final String HTTP_RESPONSE_OBJECT= "httpresponse";
+    public static final String HTTP_SERVLET_CONTEXT= "httpservletcontext";
+
+    /** The HttpRequest */
+    private HttpRequest request;
+
+    /** The HttpResponse */
+    private HttpResponse response;
+
+    /** Cache content type as there is no getContentType() in reponse object */
+    private String contentType;
+
+    /**
+     * Constructs a HttpEnvironment object from a HttpServletRequest
+     * and HttpServletResponse objects
+     */
+    public HttpEnvironment(String uri,
+                           String root,
+                           HttpServletRequest req,
+                           HttpServletResponse res,
+                           ServletContext servletContext,
+                           Context context,
+                           String containerEncoding,
+                           String defaultFormEncoding)
+    throws IOException {
+        super(uri, null, null);
+
+        this.request = new HttpRequest(req, this);
+        this.request.setCharacterEncoding(defaultFormEncoding);
+        this.request.setContainerEncoding(containerEncoding);
+        this.response = new HttpResponse(res);
+
+        setView(extractView(this.request));
+        setAction(extractAction(this.request));
+
+        this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT, this.request);
+        this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT, this.response);
+        this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT, context);
+
+        // This is a kind of a hack for the components that need
+        // the real servlet objects to pass them along to other
+        // libraries.
+        this.objectModel.put(HTTP_REQUEST_OBJECT, req);
+        this.objectModel.put(HTTP_RESPONSE_OBJECT, res);
+        this.objectModel.put(HTTP_SERVLET_CONTEXT, servletContext);
+    }
+
+    /**
+     *  Redirect the client to new URL
+     */
+    public void redirect(String newURL,
+                         boolean global,
+                         boolean permanent)
+    throws IOException {
+        // Redirect
+        String redirect = this.response.encodeRedirectURL(newURL);
+
+        // FIXME (VG): WebSphere 4.0/4.0.1 bug
+        if (!newURL.startsWith("/") && newURL.indexOf(':') == -1 && redirect.indexOf(':') != -1) {
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Redirect: WebSphere Bug Detected!");
+            }
+            String base = NetUtils.getPath(request.getRequestURI());
+            if (base.startsWith("/")) {
+                base = base.substring(1);
+            }
+            redirect = response.encodeRedirectURL(base + '/' + newURL);
+        }
+
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Sending redirect to '" + redirect + "'");
+        }
+
+        if (permanent) {
+            this.response.sendPermanentRedirect(redirect);
+        } else {
+            this.response.sendRedirect(redirect);
+        }
+    }
+
+    /**
+     * Set the StatusCode
+     */
+    public void setStatus(int statusCode) {
+        this.response.setStatus(statusCode);
+    }
+
+    /**
+     * Set the ContentType
+     */
+    public void setContentType(String contentType) {
+        this.response.setContentType(contentType);
+        this.contentType = contentType;
+    }
+
+    /**
+     * Get the ContentType
+     */
+    public String getContentType() {
+        return this.contentType;
+    }
+
+    /**
+     * Set the length of the generated content
+     */
+    public void setContentLength(int length) {
+        this.response.setContentLength(length);
+    }
+
+    /**
+     * Check if the response has been modified since the same
+     * "resource" was requested.
+     * The caller has to test if it is really the same "resource"
+     * which is requested.
+     * @return true if the response is modified or if the
+     *         environment is not able to test it
+     */
+    public boolean isResponseModified(long lastModified) {
+        if (lastModified != 0) {
+            long if_modified_since = this.request.getDateHeader("If-Modified-Since");
+            this.response.setDateHeader("Last-Modified", lastModified);
+            return (if_modified_since / 1000 < lastModified  / 1000);
+        }
+        return true;
+    }
+
+    /**
+     * Mark the response as not modified.
+     */
+    public void setResponseIsNotModified() {
+        this.response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+    }
+
+    /**
+     * Reset the response if possible. This allows error handlers to have
+     * a higher chance to produce clean output if the pipeline that raised
+     * the error has already output some data.
+     *
+     * @return true if the response was successfully reset
+     */
+    public boolean tryResetResponse()
+    throws IOException {
+        if (!super.tryResetResponse()) {
+            try {
+                if (!this.response.isCommitted()) {
+                    this.response.reset();
+                    if (getLogger().isDebugEnabled()) {
+                        getLogger().debug("Response successfully reset");
+                    }
+                    return true;
+                }
+            } catch (Exception e) {
+                // Log the error, but don't transmit it
+                getLogger().warn("Problem resetting response", e);
+            }
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Response wasn't reset");
+            }
+            return false;
+        }
+        return true;
+    }
+
+
+    /**
+     * Get the output stream where to write the generated resource.
+     * The returned stream is buffered by the environment. If the
+     * buffer size is -1 then the complete output is buffered.
+     * If the buffer size is 0, no buffering takes place.
+     */
+    public OutputStream getOutputStream(final int bufferSize)
+    throws IOException {
+        if (this.outputStream == null) {
+            this.outputStream = this.response.getOutputStream();
+        }
+        return super.getOutputStream(bufferSize);
+    }
+
+    /**
+     * Always return <code>true</code>.
+     */
+    public boolean isExternal() {
+        return true;
+    }
+}

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

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpRequest.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpRequest.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpRequest.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/http/HttpRequest.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,491 @@
+/*
+ * 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.environment.http;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Vector;
+import java.util.WeakHashMap;
+import java.lang.ref.WeakReference;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.cocoon.environment.Cookie;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.environment.impl.AbstractRequest;
+import org.apache.cocoon.servlet.multipart.MultipartHttpServletRequest;
+import org.apache.commons.collections.IteratorUtils;
+
+/**
+ * Implements the {@link org.apache.cocoon.environment.Request} interface
+ * to provide request information in the HTTP servlets environment.
+ *
+ * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
+ * @version $Id: HttpRequest.java 292734 2005-09-30 13:55:41Z bloritsch $
+ */
+public final class HttpRequest extends AbstractRequest {
+
+    /** The real HttpServletRequest object */
+    private final HttpServletRequest req;
+
+    /** The HttpEnvironment object */
+    private final HttpEnvironment env;
+
+    /** The character encoding of parameters */
+    private String form_encoding;
+
+    /** The default form encoding of the servlet container */
+    private String container_encoding;
+
+    /**
+     * The map to assure 1:1-mapping of server sessions and Cocoon session wrappers
+     */
+    private static final Map sessions = new WeakHashMap();
+
+    private final Map attributes = new HashMap();
+
+    /**
+     * Creates a HttpRequest based on a real HttpServletRequest object
+     */
+    protected HttpRequest(HttpServletRequest req, HttpEnvironment env) {
+        super();
+        this.req = req;
+        this.env = env;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#get(java.lang.String)
+     */
+    public Object get(String name) {
+        // if the request has been wrapped then access its method
+        if (req instanceof MultipartHttpServletRequest) {
+            return ((MultipartHttpServletRequest) req).get(name);
+        }
+        String[] values = req.getParameterValues(name);
+        if (values == null) {
+            return null;
+        }
+        if (values.length == 1) {
+            return values[0];
+        }
+        if (values.length > 1) {
+            Vector vect = new Vector(values.length);
+            for (int i = 0; i < values.length; i++) {
+                vect.add(values[i]);
+            }
+            return vect;
+        }
+        return null;
+    }
+
+    /* The HttpServletRequest interface methods */
+
+    public String getAuthType() {
+        return this.req.getAuthType();
+    }
+
+    private Cookie[] wrappedCookies = null;
+    private Map wrappedCookieMap = null;
+
+    public Cookie[] getCookies() {
+        if (this.wrappedCookieMap == null) {
+            wrapCookies();
+        }
+        return this.wrappedCookies;
+    }
+
+    public Map getCookieMap() {
+        if (this.wrappedCookieMap == null) {
+            wrapCookies();
+        }
+        return this.wrappedCookieMap;
+    }
+
+    private synchronized void wrapCookies() {
+        this.wrappedCookieMap = new HashMap();
+        javax.servlet.http.Cookie[] cookies = this.req.getCookies();
+        if (cookies != null) {
+            this.wrappedCookies = new Cookie[cookies.length];
+            for(int i=0; i<cookies.length;i++) {
+                HttpCookie cookie = new HttpCookie(cookies[i]);
+                this.wrappedCookies[i] = cookie;
+                this.wrappedCookieMap.put(cookie.getName(),cookie);
+            }
+        }
+        this.wrappedCookieMap = Collections.unmodifiableMap(this.wrappedCookieMap);
+    }
+
+    public long getDateHeader(String name) {
+        return this.req.getDateHeader(name);
+    }
+
+    public String getHeader(String name) {
+        return this.req.getHeader(name);
+    }
+
+    public Enumeration getHeaders(String name) {
+        return this.req.getHeaders(name);
+    }
+
+    public Enumeration getHeaderNames() {
+        return this.req.getHeaderNames();
+    }
+
+    public int getIntHeader(String name) {
+        return this.req.getIntHeader(name);
+    }
+
+    public String getMethod() {
+        return this.req.getMethod();
+    }
+
+    public String getPathInfo() {
+        return this.req.getPathInfo();
+    }
+
+    public String getPathTranslated() {
+        return this.req.getPathTranslated();
+    }
+
+    public String getContextPath() {
+        return this.req.getContextPath();
+    }
+
+    public String getQueryString() {
+        return this.req.getQueryString();
+    }
+
+    public String getRemoteUser() {
+        return this.req.getRemoteUser();
+    }
+
+    public boolean isUserInRole(String role) {
+        return this.req.isUserInRole(role);
+    }
+
+    public java.security.Principal getUserPrincipal() {
+        return this.req.getUserPrincipal();
+    }
+
+    public String getRequestedSessionId() {
+        return this.req.getRequestedSessionId();
+    }
+
+    protected String reqURI;
+
+    public String getRequestURI() {
+        if (this.reqURI == null) {
+            this.reqURI = this.req.getRequestURI();
+            if ( this.reqURI.equals("/") ) {
+                String s = this.req.getServletPath();
+                final StringBuffer buffer = new StringBuffer();
+                if ( null != s ) buffer.append(s);
+                s = this.req.getPathInfo();
+                if ( null != s ) buffer.append(s);
+                this.reqURI = buffer.toString();
+            }
+        }
+        return this.reqURI;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getSitemapURI()
+     */
+    public String getSitemapURI() {
+        return this.env.getURI();
+    }
+
+    public String getSitemapURIPrefix() {
+        return this.env.getURIPrefix();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getSitemapPath()
+     */
+    public String getSitemapPath() {
+        return this.env.getURIPrefix();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getServletPath()
+     */
+    public String getServletPath() {
+        return this.req.getServletPath();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getSession(boolean)
+     */
+    public Session getSession(boolean create) {
+        javax.servlet.http.HttpSession serverSession = this.req.getSession(create);
+        HttpSession session;
+        if (serverSession != null)
+        {
+            synchronized (sessions)
+            {
+                // retrieve existing wrapper
+                WeakReference ref = (WeakReference) sessions.get(serverSession);
+                if (ref == null || (session = (HttpSession) ref.get()) == null)
+                {
+                    // create new wrapper
+                    session = new HttpSession(serverSession);
+                    sessions.put(serverSession, new WeakReference(session));
+                }
+            }
+        }
+        else
+        {
+            // invalidate
+            session = null;
+        }
+        return session;
+    }
+
+    public Session getSession() {
+        return this.getSession(true);
+    }
+
+    public boolean isRequestedSessionIdValid() {
+        return this.req.isRequestedSessionIdValid();
+    }
+
+    public boolean isRequestedSessionIdFromCookie()  {
+        return this.req.isRequestedSessionIdFromCookie();
+    }
+
+    public boolean isRequestedSessionIdFromURL() {
+        return this.req.isRequestedSessionIdFromURL();
+    }
+
+    /**
+     * @deprecated As of Version 2.1 of the Java Servlet API, use
+     *             {@link #isRequestedSessionIdFromURL()} instead.
+     */
+    public boolean isRequestedSessionIdFromUrl() {
+        return this.req.isRequestedSessionIdFromURL();
+    }
+
+    /* The ServletRequest interface methods */
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getAttribute(java.lang.String)
+     */
+    public Object getAttribute(String name) {
+        return this.getAttribute(name, Request.GLOBAL_SCOPE);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getAttributeNames()
+     */
+    public Enumeration getAttributeNames() {
+        return this.getAttributeNames(Request.GLOBAL_SCOPE);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#setAttribute(java.lang.String, java.lang.Object)
+     */
+    public void setAttribute(String name, Object value) {
+        this.setAttribute(name, value, Request.GLOBAL_SCOPE);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#removeAttribute(java.lang.String)
+     */
+    public void removeAttribute(String name) {
+        this.removeAttribute(name, Request.GLOBAL_SCOPE);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getAttribute(java.lang.String, int)
+     */
+    public Object getAttribute(String name, int scope) {
+        if ( scope == Request.REQUEST_SCOPE ) {
+            return this.attributes.get(name);
+        }
+        return this.req.getAttribute(name);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#getAttributeNames(int)
+     */
+    public Enumeration getAttributeNames(int scope) {
+        if ( scope == Request.REQUEST_SCOPE ) {
+            return IteratorUtils.asEnumeration(this.attributes.keySet().iterator());
+        }
+        return this.req.getAttributeNames();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#setAttribute(java.lang.String, java.lang.Object, int)
+     */
+    public void setAttribute(String name, Object value, int scope) {
+        if ( scope == Request.REQUEST_SCOPE ) {
+            this.attributes.put(name, value);
+        } else {
+            this.req.setAttribute(name, value);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.environment.Request#removeAttribute(java.lang.String, int)
+     */
+    public void removeAttribute(String name, int scope) {
+        if ( scope == Request.REQUEST_SCOPE ) {
+            this.attributes.remove(name);
+        } else {
+            this.req.removeAttribute(name);
+        }
+    }
+
+    public String getCharacterEncoding() {
+        if (this.form_encoding == null) {
+            return this.req.getCharacterEncoding();
+        }
+        return this.form_encoding;
+    }
+
+    public void setCharacterEncoding(String form_encoding)
+    throws java.io.UnsupportedEncodingException {
+        this.form_encoding = form_encoding;
+    }
+
+    /**
+     * Sets the default encoding of the servlet container.
+     */
+    public void setContainerEncoding(String container_encoding) {
+        this.container_encoding = container_encoding;
+    }
+
+    public int getContentLength() {
+        return this.req.getContentLength();
+    }
+
+    public String getContentType() {
+        return this.req.getContentType();
+    }
+
+    public InputStream getInputStream() throws IOException {
+        return this.req.getInputStream();
+    }
+
+    public String getParameter(String name) {
+        String value = this.req.getParameter(name);
+        if (this.form_encoding == null || value == null) {
+            return value;
+        }
+        return decode(value);
+    }
+
+    private String decode(String str) {
+        if (str == null) return null;
+        try {
+            if (this.container_encoding == null)
+                this.container_encoding = "ISO-8859-1";
+            byte[] bytes = str.getBytes(this.container_encoding);
+            return new String(bytes, form_encoding);
+        } catch (java.io.UnsupportedEncodingException uee) {
+            throw new RequestEncodingException("Unsupported Encoding Exception", uee);
+        }
+    }
+
+    public Enumeration getParameterNames() {
+        return this.req.getParameterNames();
+    }
+
+    public String[] getParameterValues(String name) {
+        String[] values = this.req.getParameterValues(name);
+        if (values == null) return null;
+        if (this.form_encoding == null) {
+            return values;
+        }
+        String[] decoded_values = new String[values.length];
+        for (int i = 0; i < values.length; ++i) {
+            decoded_values[i] = decode(values[i]);
+        }
+        return decoded_values;
+    }
+
+    public String getProtocol() {
+        return this.req.getProtocol();
+    }
+
+    public String getScheme() {
+        return this.req.getScheme();
+    }
+
+    public String getServerName() {
+        return this.req.getServerName();
+    }
+
+    public int getServerPort() {
+        return this.req.getServerPort();
+    }
+
+    public BufferedReader getReader() throws IOException {
+        return this.req.getReader();
+    }
+
+    public String getRemoteAddr() {
+        return this.req.getRemoteAddr();
+    }
+
+    public String getRemoteHost() {
+        return this.req.getRemoteHost();
+    }
+
+    public Locale getLocale() {
+        return this.req.getLocale();
+    }
+
+    public Enumeration getLocales() {
+        return this.req.getLocales();
+    }
+
+    public boolean isSecure() {
+        return this.req.isSecure();
+    }
+
+    public RequestDispatcher getRequestDispatcher(String path) {
+        return this.req.getRequestDispatcher(path);
+    }
+
+    /**
+     * @deprecated As of Version 2.1 of the Java Servlet API, use
+     * {@link javax.servlet.ServletContext#getRealPath(java.lang.String)}instead.
+     */
+    public String getRealPath(String path) {
+        return this.req.getRealPath(path);
+    }
+
+    /**
+     * @see org.apache.cocoon.environment.Request#searchAttribute(java.lang.String)
+     */
+    public Object searchAttribute(String name) {
+        Object result = this.getAttribute(name, REQUEST_SCOPE);
+        if ( result == null ) {
+            result = this.getAttribute(name, GLOBAL_SCOPE);
+        }
+        return result;
+    }
+}

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



Mime
View raw message