View Javadoc

1   /**
2    * This file Copyright (c) 2003-2010 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.core;
35  
36  import info.magnolia.cms.security.AccessDeniedException;
37  
38  import javax.jcr.ItemNotFoundException;
39  import javax.jcr.Value;
40  import javax.jcr.RepositoryException;
41  import javax.jcr.PathNotFoundException;
42  import javax.jcr.Property;
43  import java.util.Calendar;
44  import java.util.Collection;
45  import java.io.InputStream;
46  
47  
48  /**
49   * Represents a {@linkplain Content content} value object. If the node data does not have any value
50   * {@link #isExist()} returns false. As soon a value is set - null is not considered a value - the
51   * node data starts to exist. The various value read methods ({@link #getString()},
52   * {@link #getBoolean()}, ..) will always return a value (default or null)
53   * @author gjoseph
54   * @version $Revision: $ ($Author: $)
55   */
56  public interface NodeData extends Cloneable {
57      int MULTIVALUE_UNDEFINED = -1;
58      int MULTIVALUE_TRUE = 1;
59      int MULTIVALUE_FALSE = 0;
60  
61      /**
62       * Returns the <code>value</code> of this <code>NodeData</code>. One of type:
63       * <ul>
64       * <li><code>PropertyType.STRING</code></li>
65       * <li><code>PropertyType.DATE</code></li>
66       * <li><code>PropertyType.SOFTLINK</code></li>
67       * <li><code>PropertyType.BINARY</code></li>
68       * <li><code>PropertyType.DOUBLE</code></li>
69       * <li><code>PropertyType.LONG</code></li>
70       * <li><code>PropertyType.BOOLEAN</code></li>
71       * </ul>
72       * @return Value
73       */
74      Value getValue();
75  
76      /**
77       * For multi-value properties.
78       * @return Value[]
79       */
80      Value[] getValues();
81  
82      /**
83       * Returns the <code>String</code> representation of the value: decodes like breaks with the specified regular
84       * expression.
85       * @param lineBreak , regular expression
86       * @return String
87       */
88      String getString(String lineBreak);
89  
90      /**
91       * Returns the <code>String</code> representation of the value.
92       * @return String
93       */
94      String getString();
95  
96      /**
97       * Returns the <code>long</code> representation of the value.
98       * @return long
99       */
100     long getLong();
101 
102     /**
103      * Returns the <code>double</code> representation of the value.
104      * @return double
105      */
106     double getDouble();
107 
108     /**
109      * Returns the <code>Calendar</code> representation of the value.
110      * @return Calendar
111      */
112     Calendar getDate();
113 
114     /**
115      * Returns the <code>boolean</code> representation of the value.
116      * @return boolean
117      */
118     boolean getBoolean();
119 
120     /**
121      * Returns the <code>InputStream</code> representation of the value.
122      * @return boolean
123      */
124     InputStream getStream();
125 
126     /**
127      * Returns the Content that this NodeData references (if its type is PropertyType.REFERENCE). If it is of type PATH
128      * or STRING it tries to resolve the node by using the path. The path can be relative or absolute. If the property
129      * type is STRING, it tries finally to get the node by using the value as an uuid.
130      * @throws javax.jcr.RepositoryException
131      */
132     Content getReferencedContent() throws RepositoryException, PathNotFoundException, RepositoryException;
133 
134     /**
135      * Same as {@link #getReferencedContent()} but achieves the referenced node from a different workspace.
136      */
137     Content getReferencedContent(String repositoryId) throws PathNotFoundException, RepositoryException;
138 
139     /**
140      * Returns the <code>type</code> of this <code>NodeData</code>. One of:
141      * <ul>
142      * <li><code>PropertyType.STRING</code></li>
143      * <li><code>PropertyType.DATE</code></li>
144      * <li><code>PropertyType.SOFTLINK</code></li>
145      * <li><code>PropertyType.BINARY</code></li>
146      * <li><code>PropertyType.DOUBLE</code></li>
147      * <li><code>PropertyType.LONG</code></li>
148      * <li><code>PropertyType.BOOLEAN</code></li>
149      * </ul>
150      * @return PropertyType
151      */
152     int getType();
153 
154     /**
155      * @return atom name
156      */
157     String getName();
158 
159     /**
160      * returns size in bytes.
161      * @return content length
162      */
163     long getContentLength();
164 
165     /**
166      * Access to property at the JCR level. Available only to be available, should not be used in normal circumstances!
167      * @return Property
168      */
169     Property getJCRProperty();
170 
171     /**
172      * set value of type <code>String</code>.
173      * @param value , string to be set
174      * @throws javax.jcr.RepositoryException
175      */
176     void setValue(String value) throws RepositoryException, AccessDeniedException;
177 
178     /**
179      * set value of type <code>int</code>.
180      * @param value , int value to be set
181      * @throws javax.jcr.RepositoryException
182      */
183     void setValue(int value) throws RepositoryException, AccessDeniedException;
184 
185     /**
186      * set value of type <code>long</code>.
187      * @param value , long value to be set
188      * @throws javax.jcr.RepositoryException
189      */
190     void setValue(long value) throws RepositoryException, AccessDeniedException;
191 
192     /**
193      * set value of type <code>InputStream</code>.
194      * @param value , InputStream to be set
195      * @throws javax.jcr.RepositoryException
196      */
197     void setValue(InputStream value) throws RepositoryException, AccessDeniedException;
198 
199     /**
200      * set value of type <code>double</code>.
201      * @param value , double value to be set
202      * @throws javax.jcr.RepositoryException
203      */
204     void setValue(double value) throws RepositoryException, AccessDeniedException;
205 
206     /**
207      * set value of type <code>boolean</code>.
208      * @param value , boolean value to be set
209      * @throws javax.jcr.RepositoryException
210      */
211     void setValue(boolean value) throws RepositoryException, AccessDeniedException;
212 
213     /**
214      * set value of type <code>Calendar</code>.
215      * @param value , Calendar value to be set
216      * @throws javax.jcr.RepositoryException
217      */
218     void setValue(Calendar value) throws RepositoryException, AccessDeniedException;
219 
220     /**
221      * Sets a reference value.
222      */
223     void setValue(Content value) throws RepositoryException, AccessDeniedException;
224     
225     /**
226      * set value of type <code>Value</code>.
227      * @param value
228      * @throws javax.jcr.RepositoryException
229      */
230     void setValue(Value value) throws RepositoryException, AccessDeniedException;
231 
232     /**
233      * set value of type <code>Value[]</code>.
234      * @param value
235      * @throws javax.jcr.RepositoryException
236      */
237     void setValue(Value[] value) throws RepositoryException, AccessDeniedException;
238 
239     /**
240      * set attribute, available only if NodeData is of type <code>Binary</code>.
241      * @param name
242      * @param value
243      * @throws javax.jcr.RepositoryException
244      * @throws info.magnolia.cms.security.AccessDeniedException
245      * @throws UnsupportedOperationException if its not a Binary type
246      */
247     void setAttribute(String name, String value) throws RepositoryException, AccessDeniedException,
248         UnsupportedOperationException;
249 
250     /**
251      * set attribute, available only if NodeData is of type <code>Binary</code>.
252      * @param name
253      * @param value
254      * @throws javax.jcr.RepositoryException
255      * @throws info.magnolia.cms.security.AccessDeniedException
256      * @throws UnsupportedOperationException if its not a Binary type
257      */
258     void setAttribute(String name, Calendar value) throws RepositoryException, AccessDeniedException,
259         UnsupportedOperationException;
260 
261     /**
262      * get attribute, available only if NodeData is of type <code>Binary</code>.
263      * @param name
264      * @return string value
265      */
266     String getAttribute(String name);
267 
268     /**
269      * get all attribute names.
270      * @return collection of attribute names
271      * @throws javax.jcr.RepositoryException
272      */
273     Collection<String> getAttributeNames() throws RepositoryException;
274 
275     /**
276      * checks if the atom exists in the repository.
277      * @return boolean
278      */
279     boolean isExist();
280 
281     /**
282      * get a handle representing path relative to the content repository.
283      * @return String representing path (handle) of the content
284      */
285     String getHandle();
286 
287     /**
288      * Persists all changes to the repository if validation succeeds.
289      * @throws javax.jcr.RepositoryException
290      */
291     void save() throws RepositoryException;
292 
293     /**
294      * checks for the allowed access rights.
295      * @param permissions as defined in javax.jcr.Permission
296      * @return true is the current user has specified access on this node.
297      */
298     boolean isGranted(long permissions);
299 
300     /**
301      * Remove this path.
302      * @throws javax.jcr.RepositoryException
303      */
304     void delete() throws RepositoryException;
305 
306     /**
307      * Refreshes current node keeping all changes.
308      * @throws javax.jcr.RepositoryException
309      * @see javax.jcr.Node#refresh(boolean)
310      */
311     void refresh(boolean keepChanges) throws RepositoryException;
312 
313     /**
314      * for multi-value controls.
315      * @return
316      */
317     int isMultiValue();
318 
319     /**
320      * returns Parent node.
321      */
322     Content getParent() throws AccessDeniedException, ItemNotFoundException, javax.jcr.AccessDeniedException, RepositoryException;
323 
324     HierarchyManager getHierarchyManager();
325 
326 }