Fixing Liferay 6.0.6 Diff Plugin

written by Marco Ferretti on October 15, 2012, at 01:52 PM

Since Liferay 5 there is a very neat diff plugin that works out of the box in the document library. The plugin permits to compare text files but, provided you have activated the Open Office Integration you can compare other kind of files like .doc, .docx and odt. Unfortunately there's a bug in Liferay 6.0.6 that prevents this from working.

The bug

The bug consists in a "wrong" call in the document library portlet's compare document action : the name in the request is actually the document's id and trying to get the extension of the document results in an empty string .

The solution

The solution is quite simple ... provided you can recompile portal-impl.jar :

in com.liferay.portlet.documentlibrary.action.CompareVersionsAction change

protected void compareVersions(RenderRequest renderRequest)

by adding

String title = ParamUtil.getString(renderRequest, "title");

and changing

String extension = FileUtil.getExtension(name)


String extension = FileUtil.getExtension(title);

so that the method will look like :

	protected void compareVersions(RenderRequest renderRequest)
		throws Exception {

		ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(

		long companyId = themeDisplay.getCompanyId();
		long userId = themeDisplay.getUserId();

		long fileEntryId = ParamUtil.getLong(renderRequest, "fileEntryId");

		long groupId = themeDisplay.getScopeGroupId();
		long folderId = ParamUtil.getLong(renderRequest, "folderId");
		String name = ParamUtil.getString(renderRequest, "name");
		String title = ParamUtil.getString(renderRequest, "title");
			themeDisplay.getPermissionChecker(), groupId, folderId, name,

		String extension = FileUtil.getExtension(title);

		String titleWithExtension = ParamUtil.getString(
			renderRequest, "titleWithExtension");

		String sourceVersion = ParamUtil.getString(
			renderRequest, "sourceVersion");
		String targetVersion = ParamUtil.getString(
			renderRequest, "targetVersion");

		InputStream sourceIs = DLFileEntryLocalServiceUtil.getFileAsStream(
			companyId, userId, groupId, folderId, name, sourceVersion);
		InputStream targetIs = DLFileEntryLocalServiceUtil.getFileAsStream(
			companyId, userId, groupId, folderId, name, targetVersion);

		if (extension.equals("htm") || extension.equals("html") ||
			extension.equals("xml")) {

			String escapedSource = HtmlUtil.escape(;
			String escapedTarget = HtmlUtil.escape(;

			sourceIs = new UnsyncByteArrayInputStream(
			targetIs = new UnsyncByteArrayInputStream(

		if (PrefsPropsUtil.getBoolean(
			isConvertBeforeCompare(extension)) {

			String sourceTempFileId = DocumentConversionUtil.getTempFileId(
				fileEntryId, sourceVersion);
			String targetTempFileId = DocumentConversionUtil.getTempFileId(
				fileEntryId, targetVersion);

			sourceIs = DocumentConversionUtil.convert(
				sourceTempFileId, sourceIs, extension, "txt");
			targetIs = DocumentConversionUtil.convert(
				targetTempFileId, targetIs, extension, "txt");

		List<DiffResult>[] diffResults = DiffUtil.diff(
			new InputStreamReader(sourceIs), new InputStreamReader(targetIs));

			titleWithExtension + StringPool.SPACE + sourceVersion);
			titleWithExtension + StringPool.SPACE + targetVersion);
		renderRequest.setAttribute(WebKeys.DIFF_RESULTS, diffResults);

Alternatively, and if you trust me, you can download a patched Attach:portal-impl.jar from this site. The md5sum f223ae66e1bfb93fb0658e215507e6f5 portal-impl.jar

Hope it helps !

Leave a comment

Name (required)
E-mail (required, will not be published)

Enter value: Captcha