View Javadoc

1   /**
2    * This file Copyright (c) 2009-2010 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.cms.util;
35  
36  import info.magnolia.cms.core.Content;
37  import info.magnolia.cms.core.HierarchyManager;
38  import info.magnolia.cms.core.ItemType;
39  import info.magnolia.cms.core.NodeData;
40  import info.magnolia.cms.core.search.QueryManager;
41  import info.magnolia.cms.security.AccessDeniedException;
42  import info.magnolia.cms.security.AccessManager;
43  
44  import javax.jcr.RepositoryException;
45  import javax.jcr.Workspace;
46  
47  /**
48   *
49   * @author gjoseph
50   * @version $Revision: $ ($Author: $)
51   */
52  public abstract class HierarchyManagerWrapper implements HierarchyManager {
53  
54      private final HierarchyManager wrappedHM;
55  
56      protected HierarchyManagerWrapper(HierarchyManager wrappedHM) {
57          this.wrappedHM = wrappedHM;
58      }
59  
60      public HierarchyManager getWrappedHierarchyManager() {
61          return wrappedHM;
62      }
63  
64      /**
65       * @deprecated since 4.3 use getWrappedHierarchyManager() instead
66       */
67      @Deprecated
68      public HierarchyManager getDelegate() {
69          return wrappedHM;
70      }
71  
72      public String toString() {
73          final StringBuilder buffer = new StringBuilder();
74          buffer.append(getClass().getSimpleName());
75          buffer.append(" for ");
76          buffer.append(getWrappedHierarchyManager().toString());
77          return buffer.toString();
78      }
79  
80  
81      /**
82       * Override this method to have hierarchy manager wrap every piece of content it returns
83       * @param content unwrapped content
84       * @return wrapped content (or content passed in if not overriden)
85       */
86      protected Content wrap(Content content) {
87          return content;
88      }
89  
90      /**
91       * Override this method to have hierarchy manager wrap every piece of node data it returns
92       * @param nodeData unwrapped node data
93       * @return wrapped node data (or node data passed in if not overriden)
94       */
95      protected NodeData wrap(NodeData nodeData) {
96          return nodeData;
97      }
98  
99      /**
100      * Override this method to alter all paths passed into the various hierarchy manager methods.
101      * @param path unaltered path
102      * @return wrapped path (or the one passed in if not overridden)
103      */
104     protected String transformPath(String path) {
105         return path;
106     }
107 
108     // ---- below are only generated wrappedHM methods
109     public AccessManager getAccessManager() {
110         return getWrappedHierarchyManager().getAccessManager();
111     }
112 
113     public QueryManager getQueryManager() {
114         return getWrappedHierarchyManager().getQueryManager();
115     }
116 
117     public Content createContent(String path, String label, String contentType) throws RepositoryException {
118         path = transformPath(path);
119         return wrap(getWrappedHierarchyManager().createContent(path, label, contentType));
120     }
121 
122     public Content getContent(String path) throws RepositoryException {
123         path = transformPath(path);
124         return wrap(getWrappedHierarchyManager().getContent(path));
125     }
126 
127     public Content getContent(String path, boolean create, ItemType type) throws RepositoryException {
128         path = transformPath(path);
129         return wrap(getWrappedHierarchyManager().getContent(path, create, type));
130     }
131 
132     public NodeData getNodeData(String path) throws RepositoryException {
133         path = transformPath(path);
134         return wrap(getWrappedHierarchyManager().getNodeData(path));
135     }
136 
137     /**
138      * @deprecated since 4.0 - use getContent().isNodeType() instead. (not used currently)
139       */
140      @Deprecated
141     public Content getPage(String path, String templateName) throws RepositoryException {
142         path = transformPath(path);
143         return wrap(getWrappedHierarchyManager().getPage(path, templateName));
144     }
145 
146     public void delete(String path) throws RepositoryException {
147         path = transformPath(path);
148         getWrappedHierarchyManager().delete(path);
149     }
150 
151     public Content getRoot() throws RepositoryException {
152         return wrap(getWrappedHierarchyManager().getRoot());
153     }
154 
155     /**
156      * @deprecated since 4.0 - use getContent().isNodeType() instead.
157       */
158      @Deprecated
159     public boolean isPage(String path) throws AccessDeniedException {
160         path = transformPath(path);
161         return getWrappedHierarchyManager().isPage(path);
162     }
163 
164     public boolean isExist(String path) {
165         path = transformPath(path);
166         return getWrappedHierarchyManager().isExist(path);
167     }
168 
169     public boolean isGranted(String path, long permissions) {
170         path = transformPath(path);
171         return getWrappedHierarchyManager().isGranted(path, permissions);
172     }
173 
174     /**
175      * @deprecated since 4.0 - use getContent().isNodeType() instead.
176       */
177      @Deprecated
178     public boolean isNodeType(String path, String type) {
179         path = transformPath(path);
180         return getWrappedHierarchyManager().isNodeType(path, type);
181     }
182 
183     /**
184     * @deprecated since 4.0 - use getContent().isNodeType() instead. (not used currently)
185      */
186     @Deprecated
187     public boolean isNodeType(String path, ItemType type) {
188         path = transformPath(path);
189         return getWrappedHierarchyManager().isNodeType(path, type);
190     }
191 
192     public boolean isNodeData(String path) throws AccessDeniedException {
193         path = transformPath(path);
194         return getWrappedHierarchyManager().isNodeData(path);
195     }
196 
197     public Content getContentByUUID(String uuid) throws RepositoryException {
198         return wrap(getWrappedHierarchyManager().getContentByUUID(uuid));
199     }
200 
201     public Workspace getWorkspace() {
202         return getWrappedHierarchyManager().getWorkspace();
203     }
204 
205     public void moveTo(String source, String destination) throws RepositoryException {
206         source = transformPath(source);
207         destination = transformPath(destination);
208         getWrappedHierarchyManager().moveTo(source, destination);
209     }
210 
211     public void copyTo(String source, String destination) throws RepositoryException {
212         source = transformPath(source);
213         destination = transformPath(destination);
214         getWrappedHierarchyManager().copyTo(source, destination);
215     }
216 
217     public void save() throws RepositoryException {
218         getWrappedHierarchyManager().save();
219     }
220 
221     public boolean hasPendingChanges() throws RepositoryException {
222         return getWrappedHierarchyManager().hasPendingChanges();
223     }
224 
225     public void refresh(boolean keepChanges) throws RepositoryException {
226         getWrappedHierarchyManager().refresh(keepChanges);
227     }
228 
229     public String getName() {
230         return getWrappedHierarchyManager().getName();
231     }
232 }