1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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.SimpleTag;
27  
28  public class MockJspFragment extends JspFragment {
29  
30  	private JspContext context;
31  	private String  body = "";
32  	private List<SimpleTag> childTags = new ArrayList<SimpleTag>();
33  	
34  	public void setJspContext(JspContext context) {
35  		this.context = context;
36  	}
37  	
38  	@Override
39  	public JspContext getJspContext() {
40  		return context;
41  	}
42  
43  	@Override
44  	public void invoke(Writer out) throws JspException, IOException {
45  		out.write(body);
46  		for (SimpleTag tag : childTags) {
47  			tag.setJspContext(getJspContext());
48  			tag.doTag();
49  		}
50  	}
51  
52  	public void setBody(String body) {
53  		this.body = body;
54  	}
55  
56  	public void addChildTag(SimpleTag childTag) {
57  		childTags.add(childTag);
58  	}
59  }