1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.edit; |
21 |
|
|
22 |
|
import java.util.HashMap; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.script.ScriptContext; |
27 |
|
|
28 |
|
import org.xwiki.script.ScriptContextManager; |
29 |
|
import org.xwiki.stability.Unstable; |
30 |
|
|
31 |
|
|
32 |
|
@link |
33 |
|
|
34 |
|
@param |
35 |
|
@version |
36 |
|
@since |
37 |
|
|
38 |
|
@Unstable |
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
39 |
|
public abstract class AbstractEditor<D> implements Editor<D> |
40 |
|
{ |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
private static final String EDIT_CONTEXT_KEY = "edit"; |
45 |
|
|
46 |
|
@Inject |
47 |
|
private ScriptContextManager scripts; |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
49 |
337 |
@Override... |
50 |
|
public String render(D data, Map<String, Object> parameters) throws EditException |
51 |
|
{ |
52 |
337 |
ScriptContext scriptContext = this.scripts.getCurrentScriptContext(); |
53 |
|
|
54 |
337 |
Object currentEdit = scriptContext.getAttribute(EDIT_CONTEXT_KEY, ScriptContext.ENGINE_SCOPE); |
55 |
337 |
try { |
56 |
337 |
scriptContext.setAttribute(EDIT_CONTEXT_KEY, getEditContext(data, parameters), ScriptContext.ENGINE_SCOPE); |
57 |
|
|
58 |
337 |
return render(); |
59 |
|
} finally { |
60 |
337 |
scriptContext.setAttribute(EDIT_CONTEXT_KEY, currentEdit, ScriptContext.ENGINE_SCOPE); |
61 |
|
} |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
64 |
337 |
protected Map<String, Object> getEditContext(D data, Map<String, Object> parameters)... |
65 |
|
{ |
66 |
337 |
Map<String, Object> editContext = new HashMap<>(); |
67 |
337 |
editContext.put("data", data); |
68 |
337 |
editContext.put("parameters", parameters); |
69 |
337 |
return editContext; |
70 |
|
} |
71 |
|
|
72 |
|
protected abstract String render() throws EditException; |
73 |
|
} |