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.style;
35
36 import fr.paris.lutece.portal.business.style.Mode;
37 import fr.paris.lutece.portal.business.style.ModeHome;
38 import fr.paris.lutece.portal.service.message.AdminMessage;
39 import fr.paris.lutece.portal.service.message.AdminMessageService;
40 import fr.paris.lutece.portal.service.template.AppTemplateService;
41 import fr.paris.lutece.portal.service.util.AppPathService;
42 import fr.paris.lutece.portal.web.admin.AdminFeaturesPageJspBean;
43 import fr.paris.lutece.portal.web.constants.Messages;
44 import fr.paris.lutece.portal.web.constants.Parameters;
45 import fr.paris.lutece.util.html.HtmlTemplate;
46
47 import java.io.File;
48
49 import java.util.HashMap;
50
51 import javax.servlet.http.HttpServletRequest;
52
53
54
55
56
57
58 public class ModesJspBean extends AdminFeaturesPageJspBean
59 {
60
61
62
63
64 public static final String RIGHT_MANAGE_MODES = "CORE_MODES_MANAGEMENT";
65
66
67
68
69 private static final long serialVersionUID = 8205010720652090863L;
70
71
72 private static final String MARK_MODES_LIST = "mode_list";
73 private static final String MARK_MODE = "mode";
74
75
76 private static final String PROPERTY_PAGE_TITLE_MODE_LIST = "portal.style.manage_mode.pageTitle";
77 private static final String PROPERTY_PAGE_TITLE_CREATE_MODE = "portal.style.create_mode.pageTitle";
78 private static final String PROPERTY_PAGE_TITLE_MODIFY_MODE = "portal.style.modify_mode.pageTitle";
79
80
81 private static final String TEMPLATE_MANAGE_MODES = "admin/style/manage_modes.html";
82 private static final String TEMPLATE_CREATE_MODE = "admin/style/create_mode.html";
83 private static final String TEMPLATE_MODIFY_MODE = "admin/style/modify_mode.html";
84
85
86 private static final String PROPERTY_PATH_XSL = "path.stylesheet";
87
88
89 private static final String JSP_MANAGE_MODES = "ManageModes.jsp";
90
91
92
93
94
95
96
97 public String getManageModes( HttpServletRequest request )
98 {
99 setPageTitleProperty( PROPERTY_PAGE_TITLE_MODE_LIST );
100
101 HashMap<String, Object> model = new HashMap<String, Object>( );
102 model.put( MARK_MODES_LIST, ModeHome.getModesList( ) );
103
104 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_MODES, getLocale( ), model );
105
106 return getAdminPage( template.getHtml( ) );
107 }
108
109
110
111
112
113
114
115 public String getCreateMode( HttpServletRequest request )
116 {
117 setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE_MODE );
118
119 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_MODE, getLocale( ) );
120
121 return getAdminPage( template.getHtml( ) );
122 }
123
124
125
126
127
128
129
130
131 public String doCreateMode( HttpServletRequest request )
132 {
133 String strDescription = request.getParameter( Parameters.MODE_DESCRIPTION );
134 String strPath = request.getParameter( Parameters.MODE_PATH );
135
136
137 if ( strDescription.equals( "" ) || strPath.equals( "" ) )
138 {
139 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
140 }
141
142 if ( !strPath.endsWith( "/" ) && !strPath.endsWith( "\\" ) )
143 {
144 strPath += File.separator;
145 }
146
147 File dirPath = new File( AppPathService.getPath( PROPERTY_PATH_XSL ) + strPath );
148
149 if ( dirPath.exists( ) )
150 {
151 return AdminMessageService.getMessageUrl( request, Messages.PATH_ALREADY_EXISTS, AdminMessage.TYPE_STOP );
152 }
153
154 if ( !dirPath.mkdir( ) )
155 {
156 return AdminMessageService.getMessageUrl( request, Messages.PATH_CREATION_ERROR, AdminMessage.TYPE_ERROR );
157 }
158
159 Mode mode = new Mode( );
160 mode.setDescription( strDescription );
161 mode.setPath( strPath );
162
163
164 mode.setOutputXslPropertyMethod( request.getParameter( Parameters.MODE_OUTPUT_XSL_METHOD ) );
165 mode.setOutputXslPropertyVersion( request.getParameter( Parameters.MODE_OUTPUT_XSL_VERSION ) );
166 mode.setOutputXslPropertyMediaType( request.getParameter( Parameters.MODE_OUTPUT_XSL_MEDIA_TYPE ) );
167 mode.setOutputXslPropertyEncoding( request.getParameter( Parameters.MODE_OUTPUT_XSL_ENCODING ) );
168 mode.setOutputXslPropertyIndent( request.getParameter( Parameters.MODE_OUTPUT_XSL_INDENT ) );
169 mode.setOutputXslPropertyOmitXmlDeclaration( request.getParameter(
170 Parameters.MODE_OUTPUT_XSL_OMIT_XML_DECLARATION ) );
171 mode.setOutputXslPropertyStandalone( request.getParameter( Parameters.MODE_OUTPUT_XSL_STANDALONE ) );
172
173 ModeHome.create( mode );
174
175
176 return JSP_MANAGE_MODES;
177 }
178
179
180
181
182
183
184
185 public String getModifyMode( HttpServletRequest request )
186 {
187 setPageTitleProperty( PROPERTY_PAGE_TITLE_MODIFY_MODE );
188
189 String strId = request.getParameter( Parameters.MODE_ID );
190
191 HashMap<String, Object> model = new HashMap<String, Object>( );
192 model.put( MARK_MODE, ModeHome.findByPrimaryKey( Integer.parseInt( strId ) ) );
193
194 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_MODE, getLocale( ), model );
195
196 return getAdminPage( template.getHtml( ) );
197 }
198
199
200
201
202
203
204
205
206 public String doModifyMode( HttpServletRequest request )
207 {
208 String strId = request.getParameter( Parameters.MODE_ID );
209 String strDescription = request.getParameter( Parameters.MODE_DESCRIPTION );
210
211 if ( strDescription.equals( "" ) )
212 {
213 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
214 }
215
216 Mode mode = ModeHome.findByPrimaryKey( Integer.parseInt( strId ) );
217 mode.setDescription( strDescription );
218
219
220 mode.setOutputXslPropertyMethod( request.getParameter( Parameters.MODE_OUTPUT_XSL_METHOD ) );
221 mode.setOutputXslPropertyVersion( request.getParameter( Parameters.MODE_OUTPUT_XSL_VERSION ) );
222 mode.setOutputXslPropertyMediaType( request.getParameter( Parameters.MODE_OUTPUT_XSL_MEDIA_TYPE ) );
223 mode.setOutputXslPropertyEncoding( request.getParameter( Parameters.MODE_OUTPUT_XSL_ENCODING ) );
224 mode.setOutputXslPropertyIndent( request.getParameter( Parameters.MODE_OUTPUT_XSL_INDENT ) );
225 mode.setOutputXslPropertyOmitXmlDeclaration( request.getParameter(
226 Parameters.MODE_OUTPUT_XSL_OMIT_XML_DECLARATION ) );
227 mode.setOutputXslPropertyStandalone( request.getParameter( Parameters.MODE_OUTPUT_XSL_STANDALONE ) );
228
229 ModeHome.update( mode );
230
231
232 return JSP_MANAGE_MODES;
233 }
234 }