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: NodeDataWrapper.java 47808 2011-07-28 09:16:08Z had $
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      /**
76       * Default implementation of content wrapping for cases where NodeData needs to return content.
77       * 
78       * @param content
79       * @return
80       */
81      protected Content wrap(Content content) {
82          return content;
83      }
84  
85      @Override
86      public String toString() {
87          final StringBuilder buffer = new StringBuilder();
88          buffer.append(getClass().getSimpleName());
89          buffer.append(" for ");
90          buffer.append(getWrappedNodeData().toString());
91          return buffer.toString();
92      }
93  
94      // ---- below are only generated delegate methods
95      public void delete() throws RepositoryException {
96          getWrappedNodeData().delete();
97      }
98  
99      public String getAttribute(String name) {
100         return getWrappedNodeData().getAttribute(name);
101     }
102 
103     public Collection getAttributeNames() throws RepositoryException {
104         return getWrappedNodeData().getAttributeNames();
105     }
106 
107     public boolean getBoolean() {
108         return getWrappedNodeData().getBoolean();
109     }
110 
111     public long getContentLength() {
112         return getWrappedNodeData().getContentLength();
113     }
114 
115     public Calendar getDate() {
116         return getWrappedNodeData().getDate();
117     }
118 
119     public double getDouble() {
120         return getWrappedNodeData().getDouble();
121     }
122 
123     public String getHandle() {
124         return getWrappedNodeData().getHandle();
125     }
126 
127     public HierarchyManager getHierarchyManager() {
128         return getWrappedNodeData().getHierarchyManager();
129     }
130 
131     public Property getJCRProperty() {
132         return getWrappedNodeData().getJCRProperty();
133     }
134 
135     public long getLong() {
136         return getWrappedNodeData().getLong();
137     }
138 
139     public String getName() {
140         return getWrappedNodeData().getName();
141     }
142 
143     public Content getParent() throws AccessDeniedException, ItemNotFoundException, javax.jcr.AccessDeniedException, RepositoryException {
144         return wrap(getWrappedNodeData().getParent());
145     }
146 
147     public Content getReferencedContent() throws RepositoryException, PathNotFoundException, RepositoryException {
148         return wrap(getWrappedNodeData().getReferencedContent());
149     }
150 
151     public Content getReferencedContent(String repositoryId) throws PathNotFoundException, RepositoryException {
152         return wrap(getWrappedNodeData().getReferencedContent(repositoryId));
153     }
154 
155     public InputStream getStream() {
156         return getWrappedNodeData().getStream();
157     }
158 
159     public String getString() {
160         return getWrappedNodeData().getString();
161     }
162 
163     public String getString(String lineBreak) {
164         return getWrappedNodeData().getString(lineBreak);
165     }
166 
167     public int getType() {
168         return getWrappedNodeData().getType();
169     }
170 
171     public Value getValue() {
172         return getWrappedNodeData().getValue();
173     }
174 
175     public Value[] getValues() {
176         return getWrappedNodeData().getValues();
177     }
178 
179     public boolean isExist() {
180         return getWrappedNodeData().isExist();
181     }
182 
183     public boolean isGranted(long permissions) {
184         return getWrappedNodeData().isGranted(permissions);
185     }
186 
187     public int isMultiValue() {
188         return getWrappedNodeData().isMultiValue();
189     }
190 
191     public void refresh(boolean keepChanges) throws RepositoryException {
192         getWrappedNodeData().refresh(keepChanges);
193     }
194 
195     public void save() throws RepositoryException {
196         getWrappedNodeData().save();
197     }
198 
199     public void setAttribute(String name, Calendar value) throws RepositoryException, AccessDeniedException, UnsupportedOperationException {
200         getWrappedNodeData().setAttribute(name, value);
201     }
202 
203     public void setAttribute(String name, String value) throws RepositoryException, AccessDeniedException, UnsupportedOperationException {
204         getWrappedNodeData().setAttribute(name, value);
205     }
206 
207     public void setValue(boolean value) throws RepositoryException, AccessDeniedException {
208         getWrappedNodeData().setValue(value);
209     }
210 
211     public void setValue(Calendar value) throws RepositoryException, AccessDeniedException {
212         getWrappedNodeData().setValue(value);
213     }
214 
215     public void setValue(double value) throws RepositoryException, AccessDeniedException {
216         getWrappedNodeData().setValue(value);
217     }
218 
219     public void setValue(InputStream value) throws RepositoryException, AccessDeniedException {
220         getWrappedNodeData().setValue(value);
221     }
222 
223     public void setValue(int value) throws RepositoryException, AccessDeniedException {
224         getWrappedNodeData().setValue(value);
225     }
226 
227     public void setValue(long value) throws RepositoryException, AccessDeniedException {
228         getWrappedNodeData().setValue(value);
229     }
230 
231     public void setValue(String value) throws RepositoryException, AccessDeniedException {
232         getWrappedNodeData().setValue(value);
233     }
234 
235     public void setValue(Content value) throws RepositoryException, AccessDeniedException {
236         getWrappedNodeData().setValue(value);
237     }
238 
239     public void setValue(Value value) throws RepositoryException, AccessDeniedException {
240         getWrappedNodeData().setValue(value);
241     }
242 
243     public void setValue(Value[] value) throws RepositoryException, AccessDeniedException {
244         getWrappedNodeData().setValue(value);
245     }
246 
247 }