001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Antoine Taillefer
016 */
017package org.nuxeo.ecm.diff.model.impl;
018
019import java.io.Serializable;
020
021import org.nuxeo.ecm.diff.model.ContentDiffDisplay;
022import org.nuxeo.ecm.diff.model.DifferenceType;
023
024/**
025 * Default implementation of {@link ContentDiffDisplay}.
026 *
027 * @author <a href="mailto:ataillefer@nuxeo.com">Antoine Taillefer</a>
028 * @since 5.6
029 */
030public class ContentDiffDisplayImpl extends PropertyDiffDisplayImpl implements ContentDiffDisplay {
031
032    private static final long serialVersionUID = -3187677365094933738L;
033
034    protected boolean displayHtmlConversion;
035
036    protected boolean displayTextConversion;
037
038    public ContentDiffDisplayImpl(Serializable value) {
039        this(value, false, false);
040    }
041
042    public ContentDiffDisplayImpl(Serializable value, boolean displayHtmlConversion, boolean displayTextConversion) {
043        super(value);
044        this.displayHtmlConversion = displayHtmlConversion;
045        this.displayTextConversion = displayTextConversion;
046    }
047
048    public ContentDiffDisplayImpl(Serializable value, DifferenceType differenceType) {
049        this(value, differenceType, false, false);
050    }
051
052    public ContentDiffDisplayImpl(Serializable value, DifferenceType differenceType, boolean displayHtmlConversion,
053            boolean displayTextConversion) {
054        super(value, differenceType);
055        this.displayHtmlConversion = displayHtmlConversion;
056        this.displayTextConversion = displayTextConversion;
057    }
058
059    public boolean isDisplayHtmlConversion() {
060        return displayHtmlConversion;
061    }
062
063    public void setDisplayHtmlConversion(boolean displayHtmlConversion) {
064        this.displayHtmlConversion = displayHtmlConversion;
065    }
066
067    public boolean isDisplayTextConversion() {
068        return displayTextConversion;
069    }
070
071    public void setDisplayTextConversion(boolean displayTextConversion) {
072        this.displayTextConversion = displayTextConversion;
073    }
074
075    @Override
076    public boolean equals(Object other) {
077
078        if (!super.equals(other)) {
079            return false;
080        }
081        if (this == other) {
082            return true;
083        }
084        if (other == null || !(other instanceof ContentDiffDisplay)) {
085            return false;
086        }
087
088        boolean otherDisplayHtmlConversion = ((ContentDiffDisplay) other).isDisplayHtmlConversion();
089        boolean otherDisplayTextConversion = ((ContentDiffDisplay) other).isDisplayTextConversion();
090        return displayHtmlConversion == otherDisplayHtmlConversion
091                && displayTextConversion == otherDisplayTextConversion;
092    }
093
094    @Override
095    public String toString() {
096        StringBuilder sb = new StringBuilder();
097        sb.append(super.toString());
098        sb.append(" / ");
099        sb.append(displayHtmlConversion);
100        sb.append(" / ");
101        sb.append(displayTextConversion);
102        return sb.toString();
103    }
104}