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

File AnnotationClassDocumentInitializer.java

 

Coverage histogram

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

Code metrics

2
16
3
1
101
53
4
0.25
5.33
3
1.33

Classes

Class Line # Actions
AnnotationClassDocumentInitializer 47 16 0% 4 2
0.904761990.5%
 

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.annotation.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.annotation.Annotation;
27    import org.xwiki.annotation.AnnotationConfiguration;
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.model.reference.EntityReference;
30   
31    import com.xpn.xwiki.doc.XWikiDocument;
32    import com.xpn.xwiki.internal.mandatory.AbstractMandatoryDocumentInitializer;
33    import com.xpn.xwiki.objects.classes.BaseClass;
34    import com.xpn.xwiki.objects.classes.TextAreaClass.ContentType;
35   
36    /**
37    * When the wiki is initialized, make sure that the configured annotation class contains the minimum required properties
38    * for the Annotation Application to function properly.
39    *
40    * @version $Id: 8d75b62cee549ad8ba4ecc8e5d847f4786000c01 $
41    * @since 6.2RC1
42    */
43    @Component
44    // The role hint is not a document name since it can change based the configuration
45    @Named(AnnotationClassDocumentInitializer.HINT)
46    @Singleton
 
47    public class AnnotationClassDocumentInitializer extends AbstractMandatoryDocumentInitializer
48    {
49    static final String HINT = "annotationclass";
50   
51    /**
52    * The Annotation Application's configuration.
53    */
54    @Inject
55    protected AnnotationConfiguration configuration;
56   
57    /**
58    * Default constructor.
59    */
 
60  1 toggle public AnnotationClassDocumentInitializer()
61    {
62  1 super(null);
63    }
64   
 
65  1 toggle @Override
66    public EntityReference getDocumentReference()
67    {
68  1 return this.configuration.getAnnotationClassReference();
69    }
70   
 
71  1 toggle @Override
72    public boolean updateDocument(XWikiDocument document)
73    {
74  1 if (!this.configuration.isInstalled()) {
75    // If the Annotations Application is not installed on the current wiki, do nothing.
76  0 return false;
77    }
78   
79  1 BaseClass annotationClass = document.getXClass();
80   
81  1 boolean needsUpdate = false;
82   
83  1 needsUpdate |= annotationClass.addTextField(Annotation.AUTHOR_FIELD, "Author", 30);
84  1 needsUpdate |= annotationClass.addDateField(Annotation.DATE_FIELD, "Date");
85   
86  1 needsUpdate |=
87    annotationClass.addTextAreaField(Annotation.SELECTION_FIELD, "Selection", 40, 5, ContentType.PURE_TEXT);
88  1 needsUpdate |= annotationClass.addTextAreaField(Annotation.SELECTION_LEFT_CONTEXT_FIELD,
89    "Selection Left Context", 40, 5, ContentType.PURE_TEXT);
90  1 needsUpdate |= annotationClass.addTextAreaField(Annotation.SELECTION_RIGHT_CONTEXT_FIELD,
91    "Selection Right Context", 40, 5, ContentType.PURE_TEXT);
92  1 needsUpdate |= annotationClass.addTextAreaField(Annotation.ORIGINAL_SELECTION_FIELD, "Original Selection", 40,
93    5, ContentType.PURE_TEXT);
94  1 needsUpdate |= annotationClass.addTextField(Annotation.TARGET_FIELD, "Target", 30);
95  1 needsUpdate |= annotationClass.addTextField(Annotation.STATE_FIELD, "State", 30);
96   
97  1 needsUpdate |= setClassDocumentFields(document, "Annotation Class");
98   
99  1 return needsUpdate;
100    }
101    }