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