View Javadoc
1   /**
2    * This file Copyright (c) 2012 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
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   * Simple POJO containing relevant informations for the display.
49   * This bean is used as well for the XML and configuration rendering.
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      // Used to display xml siteMaps Infos
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      // Used to display edit Infos
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       * Getter and Setter Section.
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      * Implementation for the Comparable Interface.
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      * Used for to check the unicity in the set.
255      */
256     @Override
257     public boolean equals(Object obj) {
258         // Check if this is the same object
259         if (obj==this) {
260             return true;
261         }
262 
263         // Check Class Type
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 }