View Javadoc

1   /**
2    * This file Copyright (c) 2003-2011 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.exchangesimple;
35  
36  import info.magnolia.cms.exchange.Subscription;
37  
38  /**
39   * Bean holder for the default subscription information.
40   * @author Sameer Charles
41   * $Id: DefaultSubscription.java 52595 2011-12-13 08:40:26Z had $
42   */
43  public class DefaultSubscription implements Subscription {
44      private String name;
45  
46      private String fromURI;
47  
48      private String toURI;
49  
50      private String repository;
51  
52      private boolean enabled = true;
53  
54      @Override
55      public String getName() {
56          return name;
57      }
58  
59      @Override
60      public void setName(String name) {
61          this.name = name;
62      }
63  
64      @Override
65      public String getFromURI() {
66          return fromURI;
67      }
68  
69      @Override
70      public void setFromURI(String fromURI) {
71          this.fromURI = fromURI;
72      }
73  
74      @Override
75      public String getToURI() {
76          return toURI;
77      }
78  
79      @Override
80      public void setToURI(String toURI) {
81          this.toURI = toURI;
82      }
83  
84      @Override
85      public String getRepository() {
86          return repository;
87      }
88  
89      @Override
90      public void setRepository(String repository) {
91          this.repository = repository;
92      }
93  
94      /**
95       * Checks if we are subscribed to the given path.
96       * @param value path to check
97       * @return the length of the fromURI
98       * */
99      @Override
100     public int vote(Object value) {
101         if (value == null || getFromURI() == null) {
102             // vote false, but do not throw exception (NPE)
103             return -1;
104         }
105         String path = String.valueOf(value);
106         String subscribedPath = getFromURI();
107         if (path.equals(subscribedPath)) {
108             return subscribedPath.length();
109         }
110         if (!subscribedPath.endsWith("/")) {
111             subscribedPath += "/";
112         }
113         if (path.startsWith(subscribedPath)) {
114             return subscribedPath.length();
115         }
116 
117         return -1;
118     }
119 
120     @Override
121     public boolean isEnabled() {
122         return enabled;
123     }
124 
125     public void setEnabled(boolean enabled) {
126         this.enabled = enabled;
127     }
128 }