|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
WindowOpenLinkRenderer.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
* Joey and its relative products are published under the terms
|
|
3 |
* of the Apache Software License.
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Created on 2004/01/03
|
|
7 |
*/
|
|
8 |
package org.asyrinx.brownie.tapestry.components.link;
|
|
9 |
|
|
10 |
import java.util.HashMap;
|
|
11 |
import java.util.Map;
|
|
12 |
|
|
13 |
import org.apache.tapestry.ApplicationRuntimeException;
|
|
14 |
import org.apache.tapestry.IMarkupWriter;
|
|
15 |
import org.apache.tapestry.IRequestCycle;
|
|
16 |
import org.apache.tapestry.IScript;
|
|
17 |
import org.apache.tapestry.components.ILinkComponent;
|
|
18 |
import org.apache.tapestry.engine.ILink;
|
|
19 |
import org.apache.tapestry.html.Body;
|
|
20 |
import org.apache.tapestry.link.ILinkRenderer;
|
|
21 |
import org.asyrinx.brownie.core.lang.StringUtils;
|
|
22 |
import org.asyrinx.brownie.tapestry.util.ValueTagWriter;
|
|
23 |
|
|
24 |
/**
|
|
25 |
* @author akima
|
|
26 |
*/
|
|
27 |
public class WindowOpenLinkRenderer extends AbstractScriptLinkRenderer { |
|
28 |
|
|
29 |
public static final ILinkRenderer SHARED_INSTANCE = new WindowOpenLinkRenderer(); |
|
30 |
|
|
31 |
/**
|
|
32 |
*
|
|
33 |
*/
|
|
34 | 0 |
public WindowOpenLinkRenderer() {
|
35 | 0 |
super("WindowOpenLinkRenderer.script"); |
36 |
} |
|
37 |
|
|
38 |
/**
|
|
39 |
* @see org.asyrinx.brownie.tapestry.components.link.AbstractScriptLinkRenderer#checkBeforeRender(org.apache.tapestry.IRequestCycle,
|
|
40 |
* org.apache.tapestry.components.ILinkComponent)
|
|
41 |
*/
|
|
42 | 0 |
protected void checkBeforeRender(IRequestCycle cycle, |
43 |
ILinkComponent linkComponent) { |
|
44 | 0 |
super.checkBeforeRender(cycle, linkComponent);
|
45 | 0 |
if (!(linkComponent instanceof IWindowOpenOption)) |
46 | 0 |
throw new ApplicationRuntimeException( |
47 |
"must-be-implemented-IWindowOpenOption", this, null, null); |
|
48 |
} |
|
49 |
|
|
50 |
public static final String CLICK_LINK_ROW_METHOD_NAME = "clickLink"; |
|
51 |
|
|
52 |
private static final String HREF_DUMMY = "javascript:void(0);"; |
|
53 |
|
|
54 |
public static final String SYM_METHOD_CLICK_ROW = "clickLinkMethodName"; |
|
55 |
|
|
56 |
public static final String SYM_OPTIONS = "options"; |
|
57 |
|
|
58 |
/**
|
|
59 |
* @see org.asyrinx.brownie.tapestry.components.link.AbstractScriptLinkRenderer#addScript(org.apache.tapestry.IRequestCycle,
|
|
60 |
* org.apache.tapestry.IScript, org.apache.tapestry.html.Body)
|
|
61 |
*/
|
|
62 | 0 |
protected void addScript(IRequestCycle cycle, IScript script, Body body) { |
63 | 0 |
final Map symbols = new HashMap();
|
64 | 0 |
symbols.put(SYM_METHOD_CLICK_ROW, CLICK_LINK_ROW_METHOD_NAME); |
65 | 0 |
script.execute(cycle, body, symbols); |
66 |
} |
|
67 |
|
|
68 |
/**
|
|
69 |
* @see org.asyrinx.brownie.tapestry.components.link.AbstractScriptLinkRenderer#renderBeginTag(org.apache.tapestry.IMarkupWriter,
|
|
70 |
* org.apache.tapestry.IRequestCycle,
|
|
71 |
* org.apache.tapestry.components.ILinkComponent)
|
|
72 |
*/
|
|
73 | 0 |
protected void renderBeginTag(IMarkupWriter writer, IRequestCycle cycle, |
74 |
ILinkComponent linkComponent) { |
|
75 | 0 |
if (getHasBody())
|
76 | 0 |
writer.begin(getElement()); |
77 |
else
|
|
78 | 0 |
writer.beginEmpty(getElement()); |
79 | 0 |
writer.attribute("href", HREF_DUMMY);
|
80 | 0 |
writer.attribute("onclick", CLICK_LINK_ROW_METHOD_NAME + "(this)"); |
81 |
} |
|
82 |
|
|
83 |
/**
|
|
84 |
* @see org.asyrinx.brownie.tapestry.components.link.AbstractScriptLinkRenderer#renderBody(org.apache.tapestry.IMarkupWriter,
|
|
85 |
* org.apache.tapestry.IRequestCycle,
|
|
86 |
* org.apache.tapestry.components.ILinkComponent)
|
|
87 |
*/
|
|
88 | 0 |
protected void renderBody(IMarkupWriter bodyWriter, IRequestCycle cycle, |
89 |
ILinkComponent linkComponent) { |
|
90 | 0 |
final ILink l = linkComponent.getLink(cycle); |
91 | 0 |
bodyWriter.println(); |
92 | 0 |
addIdValueSpan(bodyWriter, "href", constructURL(l, linkComponent
|
93 |
.getAnchor())); |
|
94 |
// linkComponent will be checked before here
|
|
95 | 0 |
final IWindowOpenOption option = (IWindowOpenOption) linkComponent; |
96 | 0 |
addIdValueSpan(bodyWriter, "target", option.getWindowTarget());
|
97 | 0 |
bodyWriter.println(); |
98 |
//
|
|
99 | 0 |
bodyWriter.begin("span");
|
100 | 0 |
bodyWriter.attribute("id", "options"); |
101 | 0 |
bodyWriter.attribute("style", "display:none"); |
102 | 0 |
bodyWriter.println(); |
103 | 0 |
final Map options = new HashMap();
|
104 | 0 |
options.put("toolbar", option.getWindowToolbar());
|
105 | 0 |
options.put("location", option.getWindowLocation());
|
106 | 0 |
options.put("directories", option.getWindowDirectories());
|
107 | 0 |
options.put("status", option.getWindowStatus());
|
108 | 0 |
options.put("menubar", option.getWindowMenubar());
|
109 | 0 |
options.put("scrollbars", option.getWindowScrollbars());
|
110 | 0 |
options.put("resizable", option.getWindowResizable());
|
111 | 0 |
options.put("width", option.getWindowWidth());
|
112 | 0 |
options.put("height", option.getWindowHeight());
|
113 | 0 |
options.put("left", option.getWindowLeft());
|
114 | 0 |
options.put("top", option.getWindowTop());
|
115 | 0 |
final IMarkupWriter nestedWriter = bodyWriter.getNestedWriter(); |
116 | 0 |
final ValueTagWriter tagWriter = new ValueTagWriter(nestedWriter);
|
117 | 0 |
tagWriter.addProperties(options); |
118 | 0 |
nestedWriter.close(); |
119 | 0 |
bodyWriter.end(); |
120 |
} |
|
121 |
|
|
122 | 0 |
private static void addIdValueSpan(IMarkupWriter writer, String id, |
123 |
String value) { |
|
124 | 0 |
if (StringUtils.isEmpty(value))
|
125 | 0 |
return;
|
126 | 0 |
writer.begin("span");
|
127 | 0 |
writer.attribute("id", id);
|
128 | 0 |
writer.attribute("style", "display:none"); |
129 | 0 |
final IMarkupWriter innerDivWriter = writer.getNestedWriter(); |
130 | 0 |
innerDivWriter.printRaw(value); |
131 | 0 |
innerDivWriter.close(); |
132 | 0 |
writer.end(); |
133 |
} |
|
134 |
|
|
135 |
/**
|
|
136 |
* @return
|
|
137 |
*/
|
|
138 | 0 |
private String getElement() {
|
139 | 0 |
return "a"; |
140 |
} |
|
141 |
} |
|