1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.jsr168.web.portlet;
35
36 import fr.paris.lutece.plugins.jsr168.business.portlet.Jsr168Portlet;
37 import fr.paris.lutece.plugins.jsr168.business.portlet.Jsr168PortletHome;
38 import fr.paris.lutece.plugins.jsr168.pluto.LuteceToPlutoConnector;
39 import fr.paris.lutece.plugins.jsr168.pluto.core.PortalURL;
40 import fr.paris.lutece.portal.business.portlet.PortletHome;
41 import fr.paris.lutece.portal.service.template.AppTemplateService;
42 import fr.paris.lutece.portal.web.portlet.PortletJspBean;
43 import fr.paris.lutece.util.ReferenceList;
44 import fr.paris.lutece.util.html.HtmlTemplate;
45
46 import java.util.HashMap;
47
48 import javax.servlet.http.HttpServletRequest;
49
50
51
52
53
54 public class Jsr168PortletJspBean extends PortletJspBean
55 {
56
57
58
59
60 public static final String RIGHT_MANAGE_ADMIN_SITE = "CORE_ADMIN_SITE";
61 private static final String ADMIN_SITE = "../../site/AdminSite.jsp";
62 private static final String MESSAGE_MANDATORY_PORTLET_TITLE = "../../Message.jsp?message=mandatory.portlet.title";
63 private static final String PARAM_PAGE_ID = "page_id";
64 private static final String PARAM_PORTLET_ID = "portlet_id";
65 private static final String PARAM_PORTLET_TYPE_ID = "portlet_type_id";
66 private static final String PARAM_JSR168_NAME = "jsr168_name";
67 private static final String BOOKMARK_JSR168_TITLE_COMBO = "@jsr168_title_combo@";
68
69
70 private static final String MARK_PORTLET_LIST = "portlet_list";
71 private static final String MARK_PORTLET_ID = "default_portlet_id";
72
73
74 private static final String TEMPLATE_COMBO_PORTLETS = "admin/plugins/jsr168/portlet/combo_portletsJSR.html";
75 private static final String COMBO_PORTLETS_LIST = "@combo_portletsJSR@";
76
77
78
79
80 public Jsr168PortletJspBean( )
81 {
82 }
83
84
85
86
87
88
89 public String getPropertiesPrefix( )
90 {
91 return "portlet.jsr168";
92 }
93
94
95
96
97
98
99
100 public String getCreate( HttpServletRequest request )
101 {
102 System.out.println( "in getCreate" );
103
104 String strPageId = request.getParameter( PARAM_PAGE_ID );
105 String strPortletTypeId = request.getParameter( PARAM_PORTLET_TYPE_ID );
106 HtmlTemplate template = getCreateTemplate( strPageId, strPortletTypeId );
107
108 System.out.println( "Template before :" );
109 System.out.println( template.getHtml( ) );
110
111 ReferenceList portletsList = LuteceToPlutoConnector.getPortletTitles( );
112
113 String strHtmlCombo = getPortletIndexCombo( portletsList, "" );
114 template.substitute( BOOKMARK_JSR168_TITLE_COMBO, strHtmlCombo );
115 System.out.println( "out getCreate" );
116 System.out.println( "Template after :" );
117 System.out.println( template.getHtml( ) );
118
119 return template.getHtml( );
120 }
121
122
123
124
125
126
127
128 public String getModify( HttpServletRequest request )
129 {
130 String strPortletId = request.getParameter( PARAM_PORTLET_ID );
131 int nPortletId = Integer.parseInt( strPortletId );
132 Jsr168Portlet portlet = (Jsr168Portlet) PortletHome.findByPrimaryKey( nPortletId );
133 HtmlTemplate template = getModifyTemplate( portlet );
134
135 ReferenceList portletsList = LuteceToPlutoConnector.getPortletTitles( );
136
137 String strHtmlCombo = getPortletIndexCombo( portletsList, portlet.getJsr168Name( ) );
138 template.substitute( BOOKMARK_JSR168_TITLE_COMBO, strHtmlCombo );
139
140 return template.getHtml( );
141 }
142
143
144
145
146
147
148
149 public String doCreate( HttpServletRequest request )
150 {
151 Jsr168Portlet portlet = new Jsr168Portlet( );
152
153
154 setPortletCommonData( request, portlet );
155
156
157 String strName = portlet.getName( );
158
159 if ( ( strName == null ) || "".equals( strName.trim( ) ) )
160 {
161 return MESSAGE_MANDATORY_PORTLET_TITLE;
162 }
163
164
165 String strPageId = request.getParameter( PARAM_PAGE_ID );
166 int nPageId = Integer.parseInt( strPageId );
167 portlet.setPageId( nPageId );
168
169
170 String strContent = request.getParameter( PARAM_JSR168_NAME );
171 portlet.setJsr168Name( strContent );
172
173
174 Jsr168PortletHome.getInstance( ).create( portlet );
175
176
177 return ADMIN_SITE + "?" + PARAM_PAGE_ID + "=" + portlet.getPageId( );
178 }
179
180
181
182
183
184
185
186 public String doModify( HttpServletRequest request )
187 {
188
189 String strPortletId = request.getParameter( PARAM_PORTLET_ID );
190 int nPortletId = Integer.parseInt( strPortletId );
191 Jsr168Portlet portlet = (Jsr168Portlet) PortletHome.findByPrimaryKey( nPortletId );
192
193
194 setPortletCommonData( request, portlet );
195
196
197 String strName = portlet.getName( );
198
199 if ( ( strName == null ) || "".equals( strName.trim( ) ) )
200 {
201 return MESSAGE_MANDATORY_PORTLET_TITLE;
202 }
203
204
205 String strContent = request.getParameter( PARAM_JSR168_NAME );
206 portlet.setJsr168Name( strContent );
207
208
209 portlet.update( );
210
211
212 return ADMIN_SITE + "?" + PARAM_PAGE_ID + "=" + portlet.getPageId( );
213 }
214
215
216
217
218
219
220
221
222
223
224 public boolean realiseAction( HttpServletRequest request )
225 {
226 final String strPortletId = PortalURL.extractPortletId( request );
227
228 final int nPortletId = Integer.parseInt( strPortletId );
229 final Jsr168Portlet portlet = (Jsr168Portlet) PortletHome.findByPrimaryKey( nPortletId );
230
231 return LuteceToPlutoConnector.request( nPortletId, portlet.getJsr168Name( ) );
232 }
233
234
235
236
237
238
239
240 String getPortletIndexCombo( ReferenceList listPortlets, String strDefaultPortletId )
241 {
242 HashMap model = new HashMap( );
243 model.put( MARK_PORTLET_LIST, listPortlets );
244 model.put( MARK_PORTLET_ID, strDefaultPortletId );
245
246 HtmlTemplate templateCombo = AppTemplateService.getTemplate( TEMPLATE_COMBO_PORTLETS, getLocale( ), model );
247
248 return templateCombo.getHtml( );
249 }
250 }