1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.seasar.cubby.tags;
18
19 import java.io.IOException;
20 import java.util.List;
21
22 import javax.servlet.jsp.JspException;
23 import javax.servlet.jsp.tagext.BodyContent;
24 import javax.servlet.jsp.tagext.BodyTag;
25 import javax.servlet.jsp.tagext.JspTag;
26 import javax.servlet.jsp.tagext.SimpleTag;
27 import javax.servlet.jsp.tagext.Tag;
28
29 abstract class AbstractStandardTagTestCase extends AbstractTagTestCase {
30
31 protected void setupBodyTag(BodyTag tag) {
32 tag.setPageContext(context);
33 }
34
35 protected void doLifecycle(Tag tag) throws JspException, IOException {
36 doLifecycle(tag, null);
37 }
38
39 protected void doLifecycle(Tag tag, ChildrenFactory childrenFactory)
40 throws JspException, IOException {
41 int reuslt = tag.doStartTag();
42 if (tag instanceof BodyTag) {
43 BodyTag bodyTag = (BodyTag) tag;
44 if (reuslt == BodyTag.EVAL_BODY_BUFFERED) {
45 BodyContent bodyContent = context.pushBody();
46 bodyTag.setBodyContent(bodyContent);
47 }
48 bodyTag.doInitBody();
49 if (childrenFactory != null) {
50 List<JspTag> children = childrenFactory.create();
51 if (children != null) {
52 for (JspTag child : children) {
53 if (child instanceof SimpleTag) {
54 SimpleTag simpleTag = (SimpleTag) child;
55 simpleTag.setJspBody(jspBody);
56 simpleTag.setJspContext(context);
57 simpleTag.setParent(tag);
58 } else {
59 throw new UnsupportedOperationException();
60 }
61 jspBody.addChild(child);
62 }
63 }
64 }
65 jspBody.invoke(context.getOut());
66 bodyTag.doAfterBody();
67 if (reuslt == BodyTag.EVAL_BODY_BUFFERED) {
68 context.popBody();
69 }
70 }
71 tag.doEndTag();
72 }
73
74 interface ChildrenFactory {
75 List<JspTag> create();
76 }
77
78 }