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 info.magnolia.module.googlesitemap.bean;
35
36
37 import info.magnolia.jcr.util.NodeTypes;
38 import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration;
39 import info.magnolia.module.googlesitemap.SiteMapNodeTypes;
40
41 import javax.jcr.Node;
42 import javax.jcr.RepositoryException;
43 import javax.xml.bind.annotation.XmlElement;
44 import javax.xml.bind.annotation.XmlRootElement;
45 import javax.xml.bind.annotation.XmlTransient;
46
47
48
49
50
51 @XmlRootElement(name="url")
52 public class SiteMapEntry implements Comparable<SiteMapEntry>{
53
54 public final static String PRIORITY_NAME = "priority";
55 public final static String CHANGE_FREQ_NAME = "changefreq";
56 public final static String SITE_ALERT_NAME = "styleAlert";
57 public final static String PATH_NAME = "path";
58 public final static String PAGE_NAME = "pageName";
59 public final static String FROM_NAME = "from";
60 public final static String TO_NAME = "to";
61
62
63 private String loc;
64 private String lastmod;
65 private String changefreq;
66 private Double priority;
67 private boolean hide;
68 private boolean hideChildren;
69
70
71 private int level;
72 private String path;
73 private boolean styleAlert;
74 private String pageName;
75 private String from;
76 private String to;
77
78 public SiteMapEntry() {
79 }
80
81 public SiteMapEntry(GoogleSiteMapConfiguration configuration, String loc, Node page, int rootLevel, String changefreq, Double priority) throws RepositoryException {
82 this.loc = loc;
83 this.lastmod = configuration.getFastDateFormat().format(NodeTypes.LastModified.getLastModified(page));
84 this.path = page.getPath();
85 this.level = page.getDepth() - rootLevel;
86 this.changefreq = SiteMapNodeTypes.GoogleSiteMap.getChangeFreq(page) != null ? SiteMapNodeTypes.GoogleSiteMap.getChangeFreq(page) : changefreq;
87 this.priority = SiteMapNodeTypes.GoogleSiteMap.getPriority(page) != null ? SiteMapNodeTypes.GoogleSiteMap.getPriority(page) : priority;
88 this.hide = SiteMapNodeTypes.GoogleSiteMap.isHide(page);
89 this.hideChildren = SiteMapNodeTypes.GoogleSiteMap.isHideChildren(page);
90 }
91
92
93
94
95
96 @XmlElement
97 public String getLoc() {
98 return loc;
99 }
100
101 public void setLoc(String loc) {
102 this.loc = loc;
103 }
104
105 @XmlElement
106 public String getLastmod() {
107 return lastmod;
108 }
109
110
111 public void setLastmod(String lastmod) {
112 this.lastmod = lastmod;
113 }
114
115 @XmlElement
116 public String getChangefreq() {
117 return changefreq;
118 }
119
120
121 public void setChangefreq(String changefreq) {
122 this.changefreq = changefreq;
123 }
124
125 @XmlElement
126 public Double getPriority() {
127 return priority;
128 }
129
130
131 public void setPriority(Double priority) {
132 this.priority = priority;
133 }
134
135 @XmlTransient
136 public int getLevel() {
137 return level;
138 }
139
140
141 public void setLevel(int level) {
142 this.level = level;
143 }
144
145 @XmlTransient
146 public String getPath() {
147 return path;
148 }
149
150
151 public void setPath(String path) {
152 this.path = path;
153 }
154
155 @XmlTransient
156 public boolean isStyleAlert() {
157 return styleAlert;
158 }
159
160
161 public void setStyleAlert(boolean styleAlert) {
162 this.styleAlert = styleAlert;
163 }
164
165
166 @XmlTransient
167 public String getPageName() {
168 return pageName;
169 }
170
171 public void setPageName(String pageName) {
172 this.pageName = pageName;
173 }
174
175 @XmlTransient
176 public String getFrom() {
177 return from;
178 }
179
180
181 public void setFrom(String from) {
182 this.from = from;
183 }
184
185 @XmlTransient
186 public String getTo() {
187 return to;
188 }
189
190
191 public void setTo(String to) {
192 this.to = to;
193 }
194
195 @XmlTransient
196 public boolean isHide() {
197 return hide;
198 }
199
200 public void setHide(boolean hide) {
201 this.hide = hide;
202 }
203
204 @XmlTransient
205 public boolean isHideChildren() {
206 return hideChildren;
207 }
208
209 public void setHideChildren(boolean hideChildren) {
210 this.hideChildren = hideChildren;
211 }
212
213 public String toStringDisplay(){
214 StringBuffer sb = new StringBuffer();
215 sb.append("loc :"+loc);
216 sb.append("lastmod :"+lastmod);
217 sb.append("changefreq :"+changefreq);
218 sb.append("priority :"+priority);
219 return sb.toString();
220 }
221
222 public String toStringSite(){
223 StringBuffer sb = new StringBuffer();
224 sb.append("path :"+path);
225 sb.append("pageName :" + pageName);
226 return sb.toString();
227 }
228
229 public String toStringVirtualUri(){
230 StringBuffer sb = new StringBuffer();
231 sb.append("path :"+path);
232 sb.append("from :"+from);
233 sb.append("to :"+to);
234 return sb.toString();
235 }
236
237
238
239
240 @Override
241 public int compareTo(SiteMapEntry obj) {
242 if(obj == null) {
243 return -1;
244 }
245
246 if (obj==this) {
247 return 0;
248 }
249
250 return (obj).getLoc().compareTo(this.getLoc());
251
252 }
253
254
255
256 @Override
257 public boolean equals(Object obj) {
258
259 if (obj==this) {
260 return true;
261 }
262
263
264 if (obj instanceof SiteMapEntry) {
265 return ((SiteMapEntry)obj).getLoc().equals(this.getLoc());
266 }
267
268 return false;
269 }
270
271 @Override
272 public int hashCode() {
273 int hash = 15;
274 hash = hash * getLoc().hashCode();
275 return hash;
276 }
277
278 }