KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > background > BackgroundEnvironment


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.background;
17
18 import org.apache.avalon.framework.logger.Logger;
19
20 import org.apache.cocoon.environment.AbstractEnvironment;
21 import org.apache.cocoon.environment.Context;
22 import org.apache.cocoon.environment.ObjectModelHelper;
23 import org.apache.cocoon.environment.Request;
24 import org.apache.cocoon.environment.commandline.CommandLineContext;
25 import org.apache.cocoon.environment.commandline.CommandLineRequest;
26 import org.apache.cocoon.environment.commandline.CommandLineResponse;
27 import org.apache.cocoon.util.NullOutputStream;
28
29 import java.io.File JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.io.OutputStream JavaDoc;
32 import java.net.MalformedURLException JavaDoc;
33 import java.util.Collections JavaDoc;
34 import java.util.HashMap JavaDoc;
35
36 /**
37  * A simple implementation of <code>org.apache.cocoon.environment.Environment</code>
38  * for pipeline calls which are not externally triggered.
39  *
40  * @author <a HREF="http://apache.org/~reinhard">Reinhard Poetz</a>
41  * @version CVS $Id: BackgroundEnvironment.java 37181 2004-08-29 17:47:03Z vgritsenko $
42  *
43  * @since 2.1.4
44  */

45 public class BackgroundEnvironment extends AbstractEnvironment {
46
47     public BackgroundEnvironment(Logger logger, Context ctx) throws MalformedURLException JavaDoc {
48         super("", null, new File JavaDoc(ctx.getRealPath("/")), null);
49         enableLogging(logger);
50
51         this.outputStream = new NullOutputStream();
52
53         // TODO Would special Background*-objects have advantages?
54
Request request = new CommandLineRequest(
55                 this, // environment
56
"", // context path
57
"", // servlet path
58
"", // path info
59
new HashMap JavaDoc(), // attributes
60
Collections.EMPTY_MAP, // parameters
61
Collections.EMPTY_MAP // headers
62
);
63         this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request);
64         this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT,
65                              new CommandLineResponse());
66         this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT, ctx);
67     }
68
69     /**
70      * @param uri
71      * @param view
72      * @param context
73      * @param stream
74      * @param log
75      * @throws MalformedURLException
76      */

77     public BackgroundEnvironment(String JavaDoc uri, String JavaDoc view, File JavaDoc context, OutputStream stream, Logger log)
78     throws MalformedURLException JavaDoc {
79
80         super(uri, view, context);
81         this.enableLogging(log);
82         this.outputStream = stream;
83
84         // TODO Would special Background*-objects have advantages?
85
Request request = new CommandLineRequest(this, "", uri, null, null, null);
86         this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request);
87         this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT,
88                              new CommandLineResponse());
89         this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT,
90                              new CommandLineContext(context.getAbsolutePath()));
91     }
92
93     /**
94      * @see org.apache.cocoon.environment.AbstractEnvironment#redirect(boolean, java.lang.String)
95      */

96     public void redirect(boolean sessionmode, String JavaDoc newURL) throws IOException JavaDoc {
97     }
98
99     /**
100      * @see org.apache.cocoon.environment.Environment#setContentType(java.lang.String)
101      */

102     public void setContentType(String JavaDoc mimeType) {
103     }
104
105     /**
106      * @see org.apache.cocoon.environment.Environment#getContentType()
107      */

108     public String JavaDoc getContentType() {
109         return null;
110     }
111
112     /**
113      * @see org.apache.cocoon.environment.Environment#setContentLength(int)
114      */

115     public void setContentLength(int length) {
116     }
117
118     /**
119      * Always return false
120      *
121      * @see org.apache.cocoon.environment.Environment#isExternal()
122      */

123     public boolean isExternal() {
124         return false;
125     }
126 }
127
Popular Tags