1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.define;
17
18 import org.apache.commons.jelly.JellyTagException;
19 import org.apache.commons.jelly.Script;
20 import org.apache.commons.jelly.Tag;
21 import org.apache.commons.jelly.TagSupport;
22 import org.apache.commons.jelly.XMLOutput;
23 import org.apache.commons.jelly.impl.DynamicTag;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 /***
28 * <invokeBody> tag is used inside a <tag> tag
29 * (i.e. the definition of a dynamic tag) to invoke the tags body when
30 * the tag is invoked.
31 *
32 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
33 * @version $Revision: 155420 $
34 */
35 public class InvokeBodyTag extends TagSupport {
36
37 /*** The Log to which logging calls will be made. */
38 private static final Log log = LogFactory.getLog(InvokeBodyTag.class);
39
40 public InvokeBodyTag() {
41 }
42
43
44
45 public void doTag(XMLOutput output) throws JellyTagException {
46
47 Script script = (Script) context.getVariable("org.apache.commons.jelly.body");
48 if (script != null) {
49 script.run(context, output);
50 }
51 else {
52
53
54 Tag tag = findAncestorWithClass(this, DynamicTag.class);
55 if (tag == null) {
56 throw new JellyTagException("Cannot invoke body, no dynamic tag is defined in this block");
57 }
58 else {
59 tag.invokeBody(output);
60 }
61 }
62 }
63 }