KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > Environment


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.environment;
17
18 import java.io.IOException JavaDoc;
19 import java.io.OutputStream JavaDoc;
20 import java.util.Enumeration JavaDoc;
21 import java.util.Map JavaDoc;
22
23 /**
24  * Base interface for an environment abstraction
25  *
26  * @author <a HREF="mailto:bluetkemeier@s-und-n.de">Bj&ouml;rn L&uuml;tkemeier</a>
27  * @author <a HREF="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
28  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
29  * @version CVS $Id: Environment.java 30932 2004-07-29 17:35:38Z vgritsenko $
30  */

31 public interface Environment
32     extends SourceResolver {
33
34     /**
35      * Get the URI to process. The prefix is stripped off.
36      */

37     String JavaDoc getURI();
38
39     /**
40      * Get the prefix of the URI in progress.
41      */

42     String JavaDoc getURIPrefix();
43
44     /**
45      * Get the Root Context
46      */

47     String JavaDoc getRootContext();
48
49     /**
50      * Get current context
51      */

52     String JavaDoc getContext();
53
54     /**
55      * Get the view to process
56      */

57     String JavaDoc getView();
58
59     /**
60      * Get the action to process
61      */

62     String JavaDoc getAction();
63
64     /**
65      * Set the context. This is similar to changeContext()
66      * except that it is absolute.
67      */

68     void setContext(String JavaDoc prefix, String JavaDoc uri, String JavaDoc context);
69
70     /**
71      * Change the context from uriprefix to context
72      */

73     void changeContext(String JavaDoc uriprefix, String JavaDoc context) throws Exception JavaDoc;
74
75     /**
76      * Redirect to the given URL
77      */

78     void redirect(boolean sessionmode, String JavaDoc url) throws IOException JavaDoc;
79
80     /**
81      * Set the content type of the generated resource
82      */

83     void setContentType(String JavaDoc mimeType);
84
85     /**
86      * Get the content type of the resource
87      */

88     String JavaDoc getContentType();
89
90     /**
91      * Set the length of the generated content
92      */

93     void setContentLength(int length);
94
95     /**
96      * Set the response status code
97      */

98     void setStatus(int statusCode);
99
100     /**
101      * Get the output stream where to write the generated resource.
102      * @deprecated Use {@link #getOutputStream(int)} instead.
103      */

104     OutputStream JavaDoc getOutputStream() throws IOException JavaDoc;
105
106     /**
107      * Get the output stream where to write the generated resource.
108      * The returned stream is buffered by the environment. If the
109      * buffer size is -1 then the complete output is buffered.
110      * If the buffer size is 0, no buffering takes place.
111      * This method replaces {@link #getOutputStream()}.
112      */

113     OutputStream JavaDoc getOutputStream(int bufferSize) throws IOException JavaDoc;
114
115     /**
116      * Get the underlying object model
117      */

118     Map JavaDoc getObjectModel();
119
120     /**
121      * Check if the response has been modified since the same
122      * "resource" was requested.
123      * The caller has to test if it is really the same "resource"
124      * which is requested.
125      * @return true if the response is modified or if the
126      * environment is not able to test it
127      */

128     boolean isResponseModified(long lastModified);
129
130     /**
131      * Mark the response as not modified.
132      */

133     void setResponseIsNotModified();
134
135     /**
136      * Binds an object to this environment, using the name specified. This allows
137      * the pipeline assembly engine to store for its own use objects that souldn't
138      * be exposed to other components (generators, selectors, etc) and therefore
139      * cannot be put in the object model.
140      * <p>
141      * If an object of the same name is already bound, the object is replaced.
142      *
143      * @param name the name to which the object is bound
144      * @param value the object to be bound
145      */

146     void setAttribute(String JavaDoc name, Object JavaDoc value);
147
148     /**
149      * Returns the object bound with the specified name, or <code>null</code>
150      * if no object is bound under the name.
151      *
152      * @param name a string specifying the name of the object
153      * @return the object with the specified name
154      */

155     Object JavaDoc getAttribute(String JavaDoc name);
156
157     /**
158      * Removes the object bound with the specified name from
159      * this environment. If the environment does not have an object
160      * bound with the specified name, this method does nothing.
161      *
162      * @param name the name of the object to remove
163      */

164     void removeAttribute(String JavaDoc name);
165
166     /**
167      * Returns an <code>Enumeration</code> of <code>String</code> objects
168      * containing the names of all the objects bound to this environment.
169      *
170      * @return an <code>Enumeration</code> of <code>String</code>s.
171      */

172     Enumeration JavaDoc getAttributeNames();
173
174     /**
175      * Reset the response if possible. This allows error handlers to have
176      * a higher chance to produce clean output if the pipeline that raised
177      * the error has already output some data.
178      * If a buffered output stream is used, resetting is always successful.
179      *
180      * @return true if the response was successfully reset
181      */

182     boolean tryResetResponse() throws IOException JavaDoc;
183
184
185     /**
186      * Commit the response
187      */

188     void commitResponse() throws IOException JavaDoc;
189     
190     /**
191      * Notify that the processing starts.
192      */

193     void startingProcessing();
194     
195     /**
196      * Notify that the processing is finished
197      * This can be used to cleanup the environment object
198      */

199     void finishingProcessing();
200     
201     /**
202      * Is this environment external ? An external environment is one that
203      * is created in response to an external request (http, commandline, etc.).
204      * Environments created by the "cocoon:" protocol aren't external.
205      *
206      * @return true if this environment is external
207      */

208     boolean isExternal();
209     
210     /**
211      * Is this an internal redirect?
212      * An environment is on internal redirect if it is an internal request
213      * (via the cocoon: protocol) and used for a redirect.
214      */

215     boolean isInternalRedirect();
216 }
217
218
Popular Tags