| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.rendering.wikimacro.internal; |
| 21 |
|
|
| 22 |
|
import java.util.ArrayList; |
| 23 |
|
import java.util.List; |
| 24 |
|
import java.util.Stack; |
| 25 |
|
|
| 26 |
|
import javax.inject.Inject; |
| 27 |
|
import javax.inject.Named; |
| 28 |
|
import javax.inject.Singleton; |
| 29 |
|
|
| 30 |
|
import org.slf4j.Logger; |
| 31 |
|
import org.xwiki.component.annotation.Component; |
| 32 |
|
import org.xwiki.context.Execution; |
| 33 |
|
import org.xwiki.context.ExecutionContext; |
| 34 |
|
import org.xwiki.observation.EventListener; |
| 35 |
|
import org.xwiki.observation.event.Event; |
| 36 |
|
import org.xwiki.rendering.macro.wikibridge.WikiMacro; |
| 37 |
|
import org.xwiki.rendering.macro.wikibridge.WikiMacroExecutionFinishedEvent; |
| 38 |
|
import org.xwiki.rendering.macro.wikibridge.WikiMacroExecutionStartsEvent; |
| 39 |
|
import org.xwiki.security.authorization.AuthorExecutor; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
@version |
| 46 |
|
|
| 47 |
|
@Component |
| 48 |
|
@Singleton |
| 49 |
|
@Named("WikiMacroExecutionEventListener") |
| |
|
| 93.5% |
Uncovered Elements: 2 (31) |
Complexity: 10 |
Complexity Density: 0.53 |
|
| 50 |
|
public class WikiMacroExecutionEventListener implements EventListener |
| 51 |
|
{ |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
private static final String NAME = "WikiMacroExecutionEventListener"; |
| 56 |
|
|
| 57 |
|
private static final String SUCONTEXT_KEY = "wikimacro.backup.sucontext"; |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
private static final List<Event> EVENTS = new ArrayList<Event>() |
| 63 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 64 |
20 |
{... |
| 65 |
20 |
add(new WikiMacroExecutionStartsEvent()); |
| 66 |
20 |
add(new WikiMacroExecutionFinishedEvent()); |
| 67 |
|
} |
| 68 |
|
}; |
| 69 |
|
|
| 70 |
|
@Inject |
| 71 |
|
private Execution execution; |
| 72 |
|
|
| 73 |
|
@Inject |
| 74 |
|
private AuthorExecutor suExecutor; |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
@Inject |
| 80 |
|
private Logger logger; |
| 81 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 82 |
23 |
@Override... |
| 83 |
|
public List<Event> getEvents() |
| 84 |
|
{ |
| 85 |
23 |
return EVENTS; |
| 86 |
|
} |
| 87 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 88 |
92 |
@Override... |
| 89 |
|
public String getName() |
| 90 |
|
{ |
| 91 |
92 |
return NAME; |
| 92 |
|
} |
| 93 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 94 |
292 |
@Override... |
| 95 |
|
public void onEvent(Event event, Object source, Object data) |
| 96 |
|
{ |
| 97 |
292 |
if (event instanceof WikiMacroExecutionStartsEvent) { |
| 98 |
146 |
onWikiMacroExecutionStartsEvent((WikiMacro) source); |
| 99 |
|
} else { |
| 100 |
146 |
onWikiMacroExecutionFinishedEvent(); |
| 101 |
|
} |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
|
| 105 |
|
@link |
| 106 |
|
|
| 107 |
|
@param |
| 108 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 109 |
146 |
public void onWikiMacroExecutionStartsEvent(WikiMacro wikiMacro)... |
| 110 |
|
{ |
| 111 |
|
|
| 112 |
146 |
AutoCloseable sucontext = this.suExecutor.before(wikiMacro.getAuthorReference()); |
| 113 |
|
|
| 114 |
|
|
| 115 |
146 |
ExecutionContext econtext = this.execution.getContext(); |
| 116 |
|
|
| 117 |
146 |
Stack<AutoCloseable> backup = (Stack<AutoCloseable>) econtext.getProperty(SUCONTEXT_KEY); |
| 118 |
146 |
if (backup == null) { |
| 119 |
93 |
backup = new Stack<AutoCloseable>(); |
| 120 |
93 |
econtext.setProperty(SUCONTEXT_KEY, backup); |
| 121 |
|
} |
| 122 |
146 |
backup.push(sucontext); |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
@link |
| 127 |
|
|
| |
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 128 |
146 |
public void onWikiMacroExecutionFinishedEvent()... |
| 129 |
|
{ |
| 130 |
|
|
| 131 |
146 |
ExecutionContext econtext = this.execution.getContext(); |
| 132 |
|
|
| 133 |
146 |
Stack<AutoCloseable> backup = (Stack<AutoCloseable>) econtext.getProperty(SUCONTEXT_KEY); |
| 134 |
146 |
if (backup != null && !backup.isEmpty()) { |
| 135 |
|
|
| 136 |
146 |
this.suExecutor.after(backup.pop()); |
| 137 |
|
} else { |
| 138 |
0 |
this.logger.error("Can't find any backed up execution right information in the execution context"); |
| 139 |
|
} |
| 140 |
|
} |
| 141 |
|
} |