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

File QuoteMacro.java

 

Coverage histogram

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

Code metrics

0
8
3
1
101
51
3
0.38
2.67
3
1

Classes

Class Line # Actions
QuoteMacro 51 8 0% 3 2
0.818181881.8%
 

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.internal.macro.quote;
21   
22    import java.util.ArrayList;
23    import java.util.Collections;
24    import java.util.List;
25   
26    import javax.inject.Inject;
27    import javax.inject.Named;
28    import javax.inject.Singleton;
29   
30    import org.xwiki.component.annotation.Component;
31    import org.xwiki.component.manager.ComponentManager;
32    import org.xwiki.rendering.block.Block;
33    import org.xwiki.rendering.block.QuotationBlock;
34    import org.xwiki.rendering.block.QuotationLineBlock;
35    import org.xwiki.rendering.block.VerbatimBlock;
36    import org.xwiki.rendering.macro.AbstractNoParameterMacro;
37    import org.xwiki.rendering.macro.MacroContentParser;
38    import org.xwiki.rendering.macro.MacroExecutionException;
39    import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor;
40    import org.xwiki.rendering.transformation.MacroTransformationContext;
41   
42    /**
43    * Displays passed text as inline text, with one quote per line in the content (spearated by new line characters).
44    *
45    * @version $Id: 40195ab46fd9e76982163f0c964f7fc1a5b01c45 $
46    * @since 7.3M1
47    */
48    @Component
49    @Named("quote")
50    @Singleton
 
51    public class QuoteMacro extends AbstractNoParameterMacro
52    {
53    /**
54    * The description of the macro.
55    */
56    private static final String DESCRIPTION = "Displays inline text with special quote formatting.";
57   
58    /**
59    * The description of the macro content.
60    */
61    private static final String CONTENT_DESCRIPTION = "Content to quote";
62   
63    /**
64    * Used to parse the macro content.
65    */
66    @Inject
67    private MacroContentParser macroContentParser;
68    /**
69    * Used to find the Parser corresponding to the user-specified syntax for the Macro.
70    */
71    @Inject
72    private ComponentManager componentManager;
73   
74   
75    /**
76    * Create and initialize the descriptor of the macro.
77    */
 
78  1 toggle public QuoteMacro()
79    {
80  1 super("Quote", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION));
81  1 setDefaultCategory(DEFAULT_CATEGORY_FORMATTING);
82    }
83   
 
84  0 toggle @Override
85    public boolean supportsInlineMode()
86    {
87  0 return false;
88    }
89   
 
90  1 toggle @Override
91    public List<Block> execute(Object parameters, String content, MacroTransformationContext context)
92    throws MacroExecutionException
93    {
94  1 List<Block> quoteBlocks = new ArrayList<>();
95  1 for (String line : content.split("\\r?\\n")) {
96  3 List<Block> lineContentBlocks = Collections.<Block>singletonList(new VerbatimBlock(line, true));
97  3 quoteBlocks.add(new QuotationLineBlock(lineContentBlocks));
98    }
99  1 return Collections.<Block>singletonList(new QuotationBlock(quoteBlocks));
100    }
101    }