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