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.List; |
18 |
|
|
19 |
|
import org.apache.tapestry.IAsset; |
20 |
|
import org.apache.tapestry.IMarkupWriter; |
21 |
|
import org.apache.tapestry.IPage; |
22 |
|
import org.apache.tapestry.IRender; |
23 |
|
import org.apache.tapestry.IRequestCycle; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
public class SimpleAjaxShellDelegate implements IRender |
30 |
|
{ |
31 |
|
private static final String SYSTEM_NEWLINE = "\n"; |
32 |
|
|
33 |
|
private JavascriptManager _javascriptManager; |
34 |
|
|
35 |
|
public SimpleAjaxShellDelegate(JavascriptManager javascriptManager) |
36 |
0 |
{ |
37 |
0 |
_javascriptManager = javascriptManager; |
38 |
0 |
} |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
public void render(IMarkupWriter writer, IRequestCycle cycle) |
44 |
|
{ |
45 |
0 |
StringBuffer str = new StringBuffer(300); |
46 |
|
|
47 |
0 |
processPath(str, cycle, _javascriptManager.getPath()); |
48 |
|
|
49 |
|
|
50 |
0 |
appendAssetsAsJavascript(str, cycle, _javascriptManager.getAssets()); |
51 |
|
|
52 |
0 |
IPage page = cycle.getPage(); |
53 |
0 |
if (page.hasFormComponents()) |
54 |
|
{ |
55 |
0 |
appendAssetsAsJavascript(str, cycle, _javascriptManager.getFormAssets()); |
56 |
|
} |
57 |
0 |
if (page.hasWidgets()) |
58 |
|
{ |
59 |
0 |
appendAssetsAsJavascript(str, cycle, _javascriptManager.getWidgetAssets()); |
60 |
|
} |
61 |
|
|
62 |
0 |
processTapestryPath(str, cycle, _javascriptManager.getTapestryPath()); |
63 |
|
|
64 |
|
|
65 |
0 |
IAsset tapestryAsset = _javascriptManager.getTapestryAsset(); |
66 |
0 |
if (tapestryAsset!=null) |
67 |
|
{ |
68 |
0 |
appendAssetAsJavascript(str, cycle, tapestryAsset); |
69 |
|
} |
70 |
|
|
71 |
0 |
writer.printRaw(str.toString()); |
72 |
0 |
writer.println(); |
73 |
0 |
} |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
protected void processPath(StringBuffer str, IRequestCycle cycle, IAsset path) |
83 |
|
{ |
84 |
0 |
} |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
protected void processTapestryPath(StringBuffer str, IRequestCycle cycle, IAsset path) |
94 |
|
{ |
95 |
0 |
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
protected void appendAssetAsJavascript(StringBuffer str, IRequestCycle cycle, IAsset asset) |
104 |
|
{ |
105 |
0 |
final String url = asset.buildURL(); |
106 |
0 |
str.append("<script type=\"text/javascript\" src=\"").append(url) |
107 |
|
.append("\"></script>").append(SYSTEM_NEWLINE); |
108 |
|
|
109 |
0 |
} |
110 |
|
|
111 |
|
private void appendAssetsAsJavascript(StringBuffer str, IRequestCycle cycle, List jsAssets) |
112 |
|
{ |
113 |
0 |
for (int i = 0; i < jsAssets.size(); i++) |
114 |
|
{ |
115 |
0 |
appendAssetAsJavascript(str, cycle, (IAsset) jsAssets.get(i)); |
116 |
|
} |
117 |
0 |
} |
118 |
|
} |