001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Antoine Taillefer
018 */
019package org.nuxeo.ecm.diff.model.impl;
020
021import java.io.Serializable;
022
023import org.nuxeo.ecm.diff.model.ContentDiffDisplay;
024import org.nuxeo.ecm.diff.model.DifferenceType;
025
026/**
027 * Default implementation of {@link ContentDiffDisplay}.
028 *
029 * @author <a href="mailto:ataillefer@nuxeo.com">Antoine Taillefer</a>
030 * @since 5.6
031 */
032public class ContentDiffDisplayImpl extends PropertyDiffDisplayImpl implements ContentDiffDisplay {
033
034    private static final long serialVersionUID = -3187677365094933738L;
035
036    protected boolean displayHtmlConversion;
037
038    protected boolean displayTextConversion;
039
040    public ContentDiffDisplayImpl(Serializable value) {
041        this(value, false, false);
042    }
043
044    public ContentDiffDisplayImpl(Serializable value, boolean displayHtmlConversion, boolean displayTextConversion) {
045        super(value);
046        this.displayHtmlConversion = displayHtmlConversion;
047        this.displayTextConversion = displayTextConversion;
048    }
049
050    public ContentDiffDisplayImpl(Serializable value, DifferenceType differenceType) {
051        this(value, differenceType, false, false);
052    }
053
054    public ContentDiffDisplayImpl(Serializable value, DifferenceType differenceType, boolean displayHtmlConversion,
055            boolean displayTextConversion) {
056        super(value, differenceType);
057        this.displayHtmlConversion = displayHtmlConversion;
058        this.displayTextConversion = displayTextConversion;
059    }
060
061    public boolean isDisplayHtmlConversion() {
062        return displayHtmlConversion;
063    }
064
065    public void setDisplayHtmlConversion(boolean displayHtmlConversion) {
066        this.displayHtmlConversion = displayHtmlConversion;
067    }
068
069    public boolean isDisplayTextConversion() {
070        return displayTextConversion;
071    }
072
073    public void setDisplayTextConversion(boolean displayTextConversion) {
074        this.displayTextConversion = displayTextConversion;
075    }
076
077    @Override
078    public boolean equals(Object other) {
079
080        if (!super.equals(other)) {
081            return false;
082        }
083        if (this == other) {
084            return true;
085        }
086        if (other == null || !(other instanceof ContentDiffDisplay)) {
087            return false;
088        }
089
090        boolean otherDisplayHtmlConversion = ((ContentDiffDisplay) other).isDisplayHtmlConversion();
091        boolean otherDisplayTextConversion = ((ContentDiffDisplay) other).isDisplayTextConversion();
092        return displayHtmlConversion == otherDisplayHtmlConversion
093                && displayTextConversion == otherDisplayTextConversion;
094    }
095
096    @Override
097    public String toString() {
098        StringBuilder sb = new StringBuilder();
099        sb.append(super.toString());
100        sb.append(" / ");
101        sb.append(displayHtmlConversion);
102        sb.append(" / ");
103        sb.append(displayTextConversion);
104        return sb.toString();
105    }
106}