001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    
019    import java.io.Reader;
020    
021    import java.util.List;
022    
023    /**
024     * <p>
025     * This class can compare two different versions of a text. Source refers to the
026     * earliest version of the text and target refers to a modified version of
027     * source. Changes are considered either as a removal from the source or as an
028     * addition to the target. This class detects changes to an entire line and also
029     * detects changes within lines, such as, removal or addition of characters.
030     * Take a look at <code>DiffTest</code> to see the expected inputs and outputs.
031     * </p>
032     *
033     * @author Bruno Farache
034     * @see    com.liferay.portal.kernel.util.DiffUtil
035     */
036    public class DiffUtil {
037    
038            public static List<DiffResult>[] diff(Reader source, Reader target) {
039                    return getDiff().diff(source, target);
040            }
041    
042            public static List<DiffResult>[] diff(
043                    Reader source, Reader target, String addedMarkerStart,
044                    String addedMarkerEnd, String deletedMarkerStart,
045                    String deletedMarkerEnd, int margin) {
046    
047                    return getDiff().diff(
048                            source, target, addedMarkerStart, addedMarkerEnd,
049                            deletedMarkerStart, deletedMarkerEnd, margin);
050            }
051    
052            public static Diff getDiff() {
053                    PortalRuntimePermission.checkGetBeanProperty(DiffUtil.class);
054    
055                    return _diff;
056            }
057    
058            public void setDiff(Diff diff) {
059                    PortalRuntimePermission.checkSetBeanProperty(getClass());
060    
061                    _diff = diff;
062            }
063    
064            private static Diff _diff;
065    
066    }