BrightSide Workbench Full Report + Source Code
elephant-plugins/src/main/java/org/turro/plugin/command/TimelineEvent.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.plugin.command;
20 
21 import java.text.DateFormat;
22 import java.text.SimpleDateFormat;
23 import java.util.Date;
24 import java.util.TimeZone;
25 import org.turro.string.Strings;
26 import org.turro.elephant.context.Application;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.html.HTMLGenerator;
29 import org.turro.util.CompareUtil;
30 
35 public class TimelineEvent implements Comparable<TimelineEvent> {
36 
37  private Date start, end;
38  private boolean duration;
39  private String title, image, inside, link;
40 
41  public boolean isDuration() {
42  return duration;
43  }
44 
45  public void setDuration(boolean duration) {
46  this.duration = duration;
47  }
48 
49  public Date getEnd() {
50  return end;
51  }
52 
53  public void setEnd(Date end) {
54  this.end = end;
55  }
56 
57  public String getImage() {
58  return image;
59  }
60 
61  public void setImage(String image) {
62  this.image = image;
63  }
64 
65  public String getInside() {
66  return inside;
67  }
68 
69  public void setInside(String inside) {
70  this.inside = inside;
71  }
72 
73  public String getLink() {
74  return link;
75  }
76 
77  public void setLink(String link) {
78  this.link = link;
79  }
80 
81  public Date getStart() {
82  return start;
83  }
84 
85  public void setStart(Date start) {
86  this.start = start;
87  }
88 
89  public String getTitle() {
90  return title;
91  }
92 
93  public void setTitle(String title) {
94  this.title = title;
95  }
96 
97  public String getEvent(Application app) {
98  DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
99  df.setTimeZone(TimeZone.getTimeZone("GMT"));
100  HTMLGenerator hg = new HTMLGenerator();
101  hg.startTag("event", new String[] {
102  (start != null ? "start=\"" + df.format(start) + "\"" : null),
103  (end != null ? "end=\"" + df.format(end) + "\"" : null),
104  (duration ? "isDuration=\"true\"" : null),
105  (!Strings.isBlank(title) ? "title=\"" + Strings.escapeXML(title) + "\"" : null),
106  (!Strings.isBlank(image) ? "image=\"" + ElephantContext.getRootWebPath() + image + "\"" : null),
107  (!Strings.isBlank(link) ? "link=\"" + Strings.escapeXML(link) + "\"" : null)
108  });
109  hg.write("\n");
110  if(!Strings.isBlank(inside)) {
111  hg.write(inside);
112  hg.write("\n");
113  }
114  hg.endAllTags();
115  hg.write("\n");
116  return hg.toString();
117  }
118 
119  @Override
120  public int compareTo(TimelineEvent o) {
121  int result = CompareUtil.compare(start, o.start);
122  if(result == 0) {
123  result = CompareUtil.compare(end, o.end);
124  }
125  if(result == 0) {
126  result = CompareUtil.compare(title, o.title);
127  }
128  return result;
129  }
130 
131 }
HTMLGenerator write(String value)
HTMLGenerator startTag(String tag)