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

File ColorThemeListener.java

 

Coverage histogram

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

Code metrics

4
14
4
1
110
70
8
0.57
3.5
4
2

Classes

Class Line # Actions
ColorThemeListener 53 14 0% 8 0
1.0100%
 

Contributing tests

This file is covered by 5 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.colortheme.ColorThemeReference;
36    import org.xwiki.lesscss.internal.colortheme.ColorThemeReferenceFactory;
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 file when a color theme is changed.
46    *
47    * @since 6.4M2
48    * @version $Id: 48cfd9db2963278f15e254831fd9b854b08f561e $
49    */
50    @Component
51    @Named("lessColorTheme")
52    @Singleton
 
53    public class ColorThemeListener implements EventListener
54    {
55    private static final LocalDocumentReference COLOR_THEME_CLASS =
56    new LocalDocumentReference("ColorThemes", "ColorThemeClass");
57   
58    private static final LocalDocumentReference FLAMINGO_THEME_CLASS =
59    new LocalDocumentReference("FlamingoThemesCode", "ThemeClass");
60   
61    @Inject
62    private LESSResourcesCache lessResourcesCache;
63   
64    @Inject
65    private ColorThemeCache colorThemeCache;
66   
67    @Inject
68    private ColorThemeReferenceFactory colorThemeReferenceFactory;
69   
 
70  481 toggle @Override
71    public String getName()
72    {
73  481 return "LESS Color Theme Listener";
74    }
75   
 
76  61 toggle @Override
77    public List<Event> getEvents()
78    {
79  61 return Arrays.<Event>asList(
80    new DocumentCreatedEvent(),
81    new DocumentUpdatedEvent(),
82    new DocumentDeletedEvent());
83    }
84   
 
85  3969 toggle @Override
86    public void onEvent(Event event, Object source, Object data)
87    {
88  3969 XWikiDocument document = (XWikiDocument) source;
89   
90  3969 List<BaseObject> flamingoThemeObjects = document.getXObjects(FLAMINGO_THEME_CLASS);
91  3969 if (flamingoThemeObjects != null && !flamingoThemeObjects.isEmpty()) {
92  7 clearCacheFromColorTheme(document);
93  7 return;
94    }
95   
96  3962 List<BaseObject> colorThemeObjects = document.getXObjects(COLOR_THEME_CLASS);
97  3962 if (colorThemeObjects != null && !colorThemeObjects.isEmpty()) {
98  1 clearCacheFromColorTheme(document);
99  1 return;
100    }
101    }
102   
 
103  8 toggle private void clearCacheFromColorTheme(XWikiDocument document)
104    {
105  8 ColorThemeReference colorThemeReference =
106    colorThemeReferenceFactory.createReference(document.getDocumentReference());
107  8 lessResourcesCache.clearFromColorTheme(colorThemeReference);
108  8 colorThemeCache.clearFromColorTheme(colorThemeReference);
109    }
110    }