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

File DefaultWysiwygEditorConfiguration.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

14
31
17
1
209
129
24
0.77
1.82
17
1.41

Classes

Class Line # Actions
DefaultWysiwygEditorConfiguration 46 31 0% 24 1
0.98387198.4%
 

Contributing tests

This file is covered by 1 test. .

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.wysiwyg.server.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Singleton;
24   
25    import org.apache.commons.lang3.StringUtils;
26    import org.xwiki.bridge.DocumentAccessBridge;
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.context.Execution;
29    import org.xwiki.model.EntityType;
30    import org.xwiki.model.ModelContext;
31    import org.xwiki.model.reference.DocumentReference;
32    import org.xwiki.model.reference.LocalDocumentReference;
33    import org.xwiki.model.reference.WikiReference;
34    import org.xwiki.wysiwyg.server.WysiwygEditorConfiguration;
35   
36    import com.xpn.xwiki.XWiki;
37    import com.xpn.xwiki.XWikiContext;
38   
39    /**
40    * Default WYSIWYG editor configuration source.
41    *
42    * @version $Id: 3ba370b68b9f46c04ec781d5de2e4b923423efd8 $
43    */
44    @Component
45    @Singleton
 
46    public class DefaultWysiwygEditorConfiguration implements WysiwygEditorConfiguration
47    {
48    /**
49    * The integer number used to determine if a boolean configuration property is set.
50    */
51    private static final Integer ONE = new Integer(1);
52   
53    /**
54    * A reference to the configuration XClass.
55    */
56    private static final LocalDocumentReference CONFIG_CLASS_REFERENCE = new LocalDocumentReference(XWiki.SYSTEM_SPACE,
57    "WysiwygEditorConfigClass");
58   
59    /**
60    * A local reference to the configuration document.
61    */
62    private static final LocalDocumentReference CONFIG_LOCAL_DOCUMENT_REFERENCE = new LocalDocumentReference(
63    XWiki.SYSTEM_SPACE, "WysiwygEditorConfig");
64   
65    /**
66    * The component used to access documents. This is temporary till XWiki model is moved into components.
67    */
68    @Inject
69    private DocumentAccessBridge documentAccessBridge;
70   
71    /**
72    * The component used to get a reference to the current wiki.
73    */
74    @Inject
75    private ModelContext modelContext;
76   
77    /** Execution context handler, needed for accessing the XWikiContext. */
78    @Inject
79    private Execution execution;
80   
81    /**
82    * @param propertyName the property name
83    * @return the value of the specified property of the {@link #CONFIG_CLASS_REFERENCE} object attached to
84    * {@link #CONFIG_LOCAL_DOCUMENT_REFERENCE}
85    */
 
86  327 toggle private Object getProperty(String propertyName)
87    {
88  327 String currentWiki = modelContext.getCurrentEntityReference().extractReference(EntityType.WIKI).getName();
89  327 Object value = getProperty(propertyName, currentWiki);
90  327 if (value == null) {
91  49 String mainWiki = getMainWiki();
92  49 if (!StringUtils.equals(currentWiki, mainWiki)) {
93  1 value = getProperty(propertyName, mainWiki);
94    }
95    }
96  327 return value;
97    }
98   
99    /**
100    * @param propertyName the property name
101    * @param wiki the name of the wiki where to look for the configuration document
102    * @return the value of the specified property of the {@link #CONFIG_CLASS_REFERENCE} object attached to
103    * {@link #CONFIG_LOCAL_DOCUMENT_REFERENCE} in the specified wiki
104    */
 
105  328 toggle private Object getProperty(String propertyName, String wiki)
106    {
107  328 WikiReference wikiRef = new WikiReference(wiki);
108  328 DocumentReference configDocumentReference = new DocumentReference(CONFIG_LOCAL_DOCUMENT_REFERENCE, wikiRef);
109  328 DocumentReference configClassReference = new DocumentReference(CONFIG_CLASS_REFERENCE, wikiRef);
110  328 return documentAccessBridge.getProperty(configDocumentReference, configClassReference, propertyName);
111    }
112   
113    /**
114    * @return the name of the main wiki
115    */
 
116  49 toggle private String getMainWiki()
117    {
118  49 return ((XWikiContext) execution.getContext().getProperty("xwikicontext")).getMainXWiki();
119    }
120   
 
121  24 toggle @Override
122    public Boolean areExternalImagesAllowed()
123    {
124  24 Integer externalImages = (Integer) getProperty("externalImages");
125  24 return externalImages == null ? null : ONE.equals(externalImages);
126    }
127   
 
128  24 toggle @Override
129    public String getColorPalette()
130    {
131  24 return (String) getProperty("colorPalette");
132    }
133   
 
134  24 toggle @Override
135    public Integer getColorsPerRow()
136    {
137  24 return (Integer) getProperty("colorsPerRow");
138    }
139   
 
140  24 toggle @Override
141    public String getFontNames()
142    {
143  24 return (String) getProperty("fontNames");
144    }
145   
 
146  24 toggle @Override
147    public String getFontSizes()
148    {
149  24 return (String) getProperty("fontSizes");
150    }
151   
 
152  24 toggle @Override
153    public String getMenuBar()
154    {
155  24 return (String) getProperty("menuBar");
156    }
157   
 
158  25 toggle @Override
159    public String getPlugins()
160    {
161  25 return (String) getProperty("plugins");
162    }
163   
 
164  24 toggle @Override
165    public String getStyleNames()
166    {
167  24 return (String) getProperty("styleNames");
168    }
169   
 
170  24 toggle @Override
171    public String getToolBar()
172    {
173  24 return (String) getProperty("toolBar");
174    }
175   
 
176  24 toggle @Override
177    public Boolean isAttachmentSelectionLimited()
178    {
179  24 Integer attachmentSelectionLimited = (Integer) getProperty("attachmentSelectionLimited");
180  24 return attachmentSelectionLimited == null ? null : ONE.equals(attachmentSelectionLimited);
181    }
182   
 
183  24 toggle @Override
184    public Boolean isImageSelectionLimited()
185    {
186  24 Integer imageSelectionLimited = (Integer) getProperty("imageSelectionLimited");
187  24 return imageSelectionLimited == null ? null : ONE.equals(imageSelectionLimited);
188    }
189   
 
190  14 toggle @Override
191    public Boolean isSourceEditorEnabled()
192    {
193  14 Integer sourceEditorEnabled = (Integer) getProperty("sourceEditorEnabled");
194  14 return sourceEditorEnabled == null ? null : ONE.equals(sourceEditorEnabled);
195    }
196   
 
197  24 toggle @Override
198    public Integer getHistorySize()
199    {
200  24 return (Integer) getProperty("historySize");
201    }
202   
 
203  24 toggle @Override
204    public Boolean isPasteContentCleanedAutomatically()
205    {
206  24 Integer cleanPaste = (Integer) getProperty("cleanPaste");
207  24 return cleanPaste == null ? null : ONE.equals(cleanPaste);
208    }
209    }