1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.api

File PropertyClass.java

 

Coverage histogram

../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

6
24
16
1
255
92
19
0.79
1.5
16
1.19

Classes

Class Line # Actions
PropertyClass 46 24 0% 19 22
0.521739152.2%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.api;
21   
22    import java.util.List;
23    import java.util.Map;
24   
25    import org.xwiki.model.reference.ClassPropertyReference;
26   
27    import com.xpn.xwiki.XWikiContext;
28    import com.xpn.xwiki.objects.classes.ListClass;
29    import com.xpn.xwiki.objects.classes.ListItem;
30    import com.xpn.xwiki.util.Programming;
31   
32    /**
33    * <p>
34    * XProperty definition API.
35    * </p>
36    * <p>
37    * A <strong>property definition</strong> is the instantiation of a {@link com.xpn.xwiki.objects.meta.PropertyMetaClass}
38    * for a particular <strong>Object definition</strong> ({@link Class XClass}), that customizes a property type to suit
39    * the needs of the class. For example, it can set the number type for a
40    * {@link com.xpn.xwiki.objects.classes.NumberClass}, the list of possible values for a
41    * {@link com.xpn.xwiki.objects.classes.StaticListClass}, etc.
42    * </p>
43    *
44    * @version $Id: e9f726cd77a9a9943ce254b75ad64308cba7ac36 $
45    */
 
46    public class PropertyClass extends Collection implements Comparable<PropertyClass>
47    {
48    /**
49    * Default API constructor that creates a wrapper for a {@link com.xpn.xwiki.objects.classes.PropertyClass}, given a
50    * {@link com.xpn.xwiki.XWikiContext context}.
51    *
52    * @param property the property definition to wrap
53    * @param context the current request context
54    */
 
55  17858 toggle public PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass property, XWikiContext context)
56    {
57  17858 super(property, context);
58    }
59   
60    /**
61    * Internal access to the wrapped {@link com.xpn.xwiki.objects.classes.PropertyClass}.
62    *
63    * @return the wrapped property definition
64    */
 
65  9009 toggle protected com.xpn.xwiki.objects.classes.PropertyClass getBasePropertyClass()
66    {
67  9009 return (com.xpn.xwiki.objects.classes.PropertyClass) getCollection();
68    }
69   
 
70  0 toggle @Override
71    public ClassPropertyReference getReference()
72    {
73  0 return getBasePropertyClass().getReference();
74    }
75   
76    /**
77    * Each type of XClass property is identified by a string that specifies the data type of the property value (e.g.
78    * 'String', 'Number', 'Date') without disclosing implementation details. The internal implementation of an XClass
79    * property type can change over time but its {@code classType} should not.
80    * <p>
81    * The {@code classType} can be used as a hint to lookup various components related to this specific XClass property
82    * type or it can be used as a property name to retrieve the meta class of this property from
83    * {@link com.xpn.xwiki.api.XWiki#getMetaclass()}.
84    *
85    * @return an identifier for the data type of the property value (e.g. 'String', 'Number', 'Date')
86    */
 
87  474 toggle public String getClassType()
88    {
89  474 return getBasePropertyClass().getClassType();
90    }
91   
92    /**
93    * Get the actual type of the wrapped {@link com.xpn.xwiki.objects.classes.PropertyClass}. The returned value is
94    * extracted from the class name of the runtime object representing this property definition, and denotes a
95    * user-friendly data type name, for example {@code StringClass}, {@code NumberClass} or {@code StaticListClass}.
96    *
97    * @return the type of this property definition
98    * @see #getClassType() {@code getClassType()} if you need the implementation hint of this property
99    */
 
100  1924 toggle public String getType()
101    {
102  1924 return getBasePropertyClass().getClass().getSimpleName();
103    }
104   
105    /**
106    * Get the name of the {@link com.xpn.xwiki.api.Class XClass} (Object Definition) this property definition belongs
107    * to. For example, {@code XWiki.XWikiUsers} or {@code Blog.BlogPostClass}.
108    *
109    * @return the name of the owner XClass
110    */
 
111  0 toggle public String getClassName()
112    {
113  0 return getBasePropertyClass().getObject().getName();
114    }
115   
116    /**
117    * Provides access to the wrapped {@link com.xpn.xwiki.objects.classes.PropertyClass} if Programming Rights are
118    * present.
119    *
120    * @return the wrapped property definition
121    */
 
122  0 toggle @Programming
123    public com.xpn.xwiki.objects.classes.PropertyClass getPropertyClass()
124    {
125  0 if (hasProgrammingRights()) {
126  0 return getBasePropertyClass();
127    }
128  0 return null;
129    }
130   
131    /**
132    * Get the untranslated user-friendly name of this property. For example, {@code User type} instead of the internal
133    * {@code usertype}.
134    *
135    * @return the configured pretty name of this property definition
136    * @see #getName() {@code getName()} returns the actual property name
137    */
 
138  1803 toggle @Override
139    public String getPrettyName()
140    {
141  1803 return getBasePropertyClass().getPrettyName();
142    }
143   
144    /**
145    * Get the translated user-friendly name of this property.
146    *
147    * @return the configured pretty name of this property definition
148    * @see #getName() {@code getName()} returns the actual property name
149    */
 
150  719 toggle public String getTranslatedPrettyName()
151    {
152  719 return getBasePropertyClass().getTranslatedPrettyName(this.context);
153    }
154   
155    /**
156    * Get the message that should be displayed when a value for an instance of this property definition fails the
157    * validation. For example, {@code Please enter a valid IP address}.
158    *
159    * @return the configured validation message
160    * @see #getValidationRegExp() {@code getValidationRegExp()} returns the regular expression used for validating the
161    * property value
162    */
 
163  0 toggle public String getValidationMessage()
164    {
165  0 return getBasePropertyClass().getValidationMessage();
166    }
167   
168    /**
169    * Get the regular expression used for validating a value for an instance of this property definition.
170    *
171    * @return a string representation of the validation regular expression
172    * @see #getValidationMessage() {@code getValidationMessage()} returns the message that should be displayed in case
173    * the validation failed
174    */
 
175  0 toggle public String getValidationRegExp()
176    {
177  0 return getBasePropertyClass().getValidationRegExp();
178    }
179   
180    /**
181    * Get a tooltip string that should be displayed for input fields for instances of this property definition.
182    *
183    * @return A raw tooltip string. The value does not escape special HTML characters, so the caller should manually
184    * escape quotes if the tooltip should be used as a value for the HTML {@code title} attribute.
185    */
 
186  0 toggle public String getTooltip()
187    {
188  0 return getBasePropertyClass().getTooltip();
189    }
190   
191    /**
192    * See if this property is disabled or not. A disabled property should not be editable, but existing object values
193    * are still kept in the database.
194    *
195    * @return {@code true} if this property is disabled and should not be used, {@code false} otherwise
196    * @since 2.4M2
197    */
 
198  1581 toggle public boolean isDisabled()
199    {
200  1581 return getBasePropertyClass().isDisabled();
201    }
202   
203    /**
204    * If the property is a {@link ListClass}, returns the possible values. These are the internal values (keys), and
205    * not the user-friendly or translated values that would be displayed to the user.
206    *
207    * @return the list of possible ({@code String}) values
208    * @see #getMapValues() {@code getMapValues()} returns both the keys and their user-friendly displayed values
209    **/
 
210  122 toggle public List<String> getListValues()
211    {
212  122 com.xpn.xwiki.objects.classes.PropertyClass pclass = getBasePropertyClass();
213  122 if (pclass instanceof ListClass) {
214  122 return ((ListClass) pclass).getList(this.context);
215    } else {
216    // Although we prefer to return empty lists from API methods, here returning any kind of list doesn't make
217    // sense, since the property does not have a list of possible values at all (like, a number property).
218  0 return null;
219    }
220    }
221   
222    /**
223    * If the property is a {@link ListClass}, returns the possible values as a map {@code internal key <-> displayed
224    * value}.
225    *
226    * @return the map of possible ({@code String}) values and their associated ({@code ListItem}) displayed values
227    * @see #getListValues() {@code getListValues()} returns only the list of possible internal keys
228    **/
 
229  26 toggle public Map<String, ListItem> getMapValues()
230    {
231  26 com.xpn.xwiki.objects.classes.PropertyClass pclass = getBasePropertyClass();
232  26 if (pclass instanceof ListClass) {
233  26 return ((ListClass) pclass).getMap(this.context);
234    } else {
235    // Although we prefer to return empty maps from API methods, here returning any kind of map doesn't make
236    // sense, since the property does not have a list of possible values at all (like, a number property).
237  0 return null;
238    }
239    }
240   
241    /**
242    * Compares two property definitions based on their index number.
243    *
244    * @param other the other property definition to be compared with
245    * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than
246    * the specified object.
247    * @see #getNumber()
248    * @since 2.4M2
249    */
 
250  0 toggle @Override
251    public int compareTo(PropertyClass other)
252    {
253  0 return this.getBasePropertyClass().compareTo(other.getBasePropertyClass());
254    }
255    }