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.plugins.insertalbum.web;
35
36 import fr.paris.lutece.plugins.document.business.Document;
37 import fr.paris.lutece.plugins.document.business.DocumentHome;
38 import fr.paris.lutece.plugins.document.service.spaces.DocumentSpacesService;
39 import fr.paris.lutece.plugins.insertalbum.service.NoImageInWorkspaceException;
40 import fr.paris.lutece.portal.business.user.AdminUser;
41 import fr.paris.lutece.portal.service.admin.AdminUserService;
42 import fr.paris.lutece.portal.service.template.AppTemplateService;
43 import fr.paris.lutece.portal.service.util.AppPathService;
44 import fr.paris.lutece.portal.service.util.AppPropertiesService;
45 import fr.paris.lutece.portal.web.insert.InsertServiceJspBean;
46 import fr.paris.lutece.portal.web.insert.InsertServiceSelectionBean;
47 import fr.paris.lutece.util.html.HtmlTemplate;
48
49 import org.apache.commons.lang.StringEscapeUtils;
50
51 import java.util.Arrays;
52 import java.util.HashMap;
53 import java.util.List;
54 import java.util.Locale;
55 import java.util.Map;
56
57 import javax.servlet.http.HttpServletRequest;
58
59
60
61
62
63 public class InsertAlbumJspBean extends InsertServiceJspBean implements InsertServiceSelectionBean
64 {
65 private static final String SLIDESHOW = "slideshow";
66 private static final long serialVersionUID = -3189672631047661765L;
67 private static final String TEMPLATE_SELECTOR_PAGE = "admin/plugins/insertalbum/selector.html";
68 private static final String TEMPLATE_PRESENTATION = "admin/plugins/insertalbum/presentation.html";
69
70
71 private static final String TEMPLATE_CHOOSE_DOCUMENT = "admin/plugins/insertalbum/choose_workspace.html";
72 private static final String MARK_SPACES_BROWSER = "spaces_browser";
73 private static final String PARAMETER_INPUT = "input";
74 private static final String IMAGES_LIST = "images_list";
75 private static final String BASE_URL = "baseUrl";
76 private static final String SLIDESHOWLIST = "slideshow_list";
77 private static final String TEMPLATE_PREVIEW_SLIDESHOW = "admin/plugins/insertalbum/choose_slideshow.html";
78 private AdminUser _user;
79 private String _input;
80 private String PROPERTY_SLIDESHOW_LIST = "insertalbum.slideshows";
81
82 private void init( HttpServletRequest request )
83 {
84 _user = AdminUserService.getAdminUser( request );
85 _input = request.getParameter( PARAMETER_INPUT );
86 }
87
88 public String getInsertServiceSelectorUI( HttpServletRequest request )
89 {
90 init( request );
91
92 Locale locale = AdminUserService.getLocale( request );
93 Map<String, Object> model = new HashMap<String, Object>( );
94 model.put( PARAMETER_INPUT, _input );
95
96 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PRESENTATION, locale, model );
97
98 return template.getHtml( );
99 }
100
101 public String getSpaceBrowser( HttpServletRequest request )
102 {
103 init( request );
104
105 Map<String, Object> model = new HashMap<String, Object>( );
106 String strSpaceId = request.getParameter( DocumentSpacesService.PARAMETER_BROWSER_SELECTED_SPACE_ID );
107
108 if ( ( strSpaceId != null ) && !strSpaceId.equals( "" ) )
109 {
110 return getSelectSlideshow( request );
111 }
112
113 Locale locale = AdminUserService.getLocale( request );
114
115 model.put( MARK_SPACES_BROWSER,
116 DocumentSpacesService.getInstance( ).getSpacesBrowser( request, _user, locale, true, true ) );
117
118 String strBaseUrl = AppPathService.getBaseUrl( request );
119 model.put( BASE_URL, strBaseUrl );
120 model.put( PARAMETER_INPUT, _input );
121
122 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CHOOSE_DOCUMENT, locale, model );
123
124 return template.getHtml( );
125 }
126
127
128
129
130
131
132
133 public String getSelectSlideshow( HttpServletRequest request )
134 {
135 String slideshowListInProperties = AppPropertiesService.getProperty( PROPERTY_SLIDESHOW_LIST );
136
137 List<String> slideshowList = Arrays.asList( slideshowListInProperties.split( "," ) );
138
139 String strIdWorksapce = request.getParameter( DocumentSpacesService.PARAMETER_BROWSER_SELECTED_SPACE_ID );
140
141 Map<String, Object> model = new HashMap<String, Object>( );
142 model.put( PARAMETER_INPUT, _input );
143 model.put( SLIDESHOWLIST, slideshowList );
144
145 String strBaseUrl = AppPathService.getBaseUrl( request );
146 model.put( BASE_URL, strBaseUrl );
147 model.put( DocumentSpacesService.PARAMETER_BROWSER_SELECTED_SPACE_ID, strIdWorksapce );
148
149 Locale locale = AdminUserService.getLocale( request );
150 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_SELECTOR_PAGE, locale, model );
151
152 return template.getHtml( );
153 }
154
155 public String doInsertLink( HttpServletRequest request )
156 {
157
158 String strInput = request.getParameter( PARAMETER_INPUT );
159
160 try
161 {
162 HtmlTemplate template = getSlideshowTemplate( request );
163
164 return insertUrlWithoutEscape( request, strInput, template.getHtml( ) );
165 }
166 catch ( NoImageInWorkspaceException e )
167 {
168 return insertUrlWithoutEscape( request, strInput, "" );
169 }
170 }
171
172 public String doGetSlideshow( HttpServletRequest request )
173 {
174 try
175 {
176 HtmlTemplate templateSlideshow = getSlideshowTemplate( request );
177
178 Map<String, Object> model = new HashMap<String, Object>( );
179 Locale locale = AdminUserService.getLocale( request );
180 model.put( SLIDESHOW, templateSlideshow.getHtml( ) );
181
182 String strBaseUrl = AppPathService.getBaseUrl( request );
183 model.put( BASE_URL, strBaseUrl );
184 model.put( PARAMETER_INPUT, _input );
185
186 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PREVIEW_SLIDESHOW, locale, model );
187
188 return template.getHtml( );
189 }
190 catch ( NoImageInWorkspaceException e )
191 {
192 return "no image in workspace";
193 }
194 }
195
196 private HtmlTemplate getSlideshowTemplate( HttpServletRequest request )
197 throws NoImageInWorkspaceException
198 {
199
200 String strIdWorksapce = request.getParameter( DocumentSpacesService.PARAMETER_BROWSER_SELECTED_SPACE_ID );
201 int nIdWorksapce = Integer.parseInt( strIdWorksapce );
202
203
204 String strSlideshow = request.getParameter( SLIDESHOW );
205
206
207 List<Document> documentsList = DocumentHome.findBySpaceKey( nIdWorksapce );
208
209 for ( Document doc : documentsList )
210 {
211 doc.setComment( StringEscapeUtils.escapeHtml( doc.getSummary( ) ) );
212 doc.setComment( doc.getComment( ).replaceAll( "'", "’" ) );
213 }
214
215 HtmlTemplate template = null;
216
217 String strBaseUrl = AppPathService.getBaseUrl( request );
218 Locale locale = AdminUserService.getLocale( request );
219
220 Map<String, Object> model = new HashMap<String, Object>( );
221 model.put( IMAGES_LIST, documentsList );
222 model.put( BASE_URL, strBaseUrl );
223
224 if ( ( documentsList != null ) && ( documentsList.size( ) > 0 ) && ( strSlideshow != null ) )
225 {
226 template = AppTemplateService.getTemplate( "admin/plugins/insertalbum/slideshow/" + strSlideshow + ".html",
227 locale, model );
228 }
229 else
230 {
231 throw new NoImageInWorkspaceException( );
232 }
233
234 return template;
235 }
236 }