001 /** 002 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved. 003 * 004 * The contents of this file are subject to the terms of the Liferay Enterprise 005 * Subscription License ("License"). You may not use this file except in 006 * compliance with the License. You can obtain a copy of the License by 007 * contacting Liferay, Inc. See the License for the specific language governing 008 * permissions and limitations under the License, including but not limited to 009 * distribution rights of the Software. 010 * 011 * 012 * 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 }