1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.objects.classes

File BaseClass.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
41% of files have more coverage

Code metrics

182
497
100
1
1,503
1,023
210
0.42
4.97
100
2.1

Classes

Class Line # Actions
BaseClass 66 497 0% 210 148
0.810012881%
 

Contributing tests

This file is covered by 153 tests. .

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.objects.classes;
21   
22    import java.util.ArrayList;
23    import java.util.Collection;
24    import java.util.Collections;
25    import java.util.List;
26    import java.util.Map;
27    import java.util.Set;
28   
29    import org.apache.commons.lang3.StringUtils;
30    import org.dom4j.Element;
31    import org.xwiki.model.EntityType;
32    import org.xwiki.model.reference.DocumentReference;
33    import org.xwiki.model.reference.DocumentReferenceResolver;
34    import org.xwiki.model.reference.EntityReference;
35    import org.xwiki.model.reference.SpaceReference;
36    import org.xwiki.security.authorization.ContextualAuthorizationManager;
37    import org.xwiki.security.authorization.Right;
38   
39    import com.google.common.base.Objects;
40    import com.xpn.xwiki.XWikiContext;
41    import com.xpn.xwiki.XWikiException;
42    import com.xpn.xwiki.doc.XWikiDocument;
43    import com.xpn.xwiki.doc.merge.MergeConfiguration;
44    import com.xpn.xwiki.doc.merge.MergeResult;
45    import com.xpn.xwiki.internal.merge.MergeUtils;
46    import com.xpn.xwiki.objects.BaseCollection;
47    import com.xpn.xwiki.objects.BaseObject;
48    import com.xpn.xwiki.objects.BaseProperty;
49    import com.xpn.xwiki.objects.ElementInterface;
50    import com.xpn.xwiki.objects.ObjectDiff;
51    import com.xpn.xwiki.objects.PropertyInterface;
52    import com.xpn.xwiki.objects.classes.TextAreaClass.ContentType;
53    import com.xpn.xwiki.objects.classes.TextAreaClass.EditorType;
54    import com.xpn.xwiki.objects.meta.MetaClass;
55    import com.xpn.xwiki.objects.meta.PropertyMetaClass;
56    import com.xpn.xwiki.validation.XWikiValidationInterface;
57    import com.xpn.xwiki.validation.XWikiValidationStatus;
58    import com.xpn.xwiki.web.Utils;
59   
60    /**
61    * Represents an XClass, and contains XClass properties. Each field from {@link BaseCollection} is of type
62    * {@link PropertyClass} and defines a single XClass property.
63    *
64    * @version $Id: c5520885e8826f67bd1205da788fa4ffe950c206 $
65    */
 
66    public class BaseClass extends BaseCollection<DocumentReference> implements ClassInterface
67    {
68    private String customMapping;
69   
70    private String customClass;
71   
72    private String defaultWeb;
73   
74    private String defaultViewSheet;
75   
76    private String defaultEditSheet;
77   
78    private String validationScript;
79   
80    private String nameField;
81   
82    /**
83    * Set to true if the class is modified from the database version of it.
84    */
85    private boolean isDirty = true;
86   
87    /**
88    * Used to resolve a string into a proper Document Reference using the current document's reference to fill the
89    * blanks, except for the page name for which the default page name is used instead and for the wiki name for which
90    * the current wiki is used instead of the current document reference's wiki.
91    */
92    private DocumentReferenceResolver<String> currentMixedDocumentReferenceResolver;
93   
94    private DocumentReferenceResolver<String> currentDocumentReferenceResolver;
95   
 
96  4 toggle private DocumentReferenceResolver<String> getCurrentMixedDocumentReferenceResolver()
97    {
98  4 if (this.currentMixedDocumentReferenceResolver == null) {
99  4 this.currentMixedDocumentReferenceResolver =
100    Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
101    }
102   
103  4 return this.currentMixedDocumentReferenceResolver;
104    }
105   
106    /**
107    * Used to resolve a string into a proper Document Reference using the current document's reference to fill the
108    * blanks.
109    *
110    * @since 7.2M3
111    */
 
112  2 toggle private DocumentReferenceResolver<String> getCurrentDocumentReferenceResolver()
113    {
114  2 if (this.currentDocumentReferenceResolver == null) {
115  1 this.currentDocumentReferenceResolver =
116    Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "current");
117    }
118   
119  2 return this.currentDocumentReferenceResolver;
120    }
121   
 
122  276522 toggle @Override
123    public DocumentReference getReference()
124    {
125  276522 return getDocumentReference();
126    }
127   
128    /**
129    * {@inheritDoc}
130    * <p>
131    * Note: This method is overridden to add the deprecation warning so that code using is can see it's deprecated.
132    * </p>
133    *
134    * @deprecated since 2.2M2 use {@link #getDocumentReference()}
135    */
 
136  356239 toggle @Deprecated
137    @Override
138    public String getName()
139    {
140  356249 return super.getName();
141    }
142   
143    /**
144    * {@inheritDoc}
145    * <p>
146    * Note: BaseElement#setName() does not support setting reference anymore since 2.4M2. This was broken and has been
147    * replaced by this overridden method. See XWIKI-5285
148    * </p>
149    *
150    * @deprecated since 2.2M2 use {@link #setDocumentReference(org.xwiki.model.reference.DocumentReference)}
151    */
 
152  1718 toggle @Deprecated
153    @Override
154    public void setName(String name)
155    {
156  1718 if (this instanceof MetaClass || this instanceof PropertyMetaClass) {
157  1608 super.setName(name);
158    } else {
159  110 DocumentReference reference = getDocumentReference();
160   
161  110 if (reference != null) {
162  106 EntityReference relativeReference =
163    getRelativeEntityReferenceResolver().resolve(name, EntityType.DOCUMENT);
164  106 reference = new DocumentReference(relativeReference.extractReference(EntityType.DOCUMENT).getName(),
165    new SpaceReference(relativeReference.extractReference(EntityType.SPACE).getName(),
166    reference.getParent().getParent()));
167    } else {
168  4 reference = getCurrentMixedDocumentReferenceResolver().resolve(name);
169    }
170  110 setDocumentReference(reference);
171    }
172  1718 setDirty(true);
173    }
174   
175    /**
176    * {@inheritDoc}
177    * <p>
178    * This insures natural ordering between properties.
179    * </p>
180    *
181    * @see com.xpn.xwiki.objects.BaseCollection#addField(java.lang.String, com.xpn.xwiki.objects.PropertyInterface)
182    */
 
183  154098 toggle @Override
184    public void addField(String name, PropertyInterface element)
185    {
186  154098 Set<String> properties = getPropertyList();
187  154098 if (!properties.contains(name)) {
188  154097 if (((BaseCollection) element).getNumber() == 0) {
189  56460 ((BaseCollection) element).setNumber(properties.size() + 1);
190    }
191    }
192   
193  154098 super.addField(name, element);
194   
195  154097 setDirty(true);
196    }
197   
198    /**
199    * Mark a property as disabled. A disabled property should not be editable, but existing object values are still
200    * kept in the database.
201    *
202    * @param name the name of the property to disable
203    * @since 2.4M2
204    */
 
205  0 toggle public void disableField(String name)
206    {
207  0 PropertyClass pclass = (PropertyClass) safeget(name);
208   
209  0 if (pclass != null) {
210  0 pclass.setDisabled(true);
211    }
212   
213  0 setDirty(true);
214    }
215   
216    /**
217    * Re-enable a property. This field will appear again in object instances.
218    *
219    * @param name the name of the property to enable
220    * @since 2.4M2
221    */
 
222  0 toggle public void enableField(String name)
223    {
224  0 PropertyClass pclass = (PropertyClass) safeget(name);
225   
226  0 if (pclass != null) {
227  0 pclass.setDisabled(false);
228    }
229   
230  0 setDirty(true);
231    }
232   
 
233  1724650 toggle @Override
234    public PropertyInterface get(String name)
235    {
236  1724656 return safeget(name);
237    }
238   
 
239  35970 toggle @Override
240    public void put(String name, PropertyInterface property)
241    {
242  35970 safeput(name, property);
243  35970 setDirty(true);
244    }
245   
246    /**
247    * Get the list of enabled (the default, normal state) property definitions that exist in this class. The resulting
248    * list is unmodifiable, but the contained elements are live.
249    *
250    * @return an unmodifiable list containing the enabled properties of the class
251    * @see PropertyClass#isDisabled()
252    * @since 2.4M2
253    */
 
254  2 toggle public List<PropertyClass> getEnabledProperties()
255    {
256  2 @SuppressWarnings("unchecked")
257    Collection<PropertyClass> allProperties = getFieldList();
258  2 if (allProperties == null) {
259  0 return Collections.emptyList();
260    }
261   
262  2 List<PropertyClass> enabledProperties = new ArrayList<PropertyClass>(allProperties.size());
263   
264  2 for (PropertyClass property : allProperties) {
265  156 if (property != null && !property.isDisabled()) {
266  156 enabledProperties.add(property);
267    }
268    }
269   
270  2 Collections.sort(enabledProperties);
271  2 return Collections.unmodifiableList(enabledProperties);
272    }
273   
274    /**
275    * Get the list of disabled property definitions that exist in this class. The resulting list is unmodifiable, but
276    * the contained elements are live.
277    *
278    * @return an unmodifiable list containing the disabled properties of the class
279    * @see PropertyClass#isDisabled()
280    * @since 2.4M2
281    */
 
282  0 toggle public List<PropertyClass> getDisabledProperties()
283    {
284  0 @SuppressWarnings("unchecked")
285    Collection<PropertyClass> allProperties = getFieldList();
286  0 if (allProperties == null) {
287  0 return Collections.emptyList();
288    }
289   
290  0 List<PropertyClass> disabledProperties = new ArrayList<PropertyClass>();
291   
292  0 for (PropertyClass property : allProperties) {
293  0 if (property != null && property.isDisabled()) {
294  0 disabledProperties.add(property);
295    }
296    }
297   
298  0 Collections.sort(disabledProperties);
299  0 return Collections.unmodifiableList(disabledProperties);
300    }
301   
302    /**
303    * Get the list of disabled properties that exist in a given object. This list is a subset of all the disabled
304    * properties in a class, since the object could have been created and stored before some of the class properties
305    * were added. The resulting list is unmodifiable, but the contained elements are live.
306    *
307    * @param object the instance of this class where the disabled properties must exist
308    * @return an unmodifiable list containing the disabled properties of the given object
309    * @see PropertyClass#isDisabled()
310    * @since 2.4M2
311    */
 
312  0 toggle public List<PropertyClass> getDisabledObjectProperties(BaseObject object)
313    {
314  0 List<PropertyClass> disabledProperties = getDisabledProperties();
315  0 if (disabledProperties == null) {
316  0 return Collections.emptyList();
317    }
318   
319  0 List<PropertyClass> disabledObjectProperties = new ArrayList<PropertyClass>(disabledProperties.size());
320   
321  0 for (PropertyClass property : disabledProperties) {
322  0 try {
323  0 if (object.get(property.getName()) != null) {
324  0 disabledObjectProperties.add(property);
325    }
326    } catch (XWikiException ex) {
327    // Not really gonna happen
328    }
329    }
330   
331  0 return Collections.unmodifiableList(disabledObjectProperties);
332    }
333   
334    /**
335    * Retrieves deprecated properties of the given object compared to the class. A deprecated property is a property
336    * which exists in the Object but doesn't exist anymore in the Class, or which has the wrong data type. This is used
337    * for synchronization of existing or imported Objects with respect to the modifications of their associated Class.
338    *
339    * @param object the instance of this class where to look for undefined properties
340    * @return an unmodifiable list containing the properties of the object which don't exist in the class
341    * @since 2.4M2
342    */
 
343  399 toggle public List<BaseProperty> getDeprecatedObjectProperties(BaseObject object)
344    {
345  399 @SuppressWarnings("unchecked")
346    Collection<BaseProperty> objectProperties = object.getFieldList();
347  399 if (objectProperties == null) {
348  0 return Collections.emptyList();
349    }
350   
351  399 List<BaseProperty> deprecatedObjectProperties = new ArrayList<BaseProperty>();
352   
353  399 for (BaseProperty property : objectProperties) {
354  4659 if (safeget(property.getName()) == null) {
355  15 deprecatedObjectProperties.add(property);
356    } else {
357  4644 String propertyClass = ((PropertyClass) safeget(property.getName())).newProperty().getClassType();
358  4644 String objectPropertyClass = property.getClassType();
359   
360  4644 if (!propertyClass.equals(objectPropertyClass)) {
361  0 deprecatedObjectProperties.add(property);
362    }
363    }
364    }
365   
366  399 return Collections.unmodifiableList(deprecatedObjectProperties);
367    }
368   
 
369  0 toggle public BaseProperty fromString(String value)
370    {
371  0 return null; // To change body of implemented methods use Options | File Templates.
372    }
373   
374    /**
375    * @deprecated since 2.2.3 use {@link com.xpn.xwiki.doc.XWikiDocument#newXObject}
376    */
 
377  147 toggle @Deprecated
378    public BaseCollection newObject(XWikiContext context) throws XWikiException
379    {
380  147 BaseObject bobj = newCustomClassInstance(context);
381  147 DocumentReference classReference = getDocumentReference();
382  147 bobj.setXClassReference(classReference.removeParent(classReference.getWikiReference()));
383   
384  147 return bobj;
385    }
386   
387    /**
388    * @deprecated since 2.2.3 use {@link #fromMap(java.util.Map, com.xpn.xwiki.objects.BaseCollection)}
389    */
 
390  0 toggle @Deprecated
391    public BaseCollection fromMap(Map<String, ?> map, XWikiContext context) throws XWikiException
392    {
393  0 BaseCollection object = newObject(context);
394   
395  0 return fromMap(map, object);
396    }
397   
 
398  1627 toggle public BaseCollection fromMap(Map<String, ?> map, BaseCollection object)
399    {
400  1627 for (PropertyClass property : (Collection<PropertyClass>) getFieldList()) {
401  17478 String name = property.getName();
402  17478 Object formvalues = map.get(name);
403  17478 if (formvalues != null) {
404  2994 BaseProperty objprop;
405  2994 if (formvalues instanceof String[]) {
406  2994 objprop = property.fromStringArray(((String[]) formvalues));
407  0 } else if (formvalues instanceof String) {
408  0 objprop = property.fromString(formvalues.toString());
409    } else {
410  0 objprop = property.fromValue(formvalues);
411    }
412   
413  2994 if (objprop != null) {
414  2994 objprop.setObject(object);
415  2994 object.safeput(name, objprop);
416    }
417    }
418    }
419   
420  1627 return object;
421    }
422   
 
423  426 toggle public BaseCollection fromValueMap(Map<String, ?> map, BaseCollection object)
424    {
425  426 for (PropertyClass property : (Collection<PropertyClass>) getFieldList()) {
426  33025 String name = property.getName();
427  33025 Object formvalue = map.get(name);
428  33025 if (formvalue != null) {
429  9089 BaseProperty objprop;
430  9089 objprop = property.fromValue(formvalue);
431  9089 if (objprop != null) {
432  9089 objprop.setObject(object);
433  9089 object.safeput(name, objprop);
434    }
435    }
436    }
437   
438  426 return object;
439    }
440   
 
441  188858 toggle @Override
442    public BaseClass clone()
443    {
444  188860 BaseClass bclass = (BaseClass) super.clone();
445   
446  188859 bclass.setCustomClass(getCustomClass());
447  188850 bclass.setCustomMapping(getCustomMapping());
448  188860 bclass.setDefaultWeb(getDefaultWeb());
449  188858 bclass.setDefaultViewSheet(getDefaultViewSheet());
450  188851 bclass.setDefaultEditSheet(getDefaultEditSheet());
451  188851 bclass.setValidationScript(getValidationScript());
452  188844 bclass.setNameField(getNameField());
453   
454  188848 bclass.setDirty(this.isDirty);
455  188858 bclass.setOwnerDocument(this.ownerDocument);
456   
457  188862 return bclass;
458    }
459   
 
460  2500 toggle @Override
461    public boolean equals(Object obj)
462    {
463    // Same Java object, they sure are equal
464  2500 if (this == obj) {
465  0 return true;
466    }
467   
468  2500 if (!super.equals(obj)) {
469  43 return false;
470    }
471   
472  2457 BaseClass bclass = (BaseClass) obj;
473   
474  2457 if (!getCustomClass().equals(bclass.getCustomClass())) {
475  0 return false;
476    }
477   
478  2457 if (!Objects.equal(this.customMapping, bclass.customMapping)
479    && !getCustomMapping().equals(bclass.getCustomMapping())) {
480  0 return false;
481    }
482   
483  2457 if (!getDefaultViewSheet().equals(bclass.getDefaultViewSheet())) {
484  0 return false;
485    }
486   
487  2457 if (!getDefaultEditSheet().equals(bclass.getDefaultEditSheet())) {
488  0 return false;
489    }
490   
491  2457 if (!getDefaultWeb().equals(bclass.getDefaultWeb())) {
492  0 return false;
493    }
494   
495  2457 if (!getValidationScript().equals(bclass.getValidationScript())) {
496  0 return false;
497    }
498   
499  2457 if (!getNameField().equals(bclass.getNameField())) {
500  0 return false;
501    }
502   
503  2457 return true;
504    }
505   
 
506  0 toggle public void merge(BaseClass bclass)
507    {
508    }
509   
 
510  2 toggle @Override
511    public void fromXML(Element element) throws XWikiException
512    {
513  2 super.fromXML(element);
514    }
515   
 
516  24770 toggle @Override
517    public void fromXML(String xml) throws XWikiException
518    {
519  24773 super.fromXML(xml);
520    }
521   
 
522  12620 toggle public boolean addTextField(String fieldName, String fieldPrettyName, int size)
523    {
524  12620 if (get(fieldName) == null) {
525  12254 StringClass text_class = new StringClass();
526  12254 text_class.setName(fieldName);
527  12254 text_class.setPrettyName(fieldPrettyName);
528  12254 text_class.setSize(size);
529  12254 text_class.setObject(this);
530  12254 put(fieldName, text_class);
531   
532  12254 return true;
533    }
534   
535  366 return false;
536    }
537   
 
538  529 toggle public boolean addPasswordField(String fieldName, String fieldPrettyName, int size)
539    {
540  529 return addPasswordField(fieldName, fieldPrettyName, size, null);
541    }
542   
 
543  647 toggle public boolean addPasswordField(String fieldName, String fieldPrettyName, int size, String storageType)
544    {
545  647 if (get(fieldName) == null) {
546  647 PasswordClass passwordClass = new PasswordClass();
547  647 passwordClass.setName(fieldName);
548  647 passwordClass.setPrettyName(fieldPrettyName);
549  647 passwordClass.setSize(size);
550  647 if (storageType != null) {
551  118 passwordClass.setStorageType(storageType);
552    }
553  647 passwordClass.setObject(this);
554  647 put(fieldName, passwordClass);
555   
556  647 return true;
557    }
558   
559  0 return false;
560    }
561   
 
562  209 toggle public boolean addEmailField(String fieldName, String fieldPrettyName, int size)
563    {
564  209 if (get(fieldName) == null) {
565  209 EmailClass emailClass = new EmailClass();
566  209 emailClass.setName(fieldName);
567  209 emailClass.setPrettyName(fieldPrettyName);
568  209 emailClass.setSize(size);
569  209 emailClass.setObject(this);
570  209 put(fieldName, emailClass);
571   
572  209 return true;
573    }
574   
575  0 return false;
576    }
577   
 
578  325 toggle public boolean addTimezoneField(String fieldName, String fieldPrettyName, int size)
579    {
580  325 if (get(fieldName) == null) {
581  325 TimezoneClass timezoneClass = new TimezoneClass();
582  325 timezoneClass.setName(fieldName);
583  325 timezoneClass.setPrettyName(fieldPrettyName);
584  325 timezoneClass.setSize(size);
585  325 timezoneClass.setObject(this);
586  325 put(fieldName, timezoneClass);
587   
588  325 return true;
589    }
590   
591  0 return false;
592    }
593   
594    /**
595    * @since 10.10RC1
596    */
 
597  0 toggle public boolean addBooleanField(String fieldName, String fieldPrettyName)
598    {
599  0 return addBooleanField(fieldName, fieldPrettyName, null);
600    }
601   
 
602  5405 toggle public boolean addBooleanField(String fieldName, String fieldPrettyName, String displayType)
603    {
604  5405 return addBooleanField(fieldName, fieldPrettyName, displayType, null);
605    }
606   
 
607  7349 toggle public boolean addBooleanField(String fieldName, String fieldPrettyName, String displayType, Boolean def)
608    {
609  7349 return addBooleanField(fieldName, fieldPrettyName, null, displayType, def);
610    }
611   
612    /**
613    * @since 10.7RC1
614    */
 
615  7514 toggle public boolean addBooleanField(String fieldName, String fieldPrettyName, String formType, String displayType,
616    Boolean def)
617    {
618  7514 if (get(fieldName) == null) {
619  7514 BooleanClass booleanClass = new BooleanClass();
620  7514 booleanClass.setName(fieldName);
621  7514 booleanClass.setPrettyName(fieldPrettyName);
622  7514 if (formType != null) {
623  165 booleanClass.setDisplayFormType(formType);
624    }
625  7514 booleanClass.setDisplayType(displayType);
626  7514 booleanClass.setObject(this);
627  7514 if (def != null) {
628  1996 booleanClass.setDefaultValue(def ? 1 : 0);
629    }
630   
631  7514 put(fieldName, booleanClass);
632   
633  7514 return true;
634    }
635   
636  0 return false;
637    }
638   
 
639  320 toggle public boolean addUsersField(String fieldName, String fieldPrettyName)
640    {
641  320 return addUsersField(fieldName, fieldPrettyName, true);
642    }
643   
644    /**
645    * @since 1.1.2
646    * @since 1.2M2
647    */
 
648  433 toggle public boolean addUsersField(String fieldName, String fieldPrettyName, boolean multiSelect)
649    {
650  433 return addUsersField(fieldName, fieldPrettyName, 5, multiSelect);
651    }
652   
 
653  0 toggle public boolean addUsersField(String fieldName, String fieldPrettyName, int size)
654    {
655  0 return addUsersField(fieldName, fieldPrettyName, size, true);
656    }
657   
658    /**
659    * @since 1.1.2
660    * @since 1.2M2
661    */
 
662  635 toggle public boolean addUsersField(String fieldName, String fieldPrettyName, int size, boolean multiSelect)
663    {
664  635 if (get(fieldName) == null) {
665  626 UsersClass users_class = new UsersClass();
666  626 users_class.setName(fieldName);
667  626 users_class.setPrettyName(fieldPrettyName);
668  626 users_class.setSize(size);
669  626 users_class.setMultiSelect(multiSelect);
670  626 users_class.setObject(this);
671  626 put(fieldName, users_class);
672   
673  626 return true;
674    }
675   
676  9 return false;
677    }
678   
 
679  320 toggle public boolean addLevelsField(String fieldName, String fieldPrettyName)
680    {
681  320 return addLevelsField(fieldName, fieldPrettyName, 3);
682    }
683   
 
684  320 toggle public boolean addLevelsField(String fieldName, String fieldPrettyName, int size)
685    {
686  320 if (get(fieldName) == null) {
687  320 LevelsClass levels_class = new LevelsClass();
688  320 levels_class.setName(fieldName);
689  320 levels_class.setPrettyName(fieldPrettyName);
690  320 levels_class.setSize(size);
691  320 levels_class.setMultiSelect(true);
692  320 levels_class.setObject(this);
693  320 put(fieldName, levels_class);
694   
695  320 return true;
696    }
697   
698  0 return false;
699    }
700   
 
701  320 toggle public boolean addGroupsField(String fieldName, String fieldPrettyName)
702    {
703  320 return addGroupsField(fieldName, fieldPrettyName, 5);
704    }
705   
 
706  320 toggle public boolean addGroupsField(String fieldName, String fieldPrettyName, int size)
707    {
708  320 if (get(fieldName) == null) {
709  320 GroupsClass groups_class = new GroupsClass();
710  320 groups_class.setName(fieldName);
711  320 groups_class.setPrettyName(fieldPrettyName);
712  320 groups_class.setSize(size);
713  320 groups_class.setMultiSelect(true);
714  320 groups_class.setObject(this);
715  320 put(fieldName, groups_class);
716   
717  320 return true;
718    }
719   
720  0 return false;
721    }
722   
 
723  805 toggle public boolean addTemplateField(String fieldName, String fieldPrettyName)
724    {
725  805 return addTextAreaField(fieldName, fieldPrettyName, 80, 15, EditorType.PURE_TEXT);
726    }
727   
 
728  1618 toggle public boolean addTextAreaField(String fieldName, String fieldPrettyName, int cols, int rows)
729    {
730  1618 return addTextAreaField(fieldName, fieldPrettyName, cols, rows, (String) null);
731    }
732   
 
733  1988 toggle public boolean addTextAreaField(String fieldName, String fieldPrettyName, int cols, int rows, EditorType editorType)
734    {
735  1988 return addTextAreaField(fieldName, fieldPrettyName, cols, rows, editorType,
736    TextAreaClass.getContentType(editorType, null));
737    }
738   
 
739  1618 toggle public boolean addTextAreaField(String fieldName, String fieldPrettyName, int cols, int rows, String editor)
740    {
741  1618 return addTextAreaField(fieldName, fieldPrettyName, cols, rows, editor, null);
742    }
743   
744    /**
745    * @since 8.3
746    */
 
747  2619 toggle public boolean addTextAreaField(String fieldName, String fieldPrettyName, int cols, int rows,
748    ContentType contentType)
749    {
750  2619 return addTextAreaField(fieldName, fieldPrettyName, cols, rows, TextAreaClass.getEditorType(contentType, null),
751    contentType);
752    }
753   
754    /**
755    * @since 8.3
756    */
 
757  4712 toggle public boolean addTextAreaField(String fieldName, String fieldPrettyName, int cols, int rows, EditorType editorType,
758    ContentType contentType)
759    {
760  4712 return addTextAreaField(fieldName, fieldPrettyName, cols, rows,
761  4712 editorType != null ? editorType.toString() : null, contentType != null ? contentType.toString() : null);
762    }
763   
764    /**
765    * @since 8.3
766    */
 
767  6330 toggle public boolean addTextAreaField(String fieldName, String fieldPrettyName, int cols, int rows, String editor,
768    String contenttype)
769    {
770  6330 boolean result = false;
771   
772  6330 TextAreaClass textAreaClass;
773  6330 PropertyInterface field = get(fieldName);
774  6330 if (field instanceof TextAreaClass) {
775  70 textAreaClass = (TextAreaClass) field;
776    } else {
777    // Remove the field if it already exist
778  6260 if (field != null) {
779  1 removeField(fieldName);
780    }
781   
782    // Create a new field
783  6260 textAreaClass = new TextAreaClass();
784  6260 textAreaClass.setName(fieldName);
785  6260 textAreaClass.setObject(this);
786  6260 put(fieldName, textAreaClass);
787   
788  6260 result = true;
789    }
790   
791    // If one of the other parameter values have changed, return true so that we update it.
792   
793  6330 if (!textAreaClass.getPrettyName().equals(fieldPrettyName)) {
794  6260 textAreaClass.setPrettyName(fieldPrettyName);
795  6260 result = true;
796    }
797   
798    // Note: TextAreaClass.getEditor() transforms the editor string into lowercase so we need to do the same when
799    // comparing here. In addition when the editor is not, an empty string is returned from getEditor()...
800  6330 if ((editor == null && !textAreaClass.getEditor().isEmpty())
801    || (editor != null && !textAreaClass.getEditor().equals(editor.toLowerCase()))) {
802  4670 textAreaClass.setEditor(editor);
803  4670 result = true;
804    }
805   
806    // Note: TextAreaClass.getContentType() will return a lowercase ContentType.WIKI_TEXT if the stored content
807    // editor is not set (i.e. using a default content type). Thus we need to take that into account when comparing.
808    // If the passed content type is null and the set content type is ContentType.WIKI_TEXT we don't consider that
809    // the content type is different (and vice versa).
810  6330 if ((contenttype == null && !textAreaClass.getContentType().equalsIgnoreCase(ContentType.WIKI_TEXT.toString()))
811    || (contenttype != null && !textAreaClass.getContentType().equalsIgnoreCase(contenttype))) {
812  2646 textAreaClass.setContentType(contenttype);
813  2646 result = true;
814    }
815   
816  6330 if (textAreaClass.getSize() != cols) {
817  2493 textAreaClass.setSize(cols);
818  2493 result = true;
819    }
820   
821  6330 if (textAreaClass.getRows() != rows) {
822  3770 textAreaClass.setRows(rows);
823  3770 result = true;
824    }
825   
826  6330 return result;
827    }
828   
 
829  2714 toggle public boolean addStaticListField(String fieldName, String fieldPrettyName, String values)
830    {
831  2714 return addStaticListField(fieldName, fieldPrettyName, 1, false, values);
832    }
833   
834    /**
835    * @since 10.9
836    * @since 10.8.1
837    */
 
838  437 toggle public boolean addStaticListField(String fieldName, String fieldPrettyName, String values, String defaultValue)
839    {
840  437 return addStaticListField(fieldName, fieldPrettyName, 1, false, false, values, null, null, defaultValue);
841    }
842   
 
843  3586 toggle public boolean addStaticListField(String fieldName, String fieldPrettyName, int size, boolean multiSelect,
844    String values)
845    {
846  3586 return addStaticListField(fieldName, fieldPrettyName, size, multiSelect, values, null);
847    }
848   
 
849  4040 toggle public boolean addStaticListField(String fieldName, String fieldPrettyName, int size, boolean multiSelect,
850    String values, String displayType)
851    {
852  4040 return addStaticListField(fieldName, fieldPrettyName, size, multiSelect, values, displayType, null);
853    }
854   
855    /**
856    * @since 1.1.2
857    * @since 1.2M2
858    */
 
859  5246 toggle public boolean addStaticListField(String fieldName, String fieldPrettyName, int size, boolean multiSelect,
860    String values, String displayType, String separators)
861    {
862  5246 return addStaticListField(fieldName, fieldPrettyName, size, multiSelect, false, values, displayType,
863    separators);
864    }
865   
866    /**
867    * @since 1.8M1
868    */
 
869  5491 toggle public boolean addStaticListField(String fieldName, String fieldPrettyName, int size, boolean multiSelect,
870    boolean relationalStorage, String values, String displayType, String separators)
871    {
872  5491 return addStaticListField(fieldName, fieldPrettyName, size, multiSelect, relationalStorage, values, displayType,
873    separators, null);
874    }
875   
876    /**
877    * @since 10.9
878    * @since 10.8.1
879    */
 
880  5928 toggle public boolean addStaticListField(String fieldName, String fieldPrettyName, int size, boolean multiSelect,
881    boolean relationalStorage, String values, String displayType, String separators, String defaultValue)
882    {
883  5928 if (get(fieldName) == null) {
884  5877 StaticListClass list_class = new StaticListClass();
885  5877 list_class.setName(fieldName);
886  5877 list_class.setPrettyName(fieldPrettyName);
887  5877 list_class.setSize(size);
888  5877 list_class.setMultiSelect(multiSelect);
889  5877 list_class.setRelationalStorage(relationalStorage);
890  5877 list_class.setValues(values);
891  5877 if (displayType != null) {
892  1844 list_class.setDisplayType(displayType);
893    }
894  5877 if (separators != null) {
895  1432 list_class.setSeparators(separators);
896  1432 list_class.setSeparator(separators.substring(0, 1));
897    }
898  5877 if (defaultValue != null) {
899  437 list_class.setDefaultValue(defaultValue);
900    }
901  5877 list_class.setObject(this);
902  5877 put(fieldName, list_class);
903   
904  5877 return true;
905    }
906   
907  51 return false;
908    }
909   
 
910  552 toggle public boolean addNumberField(String fieldName, String fieldPrettyName, int size, String type)
911    {
912  552 if (get(fieldName) == null) {
913  525 NumberClass number_class = new NumberClass();
914  525 number_class.setName(fieldName);
915  525 number_class.setPrettyName(fieldPrettyName);
916  525 number_class.setSize(size);
917  525 number_class.setNumberType(type);
918  525 number_class.setObject(this);
919  525 put(fieldName, number_class);
920   
921  525 return true;
922    }
923   
924  27 return false;
925    }
926   
 
927  185 toggle public boolean addDateField(String fieldName, String fieldPrettyName)
928    {
929  185 return addDateField(fieldName, fieldPrettyName, null, 1);
930    }
931   
 
932  0 toggle public boolean addDateField(String fieldName, String fieldPrettyName, String dformat)
933    {
934  0 return addDateField(fieldName, fieldPrettyName, dformat, 1);
935    }
936   
 
937  0 toggle public boolean addDateField(String fieldName, String fieldPrettyName, String dformat, int emptyIsToday)
938    {
939  0 if (get(fieldName) == null) {
940  0 DateClass date_class = new DateClass();
941  0 date_class.setName(fieldName);
942  0 date_class.setPrettyName(fieldPrettyName);
943  0 if (dformat != null) {
944  0 date_class.setDateFormat(dformat);
945    }
946  0 date_class.setObject(this);
947  0 date_class.setEmptyIsToday(emptyIsToday);
948  0 put(fieldName, date_class);
949   
950  0 return true;
951    }
952   
953  18 return false;
954    }
955   
 
956  236 toggle public boolean addDBListField(String fieldName, String fieldPrettyName, String sql)
957    {
958  236 return addDBListField(fieldName, fieldPrettyName, 1, false, sql);
959    }
960   
 
961  252 toggle public boolean addDBListField(String fieldName, String fieldPrettyName, int size, boolean multiSelect, String sql)
962    {
963  252 return addDBListField(fieldName, fieldPrettyName, size, multiSelect, multiSelect, sql);
964    }
965   
966    /**
967    * @since 1.8M1
968    */
 
969  252 toggle public boolean addDBListField(String fieldName, String fieldPrettyName, int size, boolean multiSelect,
970    boolean relationalStorage, String sql)
971    {
972  252 if (get(fieldName) == null) {
973  252 DBListClass list_class = new DBListClass();
974  252 list_class.setName(fieldName);
975  252 list_class.setPrettyName(fieldPrettyName);
976  252 list_class.setSize(size);
977  252 list_class.setMultiSelect(multiSelect);
978  252 list_class.setRelationalStorage(relationalStorage);
979  252 list_class.setSql(sql);
980  252 list_class.setObject(this);
981  252 put(fieldName, list_class);
982   
983  252 return true;
984    }
985   
986  0 return false;
987    }
988   
 
989  0 toggle public boolean addDBTreeListField(String fieldName, String fieldPrettyName, String sql)
990    {
991  0 return addDBTreeListField(fieldName, fieldPrettyName, 1, false, sql);
992    }
993   
 
994  0 toggle public boolean addDBTreeListField(String fieldName, String fieldPrettyName, int size, boolean multiSelect,
995    String sql)
996    {
997  0 return addDBTreeListField(fieldName, fieldPrettyName, size, multiSelect, multiSelect, sql);
998    }
999   
1000    /**
1001    * @since 1.8M1
1002    */
 
1003  0 toggle public boolean addDBTreeListField(String fieldName, String fieldPrettyName, int size, boolean multiSelect,
1004    boolean relationalStorage, String sql)
1005    {
1006  0 if (get(fieldName) == null) {
1007  0 DBTreeListClass list_class = new DBTreeListClass();
1008  0 list_class.setName(fieldName);
1009  0 list_class.setPrettyName(fieldPrettyName);
1010  0 list_class.setSize(size);
1011  0 list_class.setMultiSelect(multiSelect);
1012  0 list_class.setRelationalStorage(relationalStorage);
1013  0 list_class.setSql(sql);
1014  0 list_class.setObject(this);
1015  0 put(fieldName, list_class);
1016   
1017  0 return true;
1018    }
1019   
1020  0 return false;
1021    }
1022   
1023    /**
1024    * Adds a page field to the class.
1025    * <p>
1026    * The input has no multiselect by default.
1027    *
1028    * @param fieldName the field name
1029    * @param fieldPrettyName the shown name
1030    * @param size size of the input
1031    * @return true if the field has been added
1032    * @since 10.8RC1
1033    */
 
1034  453 toggle public boolean addPageField(String fieldName, String fieldPrettyName, int size)
1035    {
1036  453 return addPageField(fieldName, fieldPrettyName, size, false);
1037    }
1038   
1039    /**
1040    * Adds a page field to the class.
1041    *
1042    * @param fieldName the field name
1043    * @param fieldPrettyName the shown name
1044    * @param size size of the input
1045    * @param multiSelect specifies if there can be several values
1046    * @return true if the field has been added
1047    * @since 10.8RC1
1048    */
 
1049  453 toggle public boolean addPageField(String fieldName, String fieldPrettyName, int size, boolean multiSelect)
1050    {
1051  453 return addPageField(fieldName, fieldPrettyName, size, multiSelect, multiSelect, "");
1052    }
1053   
1054    /**
1055    * Adds a page field to the class.
1056    *
1057    * @param fieldName the field name
1058    * @param fieldPrettyName the shown name
1059    * @param size size of the input
1060    * @param multiSelect specifies if there can be several values
1061    * @param relationalStorage sets the {@link PageClass} {@code relationalStorage} property metadata with the
1062    * specified value. See {@link PageClass#setRelationalStorage} for more details
1063    * @param hqlQuery the optional HQL query to execute to return allowed document references. If null or empty, the
1064    * {@link com.xpn.xwiki.internal.objects.classes.ImplicitlyAllowedValuesPageQueryBuilder#build(PageClass)
1065    * implicit page query builder} is used
1066    * @return true if the field has been added
1067    * @since 10.8RC1
1068    */
 
1069  453 toggle public boolean addPageField(String fieldName, String fieldPrettyName, int size, boolean multiSelect,
1070    boolean relationalStorage, String hqlQuery)
1071    {
1072  453 return addPageField(fieldName, fieldPrettyName, size, multiSelect, relationalStorage, hqlQuery, "",
1073    ListClass.DISPLAYTYPE_INPUT, true, ListClass.FREE_TEXT_DISCOURAGED);
1074    }
1075   
1076    /**
1077    * Adds a page field to the class.
1078    *
1079    * @param fieldName the field name
1080    * @param fieldPrettyName the shown name
1081    * @param size size of the input
1082    * @param multiSelect specifies if there can be several values
1083    * @param relationalStorage sets the {@link PageClass} {@code relationalStorage} property metadata with the
1084    * specified value. See {@link PageClass#setRelationalStorage} for more details
1085    * @param hqlQuery the optional HQL query to execute to return allowed document references. If null or empty, the
1086    * {@link com.xpn.xwiki.internal.objects.classes.ImplicitlyAllowedValuesPageQueryBuilder#build(PageClass)
1087    * implicit page query builder} is used
1088    * @param className optional class name used to filter suggested documents containing an object of this class
1089    * @param displayType either {@link ListClass#DISPLAYTYPE_CHECKBOX}, {@link ListClass#DISPLAYTYPE_INPUT},
1090    * {@link ListClass#DISPLAYTYPE_RADIO} or {@link ListClass#DISPLAYTYPE_SELECT}
1091    * @param hasPicker enables auto suggestion display
1092    * @param freeText indicate how non document reference values are handled (forbidden, discouraged or allowed)
1093    * @return true if the field has been added
1094    * @since 10.8RC1
1095    */
 
1096  571 toggle public boolean addPageField(String fieldName, String fieldPrettyName, int size, boolean multiSelect,
1097    boolean relationalStorage, String hqlQuery, String className, String displayType, boolean hasPicker,
1098    String freeText)
1099    {
1100  571 if (getField(fieldName) == null) {
1101  571 PageClass pageClass = new PageClass();
1102  571 pageClass.setName(fieldName);
1103  571 pageClass.setPrettyName(fieldPrettyName);
1104  571 pageClass.setSize(size);
1105  571 pageClass.setMultiSelect(multiSelect);
1106  571 pageClass.setSql(hqlQuery);
1107  571 pageClass.setRelationalStorage(relationalStorage);
1108  571 pageClass.setDisplayType(displayType);
1109  571 pageClass.setPicker(hasPicker);
1110  571 pageClass.setObject(this);
1111  571 pageClass.setClassname(className);
1112  571 pageClass.setFreeText(freeText);
1113  571 put(fieldName, pageClass);
1114   
1115  571 return true;
1116    }
1117   
1118  0 return false;
1119    }
1120   
 
1121  202150 toggle public void setCustomMapping(String customMapping)
1122    {
1123  202153 this.customMapping = customMapping;
1124    }
1125   
 
1126  280935 toggle public String getCustomMapping()
1127    {
1128  280946 if ("XWiki.XWikiPreferences".equals(getName())) {
1129  6284 return "internal";
1130    }
1131   
1132  274659 if (this.customMapping == null) {
1133  155477 return "";
1134    }
1135   
1136  119181 return this.customMapping;
1137    }
1138   
 
1139  41079 toggle public boolean hasCustomMapping()
1140    {
1141  41083 String cMapping = getCustomMapping();
1142   
1143  41083 return (cMapping != null) && (!"".equals(cMapping));
1144    }
1145   
 
1146  2990 toggle public boolean hasExternalCustomMapping()
1147    {
1148  2990 String cMapping = getCustomMapping();
1149   
1150  2990 return (cMapping != null) && (!"".equals(cMapping)) && (!"internal".equals(cMapping));
1151    }
1152   
 
1153  0 toggle public boolean hasInternalCustomMapping()
1154    {
1155  0 return "internal".equals(this.customMapping);
1156    }
1157   
 
1158  0 toggle public boolean isCustomMappingValid(XWikiContext context) throws XWikiException
1159    {
1160  0 return isCustomMappingValid(getCustomMapping(), context);
1161    }
1162   
 
1163  0 toggle public boolean isCustomMappingValid(String custommapping, XWikiContext context) throws XWikiException
1164    {
1165  0 if ((custommapping != null) && (custommapping.trim().length() > 0)) {
1166  0 return context.getWiki().getStore().isCustomMappingValid(this, custommapping, context);
1167    } else {
1168  0 return true;
1169    }
1170    }
1171   
 
1172  10913 toggle public List<String> getCustomMappingPropertyList(XWikiContext context)
1173    {
1174  10913 String custommapping1 = getCustomMapping();
1175  10912 if ((custommapping1 != null) && (custommapping1.trim().length() > 0)) {
1176  567