Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 40056 invoked from network); 3 Nov 2005 14:57:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Nov 2005 14:57:54 -0000 Received: (qmail 29694 invoked by uid 500); 3 Nov 2005 14:38:18 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 28027 invoked by uid 500); 3 Nov 2005 14:37:08 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 26235 invoked by uid 99); 3 Nov 2005 14:35:44 -0000 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 03 Nov 2005 06:35:16 -0800 Received: (qmail 12363 invoked by uid 65534); 3 Nov 2005 14:34:46 -0000 Message-ID: <20051103143446.12352.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r330548 [41/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 -0000 To: cvs@cocoon.apache.org From: jheymans@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/ForwardRedirector.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/ForwardRedirector.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/ForwardRedirector.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/ForwardRedirector.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,161 @@ +/* + * 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; + +import java.io.IOException; + +import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.apache.cocoon.ProcessingException; + +/** + * A base class for Redirectors that handle forward redirects, i.e. internal + * redirects using the "cocoon:" pseudo-protocol. + *

+ * Concrete subclasses have to define the cocoonRedirect() method. + * + * @author Sylvain Wallez + * @version CVS $Id: ForwardRedirector.java 30941 2004-07-29 19:56:58Z vgritsenko $ + */ +public abstract class ForwardRedirector +extends AbstractLogEnabled +implements Redirector, PermanentRedirector { + + /** + * Was there a call to redirect() ? + */ + private boolean hasRedirected = false; + + /** The Environment to use for redirection (either internal or external) */ + protected Environment env; + + /** + * Constructor + */ + public ForwardRedirector(Environment env) { + this.env = env; + } + + /** + * Redirects to a given URL. If this URL starts with "cocoon:", then an internal + * redirect is performed. Otherwise, an external redirect is send to the + * environment. + */ + public void redirect(boolean sessionMode, String url) throws IOException, ProcessingException { + if (getLogger().isInfoEnabled()) { + getLogger().info("Redirecting to '" + url + "'"); + } + + if (url.startsWith("cocoon:")) { + cocoonRedirect(url); + } else { + this.doRedirect(sessionMode, url, false, false); + } + + this.hasRedirected = true; + } + + public void permanentRedirect(boolean sessionMode, String url) throws IOException, ProcessingException { + if (getLogger().isInfoEnabled()) { + getLogger().info("Redirecting to '" + url + "'"); + } + + if (url.startsWith("cocoon:")) { + cocoonRedirect(url); + } else { + this.doRedirect(sessionMode, url, true, false); + } + + this.hasRedirected = true; + } + + /** + * Unconditionally redirects to a given URL, even it this redirector is part of a + * subpipeline. + */ + public void globalRedirect(boolean sessionMode, String url) throws IOException, ProcessingException { + if (getLogger().isInfoEnabled()) { + getLogger().info("Redirecting to '" + url + "'"); + } + + // FIXME : how to handle global redirect to cocoon: ? + if (url.startsWith("cocoon:")) { + cocoonRedirect(url); + } else { + this.doRedirect(sessionMode, url, false, true); + } + this.hasRedirected = true; + } + + protected abstract void cocoonRedirect(String uri) throws IOException, ProcessingException; + + /* (non-Javadoc) + * @see org.apache.cocoon.environment.Redirector#hasRedirected() + */ + public boolean hasRedirected() { + return this.hasRedirected; + } + + /* (non-Javadoc) + * @see org.apache.cocoon.environment.Redirector#sendStatus(int) + */ + public void sendStatus(int sc) { + env.setStatus(sc); + this.hasRedirected = true; + } + + + /** + * Redirect the client to new URL with session mode + */ + protected void doRedirect(boolean sessionmode, + String newURL, + boolean permanent, + boolean global) + throws IOException { + final Request request = ObjectModelHelper.getRequest(this.env.getObjectModel()); + // check if session mode shall be activated + if (sessionmode) { + + // The session + Session session = null; + if (getLogger().isDebugEnabled()) { + getLogger().debug("redirect: entering session mode"); + } + String s = request.getRequestedSessionId(); + if (s != null) { + if (getLogger().isDebugEnabled()) { + getLogger().debug("Old session ID found in request, id = " + s); + if ( request.isRequestedSessionIdValid() ) { + getLogger().debug("And this old session ID is valid"); + } + } + } + // get session from request, or create new session + session = request.getSession(true); + if (session == null) { + if (getLogger().isDebugEnabled()) { + getLogger().debug("redirect session mode: unable to get session object!"); + } + } + if (getLogger().isDebugEnabled()) { + getLogger().debug ("redirect: session mode completed, id = " + session.getId() ); + } + } + // redirect + this.env.redirect(newURL, global, permanent); + } + +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/ForwardRedirector.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/ObjectModelHelper.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/ObjectModelHelper.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/ObjectModelHelper.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/ObjectModelHelper.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,84 @@ +/* + * 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; + +import java.util.Map; + +/** + * A set of constants and methods to access the content of the object model. + *

+ * The object model is a Map used to pass information about the + * calling environment to the sitemap and its components (matchers, actions, + * transformers, etc). + *

+ * This class provides accessors only for the objects in the object model that are + * common to every environment and which can thus be used safely. Some environments + * provide additional objects, but they are not described here and accessing them + * should be done in due cause since this ties the application to that particular + * environment. + * + * @author Sylvain Wallez + * @version CVS $Id: ObjectModelHelper.java 312663 2005-10-10 15:05:55Z sylvain $ + */ + +public final class ObjectModelHelper { + + /** Key for the environment {@link Request} in the object model. */ + public final static String REQUEST_OBJECT = "request"; + + /** Key for the environment {@link Response} in the object model. */ + public final static String RESPONSE_OBJECT = "response"; + + /** Key for the environment {@link Context} in the object model. */ + public final static String CONTEXT_OBJECT = "context"; + + /** Key for the expiration value (Long) in the object model. */ + public final static String EXPIRES_OBJECT = "expires"; + + /** Key for the throwable object, only available within a <map:handle-errors>. */ + public final static String THROWABLE_OBJECT = "throwable"; + + /** + * Key for a {@link Map} containing information from + * a parent request provided to a sub-request (internal processing) + */ + public final static String PARENT_CONTEXT = "parent-context"; + + + private ObjectModelHelper() { + // Forbid instantiation + } + + public static final Request getRequest(Map objectModel) { + return (Request)objectModel.get(REQUEST_OBJECT); + } + + public static final Response getResponse(Map objectModel) { + return (Response)objectModel.get(RESPONSE_OBJECT); + } + + public static final Context getContext(Map objectModel) { + return (Context)objectModel.get(CONTEXT_OBJECT); + } + + public static final Long getExpires(Map objectModel) { + return (Long)objectModel.get(EXPIRES_OBJECT); + } + + public static final Throwable getThrowable(Map objectModel) { + return (Throwable)objectModel.get(THROWABLE_OBJECT); + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/ObjectModelHelper.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/PermanentRedirector.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/PermanentRedirector.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/PermanentRedirector.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/PermanentRedirector.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,35 @@ +/* + * 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; + +import org.apache.cocoon.ProcessingException; +import java.io.IOException; + +/** + * Interface for a permanent redirector abstraction + * + * @author Upayavira + * @version CVS $Id: PermanentRedirector.java 30941 2004-07-29 19:56:58Z vgritsenko $ + */ + +public interface PermanentRedirector { + + /** + * Redirect to the given URL + */ + void permanentRedirect(boolean sessionmode, String url) throws IOException, ProcessingException; + } + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/PermanentRedirector.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Redirector.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Redirector.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Redirector.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Redirector.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,48 @@ +/* + * 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; + +import org.apache.cocoon.ProcessingException; +import java.io.IOException; + +/** + * Interface for an redirector abstraction + * + * @author Davanum Srinivas + * @version CVS $Id: Redirector.java 30941 2004-07-29 19:56:58Z vgritsenko $ + */ + +public interface Redirector { + + /** + * Redirect to the given URL + */ + void redirect(boolean sessionmode, String url) throws IOException, ProcessingException; + void globalRedirect(boolean sessionmode, String url) throws IOException, ProcessingException; + + /** + * Was one of the redirection methods called ? + */ + boolean hasRedirected(); + + /** + * Send a content-less response with the given status code. + * + * @param sc an http status code. + */ + void sendStatus(int sc); +} + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Redirector.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Request.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Request.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Request.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Request.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,994 @@ +/* + * 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; + +import java.io.IOException; +import java.io.InputStream; +import java.security.Principal; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; + +/** + * Defines an interface to provide client request information . + * + * A client can bind an object attribute into a Request by name. + * The Request interface defines two scopes for storing objects: + *

    + *
  • GLOBAL_SCOPE + *
  • REQUEST_SCOPE + *
+ * All objects stored in the request using the GLOBAL_SCOPE + * are available to all sub requests and the main request associatiated + * Objects stored in the request using the REQUEST_SCOPE are + * only available for the current (sub) request. + * + * @author Davanum Srinivas + * @author Carsten Ziegeler + * @author Berin Loritsch + * @version $Id: Request.java 202268 2005-06-28 19:03:15Z vgritsenko $ + */ +public interface Request { + + /** + * This constant defines an request wide scope for the request attribute. + * @since 2.2 + */ + public static final int GLOBAL_SCOPE = 1; + + /** + * This constant defines the scope of the request attribute to be + * private to the current (sub) request. + * @since 2.2 + */ + public static final int REQUEST_SCOPE = 2; + + /** + * + * Returns the value of the named parameter as an Object, + * or null if no parameter of the given name exists. + * Basically, this method is similar to {@link #getParameter(String)}, + * but it returns an object instead. + * This is useful when special processing has been made on these parameters, + * for example for file uploads. In this case you get an object + * representing the uploaded file. + * If the parameters have not been processed, you either get a String + * object if the parameter has one value, or a Collection of Strings + * if the parameter has more than one value. + * + * @param name a String specifying the name of + * the parameter + * + * @return an Object containing the value + * of the parameter, or null if + * the parameter does not exist + * + */ + + Object get(String name); + + /** + * + * Returns the value of the named attribute from the GLOBAL_SCOPE + * as an Object, or null if no attribute + * of the given name exists. + * + * @param name a String specifying the name of + * the attribute + * + * @return an Object containing the value + * of the attribute, or null if + * the attribute does not exist + * + */ + Object getAttribute(String name); + + /** + * Returns an Enumeration containing the + * names of the attributes available to this request in the GLOBAL_SCOPE. + * This method returns an empty Enumeration + * if the request has no attributes available to it. + * + * + * @return an Enumeration of strings + * containing the names + * of the request's attributes + * + */ + Enumeration getAttributeNames(); + + /** + * + * Stores an attribute in this request in the GLOBAL_SCOPE. + * Attributes are reset between requests. + * + *

Attribute names should follow the same conventions as + * package names. Names beginning with java.*, + * javax.*, and com.sun.*, are + * reserved for use by Sun Microsystems. + * + * + * @param name a String specifying + * the name of the attribute + * + * @param o the Object to be stored + * + */ + void setAttribute(String name, Object o); + + /** + * + * Removes an attribute from this request in the GLOBAL_SCOPE. + * This method is not + * generally needed as attributes only persist as long as the request + * is being handled. + * + *

Attribute names should follow the same conventions as + * package names. Names beginning with java.*, + * javax.*, and com.sun.*, are + * reserved for use by Sun Microsystems. + * + * + * @param name a String specifying + * the name of the attribute to remove + * + */ + void removeAttribute(String name); + + /** + * Returns the value of the named attribute from the scope + * as an Object, or null if no attribute + * of the given name exists. + * + * @param name a String specifying the name of + * the attribute + * @param scope scope (global or request) of the attribute + * + * @return an Object containing the value + * of the attribute, or null if + * the attribute does not exist + * + * @since 2.2 + */ + Object getAttribute(String name, int scope); + + /** + * Returns the value of the named attribute searching both scopes + * as an Object, or null if no attribute + * of the given name exists. This method first searches in the + * request scope and then, if no object is found, in the global scope. + * + * @param name a String specifying the name of + * the attribute + * + * @return an Object containing the value + * of the attribute, or null if + * the attribute does not exist + * + * @since 2.2 + */ + Object searchAttribute(String name); + + /** + * Returns an Enumeration containing the + * names of the attributes available to this request in the scope. + * This method returns an empty Enumeration + * if the request has no attributes available to it. + * + * @param scope scope (global or request) of the attribute + * + * @return an Enumeration of strings + * containing the names + * of the request's attributes + * + * @since 2.2 + */ + Enumeration getAttributeNames(int scope); + + /** + * + * Stores an attribute in this request in the scope. + * Attributes are reset between requests. + * + *

Attribute names should follow the same conventions as + * package names. Names beginning with java.*, + * javax.*, and com.sun.*, are + * reserved for use by Sun Microsystems. + * + * + * @param name a String specifying + * the name of the attribute + * @param o the Object to be stored + * @param scope scope (global or request) of the attribute + * + * @since 2.2 + */ + void setAttribute(String name, Object o, int scope); + + /** + * Removes an attribute from this request in the scope. + * This method is not + * generally needed as attributes only persist as long as the request + * is being handled. + * + *

Attribute names should follow the same conventions as + * package names. Names beginning with java.*, + * javax.*, and com.sun.*, are + * reserved for use by Sun Microsystems. + * + * + * @param name a String specifying + * the name of the attribute to remove + * @param scope scope (global or request) of the attribute + * + * @since 2.2 + */ + void removeAttribute(String name, int scope); + + /** + * Utility method for getting a Map view of the request attributes. + * Returns a Map with attributes from the GLOBAL_SCOPE. + * + * @return a Map containing the request attributes. + * + * @since 2.2 + */ + Map getAttributes(); + + /** + * + * Returns the name of the authentication scheme used to protect + * the servlet, for example, "BASIC" or "SSL," or null if the servlet was + * not protected + * + * @return The name of the authentication scheme used to + * protect the servlet, or null if the servlet was + * not protected + */ + + String getAuthType(); + + /** + * Returns the name of the character encoding used in the body of this + * request. This method returns null if the request + * does not specify a character encoding + * + * + * @return a String containing the name of + * the chararacter encoding, or null + * if the request does not specify a character encoding + * + */ + + String getCharacterEncoding(); + + /** + * Overrides the charactor encoding of parameters. + * + * @throws java.io.UnsupportedEncodingException if this is not a valid encoding. + * + */ + + void setCharacterEncoding(String enc) throws java.io.UnsupportedEncodingException; + + /** + * Returns the length, in bytes, of the request body + * + * @return an integer containing the length of the + * request body or -1 if the length is not known + * + */ + + int getContentLength(); + + /** + * Returns the MIME type of the body of the request + * + * @return a String containing the name + * of the MIME type of + * the request, or -1 if the type is not known + * + */ + + String getContentType(); + + /** + * Returns the value of a request parameter as a String, + * + * @param name a String specifying the + * name of the parameter + * + * @return a String representing the + * single value of the parameter + * + * @see #getParameterValues(String) + * + */ + + String getParameter(String name); + + /** + * + * Returns an Enumeration of String + * objects containing the names of the parameters contained + * in this request. If the request has + * no parameters, the method returns an + * empty Enumeration. + * + * @return an Enumeration of String + * objects, each String containing + * the name of a request parameter; or an + * empty Enumeration if the + * request has no parameters + * + */ + + Enumeration getParameterNames(); + + /** + * Returns an array of String objects containing + * all of the values the given request parameter has, or + * null if the parameter does not exist. + * + *

If the parameter has a single value, the array has a length + * of 1. + * + * @param name a String containing the name of + * the parameter whose value is requested + * + * @return an array of String objects + * containing the parameter's values + * + * @see #getParameter(String) + * + */ + + String[] getParameterValues(String name); + + + /** + * Utility method for getting a Map view of the request parameters. + * Returns a Map with request parameters. + * + * @return a Map containing the request parameters. + * + * @since 2.2 + */ + Map getParameters(); + + /** + * Returns the name and version of the protocol the request uses + * in the form protocol/majorVersion.minorVersion, for + * example, HTTP/1.1. For HTTP servlets, the value + * returned is the same as the value of the CGI variable + * SERVER_PROTOCOL. + * + * @return a String containing the protocol + * name and version number + * + */ + + String getProtocol(); + + /** + * Returns the name of the scheme used to make this request, + * for example, + * http, https, or ftp. + * Different schemes have different rules for constructing URLs, + * as noted in RFC 1738. + * + * @return a String containing the name + * of the scheme used to make this request + * + */ + + String getScheme(); + + /** + * Returns the host name of the server that received the request. + * For HTTP servlets, same as the value of the CGI variable + * SERVER_NAME. + * + * @return a String containing the name + * of the server to which the request was sent + */ + + String getServerName(); + + /** + * Returns the port number on which this request was received. + * For HTTP servlets, same as the value of the CGI variable + * SERVER_PORT. + * + * @return an integer specifying the port number + * + */ + + int getServerPort(); + + /** + * Returns the Internet Protocol (IP) address of the client + * that sent the request. For HTTP servlets, same as the value of the + * CGI variable REMOTE_ADDR. + * + * @return a String containing the + * IP address of the client that sent the request + * + */ + + String getRemoteAddr(); + + /** + * Returns the fully qualified name of the client that sent the + * request, or the IP address of the client if the name cannot be + * determined. For HTTP servlets, same as the value of the CGI variable + * REMOTE_HOST. + * + * @return a String containing the fully qualified name + * of the client + * + */ + + String getRemoteHost(); + + /** + * + * Returns the preferred Locale that the client will + * accept content in, based on the Accept-Language header. + * If the client request doesn't provide an Accept-Language header, + * this method returns the default locale for the server. + * + * + * @return the preferred Locale for the client + * + */ + + Locale getLocale(); + + /** + * + * Returns an Enumeration of Locale objects + * indicating, in decreasing order starting with the preferred locale, the + * locales that are acceptable to the client based on the Accept-Language + * header. + * If the client request doesn't provide an Accept-Language header, + * this method returns an Enumeration containing one + * Locale, the default locale for the server. + * + * + * @return an Enumeration of preferred + * Locale objects for the client + * + */ + + Enumeration getLocales(); + + /** + * + * Returns a boolean indicating whether this request was made using a + * secure channel, such as HTTPS. + * + * + * @return a boolean indicating if the request was made using a + * secure channel + * + */ + + boolean isSecure(); + + /** + * + * Returns an array containing all of the Cookie + * objects the client sent with this request. + * This method returns null if no cookies were sent. + * + * @return an array of all the Cookies + * included with this request, or null + * if the request has no cookies + * + * + */ + + Cookie[] getCookies(); + + /** + * Returns a map of the Cookie objects the client sent + * with this request, indexed by name. This method returns an empty + * map if no cookies were sent. + * + * @return a Map of Cookie objects + */ + Map getCookieMap(); + + /** + * + * Returns the value of the specified request header + * as a long value that represents a + * Date object. Use this method with + * headers that contain dates, such as + * If-Modified-Since. + * + *

The date is returned as + * the number of milliseconds since January 1, 1970 GMT. + * The header name is case insensitive. + * + *

If the request did not have a header of the + * specified name, this method returns -1. If the header + * can't be converted to a date, the method throws + * an IllegalArgumentException. + * + * @param name a String specifying the + * name of the header + * + * @return a long value + * representing the date specified + * in the header expressed as + * the number of milliseconds + * since January 1, 1970 GMT, + * or -1 if the named header + * was not included with the + * reqest + * + * @exception IllegalArgumentException If the header value + * can't be converted + * to a date + * + */ + + long getDateHeader(String name); + + /** + * + * Returns the value of the specified request header + * as a String. If the request did not include a header + * of the specified name, this method returns null. + * The header name is case insensitive. You can use + * this method with any request header. + * + * @param name a String specifying the + * header name + * + * @return a String containing the + * value of the requested + * header, or null + * if the request does not + * have a header of that name + * + */ + + String getHeader(String name); + + /** + * + * Returns all the values of the specified request header + * as an Enumeration of String objects. + * + *

Some headers, such as Accept-Language can be sent + * by clients as several headers each with a different value rather than + * sending the header as a comma separated list. + * + *

If the request did not include any headers + * of the specified name, this method returns an empty + * Enumeration. + * The header name is case insensitive. You can use + * this method with any request header. + * + * @param name a String specifying the + * header name + * + * @return a Enumeration containing the + * values of the requested + * header, or null + * if the request does not + * have any headers of that name + * + */ + + Enumeration getHeaders(String name); + + /** + * + * Returns an enumeration of all the header names + * this request contains. If the request has no + * headers, this method returns an empty enumeration. + * + *

Some servlet containers do not allow do not allow + * servlets to access headers using this method, in + * which case this method returns null + * + * @return an enumeration of all the + * header names sent with this + * request; if the request has + * no headers, an empty enumeration; + * if the servlet container does not + * allow servlets to use this method, + * null + * + */ + + Enumeration getHeaderNames(); + + /** + * Utility method for getting a Map view of the request headers. + * Returns a Map with request headers. + * + * @return a Map containing the request headers. + * + * @since 2.2 + */ + Map getHeaders(); + + /** + * Retrieves the body of the request as binary data using + * an InputStream. + * + * @return an InputStream + * containing the body of the request. + * + * @throws IOException if an input or output exception occurred + * @throws UnsupportedOperationException + */ + InputStream getInputStream() throws IOException, UnsupportedOperationException; + + /** + * + * Returns the name of the HTTP method with which this + * request was made, for example, GET, POST, or PUT. + * Same as the value of the CGI variable REQUEST_METHOD. + * + * @return a String + * specifying the name + * of the method with which + * this request was made + * + */ + + String getMethod(); + + /** + * + * Returns any extra path information associated with + * the URL the client sent when it made this request. + * The extra path information follows the servlet path + * but precedes the query string. + * This method returns null if there + * was no extra path information. + * + *

Same as the value of the CGI variable PATH_INFO. + * + * + * @return a String specifying + * extra path information that comes + * after the servlet path but before + * the query string in the request URL; + * or null if the URL does not have + * any extra path information + * + */ + + String getPathInfo(); + + /** + * + * Returns any extra path information after the servlet name + * but before the query string, and translates it to a real + * path. Same as the value of the CGI variable PATH_TRANSLATED. + * + *

If the URL does not have any extra path information, + * this method returns null. + * + * + * @return a String specifying the + * real path, or null if + * the URL does not have any extra path + * information + * + * + */ + + String getPathTranslated(); + + /** + * + * Returns the portion of the request URI that indicates the context + * of the request. The context path always comes first in a request + * URI. The path starts with a "/" character but does not end with a "/" + * character. For servlets in the default (root) context, this method + * returns "". + * + * + * @return a String specifying the + * portion of the request URI that indicates the context + * of the request + * + * + */ + + String getContextPath(); + + /** + * + * Returns the query string that is contained in the request + * URL after the path. This method returns null + * if the URL does not have a query string. Same as the value + * of the CGI variable QUERY_STRING. + * + * @return a String containing the query + * string or null if the URL + * contains no query string + * + */ + + String getQueryString(); + + /** + * + * Returns the login of the user making this request, if the + * user has been authenticated, or null if the user + * has not been authenticated. + * Whether the user name is sent with each subsequent request + * depends on the browser and type of authentication. Same as the + * value of the CGI variable REMOTE_USER. + * + * @return a String specifying the login + * of the user making this request, or nullnull if the user + * has not been authenticated. + * Whether the user name is sent with each subsequent request + * depends on the browser and type of authentication. Same as the + * value of the CGI variable REMOTE_USER. + * + * @return a String specifying the login + * of the user making this request, or nulltrue if the user is + * authenticated and in the role; + * otherwise, false + * + * + * @see #getRemoteUser() + * + */ + + boolean isUserInRole(String role); + + /** + * + * 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 + * null. + * + * + * @return a String specifying the session + * ID, or null if the request did + * not specify a session ID + * + * @see #isRequestedSessionIdValid() + * + */ + + String getRequestedSessionId(); + + /** + * + * Returns the part of this request's URL from the protocol + * name up to the query string in the first line of the HTTP request. + * For example: + * + *

+ * + *
First line of HTTP request + * Returned Value + *
POST /some/path.html HTTP/1.1/some/path.html + *
GET http://foo.bar/a.html HTTP/1.0 + * http://foo.bar/a.html + *
HEAD /xyz?a=b HTTP/1.1/xyz + *
+ *
+ * + * For internal requests, this method returns + * the information for the original/external request! + * + * @return a String containing + * the part of the URL from the + * protocol name up to the query string + */ + String getRequestURI(); + + /** + *

+ * Returns the URI of the requested resource as interpreted by the sitemap. + * For example, if your webapp is mounted at "/webapp" and the HTTP request + * is for "/webapp/foo", this method returns "foo". Consequently, if the + * request is for "/webapp", this method returns an empty string. + *

+ *

+ * Note that if the request is mapped to a pipeline that contains + * aggregated content, and if this method is called in the context of + * one of the aggregated parts (e.g. a server page), this method will + * return the URI of the aggregated part, not the original requested URI. + *

+ * + * @return a String containing the URL as mangled by the + * sitemap + */ + String getSitemapURI(); + + /** + *

+ * Returns the URI Prefix of the requested resource where the sitemap is mounted. + * For example, if your webapp is mounted at "/webapp" and the HTTP request + * is for "/webapp/foo", this method returns "webapp/". + *

+ * + * @return a String containing the URI prefix as mangled by the + * sitemap + */ + + String getSitemapURIPrefix(); + + /** + *

+ * Returns the path to the sitemap of the requested resource as interpreted + * by the sitemap. + * For example, if your webapp is mounted at "webapp" and the HTTP request + * is for "webapp/foo", this method returns "webapp/". Consequently, if the + * request is for "foo", this method returns the empty string. + *

+ * + * @return a String containing the path to the sitemap + * @since 2.2 + */ + + String getSitemapPath(); + + /** + * + * Returns the part of this request's URL that calls + * the servlet. This includes either the servlet name or + * a path to the servlet, but does not include any extra + * path information or a query string. Same as the value + * of the CGI variable SCRIPT_NAME. + * + * + * @return a String containing + * the name or path of the servlet being + * called, as specified in the request URL + * + * + */ + + String getServletPath(); + + /** + * + * Returns the current Session + * associated with this request or, if if there is no + * current session and create is true, returns + * a new session. + * + *

If create is false + * and the request has no valid Session, + * this method returns null. + * + *

To make sure the session is properly maintained, + * you must call this method before + * the response is committed. + * + * + * + * + * @param create true to create + * a new session for this request if necessary; + * false to return null + * if there's no current session + * + * + * @return the Session associated + * with this request or null if + * create is false + * and the request has no valid session + * + * @see #getSession() + * + * + */ + + Session getSession(boolean create); + + /** + * + * Returns the current session associated with this request, + * or if the request does not have a session, creates one. + * + * @return the Session associated + * with this request + * + * @see #getSession(boolean) + * + */ + + Session getSession(); + + /** + * + * Checks whether the requested session ID is still valid. + * + * @return true if this + * request has an id for a valid session + * in the current session context; + * false otherwise + * + * @see #getRequestedSessionId() + * @see #getSession() + * + */ + + boolean isRequestedSessionIdValid(); + + /** + * + * Checks whether the requested session ID came in as a cookie. + * + * @return true if the session ID + * came in as a + * cookie; otherwise, false + * + * + * @see #getSession() + * + */ + + boolean isRequestedSessionIdFromCookie(); + + /** + * + * Checks whether the requested session ID came in as part of the + * request URL. + * + * @return true if the session ID + * came in as part of a URL; otherwise, + * false + * + * + * @see #getSession() + * + */ + + boolean isRequestedSessionIdFromURL(); +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Request.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Response.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Response.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Response.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Response.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,234 @@ +/* + * 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; + +import java.util.Locale; + +/** + * Defines an interface to provide client response information . + * + * @author Davanum Srinivas + * @author Carsten Ziegeler + * @version CVS $Id: Response.java 160568 2005-04-08 17:33:05Z sylvain $ + * + */ + +public interface Response { + + /** + * Returns the name of the charset used for + * the MIME body sent in this response. + * + *

If no charset has been assigned, it is implicitly + * set to ISO-8859-1 (Latin-1). + * + *

See RFC 2047 (http://ds.internic.net/rfc/rfc2045.txt) + * for more information about character encoding and MIME. + * + * @return a String specifying the + * name of the charset, for + * example, ISO-8859-1 + * + */ + + String getCharacterEncoding(); + + /** + * Sets the locale of the response, setting the headers (including the + * Content-Type's charset) as appropriate. By default, the response locale + * is the default locale for the server. + * + * @param loc the locale of the response + * + * @see #getLocale() + * + */ + + void setLocale(Locale loc); + + /** + * Returns the locale assigned to the response. + * + * + * @see #setLocale(Locale) + * + */ + + Locale getLocale(); + + /** + * Constructs a cookie with a specified name and value. + * + *

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. + * + *

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 + * setValue method. + * + *

By default, cookies are created according to the Netscape + * cookie specification. The version can be changed with the + * setVersion method. + * + * + * @param name a String specifying the name of the cookie + * + * @param value a String 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 + * + */ + Cookie createCookie(String name, String value); + + /** + * Adds the specified cookie to the response. This method can be called + * multiple times to set more than one cookie. + * + * @param cookie the Cookie to return to the client + * + */ + + void addCookie(Cookie cookie); + + /** + * Returns a boolean indicating whether the named response header + * has already been set. + * + * @param name the header name + * @return true if the named response header + * has already been set; + * false otherwise + */ + + boolean containsHeader(String name); + + /** + * Encodes the specified URL by including the session ID in it, + * or, if encoding is not needed, returns the URL unchanged. + * The implementation of this method includes the logic to + * determine whether the session ID needs to be encoded in the URL. + * For example, if the browser supports cookies, or session + * tracking is turned off, URL encoding is unnecessary. + * + *

For robust session tracking, all URLs emitted by a servlet + * should be run through this + * method. Otherwise, URL rewriting cannot be used with browsers + * which do not support cookies. + * + * @param url the url to be encoded. + * @return the encoded URL if encoding is needed; + * the unchanged URL otherwise. + */ + + String encodeURL(String url); + + /** + * + * Sets a response header with the given name and + * date-value. The date is specified in terms of + * milliseconds since the epoch. If the header had already + * been set, the new value overwrites the previous one. The + * containsHeader method can be used to test for the + * presence of a header before setting its value. + * + * @param name the name of the header to set + * @param date the assigned date value + * + * @see #containsHeader(String) + * @see #addDateHeader(String, long) + */ + + void setDateHeader(String name, long date); + + /** + * + * Adds a response header with the given name and + * date-value. The date is specified in terms of + * milliseconds since the epoch. This method allows response headers + * to have multiple values. + * + * @param name the name of the header to set + * @param date the additional date value + * + * @see #setDateHeader(String, long) + */ + + void addDateHeader(String name, long date); + + /** + * + * Sets a response header with the given name and value. + * If the header had already been set, the new value overwrites the + * previous one. The containsHeader method can be + * used to test for the presence of a header before setting its + * value. + * + * @param name the name of the header + * @param value the header value + * + * @see #containsHeader(String) + * @see #addHeader(String, String) + */ + + void setHeader(String name, String value); + + /** + * Adds a response header with the given name and value. + * This method allows response headers to have multiple values. + * + * @param name the name of the header + * @param value the additional header value + * + * @see #setHeader(String, String) + */ + + void addHeader(String name, String value); + + /** + * Sets a response header with the given name and + * int value. If the header had already + * been set, the new value overwrites the previous one. The + * containsHeader method can be used to test for the + * presence of a header before setting its value. + * + * @param name the name of the header to set + * @param value the assigned int value + * + * @see #containsHeader(String) + * @see #addIntHeader(String, int) + */ + + void setIntHeader(String name, int value); + + /** + * Adds a response header with the given name and + * int value. This method allows response headers + * to have multiple values. + * + * @param name the name of the header to set + * @param value the additional int value + * + * @see #setIntHeader(String, int) + */ + + void addIntHeader(String name, int value); +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Response.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Session.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Session.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Session.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Session.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,240 @@ +/* + * 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; + +import java.util.Enumeration; +import java.util.Map; + +/** + * + * Provides a way to identify a user across more than one page + * request or visit to a Web site and to store information about that user. + * + *

Cocoon uses this interface to create a session + * between a client and the "cocoon server". The session persists + * for a specified time period, across more than one connection or + * page request from the user. A session usually corresponds to one + * user, who may visit a site many times. The server can maintain a + * session in many ways such as using cookies or rewriting URLs. + * + *

This interface allows Cocoon to + *

    + *
  • View and manipulate information about a session, such as + * the session identifier, creation time, and last accessed time + *
  • Bind objects to sessions, allowing user information to persist + * across multiple user connections + *
+ * + *

Session information is scoped only to the current context + * (Context), so information stored in one context + * will not be directly visible in another. + * + * @author Carsten Ziegeler + * @version CVS $Id: Session.java 170542 2005-05-17 08:10:19Z danielf $ + * + */ + +public interface Session { + + /** + * + * Returns the time when this session was created, measured + * in milliseconds since midnight January 1, 1970 GMT. + * + * @return a long specifying + * when this session was created, + * expressed in + * milliseconds since 1/1/1970 GMT + * + * @exception IllegalStateException if this method is called on an + * invalidated session + * + */ + long getCreationTime(); + + /** + * + * Returns a string containing the unique identifier assigned + * to this session. The identifier is assigned + * by the context container and is implementation dependent. + * + * @return a string specifying the identifier + * assigned to this session + * + * @exception IllegalStateException if this method is called on an + * invalidated session + * + */ + String getId(); + + /** + * + * Returns the last time the client sent a request associated with + * this session, as the number of milliseconds since midnight + * January 1, 1970 GMT. + * + *

Actions that your application takes, such as getting or setting + * a value associated with the session, do not affect the access + * time. + * + * @return a long + * representing the last time + * the client sent a request associated + * with this session, expressed in + * milliseconds since 1/1/1970 GMT + * + * @exception IllegalStateException if this method is called on an + * invalidated session + * + */ + + long getLastAccessedTime(); + + /** + * + * Specifies the time, in seconds, between client requests before the + * contextcontainer will invalidate this session. A negative time + * indicates the session should never timeout. + * + * @param interval An integer specifying the number + * of seconds + * + */ + void setMaxInactiveInterval(int interval); + + /** + * Returns the maximum time interval, in seconds, that + * the context container will keep this session open between + * client accesses. After this interval, the context container + * will invalidate the session. The maximum time interval can be set + * with the setMaxInactiveInterval method. + * A negative time indicates the session should never timeout. + * + * + * @return an integer specifying the number of + * seconds this session remains open + * between client requests + * + * @see #setMaxInactiveInterval(int) + * + * + */ + int getMaxInactiveInterval(); + + /** + * + * Returns the object bound with the specified name in this session, or + * null if no object is bound under the name. + * + * @param name a string specifying the name of the object + * + * @return the object with the specified name + * + * @exception IllegalStateException if this method is called on an + * invalidated session + * + */ + Object getAttribute(String name); + + /** + * + * Returns an Enumeration of String objects + * containing the names of all the objects bound to this session. + * + * @return an Enumeration of + * String objects specifying the + * names of all the objects bound to + * this session + * + * @exception IllegalStateException if this method is called on an + * invalidated session + * + */ + Enumeration getAttributeNames(); + + /** + * Binds an object to this session, using the name specified. + * If an object of the same name is already bound to the session, + * the object is replaced. + * + * + * @param name the name to which the object is bound; + * cannot be null + * + * @param value the object to be bound; cannot be null + * + * @exception IllegalStateException if this method is called on an + * invalidated session + * + */ + void setAttribute(String name, Object value); + + /** + * + * Removes the object bound with the specified name from + * this session. If the session does not have an object + * bound with the specified name, this method does nothing. + * + * + * @param name the name of the object to + * remove from this session + * + * @exception IllegalStateException if this method is called on an + * invalidated session + */ + void removeAttribute(String name); + + /** + * Utility method for getting a Map view of the request attributes. + * Returns a Map with attributes. + * + * @return a Map containing the request attributes. + * + * @since 2.2 + */ + Map getAttributes(); + + /** + * + * Invalidates this session + * to it. + * + * @exception IllegalStateException if this method is called on an + * already invalidated session + * + */ + void invalidate(); + + /** + * + * Returns true if the client does not yet know about the + * session or if the client chooses not to join the session. For + * example, if the server used only cookie-based sessions, and + * the client had disabled the use of cookies, then a session would + * be new on each request. + * + * @return true if the + * server has created a session, + * but the client has not yet joined + * + * @exception IllegalStateException if this method is called on an + * already invalidated session + * + */ + boolean isNew(); + +} + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/Session.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/SourceResolver.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/SourceResolver.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/SourceResolver.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/SourceResolver.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,33 @@ +/* + * 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; + +/** + * Base interface for resolving a source by system identifiers. This + * component is a special extension of the Avalon Excalibur + * {@link org.apache.excalibur.source.SourceResolver} that is only + * used for Cocoon sitemap components. + * + * @author Carsten Ziegeler + * @version CVS $Id: SourceResolver.java 165284 2005-04-29 09:24:28Z cziegeler $ + */ + +public interface SourceResolver +extends org.apache.excalibur.source.SourceResolver { + + // no methods to add +} + Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/SourceResolver.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,195 @@ +/* + * 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; + +import java.beans.PropertyDescriptor; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import org.apache.avalon.framework.parameters.Parameters; +import org.apache.cocoon.components.flow.FlowHelper; +import org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptFlowHelper; +import org.apache.commons.jxpath.DynamicPropertyHandler; +import org.apache.commons.jxpath.JXPathBeanInfo; +import org.apache.commons.jxpath.JXPathIntrospector; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.NativeJavaPackage; +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.ScriptableObject; + + +/** + * This is an utility class to create an object model which is similar to the one + * used in flow, that can be used from every component. + * + * Work-in-progress, derived from JXTemplateGenerator + * + * @version CVS $Id: TemplateObjectModelHelper.java 307316 2005-10-08 17:20:59Z cziegeler $ + */ +public class TemplateObjectModelHelper { + private static Scriptable rootScope = null; + + /** Avoid instantiation */ + private TemplateObjectModelHelper() {} + + public static Scriptable getScope() { + Context ctx = Context.enter(); + try { + // Create it if never used up to now + if (rootScope == null) + rootScope = ctx.initStandardObjects(null); + + Scriptable scope = ctx.newObject(rootScope); + scope.setPrototype(rootScope); + scope.setParentScope(null); + return scope; + } finally { + Context.exit(); + } + } + + public static void fillContext(Object contextObject, Map map) { + // Hack: I use jxpath to populate the context object's properties + // in the jexl context + final JXPathBeanInfo bi = + JXPathIntrospector.getBeanInfo(contextObject.getClass()); + if (bi.isDynamic()) { + Class cl = bi.getDynamicPropertyHandlerClass(); + try { + DynamicPropertyHandler h = + (DynamicPropertyHandler) cl.newInstance(); + String[] result = h.getPropertyNames(contextObject); + int len = result.length; + for (int i = 0; i < len; i++) { + try { + map.put(result[i], h.getProperty(contextObject, result[i])); + } catch (Exception exc) { + exc.printStackTrace(); + } + } + } catch (Exception ignored) { + ignored.printStackTrace(); + } + } else { + PropertyDescriptor[] props = bi.getPropertyDescriptors(); + int len = props.length; + for (int i = 0; i < len; i++) { + try { + Method read = props[i].getReadMethod(); + if (read != null) { + map.put(props[i].getName(), + read.invoke(contextObject, null)); + } + } catch (Exception ignored) { + ignored.printStackTrace(); + } + } + } + } + + /** + * Create the object model. + * Currently the object model is a map with one single entry: + * cocoon + request The Request Object + * + session The Session (if available) + * + context The Context + * + continuation The Continuation (if available) + * + parameters The parameters (if provided) + */ + public static Object getTemplateObjectModel(final Map objectModel, + final Parameters parameters) { + + // first create the "cocoon object": + final Map cocoon = new HashMap(); + + // Needed for the FOM wrappers + Context cx = Context.enter(); + try { + // cocoon.request + final Request request = ObjectModelHelper.getRequest( objectModel ); + cocoon.put("request", request); + + // cocoon.session + final Session session = request.getSession(false); + if (session != null) { + cocoon.put("session", session); + } + + // cocoon.context + final org.apache.cocoon.environment.Context context = + ObjectModelHelper.getContext( objectModel ); + cocoon.put("context", context); + + } finally { + Context.exit(); + } + + // cocoon.continuation + final Object cont = FlowHelper.getWebContinuation(objectModel); + if ( cont != null ) { + cocoon.put("continuation", cont); + } + + // cocoon.parameters + if ( parameters != null ) { + cocoon.put("parameters", Parameters.toProperties(parameters)); + } + + final Map map = new HashMap(); + map.put("cocoon", cocoon); + + // Now add objects from flow context (if any) + final Object contextObject = FlowHelper.getContextObject(objectModel); + if (contextObject instanceof Map) { + map.putAll((Map)contextObject); + } else if ( contextObject != null ) { + fillContext(contextObject, map); + } + + return map; + } + + /** + * Add java packages to object model. Allows to construct java objects. + * @param objectModel usually the result of invoking getTemplateObjectModel + */ + public static Object addJavaPackages( Map objectModel ) { + Object javaPkg = FOM_JavaScriptFlowHelper.getJavaPackage(objectModel); + Object pkgs = FOM_JavaScriptFlowHelper.getPackages(objectModel); + + // packages might have already been set up if flowscript is being used + if ( javaPkg != null && pkgs != null ) { + objectModel.put( "Packages", javaPkg ); + objectModel.put( "java", pkgs ); + } else { + Context cx = Context.enter(); + try { + final String JAVA_PACKAGE = "JavaPackage"; + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + Scriptable newPackages = new NativeJavaPackage( "", cl ); + newPackages.setParentScope( getScope() ); + newPackages.setPrototype( ScriptableObject.getClassPrototype( getScope(), + JAVA_PACKAGE ) ); + objectModel.put( "Packages", newPackages ); + objectModel.put( "java", ScriptableObject.getProperty( getScope(), "java" ) ); + } finally { + Context.exit(); + } + } + return objectModel; + } +} Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/TemplateObjectModelHelper.java ------------------------------------------------------------------------------ svn:eol-style = native Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java?rev=330548&view=auto ============================================================================== --- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java (added) +++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java Thu Nov 3 05:41:06 2005 @@ -0,0 +1,190 @@ +/* + * 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.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.cocoon.CascadingIOException; +import org.apache.cocoon.Constants; +import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.components.source.SourceUtil; +import org.apache.cocoon.environment.AbstractEnvironment; +import org.apache.cocoon.environment.internal.EnvironmentHelper; +import org.apache.excalibur.source.Source; +import org.apache.excalibur.source.SourceException; +import org.apache.excalibur.source.SourceResolver; +import org.xml.sax.SAXException; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.MalformedURLException; + +/** + * This environment is used to save the requested file to disk. + * + * @author Stefano Mazzocchi + * @version CVS $Id: AbstractCommandLineEnvironment.java 165284 2005-04-29 09:24:28Z cziegeler $ + */ + +public abstract class AbstractCommandLineEnvironment +extends AbstractEnvironment { + + protected String contentType; + protected int contentLength; + protected int statusCode; + + public AbstractCommandLineEnvironment(String uri, + String view, + File context, + OutputStream stream, + Logger log) + throws MalformedURLException { + super(uri, view); + this.enableLogging(log); + this.outputStream = stream; + this.statusCode = 0; + } + + /** + * Redirect the client to a new URL + */ + public void redirect(String newURL, boolean global, boolean permanent) + throws IOException { + + // fix all urls created with request.getScheme()+... etc. + if (newURL.startsWith("cli:/")) { + int pos = newURL.indexOf('/', 6); + newURL = newURL.substring(pos+1); + } + + // fix all relative urls to use to cocoon: protocol + if (newURL.indexOf(":") == -1) { + newURL = "cocoon:/" + newURL; + } + + // FIXME: this is a hack for the links view + ServiceManager manager = EnvironmentHelper.getSitemapServiceManager(); + SourceResolver resolver = null; + try { + resolver = (SourceResolver)manager.lookup(SourceResolver.ROLE); + if (newURL.startsWith("cocoon:") + && this.getView() != null + && this.getView().equals(Constants.LINK_VIEW)) { + + // as the internal cocoon protocol is used the last + // serializer is removed from it! And therefore + // the LinkSerializer is not used. + // so we create one without Avalon... + org.apache.cocoon.serialization.LinkSerializer ls = + new org.apache.cocoon.serialization.LinkSerializer(); + ls.setOutputStream(this.outputStream); + + Source redirectSource = null; + try { + redirectSource = resolver.resolveURI(newURL); + SourceUtil.parse( manager, redirectSource, ls); + } catch (SourceException se) { + throw new CascadingIOException("SourceException: " + se, se); + } catch (SAXException se) { + throw new CascadingIOException("SAXException: " + se, se); + } catch (ProcessingException pe) { + throw new CascadingIOException("ProcessingException: " + pe, pe); + } finally { + resolver.release( redirectSource ); + } + + } else { + Source redirectSource = null; + try { + redirectSource = resolver.resolveURI(newURL); + InputStream is = redirectSource.getInputStream(); + byte[] buffer = new byte[8192]; + int length = -1; + + while ((length = is.read(buffer)) > -1) { + this.outputStream.write(buffer, 0, length); + } + } catch (SourceException se) { + throw new CascadingIOException("SourceException: " + se, se); + } finally { + resolver.release( redirectSource); + } + } + } catch (ServiceException se) { + throw new CascadingIOException("Unable to get source resolver.", se); + } finally { + manager.release(resolver); + } + } + + /** + * Set the StatusCode + */ + public void setStatus(int statusCode) { + this.statusCode = statusCode; + } + + /** + * Get the StatusCode + */ + public int getStatus() { + return statusCode; + } + + /** + * Set the ContentType + */ + public void setContentType(String contentType) { + this.contentType = contentType; + } + + /** + * Set the ContentLength + */ + public void setContentLength(int contentLength) { + this.contentLength = contentLength; + } + + /** + * Get the ContentType + */ + public String getContentType() { + return this.contentType; + } + + /** + * Always return true. + */ + public boolean isExternal() { + return true; + } + + /** + * Return an OutputStream, but allow it to be null for when + * the pipeline is being streamed to the provided SAX + * content handler (using CocoonBean) + */ + public OutputStream getOutputStream(int bufferSize) throws IOException { + if (this.outputStream == null) { + return null; + } + return super.getOutputStream(bufferSize); + } + +} \ No newline at end of file Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java ------------------------------------------------------------------------------ svn:eol-style = native