List of usage examples for com.liferay.portal.kernel.diff DiffHtmlUtil diff
public static String diff(Reader source, Reader target) throws Exception
From source file:com.liferay.journal.util.impl.JournalUtil.java
License:Open Source License
public static String diffHtml(long groupId, String articleId, double sourceVersion, double targetVersion, String languageId, PortletRequestModel portletRequestModel, ThemeDisplay themeDisplay) throws Exception { JournalArticle sourceArticle = JournalArticleLocalServiceUtil.getArticle(groupId, articleId, sourceVersion); if (!JournalArticleLocalServiceUtil.isRenderable(sourceArticle, portletRequestModel, themeDisplay)) { throw new CompareVersionsException(sourceVersion); }//from w ww . ja v a2 s . c om JournalArticleDisplay sourceArticleDisplay = JournalArticleLocalServiceUtil.getArticleDisplay(sourceArticle, null, Constants.VIEW, languageId, 1, portletRequestModel, themeDisplay); JournalArticle targetArticle = JournalArticleLocalServiceUtil.getArticle(groupId, articleId, targetVersion); if (!JournalArticleLocalServiceUtil.isRenderable(targetArticle, portletRequestModel, themeDisplay)) { throw new CompareVersionsException(targetVersion); } JournalArticleDisplay targetArticleDisplay = JournalArticleLocalServiceUtil.getArticleDisplay(targetArticle, null, Constants.VIEW, languageId, 1, portletRequestModel, themeDisplay); return DiffHtmlUtil.diff(new UnsyncStringReader(sourceArticleDisplay.getContent()), new UnsyncStringReader(targetArticleDisplay.getContent())); }
From source file:com.liferay.knowledgebase.admin.util.AdminUtil.java
License:Open Source License
public static String getKBArticleDiff(long resourcePrimKey, int sourceVersion, int targetVersion, String param) throws Exception { if (sourceVersion < KBArticleConstants.DEFAULT_VERSION) { sourceVersion = KBArticleConstants.DEFAULT_VERSION; }/*from www .j a v a 2 s .co m*/ if (sourceVersion == targetVersion) { KBArticle kbArticle = KBArticleLocalServiceUtil.getKBArticle(resourcePrimKey, targetVersion); return BeanPropertiesUtil.getString(kbArticle, param); } KBArticle sourceKBArticle = KBArticleLocalServiceUtil.getKBArticle(resourcePrimKey, sourceVersion); KBArticle targetKBArticle = KBArticleLocalServiceUtil.getKBArticle(resourcePrimKey, targetVersion); String sourceHtml = BeanPropertiesUtil.getString(sourceKBArticle, param); String targetHtml = BeanPropertiesUtil.getString(targetKBArticle, param); String diff = DiffHtmlUtil.diff(new UnsyncStringReader(sourceHtml), new UnsyncStringReader(targetHtml)); Source source = new Source(diff); OutputDocument outputDocument = new OutputDocument(source); for (Element element : source.getAllElements()) { StringBundler sb = new StringBundler(4); Attributes attributes = element.getAttributes(); if (attributes == null) { continue; } Attribute changeTypeAttribute = attributes.get("changeType"); if (changeTypeAttribute != null) { String changeTypeValue = changeTypeAttribute.getValue(); if (changeTypeValue.contains("diff-added-image")) { sb.append("border: 10px solid #CFC; "); } else if (changeTypeValue.contains("diff-changed-image")) { sb.append("border: 10px solid #C6C6FD; "); } else if (changeTypeValue.contains("diff-removed-image")) { sb.append("border: 10px solid #FDC6C6; "); } } Attribute classAttribute = attributes.get("class"); if (classAttribute != null) { String classValue = classAttribute.getValue(); if (classValue.contains("diff-html-added")) { sb.append("background-color: #CFC; "); } else if (classValue.contains("diff-html-changed")) { sb.append("background-color: #C6C6FD; "); } else if (classValue.contains("diff-html-removed")) { sb.append("background-color: #FDC6C6; "); sb.append("text-decoration: line-through; "); } } if (Validator.isNull(sb.toString())) { continue; } Attribute styleAttribute = attributes.get("style"); if (styleAttribute != null) { sb.append(GetterUtil.getString(styleAttribute.getValue())); } Map<String, String> map = outputDocument.replace(attributes, false); map.put("style", sb.toString()); } return outputDocument.toString(); }
From source file:com.liferay.wiki.engine.impl.WikiEngineRenderer.java
License:Open Source License
public String diffHtml(WikiPage sourcePage, WikiPage targetPage, PortletURL viewPageURL, PortletURL editPageURL, String attachmentURLPrefix) throws Exception { String sourceContent = StringPool.BLANK; String targetContent = StringPool.BLANK; if (sourcePage != null) { sourceContent = convert(sourcePage, viewPageURL, editPageURL, attachmentURLPrefix); }// w ww .j av a2s. co m if (targetPage != null) { targetContent = convert(targetPage, viewPageURL, editPageURL, attachmentURLPrefix); } return DiffHtmlUtil.diff(new UnsyncStringReader(sourceContent), new UnsyncStringReader(targetContent)); }