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