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.template.AppTemplateService;
38 import fr.paris.lutece.portal.service.util.AppPathService;
39 import fr.paris.lutece.portal.web.l10n.LocaleService;
40 import fr.paris.lutece.util.ReferenceList;
41 import fr.paris.lutece.util.html.HtmlTemplate;
42 import fr.paris.lutece.util.url.UrlItem;
43
44 import org.apache.commons.text.StringEscapeUtils;
45
46 import java.io.Serializable;
47
48 import java.util.HashMap;
49
50 import javax.servlet.http.HttpServletRequest;
51
52
53
54
55 public abstract class InsertServiceJspBean implements Serializable
56 {
57 private static final long serialVersionUID = -2870769178710689751L;
58 private static final String PARAMETER_MODE = "mode";
59 private static final String PARAMETER_INPUT = "input";
60 private static final String PARAMETER_INSERT = "insert";
61 private static final String JSP_DO_INSERT = "jsp/admin/insert/DoInsertIntoElement.jsp";
62 private static final String TEMPLATE_LINK = "/admin/insert/insert_link.html";
63 private static final String MARK_TEXT = "text";
64 private static final String MARK_URL = "url";
65 private static final String MARK_TITLE = "title";
66 private static final String MARK_TARGET = "target";
67
68
69
70
71
72
73
74
75
76
77
78
79 protected String insertUrl( HttpServletRequest request, String strInput, String strInsert )
80 {
81
82 String strCleanInsert = strInsert.replaceAll( "\n", "" );
83 strCleanInsert = strCleanInsert.replaceAll( "\r", "" );
84
85
86 UrlItemItem.html#UrlItem">UrlItem urlDoInsert = new UrlItem( AppPathService.getBaseUrl( request ) + JSP_DO_INSERT );
87 urlDoInsert.addParameter( PARAMETER_INPUT, strInput );
88 request.getSession( ).setAttribute( InsertServiceSelectorJspBean.SESSION_INSERT, strCleanInsert );
89 urlDoInsert.addParameter( PARAMETER_MODE, 1 );
90
91 return urlDoInsert.getUrl( );
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105 protected String insertUrlWithoutEscape( HttpServletRequest request, String strInput, String strInsert )
106 {
107 String strInsertTmp = EncodingService.encodeUrl( strInsert );
108
109
110 UrlItemItem.html#UrlItem">UrlItem urlDoInsert = new UrlItem( AppPathService.getBaseUrl( request ) + JSP_DO_INSERT );
111 urlDoInsert.addParameter( PARAMETER_INPUT, strInput );
112 urlDoInsert.addParameter( PARAMETER_INSERT, strInsertTmp );
113 urlDoInsert.addParameter( PARAMETER_MODE, 2 );
114
115 return urlDoInsert.getUrl( );
116 }
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 protected String buildLink( String strText, String strUrl, String strTitle, String strTarget )
132 {
133 HashMap<String, Object> model = new HashMap<>( );
134 model.put( MARK_TEXT, StringEscapeUtils.escapeHtml4( strText ) );
135 model.put( MARK_URL, strUrl );
136 model.put( MARK_TITLE, StringEscapeUtils.escapeHtml4( strTitle ) );
137 model.put( MARK_TARGET, strTarget );
138
139 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_LINK, LocaleService.getDefault( ), model );
140
141 return template.getHtml( );
142 }
143
144
145
146
147
148
149 public ReferenceList getSubCategories( )
150 {
151 return new ReferenceList( );
152 }
153 }