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

File WikiComponentManagerEventListenerHelper.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
56% of files have more coverage

Code metrics

0
7
2
1
89
41
4
0.57
3.5
2
2

Classes

Class Line # Actions
WikiComponentManagerEventListenerHelper 46 7 0% 4 2
0.777777877.8%
 

Contributing tests

This file is covered by 2 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.List;
23   
24    import javax.inject.Inject;
25    import javax.inject.Singleton;
26   
27    import org.apache.commons.lang3.exception.ExceptionUtils;
28    import org.slf4j.Logger;
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.wiki.WikiComponent;
31    import org.xwiki.component.wiki.WikiComponentException;
32    import org.xwiki.component.wiki.WikiComponentManager;
33    import org.xwiki.component.wiki.internal.bridge.DefaultWikiObjectComponentManagerEventListener;
34    import org.xwiki.model.reference.EntityReference;
35   
36    /**
37    * This component is meant to ease the interaction between the two event listeners that are
38    * {@link DefaultWikiComponentManagerEventListener} and {@link DefaultWikiObjectComponentManagerEventListener}
39    * and the {@link DefaultWikiComponentManager}.
40    *
41    * @version $Id: 8d41b0a3e57f589690e190463120455f137c9020 $
42    * @since 9.5RC1
43    */
44    @Component(roles = WikiComponentManagerEventListenerHelper.class)
45    @Singleton
 
46    public class WikiComponentManagerEventListenerHelper
47    {
48    /**
49    * The wiki component manager that knows how to register component definition against the underlying CM.
50    */
51    @Inject
52    private WikiComponentManager wikiComponentManager;
53   
54    @Inject
55    private Logger logger;
56   
57    /**
58    * Register every given {@link WikiComponent} against the {@link WikiComponentManager}.
59    *
60    * @param components a list of components that should be registered
61    */
 
62  1923 toggle public void registerComponentList(List<WikiComponent> components)
63    {
64  1923 for (WikiComponent component : components) {
65    // Register the component
66  1902 try {
67  1902 this.wikiComponentManager.registerWikiComponent(component);
68    } catch (WikiComponentException e) {
69  0 this.logger.warn("Unable to register component(s) from document [{}]: {}",
70    component.getDocumentReference(), ExceptionUtils.getRootCauseMessage(e));
71    }
72    }
73    }
74   
75    /**
76    * Helper method to unregister a wiki component.
77    *
78    * @param entityReference the reference to the entity for which to unregister the held wiki component.
79    */
 
80  10454 toggle public void unregisterComponents(EntityReference entityReference)
81    {
82  10454 try {
83  10454 this.wikiComponentManager.unregisterWikiComponents(entityReference);
84    } catch (WikiComponentException e) {
85  0 this.logger.warn("Unable to unregister component(s) from the entity [{}]: {}", entityReference,
86    ExceptionUtils.getRootCauseMessage(e));
87    }
88    }
89    }