1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.component.wiki.internal

File AbstractAsyncClassDocumentInitializer.java

 

Coverage histogram

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

Code metrics

4
18
2
1
95
53
5
0.28
9
2
2.5

Classes

Class Line # Actions
AbstractAsyncClassDocumentInitializer 42 18 0% 5 3
0.87587.5%
 

Contributing tests

This file is covered by 12 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 org.xwiki.component.wiki.internal;
21   
22    import java.util.Collection;
23    import java.util.Collections;
24   
25    import javax.inject.Inject;
26   
27    import org.slf4j.Logger;
28    import org.xwiki.component.manager.ComponentLookupException;
29    import org.xwiki.context.concurrent.ContextStoreManager;
30    import org.xwiki.localization.ContextualLocalizationManager;
31    import org.xwiki.model.reference.EntityReference;
32   
33    import com.xpn.xwiki.doc.AbstractMandatoryClassInitializer;
34    import com.xpn.xwiki.objects.classes.BaseClass;
35   
36    /**
37    * Base class to initialize xclass for various implementations of UI extensions.
38    *
39    * @version $Id: 8ab164745f202cec51d3f11237892abbe6e322e9 $
40    * @since 10.10RC1
41    */
 
42    public abstract class AbstractAsyncClassDocumentInitializer extends AbstractMandatoryClassInitializer
43    {
44    @Inject
45    private ContextStoreManager contextStore;
46   
47    @Inject
48    private ContextualLocalizationManager localization;
49   
50    @Inject
51    private Logger logger;
52   
53    /**
54    * @param reference the reference of the document to update. Can be either local or absolute depending if the
55    * document is associated to a specific wiki or not
56    */
 
57  240 toggle public AbstractAsyncClassDocumentInitializer(EntityReference reference)
58    {
59  240 super(reference);
60    }
61   
 
62  812 toggle @Override
63    protected void createClass(BaseClass xclass)
64    {
65  812 xclass.addBooleanField(AbstractAsyncBaseObjectWikiComponent.XPROPERTY_ASYNC_ENABLED, "Asynchronous rendering",
66    null, Boolean.FALSE);
67  812 xclass.addBooleanField(AbstractAsyncBaseObjectWikiComponent.XPROPERTY_ASYNC_CACHED, "Cached", null,
68    Boolean.FALSE);
69   
70    // TODO: move all that in a custom displayer to be less static
71  812 Collection<String> contextEntries;
72  812 try {
73  812 contextEntries = this.contextStore.getSupportedEntries();
74    } catch (ComponentLookupException e) {
75  0 this.logger.error("Failed to get supported context entries", e);
76   
77  0 contextEntries = Collections.emptyList();
78    }
79  812 StringBuilder entriesString = new StringBuilder();
80  812 for (String entry : contextEntries) {
81  7308 if (entriesString.length() > 0) {
82  6496 entriesString.append('|');
83    }
84  7308 entriesString.append(entry);
85   
86  7308 String translation = this.localization.getTranslationPlain("rendering.async.context.entry." + entry);
87  7308 if (translation != null) {
88  7308 entriesString.append('=');
89  7308 entriesString.append(translation);
90    }
91    }
92  812 xclass.addStaticListField(AbstractAsyncBaseObjectWikiComponent.XPROPERTY_ASYNC_CONTEXT, "Context elements", 5,
93    true, entriesString.toString());
94    }
95    }