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.portal.web.portlet;
35
36 import fr.paris.lutece.portal.business.portlet.AliasPortlet;
37 import fr.paris.lutece.portal.business.portlet.AliasPortletHome;
38 import fr.paris.lutece.portal.business.portlet.Portlet;
39 import fr.paris.lutece.portal.business.portlet.PortletHome;
40 import fr.paris.lutece.portal.service.i18n.I18nService;
41 import fr.paris.lutece.portal.service.message.AdminMessage;
42 import fr.paris.lutece.portal.service.message.AdminMessageService;
43 import fr.paris.lutece.portal.web.constants.Messages;
44 import fr.paris.lutece.util.ReferenceList;
45 import fr.paris.lutece.util.html.HtmlTemplate;
46
47 import java.util.HashMap;
48 import java.util.Map;
49
50 import javax.servlet.http.HttpServletRequest;
51
52
53
54
55 public class AliasPortletJspBean extends PortletJspBean
56 {
57
58
59
60
61 public static final String RIGHT_MANAGE_ADMIN_SITE = "CORE_ADMIN_SITE";
62 private static final long serialVersionUID = 1894295808070813451L;
63 private static final String PARAM_PORTLET_NAME = "portlet_name";
64 private static final String PARAM_ORDER = "order";
65 private static final String PARAM_COLUMN = "column";
66 private static final String PARAM_ALIAS_ID = "alias_id";
67 private static final String PARAM_ACCEPT_ALIAS = "accept_alias";
68 private static final String MARK_ALIAS_PORTLETS_LIST = "alias_portlets_list";
69 private static final String MARK_ALIAS_PORTLET = "alias_portlet";
70 private static final String LABEL_ALIAS_PORTLET_NAME = "portal.site.portlet_alias.portlet.name.label";
71
72
73
74
75
76
77
78
79 @Override
80 public String doCreate( HttpServletRequest request )
81 {
82 AliasPortletrtlet/AliasPortlet.html#AliasPortlet">AliasPortlet aliasPortlet = new AliasPortlet( );
83 String strAliasId = request.getParameter( PARAM_ALIAS_ID );
84
85
86 if ( strAliasId == null )
87 {
88 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
89 }
90
91
92 String strName = request.getParameter( PARAM_PORTLET_NAME );
93
94
95 if ( ( strName == null ) || strName.trim( ).equals( "" ) )
96 {
97 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
98 }
99
100 String strOrder = request.getParameter( PARAM_ORDER );
101 int nOrder = Integer.parseInt( strOrder );
102 String strColumn = request.getParameter( PARAM_COLUMN );
103 int nColumn = Integer.parseInt( strColumn );
104 String strAcceptAlias = request.getParameter( PARAM_ACCEPT_ALIAS );
105 int nAcceptAlias = Integer.parseInt( strAcceptAlias );
106 aliasPortlet.setName( strName );
107 aliasPortlet.setOrder( nOrder );
108 aliasPortlet.setColumn( nColumn );
109 aliasPortlet.setAcceptAlias( nAcceptAlias );
110
111 String strPageId = request.getParameter( PARAMETER_PAGE_ID );
112 int nPageId = Integer.parseInt( strPageId );
113 int nAliasId = Integer.parseInt( strAliasId );
114 aliasPortlet.setPageId( nPageId );
115 aliasPortlet.setAliasId( nAliasId );
116
117
118 Portlet portlet = PortletHome.findByPrimaryKey( nAliasId );
119 aliasPortlet.setStyleId( portlet.getStyleId( ) );
120
121
122 AliasPortletHome.getInstance( ).create( aliasPortlet );
123
124
125 return getPageUrl( nPageId );
126 }
127
128
129
130
131
132
133
134
135 @Override
136 public String doModify( HttpServletRequest request )
137 {
138
139 String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
140 int nPortletId = Integer.parseInt( strPortletId );
141 AliasPortlet./../../../fr/paris/lutece/portal/business/portlet/AliasPortlet.html#AliasPortlet">AliasPortlet portlet = (AliasPortlet) PortletHome.findByPrimaryKey( nPortletId );
142
143
144 String strName = request.getParameter( PARAM_PORTLET_NAME );
145 String strOrder = request.getParameter( PARAM_ORDER );
146 int nOrder = Integer.parseInt( strOrder );
147 String strColumn = request.getParameter( PARAM_COLUMN );
148 int nColumn = Integer.parseInt( strColumn );
149
150
151 if ( ( strName == null ) || strName.trim( ).equals( "" ) )
152 {
153 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
154 }
155
156 portlet.setName( strName );
157 portlet.setOrder( nOrder );
158 portlet.setColumn( nColumn );
159
160 String strIdAlias = request.getParameter( PARAM_ALIAS_ID );
161 int nIdAlias = Integer.parseInt( strIdAlias );
162 portlet.setAliasId( nIdAlias );
163
164 Portlet rub = PortletHome.findByPrimaryKey( nIdAlias );
165 portlet.setStyleId( rub.getStyleId( ) );
166
167
168 portlet.update( );
169
170
171 return getPageUrl( portlet.getPageId( ) );
172 }
173
174
175
176
177
178
179
180
181 @Override
182 public String getCreate( HttpServletRequest request )
183 {
184 String strIdPage = request.getParameter( PARAMETER_PAGE_ID );
185 String strIdPortletType = request.getParameter( PARAMETER_PORTLET_TYPE_ID );
186 Map<String, Object> model = new HashMap<>( );
187 model.put( MARK_ALIAS_PORTLETS_LIST, buildAliasPortletList( ) );
188
189 HtmlTemplate template = getCreateTemplate( strIdPage, strIdPortletType, model );
190
191 return template.getHtml( );
192 }
193
194
195
196
197
198
199
200
201 @Override
202 public String getModify( HttpServletRequest request )
203 {
204 String strIdPortlet = request.getParameter( PARAMETER_PORTLET_ID );
205 int idPortlet = Integer.parseInt( strIdPortlet );
206 Portlet portlet = PortletHome.findByPrimaryKey( idPortlet );
207 AliasPortlet../../fr/paris/lutece/portal/business/portlet/AliasPortlet.html#AliasPortlet">AliasPortlet aliasPortlet = (AliasPortlet) portlet;
208 Map<String, Object> model = new HashMap<>( );
209 model.put( MARK_ALIAS_PORTLETS_LIST, buildAliasPortletList( ) );
210 model.put( MARK_ALIAS_PORTLET, aliasPortlet.getAliasId( ) );
211
212 HtmlTemplate template = getModifyTemplate( portlet, model );
213
214 return template.getHtml( );
215 }
216
217
218
219
220
221
222 private ReferenceList buildAliasPortletList( )
223 {
224
225 ReferenceListList.html#ReferenceList">ReferenceList refList = new ReferenceList( );
226
227 for ( Portlet portlet : AliasPortletHome.getAcceptAliasPortletList( ) )
228 {
229 refList.addItem( portlet.getId( ), I18nService.getLocalizedString( LABEL_ALIAS_PORTLET_NAME, new String [ ] {
230 String.valueOf( portlet.getPageId( ) ), portlet.getName( )
231 }, getLocale( ) ) );
232 }
233 return refList;
234 }
235 }