|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
MetadataBlockMatcher | Line # 32 | 11 | 0% | 5 | 3 | 82.4% |
0.8235294
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(24) | |||
Result | |||
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8235294
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
1 | /* | |
2 | * See the NOTICE file distributed with this work for additional | |
3 | * information regarding copyright ownership. | |
4 | * | |
5 | * This is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 2.1 of | |
8 | * the License, or (at your option) any later version. | |
9 | * | |
10 | * This software is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this software; if not, write to the Free | |
17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
19 | */ | |
20 | package org.xwiki.rendering.block.match; | |
21 | ||
22 | import org.xwiki.rendering.block.Block; | |
23 | import org.xwiki.rendering.block.MetaDataBlock; | |
24 | import org.xwiki.rendering.listener.MetaData; | |
25 | ||
26 | /** | |
27 | * Implementation of {@link BlockMatcher} which matches {@link MetaData} information. | |
28 | * | |
29 | * @version $Id$ | |
30 | * @since 3.0M3 | |
31 | */ | |
32 | public class MetadataBlockMatcher extends ClassBlockMatcher | |
33 | { | |
34 | /** | |
35 | * The key of the {@link MetaData}. | |
36 | */ | |
37 | private String metadataKey; | |
38 | ||
39 | /** | |
40 | * The value of the {@link MetaData}. | |
41 | */ | |
42 | private Object metadataValue; | |
43 | ||
44 | /** | |
45 | * Match {@link MetaDataBlock} containing the provided key. | |
46 | * | |
47 | * @param metadataKey the key of the {@link MetaData} | |
48 | */ | |
49 | 40 | public MetadataBlockMatcher(String metadataKey) |
50 | { | |
51 | 40 | this(metadataKey, null); |
52 | } | |
53 | ||
54 | /** | |
55 | * Match {@link MetaDataBlock} containing the provided key/value pair. | |
56 | * | |
57 | * @param metadataKey the key of the {@link MetaData} | |
58 | * @param metadataValue the value of the {@link MetaData} | |
59 | */ | |
60 | 40 | public MetadataBlockMatcher(String metadataKey, Object metadataValue) |
61 | { | |
62 | 40 | super(MetaDataBlock.class); |
63 | ||
64 | 40 | this.metadataKey = metadataKey; |
65 | 40 | this.metadataValue = metadataValue; |
66 | } | |
67 | ||
68 | 85 | @Override |
69 | public boolean match(Block block) | |
70 | { | |
71 | 85 | return super.match(block) && matchMetadata(((MetaDataBlock) block).getMetaData()); |
72 | } | |
73 | ||
74 | /** | |
75 | * Matches the {@link MetaData} for provided key and value. | |
76 | * | |
77 | * @param metadata the {@link MetaData} to analyze | |
78 | * @return true is the {@link MetaData} is matched, false otherwise | |
79 | */ | |
80 | 40 | private boolean matchMetadata(MetaData metadata) |
81 | { | |
82 | 40 | boolean match; |
83 | ||
84 | 40 | if (this.metadataValue != null) { |
85 | 0 | Object value = metadata.getMetaData(this.metadataKey); |
86 | 0 | match = value != null && value.equals(this.metadataValue); |
87 | } else { | |
88 | 40 | match = metadata.contains(this.metadataKey); |
89 | } | |
90 | ||
91 | 40 | return match; |
92 | } | |
93 | } |
|