View Javadoc

1   package org.gnomekr.potron.data;
2   
3   import java.io.Serializable;
4   import java.util.Date;
5   import java.util.List;
6   import java.util.Set;
7   
8   import org.apache.commons.lang.StringUtils;
9   import org.apache.commons.lang.builder.EqualsBuilder;
10  import org.apache.commons.lang.builder.HashCodeBuilder;
11  import org.apache.commons.lang.builder.ToStringBuilder;
12  import org.gnomekr.potron.parser.ParserEntry;
13  
14  /***
15   * TranslatedEntry.java
16   * @author Xavier Cho
17   * @version $Revision 1.1 $ $Date: 2005/09/11 05:49:44 $
18   * @hibernate.class table = "POTRON_TRANS_ENTRY"
19   * @hibernate.cache usage = "nonstrict-read-write"
20   */
21  public class TranslatedEntry implements Serializable {
22  
23      private static final long serialVersionUID = 5411524675311419135L;
24  
25      private long id = -1;
26      private Entry entry;
27      private String comment;
28      private boolean fuzzy = false;
29      private Translation translation;
30      private String translatedString;
31      private List<String> pluralStrings;
32      private User translator;
33      private Date modifiedDate;
34      private Lock lock;
35      private Set<EntryLog> entryLogs;
36  
37      public TranslatedEntry() {
38      }
39  
40      /***
41       * @param entry
42       */
43      public TranslatedEntry(ParserEntry entry) {
44          if (entry != null) {
45              this.comment = entry.getComment();
46              this.fuzzy = entry.isFuzzy();
47  
48              List<String> messages = entry.getMsgStr();
49              if (messages != null && !messages.isEmpty()) {
50                  String message = messages.get(0);
51  
52                  if (message.length() > 0) {
53                      this.translatedString = message;
54                  }
55  
56                  if (messages.size() > 1) {
57                      messages.remove(0);
58                      this.pluralStrings = messages;
59                  }
60              }
61          }
62      }
63  
64      /***
65       * @param entry2
66       */
67      public TranslatedEntry(Entry entry, Translation trans) {
68          if (entry != null) {
69              this.entry = entry;
70              this.comment = entry.getComment();
71          }
72          this.translation = trans;
73      }
74  
75      /***
76       * @return Returns the id.
77       * @hibernate.id
78       *          column = "trans_entry_id"
79       *          length = "20"
80       *          unsaved-value = "-1"
81       *          generator-class = "native"
82       * @hibernate.generator-param
83       *          name = "sequence"
84       *          value = "POTRON_SEQ_TENTRY"
85       */
86      public long getId() {
87          return id;
88      }
89  
90      /***
91       * @return Returns the entry.
92       * @hibernate.many-to-one
93       *          class = "org.gnomekr.potron.data.Entry"
94       *          column = "entry_id"
95       *          not-null = "true"
96       */
97      public Entry getEntry() {
98          return entry;
99      }
100 
101     /***
102      * @return
103      * @hibernate.property
104      *          column = "comment"
105      *          update = "true"
106      *          not-null = "true"
107      *          type = "text"
108      */
109     public String getComment() {
110         return comment;
111     }
112 
113     /***
114      * @return Returns the fuzzy.
115      * @hibernate.property
116      *          column = "fuzzy"
117      *          update = "true"
118      *          not-null = "true"
119      */
120     public boolean isFuzzy() {
121         return fuzzy;
122     }
123 
124     /***
125      * @return Returns the translation.
126      * @hibernate.property
127      *          column = "translation"
128      *          update = "true"
129      *          not-null = "false"
130      *          type = "text"
131      */
132     public String getTranslatedString() {
133         return translatedString;
134     }
135 
136     /***
137      * @return Returns the pluralStrings.
138      * @hibernate.collection-key
139      *          column = "trans_entry_id"
140      *@hibernate.collection-index
141      *          column = "plural_index"
142      *          type = "int"
143      *          length = "10"
144      *@hibernate.collection-element
145      *          column = "plural_str"
146      *          type = "text"
147      * @hibernate.list
148      *          table = "POTRON_PLURAL_STR"
149      *          lazy = "true"
150      *          cascade = "all"
151      */
152     public List<String> getPluralStrings() {
153         return pluralStrings;
154     }
155 
156     /***
157      * @return Returns the translator.
158      * @hibernate.many-to-one
159      *          class = "org.gnomekr.potron.data.User"
160      *          column = "translator"
161      */
162     public User getTranslator() {
163         return translator;
164     }
165 
166     /***
167      * @return
168      * @hibernate.many-to-one
169      *          class = "org.gnomekr.potron.data.Translation"
170      *          column = "trans_id"
171      */
172     public Translation getTranslation() {
173         return translation;
174     }
175 
176     /***
177      * @return Returns the modifiedDate.
178      * @hibernate.property
179      *          column = "modified_date"
180      *          update = "true"
181      *          not-null = "false"
182      */
183     public Date getModifiedDate() {
184         return modifiedDate;
185     }
186 
187     /***
188      * @return Returns the entryLogs.
189      * @hibernate.collection-one-to-many
190      *          class = "org.gnomekr.potron.data.EntryLog"
191      * @hibernate.collection-key
192      *          column = "trans_entry_id"
193      * @hibernate.set
194      *          lazy = "true"
195      *          inverse = "true"
196      *          order-by = "modified_date desc"
197      *          cascade = "all-delete-orphan"
198      */
199     public Set<EntryLog> getEntryLogs() {
200         return entryLogs;
201     }
202 
203     /***
204      * @return Returns the lock.
205      * @hibernate.component
206      *          class = "org.gnomekr.potron.data.Lock"
207      */
208     public Lock getLock() {
209         return lock;
210     }
211 
212     /***
213      * @param comment The comment to set.
214      */
215     public void setComment(String comment) {
216         this.comment = comment;
217     }
218 
219     /***
220      * @param entry The entry to set.
221      */
222     public void setEntry(Entry entry) {
223         this.entry = entry;
224     }
225 
226     /***
227      * @param entryLogs The entryLogs to set.
228      */
229     public void setEntryLogs(Set<EntryLog> entryLogs) {
230         this.entryLogs = entryLogs;
231     }
232 
233     /***
234      * @param fuzzy The fuzzy to set.
235      */
236     public void setFuzzy(boolean fuzzy) {
237         this.fuzzy = fuzzy;
238     }
239 
240     /***
241      * @param id The id to set.
242      */
243     public void setId(long id) {
244         this.id = id;
245     }
246 
247     /***
248      * @param lock The lock to set.
249      */
250     public void setLock(Lock lock) {
251         this.lock = lock;
252     }
253 
254     /***
255      * @param modifiedDate The modifiedDate to set.
256      */
257     public void setModifiedDate(Date modifiedDate) {
258         this.modifiedDate = modifiedDate;
259     }
260 
261     /***
262      * @param translatedString The translatedString to set.
263      */
264     public void setTranslatedString(String translatedString) {
265         if (StringUtils.isBlank(translatedString)) {
266             this.translatedString = null;
267         } else {
268             this.translatedString = translatedString;
269         }
270     }
271 
272     /***
273      * @param pluralStrings The pluralStrings to set.
274      */
275     public void setPluralStrings(List<String> pluralStrings) {
276         this.pluralStrings = pluralStrings;
277     }
278 
279     /***
280      * @param translation
281      */
282     public void setTranslation(Translation translation) {
283         this.translation = translation;
284     }
285 
286     /***
287      * @param translator The translator to set.
288      */
289     public void setTranslator(User translator) {
290         this.translator = translator;
291     }
292 
293     /***
294      * @see java.lang.Object#equals(java.lang.Object)
295      */
296     public boolean equals(final Object object) {
297         if (object instanceof TranslatedEntry) {
298             TranslatedEntry entry = (TranslatedEntry) object;
299 
300             EqualsBuilder builder = new EqualsBuilder();
301             builder.append(id, entry.getId());
302             builder.append(entry, entry.getEntry());
303             builder.append(modifiedDate, entry.getModifiedDate());
304 
305             return builder.isEquals();
306         }
307 
308         return false;
309     }
310 
311     /***
312      * @see java.lang.Object#toString()
313      */
314     public String toString() {
315         ToStringBuilder builder = new ToStringBuilder(this);
316         builder.append("id", id);
317         builder.append("entry", entry);
318         builder.append("translation", translatedString);
319 
320         return builder.toString();
321     }
322 
323     /***
324      * @see java.lang.Object#hashCode()
325      */
326     public int hashCode() {
327         HashCodeBuilder builder = new HashCodeBuilder();
328         builder.append(id);
329         builder.append(entry);
330         builder.append(modifiedDate);
331 
332         return builder.toHashCode();
333     }
334 }