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

File IconThemeListener.java

 

Coverage histogram

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

Code metrics

2
10
3
1
87
50
5
0.5
3.33
3
1.67

Classes

Class Line # Actions
IconThemeListener 49 10 0% 5 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.icon.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.Singleton;
28   
29    import org.xwiki.bridge.event.DocumentDeletedEvent;
30    import org.xwiki.bridge.event.DocumentUpdatedEvent;
31    import org.xwiki.component.annotation.Component;
32    import org.xwiki.icon.IconSetCache;
33    import org.xwiki.model.reference.LocalDocumentReference;
34    import org.xwiki.observation.EventListener;
35    import org.xwiki.observation.event.Event;
36   
37    import com.xpn.xwiki.doc.XWikiDocument;
38    import com.xpn.xwiki.objects.BaseObject;
39   
40    /**
41    * Component that removes from the cache any icon set corresponding to an updated or deleted wiki document.
42    *
43    * @since 6.2M1
44    * @version $Id: 9fe92907ecae5f75f81e17443d3f66202ae4e5b1 $
45    */
46    @Component
47    @Named("iconTheme")
48    @Singleton
 
49    public class IconThemeListener implements EventListener
50    {
51    private static final LocalDocumentReference ICON_THEME_CLASS =
52    new LocalDocumentReference("IconThemesCode", "IconThemeClass");
53   
54    @Inject
55    private IconSetCache iconSetCache;
56   
 
57  361 toggle @Override
58    public String getName()
59    {
60  361 return "Icon Theme listener.";
61    }
62   
 
63  61 toggle @Override
64    public List<Event> getEvents()
65    {
66  61 return Arrays.<Event>asList(
67    new DocumentUpdatedEvent(),
68    new DocumentDeletedEvent());
69    }
70   
 
71  586 toggle @Override
72    public void onEvent(Event event, Object source, Object data)
73    {
74  586 XWikiDocument document = (XWikiDocument) source;
75   
76  586 List<BaseObject> iconThemeObjects = document.getXObjects(ICON_THEME_CLASS);
77  586 if (iconThemeObjects != null && !iconThemeObjects.isEmpty()) {
78    // Clear the icon set from the cache (since it has been updated)
79  1 iconSetCache.clear(document.getDocumentReference());
80    // Clear the icon set from its name
81  1 BaseObject iconThemeObj = iconThemeObjects.get(0);
82  1 String iconThemeName = iconThemeObj.getStringValue("name");
83  1 String currentWiki = document.getDocumentReference().getWikiReference().getName();
84  1 iconSetCache.clear(iconThemeName, currentWiki);
85    }
86    }
87    }