1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.struts.flow.core.source.impl;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21
22 import org.apache.struts.flow.core.source.Source;
23 import org.apache.struts.flow.core.source.SourceException;
24 import org.apache.struts.flow.core.source.SourceValidity;
25
26 /***
27 * Abstract base class for a source implementation.
28 *
29 * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
30 * @version CVS $Revision: 1.5 $ $Date: 2004/02/28 11:47:24 $
31 */
32
33 public abstract class AbstractSource
34 implements Source
35 {
36 private boolean m_gotInfos;
37 private long m_lastModificationDate;
38 private long m_contentLength;
39 private String m_systemId;
40
41 private String m_scheme;
42
43 /***
44 * Get the last modification date and content length of the source.
45 * Any exceptions are ignored.
46 * Override this to get the real information
47 */
48 protected void getInfos()
49 {
50 this.m_contentLength = -1;
51 this.m_lastModificationDate = 0;
52 }
53
54 /***
55 * Call {@link #getInfos()} if it hasn't already been called since the last
56 * call to {@link #refresh()}.
57 */
58 protected void checkInfos()
59 {
60 if( !m_gotInfos )
61 {
62 getInfos();
63 m_gotInfos = true;
64 }
65 }
66
67 /***
68 * Return an <code>InputStream</code> object to read from the source.
69 *
70 * The returned stream must be closed by the calling code.
71 *
72 * @throws SourceException if file not found or
73 * HTTP location does not exist.
74 * @throws IOException if I/O error occured.
75 */
76 public InputStream getInputStream()
77 throws IOException, SourceException
78 {
79 return null;
80 }
81
82 /***
83 * Return the unique identifer for this source
84 */
85 public String getURI()
86 {
87 return m_systemId;
88 }
89
90 /***
91 * Return the protocol identifier.
92 */
93 public String getScheme()
94 {
95 return this.m_scheme;
96 }
97
98 /***
99 * Get the Validity object. This can either wrap the last modification
100 * date or the expires information or...
101 * If it is currently not possible to calculate such an information
102 * <code>null</code> is returned.
103 */
104 public SourceValidity getValidity()
105 {
106 return null;
107 }
108
109 /***
110 * Refresh this object and update the last modified date
111 * and content length.
112 */
113 public void refresh()
114 {
115 m_gotInfos = false;
116 }
117
118 /***
119 * The mime-type of the content described by this object.
120 * If the source is not able to determine the mime-type by itself
121 * this can be null.
122 */
123 public String getMimeType()
124 {
125 return null;
126 }
127
128 /***
129 * Return the content length of the content or -1 if the length is
130 * unknown
131 */
132 public long getContentLength()
133 {
134 checkInfos();
135 return this.m_contentLength;
136 }
137
138 /***
139 * Get the last modification date of the source or 0 if it
140 * is not possible to determine the date.
141 */
142 public long getLastModified()
143 {
144 checkInfos();
145 return this.m_lastModificationDate;
146 }
147 /***
148 * Sets the contentLength.
149 * @param contentLength The contentLength to set
150 */
151 protected void setContentLength(long contentLength)
152 {
153 m_contentLength = contentLength;
154 }
155
156 /***
157 * Sets the lastModificationDate.
158 * @param lastModificationDate The lastModificationDate to set
159 */
160 protected void setLastModified(long lastModificationDate)
161 {
162 m_lastModificationDate = lastModificationDate;
163 }
164
165 /***
166 * Sets the scheme.
167 * @param scheme The scheme to set
168 */
169 protected void setScheme(String scheme)
170 {
171 m_scheme = scheme;
172 }
173
174 /***
175 * Sets the systemId.
176 * @param systemId The systemId to set
177 */
178 protected void setSystemId(String systemId)
179 {
180 m_systemId = systemId;
181 }
182
183 }