1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.block

File LinkBlock.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
76% of files have more coverage

Code metrics

4
24
9
1
149
72
12
0.5
2.67
9
1.33

Classes

Class Line # Actions
LinkBlock 37 24 0% 12 19
0.486486548.6%
 

Contributing tests

This file is covered by 266 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.Collections;
23    import java.util.List;
24    import java.util.Map;
25   
26    import org.apache.commons.lang3.builder.EqualsBuilder;
27    import org.apache.commons.lang3.builder.HashCodeBuilder;
28    import org.xwiki.rendering.listener.Listener;
29    import org.xwiki.rendering.listener.reference.ResourceReference;
30   
31    /**
32    * Represents a Link element in a page.
33    *
34    * @version $Id: 3c8452834a64287bbbd0a2b1ee08f1256403f033 $
35    * @since 1.5M2
36    */
 
37    public class LinkBlock extends AbstractBlock
38    {
39    /**
40    * A reference to the link target. See {@link org.xwiki.rendering.listener.reference.ResourceReference} for more
41    * details.
42    */
43    private ResourceReference reference;
44   
45    /**
46    * If true then the link is a free standing URI directly in the text.
47    */
48    private boolean freestanding;
49   
50    /**
51    * @param childrenBlocks the nested children blocks
52    * @param reference the reference to the target resource to link to
53    * @param freestanding if true then the link is a free standing URI directly in the text
54    * @since 2.5RC1
55    */
 
56  3805 toggle public LinkBlock(List<Block> childrenBlocks, ResourceReference reference, boolean freestanding)
57    {
58  3805 this(childrenBlocks, reference, freestanding, Collections.<String, String>emptyMap());
59    }
60   
61    /**
62    * @param childrenBlocks the nested children blocks
63    * @param reference the reference to the target resource to link to
64    * @param freestanding if true then the link is a free standing URI directly in the text
65    * @param parameters the parameters to set
66    * @since 2.5RC1
67    */
 
68  29379 toggle public LinkBlock(List<Block> childrenBlocks, ResourceReference reference, boolean freestanding,
69    Map<String, String> parameters)
70    {
71  29374 super(childrenBlocks, parameters);
72  29379 this.reference = reference;
73  29380 this.freestanding = freestanding;
74    }
75   
76    /**
77    * @return the reference to the target to link to
78    * @see org.xwiki.rendering.listener.reference.ResourceReference
79    * @since 2.5RC1
80    */
 
81  317320 toggle public ResourceReference getReference()
82    {
83  317338 return this.reference;
84    }
85   
86    /**
87    * @return true if the link is a free standing URI directly in the text, false otherwise
88    */
 
89  115949 toggle public boolean isFreeStandingURI()
90    {
91  115959 return this.freestanding;
92    }
93   
 
94  57977 toggle @Override
95    public void before(Listener listener)
96    {
97  57978 listener.beginLink(getReference(), isFreeStandingURI(), getParameters());
98    }
99   
 
100  57975 toggle @Override
101    public void after(Listener listener)
102    {
103  57978 listener.endLink(getReference(), isFreeStandingURI(), getParameters());
104    }
105   
106    /**
107    * {@inheritDoc}
108    *
109    * @since 1.8RC2
110    */
 
111  199727 toggle @Override
112    public LinkBlock clone(BlockFilter blockFilter)
113    {
114  199736 LinkBlock clone = (LinkBlock) super.clone(blockFilter);
115  199736 clone.reference = getReference().clone();
116  199730 return clone;
117    }
118   
 
119  0 toggle @Override
120    public boolean equals(Object obj)
121    {
122  0 if (obj == this) {
123  0 return true;
124    }
125   
126  0 if (obj instanceof LinkBlock && super.equals(obj)) {
127  0 EqualsBuilder builder = new EqualsBuilder();
128   
129  0 builder.append(getReference(), ((LinkBlock) obj).getReference());
130  0 builder.append(isFreeStandingURI(), ((LinkBlock) obj).isFreeStandingURI());
131   
132  0 return builder.isEquals();
133    }
134   
135  0 return false;
136    }
137   
 
138  0 toggle @Override
139    public int hashCode()
140    {
141  0 HashCodeBuilder builder = new HashCodeBuilder();
142   
143  0 builder.appendSuper(super.hashCode());
144  0 builder.append(getReference());
145  0 builder.append(isFreeStandingURI());
146   
147  0 return builder.toHashCode();
148    }
149    }