org.apache.cocoon.environment.http
Class HttpEnvironment

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.environment.AbstractEnvironment
          extended by org.apache.cocoon.environment.http.HttpEnvironment
All Implemented Interfaces:
LogEnabled, Environment, PermanentRedirector, Redirector, SourceResolver

public class HttpEnvironment
extends AbstractEnvironment
implements Redirector, PermanentRedirector

HTTP Servlet environment.

Version:
$Id: HttpEnvironment.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Apache Cocoon Team

Field Summary
static String HTTP_REQUEST_OBJECT
           
static String HTTP_RESPONSE_OBJECT
           
static String HTTP_SERVLET_CONTEXT
           
 
Fields inherited from class org.apache.cocoon.environment.AbstractEnvironment
action, avalonToCocoonSourceWrapper, context, initializedComponents, manager, objectModel, outputStream, prefix, rootContext, secureOutputStream, sourceResolver, uris, view
 
Fields inherited from interface org.apache.excalibur.source.SourceResolver
METHOD, ROLE, URI_ENCODING, URI_PARAMETERS
 
Constructor Summary
HttpEnvironment(String uri, String root, HttpServletRequest req, HttpServletResponse res, ServletContext servletContext, HttpContext context, String containerEncoding, String defaultFormEncoding)
          Constructs a HttpEnvironment object from a HttpServletRequest and HttpServletResponse objects
 
Method Summary
 String getContentType()
          Get the ContentType
 OutputStream getOutputStream(int bufferSize)
          Get the output stream where to write the generated resource.
 boolean hasRedirected()
          Was one of the redirection methods called ?
 boolean isExternal()
          Always return true.
 boolean isResponseModified(long lastModified)
          Check if the response has been modified since the same "resource" was requested.
 void permanentRedirect(boolean sessionmode, String newURL)
          Redirect to the given URL
 void redirect(boolean sessionmode, String newURL)
          Redirect to the given URL
 void sendStatus(int sc)
          Send a content-less response with the given status code.
 void setContentLength(int length)
          Set the length of the generated content
 void setContentType(String contentType)
          Set the ContentType
 void setResponseIsNotModified()
          Mark the response as not modified.
 void setStatus(int statusCode)
          Set the StatusCode
 boolean tryResetResponse()
          Reset the response if possible.
 
Methods inherited from class org.apache.cocoon.environment.AbstractEnvironment
changeContext, commitResponse, extractAction, extractView, finishingProcessing, getAction, getAttribute, getAttributeNames, getContext, getObjectModel, getOutputStream, getRootContext, getURI, getURIPrefix, getView, globalRedirect, hasAttribute, initComponents, isInternalRedirect, release, removeAttribute, resolve, resolveURI, resolveURI, setAction, setAttribute, setContext, setContext, setURIPrefix, setView, startingProcessing
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.environment.Redirector
globalRedirect
 

Field Detail

HTTP_REQUEST_OBJECT

public static final String HTTP_REQUEST_OBJECT
See Also:
Constant Field Values

HTTP_RESPONSE_OBJECT

public static final String HTTP_RESPONSE_OBJECT
See Also:
Constant Field Values

HTTP_SERVLET_CONTEXT

public static final String HTTP_SERVLET_CONTEXT
See Also:
Constant Field Values
Constructor Detail

HttpEnvironment

public HttpEnvironment(String uri,
                       String root,
                       HttpServletRequest req,
                       HttpServletResponse res,
                       ServletContext servletContext,
                       HttpContext context,
                       String containerEncoding,
                       String defaultFormEncoding)
                throws MalformedURLException,
                       IOException
Constructs a HttpEnvironment object from a HttpServletRequest and HttpServletResponse objects

Throws:
MalformedURLException
IOException
Method Detail

redirect

public void redirect(boolean sessionmode,
                     String newURL)
              throws IOException
Description copied from interface: Redirector
Redirect to the given URL

Specified by:
redirect in interface Environment
Specified by:
redirect in interface Redirector
Throws:
IOException

permanentRedirect

public void permanentRedirect(boolean sessionmode,
                              String newURL)
                       throws IOException
Description copied from interface: PermanentRedirector
Redirect to the given URL

Specified by:
permanentRedirect in interface PermanentRedirector
Throws:
IOException

sendStatus

public void sendStatus(int sc)
Description copied from interface: Redirector
Send a content-less response with the given status code.

Specified by:
sendStatus in interface Redirector
Parameters:
sc - an http status code.

hasRedirected

public boolean hasRedirected()
Description copied from interface: Redirector
Was one of the redirection methods called ?

Specified by:
hasRedirected in interface Redirector

setStatus

public void setStatus(int statusCode)
Set the StatusCode

Specified by:
setStatus in interface Environment
Overrides:
setStatus in class AbstractEnvironment

setContentType

public void setContentType(String contentType)
Set the ContentType

Specified by:
setContentType in interface Environment

getContentType

public String getContentType()
Get the ContentType

Specified by:
getContentType in interface Environment

setContentLength

public void setContentLength(int length)
Set the length of the generated content

Specified by:
setContentLength in interface Environment

isResponseModified

public boolean isResponseModified(long lastModified)
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.

Specified by:
isResponseModified in interface Environment
Overrides:
isResponseModified in class AbstractEnvironment
Returns:
true if the response is modified or if the environment is not able to test it

setResponseIsNotModified

public void setResponseIsNotModified()
Mark the response as not modified.

Specified by:
setResponseIsNotModified in interface Environment
Overrides:
setResponseIsNotModified in class AbstractEnvironment

tryResetResponse

public boolean tryResetResponse()
                         throws IOException
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.

Specified by:
tryResetResponse in interface Environment
Overrides:
tryResetResponse in class AbstractEnvironment
Returns:
true if the response was successfully reset
Throws:
IOException

getOutputStream

public OutputStream getOutputStream(int bufferSize)
                             throws IOException
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. This method replaces AbstractEnvironment.getOutputStream().

Specified by:
getOutputStream in interface Environment
Overrides:
getOutputStream in class AbstractEnvironment
Throws:
IOException

isExternal

public boolean isExternal()
Always return true.

Specified by:
isExternal in interface Environment
Returns:
true if this environment is external


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.