| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package net.wotonomy.web; |
| 20 |
|
|
| 21 |
|
import java.util.Iterator; |
| 22 |
|
import java.util.Map; |
| 23 |
|
|
| 24 |
|
import net.wotonomy.foundation.NSArray; |
| 25 |
|
import net.wotonomy.foundation.NSDictionary; |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
public class WOHyperlink extends WODynamicElement { |
| 54 |
|
|
| 55 |
|
protected String string; |
| 56 |
|
protected String href; |
| 57 |
|
protected String pageName; |
| 58 |
|
protected String directActionName; |
| 59 |
|
protected String actionClass; |
| 60 |
|
protected String action; |
| 61 |
|
protected boolean escapeHTML; |
| 62 |
|
protected String anchorName; |
| 63 |
|
protected String ref; |
| 64 |
|
|
| 65 |
|
protected WOHyperlink() { |
| 66 |
0 |
super(); |
| 67 |
0 |
} |
| 68 |
|
|
| 69 |
|
public WOHyperlink(String aName, NSDictionary aMap, WOElement aRootElement) { |
| 70 |
0 |
super(aName, aMap, aRootElement); |
| 71 |
0 |
escapeHTML = true; |
| 72 |
0 |
} |
| 73 |
|
|
| 74 |
|
public void setString(String value) { |
| 75 |
0 |
string = value; |
| 76 |
0 |
} |
| 77 |
|
public String string() { |
| 78 |
0 |
return string; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
public void setHref(String value) { |
| 82 |
0 |
href = value; |
| 83 |
0 |
} |
| 84 |
|
public String href() { |
| 85 |
0 |
return href; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
public void setAnchorName(String value) { |
| 89 |
0 |
anchorName = value; |
| 90 |
0 |
} |
| 91 |
|
public String anchorName() { |
| 92 |
0 |
return anchorName; |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
public void setPageName(String value) { |
| 96 |
0 |
pageName = value; |
| 97 |
0 |
} |
| 98 |
|
public String pageName() { |
| 99 |
0 |
return pageName; |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
public void setDirectActionName(String value) { |
| 103 |
0 |
directActionName = value; |
| 104 |
0 |
} |
| 105 |
|
public String directActionName() { |
| 106 |
0 |
return directActionName; |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
public void setActionClass(String value) { |
| 110 |
0 |
actionClass = value; |
| 111 |
0 |
} |
| 112 |
|
public String actionClass() { |
| 113 |
0 |
return actionClass; |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
|
| 117 |
|
public void setEscapeHTML(boolean escape) { |
| 118 |
0 |
escapeHTML = escape; |
| 119 |
0 |
} |
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
public boolean escapeHTML() { |
| 127 |
0 |
return escapeHTML; |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
public String actionURL(WOContext c) { |
| 131 |
|
|
| 132 |
0 |
if (href() != null) { |
| 133 |
0 |
return href(); |
| 134 |
0 |
} else if (pageName() != null || associations.objectForKey("action") != null) { |
| 135 |
0 |
StringBuffer retval = new StringBuffer(c.componentActionURL()); |
| 136 |
0 |
Map addFields = urlFields(c.component()); |
| 137 |
0 |
if (addFields.size() > 0) { |
| 138 |
0 |
Iterator enumeration = addFields.keySet().iterator(); |
| 139 |
0 |
retval.append('?'); |
| 140 |
0 |
while (enumeration.hasNext()) { |
| 141 |
0 |
String encoding = c.response() != null ? c.response().contentEncoding() : c.request().contentEncoding(); |
| 142 |
0 |
String key = (String)enumeration.next(); |
| 143 |
|
try { |
| 144 |
0 |
retval.append(java.net.URLEncoder.encode(key, encoding)); |
| 145 |
0 |
} catch (java.io.UnsupportedEncodingException ex) { |
| 146 |
0 |
retval.append(key); |
| 147 |
0 |
} |
| 148 |
0 |
retval.append("="); |
| 149 |
|
try { |
| 150 |
0 |
retval.append(java.net.URLEncoder.encode(addFields.get(key).toString(), encoding)); |
| 151 |
0 |
} catch (java.io.UnsupportedEncodingException e) { |
| 152 |
0 |
retval.append(addFields.get(key).toString()); |
| 153 |
0 |
} |
| 154 |
0 |
if (enumeration.hasNext()) |
| 155 |
0 |
retval.append('&'); |
| 156 |
0 |
} |
| 157 |
|
} |
| 158 |
0 |
return retval.toString(); |
| 159 |
0 |
} else if (directActionName() != null) { |
| 160 |
0 |
String fullActionName = null; |
| 161 |
0 |
if (actionClass() != null ) |
| 162 |
0 |
fullActionName = actionClass() + "/" + directActionName(); |
| 163 |
|
else |
| 164 |
0 |
fullActionName = directActionName(); |
| 165 |
0 |
return c.directActionURLForActionNamed(fullActionName, urlFields(c.component())); |
| 166 |
|
} |
| 167 |
0 |
return null; |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
protected void pullValuesFromParent(WOComponent c) { |
| 171 |
0 |
string = stringForProperty("string", c); |
| 172 |
0 |
href = stringForProperty("href", c); |
| 173 |
0 |
pageName = stringForProperty("pageName", c); |
| 174 |
0 |
directActionName = stringForProperty("directActionName", c); |
| 175 |
0 |
actionClass = stringForProperty("actionClass", c); |
| 176 |
|
|
| 177 |
0 |
escapeHTML = booleanForProperty("escapeHTML", c); |
| 178 |
0 |
anchorName = stringForProperty("anchorName", c); |
| 179 |
0 |
ref = stringForProperty("ref", c); |
| 180 |
0 |
} |
| 181 |
|
|
| 182 |
|
public void appendToResponse(WOResponse r, WOContext c) { |
| 183 |
0 |
pullValuesFromParent( c.component() ); |
| 184 |
0 |
r.appendContentString("<A"); |
| 185 |
0 |
boolean closeQuotes = false; |
| 186 |
|
|
| 187 |
0 |
String _href = actionURL(c); |
| 188 |
0 |
if (_href != null) { |
| 189 |
0 |
closeQuotes = true; |
| 190 |
0 |
r.appendContentString(" HREF=\""); |
| 191 |
0 |
r.appendContentString(_href); |
| 192 |
0 |
} else if (anchorName() != null) { |
| 193 |
0 |
r.appendContentString(" NAME=\""); |
| 194 |
0 |
r.appendContentString(anchorName()); |
| 195 |
0 |
closeQuotes = true; |
| 196 |
|
} |
| 197 |
0 |
if (ref != null) { |
| 198 |
0 |
if (!closeQuotes) { |
| 199 |
0 |
r.appendContentString(" HREF=\"#"); |
| 200 |
0 |
closeQuotes = true; |
| 201 |
0 |
} else |
| 202 |
0 |
r.appendContentString("#"); |
| 203 |
0 |
r.appendContentString(ref); |
| 204 |
|
} |
| 205 |
0 |
if (closeQuotes) |
| 206 |
0 |
r.appendContentString("\""); |
| 207 |
0 |
r.appendContentString(additionalHTMLProperties(c.component(), new NSArray(new Object[]{ |
| 208 |
0 |
"name", "href", "pageName", "action", "directActionName", "actionClass", "anchorName", |
| 209 |
0 |
"escapeHTML", "string" }))); |
| 210 |
0 |
r.appendContentString(">"); |
| 211 |
|
|
| 212 |
0 |
if (string() != null) { |
| 213 |
0 |
if (escapeHTML()) |
| 214 |
0 |
r.appendContentHTMLString(string()); |
| 215 |
|
else |
| 216 |
0 |
r.appendContentString(string()); |
| 217 |
|
} |
| 218 |
|
|
| 219 |
0 |
if (rootElement != null) { |
| 220 |
0 |
rootElement.appendToResponse(r, c); |
| 221 |
|
} |
| 222 |
|
|
| 223 |
0 |
r.appendContentString("</A>"); |
| 224 |
0 |
} |
| 225 |
|
|
| 226 |
|
public WOActionResults invokeAction(WORequest r, WOContext c) { |
| 227 |
0 |
System.out.println("invoke action with elementID=" + c.elementID() + " senderID=" + c.senderID()); |
| 228 |
|
|
| 229 |
0 |
if (c.senderID().equals(c.elementID())) { |
| 230 |
0 |
if (pageName() != null) |
| 231 |
|
{ |
| 232 |
0 |
return WOApplication.application().pageWithName(pageName(), r); |
| 233 |
|
} |
| 234 |
|
else |
| 235 |
|
{ |
| 236 |
0 |
WOAssociation ass = (WOAssociation) associations.objectForKey("action"); |
| 237 |
0 |
if ( ass != null && ass.path != null ) |
| 238 |
0 |
return (WOActionResults)c.component().performAction( ass.path ); |
| 239 |
|
} |
| 240 |
|
} |
| 241 |
0 |
return null; |
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
public void takeValuesFromRequest(WORequest r, WOContext c) { |
| 245 |
0 |
System.out.println("takeValuesFromRequest elementID=" + c.elementID() + " senderID=" + c.senderID()); |
| 246 |
0 |
super.takeValuesFromRequest(r, c); |
| 247 |
0 |
} |
| 248 |
|
|
| 249 |
|
} |