View Javadoc
1   /**
2    * This file Copyright (c) 2009-2015 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.NodeData;
39  import info.magnolia.cms.security.AccessDeniedException;
40  
41  import java.io.InputStream;
42  import java.util.Calendar;
43  import java.util.Collection;
44  
45  import javax.jcr.ItemNotFoundException;
46  import javax.jcr.PathNotFoundException;
47  import javax.jcr.Property;
48  import javax.jcr.RepositoryException;
49  import javax.jcr.Value;
50  
51  
52  /**
53   * Wraps a {@link NodeData} to which it delegates. Used to manipulate node datas.
54   */
55  public abstract class NodeDataWrapper implements NodeData {
56  
57      private NodeData wrappedNodeData;
58  
59      public NodeDataWrapper() {
60      }
61  
62      public NodeDataWrapper(NodeData wrappedNodeData) {
63          this.wrappedNodeData = wrappedNodeData;
64      }
65  
66      public NodeData getWrappedNodeData() {
67          return this.wrappedNodeData;
68      }
69  
70      public void setWrappedNodeData(NodeData wrappedNodeData) {
71          this.wrappedNodeData = wrappedNodeData;
72      }
73  
74      @Override
75      public String toString() {
76          final StringBuilder builder = new StringBuilder();
77          builder.append(getClass().getSimpleName());
78          builder.append(" for ");
79          builder.append(getWrappedNodeData().toString());
80          return builder.toString();
81      }
82  
83      /**
84       * Default implementation of content wrapping for cases where NodeData needs to return content.
85       */
86      protected Content wrap(Content content) {
87          return content;
88      }
89  
90      // ---- below are only generated delegate methods
91      @Override
92      public void delete() throws RepositoryException {
93          getWrappedNodeData().delete();
94      }
95  
96      @Override
97      public String getAttribute(String name) {
98          return getWrappedNodeData().getAttribute(name);
99      }
100 
101     @Override
102     public Collection<String> getAttributeNames() throws RepositoryException {
103         return getWrappedNodeData().getAttributeNames();
104     }
105 
106     @Override
107     public boolean getBoolean() {
108         return getWrappedNodeData().getBoolean();
109     }
110 
111     @Override
112     public long getContentLength() {
113         return getWrappedNodeData().getContentLength();
114     }
115 
116     @Override
117     public Calendar getDate() {
118         return getWrappedNodeData().getDate();
119     }
120 
121     @Override
122     public double getDouble() {
123         return getWrappedNodeData().getDouble();
124     }
125 
126     @Override
127     public String getHandle() {
128         return getWrappedNodeData().getHandle();
129     }
130 
131     @Override
132     public HierarchyManager getHierarchyManager() {
133         return getWrappedNodeData().getHierarchyManager();
134     }
135 
136     @Override
137     public Property getJCRProperty() throws PathNotFoundException {
138         return getWrappedNodeData().getJCRProperty();
139     }
140 
141     @Override
142     public long getLong() {
143         return getWrappedNodeData().getLong();
144     }
145 
146     @Override
147     public String getName() {
148         return getWrappedNodeData().getName();
149     }
150 
151     @Override
152     public Content getParent() throws AccessDeniedException, ItemNotFoundException, javax.jcr.AccessDeniedException, RepositoryException {
153         return wrap(getWrappedNodeData().getParent());
154     }
155 
156     @Override
157     public Content getReferencedContent() throws RepositoryException, PathNotFoundException, RepositoryException {
158         return wrap(getWrappedNodeData().getReferencedContent());
159     }
160 
161     @Override
162     public Content getReferencedContent(String repositoryId) throws PathNotFoundException, RepositoryException {
163         return wrap(getWrappedNodeData().getReferencedContent(repositoryId));
164     }
165 
166     @Override
167     public InputStream getStream() {
168         return getWrappedNodeData().getStream();
169     }
170 
171     @Override
172     public String getString() {
173         return getWrappedNodeData().getString();
174     }
175 
176     @Override
177     public String getString(String lineBreak) {
178         return getWrappedNodeData().getString(lineBreak);
179     }
180 
181     @Override
182     public int getType() {
183         return getWrappedNodeData().getType();
184     }
185 
186     @Override
187     public Value getValue() {
188         return getWrappedNodeData().getValue();
189     }
190 
191     @Override
192     public Value[] getValues() {
193         return getWrappedNodeData().getValues();
194     }
195 
196     @Override
197     public boolean isExist() {
198         return getWrappedNodeData().isExist();
199     }
200 
201     @Override
202     public boolean isGranted(long permissions) {
203         return getWrappedNodeData().isGranted(permissions);
204     }
205 
206     @Override
207     public int isMultiValue() {
208         return getWrappedNodeData().isMultiValue();
209     }
210 
211     @Override
212     public void refresh(boolean keepChanges) throws RepositoryException {
213         getWrappedNodeData().refresh(keepChanges);
214     }
215 
216     @Override
217     public void save() throws RepositoryException {
218         getWrappedNodeData().save();
219     }
220 
221     @Override
222     public void setAttribute(String name, Calendar value) throws RepositoryException, AccessDeniedException, UnsupportedOperationException {
223         getWrappedNodeData().setAttribute(name, value);
224     }
225 
226     @Override
227     public void setAttribute(String name, String value) throws RepositoryException, AccessDeniedException, UnsupportedOperationException {
228         getWrappedNodeData().setAttribute(name, value);
229     }
230 
231     @Override
232     public void setValue(boolean value) throws RepositoryException, AccessDeniedException {
233         getWrappedNodeData().setValue(value);
234     }
235 
236     @Override
237     public void setValue(Calendar value) throws RepositoryException, AccessDeniedException {
238         getWrappedNodeData().setValue(value);
239     }
240 
241     @Override
242     public void setValue(double value) throws RepositoryException, AccessDeniedException {
243         getWrappedNodeData().setValue(value);
244     }
245 
246     @Override
247     public void setValue(InputStream value) throws RepositoryException, AccessDeniedException {
248         getWrappedNodeData().setValue(value);
249     }
250 
251     @Override
252     public void setValue(int value) throws RepositoryException, AccessDeniedException {
253         getWrappedNodeData().setValue(value);
254     }
255 
256     @Override
257     public void setValue(long value) throws RepositoryException, AccessDeniedException {
258         getWrappedNodeData().setValue(value);
259     }
260 
261     @Override
262     public void setValue(String value) throws RepositoryException, AccessDeniedException {
263         getWrappedNodeData().setValue(value);
264     }
265 
266     @Override
267     public void setValue(Content value) throws RepositoryException, AccessDeniedException {
268         getWrappedNodeData().setValue(value);
269     }
270 
271     @Override
272     public void setValue(Value value) throws RepositoryException, AccessDeniedException {
273         getWrappedNodeData().setValue(value);
274     }
275 
276     @Override
277     public void setValue(Value[] value) throws RepositoryException, AccessDeniedException {
278         getWrappedNodeData().setValue(value);
279     }
280 
281 }