2
* This file is part of the SUB Commons project.
3
* Visit the websites for more information.
4
* - http://gdz.sub.uni-goettingen.de
6
* Copyright 2009, Center for Retrospective Digitization, Göttingen (GDZ),
9
* Licensed under the Apache License, Version 2.0 (the “License”);
10
* you may not use this file except in compliance with the License.
11
* You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* Unless required by applicable law or agreed to in writing, software
16
* distributed under the License is distributed on an “AS IS” BASIS,
17
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
* See the License for the specific language governing permissions and
19
* limitations under the License.
21
package de.unigoettingen.sub.commons.util.datasource;
24
import java.io.IOException;
25
import java.net.MalformedURLException;
27
import java.util.ArrayList;
28
import java.util.Arrays;
29
import java.util.List;
32
// TODO: Auto-generated Javadoc
34
* The Class DirectoryListingUrlImageSource.
36
public class DirectoryListingUrlImageSource implements ImageSource {
39
protected File dir = null;
42
private List<File> files = null;
45
* Instantiates a new directory listing url image source.
49
public DirectoryListingUrlImageSource (File dir) {
54
* @see de.unigoettingen.sub.commons.util.datasource.ImageSource#getImage(java.lang.Integer)
56
public Image getImage(Integer pageNr) throws IOException {
58
SimpleUrlImage img = new SimpleUrlImage();
59
img.setPageNumber(pageNr);
60
img.setURL(files.get(pageNr).toURI().toURL());
65
* @see de.unigoettingen.sub.commons.util.datasource.ImageSource#getImageList()
67
public List<? extends Image> getImageList() throws IOException {
69
List<SimpleUrlImage> images = new ArrayList<SimpleUrlImage>();
70
for (int i = 0; i < files.size(); i++) {
71
SimpleUrlImage img = new SimpleUrlImage();
72
img.setPageNumber(i + 1);
73
img.setURL(files.get(i).toURI().toURL());
80
* @see de.unigoettingen.sub.commons.util.datasource.ImageSource#getImageMap()
82
public Map<Integer, ? extends Image> getImageMap() throws IOException {
83
// TODO Auto-generated method stub
88
* @see de.unigoettingen.sub.commons.util.datasource.ImageSource#getNumberOfPages()
90
public Integer getNumberOfPages() {
93
} catch (IOException e) {
100
* @see de.unigoettingen.sub.commons.util.datasource.DataSource#close()
102
public void close() throws IOException {
107
* @see de.unigoettingen.sub.commons.util.datasource.DataSource#getUrl()
109
public URL getUrl() {
111
return dir.toURI().toURL();
112
} catch (MalformedURLException e) {
118
* Checks the given directory and add its contens as list
120
* @throws IOException Signals that an I/O exception has occurred.
122
private void init () throws IOException {
124
if (!dir.isDirectory()) {
125
throw new IOException("Given File is not a directory");
127
files = Arrays.asList(dir.listFiles());
128
//TODO: Filter for supported Filetypes