Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
9   121   6   1.5
0   37   0.67   6
6     1  
1    
 
  MacroBlock       Line # 36 9 0% 6 0 100% 1.0
 
  (220)
 
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;
21   
22    import java.util.Map;
23   
24    import org.xwiki.rendering.listener.Listener;
25   
26    /**
27    * Represents a Macro (standalone or inline) defined in a page.
28    * <p>
29    * Note: You can get macro parameters using {@link #getParameters()} for example. Macro block is reusing Block standard
30    * custom parameters API since macro by definition already have parameters and don't need also block parameters. So in
31    * this case MacroBlock parameters and Block parameters are the same thing.
32    *
33    * @version $Id$
34    * @since 1.8M2
35    */
 
36    public class MacroBlock extends AbstractBlock
37    {
38    /**
39    * @see #getId
40    */
41    private String id;
42   
43    /**
44    * The macro content for macro that have content. Otherwise it's null.
45    */
46    private String content;
47   
48    /**
49    * The macro is located in a inline content (like paragraph, etc.).
50    */
51    private boolean isInline;
52   
53    /**
54    * @param id the id of the macro
55    * @param parameters the parameters of the macro
56    * @param isInline indicate if the macro is located in a inline content (like paragraph, etc.)
57    */
 
58  1010 toggle public MacroBlock(String id, Map<String, String> parameters, boolean isInline)
59    {
60  1010 this(id, parameters, null, isInline);
61    }
62   
63    /**
64    * @param id the id of the macro
65    * @param parameters the parameters of the macro
66    * @param content the content of the macro. Null if the macro does not have content
67    * @param isInline indicate if the macro is located in a inline content (like paragraph, etc.)
68    */
 
69  1322 toggle public MacroBlock(String id, Map<String, String> parameters, String content, boolean isInline)
70    {
71  1322 super(parameters);
72   
73  1322 this.id = id;
74  1322 this.content = content;
75  1322 this.isInline = isInline;
76    }
77   
78    /**
79    * @return the macro id (eg "toc" for the TOC Macro).
80    * @since 2.0M3
81    */
 
82  2551 toggle public String getId()
83    {
84  2551 return this.id;
85    }
86   
87    /**
88    * @return the macro content.
89    */
 
90  2467 toggle public String getContent()
91    {
92  2467 return this.content;
93    }
94   
95    /**
96    * @return if true the macro is located in a inline content (like paragraph, etc.).
97    */
 
98  2512 toggle public boolean isInline()
99    {
100  2512 return this.isInline;
101    }
102   
 
103  176 toggle @Override
104    public void traverse(Listener listener)
105    {
106    // Don't do anything here since we want the Macro Transformer component to take in charge
107    // Macro execution. This is because Macro execution is a complex process that involves:
108    // * computing the order in which the macros should be evaluated. For example the TOC macro
109    // should evaluate last since other macros can contribute headers/sections blocks.
110    // * some macros need to modify blocks in the XDOM object
111    // * macro execution is a multi-pass process
112    // In essence the Macro Transformer will replace all MacroBlock blocks with other Blocks
113    // generated from the execution of the Macros when XDOM.traverse() is called there
114    // won't be any MacroBlock.traverse() method called at all.
115   
116    // Note: We're calling the event to let other listener downstream decide what to do with it.
117    // In practice as described above this method will never get called when the whole rendering
118    // process is executed. This does get called during our unit tests though.
119  176 listener.onMacro(getId(), getParameters(), getContent(), isInline());
120    }
121    }