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.lang.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
56 public abstract class InsertServiceJspBean implements Serializable
57 {
58 private static final long serialVersionUID = -2870769178710689751L;
59 private static final String PARAMETER_MODE = "mode";
60 private static final String PARAMETER_INPUT = "input";
61 private static final String PARAMETER_INSERT = "insert";
62 private static final String JSP_DO_INSERT = "jsp/admin/insert/DoInsertIntoElement.jsp";
63 private static final String TEMPLATE_LINK = "/admin/insert/insert_link.html";
64 private static final String MARK_TEXT = "text";
65 private static final String MARK_URL = "url";
66 private static final String MARK_TITLE = "title";
67 private static final String MARK_TARGET = "target";
68
69
70
71
72
73
74
75
76 protected String insertUrl( HttpServletRequest request, String strInput, String strInsert )
77 {
78
79 String strCleanInsert = strInsert.replaceAll( "\n", "" );
80 strCleanInsert = strCleanInsert.replaceAll( "\r", "" );
81
82
83
84
85
86 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
90 urlDoInsert.addParameter( PARAMETER_MODE, 1 );
91
92 return urlDoInsert.getUrl( );
93 }
94
95
96
97
98
99
100
101
102 protected String insertUrlWithoutEscape( HttpServletRequest request, String strInput, String strInsert )
103 {
104 String strInsertTmp = EncodingService.encodeUrl( strInsert );
105
106
107 UrlItem urlDoInsert = new UrlItem( AppPathService.getBaseUrl( request ) + JSP_DO_INSERT );
108 urlDoInsert.addParameter( PARAMETER_INPUT, strInput );
109 urlDoInsert.addParameter( PARAMETER_INSERT, strInsertTmp );
110 urlDoInsert.addParameter( PARAMETER_MODE, 2 );
111
112 return urlDoInsert.getUrl( );
113 }
114
115
116
117
118
119
120
121
122
123 protected String buildLink( String strText, String strUrl, String strTitle, String strTarget )
124 {
125 HashMap<String, Object> model = new HashMap<String, Object>( );
126 model.put( MARK_TEXT, StringEscapeUtils.escapeHtml( strText ) );
127 model.put( MARK_URL, strUrl );
128 model.put( MARK_TITLE, StringEscapeUtils.escapeHtml( strTitle ) );
129 model.put( MARK_TARGET, strTarget );
130
131 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_LINK, LocaleService.getDefault( ), model );
132
133 return template.getHtml( );
134 }
135
136
137
138
139
140 public ReferenceList getSubCategories( )
141 {
142 return new ReferenceList( );
143 }
144 }