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

File WikiMacroInitializerListener.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

4
11
3
1
103
57
7
0.64
3.67
3
2.33

Classes

Class Line # Actions
WikiMacroInitializerListener 48 11 0% 7 8
0.555555655.6%
 

Contributing tests

This file is covered by 11 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.rendering.internal.macro.wikibridge;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Provider;
28    import javax.inject.Singleton;
29   
30    import org.slf4j.Logger;
31    import org.xwiki.bridge.event.ApplicationReadyEvent;
32    import org.xwiki.bridge.event.WikiReadyEvent;
33    import org.xwiki.component.annotation.Component;
34    import org.xwiki.observation.EventListener;
35    import org.xwiki.observation.event.Event;
36    import org.xwiki.rendering.macro.wikibridge.WikiMacroInitializer;
37    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
38   
39    /**
40    * Called at startup to initialize existing wiki macros.
41    *
42    * @version $Id: 4d07ce78abe4451fa84954c8d662752932470a21 $
43    * @since 4.2M1
44    */
45    @Component
46    @Singleton
47    @Named(WikiMacroInitializerListener.NAME)
 
48    public class WikiMacroInitializerListener implements EventListener
49    {
50    static final String NAME = "WikiMacroInitializerListener";
51   
52    /**
53    * The events observed by this event listener.
54    */
55    private static final List<Event> EVENTS = Arrays.asList(new ApplicationReadyEvent(), new WikiReadyEvent());
56   
57    /**
58    * The macro initializer used to register the wiki macros.
59    */
60    @Inject
61    private Provider<WikiMacroInitializer> macroInitializer;
62   
63    @Inject
64    private WikiDescriptorManager wikiManager;
65   
66    /**
67    * The logger to log.
68    */
69    @Inject
70    private Logger logger;
71   
 
72  30 toggle @Override
73    public List<Event> getEvents()
74    {
75  30 return EVENTS;
76    }
77   
 
78  158 toggle @Override
79    public String getName()
80    {
81  158 return NAME;
82    }
83   
 
84  19 toggle @Override
85    public void onEvent(Event event, Object source, Object data)
86    {
87  19 WikiMacroInitializer initializer = this.macroInitializer.get();
88   
89  19 if (event instanceof ApplicationReadyEvent) {
90  19 try {
91  19 initializer.registerExistingWikiMacros(wikiManager.getCurrentWikiId());
92    } catch (Exception e) {
93  0 this.logger.error("Error while registering wiki macros.", e);
94    }
95  0 } else if (event instanceof WikiReadyEvent) {
96  0 try {
97  0 initializer.registerExistingWikiMacros(((WikiReadyEvent) event).getWikiId());
98    } catch (Exception e) {
99  0 this.logger.error("Error while initializing wiki macro classes.", e);
100    }
101    }
102    }
103    }