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.insert;
35
36 import fr.paris.lutece.portal.service.html.EncodingService;
37 import fr.paris.lutece.portal.service.insert.InsertResourceIdService;
38 import fr.paris.lutece.portal.service.insert.InsertService;
39 import fr.paris.lutece.portal.service.insert.InsertServiceManager;
40 import fr.paris.lutece.portal.service.message.AdminMessage;
41 import fr.paris.lutece.portal.service.message.AdminMessageService;
42 import fr.paris.lutece.portal.service.rbac.RBACService;
43 import fr.paris.lutece.portal.service.template.AppTemplateService;
44 import fr.paris.lutece.portal.web.admin.AdminFeaturesPageJspBean;
45 import fr.paris.lutece.util.html.HtmlTemplate;
46
47 import java.util.Collection;
48 import java.util.HashMap;
49 import java.util.Map;
50
51 import javax.servlet.http.HttpServletRequest;
52
53
54
55
56 public class InsertServiceSelectorJspBean extends AdminFeaturesPageJspBean
57 {
58
59
60
61 public static final String RIGHT_MANAGE_LINK_SERVICE = "CORE_LINK_SERVICE_MANAGEMENT";
62
63
64
65
66 public static final String SESSION_INSERT = "portal.session.insertServiceSelector.contentToInsert";
67 private static final long serialVersionUID = 3395846045509139922L;
68
69
70 private static final String TEMPLATE_INSERT_TYPE_PAGE = "admin/insert/page_insertservice.html";
71 private static final String TEMPLATE_INSERT_TYPE_PAGE_DATA = "admin/insert/page_insertservice_data.html";
72 private static final String TEMPLATE_INSERT_INTO_ELEMENT = "admin/insert/insert_into_element.html";
73 private static final String TEMPLATE_INSERT_INTO_ELEMENT2 = "admin/insert/insert_into_element2.html";
74 private static final String MSG_NO_SERVICE_AVAILABLE = "portal.insert.message.noServiceAvailable";
75
76
77 private static final String PARAMETER_INSERT_SERVICE_TYPE = "insert_service_type";
78 private static final String PARAMETER_MODE = "mode";
79 private static final String PARAMETER_INPUT = "input";
80 private static final String PARAMETER_INSERT = "insert";
81 private static final String PARAMETER_SELECTED_TEXT = "selected_text";
82 private static final String MARK_INSERT_SERVICES_LIST = "insert_services_list";
83 private static final String MARK_SELECTED_TEXT = "selected_text";
84 private static final String MARK_INPUT = "input";
85 private static final String MARK_INSERT = "insert";
86
87
88
89
90
91
92
93
94 public String getServicesListPage( HttpServletRequest request )
95 {
96 String strInput = request.getParameter( PARAMETER_INPUT );
97 String strText = request.getParameter( PARAMETER_SELECTED_TEXT );
98 String strMode = request.getParameter( PARAMETER_MODE );
99
100
101 strText = EncodingService.encodeUrl( strText );
102
103 Collection<InsertService> listServices = InsertServiceManager.getInsertServicesList( );
104
105
106 Map<String, Object> model = new HashMap<>( );
107 model.put( MARK_INSERT_SERVICES_LIST, RBACService.getAuthorizedCollection( listServices, InsertResourceIdService.PERMISSION_USE, getUser( ) ) );
108 model.put( MARK_SELECTED_TEXT, strText );
109 model.put( MARK_INPUT, strInput );
110
111 HtmlTemplate t;
112
113 if ("2".equals(strMode))
114 {
115 t = AppTemplateService.getTemplate( TEMPLATE_INSERT_TYPE_PAGE_DATA, getLocale( ), model );
116 }
117 else
118 {
119 t = AppTemplateService.getTemplate( TEMPLATE_INSERT_TYPE_PAGE, getLocale( ), model );
120 }
121 return t.getHtml( );
122 }
123
124
125
126
127
128
129
130
131 public String displayService( HttpServletRequest request )
132 {
133 String strInsertService = request.getParameter( PARAMETER_INSERT_SERVICE_TYPE );
134
135 if ( ( strInsertService != null ) && !strInsertService.equals( "" ) )
136 {
137 InsertService is = InsertServiceManager.getInsertService( strInsertService );
138
139 return is.getSelectorUI( request );
140 }
141 else
142 {
143 return AdminMessageService.getMessageUrl( request, MSG_NO_SERVICE_AVAILABLE, AdminMessage.TYPE_STOP );
144 }
145 }
146
147
148
149
150
151
152
153
154 public String doInsertIntoElement( HttpServletRequest request )
155 {
156 String strMode = request.getParameter( PARAMETER_MODE );
157 String strInput = request.getParameter( PARAMETER_INPUT );
158 String strInsert = (String) request.getSession( ).getAttribute( SESSION_INSERT );
159
160 if ( strInsert == null )
161 {
162 strInsert = request.getParameter( PARAMETER_INSERT );
163 }
164
165 request.getSession( ).removeAttribute( SESSION_INSERT );
166
167 Map<String, String> model = new HashMap<>( );
168 model.put( MARK_INPUT, strInput );
169 model.put( MARK_INSERT, strInsert );
170
171 HtmlTemplate template;
172
173 if ( strMode.compareTo( "2" ) == 0 )
174 {
175 template = AppTemplateService.getTemplate( TEMPLATE_INSERT_INTO_ELEMENT2, getLocale( ), model );
176 }
177 else
178 {
179 template = AppTemplateService.getTemplate( TEMPLATE_INSERT_INTO_ELEMENT, getLocale( ), model );
180 }
181
182 return template.getHtml( );
183 }
184 }