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

File AbstractPanelsUIExtensionManager.java

 

Coverage histogram

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

Code metrics

4
14
1
1
120
57
4
0.29
14
1
4

Classes

Class Line # Actions
AbstractPanelsUIExtensionManager 46 14 0% 4 2
0.894736889.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.panels.internal;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Provider;
28   
29    import org.apache.commons.lang3.StringUtils;
30    import org.slf4j.Logger;
31    import org.xwiki.component.manager.ComponentLookupException;
32    import org.xwiki.component.manager.ComponentManager;
33    import org.xwiki.configuration.ConfigurationSource;
34    import org.xwiki.model.reference.DocumentReferenceResolver;
35    import org.xwiki.model.reference.EntityReferenceSerializer;
36    import org.xwiki.uiextension.UIExtension;
37    import org.xwiki.uiextension.UIExtensionManager;
38   
39    /**
40    * Abstract panels UI extension manager. Implementations must provide a list of panel IDs to be displayed, this class
41    * handles the retrieval of the UI extensions corresponding to the configured list.
42    *
43    * @version $Id: f70bd308afd189fc41885650673381bb70671c50 $
44    * @since 4.3.1
45    */
 
46    public abstract class AbstractPanelsUIExtensionManager implements UIExtensionManager
47    {
48    /**
49    * The default configuration source.
50    */
51    @Inject
52    protected ConfigurationSource configurationSource;
53   
54    /**
55    * The logger to log.
56    */
57    @Inject
58    private Logger logger;
59   
60    /**
61    * Resolver allowing to retrieve reference from the panels configuration.
62    */
63    @Inject
64    @Named("currentmixed")
65    private DocumentReferenceResolver<String> resolver;
66   
67    /**
68    * Serializer allowing to serialize references into their absolute representation.
69    */
70    @Inject
71    private EntityReferenceSerializer<String> serializer;
72   
73    /**
74    * We use the Context Component Manager to lookup UI Extensions registered as components.
75    * The Context Component Manager allows Extensions to be registered for a specific user, for a specific wiki or for
76    * a whole farm.
77    */
78    @Inject
79    @Named("context")
80    private Provider<ComponentManager> contextComponentManagerProvider;
81   
82    /**
83    * Method returning the list of configured panels.
84    *
85    * @return a comma separated list of panel IDs
86    */
87    protected abstract String getConfiguration();
88   
 
89  18 toggle @Override
90    public List<UIExtension> get(String extensionPointId)
91    {
92  18 List<UIExtension> panels = new ArrayList<UIExtension>();
93   
94  18 String panelConfigurationString = getConfiguration();
95   
96    // Verify that there's a panel configuration property defined, and if not don't return any panel extension.
97  18 if (!StringUtils.isEmpty(panelConfigurationString)) {
98  18 List<String> panelSerializedReferences = new ArrayList<String>();
99  18 for (String serializedReference : getConfiguration().split(",")) {
100  39 panelSerializedReferences.add(serializer.serialize(resolver.resolve(serializedReference.trim())));
101    }
102   
103  18 try {
104  18 List<UIExtension> allExtensions =
105    contextComponentManagerProvider.get().getInstanceList(UIExtension.class);
106  18 for (String panelSerializedReference : panelSerializedReferences) {
107  39 for (UIExtension extension : allExtensions) {
108  1337 if (extension.getId().equals(panelSerializedReference)) {
109  21 panels.add(extension);
110    }
111    }
112    }
113    } catch (ComponentLookupException e) {
114  0 logger.error("Failed to lookup Panels instances, error: [{}]", e);
115    }
116    }
117   
118  18 return panels;
119    }
120    }