KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > components > skinsource > SkinSource


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
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.frontend.components.skinsource;
17
18 import org.apache.excalibur.source.Source;
19 import org.apache.excalibur.source.SourceNotFoundException;
20 import org.apache.excalibur.source.SourceValidity;
21
22 import java.io.*;
23 import java.net.URLConnection JavaDoc;
24
25 public class SkinSource implements Source {
26     private File file;
27     private String JavaDoc uri;
28
29     public SkinSource(File file, String JavaDoc uri) {
30         this.file = file;
31         this.uri = uri;
32     }
33
34     public boolean exists() {
35         return file.exists();
36     }
37
38     public InputStream getInputStream() throws IOException, SourceNotFoundException {
39         try {
40             return new FileInputStream(file);
41         } catch (FileNotFoundException fnfe) {
42             throw new SourceNotFoundException(uri + " doesn't exist.", fnfe);
43         }
44     }
45
46     public String JavaDoc getURI() {
47         return uri;
48     }
49
50     public String JavaDoc getScheme() {
51         return "daisyskin";
52     }
53
54     public SourceValidity getValidity() {
55         if (file.exists()) {
56             return new SkinSourceValidity(file);
57         } else {
58             return null;
59         }
60     }
61
62     public void refresh() {
63         // nothing to do
64
}
65
66     public String JavaDoc getMimeType() {
67         return URLConnection.getFileNameMap().getContentTypeFor(file.getName());
68     }
69
70     public long getContentLength() {
71         return file.length();
72     }
73
74     public long getLastModified() {
75         return file.lastModified();
76     }
77 }
78
Popular Tags