1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.model.reference.internal; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.crypto.BinaryStringEncoder; |
30 |
|
import org.xwiki.crypto.Digest; |
31 |
|
import org.xwiki.crypto.DigestFactory; |
32 |
|
import org.xwiki.model.EntityType; |
33 |
|
import org.xwiki.model.reference.BlockReference; |
34 |
|
import org.xwiki.model.reference.BlockReferenceResolver; |
35 |
|
import org.xwiki.model.reference.EntityReference; |
36 |
|
import org.xwiki.rendering.block.Block; |
37 |
|
import org.xwiki.rendering.signature.internal.BlockDumper; |
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@link |
45 |
|
|
46 |
|
@version |
47 |
|
@since |
48 |
|
|
49 |
|
@Component |
50 |
|
@Named("signedmacro") |
51 |
|
@Singleton |
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 4 |
Complexity Density: 0.5 |
|
52 |
|
public class SignedMacroBlockReferenceResolver implements BlockReferenceResolver<Block> |
53 |
|
{ |
54 |
|
@Inject |
55 |
|
@Named("SHA-1") |
56 |
|
private DigestFactory digestFactory; |
57 |
|
|
58 |
|
@Inject |
59 |
|
@Named("Base64") |
60 |
|
private BinaryStringEncoder encoder; |
61 |
|
|
62 |
|
@Inject |
63 |
|
@Named("macro") |
64 |
|
private BlockDumper dumper; |
65 |
|
|
66 |
|
|
67 |
|
@inheritDoc |
68 |
|
|
69 |
|
|
70 |
|
@link@link |
71 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 4 |
Complexity Density: 0.5 |
|
72 |
3 |
@Override... |
73 |
|
public BlockReference resolve(Block block, Object... parameters) |
74 |
|
{ |
75 |
3 |
EntityReference parent = null; |
76 |
|
|
77 |
3 |
if (parameters.length > 0 && parameters[0] instanceof EntityReference) { |
78 |
|
|
79 |
1 |
parent = (EntityReference) parameters[0]; |
80 |
|
} |
81 |
|
|
82 |
3 |
Digest digest = digestFactory.getInstance(); |
83 |
|
|
84 |
3 |
try { |
85 |
3 |
dumper.dump(digest.getOutputStream(), block); |
86 |
3 |
return new BlockReference(new EntityReference(encoder.encode(digest.digest()), EntityType.BLOCK, parent)); |
87 |
|
} catch (IOException ignore) { |
88 |
|
|
89 |
|
} |
90 |
0 |
return null; |
91 |
|
} |
92 |
|
} |