01: /* AbstractLoader.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Fri Jun 3 09:45:42 2005, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.util.resource;
20:
21: import java.io.File;
22: import java.io.IOException;
23: import java.net.URL;
24:
25: /**
26: * A skeletal implementation that assumes the source is either URL or File.
27: *
28: * @author tomyeh
29: */
30: abstract public class AbstractLoader implements Loader {
31: //-- Loader --//
32: public boolean shallCheck(Object src, long expiredMillis) {
33: return expiredMillis > 0;
34: //FUTURE: prolong if src.url's protocol is http, https or ftp
35: }
36:
37: public long getLastModified(Object src) {
38: if (src instanceof URL) {
39: //Due to round-trip, we don't retrieve last-modified
40: final URL url = (URL) src;
41: final String protocol = url.getProtocol().toLowerCase();
42: if (!"http".equals(protocol) && !"https".equals(protocol)
43: && !"ftp".equals(protocol)) {
44: try {
45: return url.openConnection().getLastModified();
46: } catch (IOException ex) {
47: return -1; //reload
48: }
49: }
50: return -1; //reload
51: } else if (src instanceof File) {
52: return ((File) src).lastModified();
53: } else if (src == null) {
54: throw new NullPointerException();
55: } else {
56: throw new IllegalArgumentException("Unknown soruce: " + src
57: + "\nOnly File and URL are supported");
58: }
59: }
60: }
|