| 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.Arrays; |
| 24 |
|
import java.util.List; |
| 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.observation.EventListener; |
| 34 |
|
import org.xwiki.observation.event.Event; |
| 35 |
|
import org.xwiki.rendering.macro.wikibridge.WikiMacroInitializer; |
| 36 |
|
|
| 37 |
|
import com.xpn.xwiki.XWikiContext; |
| 38 |
|
import com.xpn.xwiki.internal.event.XARImportedEvent; |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@version |
| 47 |
|
|
| 48 |
|
@Component |
| 49 |
|
@Singleton |
| 50 |
|
@Named("register-macros-on-import") |
| |
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 51 |
|
public class RegisterMacrosOnImportListener implements EventListener |
| 52 |
|
{ |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
@Inject |
| 57 |
|
private WikiMacroInitializer macroInitializer; |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
@Inject |
| 63 |
|
private Execution execution; |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
@Inject |
| 69 |
|
private Logger logger; |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
private final List<Event> eventsList = new ArrayList<Event>(Arrays.asList(new XARImportedEvent())); |
| 75 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 76 |
23 |
@Override... |
| 77 |
|
public List<Event> getEvents() |
| 78 |
|
{ |
| 79 |
23 |
return eventsList; |
| 80 |
|
} |
| 81 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 82 |
69 |
@Override... |
| 83 |
|
public String getName() |
| 84 |
|
{ |
| 85 |
69 |
return "RegisterMacrosOnImportListener"; |
| 86 |
|
} |
| 87 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 88 |
19 |
@Override... |
| 89 |
|
public void onEvent(Event event, Object source, Object data) |
| 90 |
|
{ |
| 91 |
|
|
| 92 |
19 |
try { |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
19 |
XWikiContext xcontext = (XWikiContext) execution.getContext().getProperty("xwikicontext"); |
| 100 |
19 |
xcontext.remove("grouplist"); |
| 101 |
|
|
| 102 |
19 |
String currentWiki = xcontext.getWikiId(); |
| 103 |
19 |
macroInitializer.registerExistingWikiMacros(currentWiki); |
| 104 |
|
} catch (Exception e) { |
| 105 |
0 |
this.logger.warn("Could not register existing macros on import", e); |
| 106 |
|
} |
| 107 |
|
} |
| 108 |
|
} |