View Javadoc

1   /*
2    * This file was automatically generated by Apache Tiles Autotag.
3    */
4   package org.apache.tiles.velocity.template;
5   
6   import java.io.IOException;
7   import java.io.Writer;
8   
9   import org.apache.tiles.autotag.core.runtime.ModelBody;
10  import org.apache.tiles.autotag.core.runtime.AutotagRuntime;
11  import org.apache.velocity.context.InternalContextAdapter;
12  import org.apache.velocity.runtime.directive.Directive;
13  import org.apache.velocity.runtime.parser.node.Node;
14  
15  /**
16   * <p>
17   * <strong>Put an attribute in enclosing attribute container tag.</strong>
18   * </p>
19   * <p>
20   * Enclosing attribute container tag can be :
21   * <ul>
22   * <li>&lt;initContainer&gt;</li>
23   * <li>&lt;definition&gt;</li>
24   * <li>&lt;insertAttribute&gt;</li>
25   * <li>&lt;insertDefinition&gt;</li>
26   * <li>&lt;putListAttribute&gt;</li>
27   * </ul>
28   * (or any other tag which implements the <code>PutAttributeTagParent</code>
29   * interface. Exception is thrown if no appropriate tag can be found.
30   * </p>
31   * <p>
32   * Put tag can have following atributes :
33   * <ul>
34   * <li>name : Name of the attribute</li>
35   * <li>value : value to put as attribute</li>
36   * <li>type : value type. Possible type are : string (value is used as direct
37   * string), template (value is used as a page url to insert), definition (value
38   * is used as a definition name to insert), object (value is used as it is)</li>
39   * <li>role : Role to check when 'insertAttribute' will be called.</li>
40   * </ul>
41   * </p>
42   * <p>
43   * Value can also come from tag body. Tag body is taken into account only if
44   * value is not set by one of the tag attributes. In this case Attribute type is
45   * "string", unless tag body define another type.
46   * </p>
47   */
48  public class PutAttributeDirective extends Directive {
49  
50      /**
51       * The template model.
52       */
53      private org.apache.tiles.template.PutAttributeModel model = new org.apache.tiles.template.PutAttributeModel();
54  
55      /** {@inheritDoc} */
56      @Override
57      public String getName() {
58          return "tiles_putAttribute";
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public int getType() {
64          return BLOCK;
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public boolean render(InternalContextAdapter context, Writer writer, Node node)
70              throws IOException {
71          AutotagRuntime<org.apache.tiles.request.Request> runtime = new org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime();
72          if (runtime instanceof Directive) {
73              ((Directive) runtime).render(context, writer, node);
74          }
75          org.apache.tiles.request.Request request = runtime.createRequest();
76          ModelBody modelBody = runtime.createModelBody();
77          model.execute(
78              runtime.getParameter("name", java.lang.String.class, null),
79              runtime.getParameter("value", java.lang.Object.class, null),
80              runtime.getParameter("expression", java.lang.String.class, null),
81              runtime.getParameter("role", java.lang.String.class, null),
82              runtime.getParameter("type", java.lang.String.class, null),
83              runtime.getParameter("cascade", java.lang.Boolean.class, false),
84              request, modelBody
85          );
86          return true;
87      }
88  }