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.calendar.web;
35
36 import fr.paris.lutece.plugins.calendar.business.MultiAgendaEvent;
37 import fr.paris.lutece.plugins.calendar.service.AgendaResource;
38 import fr.paris.lutece.plugins.calendar.service.CalendarService;
39 import fr.paris.lutece.portal.service.spring.SpringContextService;
40 import fr.paris.lutece.portal.service.util.AppPropertiesService;
41
42 import java.util.Map;
43
44 import org.apache.commons.lang.StringUtils;
45
46
47
48
49
50 public final class HtmlUtils
51 {
52 private static final String HTML_START = "<";
53 private static final String HTML_BR = "<br />";
54 private static final String LINEFEED = "\\n";
55
56
57
58
59 private HtmlUtils( )
60 {
61 }
62
63
64
65
66
67
68 public static String removeHtml( String strSource )
69 {
70 String strReturn = strSource;
71 int nPos = strSource.indexOf( HTML_START );
72
73 if ( nPos >= 0 )
74 {
75 strReturn = strSource.substring( 0, nPos );
76 }
77
78 return strReturn;
79 }
80
81
82
83
84
85
86 public static String convertCR( String strSource )
87 {
88 String strReturn = StringUtils.EMPTY;
89
90 if ( StringUtils.isNotBlank( strSource ) )
91 {
92 strReturn = strSource.replaceAll( LINEFEED, HTML_BR );
93 }
94
95 return strReturn;
96 }
97
98
99
100
101
102
103
104 public static void fillEventTemplate( Map<String, Object> model, MultiAgendaEvent event, String strDate )
105 {
106 CalendarService calendarService = SpringContextService.getBean( Constants.BEAN_CALENDAR_CALENDARSERVICE );
107 int nShortTitleLength = AppPropertiesService.getPropertyInt( Constants.PROPERTY_EVENT_SHORT_TITLE_LENGTH, 18 );
108 StringBuilder sbTitle = new StringBuilder( );
109 String strImage = StringUtils.EMPTY;
110
111 AgendaResource agenda = calendarService.getAgendaResource( event.getAgenda( ) );
112 if ( agenda != null )
113 {
114 sbTitle.append( agenda.getEventPrefix( ) );
115 sbTitle.append( Constants.SPACE );
116 strImage = agenda.getEventImage( );
117 }
118
119 if ( StringUtils.isNotBlank( event.getDateTimeStart( ) ) )
120 {
121 sbTitle.append( event.getDateTimeStart( ) );
122 }
123 sbTitle.append( Constants.INDENT );
124 if ( StringUtils.isNotBlank( event.getDateTimeEnd( ) ) )
125 {
126 sbTitle.append( event.getDateTimeEnd( ) );
127 }
128 sbTitle.append( Constants.SPACE );
129
130 sbTitle.append( removeHtml( event.getTitle( ) ) );
131
132 String strShortTitle = sbTitle.toString( );
133
134 if ( strShortTitle.length( ) > nShortTitleLength )
135 {
136 StringBuilder sbShortTitle = new StringBuilder( );
137 sbShortTitle.append( strShortTitle.substring( 0, nShortTitleLength ) );
138 sbShortTitle.append( AppPropertiesService.getProperty( Constants.PROPERTY_EVENT_SHORT_TITLE_END ) );
139 strShortTitle = sbShortTitle.toString( );
140 }
141
142 String strDescription = ( event.getDescription( ) != null ) ? event.getDescription( ) : StringUtils.EMPTY;
143 String strLocation = ( event.getLocation( ) != null ) ? event.getLocation( ) : StringUtils.EMPTY;
144 String strUrl = ( event.getUrl( ) != null ) ? event.getUrl( ) : StringUtils.EMPTY;
145
146 model.put( Constants.MARK_AGENDA, event.getAgenda( ) );
147 model.put( Constants.MARK_EVENT_TITLE, sbTitle.toString( ) );
148 model.put( Constants.MARK_EVENT_SHORT_TITLE, strShortTitle );
149 model.put( Constants.MARK_EVENT_DESCRIPTION, strDescription );
150 model.put( Constants.MARK_EVENT_LOCATION, strLocation );
151 model.put( Constants.MARK_EVENT_URL, strUrl );
152 model.put( Constants.MARK_EVENT_IMAGE, strImage );
153 model.put( Constants.MARK_DATE, strDate );
154 }
155 }