1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.wcm.webui.search;
18
19 import javax.portlet.PortletMode;
20 import javax.portlet.PortletPreferences;
21
22 import org.exoplatform.ecm.resolver.JCRResourceResolver;
23 import org.exoplatform.portal.webui.container.UIContainer;
24 import org.exoplatform.resolver.ResourceResolver;
25 import org.exoplatform.services.cms.impl.DMSConfiguration;
26 import org.exoplatform.webui.application.WebuiRequestContext;
27 import org.exoplatform.webui.application.portlet.PortletRequestContext;
28 import org.exoplatform.webui.config.annotation.ComponentConfig;
29 import org.exoplatform.webui.config.annotation.EventConfig;
30 import org.exoplatform.webui.core.lifecycle.Lifecycle;
31 import org.exoplatform.webui.event.Event;
32 import org.exoplatform.webui.event.EventListener;
33
34
35
36
37
38 @ComponentConfig(
39 lifecycle = Lifecycle.class,
40 events = {
41 @EventConfig(listeners = UISearchPageLayout.QuickEditActionListener.class)
42 }
43 )
44 public class UISearchPageLayout extends UIContainer {
45
46
47 public static final String SEARCH_FORM = "uiSearchForm";
48
49
50 public static final String SEARCH_RESULT = "uiSearchResult";
51
52
53
54
55
56
57 public UISearchPageLayout() throws Exception {
58 WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
59 UISearchForm uiSearchForm = addChild(UISearchForm.class, null, null);
60 UISearchResult uiSearchResult = addChild(UISearchResult.class, null, null);
61 String searchFormTemplatePath = getTemplatePath(UIWCMSearchPortlet.SEARCH_FORM_TEMPLATE_PATH);
62 uiSearchForm.init(searchFormTemplatePath, getTemplateResourceResolver(context,
63 searchFormTemplatePath));
64 String searchResultTemplatePath = getTemplatePath(UIWCMSearchPortlet.SEARCH_RESULT_TEMPLATE_PATH);
65 uiSearchResult.init(searchResultTemplatePath,
66 getTemplateResourceResolver(context, searchResultTemplatePath));
67 }
68
69
70
71
72
73
74 private PortletPreferences getPortletPreference() {
75 PortletRequestContext portletRequestContext = WebuiRequestContext.getCurrentInstance();
76 return portletRequestContext.getRequest().getPreferences();
77 }
78
79
80
81
82
83
84
85
86 private String getTemplatePath(String templateType) {
87 return getPortletPreference().getValue(templateType, null);
88 }
89
90
91
92
93
94 public String getTemplate() {
95 String template = getPortletPreference().getValue(UIWCMSearchPortlet.SEARCH_PAGE_LAYOUT_TEMPLATE_PATH,
96 null);
97 return template;
98 }
99
100
101
102
103
104
105
106 public ResourceResolver getTemplateResourceResolver(WebuiRequestContext context, String template) {
107 try {
108 DMSConfiguration dmsConfiguration = getApplicationComponent(DMSConfiguration.class);
109 String workspace = dmsConfiguration.getConfig().getSystemWorkspace();
110 return new JCRResourceResolver(workspace);
111 } catch (Exception e) {
112 return null;
113 }
114 }
115
116
117
118
119
120
121 public String getPortletId() {
122 PortletRequestContext pContext = (PortletRequestContext) WebuiRequestContext.getCurrentInstance();
123 return pContext.getWindowId();
124 }
125
126
127
128
129
130
131
132
133
134
135 public static class QuickEditActionListener extends EventListener<UISearchPageLayout> {
136
137
138
139
140
141
142
143 public void execute(Event<UISearchPageLayout> event) throws Exception {
144 PortletRequestContext context = (PortletRequestContext) event.getRequestContext();
145 context.setApplicationMode(PortletMode.EDIT);
146 }
147 }
148 }