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

File XWikiPreferencesDocumentInitializer.java

 

Coverage histogram

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

Code metrics

14
105
2
1
240
164
9
0.09
52.5
2
4.5

Classes

Class Line # Actions
XWikiPreferencesDocumentInitializer 47 105 0% 9 12
0.9008264590.1%
 

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 com.xpn.xwiki.internal.mandatory;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.model.reference.DocumentReference;
28    import org.xwiki.sheet.SheetBinder;
29   
30    import com.xpn.xwiki.XWiki;
31    import com.xpn.xwiki.doc.XWikiDocument;
32    import com.xpn.xwiki.objects.PropertyInterface;
33    import com.xpn.xwiki.objects.classes.BaseClass;
34    import com.xpn.xwiki.objects.classes.BooleanClass;
35    import com.xpn.xwiki.objects.classes.TextAreaClass.ContentType;
36    import com.xpn.xwiki.objects.classes.TimezoneClass;
37   
38    /**
39    * Update XWiki.XWikiPreferences document with all required informations.
40    *
41    * @version $Id: ea038f50a610c33d909bd8b5682f9705013ab55b $
42    * @since 4.3M1
43    */
44    @Component
45    @Named("XWiki.XWikiPreferences")
46    @Singleton
 
47    public class XWikiPreferencesDocumentInitializer extends AbstractMandatoryDocumentInitializer
48    {
49    /**
50    * The name of the field containing the time zone.
51    */
52    private static final String TIMEZONE_FIELD = "timezone";
53   
54    /**
55    * Used to bind a class to a document sheet.
56    */
57    @Inject
58    @Named("class")
59    protected SheetBinder classSheetBinder;
60   
61    /**
62    * Default constructor.
63    */
 
64  61 toggle public XWikiPreferencesDocumentInitializer()
65    {
66  61 super(XWiki.SYSTEM_SPACE, "XWikiPreferences");
67    }
68   
 
69  94 toggle @Override
70    public boolean updateDocument(XWikiDocument document)
71    {
72  94 boolean needsUpdate = false;
73   
74  94 BaseClass bclass = document.getXClass();
75   
76  94 if (!"internal".equals(bclass.getCustomMapping())) {
77  0 needsUpdate = true;
78  0 bclass.setCustomMapping("internal");
79    }
80   
81  94 needsUpdate |= bclass.addTextField("parent", "Parent Space", 30);
82  94 needsUpdate |= bclass.addBooleanField("multilingual", "Multi-Lingual", "yesno");
83  94 needsUpdate |= bclass.addTextField("default_language", "Default Language", 5);
84  94 needsUpdate |= bclass.addBooleanField("authenticate_edit", "Authenticated Edit", "yesno");
85  94 needsUpdate |= bclass.addBooleanField("authenticate_view", "Authenticated View", "yesno");
86  94 needsUpdate |= bclass.addBooleanField("auth_active_check", "Authentication Active Check", "yesno");
87   
88  94 needsUpdate |= bclass.addTextField("skin", "Skin", 30);
89  94 needsUpdate |=
90    bclass.addDBListField("colorTheme", "Color theme",
91    "select doc.fullName, doc.title from XWikiDocument as doc, BaseObject as theme "
92    + "where doc.fullName=theme.name and (theme.className='ColorThemes.ColorThemeClass' "
93    + "or theme.className='FlamingoThemesCode.ThemeClass') "
94    + "and doc.fullName<>'ColorThemes.ColorThemeTemplate' "
95    + "and doc.fullName<>'FlamingoThemesCode.ThemeTemplate'");
96    // This one should not be in the prefs
97  94 PropertyInterface baseskinProp = bclass.get("baseskin");
98  94 if (baseskinProp != null) {
99  0 bclass.removeField("baseskin");
100  0 needsUpdate = true;
101    }
102  94 needsUpdate |=
103    bclass.addDBListField("iconTheme", "Icon theme",
104    "select doc.fullName, propName.value from XWikiDocument as doc, BaseObject as theme, "
105    + "StringProperty propName "
106    + "where doc.fullName=theme.name and theme.className='IconThemesCode.IconThemeClass' "
107    + "and doc.fullName<>'IconThemesCode.IconThemeTemplate' "
108    + "and theme.id = propName.id and propName.name = 'name'");
109  94 needsUpdate |= bclass.addTextField("stylesheet", "Default Stylesheet", 30);
110  94 needsUpdate |= bclass.addTextField("stylesheets", "Alternative Stylesheet", 60);
111  94 needsUpdate |= bclass.addBooleanField("accessibility", "Enable extra accessibility features", "yesno");
112   
113  94 needsUpdate |= bclass.addStaticListField("editor", "Default Editor", "---|Text|Wysiwyg");
114   
115  94 needsUpdate |= bclass.addTextField("webcopyright", "Copyright", 30);
116  94 needsUpdate |= bclass.addTextField("title", "Title", 30);
117  94 needsUpdate |= bclass.addTextField("version", "Version", 30);
118  94 needsUpdate |= bclass.addTextAreaField("meta", "HTTP Meta Info", 60, 8, ContentType.PURE_TEXT);
119  94 needsUpdate |= bclass.addTextField("dateformat", "Date Format", 30);
120   
121    // mail
122  94 needsUpdate |= bclass.addBooleanField("use_email_verification", "Use eMail Verification", "yesno");
123  94 needsUpdate |= bclass.addTextField("admin_email", "Admin eMail", 30);
124  94 needsUpdate |= bclass.addTextField("smtp_server", "SMTP Server", 30);
125  94 needsUpdate |= bclass.addTextField("smtp_port", "SMTP Port", 5);
126  94 needsUpdate |= bclass.addTextField("smtp_server_username", "Server username (optional)", 30);
127  94 needsUpdate |= bclass.addTextField("smtp_server_password", "Server password (optional)", 30);
128  94 needsUpdate |= bclass.addTextAreaField("javamail_extra_props", "Additional JavaMail properties", 60, 6,
129    ContentType.PURE_TEXT);
130  94 needsUpdate |= bclass.addTextAreaField("validation_email_content", "Validation eMail Content", 72, 10,
131    ContentType.PURE_TEXT);
132  94 needsUpdate |= bclass.addTextAreaField("confirmation_email_content", "Confirmation eMail Content", 72, 10,
133    ContentType.PURE_TEXT);
134  94 needsUpdate |= bclass.addTextAreaField("invitation_email_content", "Invitation eMail Content", 72, 10,
135    ContentType.PURE_TEXT);
136  94 needsUpdate |= bclass.addBooleanField("obfuscateEmailAddresses", "Obfuscate Email Addresses", "yesno");
137   
138  94 needsUpdate |= bclass.addStaticListField("registration_anonymous", "Anonymous", "---|Image|Text");
139  94 needsUpdate |= bclass.addStaticListField("registration_registered", "Registered", "---|Image|Text");
140  94 needsUpdate |= bclass.addStaticListField("edit_anonymous", "Anonymous", "---|Image|Text");
141  94 needsUpdate |= bclass.addStaticListField("edit_registered", "Registered", "---|Image|Text");
142  94 needsUpdate |= bclass.addStaticListField("comment_anonymous", "Anonymous", "---|Image|Text");
143  94 needsUpdate |= bclass.addStaticListField("comment_registered", "Registered", "---|Image|Text");
144   
145  94 needsUpdate |= bclass.addNumberField("upload_maxsize", "Maximum Upload Size", 5, "long");
146   
147    // Captcha for guest comments
148  94 needsUpdate |=
149    bclass.addBooleanField("guest_comment_requires_captcha",
150    "Enable CAPTCHA in Comments for Unregistered Users", "select");
151   
152    // Document editing
153  94 needsUpdate |= bclass.addTextField("core.defaultDocumentSyntax", "Default document syntax", 60);
154  94 needsUpdate |= bclass.addBooleanField("xwiki.title.mandatory", "Make document title field mandatory", "yesno");
155   
156    // for tags
157  94 needsUpdate |= bclass.addBooleanField("tags", "Activate the tagging", "yesno");
158   
159    // for backlinks
160  94 needsUpdate |= bclass.addBooleanField("backlinks", "Activate the backlinks", "yesno");
161   
162    // New fields for the XWiki 1.0 skin
163  94 needsUpdate |= bclass.addTextField("leftPanels", "Panels displayed on the left", 60);
164  94 needsUpdate |= bclass.addTextField("rightPanels", "Panels displayed on the right", 60);
165  94 needsUpdate |= bclass.addBooleanField("showLeftPanels", "Display the left panel column", "yesno");
166  94 needsUpdate |= bclass.addBooleanField("showRightPanels", "Display the right panel column", "yesno");
167  94 needsUpdate |= bclass.addStaticListField("leftPanelsWidth", "Width of the left panel column",
168    "---|Small|Medium|Large");
169  94 needsUpdate |= bclass.addStaticListField("rightPanelsWidth", "Width of the right panel column",
170    "---|Small|Medium|Large");
171  94 needsUpdate |= bclass.addTextField("languages", "Supported languages", 30);
172  94 needsUpdate |= bclass.addTextField("documentBundles", "Internationalization Document Bundles", 60);
173   
174    // Timezone. Handle upgrade since in the past we were using a standard text field with a custom displayer and
175    // we're now using a Timezone Class. Thus we need to remove any existing field to upgrade it.
176  94 if (!(bclass.getField(TIMEZONE_FIELD) instanceof TimezoneClass)) {
177  39 bclass.removeField(TIMEZONE_FIELD);
178  39 bclass.addTimezoneField(TIMEZONE_FIELD, "Time Zone", 30);
179  39 needsUpdate = true;
180    }
181   
182    // Only used by LDAP authentication service
183   
184  94 needsUpdate |= bclass.addBooleanField("ldap", "Ldap", "yesno");
185  94 needsUpdate |= bclass.addTextField("ldap_server", "Ldap server adress", 60);
186  94 needsUpdate |= bclass.addTextField("ldap_port", "Ldap server port", 60);
187  94 needsUpdate |= bclass.addTextField("ldap_bind_DN", "Ldap login matching", 60);
188  94 needsUpdate |= bclass.addTextField("ldap_bind_pass", "Ldap password matching", 60);
189  94 needsUpdate |= bclass.addBooleanField("ldap_validate_password", "Validate Ldap user/password", "yesno");
190  94 needsUpdate |= bclass.addTextField("ldap_user_group", "Ldap group filter", 60);
191  94 needsUpdate |= bclass.addTextField("ldap_exclude_group", "Ldap group to exclude", 60);
192  94 needsUpdate |= bclass.addTextField("ldap_base_DN", "Ldap base DN", 60);
193  94 needsUpdate |= bclass.addTextField("ldap_UID_attr", "Ldap UID attribute name", 60);
194  94 needsUpdate |= bclass.addTextField("ldap_fields_mapping", "Ldap user fiels mapping", 60);
195  94 needsUpdate |= bclass.addBooleanField("ldap_update_user", "Update user from LDAP", "yesno");
196  94 needsUpdate |= bclass.addBooleanField("ldap_update_photo", "Update user photo from LDAP", "yesno");
197  94 needsUpdate |= bclass.addTextField("ldap_photo_attachment_name", "Attachment name to save LDAP photo", 30);
198  94 needsUpdate |= bclass.addTextField("ldap_photo_attribute", "Ldap photo attribute name", 60);
199  94 needsUpdate |=
200    bclass.addTextAreaField("ldap_group_mapping", "Ldap groups mapping", 60, 5, ContentType.PURE_TEXT);
201  94 needsUpdate |= bclass.addTextField("ldap_groupcache_expiration", "LDAP groups members cache", 60);
202  94 needsUpdate |= bclass.addStaticListField("ldap_mode_group_sync", "LDAP groups sync mode", "|always|create");
203  94 needsUpdate |= bclass.addBooleanField("ldap_trylocal", "Try local login", "yesno");
204   
205  94 if (((BooleanClass) bclass.get("showLeftPanels")).getDisplayType().equals("checkbox")) {
206  0 ((BooleanClass) bclass.get("showLeftPanels")).setDisplayType("yesno");
207  0 ((BooleanClass) bclass.get("showRightPanels")).setDisplayType("yesno");
208  0 needsUpdate = true;
209    }
210   
211  94 needsUpdate |= bclass.addBooleanField("showannotations", "Show document annotations", "yesno");
212  94 needsUpdate |= bclass.addBooleanField("showcomments", "Show document comments", "yesno");
213  94 needsUpdate |= bclass.addBooleanField("showattachments", "Show document attachments", "yesno");
214  94 needsUpdate |= bclass.addBooleanField("showhistory", "Show document history", "yesno");
215  94 needsUpdate |= bclass.addBooleanField("showinformation", "Show document information", "yesno");
216  94 needsUpdate |= bclass.addBooleanField("editcomment", "Enable version summary", "yesno");
217  94 needsUpdate |= bclass.addBooleanField("editcomment_mandatory", "Make version summary mandatory", "yesno");
218  94 needsUpdate |= bclass.addBooleanField("minoredit", "Enable minor edits", "yesno");
219   
220  94 boolean withoutDocumentSheets = this.documentSheetBinder.getSheets(document).isEmpty();
221  94 if (withoutDocumentSheets) {
222    // Bind a document sheet to prevent the default class sheet from being used.
223  94 this.documentSheetBinder.bind(document, document.getDocumentReference());
224    }
225  94 needsUpdate |= setClassDocumentFields(document, "XWiki Preferences");
226  94 if (withoutDocumentSheets) {
227    // Unbind the document sheet we bound earlier.
228  94 this.documentSheetBinder.unbind(document, document.getDocumentReference());
229    }
230   
231    // Use AdminSheet to display documents having XWikiPreferences objects if no other class sheet is specified.
232  94 if (this.classSheetBinder.getSheets(document).isEmpty()) {
233  39 String wikiName = document.getDocumentReference().getWikiReference().getName();
234  39 DocumentReference sheet = new DocumentReference(wikiName, XWiki.SYSTEM_SPACE, "AdminSheet");
235  39 needsUpdate |= this.classSheetBinder.bind(document, sheet);
236    }
237   
238  94 return needsUpdate;
239    }
240    }