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.database;
17  
18  import java.util.List;
19  
20  import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
21  import org.seasar.tuigwaa.cms.core.CmsRequest;
22  import org.seasar.tuigwaa.cms.core.CmsResponse;
23  import org.seasar.tuigwaa.cms.core.wiki.WikiContext;
24  import org.seasar.tuigwaa.model.core.TgwEntity;
25  import org.seasar.tuigwaa.model.core.impl.SetAttribute;
26  import org.seasar.tuigwaa.plugin.PluginException;
27  import org.seasar.tuigwaa.plugin.PluginRequest;
28  import org.seasar.tuigwaa.plugin.basic.VelocityPlugin;
29  import org.seasar.tuigwaa.plugin.database.component.ActionLinkFactory;
30  import org.seasar.tuigwaa.plugin.database.component.ResultDto;
31  import org.seasar.tuigwaa.system.Constants;
32  import org.seasar.tuigwaa.util.TgwContext;
33  
34  /***
35   * @author nishioka
36   */
37  public class TablePlugin extends VelocityPlugin {
38  
39  	private static final String TEMPLATE_TABLE = "template/parts/table.vm";
40  
41  	public static void setResult(ResultDto dto) {
42  		SingletonS2ContainerFactory.getContainer().getRequest().setAttribute(
43  				TablePlugin.class.getName() + "/"
44  						+ dto.getEntity().getDomainName() + "/"
45  						+ dto.getEntity().getName(), dto);
46  	}
47  
48  	public static ResultDto getResult(TgwEntity entity) {
49  		if (entity == null) {
50  			return null;
51  		}
52  		return (ResultDto) SingletonS2ContainerFactory.getContainer()
53  				.getRequest().getAttribute(
54  						TablePlugin.class.getName() + "/"
55  								+ entity.getDomainName() + "/"
56  								+ entity.getName());
57  	}
58  
59  	public String doHTMLView(CmsRequest req, CmsResponse res,
60  			PluginRequest prequest) throws PluginException {
61  
62  		String[] args = prequest.getArgs();
63  
64  		// Get Entity And Filter
65  		String domain = req.getSiteName();
66  		String entityName = args[0];
67  		TgwEntity entity = getEntity(domain, entityName);
68  		String filter = (existArg(args, 1)) ? args[1] : null;
69  
70  		int first = 0;
71  		String firstStr = TgwContext.getRequest().getParameter(
72  				Constants.PARAM_ENTITY_FIRST);
73  		String entityParam = TgwContext.getRequest().getParameter(
74  				Constants.PARAM_PREFIX_ENTITY_ESCAPE
75  						+ Constants.PARAM_ENTITY_NAME);
76  		if (firstStr != null && firstStr.length() > 0 && entityParam != null
77  				&& entityParam.equals(entityName)) {
78  			first = Integer.parseInt(firstStr);
79  		}
80  
81  		// Get Ouput Dto
82  		ResultDto dto = getResultDto(req, entity, filter, first);
83  		if (dto == null) {
84  			return null;
85  		}
86  
87  		String child = (String) prequest.getChild();
88  		if (child != null) {
89  			SetAttribute childAttr = (SetAttribute) entity
90  					.getAttributeByDisplayName(child);
91  			dto.setChildAttribute(childAttr);
92  		}
93  
94  		// Set Action Links
95  		WikiContext ctx = getConfiguration().getWikiContext();
96  		List links = new ActionLinkFactory(ctx, entity, req, 2, args).create();
97  		dto.setActionLinks(links);
98  
99  		return doHTMLViewBindingObject(req, res, prequest, dto, TEMPLATE_TABLE);
100 	}
101 }