1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.doc

File AbstractMandatoryClassInitializer.java

 

Coverage histogram

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

Code metrics

4
19
6
1
131
52
8
0.42
3.17
6
1.33

Classes

Class Line # Actions
AbstractMandatoryClassInitializer 34 19 0% 8 4
0.8620689586.2%
 

Contributing tests

This file is covered by 18 tests. .

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.doc;
21   
22    import org.xwiki.model.reference.EntityReference;
23    import org.xwiki.model.reference.LocalDocumentReference;
24   
25    import com.xpn.xwiki.XWiki;
26    import com.xpn.xwiki.objects.classes.BaseClass;
27   
28    /**
29    * Base class for standard mandatory document initializers.
30    *
31    * @version $Id: 1e541991cc3286e2244af8548741e3e16aed095b $
32    * @since 9.0RC1
33    */
 
34    public abstract class AbstractMandatoryClassInitializer extends AbstractMandatoryDocumentInitializer
35    {
36    private static final LocalDocumentReference CLASSSHEET_REFERENCE =
37    new LocalDocumentReference(XWiki.SYSTEM_SPACE, "ClassSheet");
38   
39    private static final LocalDocumentReference XWIKICLASSES_REFERENCE =
40    new LocalDocumentReference(XWiki.SYSTEM_SPACE, "XWikiClasses");
41   
42    /**
43    * @param reference the reference of the document to update. Can be either local or absolute depending if the
44    * document is associated to a specific wiki or not
45    */
 
46  2014 toggle public AbstractMandatoryClassInitializer(EntityReference reference)
47    {
48  2014 super(reference);
49    }
50   
51    /**
52    * @param reference the reference of the document to update. Can be either local or absolute depending if the
53    * document is associated to a specific wiki or not
54    * @param title the title of the document
55    */
 
56  2 toggle public AbstractMandatoryClassInitializer(EntityReference reference, String title)
57    {
58  2 super(reference, title);
59    }
60   
 
61  4136 toggle @Override
62    public boolean updateDocument(XWikiDocument document)
63    {
64  4136 boolean needUpdate = super.updateDocument(document);
65   
66    // Class related document fields
67  4136 needUpdate |= updateClassDocumentFields(document);
68   
69    // Get document class
70  4136 BaseClass currentClass = document.getXClass();
71   
72    // Generate the class from scratch
73  4136 BaseClass newClass = new BaseClass();
74  4136 newClass.setDocumentReference(currentClass.getDocumentReference());
75  4136 createClass(newClass);
76   
77    // Make sure the current class contains required properties
78  4136 needUpdate |= currentClass.apply(newClass, false);
79   
80  4136 return needUpdate;
81    }
82   
83    /**
84    * @param xclass the class to create
85    * @since 9.0RC1
86    */
 
87  0 toggle protected void createClass(BaseClass xclass)
88    {
89    // Override
90    }
91   
92    /**
93    * Update document with standard class related properties.
94    *
95    * @param document the document to update
96    * @return true if the document has been modified, false otherwise
97    * @since 9.0
98    */
 
99  4136 toggle protected boolean updateClassDocumentFields(XWikiDocument document)
100    {
101  4136 boolean needsUpdate = false;
102   
103    // Set the parent since it is different from the current document's space homepage.
104  4136 if (document.getParentReference() == null) {
105  0 needsUpdate = true;
106  0 document.setParentReference(XWIKICLASSES_REFERENCE);
107    }
108   
109    // Set the sheet of the document
110  4136 needsUpdate |= updateDocumentSheet(document);
111   
112  4136 return needsUpdate;
113    }
114   
115    /**
116    * Update document sheet. By default set the class sheet.
117    *
118    * @param document the document to update
119    * @return true if the document has been modified, false otherwise
120    * @since 9.0
121    */
 
122  4018 toggle protected boolean updateDocumentSheet(XWikiDocument document)
123    {
124    // Use ClassSheet to display the class document if no other sheet is explicitly specified.
125  4018 if (this.documentSheetBinder.getSheets(document).isEmpty()) {
126  959 return this.documentSheetBinder.bind(document, CLASSSHEET_REFERENCE);
127    }
128   
129  3059 return false;
130    }
131    }