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

File ImageBlock.java

 

Coverage histogram

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

Code metrics

4
23
8
1
142
65
11
0.48
2.88
8
1.38

Classes

Class Line # Actions
ImageBlock 36 23 0% 11 19
0.4571428645.7%
 

Contributing tests

This file is covered by 129 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.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    import org.xwiki.rendering.listener.reference.ResourceReference;
29   
30    /**
31    * Represents an image.
32    *
33    * @version $Id: 8343690a62eac95d4121cbf4db49baf19bc1b1f5 $
34    * @since 1.7M2
35    */
 
36    public class ImageBlock extends AbstractBlock
37    {
38    /**
39    * A reference to the image target. See {@link org.xwiki.rendering.listener.reference.ResourceReference} for more
40    * details.
41    */
42    private ResourceReference reference;
43   
44    /**
45    * If true then the image is defined as a free standing URI directly in the text.
46    */
47    private boolean freestanding;
48   
49    /**
50    * @param reference the image reference
51    * @param freestanding indicate if the image syntax is simple a full descriptive syntax (detail depending of the
52    * syntax)
53    * @since 2.5RC1
54    */
 
55  613 toggle public ImageBlock(ResourceReference reference, boolean freestanding)
56    {
57  613 this(reference, freestanding, Collections.<String, String>emptyMap());
58    }
59   
60    /**
61    * @param reference the image reference
62    * @param freestanding indicate if the image syntax is simple a full descriptive syntax (detail depending of the
63    * syntax)
64    * @param parameters the custom parameters
65    * @since 2.5RC1
66    */
 
67  1157 toggle public ImageBlock(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
68    {
69  1157 super(parameters);
70   
71  1157 this.reference = reference;
72  1157 this.freestanding = freestanding;
73    }
74   
75    /**
76    * @return the reference to the image
77    * @see org.xwiki.rendering.listener.reference.ResourceReference
78    * @since 2.5RC1
79    */
 
80  628 toggle public ResourceReference getReference()
81    {
82  628 return this.reference;
83    }
84   
85    /**
86    * @return true if the image is defined as a free standing URI directly in the text, false otherwise
87    */
 
88  598 toggle public boolean isFreeStandingURI()
89    {
90  598 return this.freestanding;
91    }
92   
 
93  598 toggle @Override
94    public void traverse(Listener listener)
95    {
96  598 listener.onImage(getReference(), isFreeStandingURI(), getParameters());
97    }
98   
99    /**
100    * {@inheritDoc}
101    *
102    * @since 1.8RC2
103    */
 
104  26 toggle @Override
105    public ImageBlock clone(BlockFilter blockFilter)
106    {
107  26 ImageBlock clone = (ImageBlock) super.clone(blockFilter);
108  26 clone.reference = getReference().clone();
109  26 return clone;
110    }
111   
 
112  0 toggle @Override
113    public boolean equals(Object obj)
114    {
115  0 if (obj == this) {
116  0 return true;
117    }
118   
119  0 if (obj instanceof ImageBlock && super.equals(obj)) {
120  0 EqualsBuilder builder = new EqualsBuilder();
121   
122  0 builder.append(getReference(), ((ImageBlock) obj).getReference());
123  0 builder.append(isFreeStandingURI(), ((ImageBlock) obj).isFreeStandingURI());
124   
125  0 return builder.isEquals();
126    }
127   
128  0 return false;
129    }
130   
 
131  0 toggle @Override
132    public int hashCode()
133    {
134  0 HashCodeBuilder builder = new HashCodeBuilder();
135   
136  0 builder.appendSuper(super.hashCode());
137  0 builder.append(getReference());
138  0 builder.append(isFreeStandingURI());
139   
140  0 return builder.toHashCode();
141    }
142    }