1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.javascript; |
16 |
|
|
17 |
|
import java.util.ArrayList; |
18 |
|
import java.util.List; |
19 |
|
|
20 |
|
import org.apache.hivemind.HiveMind; |
21 |
|
import org.apache.hivemind.Location; |
22 |
|
import org.apache.hivemind.util.URLResource; |
23 |
|
import org.apache.tapestry.IAsset; |
24 |
|
import org.apache.tapestry.TapestryUtils; |
25 |
|
import org.apache.tapestry.asset.AssetSource; |
26 |
|
import org.apache.tapestry.util.DescribedLocation; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
public class JavascriptManagerImpl implements JavascriptManager |
36 |
|
{ |
37 |
|
private AssetSource _assetSource; |
38 |
|
private List _files; |
39 |
|
private List _formFiles; |
40 |
|
private List _widgetFiles; |
41 |
|
private IAsset _path; |
42 |
|
private IAsset _tapestryFile; |
43 |
|
private IAsset _tapestryPath; |
44 |
|
|
45 |
|
public JavascriptManagerImpl() |
46 |
3 |
{ |
47 |
3 |
_files = new ArrayList(); |
48 |
3 |
_formFiles = new ArrayList(); |
49 |
3 |
_widgetFiles = new ArrayList(); |
50 |
3 |
} |
51 |
|
|
52 |
|
public IAsset getFirstAsset() |
53 |
|
{ |
54 |
3 |
return findFirst(_files); |
55 |
|
} |
56 |
|
|
57 |
|
public IAsset getFirstFormAsset() |
58 |
|
{ |
59 |
2 |
return findFirst(_formFiles); |
60 |
|
} |
61 |
|
|
62 |
|
public IAsset getFirstWidgetAsset() |
63 |
|
{ |
64 |
2 |
return findFirst(_widgetFiles); |
65 |
|
} |
66 |
|
|
67 |
|
public List getAssets() |
68 |
|
{ |
69 |
3 |
return _files; |
70 |
|
} |
71 |
|
|
72 |
|
public List getFormAssets() |
73 |
|
{ |
74 |
2 |
return _formFiles; |
75 |
|
} |
76 |
|
|
77 |
|
public List getWidgetAssets() |
78 |
|
{ |
79 |
2 |
return _widgetFiles; |
80 |
|
} |
81 |
|
|
82 |
|
public IAsset getPath() |
83 |
|
{ |
84 |
2 |
return _path; |
85 |
|
} |
86 |
|
|
87 |
|
public IAsset getTapestryAsset() |
88 |
|
{ |
89 |
3 |
return _tapestryFile; |
90 |
|
} |
91 |
|
|
92 |
|
public IAsset getTapestryPath() |
93 |
|
{ |
94 |
2 |
return _tapestryPath; |
95 |
|
} |
96 |
|
|
97 |
|
public void setFiles(String files) |
98 |
|
{ |
99 |
2 |
_files = buildAssetList(files, "files"); |
100 |
2 |
} |
101 |
|
|
102 |
|
public void setFormFiles(String formFiles) |
103 |
|
{ |
104 |
2 |
_formFiles = buildAssetList(formFiles, "formFiles"); |
105 |
2 |
} |
106 |
|
|
107 |
|
public void setWidgetFiles(String widgetFiles) |
108 |
|
{ |
109 |
2 |
_widgetFiles = buildAssetList(widgetFiles, "widgetFiles"); |
110 |
2 |
} |
111 |
|
|
112 |
|
public void setFolder(String path) |
113 |
|
{ |
114 |
2 |
_path = findAsset(path, "folder"); |
115 |
2 |
} |
116 |
|
|
117 |
|
public void setTapestryFile(String tapestryFile) |
118 |
|
{ |
119 |
2 |
_tapestryFile = findAsset(tapestryFile, "tapestryFile"); |
120 |
2 |
} |
121 |
|
|
122 |
|
public void setTapestryFolder(String tapestryPath) |
123 |
|
{ |
124 |
2 |
_tapestryPath = findAsset(tapestryPath, "tapestryFolder"); |
125 |
2 |
} |
126 |
|
|
127 |
|
public void setAssetSource(AssetSource assetSource) |
128 |
|
{ |
129 |
3 |
_assetSource = assetSource; |
130 |
3 |
} |
131 |
|
|
132 |
|
private List buildAssetList(String files, String name) |
133 |
|
{ |
134 |
6 |
String[] js = TapestryUtils.split(files); |
135 |
|
|
136 |
6 |
List list = new ArrayList(js.length); |
137 |
8 |
for (int i=0; i<js.length; i++) { |
138 |
2 |
list.add(findAsset(js[i], name + i)); |
139 |
|
} |
140 |
|
|
141 |
6 |
return list; |
142 |
|
} |
143 |
|
|
144 |
|
private IAsset findAsset(String path, String description) |
145 |
|
{ |
146 |
8 |
IAsset asset = null; |
147 |
8 |
if ( !HiveMind.isBlank(path) ) |
148 |
|
{ |
149 |
3 |
Location location = new DescribedLocation(new URLResource(path), description); |
150 |
3 |
asset = _assetSource.findAsset(null, path, null, location); |
151 |
|
} |
152 |
8 |
return asset; |
153 |
|
} |
154 |
|
|
155 |
|
private IAsset findFirst(List list) |
156 |
|
{ |
157 |
7 |
if (list == null || list.isEmpty()) |
158 |
6 |
return null; |
159 |
|
else |
160 |
1 |
return (IAsset) list.get(0); |
161 |
|
} |
162 |
|
} |