1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.block

File BlockMatcherConverter.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

10
16
2
1
80
45
8
0.5
8
2
4

Classes

Class Line # Actions
BlockMatcherConverter 41 16 0% 8 4
0.8571428785.7%
 

Contributing tests

No tests hitting this source file were found.

Source view

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.internal.block;
21   
22    import java.lang.reflect.Type;
23   
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.properties.converter.AbstractConverter;
28    import org.xwiki.properties.converter.ConversionException;
29    import org.xwiki.rendering.block.Block;
30    import org.xwiki.rendering.block.match.BlockMatcher;
31    import org.xwiki.rendering.block.match.ClassBlockMatcher;
32   
33    /**
34    * Construct a BlockFilter from a String to a Syntax object and the other way around.
35    *
36    * @version $Id: 3e71008239c2d2466a3be9c8c706684bcf4c8ded $
37    * @since 6.1RC1
38    */
39    @Component
40    @Singleton
 
41    public class BlockMatcherConverter extends AbstractConverter<BlockMatcher>
42    {
43   
 
44  6 toggle @Override
45    protected BlockMatcher convertToType(Type targetType, Object value)
46    {
47  6 if (value == null) {
48  0 return null;
49    }
50  6 String matcherName = value.toString().trim();
51   
52  6 BlockMatcher matcher = null;
53  6 if (matcherName.startsWith("class:")) {
54  5 String blockClassName = matcherName.substring(6);
55  5 if (blockClassName.indexOf('.') == -1) {
56  2 blockClassName = "org.xwiki.rendering.block." + blockClassName;
57    }
58  5 try {
59  5 Class<?> blockClass = Class.forName(blockClassName);
60  3 if (Block.class.isAssignableFrom(blockClass)) {
61  2 matcher = new ClassBlockMatcher((Class<Block>) blockClass);
62    }
63    } catch (ClassNotFoundException c) {
64    // keep matcher as null and throw new exception later on
65    }
66    }
67   
68    // still having null here means the matcher is not found, return an error
69  6 if (matcher == null) {
70  4 throw new ConversionException(String.format("Unknown BlockMatcher [%s]", matcherName));
71    }
72  2 return matcher;
73    }
74   
 
75  0 toggle @Override
76    protected String convertToString(BlockMatcher value)
77    {
78  0 throw new ConversionException("not implemented yet");
79    }
80    }