View Javadoc

1   
2   package net.wotonomy.web;
3   
4   import java.util.Enumeration;
5   
6   import net.wotonomy.foundation.NSDictionary;
7   import net.wotonomy.foundation.NSMutableDictionary;
8   
9   /***
10   * WOActiveImage renders a dynamically generated IMG tag, enclosed in a hyperlink.
11   * Internally, it uses a WOImage and a WOHyperlink to do the actual work.
12   *
13   * The bindings are those of WOImage and WOHyperlink combined.
14   *
15   * @author ezamudio@nasoft.com
16   * @author $Author: cgruber $
17   * @version $Revision: 905 $
18   */
19  public class WOActiveImage extends WODynamicElement {
20  
21      protected WOActiveImage() {
22          super();
23      }
24  
25      public WOActiveImage(String aName, NSDictionary aMap, WOElement template) {
26          super(aName, aMap, template);
27      }
28  
29      public void appendToResponse(WOResponse r, WOContext c) {
30          NSMutableDictionary atribs = new NSMutableDictionary(5);
31          if (associations.objectForKey("mimeType") != null)
32              atribs.setObjectForKey(associations.objectForKey("mimeType"), "mimeType");
33          if (associations.objectForKey("data") != null)
34              atribs.setObjectForKey(associations.objectForKey("data"), "data");
35          if (associations.objectForKey("src") != null)
36              atribs.setObjectForKey(associations.objectForKey("src"), "src");
37          if (associations.objectForKey("framework") != null)
38              atribs.setObjectForKey(associations.objectForKey("framework"), "framework");
39          if (associations.objectForKey("filename") != null)
40              atribs.setObjectForKey(associations.objectForKey("filename"), "filename");
41          if (associations.objectForKey("alt") != null)
42              atribs.setObjectForKey(associations.objectForKey("alt"), "alt");
43          if (associations.objectForKey("border") != null)
44              atribs.setObjectForKey(associations.objectForKey("border"), "border");
45          if (associations.objectForKey("width") != null)
46              atribs.setObjectForKey(associations.objectForKey("width"), "width");
47          if (associations.objectForKey("height") != null)
48              atribs.setObjectForKey(associations.objectForKey("height"), "height");
49          WODynamicElement img = new WOImage("WOImage_" + name, atribs, null);
50          NSMutableDictionary uf = new NSMutableDictionary();
51          Enumeration enumeration = associations.keyEnumerator();
52          while (enumeration.hasMoreElements()) {
53              String key = (String)enumeration.nextElement();
54              if (key.startsWith("?"))
55                  uf.setObjectForKey(associations.objectForKey(key), key);
56          }
57          createLink(img).appendToResponse(r, c);
58      }
59  
60      public WOActionResults invokeAction(WORequest r, WOContext c) {
61          return createLink(null).invokeAction(r, c);
62      }
63  
64      protected WOHyperlink createLink(WOElement e) {
65          NSMutableDictionary atribs = new NSMutableDictionary(5);
66          if (associations.objectForKey("href") != null)
67              atribs.setObjectForKey(associations.objectForKey("href"), "href");
68          if (associations.objectForKey("pageName") != null)
69              atribs.setObjectForKey(associations.objectForKey("pageName"), "pageName");
70          if (associations.objectForKey("action") != null)
71              atribs.setObjectForKey(associations.objectForKey("action"), "action");
72          if (associations.objectForKey("directActionName") != null)
73              atribs.setObjectForKey(associations.objectForKey("directActionName"), "directActionName");
74          if (associations.objectForKey("actionClass") != null)
75              atribs.setObjectForKey(associations.objectForKey("actionClass"), "actionClass");
76          if (associations.objectForKey("target") != null)
77              atribs.setObjectForKey(associations.objectForKey("target"), "target");
78          return new WOHyperlink(name, atribs, e);
79      }
80  
81  }