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

File AbstractScriptCheckerListener.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

4
5
2
1
86
30
7
1.4
2.5
2
3.5

Classes

Class Line # Actions
AbstractScriptCheckerListener 40 5 0% 7 3
0.7272727572.7%
 

Contributing tests

This file is covered by 100 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.rendering.internal.macro.script;
21   
22    import java.util.Collections;
23    import java.util.List;
24   
25    import org.xwiki.observation.EventListener;
26    import org.xwiki.observation.event.CancelableEvent;
27    import org.xwiki.observation.event.Event;
28    import org.xwiki.script.event.ScriptEvaluatingEvent;
29    import org.xwiki.rendering.macro.script.ScriptMacroParameters;
30    import org.xwiki.rendering.transformation.MacroTransformationContext;
31   
32    /**
33    * Abstract base class for listeners that need to perform some checks just before a script macro is executed. Subclasses
34    * must implement {@link #check(CancelableEvent, MacroTransformationContext, ScriptMacroParameters)} that allows
35    * them to avoid casting and checking for the right event type.
36    *
37    * @version $Id: 00c8985a202cfb230b3a93fde10746356b70c159 $
38    * @since 2.5M1
39    */
 
40    public abstract class AbstractScriptCheckerListener implements EventListener
41    {
42    /**
43    * {@inheritDoc}
44    * <p>
45    * This implementation returns a singleton list with a {@link org.xwiki.script.event.ScriptEvaluatingEvent}.
46    * </p>
47    *
48    * @see org.xwiki.observation.EventListener#getEvents()
49    */
 
50  286 toggle @Override
51    public List<Event> getEvents()
52    {
53  286 return Collections.singletonList((Event) new ScriptEvaluatingEvent());
54    }
55   
56    /**
57    * {@inheritDoc}
58    * <p>
59    * This implementation casts the arguments to the correct type and calls
60    * {@link #check(CancelableEvent, MacroTransformationContext, ScriptMacroParameters)}.
61    * </p>
62    *
63    * @see org.xwiki.observation.EventListener#onEvent(Event, java.lang.Object, java.lang.Object)
64    */
 
65  17485 toggle @Override
66    public void onEvent(Event event, Object source, Object data)
67    {
68  17484 if (!(event instanceof ScriptEvaluatingEvent)) {
69  0 return;
70    }
71  17485 if ((source == null || source instanceof MacroTransformationContext)
72    && (data == null || data instanceof ScriptMacroParameters)) {
73  17485 check((CancelableEvent) event, (MacroTransformationContext) source, (ScriptMacroParameters) data);
74    }
75    }
76   
77    /**
78    * This method is called when an {@link org.xwiki.script.event.ScriptEvaluatingEvent} is received.
79    *
80    * @param event the received event
81    * @param context current transformation context
82    * @param parameters parameters of the script macro about to be executed
83    */
84    protected abstract void check(CancelableEvent event, MacroTransformationContext context,
85    ScriptMacroParameters parameters);
86    }