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

File XWikiUsersDocumentInitializer.java

 

Coverage histogram

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

Code metrics

8
40
2
1
135
75
6
0.15
20
2
3

Classes

Class Line # Actions
XWikiUsersDocumentInitializer 46 40 0% 6 3
0.9494%
 

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.rendering.syntax.Syntax;
29    import org.xwiki.sheet.SheetBinder;
30   
31    import com.xpn.xwiki.XWiki;
32    import com.xpn.xwiki.doc.XWikiDocument;
33    import com.xpn.xwiki.objects.classes.BaseClass;
34    import com.xpn.xwiki.objects.classes.EmailClass;
35    import com.xpn.xwiki.objects.classes.TimezoneClass;
36   
37    /**
38    * Update XWiki.XWikiUsers document with all required informations.
39    *
40    * @version $Id: 4b420132179c362bb83a951675fab9e4fdc55831 $
41    * @since 4.3M1
42    */
43    @Component
44    @Named("XWiki.XWikiUsers")
45    @Singleton
 
46    public class XWikiUsersDocumentInitializer extends AbstractMandatoryDocumentInitializer
47    {
48    /**
49    * The name of the field containing the user email.
50    */
51    private static final String EMAIL_FIELD = "email";
52   
53    /**
54    * The name of the field containing the time zone.
55    */
56    private static final String TIMEZONE_FIELD = "timezone";
57   
58    /**
59    * Used to bind a class to a document sheet.
60    */
61    @Inject
62    @Named("class")
63    private SheetBinder classSheetBinder;
64   
65    /**
66    * Default constructor.
67    */
 
68  61 toggle public XWikiUsersDocumentInitializer()
69    {
70  61 super(XWiki.SYSTEM_SPACE, "XWikiUsers");
71    }
72   
 
73  125 toggle @Override
74    public boolean updateDocument(XWikiDocument document)
75    {
76  125 boolean needsUpdate = false;
77   
78  125 BaseClass bclass = document.getXClass();
79   
80    // Force the class document to use the 2.1 syntax default syntax, the same syntax used in the custom displayer.
81  125 if (!Syntax.XWIKI_2_1.equals(document.getSyntax())) {
82  0 document.setSyntax(Syntax.XWIKI_2_1);
83  0 needsUpdate = true;
84    }
85   
86  125 needsUpdate |= bclass.addTextField("first_name", "First Name", 30);
87  125 needsUpdate |= bclass.addTextField("last_name", "Last Name", 30);
88   
89    // Email. Handle upgrade since in the past we were using a standard text field with a custom displayer and
90    // we're now using an Email Class. Thus we need to remove any existing field to upgrade it.
91  125 if (!(bclass.getField(EMAIL_FIELD) instanceof EmailClass)) {
92  39 bclass.removeField(EMAIL_FIELD);
93  39 bclass.addEmailField(EMAIL_FIELD, "e-Mail", 30);
94  39 needsUpdate = true;
95    }
96  125 needsUpdate |= bclass.addPasswordField("password", "Password", 10);
97  125 needsUpdate |= bclass.addPasswordField("validkey", "Validation Key", 10);
98  125 needsUpdate |= bclass.addBooleanField("active", "Active", "active");
99  125 needsUpdate |= bclass.addTextField("default_language", "Default Language", 30);
100  125 needsUpdate |= bclass.addTextField("company", "Company", 30);
101  125 needsUpdate |= bclass.addTextField("blog", "Blog", 60);
102  125 needsUpdate |= bclass.addTextField("blogfeed", "Blog Feed", 60);
103  125 needsUpdate |= bclass.addTextAreaField("comment", "Comment", 40, 5);
104  125 needsUpdate |= bclass.addStaticListField("imtype", "IM Type", "---|AIM|Yahoo|Jabber|MSN|Skype|ICQ");
105  125 needsUpdate |= bclass.addTextField("imaccount", "imaccount", 30);
106  125 needsUpdate |= bclass.addStaticListField("editor", "Default Editor", "---|Text|Wysiwyg");
107  125 needsUpdate |= bclass.addStaticListField("usertype", "User type", "Simple|Advanced");
108  125 needsUpdate |= bclass.addBooleanField("accessibility", "Enable extra accessibility features", "yesno");
109  125 needsUpdate |= bclass.addBooleanField("displayHiddenDocuments", "Display Hidden Documents", "yesno");
110   
111    // Timezone. Handle upgrade since in the past we were using a standard text field with a custom displayer and
112    // we're now using a Timezone Class. Thus we need to remove any existing field to upgrade it.
113  125 if (!(bclass.getField(TIMEZONE_FIELD) instanceof TimezoneClass)) {
114  39 bclass.removeField(TIMEZONE_FIELD);
115  39 bclass.addTimezoneField(TIMEZONE_FIELD, "Time Zone", 30);
116  39 needsUpdate = true;
117    }
118   
119    // New fields for the XWiki 1.0 skin
120  125 needsUpdate |= bclass.addTextField("skin", "skin", 30);
121  125 needsUpdate |= bclass.addTextField("avatar", "Avatar", 30);
122  125 needsUpdate |= bclass.addTextField("phone", "Phone", 30);
123  125 needsUpdate |= bclass.addTextAreaField("address", "Address", 40, 3);
124  125 needsUpdate |= setClassDocumentFields(document, "XWiki User Class");
125   
126    // Use XWikiUserSheet to display documents having XWikiUsers objects if no other class sheet is specified.
127  125 if (this.classSheetBinder.getSheets(document).isEmpty()) {
128  39 String wikiName = document.getDocumentReference().getWikiReference().getName();
129  39 DocumentReference sheet = new DocumentReference(wikiName, XWiki.SYSTEM_SPACE, "XWikiUserSheet");
130  39 needsUpdate |= this.classSheetBinder.bind(document, sheet);
131    }
132   
133  125 return needsUpdate;
134    }
135    }