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

File WikiTemplateClassDocumentInitializer.java

 

Coverage histogram

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

Code metrics

4
13
3
1
123
50
5
0.38
4.33
3
1.67

Classes

Class Line # Actions
WikiTemplateClassDocumentInitializer 42 13 0% 5 2
0.990%
 

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.template.internal;
21   
22    import javax.inject.Named;
23    import javax.inject.Singleton;
24   
25    import org.xwiki.component.annotation.Component;
26    import org.xwiki.model.EntityType;
27    import org.xwiki.model.reference.EntityReference;
28   
29    import com.xpn.xwiki.doc.XWikiDocument;
30    import com.xpn.xwiki.internal.mandatory.AbstractMandatoryDocumentInitializer;
31    import com.xpn.xwiki.objects.classes.BaseClass;
32   
33    /**
34    * Update the WikiManagerCode.WikiTemplateClass document with all required information.
35    *
36    * @since 5.3M2
37    * @version $Id: 2d8ecdb191a5506564fe773211f822f20de26a94 $
38    */
39    @Component
40    @Named("WikiManagerCode.WikiTemplateClass")
41    @Singleton
 
42    public class WikiTemplateClassDocumentInitializer extends AbstractMandatoryDocumentInitializer
43    {
44    /**
45    * The name of the mandatory document.
46    */
47    public static final String DOCUMENT_NAME = "WikiTemplateClass";
48   
49    /**
50    * The space of the mandatory document.
51    */
52    public static final String DOCUMENT_SPACE = "WikiManager";
53   
54    /**
55    * Reference to the server class.
56    */
57    public static final EntityReference SERVER_CLASS = new EntityReference(DOCUMENT_NAME, EntityType.DOCUMENT,
58    new EntityReference(DOCUMENT_SPACE, EntityType.SPACE));
59   
60    /**
61    * Name of field <code>iswikitemplate</code> for the XWiki class WikiManagerCode.WikiTemplateClass.
62    */
63    public static final String FIELD_ISWIKITEMPLATE = "iswikitemplate";
64   
65    /**
66    * Pretty name of field <code>iswikitemplate</code> for the XWiki class WikiManagerCode.WikiTemplateClass.
67    */
68    public static final String FIELDPN_ISWIKITEMPLATE = "Template";
69   
70    /**
71    * Display type of field <code>iswikitemplate</code> for the XWiki class WikiManagerCode.WikiTemplateClass.
72    */
73    public static final String FIELDDT_ISWIKITEMPLATE = "checkbox";
74   
75    /**
76    * Default value of field <code>iswikitemplate</code> for the XWiki class WikiManagerCode.WikiTemplateClass.
77    */
78    public static final Boolean DEFAULT_ISWIKITEMPLATE = Boolean.FALSE;
79   
80    /**
81    * Constructor.
82    */
 
83  1 toggle public WikiTemplateClassDocumentInitializer()
84    {
85    // Since we can`t get the main wiki here, this is just to be able to use the Abstract class.
86    // getDocumentReference() returns the actual main wiki document reference.
87  1 super(DOCUMENT_SPACE, DOCUMENT_NAME);
88    }
89   
 
90  1 toggle @Override
91    protected boolean isMainWikiOnly()
92    {
93    // The class is used inside wiki descriptors which are located on main wiki
94  1 return true;
95    }
96   
 
97  1 toggle @Override
98    public boolean updateDocument(XWikiDocument document)
99    {
100  1 boolean needsUpdate = false;
101   
102    // Add missing class fields
103  1 BaseClass baseClass = document.getXClass();
104   
105  1 needsUpdate |= baseClass.addBooleanField(FIELD_ISWIKITEMPLATE, FIELDPN_ISWIKITEMPLATE, FIELDDT_ISWIKITEMPLATE);
106  1 needsUpdate |= updateBooleanClassDefaultValue(baseClass, FIELD_ISWIKITEMPLATE, DEFAULT_ISWIKITEMPLATE);
107   
108    // Check if the document is hidden
109  1 if (!document.isHidden()) {
110  1 document.setHidden(true);
111  1 needsUpdate = true;
112    }
113   
114    // Mark this document as Wiki Class.
115  1 if (document.isNew()) {
116  1 needsUpdate |= setClassDocumentFields(document, "Wiki Template Class");
117  1 document.setContent(document.getContent() + "\n\nClass that represents the wiki descriptor property group"
118    + " for the template feature.");
119    }
120   
121  1 return needsUpdate;
122    }
123    }