01: // PushReply.java
02: // $Id: PushReply.java,v 1.1 2001/10/03 15:00:46 ylafon Exp $
03: // (c) COPYRIGHT MIT, INRIA and Keio, 2001.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.www.protocol.http.cache.push;
07:
08: import org.w3c.www.mime.Utils;
09: import org.w3c.www.mime.MimeType;
10:
11: import org.w3c.www.protocol.http.Reply;
12:
13: import java.io.File;
14: import java.io.FileInputStream;
15: import java.io.FileNotFoundException;
16:
17: /**
18: * PushReply
19: * "Forged" Reply for resources inserted into the cache from a push source
20: * Created by PushCacheHandler on receipt of an "ADD" request
21: *
22: * @author Paul Henshaw, The Fantastic Corporation, Paul.Henshaw@fantastic.com
23: * @version $Revision: 1.1 $
24: * $Id: PushReply.java,v 1.1 2001/10/03 15:00:46 ylafon Exp $
25: */
26: public class PushReply extends Reply {
27: /**
28: * Default mime type is "text/html"
29: */
30: public static final String DEFAULT_MIME_TYPE = "text/html";
31:
32: private String _path = null;
33: private String _url = null;
34: private FileInputStream _fis;
35: private File _file;
36:
37: /**
38: * The URL for which the Reply has been forged
39: */
40: public String getUrl() {
41: return (_url);
42: }
43:
44: /**
45: * The file to be stored
46: */
47: public File getFile() {
48: return (_file);
49: }
50:
51: /**
52: * Access to file contents
53: */
54: public FileInputStream getStream() {
55: return (_fis);
56: }
57:
58: /**
59: * Construct a PushReply.
60: * Use PushCacheManager.storeReply to store reply in the cache
61: * Throws a FileNotFoundException if the path specified is not found
62: *
63: * @param path absolute pathname of the file to appear as response
64: * @param url the URL to masquerade as
65: */
66: public PushReply(String path, String url)
67: throws FileNotFoundException {
68: super ((short) 1, (short) 1, 200); // HTTP 1.1, 200 OK
69:
70: _url = new String(url);
71: _path = new String(path);
72: _file = new File(path);
73:
74: _fis = new FileInputStream(_file);
75: setStream(_fis);
76:
77: String mimeType = Utils.guessContentTypeFromName(_url);
78:
79: try {
80: if (mimeType == null || mimeType.equals("content/unknown")) {
81: setContentType(new MimeType(DEFAULT_MIME_TYPE));
82: } else {
83: setContentType(new MimeType(mimeType));
84: }
85: } catch (org.w3c.www.mime.MimeTypeFormatException e) {
86: e.printStackTrace();
87: // SHOULD NEVER HAPPEN
88: }
89:
90: setContentLength((int) _file.length());
91: setValue(PushCacheManager.HEADER_FIELD,
92: PushCacheManager.HEADER_VALUE);
93: }
94: }
|