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.io.Writer;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import javax.servlet.jsp.JspContext;
24 import javax.servlet.jsp.JspException;
25 import javax.servlet.jsp.tagext.JspFragment;
26 import javax.servlet.jsp.tagext.JspTag;
27 import javax.servlet.jsp.tagext.SimpleTag;
28
29 public class MockJspFragment extends JspFragment {
30
31 private JspContext context;
32 private String body = "";
33 private List<JspTag> children = new ArrayList<JspTag>();
34
35 public void setJspContext(JspContext context) {
36 this.context = context;
37 }
38
39 @Override
40 public JspContext getJspContext() {
41 return context;
42 }
43
44 @Override
45 public void invoke(Writer out) throws JspException, IOException {
46 out.write(body);
47 for (JspTag child : children) {
48 if (child instanceof SimpleTag) {
49 SimpleTag simpleTag = (SimpleTag) child;
50 simpleTag.setJspContext(getJspContext());
51 simpleTag.doTag();
52 } else {
53 throw new UnsupportedOperationException();
54 }
55 }
56 }
57
58 public void setBody(String body) {
59 this.body = body;
60 }
61
62 public void addChild(JspTag child) {
63 children.add(child);
64 }
65 }