View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.calendar.modules.ical;
35  
36  import fr.paris.lutece.plugins.calendar.business.Event;
37  import fr.paris.lutece.plugins.calendar.service.Utils;
38  import fr.paris.lutece.portal.service.image.ImageResource;
39  
40  import java.util.Date;
41  
42  
43  /**
44   * This class implements the Event interface for events using
45   * the iCalendar format (RFC 2445).
46   */
47  public class ICalEvent implements Event
48  {
49      private static final long serialVersionUID = -5892714649982713744L;
50  
51      // Constants
52      private static final int DATE_ONLY_LENGTH = 8;
53      private static final int DATE_TIME_LENGTH = 15;
54  
55      // Variables
56      private Date _dateEvent;
57      private String _strDescription;
58      private String _strLocation;
59      private String _strStartHour;
60      private String _strStartMinute;
61      private String _strEndHour;
62      private String _strEndMinute;
63      private String _strTitle;
64      private String _strEventClass;
65      private String _strDateTimeStart;
66      private String _strDateTimeEnd;
67      private String _strCategories;
68      private String _strStatus;
69      private int _nPriority;
70      private String _strUrl;
71      private int _nPeriodicity;
72      private int _nOccurrence;
73      private String _strLocationTown;
74      private String _strLocationZip;
75      private String _strLocationAddress;
76      private String _strMapUrl;
77      private String _strLinkUrl;
78      private int _nDocumentId;
79      private String _strPageUrl;
80      private ImageResource _imageRessource;
81      private int _nTopEvent;
82      private Date _dateEnd;
83      private Date _dateCreation;
84      private int _nId;
85      private String _searchType;
86  
87      // Event interface implementation
88  
89      /**
90       * Returns the id of the event
91       * 
92       * @return The id
93       */
94      public int getId( )
95      {
96          return _nId;
97      }
98  
99      /**
100      * Returns the Date
101      * 
102      * @return The Date
103      */
104     public Date getDate( )
105     {
106         return _dateEvent;
107     }
108 
109     /**
110      * Returns the Title
111      * 
112      * @return The Title
113      */
114     public String getTitle( )
115     {
116         return _strTitle;
117     }
118 
119     /**
120      * Returns the EventClass
121      * 
122      * @return The Evenet class
123      */
124     public String getEventClass( )
125     {
126         return _strEventClass;
127     }
128 
129     /**
130      * Returns the Location
131      * 
132      * @return The Location
133      */
134     public String getLocation( )
135     {
136         return _strLocation;
137     }
138 
139     /**
140      * Returns the Description
141      * 
142      * @return The Description
143      */
144     public String getDescription( )
145     {
146         return _strDescription;
147     }
148 
149     /**
150      * Returns the DateTimeStart
151      * 
152      * @return The DateTimeStart
153      */
154     public String getDateTimeStart( )
155     {
156         return _strDateTimeStart;
157     }
158 
159     /**
160      * Returns the DateTimeEnd
161      * 
162      * @return The DateTimeEnd
163      */
164     public String getDateTimeEnd( )
165     {
166         return _strDateTimeEnd;
167     }
168 
169     /**
170      * Returns the Categories
171      * 
172      * @return The Categories
173      */
174     public String getCategories( )
175     {
176         return _strCategories;
177     }
178 
179     /**
180      * Returns the Status
181      * 
182      * @return The Status
183      */
184     public String getStatus( )
185     {
186         return _strStatus;
187     }
188 
189     /**
190      * Returns the Priority
191      * 
192      * @return The Priority
193      */
194     public int getPriority( )
195     {
196         return _nPriority;
197     }
198 
199     /**
200      * Returns the Url
201      * 
202      * @return The Url
203      */
204     public String getUrl( )
205     {
206         return _strUrl;
207     }
208 
209     /**
210      * @return the periodicity
211      */
212     public int getPeriodicity( )
213     {
214         return _nPeriodicity;
215     }
216 
217     /**
218      * @return the occurence
219      */
220     public int getOccurrence( )
221     {
222         return _nOccurrence;
223     }
224 
225     /**
226      * Returns the date end
227      * 
228      * @return The date end
229      */
230     public Date getDateEnd( )
231     {
232         return _dateEnd;
233     }
234 
235     /**
236      * Returns the location Town
237      * 
238      * @return The location Town
239      */
240     public String getLocationTown( )
241     {
242         return _strLocationTown;
243     }
244 
245     /**
246      * Returns the location Address
247      * 
248      * @return The location Address
249      */
250     public String getLocationAddress( )
251     {
252         return _strLocationAddress;
253     }
254 
255     /**
256      * Returns the date end
257      * 
258      * @return The date end
259      */
260     public String getMapUrl( )
261     {
262         return _strMapUrl;
263     }
264 
265     /**
266      * Returns the link Url
267      * 
268      * @return The link Url
269      */
270     public String getLinkUrl( )
271     {
272         return _strLinkUrl;
273     }
274 
275     /**
276      * Returns the document id
277      * 
278      * @return The document id
279      */
280     public int getDocumentId( )
281     {
282         return _nDocumentId;
283     }
284 
285     /**
286      * Returns the page Url
287      * 
288      * @return The page Url
289      */
290     public String getPageUrl( )
291     {
292         return _strPageUrl;
293     }
294 
295     /**
296      * Returns the top Event
297      * 
298      * @return The top Event
299      */
300     public int getTopEvent( )
301     {
302         return _nTopEvent;
303     }
304 
305     ////////////////////////////////////////////////////////////////////////////
306     // Setters : scope package
307     /**
308      * Set the periodicity of the event
309      * @param nPeriodicity The periodicity of the event
310      */
311     public void setPeriodicity( int nPeriodicity )
312     {
313         _nPeriodicity = nPeriodicity;
314     }
315 
316     /**
317      * Set the occurrence of the event
318      * @param nOccurrence The occurrence of the event
319      */
320     public void setOccurrence( int nOccurrence )
321     {
322         _nOccurrence = nOccurrence;
323     }
324 
325     /**
326      * Sets the DateTimeStart
327      * 
328      * @param strDateTimeStart The Date
329      */
330     void setDateTimeStart( String strDateTimeStart )
331     {
332         if ( strDateTimeStart.length( ) == DATE_ONLY_LENGTH )
333         {
334             _dateEvent = Utils.getDate( strDateTimeStart );
335         }
336         else if ( strDateTimeStart.length( ) == DATE_TIME_LENGTH )
337         {
338             _dateEvent = Utils.getDate( strDateTimeStart );
339             _strStartHour = strDateTimeStart.substring( 9, 11 );
340             _strStartMinute = strDateTimeStart.substring( 11, 13 );
341             _strDateTimeStart = _strStartHour + ":" + _strStartMinute;
342         }
343     }
344 
345     /**
346      * Sets the DateTimeEnd
347      * 
348      * @param strDateTimeEnd The Date
349      */
350     void setDateTimeEnd( String strDateTimeEnd )
351     {
352         if ( strDateTimeEnd.length( ) == DATE_TIME_LENGTH )
353         {
354             _dateEvent = Utils.getDate( strDateTimeEnd );
355             _strEndHour = strDateTimeEnd.substring( 9, 11 );
356             _strEndMinute = strDateTimeEnd.substring( 11, 13 );
357             _strDateTimeEnd = _strEndHour + ":" + _strEndMinute;
358         }
359     }
360 
361     /**
362      * Sets the Title
363      * 
364      * @param strTitle The Title
365      */
366     void setTitle( String strTitle )
367     {
368         _strTitle = strTitle;
369     }
370 
371     /**
372      * Sets the Location
373      * 
374      * @param strLocation The Location
375      */
376     void setLocation( String strLocation )
377     {
378         _strLocation = strLocation;
379     }
380 
381     /**
382      * Sets the EventClass
383      * 
384      * @param strEventClass The EventClass
385      */
386     public void setEventClass( String strEventClass )
387     {
388         _strEventClass = strEventClass;
389     }
390 
391     /**
392      * Sets the Description
393      * 
394      * @param strDescription The Description
395      */
396     void setDescription( String strDescription )
397     {
398         _strDescription = strDescription;
399     }
400 
401     /**
402      * Sets the Categories
403      * 
404      * @param strCategories The Categories
405      */
406     void setCategories( String strCategories )
407     {
408         _strCategories = strCategories;
409     }
410 
411     /**
412      * Sets the Status
413      * 
414      * @param strStatus The Status
415      */
416     public void setStatus( String strStatus )
417     {
418         _strStatus = strStatus;
419     }
420 
421     /**
422      * Sets the Priority
423      * 
424      * @param nPriority The Priority
425      */
426     public void setPriority( int nPriority )
427     {
428         _nPriority = nPriority;
429     }
430 
431     /**
432      * Sets the Url
433      * 
434      * @param strUrl The Url
435      */
436     public void setUrl( String strUrl )
437     {
438         _strUrl = strUrl;
439     }
440 
441     /**
442      * Sets the Date End
443      * @param dateEnd The Date End
444      */
445     public void setDateEnd( Date dateEnd )
446     {
447         _dateEnd = dateEnd;
448     }
449 
450     /**
451      * Sets the location Town
452      * 
453      * @param strLocationTown The location Town
454      */
455     public void setLocationTown( String strLocationTown )
456     {
457         _strLocationTown = strLocationTown;
458     }
459 
460     /**
461      * Returns the location Zip
462      * 
463      * @return The location Zip
464      */
465     public String getLocationZip( )
466     {
467         return _strLocationZip;
468     }
469 
470     /**
471      * Sets the location Zip
472      * 
473      * @param strLocationZip The location Zip
474      */
475     public void setLocationZip( String strLocationZip )
476     {
477         _strLocationZip = strLocationZip;
478     }
479 
480     /**
481      * Sets the location Address
482      * 
483      * @param strLocationAddress The location Address
484      */
485     public void setLocationAddress( String strLocationAddress )
486     {
487         _strLocationAddress = strLocationAddress;
488     }
489 
490     /**
491      * Sets the Map Url
492      * 
493      * @param strMapUrl The Map Url
494      */
495     public void setMapUrl( String strMapUrl )
496     {
497         _strMapUrl = strMapUrl;
498     }
499 
500     /**
501      * Sets the link Url
502      * 
503      * @param strLinkUrl The link Url
504      */
505     public void setLinkUrl( String strLinkUrl )
506     {
507         _strLinkUrl = strLinkUrl;
508     }
509 
510     /**
511      * Sets the document id
512      * 
513      * @param nDocumentId The document id
514      */
515     public void setDocumentId( int nDocumentId )
516     {
517         _nDocumentId = nDocumentId;
518     }
519 
520     /**
521      * Sets the page Url
522      * 
523      * @param strPageUrl The page Url
524      */
525     public void setPageUrl( String strPageUrl )
526     {
527         _strPageUrl = strPageUrl;
528     }
529 
530     /**
531      * Sets the top Event
532      * 
533      * @param strTopEvent The top Event
534      */
535     public void setTopEvent( int strTopEvent )
536     {
537         _nTopEvent = strTopEvent;
538     }
539 
540     /**
541      * Sets the Date
542      * 
543      * @param nId The id of the event
544      */
545     public void setId( int nId )
546     {
547         _nId = nId;
548     }
549 
550     /**
551      * Returns the type
552      * 
553      * @return The type
554      */
555     public String getType( )
556     {
557         return _searchType;
558     }
559 
560     /**
561      * Sets the type
562      * 
563      * @param type The type
564      */
565     public void setType( String type )
566     {
567         _searchType = type;
568     }
569 
570     /**
571      * Returns the ImageResource
572      * 
573      * @return The ImageResource
574      */
575     public ImageResource getImageResource( )
576     {
577         return _imageRessource;
578     }
579 
580     /**
581      * Sets the ImageResource
582      * 
583      * @param imageResource the ImageResource
584      */
585     public void setImageResource( ImageResource imageResource )
586     {
587         _imageRessource = imageResource;
588     }
589 
590     /**
591      * Returns the event date creation
592      * 
593      * @return The event date creation
594      */
595     public Date getDateCreation( )
596     {
597         return _dateCreation;
598     }
599 
600     /**
601      * Sets the date event date creation
602      * 
603      * @param dateCreation The event date creation
604      */
605     public void setDateCreation( Date dateCreation )
606     {
607         _dateCreation = dateCreation;
608     }
609 
610     /**
611      * @return the id of calendar
612      */
613     public int getIdCalendar( )
614     {
615         return 0;
616     }
617 }