| Constructor: |
public EnvironmentWrapper(Environment env,
String requestURI,
String queryString,
Logger logger) throws MalformedURLException {
this(env, requestURI, queryString, logger, false);
}
Constructs an EnvironmentWrapper object from a Request
and Response objects |
public EnvironmentWrapper(Environment env,
String requestURI,
String queryString,
Logger logger,
boolean rawMode) throws MalformedURLException {
this(env, requestURI, queryString, logger, null, rawMode);
}
Constructs an EnvironmentWrapper object from a Request
and Response objects |
public EnvironmentWrapper(Environment env,
ComponentManager manager,
String uri,
Logger logger,
boolean wrapResponse) throws MalformedURLException {
super(env.getURI(), env.getView(), env.getContext(), env.getAction());
// FIXME(SW): code stolen from SitemapSource. Factorize somewhere...
boolean rawMode = false;
// remove the protocol
int position = uri.indexOf(':") + 1;
if (position != 0) {
// this.protocol = uri.substring(0, position-1);
// check for subprotocol
if (uri.startsWith("raw:", position)) {
position += 4;
rawMode = true;
}
} else {
throw new MalformedURLException("No protocol found for sitemap source in " + uri);
}
// does the uri point to this sitemap or to the root sitemap?
String prefix;
if (uri.startsWith("//", position)) {
position += 2;
// try {
// this.processor = (Processor)this.manager.lookup(Processor.ROLE);
// } catch (ComponentException e) {
// throw new MalformedURLException("Cannot get Processor instance");
// }
prefix = ""; // start at the root
} else if (uri.startsWith("/", position)) {
position ++;
prefix = null;
// this.processor = CocoonComponentManager.getCurrentProcessor();
} else {
throw new MalformedURLException("Malformed cocoon URI: " + uri);
}
// create the queryString (if available)
String queryString = null;
int queryStringPos = uri.indexOf('?", position);
if (queryStringPos != -1) {
queryString = uri.substring(queryStringPos + 1);
uri = uri.substring(position, queryStringPos);
} else if (position > 0) {
uri = uri.substring(position);
}
// determine if the queryString specifies a cocoon-view
String view = null;
if (queryString != null) {
int index = queryString.indexOf(Constants.VIEW_PARAM);
if (index != -1
&& (index == 0 || queryString.charAt(index-1) == '&")
&& queryString.length() > index + Constants.VIEW_PARAM.length()
&& queryString.charAt(index+Constants.VIEW_PARAM.length()) == '=") {
String tmp = queryString.substring(index+Constants.VIEW_PARAM.length()+1);
index = tmp.indexOf('&");
if (index != -1) {
view = tmp.substring(0,index);
} else {
view = tmp;
}
} else {
view = env.getView();
}
} else {
view = env.getView();
}
// build the request uri which is relative to the context
String requestURI = (prefix == null ? env.getURIPrefix() + uri : uri);
// // create system ID
// this.systemId = queryString == null ?
// this.protocol + "://" + requestURI :
// this.protocol + "://" + requestURI + "?" + queryString;
this.init(env, requestURI, queryString, logger, manager, rawMode, view, wrapResponse);
this.setURI(prefix, uri);
}
|
public EnvironmentWrapper(Environment env,
String requestURI,
String queryString,
Logger logger,
ComponentManager manager,
boolean rawMode) throws MalformedURLException {
this(env, requestURI, queryString, logger, null, rawMode,env.getView(), true);
}
Constructs an EnvironmentWrapper object from a Request
and Response objects |
public EnvironmentWrapper(Environment env,
String requestURI,
String queryString,
Logger logger,
ComponentManager manager,
boolean rawMode,
String view) throws MalformedURLException {
this(env, requestURI, queryString, logger, manager, rawMode, view, true);
}
Constructs an EnvironmentWrapper object from a Request
and Response objects |
public EnvironmentWrapper(Environment env,
String requestURI,
String queryString,
Logger logger,
ComponentManager manager,
boolean rawMode,
String view,
boolean wrapResponse) throws MalformedURLException {
super(env.getURI(), view, env.getContext(), env.getAction());
init(env, requestURI, queryString, logger, manager, rawMode, view, wrapResponse);
}
Constructs an EnvironmentWrapper object from a Request
and Response objects |
| Method from org.apache.cocoon.environment.wrapper.EnvironmentWrapper Detail: |
public void commitResponse() throws IOException {
final OutputStream outputStream = getOutputStream(-1);
if (outputStream != null && outputStream instanceof BufferedOutputStream) {
((BufferedOutputStream)outputStream).realFlush();
} else {
super.commitResponse();
}
}
|
public Object getAttribute(String name) {
Object value = super.getAttribute(name);
// get it from the wrapped env only if it's not defined here with a null value
if (value == null && !hasAttribute(name)) {
value = this.environment.getAttribute(name);
}
return value;
}
Lookup an attribute in this instance, and if not found search it
in the wrapped environment. |
public String getContentType() {
return this.contentType;
}
|
public Map getObjectModel() {
return this.objectModel;
}
Get the underlying object model |
public OutputStream getOutputStream() throws IOException {
Deprecation.logger.warn("The method Environment.getOutputStream() " +
"is deprecated. Use getOutputStream(-1) instead.");
// by default we use the complete buffering output stream
return getOutputStream(-1);
} Deprecated! use - #getOutputStream(int) instead.
|
public OutputStream getOutputStream(int bufferSize) throws IOException {
return this.outputStream == null
? this.environment.getOutputStream(bufferSize)
: this.outputStream;
}
|
public String getRedirectURL() {
return this.redirectURL;
}
if a redirect should happen this returns the url,
otherwise null is returned |
public void globalRedirect(boolean sessionmode,
String newURL) throws IOException {
if (environment instanceof EnvironmentWrapper) {
((EnvironmentWrapper)environment).globalRedirect(sessionmode, newURL);
} else if ( environment instanceof MutableEnvironmentFacade ) {
((MutableEnvironmentFacade)environment).getDelegate().globalRedirect(sessionmode, newURL);
} else {
environment.redirect(sessionmode,newURL);
}
}
Redirect in the first non-wrapped environment |
public boolean isExternal() {
return false;
}
|
public boolean isInternalRedirect() {
return this.internalRedirect;
}
|
public void redirect(boolean sessionmode,
String newURL) throws IOException {
this.redirectURL = newURL;
// check if session mode shall be activated
if (sessionmode) {
// get session from request, or create new session
request.getSession(true);
}
}
Redirect the client to a new URL is not allowed |
public void reset() {
this.redirectURL = null;
}
|
public void setContentLength(int length) {
// ignore this
}
|
public void setContentType(String contentType) {
this.contentType = contentType;
}
|
public void setInternalRedirect(boolean flag) {
this.internalRedirect = flag;
if ( flag ) {
((RequestWrapper)this.request).setRequestURI(this.prefix.toString(), this.uris);
}
}
|
public void setOutputStream(OutputStream stream) {
this.outputStream = stream;
}
Set the output stream for this environment. It hides the one of the
wrapped environment. |
public void setStatus(int statusCode) {
// ignore this
}
|
public void setURI(String prefix,
String uris) {
if(getLogger().isDebugEnabled()) {
getLogger().debug("Setting uri (prefix=" + prefix + ", uris=" + uris + ")");
}
if ( !this.initializedComponents) {
this.initComponents();
}
if (prefix != null) {
setContext(getRootContext());
setURIPrefix(prefix);
}
this.uris = uris;
}
Set a new URI for processing. If the prefix is null the
new URI is inside the current context.
If the prefix is not null the context is changed to the root
context and the prefix is set. |
public boolean tryResetResponse() throws IOException {
final OutputStream outputStream = getOutputStream(-1);
if (outputStream != null && outputStream instanceof BufferedOutputStream) {
((BufferedOutputStream)outputStream).clearBuffer();
return true;
} else {
return super.tryResetResponse();
}
}
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. |