| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.uiextension.internal; |
| 21 |
|
|
| 22 |
|
import java.lang.reflect.Type; |
| 23 |
|
import java.util.Collections; |
| 24 |
|
import java.util.Map; |
| 25 |
|
|
| 26 |
|
import org.slf4j.Logger; |
| 27 |
|
import org.slf4j.LoggerFactory; |
| 28 |
|
import org.xwiki.component.wiki.WikiComponent; |
| 29 |
|
import org.xwiki.component.wiki.WikiComponentScope; |
| 30 |
|
import org.xwiki.model.reference.DocumentReference; |
| 31 |
|
import org.xwiki.model.reference.ObjectReference; |
| 32 |
|
import org.xwiki.rendering.block.Block; |
| 33 |
|
import org.xwiki.rendering.block.WordBlock; |
| 34 |
|
import org.xwiki.security.authorization.AuthorExecutor; |
| 35 |
|
import org.xwiki.uiextension.UIExtension; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
@version |
| 42 |
|
@since |
| 43 |
|
|
| |
|
| 97.6% |
Uncovered Elements: 1 (41) |
Complexity: 16 |
Complexity Density: 0.67 |
|
| 44 |
|
public class WikiUIExtension implements UIExtension, WikiComponent |
| 45 |
|
{ |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
public static final String CONTEXT_UIX_KEY = "uix"; |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
public static final String CONTEXT_UIX_DOC_KEY = "doc"; |
| 55 |
|
|
| 56 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(WikiUIExtension.class); |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
@see |
| 60 |
|
|
| 61 |
|
private final DocumentReference documentReference; |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
@see |
| 65 |
|
|
| 66 |
|
private final DocumentReference authorReference; |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
@see |
| 70 |
|
|
| 71 |
|
private final String id; |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
@see |
| 75 |
|
|
| 76 |
|
private final String extensionPointId; |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
@see |
| 80 |
|
|
| 81 |
|
private final String roleHint; |
| 82 |
|
|
| 83 |
|
private final AuthorExecutor authorExecutor; |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
private WikiUIExtensionParameters parameters; |
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
private WikiUIExtensionRenderer renderer; |
| 94 |
|
|
| 95 |
|
|
| 96 |
|
@see |
| 97 |
|
|
| 98 |
|
private WikiComponentScope scope = WikiComponentScope.WIKI; |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
@param |
| 104 |
|
@param |
| 105 |
|
@param |
| 106 |
|
@param |
| 107 |
|
@param |
| 108 |
|
@param |
| 109 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 110 |
129 |
public WikiUIExtension(String roleHint, String id, String extensionPointId, ObjectReference objectReference,... |
| 111 |
|
DocumentReference authorReference, AuthorExecutor authorExecutor) |
| 112 |
|
{ |
| 113 |
129 |
this.roleHint = roleHint; |
| 114 |
129 |
this.id = id; |
| 115 |
129 |
this.extensionPointId = extensionPointId; |
| 116 |
129 |
this.authorReference = authorReference; |
| 117 |
129 |
this.documentReference = (DocumentReference) objectReference.getParent(); |
| 118 |
|
|
| 119 |
129 |
this.authorExecutor = authorExecutor; |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
@param |
| 126 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 127 |
128 |
public void setParameters(WikiUIExtensionParameters parameters)... |
| 128 |
|
{ |
| 129 |
128 |
this.parameters = parameters; |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
@param |
| 136 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 137 |
128 |
public void setRenderer(WikiUIExtensionRenderer renderer)... |
| 138 |
|
{ |
| 139 |
128 |
this.renderer = renderer; |
| 140 |
|
} |
| 141 |
|
|
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
@param |
| 146 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 147 |
129 |
public void setScope(WikiComponentScope scope)... |
| 148 |
|
{ |
| 149 |
129 |
this.scope = scope; |
| 150 |
|
} |
| 151 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 152 |
207 |
@Override... |
| 153 |
|
public String getId() |
| 154 |
|
{ |
| 155 |
207 |
return this.id; |
| 156 |
|
} |
| 157 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 158 |
18122 |
@Override... |
| 159 |
|
public String getExtensionPointId() |
| 160 |
|
{ |
| 161 |
18122 |
return this.extensionPointId; |
| 162 |
|
} |
| 163 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 164 |
2965 |
@Override... |
| 165 |
|
public Map<String, String> getParameters() |
| 166 |
|
{ |
| 167 |
2965 |
if (this.parameters != null) { |
| 168 |
2964 |
return this.parameters.get(); |
| 169 |
|
} else { |
| 170 |
1 |
return Collections.emptyMap(); |
| 171 |
|
} |
| 172 |
|
} |
| 173 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 174 |
1294 |
@Override... |
| 175 |
|
public Block execute() |
| 176 |
|
{ |
| 177 |
1294 |
if (this.renderer != null) { |
| 178 |
1293 |
try { |
| 179 |
1293 |
return this.authorExecutor.call(this.renderer::execute, getAuthorReference()); |
| 180 |
|
} catch (Exception e) { |
| 181 |
0 |
LOGGER.error("Error while executing transformation for extension [{}]", documentReference.toString()); |
| 182 |
|
} |
| 183 |
|
} |
| 184 |
|
|
| 185 |
1 |
return new WordBlock(""); |
| 186 |
|
} |
| 187 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 188 |
385 |
@Override... |
| 189 |
|
public DocumentReference getDocumentReference() |
| 190 |
|
{ |
| 191 |
385 |
return documentReference; |
| 192 |
|
} |
| 193 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 194 |
2684 |
@Override... |
| 195 |
|
public DocumentReference getAuthorReference() |
| 196 |
|
{ |
| 197 |
2684 |
return authorReference; |
| 198 |
|
} |
| 199 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 200 |
133 |
@Override... |
| 201 |
|
public Type getRoleType() |
| 202 |
|
{ |
| 203 |
133 |
return UIExtension.class; |
| 204 |
|
} |
| 205 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 206 |
133 |
@Override... |
| 207 |
|
public String getRoleHint() |
| 208 |
|
{ |
| 209 |
133 |
return roleHint; |
| 210 |
|
} |
| 211 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 212 |
133 |
@Override... |
| 213 |
|
public WikiComponentScope getScope() |
| 214 |
|
{ |
| 215 |
133 |
return scope; |
| 216 |
|
} |
| 217 |
|
} |