View Javadoc
1   /*
2    * Copyright (c) 2002-2017, 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.chat.business;
35  
36  import java.util.Date;
37  
38  
39  /**
40   * This class represents an entry in the chat.
41   */
42  public class ChatEntry
43  {
44      public static final int TYPE_MESSAGE = 0;
45      public static final int TYPE_NOTIFICATION = 1;
46      private String _strNickname;
47      private String _strChatMessage;
48      private int _nEntryType;
49      private Date _dateEntry;
50  
51      /**
52       * Creates a new ChatEntry object.
53       *
54       * @param strNickname The nick name of the user
55       * @param strChatMessage The message
56       * @param nEntryType The type of entry
57       */
58      public ChatEntry( String strNickname, String strChatMessage, int nEntryType )
59      {
60          setChatEntry( strNickname, strChatMessage, nEntryType );
61      }
62  
63      /**
64       * Creates a new ChatEntry object.
65       *
66       * @param strNickname The nick name of the user
67       * @param strChatMessage The message
68       */
69      public ChatEntry( String strNickname, String strChatMessage )
70      {
71          setChatEntry( strNickname, strChatMessage, TYPE_MESSAGE );
72      }
73  
74      /**
75       * Creates a new ChatEntry object.
76       *
77       * @param strChatMessage The message
78       */
79      public ChatEntry( String strChatMessage )
80      {
81          setChatEntry( "", strChatMessage, TYPE_NOTIFICATION );
82      }
83  
84      /**
85       * Sets an entry in the chat with the specified nick name, message, entry type and the current date.
86       *
87       * @param strNickname The nick name of the user
88       * @param strChatMessage The message
89       * @param nEntryType The type of entry
90       */
91      private void setChatEntry( String strNickname, String strChatMessage, int nEntryType )
92      {
93          _strNickname = strNickname;
94          _strChatMessage = strChatMessage;
95          _nEntryType = nEntryType;
96          _dateEntry = new Date(  );
97      }
98  
99      /**
100      * Returns the nick name of this chat entry
101      *
102      * @return The nick name as a String
103      */
104     public String getNickname(  )
105     {
106         return _strNickname;
107     }
108 
109     /**
110      * Returns the message of this Chat entry
111      *
112      * @return The message as a String
113      */
114     public String getChatMessage(  )
115     {
116         return _strChatMessage;
117     }
118 
119     /**
120      * Returns the type of this chat entry
121      *
122      * @return The type as an int
123      */
124     public int getType(  )
125     {
126         return _nEntryType;
127     }
128 
129     /**
130      * Returns the date of this chat entry
131      *
132      * @return The date
133      */
134     public long getTime(  )
135     {
136         return _dateEntry.getTime(  );
137     }
138 }