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

File SkinListener.java

 

Coverage histogram

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

Code metrics

2
10
4
1
100
62
6
0.6
2.5
4
1.5

Classes

Class Line # Actions
SkinListener 53 10 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 4 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.lesscss.internal.listeners;
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.Singleton;
28   
29    import org.xwiki.bridge.event.DocumentCreatedEvent;
30    import org.xwiki.bridge.event.DocumentDeletedEvent;
31    import org.xwiki.bridge.event.DocumentUpdatedEvent;
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.lesscss.internal.cache.ColorThemeCache;
34    import org.xwiki.lesscss.internal.cache.LESSResourcesCache;
35    import org.xwiki.lesscss.internal.skin.SkinReference;
36    import org.xwiki.lesscss.internal.skin.SkinReferenceFactory;
37    import org.xwiki.model.reference.LocalDocumentReference;
38    import org.xwiki.observation.EventListener;
39    import org.xwiki.observation.event.Event;
40   
41    import com.xpn.xwiki.doc.XWikiDocument;
42    import com.xpn.xwiki.objects.BaseObject;
43   
44    /**
45    * Listener that clears the cache of compiled LESS Skin resources when a skin document is saved.
46    *
47    * @since 6.4M2
48    * @version $Id: 24aea36d4a6e177e79ff470c8481b829336163dc $
49    */
50    @Component
51    @Named("lessSkin")
52    @Singleton
 
53    public class SkinListener implements EventListener
54    {
55    private static final LocalDocumentReference SKIN_CLASS =
56    new LocalDocumentReference("XWiki", "XWikiSkins");
57   
58    @Inject
59    private LESSResourcesCache lessResourcesCache;
60   
61    @Inject
62    private ColorThemeCache colorThemeCache;
63   
64    @Inject
65    private SkinReferenceFactory skinReferenceFactory;
66   
 
67  481 toggle @Override
68    public String getName()
69    {
70  481 return "LESS Skin Listener";
71    }
72   
 
73  61 toggle @Override
74    public List<Event> getEvents()
75    {
76  61 return Arrays.<Event>asList(
77    new DocumentCreatedEvent(),
78    new DocumentUpdatedEvent(),
79    new DocumentDeletedEvent());
80    }
81   
 
82  3968 toggle @Override
83    public void onEvent(Event event, Object source, Object data)
84    {
85  3968 XWikiDocument document = (XWikiDocument) source;
86   
87  3968 List<BaseObject> skinObjects = document.getXObjects(SKIN_CLASS);
88  3968 if (skinObjects != null && !skinObjects.isEmpty()) {
89  1 clearCacheFromSkin(document);
90  1 return;
91    }
92    }
93   
 
94  1 toggle private void clearCacheFromSkin(XWikiDocument document)
95    {
96  1 SkinReference skinReference = skinReferenceFactory.createReference(document.getDocumentReference());
97  1 lessResourcesCache.clearFromSkin(skinReference);
98  1 colorThemeCache.clearFromSkin(skinReference);
99    }
100    }