KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > books > store > source > BookStoreSource


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.books.store.source;
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.books.store.BookInstance;
23 import org.outerx.daisy.x10Bookstoremeta.ResourcePropertiesDocument;
24
25 import java.io.InputStream JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.net.URLConnection JavaDoc;
28
29 public class BookStoreSource implements Source {
30     private BookInstance bookInstance;
31     private String JavaDoc resource;
32
33     public BookStoreSource(BookInstance bookInstance, String JavaDoc resource) {
34         this.bookInstance = bookInstance;
35         this.resource = resource;
36     }
37
38     public boolean exists() {
39         return bookInstance.exists(resource);
40     }
41
42     public InputStream JavaDoc getInputStream() throws IOException JavaDoc, SourceNotFoundException {
43         return bookInstance.getResource(resource);
44     }
45
46     public String JavaDoc getURI() {
47         return "bookstore:" + bookInstance.getName() + "/" + resource;
48     }
49
50     public String JavaDoc getScheme() {
51         return "bookstore";
52     }
53
54     public SourceValidity getValidity() {
55         return new TimeStampValidity(getLastModified());
56     }
57
58     public void refresh() {
59     }
60
61     public String JavaDoc getMimeType() {
62         ResourcePropertiesDocument propertiesDocument = bookInstance.getResourceProperties(resource);
63         String JavaDoc mimeType = (propertiesDocument != null && propertiesDocument.getResourceProperties() != null) ? propertiesDocument.getResourceProperties().getMimeType() : null;
64         if (mimeType == null)
65             mimeType = URLConnection.getFileNameMap().getContentTypeFor(resource);
66         return mimeType;
67     }
68
69     public long getContentLength() {
70         return bookInstance.getContentLength(resource);
71     }
72
73     public long getLastModified() {
74         return bookInstance.getLastModified(resource);
75     }
76 }
77
Popular Tags