KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > jwi > jgallery > WebImageAccessor


1 package de.jwi.jgallery;
2
3 /*
4  * jGallery - Java web application to display image galleries
5  *
6  * Copyright (C) 2004 Juergen Weber
7  *
8  * This file is part of jGallery.
9  *
10  * jGallery is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * jGallery is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with jGallery; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston
23  */

24
25 import java.io.File JavaDoc;
26 import java.io.FileNotFoundException JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.net.URL JavaDoc;
30 import java.net.URLConnection JavaDoc;
31
32 /**
33  * @author Jürgen Weber
34  * Source file created on 07.03.2004
35  *
36  */

37 public class WebImageAccessor implements IImageAccessor
38 {
39
40     private String JavaDoc name;
41
42     private WebFolder folder;
43
44     InputStream JavaDoc imageInputStream;
45     InputStream JavaDoc thumbInputStream;
46     File JavaDoc directory;
47     
48     private long lastModified;
49     private long length;
50     
51     private String JavaDoc baseURL;
52     private String JavaDoc folderPath;
53
54     WebImageAccessor(String JavaDoc name, WebFolder folder)
55     {
56         this.name = name;
57         this.folder = folder;
58         baseURL = folder.getBaseURL();
59         folderPath = folder.getFolderPath();
60     }
61
62     
63     public InputStream JavaDoc getImageInputStream()
64     throws FileNotFoundException JavaDoc
65     {
66         
67         URL JavaDoc url;
68         URLConnection JavaDoc connection;
69         
70         try
71         {
72             url = new URL JavaDoc(folderPath + "/" + name);
73             connection = url.openConnection();
74             connection.connect();
75         }
76         catch (Exception JavaDoc e)
77         {
78             throw new FileNotFoundException JavaDoc(e.getMessage());
79         }
80         
81         try
82         {
83             imageInputStream = connection.getInputStream();
84         }
85         catch (IOException JavaDoc e)
86         {
87             throw new FileNotFoundException JavaDoc(e.getMessage());
88         }
89         
90         lastModified = connection.getLastModified();
91         length = connection.getContentLength();
92         
93         return imageInputStream;
94     }
95
96     public long getLastModified()
97     {
98         return lastModified;
99     }
100
101     public long getLength()
102     {
103         return length;
104     }
105     
106     
107     public InputStream JavaDoc getThumbInputStream()
108     throws FileNotFoundException JavaDoc
109     {
110         
111         URL JavaDoc url;
112         URLConnection JavaDoc connection;
113         
114         try
115         {
116             url = new URL JavaDoc(folderPath + folder.getThumbsdir() + "/" + name);
117             connection = url.openConnection();
118             connection.connect();
119         }
120         catch (Exception JavaDoc e)
121         {
122             throw new FileNotFoundException JavaDoc(e.getMessage());
123         }
124         
125         try
126         {
127             imageInputStream = connection.getInputStream();
128         }
129         catch (IOException JavaDoc e)
130         {
131             throw new FileNotFoundException JavaDoc(e.getMessage());
132         }
133         
134         lastModified = connection.getLastModified();
135         length = connection.getContentLength();
136         
137         return imageInputStream;
138     }
139     
140     
141 }
142
Popular Tags