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

File LinkCheckerEventListener.java

 

Coverage histogram

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

Code metrics

2
10
3
1
90
49
4
0.4
3.33
3
1.33

Classes

Class Line # Actions
LinkCheckerEventListener 48 10 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.linkchecker.internal;
21   
22    import java.util.Arrays;
23    import java.util.List;
24    import java.util.Map;
25   
26    import javax.inject.Inject;
27    import javax.inject.Named;
28    import javax.inject.Singleton;
29   
30    import org.xwiki.bridge.DocumentModelBridge;
31    import org.xwiki.bridge.event.DocumentUpdatingEvent;
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.model.reference.EntityReferenceSerializer;
34    import org.xwiki.observation.EventListener;
35    import org.xwiki.observation.event.Event;
36    import org.xwiki.rendering.transformation.linkchecker.LinkState;
37    import org.xwiki.rendering.transformation.linkchecker.LinkStateManager;
38   
39    /**
40    * Listen to Document updates and removes all Link States for the Document being modified.
41    *
42    * @version $Id: 41f1eecc7c0180b414cd8b52aa2e8f2057f29304 $
43    * @since 3.3M2
44    */
45    @Component
46    @Named("linkchecker")
47    @Singleton
 
48    public class LinkCheckerEventListener implements EventListener
49    {
50    /**
51    * The Reference serializer to serialize the reference of the Document which is being modified in order to
52    * compare it with the link state information.
53    */
54    @Inject
55    private EntityReferenceSerializer<String> serializer;
56   
57    /**
58    * Used to access the link states.
59    */
60    @Inject
61    private LinkStateManager linkStateManager;
62   
 
63  1 toggle @Override
64    public List<Event> getEvents()
65    {
66  1 return Arrays.<Event> asList(new DocumentUpdatingEvent());
67    }
68   
 
69  3 toggle @Override
70    public String getName()
71    {
72  3 return "LinkChecker";
73    }
74   
 
75  2 toggle @Override
76    public void onEvent(Event event, Object source, Object data)
77    {
78  2 DocumentModelBridge doc = (DocumentModelBridge) source;
79  2 final String reference = this.serializer.serialize(doc.getDocumentReference());
80   
81  2 Map<String, Map<String, LinkState>> states = this.linkStateManager.getLinkStates();
82  2 for (Map.Entry<String, Map<String, LinkState>> entry : states.entrySet()) {
83  2 Map<String, LinkState> state = entry.getValue();
84  2 state.remove(reference);
85  2 if (state.size() == 0) {
86  1 states.remove(entry.getKey());
87    }
88    }
89    }
90    }