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

File ExtensionUpdaterListener.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
8
3
1
89
51
5
0.62
2.67
3
1.67

Classes

Class Line # Actions
ExtensionUpdaterListener 44 8 0% 5 1
0.923076992.3%
 

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.repository.internal;
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.DocumentCreatingEvent;
32    import org.xwiki.bridge.event.DocumentUpdatingEvent;
33    import org.xwiki.component.annotation.Component;
34    import org.xwiki.observation.EventListener;
35    import org.xwiki.observation.event.Event;
36   
37    import com.xpn.xwiki.XWikiException;
38    import com.xpn.xwiki.doc.XWikiDocument;
39    import com.xpn.xwiki.objects.BaseObject;
40   
41    @Component
42    @Named("ExtensionUpdaterListener")
43    @Singleton
 
44    public class ExtensionUpdaterListener implements EventListener
45    {
46    /**
47    * Listened events.
48    */
49    private static final List<Event> EVENTS = Arrays.<Event> asList(new DocumentCreatingEvent(),
50    new DocumentUpdatingEvent());
51   
52    /**
53    * The logger to log.
54    */
55    @Inject
56    private Logger logger;
57   
58    @Inject
59    private Provider<RepositoryManager> repositoryManagerProvider;
60   
 
61  2 toggle @Override
62    public List<Event> getEvents()
63    {
64  2 return EVENTS;
65    }
66   
 
67  8 toggle @Override
68    public String getName()
69    {
70  8 return "ExtensionUpdaterListener";
71    }
72   
 
73  87 toggle @Override
74    public void onEvent(Event event, Object source, Object data)
75    {
76  87 XWikiDocument document = (XWikiDocument) source;
77   
78  87 BaseObject extensionObject = document.getXObject(XWikiRepositoryModel.EXTENSION_CLASSREFERENCE);
79   
80  87 if (extensionObject != null) {
81  45 try {
82  45 this.repositoryManagerProvider.get().validateExtension(document, false);
83    } catch (XWikiException e) {
84  0 this.logger.error("Failed to validate extension in document [{}]", document.getDocumentReference(), e);
85    }
86    }
87    }
88   
89    }