summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOHyperlink.java
diff options
context:
space:
mode:
Diffstat (limited to 'projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOHyperlink.java')
-rw-r--r--projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOHyperlink.java408
1 files changed, 208 insertions, 200 deletions
diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOHyperlink.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOHyperlink.java
index d0f3ff7..e2041d5 100644
--- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOHyperlink.java
+++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOHyperlink.java
@@ -25,26 +25,30 @@ import net.wotonomy.foundation.NSArray;
import net.wotonomy.foundation.NSDictionary;
/**
-* WOHyperlink renders a dynamically generated hyperlink in the output.
- * Bindings are:
+ * WOHyperlink renders a dynamically generated hyperlink in the output. Bindings
+ * are:
* <ul>
- * <li>string: a string to be included between the hyperlink tags (optional).</li>
+ * <li>string: a string to be included between the hyperlink tags
+ * (optional).</li>
* <li>escapeHTML: a property returning a value convertable to a Boolean
- * indicating whether the any html characters in the output should be
- * escaped so they are shown as html characters rather than interpreted
- * as html.</li>
+ * indicating whether the any html characters in the output should be escaped so
+ * they are shown as html characters rather than interpreted as html.</li>
* <li>href: The URL that the hyperlink should point to.</li>
- * <li>pageName: The name of the WOComponent that the hyperlink should point to.</li>
- * <li>directActionName: The name of the direct action to call when the link is activated.</li>
- * <li>actionClass: The name of the WODirectAction subclass where the direct action resides.</li>
+ * <li>pageName: The name of the WOComponent that the hyperlink should point
+ * to.</li>
+ * <li>directActionName: The name of the direct action to call when the link is
+ * activated.</li>
+ * <li>actionClass: The name of the WODirectAction subclass where the direct
+ * action resides.</li>
* <li>anchorName: The name of the link, for anchor tags.</li>
- * <li>action: A pointer to a method on the component that contains this element. If the link is activated,
- * the method will be called.
+ * <li>action: A pointer to a method on the component that contains this
+ * element. If the link is activated, the method will be called.
* <li>ref: The name of the anchor to go to inside the resulting page.</li>
* </ul>
*
- * The href, pageName and directActionName/actionClass and name properties are mutually exclusive and you should
- * only use at most one of them simultaneously.
+ * The href, pageName and directActionName/actionClass and name properties are
+ * mutually exclusive and you should only use at most one of them
+ * simultaneously.
*
* @author ezamudio@nasoft.com
* @author $Author: cgruber $
@@ -52,198 +56,202 @@ import net.wotonomy.foundation.NSDictionary;
*/
public class WOHyperlink extends WODynamicElement {
- protected String string;
- protected String href;
- protected String pageName;
- protected String directActionName;
- protected String actionClass;
- protected String action;
- protected boolean escapeHTML;
- protected String anchorName;
- protected String ref;
-
- protected WOHyperlink() {
- super();
- }
-
- public WOHyperlink(String aName, NSDictionary aMap, WOElement aRootElement) {
- super(aName, aMap, aRootElement);
- escapeHTML = true;
- }
-
- public void setString(String value) {
- string = value;
- }
- public String string() {
- return string;
- }
-
- public void setHref(String value) {
- href = value;
- }
- public String href() {
- return href;
- }
-
- public void setAnchorName(String value) {
- anchorName = value;
- }
- public String anchorName() {
- return anchorName;
- }
-
- public void setPageName(String value) {
- pageName = value;
- }
- public String pageName() {
- return pageName;
- }
-
- public void setDirectActionName(String value) {
- directActionName = value;
- }
- public String directActionName() {
- return directActionName;
- }
-
- public void setActionClass(String value) {
- actionClass = value;
- }
- public String actionClass() {
- return actionClass;
- }
-
- /** Sets the escapeHTML property. */
- public void setEscapeHTML(boolean escape) {
- escapeHTML = escape;
- }
-
- /** If true, inserts escape codes in to the <B>string</B> string so
- * that HTML special characters (greater-than, less-than, etc.)
- * appear correctly. If false, those characters will get
- * interpreted by the browser. Defaults to true.
- */
- public boolean escapeHTML() {
- return escapeHTML;
- }
-
- public String actionURL(WOContext c) {
- //Check if the href property is set
- if (href() != null) {
- return href();
- } else if (pageName() != null || associations.objectForKey("action") != null) { //write this component's URL
- StringBuffer retval = new StringBuffer(c.componentActionURL());
- Map addFields = urlFields(c.component());
- if (addFields.size() > 0) {
- Iterator enumeration = addFields.keySet().iterator();
- retval.append('?');
- while (enumeration.hasNext()) {
- String encoding = c.response() != null ? c.response().contentEncoding() : c.request().contentEncoding();
- String key = (String)enumeration.next();
- try {
+ protected String string;
+ protected String href;
+ protected String pageName;
+ protected String directActionName;
+ protected String actionClass;
+ protected String action;
+ protected boolean escapeHTML;
+ protected String anchorName;
+ protected String ref;
+
+ protected WOHyperlink() {
+ super();
+ }
+
+ public WOHyperlink(String aName, NSDictionary aMap, WOElement aRootElement) {
+ super(aName, aMap, aRootElement);
+ escapeHTML = true;
+ }
+
+ public void setString(String value) {
+ string = value;
+ }
+
+ public String string() {
+ return string;
+ }
+
+ public void setHref(String value) {
+ href = value;
+ }
+
+ public String href() {
+ return href;
+ }
+
+ public void setAnchorName(String value) {
+ anchorName = value;
+ }
+
+ public String anchorName() {
+ return anchorName;
+ }
+
+ public void setPageName(String value) {
+ pageName = value;
+ }
+
+ public String pageName() {
+ return pageName;
+ }
+
+ public void setDirectActionName(String value) {
+ directActionName = value;
+ }
+
+ public String directActionName() {
+ return directActionName;
+ }
+
+ public void setActionClass(String value) {
+ actionClass = value;
+ }
+
+ public String actionClass() {
+ return actionClass;
+ }
+
+ /** Sets the escapeHTML property. */
+ public void setEscapeHTML(boolean escape) {
+ escapeHTML = escape;
+ }
+
+ /**
+ * If true, inserts escape codes in to the <B>string</B> string so that HTML
+ * special characters (greater-than, less-than, etc.) appear correctly. If
+ * false, those characters will get interpreted by the browser. Defaults to
+ * true.
+ */
+ public boolean escapeHTML() {
+ return escapeHTML;
+ }
+
+ public String actionURL(WOContext c) {
+ // Check if the href property is set
+ if (href() != null) {
+ return href();
+ } else if (pageName() != null || associations.objectForKey("action") != null) { // write this component's URL
+ StringBuffer retval = new StringBuffer(c.componentActionURL());
+ Map addFields = urlFields(c.component());
+ if (addFields.size() > 0) {
+ Iterator enumeration = addFields.keySet().iterator();
+ retval.append('?');
+ while (enumeration.hasNext()) {
+ String encoding = c.response() != null ? c.response().contentEncoding()
+ : c.request().contentEncoding();
+ String key = (String) enumeration.next();
+ try {
retval.append(java.net.URLEncoder.encode(key, encoding));
- } catch (java.io.UnsupportedEncodingException ex) {
- retval.append(key);
- }
- retval.append("=");
+ } catch (java.io.UnsupportedEncodingException ex) {
+ retval.append(key);
+ }
+ retval.append("=");
try {
retval.append(java.net.URLEncoder.encode(addFields.get(key).toString(), encoding));
} catch (java.io.UnsupportedEncodingException e) {
retval.append(addFields.get(key).toString());
}
- if (enumeration.hasNext())
- retval.append('&');
- }
- }
- return retval.toString();
- } else if (directActionName() != null) { //compose the direct action URL
- String fullActionName = null;
- if (actionClass() != null )
- fullActionName = actionClass() + "/" + directActionName();
- else
- fullActionName = directActionName();
- return c.directActionURLForActionNamed(fullActionName, urlFields(c.component()));
- }
- return null;
- }
-
- protected void pullValuesFromParent(WOComponent c) {
- string = stringForProperty("string", c);
- href = stringForProperty("href", c);
- pageName = stringForProperty("pageName", c);
- directActionName = stringForProperty("directActionName", c);
- actionClass = stringForProperty("actionClass", c);
- //action = stringForProperty("action", c);
- escapeHTML = booleanForProperty("escapeHTML", c);
- anchorName = stringForProperty("anchorName", c);
- ref = stringForProperty("ref", c);
- }
-
- public void appendToResponse(WOResponse r, WOContext c) {
- pullValuesFromParent( c.component() );
- r.appendContentString("<A");
- boolean closeQuotes = false;
- //Check if the href property is set
- String _href = actionURL(c);
- if (_href != null) {
- closeQuotes = true;
- r.appendContentString(" HREF=\"");
- r.appendContentString(_href);
- } else if (anchorName() != null) {
- r.appendContentString(" NAME=\"");
- r.appendContentString(anchorName());
- closeQuotes = true;
- }
- if (ref != null) {
- if (!closeQuotes) {
- r.appendContentString(" HREF=\"#");
- closeQuotes = true;
- } else
- r.appendContentString("#");
- r.appendContentString(ref);
- }
- if (closeQuotes)
- r.appendContentString("\"");
- r.appendContentString(additionalHTMLProperties(c.component(), new NSArray(new Object[]{
- "name", "href", "pageName", "action", "directActionName", "actionClass", "anchorName",
- "escapeHTML", "string" })));
- r.appendContentString(">");
- //Append the string if present
- if (string() != null) {
- if (escapeHTML())
- r.appendContentHTMLString(string());
- else
- r.appendContentString(string());
- }
- //If there is a template, call appendToResponse on it
- if (rootElement != null) {
- rootElement.appendToResponse(r, c);
- }
- //Close the tag
- r.appendContentString("</A>");
- }
-
- public WOActionResults invokeAction(WORequest r, WOContext c) {
- System.out.println("invoke action with elementID=" + c.elementID() + " senderID=" + c.senderID());
- //Check if this element is the target
- if (c.senderID().equals(c.elementID())) {
- if (pageName() != null)
- {
- return WOApplication.application().pageWithName(pageName(), r);
- }
- else
- {
- WOAssociation ass = (WOAssociation) associations.objectForKey("action");
- if ( ass != null && ass.path != null ) //??
- return (WOActionResults)c.component().performAction( ass.path );
- }
- }
- return null;
- }
-
- public void takeValuesFromRequest(WORequest r, WOContext c) {
- System.out.println("takeValuesFromRequest elementID=" + c.elementID() + " senderID=" + c.senderID());
- super.takeValuesFromRequest(r, c);
- }
+ if (enumeration.hasNext())
+ retval.append('&');
+ }
+ }
+ return retval.toString();
+ } else if (directActionName() != null) { // compose the direct action URL
+ String fullActionName = null;
+ if (actionClass() != null)
+ fullActionName = actionClass() + "/" + directActionName();
+ else
+ fullActionName = directActionName();
+ return c.directActionURLForActionNamed(fullActionName, urlFields(c.component()));
+ }
+ return null;
+ }
+
+ protected void pullValuesFromParent(WOComponent c) {
+ string = stringForProperty("string", c);
+ href = stringForProperty("href", c);
+ pageName = stringForProperty("pageName", c);
+ directActionName = stringForProperty("directActionName", c);
+ actionClass = stringForProperty("actionClass", c);
+ // action = stringForProperty("action", c);
+ escapeHTML = booleanForProperty("escapeHTML", c);
+ anchorName = stringForProperty("anchorName", c);
+ ref = stringForProperty("ref", c);
+ }
+
+ public void appendToResponse(WOResponse r, WOContext c) {
+ pullValuesFromParent(c.component());
+ r.appendContentString("<A");
+ boolean closeQuotes = false;
+ // Check if the href property is set
+ String _href = actionURL(c);
+ if (_href != null) {
+ closeQuotes = true;
+ r.appendContentString(" HREF=\"");
+ r.appendContentString(_href);
+ } else if (anchorName() != null) {
+ r.appendContentString(" NAME=\"");
+ r.appendContentString(anchorName());
+ closeQuotes = true;
+ }
+ if (ref != null) {
+ if (!closeQuotes) {
+ r.appendContentString(" HREF=\"#");
+ closeQuotes = true;
+ } else
+ r.appendContentString("#");
+ r.appendContentString(ref);
+ }
+ if (closeQuotes)
+ r.appendContentString("\"");
+ r.appendContentString(additionalHTMLProperties(c.component(), new NSArray(new Object[] { "name", "href",
+ "pageName", "action", "directActionName", "actionClass", "anchorName", "escapeHTML", "string" })));
+ r.appendContentString(">");
+ // Append the string if present
+ if (string() != null) {
+ if (escapeHTML())
+ r.appendContentHTMLString(string());
+ else
+ r.appendContentString(string());
+ }
+ // If there is a template, call appendToResponse on it
+ if (rootElement != null) {
+ rootElement.appendToResponse(r, c);
+ }
+ // Close the tag
+ r.appendContentString("</A>");
+ }
+
+ public WOActionResults invokeAction(WORequest r, WOContext c) {
+ System.out.println("invoke action with elementID=" + c.elementID() + " senderID=" + c.senderID());
+ // Check if this element is the target
+ if (c.senderID().equals(c.elementID())) {
+ if (pageName() != null) {
+ return WOApplication.application().pageWithName(pageName(), r);
+ } else {
+ WOAssociation ass = (WOAssociation) associations.objectForKey("action");
+ if (ass != null && ass.path != null) // ??
+ return (WOActionResults) c.component().performAction(ass.path);
+ }
+ }
+ return null;
+ }
+
+ public void takeValuesFromRequest(WORequest r, WOContext c) {
+ System.out.println("takeValuesFromRequest elementID=" + c.elementID() + " senderID=" + c.senderID());
+ super.takeValuesFromRequest(r, c);
+ }
}