1   /*
2    * Copyright 2004-2010 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  
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  }