View Javadoc
1   /*
2    * Copyright (C) 2003-2008 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.services.wcm.link;
18  
19  /**
20   * Created by The eXo Platform SAS
21   * Author : Phan Le Thanh Chuong
22   *          chuong_phan@exoplatform.com
23   * Sep 4, 2008
24   */
25  public class LinkBean {
26  
27    static final public String SEPARATOR = "@";
28    static final public String STATUS = "status=";
29    static final public String URL = "url=";
30  
31    static final public String STATUS_UNCHECKED = "unchecked";
32    static final public String STATUS_ACTIVE = "active";
33    static final public String STATUS_BROKEN = "broken";
34  
35    private String url;
36    private String status;
37  
38    public LinkBean(String url, String status) {
39      this.url = url;
40      this.status = status;
41    }
42  
43    public String getStatus() {
44      return status;
45    }
46  
47    public void setStatus(String status) {
48      this.status = status;
49    }
50  
51    public String getUrl() {
52      return url;
53    }
54  
55    public void setUrl(String url) {
56      this.url = url;
57    }
58  
59    public String toString() {
60      return STATUS + status + SEPARATOR + URL + url;
61    }
62  
63    public boolean isBroken() {
64      return STATUS_BROKEN.equalsIgnoreCase(status);
65    }
66  
67    public boolean isUnchecked() {
68      return STATUS_UNCHECKED.equalsIgnoreCase(status);
69    }
70  
71    public boolean isActive() {
72      return STATUS_ACTIVE.equalsIgnoreCase(status);
73    }
74  
75    public static LinkBean parse(String link) {
76      if (link == null) return new LinkBean("","");
77      String[] links = link.split(SEPARATOR);
78      if (links.length < 2) return new LinkBean("","");
79      String url = links[1].replaceAll(URL, "");
80      String status = links[0].replaceAll(STATUS, "");
81      return new LinkBean(url,status);
82    }
83  }