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

File XWikiServerClassDocumentInitializer.java

 

Coverage histogram

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

Code metrics

2
20
3
1
260
87
4
0.2
6.67
3
1.33

Classes

Class Line # Actions
XWikiServerClassDocumentInitializer 45 20 0% 4 0
1.0100%
 

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.wiki.internal.descriptor.document;
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.model.reference.LocalDocumentReference;
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.internal.mandatory.AbstractMandatoryDocumentInitializer;
34    import com.xpn.xwiki.objects.classes.BaseClass;
35   
36    /**
37    * Update the XWiki.XWikiServerClass document with all required information.
38    *
39    * @version $Id: 15076b75cf98442c62ff49e4f2a21ce3696e6a06 $
40    * @since 5.0M2
41    */
42    @Component
43    @Named("XWiki.XWikiServerClass")
44    @Singleton
 
45    public class XWikiServerClassDocumentInitializer extends AbstractMandatoryDocumentInitializer
46    {
47    /**
48    * The name of the mandatory document.
49    */
50    public static final String DOCUMENT_NAME = "XWikiServerClass";
51   
52    /**
53    * Reference to the server class.
54    */
55    public static final LocalDocumentReference SERVER_CLASS =
56    new LocalDocumentReference(XWiki.SYSTEM_SPACE, DOCUMENT_NAME);
57   
58    /**
59    * Default list separators of XWiki.XWikiServerClass fields.
60    */
61    public static final String DEFAULT_FIELDS_SEPARATOR = "|";
62   
63    /**
64    * Name of field <code>prettyname</code> for the XWiki class XWiki.XWikiServerClass.
65    */
66    public static final String FIELD_WIKIPRETTYNAME = "wikiprettyname";
67   
68    /**
69    * Pretty name of field <code>prettyname</code> for the XWiki class XWiki.XWikiServerClass.
70    */
71    public static final String FIELDPN_WIKIPRETTYNAME = "Wiki pretty name";
72   
73    /**
74    * Name of field <code>owner</code> for the XWiki class XWiki.XWikiServerClass.
75    */
76    public static final String FIELD_OWNER = "owner";
77   
78    /**
79    * Pretty name of field <code>owner</code> for the XWiki class XWiki.XWikiServerClass.
80    */
81    public static final String FIELDPN_OWNER = "Owner";
82   
83    /**
84    * Name of field <code>description</code> for the XWiki class XWiki.XWikiServerClass.
85    */
86    public static final String FIELD_DESCRIPTION = "description";
87   
88    /**
89    * Pretty name of field <code>description</code> for the XWiki class XWiki.XWikiServerClass.
90    */
91    public static final String FIELDPN_DESCRIPTION = "Description";
92   
93    /**
94    * Name of field <code>server</code> for the XWiki class XWiki.XWikiServerClass.
95    */
96    public static final String FIELD_SERVER = "server";
97   
98    /**
99    * Pretty name of field <code>server</code> for the XWiki class XWiki.XWikiServerClass.
100    */
101    public static final String FIELDPN_SERVER = "Server";
102   
103    /**
104    * Name of field <code>visibility</code> for the XWiki class XWiki.XWikiServerClass.
105    */
106    public static final String FIELD_VISIBILITY = "visibility";
107   
108    /**
109    * First possible values for <code>visibility</code> for the XWiki class XWiki.XWikiServerClass.
110    */
111    public static final String FIELDL_VISIBILITY_PUBLIC = "public";
112   
113    /**
114    * Second possible values for <code>visibility</code> for the XWiki class XWiki.XWikiServerClass.
115    */
116    public static final String FIELDL_VISIBILITY_PRIVATE = "private";
117   
118    /**
119    * List of possible values for <code>visibility</code> for the XWiki class XWiki.XWikiServerClass.
120    */
121    public static final String FIELDL_VISIBILITY = FIELDL_VISIBILITY_PUBLIC + DEFAULT_FIELDS_SEPARATOR
122    + FIELDL_VISIBILITY_PRIVATE + DEFAULT_FIELDS_SEPARATOR;
123   
124    /**
125    * Pretty name of field <code>visibility</code> for the XWiki class XWiki.XWikiServerClass.
126    */
127    public static final String FIELDPN_VISIBILITY = "Visibility";
128   
129    /**
130    * Name of field <code>state</code> for the XWiki class XWiki.XWikiServerClass.
131    */
132    public static final String FIELD_STATE = "state";
133   
134    /**
135    * First possible values for <code>state</code> for the XWiki class XWiki.XWikiServerClass.
136    */
137    public static final String FIELDL_STATE_ACTIVE = "active";
138   
139    /**
140    * Second possible values for <code>state</code> for the XWiki class XWiki.XWikiServerClass.
141    */
142    public static final String FIELDL_STATE_INACTIVE = "inactive";
143   
144    /**
145    * Third possible values for <code>state</code> for the XWiki class XWiki.XWikiServerClass.
146    */
147    public static final String FIELDL_STATE_LOCKED = "locked";
148   
149    /**
150    * List of possible values for <code>state</code> for the XWiki class XWiki.XWikiServerClass.
151    */
152    public static final String FIELDL_STATE = FIELDL_STATE_ACTIVE + DEFAULT_FIELDS_SEPARATOR + FIELDL_STATE_INACTIVE
153    + DEFAULT_FIELDS_SEPARATOR + FIELDL_STATE_LOCKED;
154   
155    /**
156    * Pretty name of field <code>state</code> for the XWiki class XWiki.XWikiServerClass.
157    */
158    public static final String FIELDPN_STATE = "State";
159   
160    /**
161    * Name of field <code>language</code> for the XWiki class XWiki.XWikiServerClass.
162    */
163    public static final String FIELD_LANGUAGE = "language";
164   
165    /**
166    * List of possible values for <code>language</code> for the XWiki class XWiki.XWikiServerClass.
167    */
168    public static final String FIELDL_LANGUAGE = "en|fr";
169   
170    /**
171    * Pretty name of field <code>language</code> for the XWiki class XWiki.XWikiServerClass.
172    */
173    public static final String FIELDPN_LANGUAGE = "Language";
174   
175    /**
176    * Name of field <code>secure</code> for the XWiki class XWiki.XWikiServerClass.
177    */
178    public static final String FIELD_SECURE = "secure";
179   
180    /**
181    * Pretty name of field <code>secure</code> for the XWiki class XWiki.XWikiServerClass.
182    */
183    public static final String FIELDPN_SECURE = "Secure";
184   
185    /**
186    * Display type of field <code>secure</code> for the XWiki class XWiki.XWikiServerClass.
187    */
188    public static final String FIELDDT_SECURE = "checkbox";
189   
190    /**
191    * Default value of field <code>secure</code> for the XWiki class XWiki.XWikiServerClass.
192    */
193    public static final Boolean DEFAULT_SECURE = Boolean.FALSE;
194   
195    /**
196    * Name of field <code>homepage</code> for the XWiki class XWiki.XWikiServerClass.
197    */
198    public static final String FIELD_HOMEPAGE = "homepage";
199   
200    /**
201    * Pretty name of field <code>homepage</code> for the XWiki class XWiki.XWikiServerClass.
202    */
203    public static final String FIELDPN_HOMEPAGE = "Home page";
204   
205    /**
206    * Used to bind a class to a document sheet.
207    */
208    @Inject
209    @Named("class")
210    private SheetBinder classSheetBinder;
211   
212    /**
213    * Default constructor.
214    */
 
215  60 toggle public XWikiServerClassDocumentInitializer()
216    {
217  60 super(XWiki.SYSTEM_SPACE, DOCUMENT_NAME);
218    }
219   
 
220  60 toggle @Override
221    public boolean isMainWikiOnly()
222    {
223    // Initialize it only for the main wiki.
224  60 return true;
225    }
226   
 
227  88 toggle @Override
228    public boolean updateDocument(XWikiDocument document)
229    {
230  88 boolean needsUpdate = false;
231   
232    // Add missing class fields
233  88 BaseClass baseClass = document.getXClass();
234   
235  88 needsUpdate |= baseClass.addTextField(FIELD_WIKIPRETTYNAME, FIELDPN_WIKIPRETTYNAME, 30);
236  88 needsUpdate |= baseClass.addUsersField(FIELD_OWNER, FIELDPN_OWNER, false);
237  88 needsUpdate |= baseClass.addTextAreaField(FIELD_DESCRIPTION, FIELDPN_DESCRIPTION, 40, 5);
238  88 needsUpdate |= baseClass.addTextField(FIELD_SERVER, FIELDPN_SERVER, 30);
239  88 needsUpdate |= baseClass.addStaticListField(FIELD_VISIBILITY, FIELDPN_VISIBILITY, FIELDL_VISIBILITY);
240  88 needsUpdate |= baseClass.addStaticListField(FIELD_STATE, FIELDPN_STATE, FIELDL_STATE);
241  88 needsUpdate |= baseClass.addStaticListField(FIELD_LANGUAGE, FIELDPN_LANGUAGE, FIELDL_LANGUAGE);
242  88 needsUpdate |= baseClass.addBooleanField(FIELD_SECURE, FIELDPN_SECURE, FIELDDT_SECURE);
243  88 needsUpdate |= updateBooleanClassDefaultValue(baseClass, FIELD_SECURE, DEFAULT_SECURE);
244  88 needsUpdate |= baseClass.addTextField(FIELD_HOMEPAGE, FIELDPN_HOMEPAGE, 30);
245   
246    // Add missing document fields
247  88 needsUpdate |= setClassDocumentFields(document, "XWiki Server Class");
248   
249    // Use XWikiServerClassSheet to display documents having XWikiServerClass objects if no other class sheet is
250    // specified.
251  88 if (this.classSheetBinder.getSheets(document).isEmpty()) {
252  34 String wikiName = document.getDocumentReference().getWikiReference().getName();
253  34 DocumentReference sheet = new DocumentReference(wikiName, XWiki.SYSTEM_SPACE, "XWikiServerClassSheet");
254  34 needsUpdate |= this.classSheetBinder.bind(document, sheet);
255    }
256   
257  88 return needsUpdate;
258    }
259   
260    }