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

File FootnoteMacro.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

2
11
4
1
103
54
5
0.45
2.75
4
1.25

Classes

Class Line # Actions
FootnoteMacro 48 11 0% 5 4
0.764705976.5%
 

Contributing tests

This file is covered by 2 tests. .

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.footnote;
21   
22    import java.util.Collections;
23    import java.util.List;
24   
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.rendering.block.Block;
30    import org.xwiki.rendering.block.MacroBlock;
31    import org.xwiki.rendering.block.match.MacroBlockMatcher;
32    import org.xwiki.rendering.macro.AbstractMacro;
33    import org.xwiki.rendering.macro.MacroExecutionException;
34    import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor;
35    import org.xwiki.rendering.macro.footnote.FootnoteMacroParameters;
36    import org.xwiki.rendering.transformation.MacroTransformationContext;
37   
38    /**
39    * Generate footnotes, listed at the end of the page. A reference to the generated footnote is inserted at the location
40    * where the macro is called.
41    *
42    * @version $Id: 2dea758f90c050d749d69094c389e93b87fa376d $
43    * @since 2.0M2
44    */
45    @Component
46    @Named(FootnoteMacro.MACRO_NAME)
47    @Singleton
 
48    public class FootnoteMacro extends AbstractMacro<FootnoteMacroParameters>
49    {
50    /** The name of this macro. */
51    public static final String MACRO_NAME = "footnote";
52   
53    /** The description of the macro. */
54    private static final String DESCRIPTION = "Generates a footnote to display at the end of the page.";
55   
56    /** The description of the macro content. */
57    private static final String CONTENT_DESCRIPTION = "the text to place in the footnote";
58   
59    /**
60    * Matches MacroBlocks having a macro id of {@link PutFootnotesMacro#MACRO_NAME}.
61    */
62    private static final MacroBlockMatcher MACRO_BLOCK_MATCHER = new MacroBlockMatcher(PutFootnotesMacro.MACRO_NAME);
63   
64    /**
65    * Create and initialize the descriptor of the macro.
66    */
 
67  2 toggle public FootnoteMacro()
68    {
69  2 super("Footnote", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION),
70    FootnoteMacroParameters.class);
71  2 setDefaultCategory(DEFAULT_CATEGORY_CONTENT);
72    }
73   
 
74  2 toggle @Override
75    public boolean supportsInlineMode()
76    {
77  2 return true;
78    }
79   
 
80  0 toggle @Override
81    public int getPriority()
82    {
83  0 return 500;
84    }
85   
 
86  2 toggle @Override
87    public List<Block> execute(FootnoteMacroParameters parameters, String content, MacroTransformationContext context)
88    throws MacroExecutionException
89    {
90  2 Block root = context.getXDOM();
91   
92  2 Block matchingBlock = root.getFirstBlock(MACRO_BLOCK_MATCHER, Block.Axes.DESCENDANT);
93  2 if (matchingBlock != null) {
94  0 return Collections.emptyList();
95    }
96   
97  2 Block putFootnotesMacro =
98    new MacroBlock(PutFootnotesMacro.MACRO_NAME, Collections.<String, String>emptyMap(), false);
99  2 root.addChild(putFootnotesMacro);
100   
101  2 return Collections.emptyList();
102    }
103    }