1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.nuiton.util;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 import javax.xml.transform.Source;
29 import javax.xml.transform.stream.StreamSource;
30 import java.net.URL;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public class FasterCachedResourceResolver extends ResourceResolver {
53
54
55 private static final Log log = LogFactory.getLog(FasterCachedResourceResolver.class);
56
57 protected boolean offline;
58
59 public FasterCachedResourceResolver() {
60 this(null);
61 }
62
63 public FasterCachedResourceResolver(String base) {
64 super(base);
65 }
66
67 public void setOffline(boolean offline) {
68 this.offline = offline;
69 }
70
71 @Override
72 protected Source findHrefSource(String path) {
73 long t0 = System.nanoTime();
74 String resource = "META-INF/cache/" + path;
75
76 if (verbose) {
77 log.info("will discover " + resource);
78 }
79
80 URL url = cl.getResource(resource);
81
82 Source source = null;
83
84 if (url != null) {
85 if (verbose) {
86 log.info(url.toString());
87 }
88 source = new StreamSource(url.toString());
89 }
90 if (source == null) {
91 if (offline) {
92 throw new IllegalStateException("offline - could not find extact resource at location " + resource);
93 }
94 log.warn("could not find extact resource at location " + resource);
95 }
96 if (verbose) {
97 log.info("resolved in " + StringUtil.convertTime(System.nanoTime() - t0));
98 }
99 return source;
100 }
101 }