1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.plugin.database;
17
18 import java.util.Map;
19
20 import org.seasar.tuigwaa.cms.core.CmsRequest;
21 import org.seasar.tuigwaa.cms.core.CmsResponse;
22 import org.seasar.tuigwaa.model.core.TgwEntity;
23 import org.seasar.tuigwaa.plugin.AbstractTgwPlugin;
24 import org.seasar.tuigwaa.plugin.PluginException;
25 import org.seasar.tuigwaa.plugin.PluginRequest;
26 import org.seasar.tuigwaa.plugin.database.component.ResultDto;
27 import org.seasar.tuigwaa.system.ServiceHelper;
28 import org.seasar.tuigwaa.view.HtmlService;
29 import org.seasar.tuigwaa.view.SearchFormComponent;
30
31 import com.isenshi.util.JSONUtils;
32 import com.isenshi.util.LabelValue;
33
34 public class SearchFormPlugin extends AbstractTgwPlugin {
35
36 private ServiceHelper helper = (ServiceHelper) getService(ServiceHelper.class);
37
38 private HtmlService htmlService = (HtmlService) getService(HtmlService.class);
39
40 public String doHTMLView(CmsRequest request, CmsResponse response,
41 PluginRequest prequest) throws PluginException {
42
43 String[] args = prequest.getArgs();
44
45 String siteName = request.getSiteName();
46 String entityName = args[0];
47 TgwEntity entity = getEntity(siteName, entityName);
48
49 LabelValue lv = new LabelValue(args[1]);
50 String sformName = lv.getLabel();
51 String searchLegend = lv.getValue();
52
53 SearchFormComponent sform = helper.getSearchForm(entity, sformName);
54
55 setForwardPage(sform, request, args);
56 setMax(sform, args);
57 setExtraFilterName(sform, args);
58
59 ResultDto dto = TablePlugin.getResult(entity);
60 if (dto != null && sformName.equals(dto.getSearchName())) {
61 sform.setValueObject(dto.getSearchDto());
62 }
63
64 sform.setDisplayName(searchLegend);
65
66 String child = (String) prequest.getChild();
67 if (child != null && !child.equals("")) {
68 Map dispMap = JSONUtils.toMap(child);
69 sform.setAlternateDisplayMap(dispMap);
70 }
71 return htmlService.toHtml(sform);
72 }
73
74 private void setForwardPage(SearchFormComponent sform, CmsRequest request,
75 String[] args) {
76 String forwardPageName = null;
77 if (existArg(args, 2)) {
78 forwardPageName = args[2];
79 } else {
80 forwardPageName = request.getPage().getResource().getPath();
81 }
82 sform.setForwardPageName(forwardPageName);
83 }
84
85 private void setMax(SearchFormComponent sform, String[] args) {
86 int max = 0;
87 if (existArg(args, 3)) {
88 max = Integer.parseInt(args[3]);
89 }
90 sform.setMax(max);
91 }
92
93 private void setExtraFilterName(SearchFormComponent sform, String[] args) {
94 if (existArg(args, 4)) {
95 sform.setExtraFilterName(args[4]);
96 }
97 }
98 }