KickJava   Java API By Example, From Geeks To Geeks.

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

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

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

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

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

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

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

126     public boolean isExternal() {
127         return false;
128     }
129 }
Popular Tags