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

File MacroMarkerBlock.java

 

Coverage histogram

../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

4
26
10
1
161
76
13
0.5
2.6
10
1.3

Classes

Class Line # Actions
MacroMarkerBlock 37 26 0% 13 15
0.62562.5%
 

Contributing tests

This file is covered by 241 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.block;
21   
22    import java.util.List;
23    import java.util.Map;
24   
25    import org.apache.commons.lang3.builder.EqualsBuilder;
26    import org.apache.commons.lang3.builder.HashCodeBuilder;
27    import org.xwiki.rendering.listener.Listener;
28   
29    /**
30    * A special block that Macro Blocks generate when they are executed so that it's possible to reconstruct the initial
31    * syntax even after Macros have been executed. For example this is important in a WYSWIYG editor where you want to show
32    * the Macro's rendered result and also let users modify the macro content.
33    *
34    * @version $Id: 95fe564fa71f8143d0eb57a00ddb58609286782b $
35    * @since 1.5M2
36    */
 
37    public class MacroMarkerBlock extends AbstractBlock
38    {
39    /**
40    * The macro name that we are preserving.
41    */
42    private String id;
43   
44    /**
45    * The macro content that we are preserving.
46    */
47    private String content;
48   
49    /**
50    * The macro is located in a inline content (like paragraph, etc.).
51    */
52    private boolean isInline;
53   
54    /**
55    * @param id the name of the macro
56    * @param parameters the parameters of the macro
57    * @param childBlocks the list of children blocks generated by the macro
58    * @param isInline indicate if the macro is located in a inline content (like paragraph, etc.)
59    */
 
60  14 toggle public MacroMarkerBlock(String id, Map<String, String> parameters, List<Block> childBlocks, boolean isInline)
61    {
62  14 this(id, parameters, null, childBlocks, isInline);
63    }
64   
65    /**
66    * @param id the name of the macro
67    * @param parameters the parameters of the macro
68    * @param content the content of the macro. Null if the macro does not have content
69    * @param childBlocks the list of children blocks generated by the macro
70    * @param isInline indicate if the macro is located in a inline content (like paragraph, etc.)
71    */
 
72  17792 toggle public MacroMarkerBlock(String id, Map<String, String> parameters, String content, List<Block> childBlocks,
73    boolean isInline)
74    {
75  17792 super(childBlocks, parameters);
76   
77  17790 this.id = id;
78  17792 this.content = content;
79  17791 this.isInline = isInline;
80    }
81   
82    /**
83    * @return the macro name.
84    * @deprecated since 2.4M1 use {@link #getId()} instead
85    */
 
86  0 toggle @Deprecated
87    public String getName()
88    {
89  0 return getId();
90    }
91   
92    /**
93    * @return the macro identifier.
94    * @since 2.4M1
95    */
 
96  52793 toggle public String getId()
97    {
98  52793 return this.id;
99    }
100   
101    /**
102    * @return the macro content.
103    */
 
104  34867 toggle public String getContent()
105    {
106  34866 return this.content;
107    }
108   
109    /**
110    * @return if true the macro is located in a inline content (like paragraph, etc.).
111    */
 
112  34862 toggle public boolean isInline()
113    {
114  34862 return this.isInline;
115    }
116   
 
117  17431 toggle @Override
118    public void before(Listener listener)
119    {
120  17430 listener.beginMacroMarker(getId(), getParameters(), getContent(), isInline());
121    }
122   
 
123  17431 toggle @Override
124    public void after(Listener listener)
125    {
126  17431 listener.endMacroMarker(getId(), getParameters(), getContent(), isInline());
127    }
128   
 
129  2 toggle @Override
130    public boolean equals(Object obj)
131    {
132  2 if (obj == this) {
133  1 return true;
134    }
135   
136  1 if (obj instanceof MacroMarkerBlock && super.equals(obj)) {
137  0 EqualsBuilder builder = new EqualsBuilder();
138   
139  0 builder.append(getContent(), ((MacroMarkerBlock) obj).getContent());
140  0 builder.append(getId(), ((MacroMarkerBlock) obj).getId());
141  0 builder.append(isInline(), ((MacroMarkerBlock) obj).isInline());
142   
143  0 return builder.isEquals();
144    }
145   
146  1 return false;
147    }
148   
 
149  0 toggle @Override
150    public int hashCode()
151    {
152  0 HashCodeBuilder builder = new HashCodeBuilder();
153   
154  0 builder.appendSuper(super.hashCode());
155  0 builder.append(getContent());
156  0 builder.append(getId());
157  0 builder.append(isInline());
158   
159  0 return builder.toHashCode();
160    }
161    }