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

File TestTextMacro.java

 

Coverage histogram

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

Code metrics

2
8
3
1
81
47
5
0.62
2.67
3
1.67

Classes

Class Line # Actions
TestTextMacro 41 8 0% 5 2
0.8461538684.6%
 

Contributing tests

This file is covered by 1 test. .

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.macro.html;
21   
22    import java.io.StringReader;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.rendering.block.Block;
31    import org.xwiki.rendering.macro.AbstractNoParameterMacro;
32    import org.xwiki.rendering.macro.MacroExecutionException;
33    import org.xwiki.rendering.parser.ParseException;
34    import org.xwiki.rendering.parser.Parser;
35    import org.xwiki.rendering.transformation.MacroTransformationContext;
36    import org.xwiki.rendering.util.ParserUtils;
37   
38    @Component
39    @Named("testtextmacro")
40    @Singleton
 
41    public class TestTextMacro extends AbstractNoParameterMacro
42    {
43    /**
44    * Used to clean result of the parser syntax.
45    */
46    private ParserUtils parserUtils = new ParserUtils();
47   
48    @Inject
49    @Named("plain/1.0")
50    private Parser plainTextParser;
51   
 
52  1 toggle public TestTextMacro()
53    {
54  1 super("Text Macro");
55    }
56   
 
57  1 toggle @Override
58    public boolean supportsInlineMode()
59    {
60  1 return true;
61    }
62   
 
63  1 toggle @Override
64    public List<Block> execute(Object parameters, String content, MacroTransformationContext context)
65    throws MacroExecutionException
66    {
67  1 try {
68  1 List<Block> result = this.plainTextParser.parse(new StringReader(content)).getChildren();
69   
70  1 if (context.isInline()) {
71  1 this.parserUtils.removeTopLevelParagraph(result);
72    }
73   
74  1 return result;
75    } catch (ParseException e) {
76    // This shouldn't happen since the parser cannot throw an exception since the source is a memory
77    // String.
78  0 throw new RuntimeException("Failed to execute testextmacro", e);
79    }
80    }
81    }