01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
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: */
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;
26: import java.io.IOException;
27:
28: /**
29: * See {@link DaisySourceFactory}.
30: */
31: public class DaisySource implements Source {
32: private BlobInfo blobInfo;
33: private String url;
34:
35: public DaisySource(BlobInfo blobInfo, String url) {
36: this .blobInfo = blobInfo;
37: this .url = url;
38: }
39:
40: public boolean exists() {
41: return true;
42: }
43:
44: public InputStream getInputStream() throws IOException,
45: SourceNotFoundException {
46: try {
47: return blobInfo.getInputStream();
48: } catch (RepositoryException e) {
49: throw new IOException("Error in daisy source: "
50: + e.toString());
51: }
52: }
53:
54: public String getURI() {
55: return url;
56: }
57:
58: public String getScheme() {
59: return "daisy";
60: }
61:
62: public SourceValidity getValidity() {
63: return new TimeStampValidity(getLastModified());
64: }
65:
66: public void refresh() {
67: }
68:
69: public String getMimeType() {
70: return blobInfo.getMimeType();
71: }
72:
73: public long getContentLength() {
74: return blobInfo.getSize();
75: }
76:
77: public long getLastModified() {
78: return blobInfo.getLastModified().getTime();
79: }
80:
81: public void dispose() {
82: this.blobInfo.dispose();
83: }
84: }
|