Java tutorial
/* * See the NOTICE file distributed with this work for additional * information regarding copyright ownership. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.xwiki.rendering.block; import java.util.Collections; import java.util.Map; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.xwiki.rendering.listener.Listener; import org.xwiki.rendering.listener.reference.ResourceReference; /** * Represents an image. * * @version $Id: 8343690a62eac95d4121cbf4db49baf19bc1b1f5 $ * @since 1.7M2 */ public class ImageBlock extends AbstractBlock { /** * A reference to the image target. See {@link org.xwiki.rendering.listener.reference.ResourceReference} for more * details. */ private ResourceReference reference; /** * If true then the image is defined as a free standing URI directly in the text. */ private boolean freestanding; /** * @param reference the image reference * @param freestanding indicate if the image syntax is simple a full descriptive syntax (detail depending of the * syntax) * @since 2.5RC1 */ public ImageBlock(ResourceReference reference, boolean freestanding) { this(reference, freestanding, Collections.<String, String>emptyMap()); } /** * @param reference the image reference * @param freestanding indicate if the image syntax is simple a full descriptive syntax (detail depending of the * syntax) * @param parameters the custom parameters * @since 2.5RC1 */ public ImageBlock(ResourceReference reference, boolean freestanding, Map<String, String> parameters) { super(parameters); this.reference = reference; this.freestanding = freestanding; } /** * @return the reference to the image * @see org.xwiki.rendering.listener.reference.ResourceReference * @since 2.5RC1 */ public ResourceReference getReference() { return this.reference; } /** * @return true if the image is defined as a free standing URI directly in the text, false otherwise */ public boolean isFreeStandingURI() { return this.freestanding; } @Override public void traverse(Listener listener) { listener.onImage(getReference(), isFreeStandingURI(), getParameters()); } /** * {@inheritDoc} * * @since 1.8RC2 */ @Override public ImageBlock clone(BlockFilter blockFilter) { ImageBlock clone = (ImageBlock) super.clone(blockFilter); clone.reference = getReference().clone(); return clone; } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof ImageBlock && super.equals(obj)) { EqualsBuilder builder = new EqualsBuilder(); builder.append(getReference(), ((ImageBlock) obj).getReference()); builder.append(isFreeStandingURI(), ((ImageBlock) obj).isFreeStandingURI()); return builder.isEquals(); } return false; } @Override public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder(); builder.appendSuper(super.hashCode()); builder.append(getReference()); builder.append(isFreeStandingURI()); return builder.toHashCode(); } }