KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > components > daisysource > DaisySource


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.daisysource;
17
18 import org.apache.excalibur.source.Source;
19 import org.apache.excalibur.source.SourceNotFoundException;
20 import org.apache.excalibur.source.SourceValidity;
21 import org.apache.excalibur.source.impl.validity.TimeStampValidity;
22 import org.outerj.daisy.publisher.BlobInfo;
23 import org.outerj.daisy.repository.RepositoryException;
24
25 import java.io.InputStream JavaDoc;
26 import java.io.IOException JavaDoc;
27
28 /**
29  * See {@link DaisySourceFactory}.
30  */

31 public class DaisySource implements Source {
32     private BlobInfo blobInfo;
33     private String JavaDoc url;
34
35     public DaisySource(BlobInfo blobInfo, String JavaDoc url) {
36         this.blobInfo = blobInfo;
37         this.url = url;
38     }
39
40     public boolean exists() {
41         return true;
42     }
43
44     public InputStream JavaDoc getInputStream() throws IOException JavaDoc, SourceNotFoundException {
45         try {
46             return blobInfo.getInputStream();
47         } catch (RepositoryException e) {
48             throw new IOException JavaDoc("Error in daisy source: " + e.toString());
49         }
50     }
51
52     public String JavaDoc getURI() {
53         return url;
54     }
55
56     public String JavaDoc getScheme() {
57         return "daisy";
58     }
59
60     public SourceValidity getValidity() {
61         return new TimeStampValidity(getLastModified());
62     }
63
64     public void refresh() {
65     }
66
67     public String JavaDoc getMimeType() {
68         return blobInfo.getMimeType();
69     }
70
71     public long getContentLength() {
72         return blobInfo.getSize();
73     }
74
75     public long getLastModified() {
76         return blobInfo.getLastModified().getTime();
77     }
78
79     public void dispose() {
80         this.blobInfo.dispose();
81     }
82 }
83
Popular Tags