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