1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.edit.internal

File AbstractEditorBindingsSource.java

 

Coverage histogram

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

Code metrics

8
17
3
1
87
50
8
0.47
5.67
3
2.67

Classes

Class Line # Actions
AbstractEditorBindingsSource 42 17 0% 8 11
0.6071428760.7%
 

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 org.xwiki.edit.internal;
21   
22    import java.util.Collections;
23    import java.util.List;
24    import java.util.Objects;
25   
26    import org.apache.commons.lang3.StringUtils;
27    import org.xwiki.configuration.internal.AbstractDocumentConfigurationSource;
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.model.reference.LocalDocumentReference;
30   
31    import com.xpn.xwiki.XWikiContext;
32    import com.xpn.xwiki.XWikiException;
33    import com.xpn.xwiki.doc.XWikiDocument;
34    import com.xpn.xwiki.objects.BaseObject;
35   
36    /**
37    * Base class for configuration sources that read the editor bindings from {@code EditorBindingClass} objects.
38    *
39    * @version $Id: 6792d6a16f0a4193f30aeb5cc73c05d30f9db51d $
40    * @since 8.2RC1
41    */
 
42    public abstract class AbstractEditorBindingsSource extends AbstractDocumentConfigurationSource
43    {
44    /**
45    * The local reference of the class used to bind editors to data types.
46    */
47    private static final LocalDocumentReference CLASS_REFERENCE = new LocalDocumentReference("XWiki",
48    "EditorBindingClass");
49   
 
50  211 toggle @Override
51    protected LocalDocumentReference getClassReference()
52    {
53  211 return CLASS_REFERENCE;
54    }
55   
 
56  160 toggle @Override
57    protected Object getBaseProperty(String propertyName, boolean text) throws XWikiException
58    {
59  160 for (BaseObject baseObject : getBaseObjects()) {
60  0 String dataType = baseObject.getStringValue("dataType");
61  0 if (Objects.equals(dataType, propertyName)) {
62  0 String roleHint = baseObject.getStringValue("roleHint");
63  0 if (!StringUtils.isEmpty(roleHint)) {
64  0 return roleHint;
65    }
66    }
67    }
68  160 return null;
69    }
70   
 
71  160 toggle private List<BaseObject> getBaseObjects() throws XWikiException
72    {
73  160 DocumentReference documentReference = getFailsafeDocumentReference();
74  160 LocalDocumentReference classReference = getFailsafeClassReference();
75   
76  160 if (documentReference != null && classReference != null) {
77  156 XWikiContext xcontext = this.xcontextProvider.get();
78  156 XWikiDocument document = xcontext.getWiki().getDocument(getDocumentReference(), xcontext);
79  156 List<BaseObject> objects = document.getXObjects(classReference);
80  156 if (objects != null) {
81  0 return objects;
82    }
83    }
84   
85  160 return Collections.emptyList();
86    }
87    }