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