01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: **/package org.araneaframework.http.service;
16:
17: import java.util.Map;
18: import org.araneaframework.framework.ManagedServiceContext;
19: import org.araneaframework.http.widget.FileDownloaderWidget;
20: import org.araneaframework.uilib.support.FileInfo;
21:
22: /**
23: * Service that serves content (allows downloading) of specified files. It is a suicidal service that
24: * kills itself after having served file content once.
25: *
26: * @author Taimo Peelo (taimo@araneaframework.org)
27: * @author Alar Kvell (alar@araneaframework.org)
28: */
29: public class FileDownloaderService extends FileDownloaderWidget {
30:
31: public FileDownloaderService(FileInfo file) {
32: super (file);
33: }
34:
35: public FileDownloaderService(byte[] fileContent,
36: String contentType, String fileName) {
37: super (fileContent, contentType, fileName);
38: }
39:
40: /** @since 1.1 */
41: public FileDownloaderService(byte[] fileContent, Map headers) {
42: super (fileContent, headers);
43: }
44:
45: protected void close() {
46: //Ensure that allow to download only once...
47: ManagedServiceContext mngCtx = (ManagedServiceContext) getEnvironment()
48: .getEntry(ManagedServiceContext.class);
49: mngCtx.close(mngCtx.getCurrentId());
50: }
51: }
|