View Javadoc

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