001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.environment.background;
018:
019: import org.apache.avalon.framework.logger.Logger;
020:
021: import org.apache.cocoon.environment.AbstractEnvironment;
022: import org.apache.cocoon.environment.Context;
023: import org.apache.cocoon.environment.ObjectModelHelper;
024: import org.apache.cocoon.environment.Request;
025: import org.apache.cocoon.environment.commandline.CommandLineContext;
026: import org.apache.cocoon.environment.commandline.CommandLineRequest;
027: import org.apache.cocoon.environment.commandline.CommandLineResponse;
028: import org.apache.cocoon.util.NullOutputStream;
029:
030: import java.io.File;
031: import java.io.IOException;
032: import java.io.OutputStream;
033: import java.net.MalformedURLException;
034: import java.util.Collections;
035: import java.util.HashMap;
036:
037: /**
038: * A simple implementation of <code>org.apache.cocoon.environment.Environment</code>
039: * for pipeline calls which are not externally triggered.
040: *
041: * @author <a href="http://apache.org/~reinhard">Reinhard Poetz</a>
042: * @version CVS $Id: BackgroundEnvironment.java 433543 2006-08-22 06:22:54Z crossley $
043: *
044: * @since 2.1.4
045: */
046: public class BackgroundEnvironment extends AbstractEnvironment {
047:
048: public BackgroundEnvironment(Logger logger, Context ctx)
049: throws MalformedURLException {
050: super ("", null, new File(ctx.getRealPath("/")), null);
051: enableLogging(logger);
052:
053: this .outputStream = new NullOutputStream();
054:
055: // TODO Would special Background*-objects have advantages?
056: Request request = new CommandLineRequest(this , // environment
057: "", // context path
058: "", // servlet path
059: "", // path info
060: new HashMap(), // attributes
061: Collections.EMPTY_MAP, // parameters
062: Collections.EMPTY_MAP // headers
063: );
064: this .objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request);
065: this .objectModel.put(ObjectModelHelper.RESPONSE_OBJECT,
066: new CommandLineResponse());
067: this .objectModel.put(ObjectModelHelper.CONTEXT_OBJECT, ctx);
068: }
069:
070: /**
071: * @param uri
072: * @param view
073: * @param context
074: * @param stream
075: * @param log
076: * @throws MalformedURLException
077: */
078: public BackgroundEnvironment(String uri, String view, File context,
079: OutputStream stream, Logger log)
080: throws MalformedURLException {
081:
082: super (uri, view, context);
083: this .enableLogging(log);
084: this .outputStream = stream;
085:
086: // TODO Would special Background*-objects have advantages?
087: Request request = new CommandLineRequest(this , "", uri, null,
088: null, null);
089: this .objectModel.put(ObjectModelHelper.REQUEST_OBJECT, request);
090: this .objectModel.put(ObjectModelHelper.RESPONSE_OBJECT,
091: new CommandLineResponse());
092: this .objectModel.put(ObjectModelHelper.CONTEXT_OBJECT,
093: new CommandLineContext(context.getAbsolutePath()));
094: }
095:
096: /**
097: * @see org.apache.cocoon.environment.AbstractEnvironment#redirect(boolean, java.lang.String)
098: */
099: public void redirect(boolean sessionmode, String newURL)
100: throws IOException {
101: }
102:
103: /**
104: * @see org.apache.cocoon.environment.Environment#setContentType(java.lang.String)
105: */
106: public void setContentType(String mimeType) {
107: }
108:
109: /**
110: * @see org.apache.cocoon.environment.Environment#getContentType()
111: */
112: public String getContentType() {
113: return null;
114: }
115:
116: /**
117: * @see org.apache.cocoon.environment.Environment#setContentLength(int)
118: */
119: public void setContentLength(int length) {
120: }
121:
122: /**
123: * Always return false
124: *
125: * @see org.apache.cocoon.environment.Environment#isExternal()
126: */
127: public boolean isExternal() {
128: return false;
129: }
130: }
|