View Javadoc

1   /*
2    * Copyright 2004-2006 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.tuigwaa.plugin;
17  
18  import java.io.IOException;
19  
20  import javax.servlet.jsp.JspException;
21  import javax.servlet.jsp.tagext.SimpleTagSupport;
22  
23  import org.seasar.tuigwaa.cms.core.CmsConstants;
24  import org.seasar.tuigwaa.cms.core.CmsRequest;
25  import org.seasar.tuigwaa.cms.core.wiki.base.WikiConfigurationFactory;
26  import org.seasar.tuigwaa.cms.core.wiki.base.WikiException;
27  import org.seasar.tuigwaa.util.TgwContext;
28  
29  public class PluginTag extends SimpleTagSupport {
30  
31  	private String args;
32  
33  	private String name;
34  
35  	public String getArgs() {
36  		return args;
37  	}
38  
39  	public void setArgs(String args) {
40  		this.args = args;
41  	}
42  
43  	public void setName(String pluginName) {
44  		this.name = pluginName;
45  	}
46  
47  	public String getName() {
48  		return name;
49  	}
50  
51  	public void doTag() throws JspException, IOException {
52  		String ret = "";
53  
54  		try {
55  			String[] args = (getArgs() != null) ? getArgs().split(",") : null;
56  			PluginRequest request = new PluginRequest(getName(), args);
57  			Plugin plugin;
58  			plugin = WikiConfigurationFactory.getInstance()
59  					.createConfiguration().getPlugin(getName());
60  			
61  			CmsRequest req = TgwContext.getCmsRequest();
62  			req.setType(CmsConstants.OUTPUTTYPE_HTML);
63  			req.setSiteName(TgwContext.getSiteName());
64  			
65  			ret = (String)plugin.service(TgwContext.getCmsRequest(), TgwContext
66  					.getCmsResponse(), request);
67  		} catch (WikiException e) {
68  			e.printStackTrace();
69  			ret = e.toString();
70  		} catch (PluginException e) {
71  			e.printStackTrace();
72  			ret = e.toString();
73  		}
74  		getJspContext().getOut().write(ret);
75  	}
76  }