1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.catalina;
18
19 import java.io.InputStream;
20 import java.net.URL;
21 import java.security.cert.Certificate;
22 import java.util.jar.Manifest;
23
24 /**
25  * Represents a file or directory within a web application. It borrows heavily
26  * from {@link java.io.File}.
27  */

28 public interface WebResource {
29     /**
30      * @return {@link java.io.File#lastModified()}.
31      */

32     long getLastModified();
33
34     /**
35      * @return the last modified time of this resource in the correct format for
36      * the HTTP Last-Modified header as specified by RFC 2616.
37      */

38     String getLastModifiedHttp();
39
40     /**
41      * @return {@link java.io.File#exists()}.
42      */

43     boolean exists();
44
45     /**
46      * Indicates if this resource is required for applications to correctly scan
47      * the file structure but that does not exist in either the main or any
48      * additional {@link WebResourceSet}. For example, if an external
49      * directory is mapped to /WEB-INF/lib in an otherwise empty web
50      * application, /WEB-INF will be represented as a virtual resource.
51      *
52      * @return <code>true</code> for a virtual resource
53      */

54     boolean isVirtual();
55
56     /**
57      * @return {@link java.io.File#isDirectory()}.
58      */

59     boolean isDirectory();
60
61     /**
62      * @return {@link java.io.File#isFile()}.
63      */

64     boolean isFile();
65
66     /**
67      * @return {@link java.io.File#delete()}.
68      */

69     boolean delete();
70
71     /**
72      * @return {@link java.io.File#getName()}.
73      */

74     String getName();
75
76     /**
77      * @return {@link java.io.File#length()}.
78      */

79     long getContentLength();
80
81     /**
82      * @return {@link java.io.File#getCanonicalPath()}.
83      */

84     String getCanonicalPath();
85
86     /**
87      * @return {@link java.io.File#canRead()}.
88      */

89     boolean canRead();
90
91     /**
92      * @return The path of this resource relative to the web application root. If the
93      * resource is a directory, the return value will end in '/'.
94      */

95     String getWebappPath();
96
97     /**
98      * Return the strong ETag if available (currently not supported) else return
99      * the weak ETag calculated from the content length and last modified.
100      *
101      * @return  The ETag for this resource
102      */

103     String getETag();
104
105     /**
106      * Set the MIME type for this Resource.
107      *
108      * @param mimeType The mime type that will be associated with the resource
109      */

110     void setMimeType(String mimeType);
111
112     /**
113      * @return the MIME type for this Resource.
114      */

115     String getMimeType();
116
117     /**
118      * Obtain an InputStream based on the contents of this resource.
119      *
120      * @return  An InputStream based on the contents of this resource or
121      *          <code>null</code> if the resource does not exist or does not
122      *          represent a file
123      */

124     InputStream getInputStream();
125
126     /**
127      * @return the binary content of this resource or {@code nullif it is not
128      *         available in a byte[] because, for example, it is too big.
129      */

130     byte[] getContent();
131
132     /**
133      * @return The time the file was created. If not available, the result of
134      * {@link #getLastModified()} will be returned.
135      */

136     long getCreation();
137
138     /**
139      * @return a URL to access the resource or <code>null</code> if no such URL
140      * is available or if the resource does not exist.
141      */

142     URL getURL();
143
144     /**
145      * @return the code base for this resource that will be used when looking up the
146      * assigned permissions for the code base in the security policy file when
147      * running under a security manager.
148      */

149     URL getCodeBase();
150
151     /**
152      * @return a reference to the WebResourceRoot of which this WebResource is a
153      * part.
154      */

155     WebResourceRoot getWebResourceRoot();
156
157     /**
158      * @return the certificates that were used to sign this resource to verify
159      * it or @null if none.
160      *
161      * @see java.util.jar.JarEntry#getCertificates()
162      */

163     Certificate[] getCertificates();
164
165     /**
166      * @return the manifest associated with this resource or @null if none.
167      *
168      * @see java.util.jar.JarFile#getManifest()
169      */

170     Manifest getManifest();
171 }
172