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