View Javadoc

1   /*
2    Wotonomy: OpenStep design patterns for pure Java applications.
3    Copyright (C) 2000 Blacksmith, Inc.
4   
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9   
10   This library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14  
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, see http://www.gnu.org
17   */
18  
19  package net.wotonomy.web;
20  
21  import net.wotonomy.foundation.NSArray;
22  import net.wotonomy.foundation.NSDictionary;
23  
24  /***
25   * Used to generate any HTML element dynamically. It only creates the opening tag without a closing tag.
26   * To generate HTML elements that have opening and closing tags, as well as some content in between,
27   * use WOGenericContainer instead.
28   * @author michael@mpowers.net
29   * @author $Author: cgruber $
30   * @version $Revision: 905 $
31   */
32  public class WOGenericElement extends WODynamicElement {
33  
34      static NSArray bindings = new NSArray( new Object[] 
35          { "elementName", "omitTags", "elementID", "otherTagString",
36            "formValue", "formValues", "invokeAction" } );
37            
38      public WOGenericElement() {
39          super();
40      }
41  
42      public WOGenericElement(String n, NSDictionary m, WOElement t) {
43          super(n, m, t);
44      }
45  
46      public String elementName(WOContext c) {
47          String x = (String)valueForProperty("elementName", c.component());
48          if (x != null)
49              return x;
50          return c.elementID();
51      }
52  
53      public void takeValuesFromRequest(WORequest r, WOContext c) {
54          if ( c.elementID().equals( c.senderID() ) )
55          {
56              Object value;
57              value = r.formValueForKey( c.elementID() );
58              setValueForProperty( "formValue", value, c.component() );
59              value = r.formValuesForKey( c.elementID() );
60              setValueForProperty( "formValues", value, c.component() );
61          }
62      }
63  
64      public WOActionResults invokeAction(WORequest r, WOContext c) 
65      {
66          WOActionResults result = null;
67          String action = stringForProperty( "invokeAction", c.component() );
68          if ( action != null && c.elementID().equals( c.senderID() ) )
69          {
70              result = c.component().performAction( action );
71          }
72          return result;
73      }
74      
75      public void appendToResponse(WOResponse r, WOContext c) {
76          WOComponent component = c.component();
77          if ( !booleanForProperty( "omitTags", component ) )
78          {
79              r.appendContentString("<");
80              r.appendContentString(elementName(c));
81              String other = stringForProperty( "otherTagString", component );
82              if ( other != null )
83              {
84                  r.appendContentString( " " );
85                  r.appendContentString( other );
86              }
87              String add = additionalHTMLProperties(component, bindings);
88              if (add.length() > 0)
89                  r.appendContentString(add);
90              r.appendContentString(">");
91          }
92          setValueForProperty( "elementID", c.elementID(), component );
93      }
94  
95  }