|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.asset; |
|
16 |
| |
|
17 |
| import java.util.HashMap; |
|
18 |
| import java.util.Iterator; |
|
19 |
| import java.util.List; |
|
20 |
| import java.util.Locale; |
|
21 |
| import java.util.Map; |
|
22 |
| |
|
23 |
| import org.apache.hivemind.Location; |
|
24 |
| import org.apache.hivemind.Resource; |
|
25 |
| import org.apache.hivemind.util.Defense; |
|
26 |
| import org.apache.tapestry.IAsset; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| public class AssetSourceImpl implements AssetSource |
|
35 |
| { |
|
36 |
| private Map _assetFactoryByPrefix = new HashMap(); |
|
37 |
| |
|
38 |
| private List _contributions; |
|
39 |
| |
|
40 |
| private AssetFactory _defaultAssetFactory; |
|
41 |
| |
|
42 |
| private AssetFactory _lookupAssetFactory; |
|
43 |
| |
|
44 |
117
| public void initializeService()
|
|
45 |
| { |
|
46 |
117
| Iterator i = _contributions.iterator();
|
|
47 |
117
| while (i.hasNext())
|
|
48 |
| { |
|
49 |
231
| AssetFactoryContribution c = (AssetFactoryContribution) i.next();
|
|
50 |
| |
|
51 |
231
| _assetFactoryByPrefix.put(c.getPrefix(), c.getFactory());
|
|
52 |
| } |
|
53 |
| } |
|
54 |
| |
|
55 |
1194
| public IAsset findAsset(Resource base, String path, Locale locale, Location location)
|
|
56 |
| { |
|
57 |
1194
| Defense.notNull(base, "base");
|
|
58 |
1194
| Defense.notNull(path, "path");
|
|
59 |
1194
| Defense.notNull(location, "location");
|
|
60 |
| |
|
61 |
1194
| int colonx = path.indexOf(':');
|
|
62 |
| |
|
63 |
1194
| if (colonx < 0)
|
|
64 |
1152
| return _lookupAssetFactory.createAsset(base, path, locale, location);
|
|
65 |
| |
|
66 |
42
| String prefix = path.substring(0, colonx);
|
|
67 |
42
| String truePath = path.substring(colonx + 1);
|
|
68 |
| |
|
69 |
42
| AssetFactory factory = (AssetFactory) _assetFactoryByPrefix.get(prefix);
|
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
42
| if (factory == null)
|
|
75 |
| { |
|
76 |
6
| factory = _defaultAssetFactory;
|
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
6
| truePath = path;
|
|
82 |
| } |
|
83 |
| |
|
84 |
42
| if (truePath.startsWith("/"))
|
|
85 |
27
| return factory.createAbsoluteAsset(truePath, locale, location);
|
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
15
| return factory.createAsset(base, truePath, locale, location);
|
|
90 |
| } |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
117
| public void setLookupAssetFactory(AssetFactory lookupAssetFactory)
|
|
98 |
| { |
|
99 |
117
| _lookupAssetFactory = lookupAssetFactory;
|
|
100 |
| } |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
117
| public void setContributions(List contributions)
|
|
107 |
| { |
|
108 |
117
| _contributions = contributions;
|
|
109 |
| } |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
117
| public void setDefaultAssetFactory(AssetFactory defaultAssetFactory)
|
|
116 |
| { |
|
117 |
117
| _defaultAssetFactory = defaultAssetFactory;
|
|
118 |
| } |
|
119 |
| |
|
120 |
| } |