com.liferay.wiki.engine.impl.WikiEngineRenderer Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.wiki.engine.impl;
import com.liferay.portal.kernel.diff.DiffHtmlUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.io.unsync.UnsyncStringReader;
import com.liferay.portal.kernel.io.unsync.UnsyncStringWriter;
import com.liferay.portal.kernel.portlet.LiferayPortletURL;
import com.liferay.portal.kernel.portlet.PortletURLUtil;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.kernel.util.HttpUtil;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.taglib.servlet.PipingServletResponse;
import com.liferay.wiki.engine.WikiEngine;
import com.liferay.wiki.exception.PageContentException;
import com.liferay.wiki.exception.WikiFormatException;
import com.liferay.wiki.model.WikiNode;
import com.liferay.wiki.model.WikiPage;
import com.liferay.wiki.model.WikiPageDisplay;
import com.liferay.wiki.util.WikiCacheHelper;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Brian Wing Shun Chan
* @author Jorge Ferrer
*/
@Component(immediate = true, service = WikiEngineRenderer.class)
public class WikiEngineRenderer {
public String convert(
WikiPage page, PortletURL viewPageURL, PortletURL editPageURL,
String attachmentURLPrefix)
throws PageContentException, WikiFormatException {
LiferayPortletURL liferayViewPageURL = (LiferayPortletURL)viewPageURL;
LiferayPortletURL liferayEditPageURL = (LiferayPortletURL)editPageURL;
WikiEngine wikiEngine = fetchWikiEngine(page.getFormat());
if (wikiEngine == null) {
throw new WikiFormatException();
}
String content = wikiEngine.convert(
page, viewPageURL, editPageURL, attachmentURLPrefix);
String editPageURLString = StringPool.BLANK;
if (editPageURL != null) {
liferayEditPageURL.setParameter("title", "__REPLACEMENT__", false);
editPageURLString = editPageURL.toString();
editPageURLString = StringUtil.replace(
editPageURLString, "__REPLACEMENT__", "$1");
}
Matcher matcher = _editPageURLPattern.matcher(content);
content = _convertURLs(editPageURLString, matcher);
String viewPageURLString = StringPool.BLANK;
if (viewPageURL != null) {
liferayViewPageURL.setParameter("title", "__REPLACEMENT__", false);
viewPageURLString = viewPageURL.toString();
viewPageURLString = StringUtil.replace(
viewPageURLString, "__REPLACEMENT__", "$1");
}
matcher = _viewPageURLPattern.matcher(content);
content = _convertURLs(viewPageURLString, matcher);
content = _replaceAttachments(
content, page.getTitle(), attachmentURLPrefix);
return content;
}
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);
}
if (targetPage != null) {
targetContent = convert(
targetPage, viewPageURL, editPageURL, attachmentURLPrefix);
}
return DiffHtmlUtil.diff(
new UnsyncStringReader(sourceContent),
new UnsyncStringReader(targetContent));
}
public WikiEngine fetchWikiEngine(String format) {
return _wikiEngineTracker.getWikiEngine(format);
}
public List filterOrphans(List pages)
throws PortalException {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy