You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2020/01/16 23:07:41 UTC
[jspwiki] 21/26: JSPWIKI-120: moved getHTML methods from WikiEngine
to PageManager
This is an automated email from the ASF dual-hosted git repository.
juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit cc800371717f37236f5a54a8909f030f9c932924
Author: juanpablo <ju...@apache.org>
AuthorDate: Thu Jan 16 00:46:47 2020 +0100
JSPWIKI-120: moved getHTML methods from WikiEngine to PageManager
---
.../src/main/java/org/apache/wiki/WikiEngine.java | 46 +---
.../apache/wiki/auth/acl/DefaultAclManager.java | 2 +-
.../java/org/apache/wiki/plugin/WeblogPlugin.java | 274 +++++++--------------
.../wiki/render/DefaultRenderingManager.java | 25 ++
.../org/apache/wiki/render/RenderingManager.java | 31 +++
.../java/org/apache/wiki/rss/RSSGenerator.java | 2 +-
.../java/org/apache/wiki/tags/InsertPageTag.java | 2 +-
.../org/apache/wiki/xmlrpc/MetaWeblogHandler.java | 86 +++----
.../java/org/apache/wiki/xmlrpc/RPCHandler.java | 4 +-
.../org/apache/wiki/xmlrpc/RPCHandlerUTF8.java | 4 +-
.../src/test/java/org/apache/wiki/TestEngine.java | 2 +-
.../test/java/org/apache/wiki/WikiEngineTest.java | 13 +-
.../apache/wiki/pages/DefaultPageManagerTest.java | 4 +-
.../wiki/plugin/DefaultPluginManagerTest.java | 2 +-
.../java/org/apache/wiki/plugin/GroupsTest.java | 2 +-
.../java/org/apache/wiki/plugin/IfPluginTest.java | 14 +-
.../org/apache/wiki/plugin/InsertPageTest.java | 42 ++--
.../org/apache/wiki/plugin/PageViewPluginTest.java | 36 +--
.../apache/wiki/render/RenderingManagerTest.java | 10 +
.../apache/wiki/stress/MassiveRepositoryTest.java | 2 +-
20 files changed, 245 insertions(+), 358 deletions(-)
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
index de440ae..9b522e4 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
@@ -41,7 +41,6 @@ import org.apache.wiki.event.WikiPageEvent;
import org.apache.wiki.i18n.InternationalizationManager;
import org.apache.wiki.pages.PageManager;
import org.apache.wiki.parser.MarkupParser;
-import org.apache.wiki.providers.WikiPageProvider;
import org.apache.wiki.references.ReferenceManager;
import org.apache.wiki.render.RenderingManager;
import org.apache.wiki.rss.RSSGenerator;
@@ -241,9 +240,6 @@ public class WikiEngine {
is not running inside a servlet container (i.e. when testing). */
private ServletContext m_servletContext = null;
- /** If true, all titles will be cleaned. */
- private boolean m_beautifyTitle = false;
-
/** Stores the template path. This is relative to "templates". */
private String m_templateDir;
@@ -618,7 +614,7 @@ public class WikiEngine {
final URL url = m_servletContext.getResource( viewTemplate );
exists = url != null && StringUtils.isNotEmpty( url.getFile() );
} catch( final MalformedURLException e ) {
- exists = false;
+ log.warn( "template not found with viewTemplate " + viewTemplate );
}
}
if( !exists ) {
@@ -851,7 +847,7 @@ public class WikiEngine {
*/
// FIXME: Should use servlet context as a default instead of a constant.
public String getApplicationName() {
- String appName = TextUtil.getStringProperty( m_properties, PROP_APPNAME, Release.APPNAME );
+ final String appName = TextUtil.getStringProperty( m_properties, PROP_APPNAME, Release.APPNAME );
return MarkupParser.cleanLink( appName );
}
@@ -922,44 +918,6 @@ public class WikiEngine {
}
/**
- * Returns the converted HTML of the page using a different context than the default context.
- *
- * @param context A WikiContext in which you wish to render this page in.
- * @param page WikiPage reference.
- * @return HTML-rendered version of the page.
- */
- public String getHTML( final WikiContext context, final WikiPage page ) {
- final String pagedata = getPageManager().getPureText( page.getName(), page.getVersion() );
- return m_renderingManager.textToHTML( context, pagedata );
- }
-
- /**
- * Returns the converted HTML of the page.
- *
- * @param page WikiName of the page to convert.
- * @return HTML-rendered version of the page.
- */
- public String getHTML( final String page )
- {
- return getHTML( page, WikiPageProvider.LATEST_VERSION );
- }
-
- /**
- * Returns the converted HTML of the page's specific version. The version must be a positive integer, otherwise the current
- * version is returned.
- *
- * @param pagename WikiName of the page to convert.
- * @param version Version number to fetch
- * @return HTML-rendered page text.
- */
- public String getHTML( final String pagename, final int version ) {
- final WikiPage page = getPageManager().getPage( pagename, version );
- final WikiContext context = new WikiContext( this, page );
- context.setRequestContext( WikiContext.NONE );
- return getHTML( context, page );
- }
-
- /**
* Protected method that signals that the WikiEngine will be shut down by the servlet container. It is called by
* {@link WikiServlet#destroy()}. When this method is called, it fires a "shutdown" WikiEngineEvent to all registered listeners.
*/
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/auth/acl/DefaultAclManager.java b/jspwiki-main/src/main/java/org/apache/wiki/auth/acl/DefaultAclManager.java
index d5ff97f..7b0ca22 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/auth/acl/DefaultAclManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/acl/DefaultAclManager.java
@@ -164,7 +164,7 @@ public class DefaultAclManager implements AclManager {
// Or, try parsing the page
final WikiContext ctx = new WikiContext( m_engine, page );
ctx.setVariable( WikiContext.VAR_EXECUTE_PLUGINS, Boolean.FALSE );
- m_engine.getHTML(ctx, page);
+ m_engine.getRenderingManager().getHTML(ctx, page);
if (page.getAcl() == null) {
page.setAcl( new AclImpl() );
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/WeblogPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/WeblogPlugin.java
index b62b58b..418aa9e 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/WeblogPlugin.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/WeblogPlugin.java
@@ -41,7 +41,6 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
-import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
@@ -82,10 +81,9 @@ import java.util.regex.Pattern;
// FIXME: Add "entries" param as an alternative to "days".
// FIXME: Entries arrive in wrong order.
-public class WeblogPlugin
- implements WikiPlugin, ParserStagePlugin
-{
- private static Logger log = Logger.getLogger(WeblogPlugin.class);
+public class WeblogPlugin implements WikiPlugin, ParserStagePlugin {
+
+ private static final Logger log = Logger.getLogger(WeblogPlugin.class);
private static final Pattern HEADINGPATTERN;
/** How many days are considered by default. Default value is {@value} */
@@ -115,8 +113,7 @@ public class WeblogPlugin
*/
public static final String ATTR_ISWEBLOG = "weblogplugin.isweblog";
- static
- {
+ static {
// This is a pretty ugly, brute-force regex. But it will do for now...
HEADINGPATTERN = Pattern.compile("(<h[1-4][^>]*>)(.*)(</h[1-4]>)", Pattern.CASE_INSENSITIVE);
}
@@ -129,10 +126,7 @@ public class WeblogPlugin
* @param entryNum The entry number.
* @return A formatted page name.
*/
- public static String makeEntryPage( String pageName,
- String date,
- String entryNum )
- {
+ public static String makeEntryPage( final String pageName, final String date, final String entryNum ) {
return TextUtil.replaceString(DEFAULT_PAGEFORMAT,"%p",pageName)+date+"_"+entryNum;
}
@@ -142,7 +136,7 @@ public class WeblogPlugin
* @param pageName The name of the blog.
* @return A formatted name.
*/
- public static String makeEntryPage( String pageName )
+ public static String makeEntryPage( final String pageName )
{
return TextUtil.replaceString(DEFAULT_PAGEFORMAT,"%p",pageName);
}
@@ -154,96 +148,76 @@ public class WeblogPlugin
* @param date The date.
* @return A base name for the blog entries.
*/
- public static String makeEntryPage( String pageName, String date )
- {
+ public static String makeEntryPage( final String pageName, final String date ) {
return TextUtil.replaceString(DEFAULT_PAGEFORMAT,"%p",pageName)+date;
}
/**
* {@inheritDoc}
*/
- public String execute( WikiContext context, Map<String, String> params )
- throws PluginException
- {
- Calendar startTime;
- Calendar stopTime;
+ public String execute( final WikiContext context, final Map< String, String > params ) throws PluginException {
+ final Calendar startTime;
+ final Calendar stopTime;
int numDays = DEFAULT_DAYS;
- WikiEngine engine = context.getEngine();
- AuthorizationManager mgr = engine.getAuthorizationManager();
+ final WikiEngine engine = context.getEngine();
+ final AuthorizationManager mgr = engine.getAuthorizationManager();
//
// Parse parameters.
//
- String days;
- DateFormat entryFormat;
- String startDay = null;
+ String days;
+ final DateFormat entryFormat;
+ String startDay;
boolean hasComments = false;
- int maxEntries;
- String weblogName;
+ int maxEntries;
+ String weblogName;
- if( (weblogName = params.get(PARAM_PAGE)) == null )
- {
+ if( (weblogName = params.get(PARAM_PAGE)) == null ) {
weblogName = context.getPage().getName();
}
- if( (days = context.getHttpParameter( "weblog."+PARAM_DAYS )) == null )
- {
+ if( (days = context.getHttpParameter( "weblog."+PARAM_DAYS )) == null ) {
days = params.get( PARAM_DAYS );
}
- if( ( params.get(PARAM_ENTRYFORMAT)) == null )
- {
+ if( ( params.get(PARAM_ENTRYFORMAT)) == null ) {
entryFormat = Preferences.getDateFormat( context, TimeFormat.DATETIME );
- }
- else
- {
+ } else {
entryFormat = new SimpleDateFormat( params.get(PARAM_ENTRYFORMAT) );
}
- if( days != null )
- {
- if( days.equalsIgnoreCase("all") )
- {
+ if( days != null ) {
+ if( days.equalsIgnoreCase("all") ) {
numDays = Integer.MAX_VALUE;
- }
- else
- {
+ } else {
numDays = TextUtil.parseIntParameter( days, DEFAULT_DAYS );
}
}
- if( (startDay = params.get(PARAM_STARTDATE)) == null )
- {
+ if( (startDay = params.get(PARAM_STARTDATE)) == null ) {
startDay = context.getHttpParameter( "weblog."+PARAM_STARTDATE );
}
- if( TextUtil.isPositive( params.get(PARAM_ALLOWCOMMENTS) ) )
- {
+ if( TextUtil.isPositive( params.get(PARAM_ALLOWCOMMENTS) ) ) {
hasComments = true;
}
- maxEntries = TextUtil.parseIntParameter( params.get(PARAM_MAXENTRIES),
- Integer.MAX_VALUE );
+ maxEntries = TextUtil.parseIntParameter( params.get(PARAM_MAXENTRIES), Integer.MAX_VALUE );
//
// Determine the date range which to include.
//
-
startTime = Calendar.getInstance();
stopTime = Calendar.getInstance();
- if( startDay != null )
- {
- SimpleDateFormat fmt = new SimpleDateFormat( DEFAULT_DATEFORMAT );
- try
- {
- Date d = fmt.parse( startDay );
+ if( startDay != null ) {
+ final SimpleDateFormat fmt = new SimpleDateFormat( DEFAULT_DATEFORMAT );
+ try {
+ final Date d = fmt.parse( startDay );
startTime.setTime( d );
stopTime.setTime( d );
- }
- catch( ParseException e )
- {
+ } catch( final ParseException e ) {
return "Illegal time format: "+startDay;
}
}
@@ -251,12 +225,10 @@ public class WeblogPlugin
//
// Mark this to be a weblog
//
-
context.getPage().setAttribute(ATTR_ISWEBLOG, "true");
//
- // We make a wild guess here that nobody can do millisecond
- // accuracy here.
+ // We make a wild guess here that nobody can do millisecond accuracy here.
//
startTime.add( Calendar.DAY_OF_MONTH, -numDays );
startTime.set( Calendar.HOUR, 0 );
@@ -266,38 +238,21 @@ public class WeblogPlugin
stopTime.set( Calendar.MINUTE, 59 );
stopTime.set( Calendar.SECOND, 59 );
- StringBuilder sb = new StringBuilder();
-
- try
- {
- List<WikiPage> blogEntries = findBlogEntries( engine,
- weblogName,
- startTime.getTime(),
- stopTime.getTime() );
-
- Collections.sort( blogEntries, new PageDateComparator() );
+ final StringBuilder sb = new StringBuilder();
+ final List<WikiPage> blogEntries = findBlogEntries( engine, weblogName, startTime.getTime(), stopTime.getTime() );
+ blogEntries.sort( new PageDateComparator() );
- sb.append("<div class=\"weblog\">\n");
+ sb.append("<div class=\"weblog\">\n");
- for( Iterator< WikiPage > i = blogEntries.iterator(); i.hasNext() && maxEntries-- > 0 ; )
- {
- WikiPage p = i.next();
-
- if( mgr.checkPermission( context.getWikiSession(),
- new PagePermission(p, PagePermission.VIEW_ACTION) ) )
- {
- addEntryHTML(context, entryFormat, hasComments, sb, p, params);
- }
+ for( final Iterator< WikiPage > i = blogEntries.iterator(); i.hasNext() && maxEntries-- > 0 ; ) {
+ final WikiPage p = i.next();
+ if( mgr.checkPermission( context.getWikiSession(), new PagePermission(p, PagePermission.VIEW_ACTION) ) ) {
+ addEntryHTML( context, entryFormat, hasComments, sb, p, params );
}
-
- sb.append("</div>\n");
- }
- catch( ProviderException e )
- {
- log.error( "Could not locate blog entries", e );
- throw new PluginException( "Could not locate blog entries: "+e.getMessage() );
}
+ sb.append("</div>\n");
+
return sb.toString();
}
@@ -311,12 +266,10 @@ public class WeblogPlugin
* @param entry
* @throws ProviderException
*/
- private void addEntryHTML(WikiContext context, DateFormat entryFormat, boolean hasComments,
- StringBuilder buffer, WikiPage entry, Map<String, String> params)
- throws ProviderException
- {
- WikiEngine engine = context.getEngine();
- ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
+ private void addEntryHTML( final WikiContext context, final DateFormat entryFormat, final boolean hasComments,
+ final StringBuilder buffer, final WikiPage entry, final Map< String, String > params) {
+ final WikiEngine engine = context.getEngine();
+ final ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
buffer.append("<div class=\"weblogentry\">\n");
@@ -325,40 +278,33 @@ public class WeblogPlugin
//
buffer.append("<div class=\"weblogentryheading\">\n");
- Date entryDate = entry.getLastModified();
- buffer.append( entryFormat.format(entryDate) );
-
+ final Date entryDate = entry.getLastModified();
+ buffer.append( entryFormat != null ? entryFormat.format(entryDate) : entryDate );
buffer.append("</div>\n");
//
- // Append the text of the latest version. Reset the
- // context to that page.
+ // Append the text of the latest version. Reset the context to that page.
//
-
- WikiContext entryCtx = (WikiContext) context.clone();
+ final WikiContext entryCtx = (WikiContext) context.clone();
entryCtx.setPage( entry );
- String html = engine.getHTML( entryCtx, engine.getPageManager().getPage( entry.getName() ) );
+ String html = engine.getRenderingManager().getHTML( entryCtx, engine.getPageManager().getPage( entry.getName() ) );
// Extract the first h1/h2/h3 as title, and replace with null
buffer.append("<div class=\"weblogentrytitle\">\n");
- Matcher matcher = HEADINGPATTERN.matcher( html );
- if ( matcher.find() )
- {
- String title = matcher.group(2);
+ final Matcher matcher = HEADINGPATTERN.matcher( html );
+ if ( matcher.find() ) {
+ final String title = matcher.group(2);
html = matcher.replaceFirst("");
buffer.append( title );
- }
- else
- {
+ } else {
buffer.append( entry.getName() );
}
buffer.append("</div>\n");
-
buffer.append("<div class=\"weblogentrybody\">\n");
- int preview = TextUtil.parseIntParameter(params.get(PARAM_PREVIEW), 0);
- if (preview > 0)
- {
+
+ final int preview = TextUtil.parseIntParameter(params.get(PARAM_PREVIEW), 0);
+ if (preview > 0) {
//
// We start with the first 'preview' number of characters from the text,
// and then add characters to it until we get to a linebreak or a period.
@@ -367,15 +313,11 @@ public class WeblogPlugin
//
boolean hasBeenCutOff = false;
int cutoff = Math.min(preview, html.length());
- while (cutoff < html.length())
- {
- if (html.charAt(cutoff) == '\r' || html.charAt(cutoff) == '\n')
- {
+ while (cutoff < html.length()) {
+ if (html.charAt(cutoff) == '\r' || html.charAt(cutoff) == '\n') {
hasBeenCutOff = true;
break;
- }
- else if (html.charAt(cutoff) == '.')
- {
+ } else if (html.charAt(cutoff) == '.') {
// we do want the period
cutoff++;
hasBeenCutOff = true;
@@ -384,13 +326,10 @@ public class WeblogPlugin
cutoff++;
}
buffer.append(html.substring(0, cutoff));
- if (hasBeenCutOff)
- {
+ if (hasBeenCutOff) {
buffer.append(" <a href=\""+entryCtx.getURL(WikiContext.VIEW, entry.getName())+"\">"+rb.getString("weblogentryplugin.more")+"</a>\n");
}
- }
- else
- {
+ } else {
buffer.append(html);
}
buffer.append("</div>\n");
@@ -402,44 +341,32 @@ public class WeblogPlugin
String author = entry.getAuthor();
- if( author != null )
- {
- if( engine.getPageManager().wikiPageExists(author) )
- {
+ if( author != null ) {
+ if( engine.getPageManager().wikiPageExists(author) ) {
author = "<a href=\""+entryCtx.getURL( WikiContext.VIEW, author )+"\">"+engine.getRenderingManager().beautifyTitle(author)+"</a>";
}
- }
- else
- {
+ } else {
author = "AnonymousCoward";
}
buffer.append( MessageFormat.format( rb.getString("weblogentryplugin.postedby"), author));
- buffer.append( "<a href=\""+entryCtx.getURL(WikiContext.VIEW, entry.getName())+"\">"+rb.getString("weblogentryplugin.permalink")+"</a>" );
- String commentPageName = TextUtil.replaceString( entry.getName(),
- "blogentry",
- "comments" );
+ buffer.append( "<a href=\"" + entryCtx.getURL( WikiContext.VIEW, entry.getName() ) + "\">" + rb.getString("weblogentryplugin.permalink") + "</a>" );
+ final String commentPageName = TextUtil.replaceString( entry.getName(), "blogentry", "comments" );
- if( hasComments )
- {
+ if( hasComments ) {
int numComments = guessNumberOfComments( engine, commentPageName );
//
- // We add the number of comments to the URL so that
- // the user's browsers would realize that the page
- // has changed.
+ // We add the number of comments to the URL so that the user's browsers would realize that the page has changed.
//
buffer.append( " " );
- String addcomment = rb.getString("weblogentryplugin.addcomment");
+ final String addcomment = rb.getString("weblogentryplugin.addcomment");
buffer.append( "<a href=\""+
- entryCtx.getURL(WikiContext.COMMENT,
- commentPageName,
- "nc="+numComments)+
- "\">"+
- MessageFormat.format(addcomment, numComments)
- +"</a>" );
+ entryCtx.getURL( WikiContext.COMMENT, commentPageName, "nc=" + numComments ) + "\">" +
+ MessageFormat.format( addcomment, numComments ) +
+ "</a>" );
}
buffer.append("</div>\n");
@@ -468,37 +395,25 @@ public class WeblogPlugin
* @param start The date which is the first to be considered
* @param end The end date which is the last to be considered
* @return a list of pages with their FIRST revisions.
- * @throws ProviderException If something goes wrong
*/
- public List< WikiPage > findBlogEntries( WikiEngine engine, String baseName, Date start, Date end )
- throws ProviderException
- {
- PageManager mgr = engine.getPageManager();
- Set< String > allPages = engine.getReferenceManager().findCreated();
-
- ArrayList<WikiPage> result = new ArrayList<WikiPage>();
+ public List< WikiPage > findBlogEntries( final WikiEngine engine, String baseName, final Date start, final Date end ) {
+ final PageManager mgr = engine.getPageManager();
+ final Set< String > allPages = engine.getReferenceManager().findCreated();
+ final ArrayList<WikiPage> result = new ArrayList<>();
baseName = makeEntryPage( baseName );
- for( Iterator< String > i = allPages.iterator(); i.hasNext(); )
- {
- String pageName = i.next();
-
- if( pageName.startsWith( baseName ) )
- {
- try
- {
- WikiPage firstVersion = mgr.getPageInfo( pageName, 1 );
- Date d = firstVersion.getLastModified();
+ for( final String pageName : allPages ) {
+ if( pageName.startsWith( baseName ) ) {
+ try {
+ final WikiPage firstVersion = mgr.getPageInfo( pageName, 1 );
+ final Date d = firstVersion.getLastModified();
- if( d.after(start) && d.before(end) )
- {
+ if( d.after( start ) && d.before( end ) ) {
result.add( firstVersion );
}
- }
- catch( Exception e )
- {
- log.debug("Page name :"+pageName+" was suspected as a blog entry but it isn't because of parsing errors",e);
+ } catch( final Exception e ) {
+ log.debug( "Page name :" + pageName + " was suspected as a blog entry but it isn't because of parsing errors", e );
}
}
}
@@ -509,25 +424,22 @@ public class WeblogPlugin
/**
* Reverse comparison.
*/
- private static class PageDateComparator implements Comparator<WikiPage>
- {
- public int compare( WikiPage page1, WikiPage page2 )
- {
- if( page1 == null || page2 == null )
- {
+ private static class PageDateComparator implements Comparator< WikiPage > {
+
+ public int compare( final WikiPage page1, final WikiPage page2 ) {
+ if( page1 == null || page2 == null ) {
return 0;
}
-
return page2.getLastModified().compareTo( page1.getLastModified() );
}
+
}
/**
* Mark us as being a real weblog.
* {@inheritDoc}
*/
- public void executeParser(PluginContent element, WikiContext context, Map<String, String> params)
- {
+ public void executeParser( final PluginContent element, final WikiContext context, final Map< String, String > params ) {
context.getPage().setAttribute( ATTR_ISWEBLOG, "true" );
}
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/render/DefaultRenderingManager.java b/jspwiki-main/src/main/java/org/apache/wiki/render/DefaultRenderingManager.java
index 686070c..cd1117a 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/render/DefaultRenderingManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/render/DefaultRenderingManager.java
@@ -26,6 +26,7 @@ import org.apache.log4j.Logger;
import org.apache.wiki.StringTransmutator;
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
+import org.apache.wiki.WikiPage;
import org.apache.wiki.api.exceptions.FilterException;
import org.apache.wiki.api.exceptions.ProviderException;
import org.apache.wiki.api.exceptions.WikiException;
@@ -270,6 +271,30 @@ public class DefaultRenderingManager implements RenderingManager {
* {@inheritDoc}
*/
@Override
+ public String getHTML( final WikiContext context, final WikiPage page ) {
+ final String pagedata = m_engine.getPageManager().getPureText( page.getName(), page.getVersion() );
+ return textToHTML( context, pagedata );
+ }
+
+ /**
+ * Returns the converted HTML of the page's specific version. The version must be a positive integer, otherwise the current
+ * version is returned.
+ *
+ * @param pagename WikiName of the page to convert.
+ * @param version Version number to fetch
+ * @return HTML-rendered page text.
+ */
+ public String getHTML( final String pagename, final int version ) {
+ final WikiPage page = m_engine.getPageManager().getPage( pagename, version );
+ final WikiContext context = new WikiContext( m_engine, page );
+ context.setRequestContext( WikiContext.NONE );
+ return getHTML( context, page );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String textToHTML( final WikiContext context, String pagedata ) {
String result = "";
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/render/RenderingManager.java b/jspwiki-main/src/main/java/org/apache/wiki/render/RenderingManager.java
index ac2c4b0..fabfaaa 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/render/RenderingManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/render/RenderingManager.java
@@ -22,11 +22,13 @@ import org.apache.log4j.Logger;
import org.apache.wiki.StringTransmutator;
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
+import org.apache.wiki.WikiPage;
import org.apache.wiki.api.exceptions.WikiException;
import org.apache.wiki.event.WikiEventListener;
import org.apache.wiki.modules.InternalModule;
import org.apache.wiki.parser.MarkupParser;
import org.apache.wiki.parser.WikiDocument;
+import org.apache.wiki.providers.WikiPageProvider;
import java.io.IOException;
import java.util.Properties;
@@ -141,6 +143,25 @@ public interface RenderingManager extends WikiEventListener, InternalModule {
String getHTML( WikiContext context, WikiDocument doc ) throws IOException;
/**
+ * Returns the converted HTML of the page using a different context than the default context.
+ *
+ * @param context A WikiContext in which you wish to render this page in.
+ * @param page WikiPage reference.
+ * @return HTML-rendered version of the page.
+ */
+ String getHTML( WikiContext context, WikiPage page );
+
+ /**
+ * Returns the converted HTML of the page's specific version. The version must be a positive integer, otherwise the current
+ * version is returned.
+ *
+ * @param pagename WikiName of the page to convert.
+ * @param version Version number to fetch
+ * @return HTML-rendered page text.
+ */
+ String getHTML( String pagename, int version );
+
+ /**
* Convenience method for rendering, using the default parser and renderer. Note that you can't use this method
* to do any arbitrary rendering, as the pagedata MUST be the data from the that the WikiContext refers to - this
* method caches the HTML internally, and will return the cached version. If the pagedata is different from what
@@ -162,6 +183,16 @@ public interface RenderingManager extends WikiEventListener, InternalModule {
}
/**
+ * Returns the converted HTML of the page.
+ *
+ * @param page WikiName of the page to convert.
+ * @return HTML-rendered version of the page.
+ */
+ default String getHTML( final String page ) {
+ return getHTML( page, WikiPageProvider.LATEST_VERSION );
+ }
+
+ /**
* Converts raw page data to HTML.
*
* @param pagedata Raw page data to convert to HTML
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/rss/RSSGenerator.java b/jspwiki-main/src/main/java/org/apache/wiki/rss/RSSGenerator.java
index d4e5687..dfe9391 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/rss/RSSGenerator.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/rss/RSSGenerator.java
@@ -204,7 +204,7 @@ public class RSSGenerator {
else
{
buf.append(author+" created this page on "+page.getLastModified()+":<br /><hr /><br />" );
- buf.append(m_engine.getHTML( page.getName() ));
+ buf.append(m_engine.getRenderingManager().getHTML( page.getName() ));
}
return buf.toString();
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/InsertPageTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/InsertPageTag.java
index 2f547b6..e932cdd 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/tags/InsertPageTag.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/InsertPageTag.java
@@ -109,7 +109,7 @@ public class InsertPageTag extends WikiTagBase {
final WikiPage oldPage = m_wikiContext.setRealPage( insertedPage );
switch( m_mode ) {
- case HTML: out.print( engine.getHTML( m_wikiContext, insertedPage ) ); break;
+ case HTML: out.print( engine.getRenderingManager().getHTML( m_wikiContext, insertedPage ) ); break;
case PLAIN: out.print( engine.getPageManager().getText( insertedPage ) ); break;
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/MetaWeblogHandler.java b/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/MetaWeblogHandler.java
index c726b83..d2d8c80 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/MetaWeblogHandler.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/MetaWeblogHandler.java
@@ -22,7 +22,6 @@ import org.apache.log4j.Logger;
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiPage;
-import org.apache.wiki.api.exceptions.ProviderException;
import org.apache.wiki.attachment.Attachment;
import org.apache.wiki.attachment.AttachmentManager;
import org.apache.wiki.auth.AuthenticationManager;
@@ -35,7 +34,6 @@ import org.apache.wiki.plugin.WeblogPlugin;
import org.apache.xmlrpc.XmlRpcException;
import java.io.ByteArrayInputStream;
-import java.util.Collections;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
@@ -108,8 +106,7 @@ public class MetaWeblogHandler
}
/**
- * JSPWiki does not support categories, therefore JSPWiki
- * always returns an empty list for categories.
+ * JSPWiki does not support categories, therefore JSPWiki always returns an empty list for categories.
*
* @param blogid The id of the blog.
* @param username The username to use
@@ -117,36 +114,25 @@ public class MetaWeblogHandler
* @throws XmlRpcException If something goes wrong
* @return An empty hashtable.
*/
- public Hashtable getCategories( String blogid,
- String username,
- String password )
- throws XmlRpcException
- {
- WikiPage page = m_context.getEngine().getPageManager().getPage( blogid );
-
+ public Hashtable getCategories( String blogid, String username, String password ) throws XmlRpcException {
+ final WikiPage page = m_context.getEngine().getPageManager().getPage( blogid );
checkPermissions( page, username, password, "view" );
-
- Hashtable ht = new Hashtable();
+ final Hashtable ht = new Hashtable();
return ht;
}
- private String getURL( String page )
- {
- return m_context.getEngine().getURL( WikiContext.VIEW,
- page,
- null,
- true ); // Force absolute urls
+ private String getURL( String page ) {
+ return m_context.getEngine().getURL( WikiContext.VIEW, page,null, true ); // Force absolute urls
}
/**
- * Takes a wiki page, and creates a metaWeblog struct
- * out of it.
+ * Takes a wiki page, and creates a metaWeblog struct out of it.
+ *
* @param page The actual entry page
* @return A metaWeblog entry struct.
*/
- private Hashtable<String,Object> makeEntry( WikiPage page )
- {
+ private Hashtable<String,Object> makeEntry( WikiPage page ) {
Hashtable<String, Object> ht = new Hashtable<>();
WikiPage firstVersion = m_context.getEngine().getPageManager().getPage( page.getName(), 1 );
@@ -157,19 +143,22 @@ public class MetaWeblogHandler
ht.put("postid", page.getName());
ht.put("userid", page.getAuthor());
- String pageText = m_context.getEngine().getPageManager().getText(page.getName());
+ final String pageText = m_context.getEngine().getPageManager().getText(page.getName());
String title = "";
- int firstLine = pageText.indexOf('\n');
+ final int firstLine = pageText.indexOf('\n');
- if( firstLine > 0 )
- {
+ if( firstLine > 0 ) {
title = pageText.substring( 0, firstLine );
}
- if( title.trim().length() == 0 ) title = page.getName();
+ if( title.trim().length() == 0 ) {
+ title = page.getName();
+ }
// Remove wiki formatting
- while( title.startsWith("!") ) title = title.substring(1);
+ while( title.startsWith("!") ) {
+ title = title.substring(1);
+ }
ht.put("title", title);
ht.put("description", pageText);
@@ -187,16 +176,8 @@ public class MetaWeblogHandler
* @throws XmlRpcException If something goes wrong
* @return As per MetaweblogAPI specification
*/
-
- // FIXME: The implementation is suboptimal, as it
- // goes through all of the blog entries.
-
- public Hashtable getRecentPosts( String blogid,
- String username,
- String password,
- int numberOfPosts)
- throws XmlRpcException
- {
+ // FIXME: The implementation is suboptimal, as it goes through all of the blog entries.
+ public Hashtable getRecentPosts( String blogid, String username, String password, int numberOfPosts) throws XmlRpcException {
Hashtable<String, Hashtable<String, Object>> result = new Hashtable<>();
log.info( "metaWeblog.getRecentPosts() called");
@@ -205,29 +186,20 @@ public class MetaWeblogHandler
checkPermissions( page, username, password, "view" );
- try {
- WeblogPlugin plugin = new WeblogPlugin();
-
- List<WikiPage> changed = plugin.findBlogEntries(m_context.getEngine(),
- blogid,
- new Date(0L),
- new Date());
-
- Collections.sort( changed, new PageTimeComparator() );
+ final WeblogPlugin plugin = new WeblogPlugin();
+ final List<WikiPage> changed = plugin.findBlogEntries( m_context.getEngine(), blogid, new Date( 0L ), new Date() );
- int items = 0;
- for( Iterator< WikiPage > i = changed.iterator(); i.hasNext() && items < numberOfPosts; items++ )
- {
- WikiPage p = i.next();
+ changed.sort( new PageTimeComparator() );
- result.put( "entry", makeEntry( p ) );
- }
+ int items = 0;
+ for( Iterator< WikiPage > i = changed.iterator(); i.hasNext() && items < numberOfPosts; items++ )
+ {
+ WikiPage p = i.next();
- } catch( final ProviderException e ) {
- log.error( "Failed to list recent posts", e );
- throw new XmlRpcException( 0, e.getMessage() );
+ result.put( "entry", makeEntry( p ) );
}
+
return result;
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/RPCHandler.java b/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/RPCHandler.java
index ee7ccfb..756a710 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/RPCHandler.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/RPCHandler.java
@@ -199,13 +199,13 @@ public class RPCHandler extends AbstractRPCHandler {
public byte[] getPageHTML( String pagename ) throws XmlRpcException {
pagename = parsePageCheckCondition( pagename );
- return toRPCBase64( m_engine.getHTML( pagename ) );
+ return toRPCBase64( m_engine.getRenderingManager().getHTML( pagename ) );
}
public byte[] getPageHTMLVersion( String pagename, int version ) throws XmlRpcException {
pagename = parsePageCheckCondition( pagename );
- return toRPCBase64( m_engine.getHTML( pagename, version ) );
+ return toRPCBase64( m_engine.getRenderingManager().getHTML( pagename, version ) );
}
public Vector< Hashtable< String, String > > listLinks( String pagename ) throws XmlRpcException {
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/RPCHandlerUTF8.java b/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/RPCHandlerUTF8.java
index fa1a451..a0b323b 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/RPCHandlerUTF8.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/RPCHandlerUTF8.java
@@ -155,11 +155,11 @@ public class RPCHandlerUTF8 extends AbstractRPCHandler {
}
public String getPageHTML( final String pagename ) throws XmlRpcException {
- return m_engine.getHTML( parsePageCheckCondition( pagename ) );
+ return m_engine.getRenderingManager().getHTML( parsePageCheckCondition( pagename ) );
}
public String getPageHTMLVersion( final String pagename, final int version ) throws XmlRpcException {
- return m_engine.getHTML( parsePageCheckCondition( pagename ), version );
+ return m_engine.getRenderingManager().getHTML( parsePageCheckCondition( pagename ), version );
}
public Vector< Hashtable< String, String > > listLinks( String pagename ) throws XmlRpcException {
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java b/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java
index 9aaf8d2..f97fa6e 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java
@@ -395,7 +395,7 @@ public class TestEngine extends WikiEngine
final WikiPage page = getPageManager().getPage( pagename, WikiPageProvider.LATEST_VERSION );
final WikiContext context = new WikiContext( this, newHttpRequest(), page );
context.setRequestContext( WikiContext.NONE );
- return getHTML( context, page );
+ return getRenderingManager().getHTML( context, page );
}
public static void trace() {
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java b/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java
index 7eb97c2..69d3f0e 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java
@@ -101,16 +101,6 @@ public class WikiEngineTest {
}
@Test
- public void testGetHTML() throws Exception {
- final String text = "''Foobar.''";
- final String name = NAME1;
- m_engine.saveText( name, text );
-
- final String data = m_engine.getHTML( name );
- Assertions.assertEquals( "<i>Foobar.</i>\n", data );
- }
-
- @Test
public void testEncodeNameLatin1() {
final String name = "abc\u00e5\u00e4\u00f6";
Assertions.assertEquals( "abc%E5%E4%F6", m_engine.encodeName(name) );
@@ -284,11 +274,10 @@ public class WikiEngineTest {
Assertions.assertEquals( "puppaa", m_engine.getPageManager().getText("This is a test").trim(), "normal" );
}
-
@Test
public void testParsedVariables() throws Exception {
m_engine.saveText( "TestPage", "[{SET foo=bar}][{SamplePlugin text='{$foo}'}]");
- final String res = m_engine.getHTML( "TestPage" );
+ final String res = m_engine.getRenderingManager().getHTML( "TestPage" );
Assertions.assertEquals( "bar\n", res );
}
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/pages/DefaultPageManagerTest.java b/jspwiki-main/src/test/java/org/apache/wiki/pages/DefaultPageManagerTest.java
index 1897db6..7966f79 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/pages/DefaultPageManagerTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/pages/DefaultPageManagerTest.java
@@ -224,7 +224,7 @@ public class DefaultPageManagerTest {
props.setProperty( "jspwiki.pageProvider", "org.apache.wiki.providers.VerySimpleProvider" );
props.setProperty( "jspwiki.usePageCache", "false" );
final WikiEngine engine = new TestEngine( props );
- final String p = engine.getHTML( "test", -1 );
+ final String p = engine.getRenderingManager().getHTML( "test", -1 );
final VerySimpleProvider vsp = (VerySimpleProvider) engine.getPageManager().getProvider();
Assertions.assertEquals( "test", vsp.m_latestReq, "wrong page" );
@@ -238,7 +238,7 @@ public class DefaultPageManagerTest {
props.setProperty( "jspwiki.pageProvider", "org.apache.wiki.providers.VerySimpleProvider" );
props.setProperty( "jspwiki.usePageCache", "true" );
final WikiEngine engine = new TestEngine( props );
- final String p = engine.getHTML( VerySimpleProvider.PAGENAME, -1 );
+ final String p = engine.getRenderingManager().getHTML( VerySimpleProvider.PAGENAME, -1 );
final CachingProvider cp = (CachingProvider)engine.getPageManager().getProvider();
final VerySimpleProvider vsp = (VerySimpleProvider) cp.getRealProvider();
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/plugin/DefaultPluginManagerTest.java b/jspwiki-main/src/test/java/org/apache/wiki/plugin/DefaultPluginManagerTest.java
index ca5aac5..69cf0aa 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/plugin/DefaultPluginManagerTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/plugin/DefaultPluginManagerTest.java
@@ -147,7 +147,7 @@ public class DefaultPluginManagerTest {
@Test
public void testParserPlugin() throws Exception {
engine.getPageManager().saveText(context, "[{SamplePlugin render=true}]");
- engine.getHTML( "Testpage" );
+ engine.getRenderingManager().getHTML( "Testpage" );
Assertions.assertTrue( SamplePlugin.c_rendered );
}
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/plugin/GroupsTest.java b/jspwiki-main/src/test/java/org/apache/wiki/plugin/GroupsTest.java
index 529af2c..6979a65 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/plugin/GroupsTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/plugin/GroupsTest.java
@@ -40,7 +40,7 @@ public class GroupsTest {
testEngine.saveText( "Test", src );
- String res = testEngine.getHTML( "Test" );
+ String res = testEngine.getRenderingManager().getHTML( "Test" );
Assertions.assertEquals( "<a href=\"/test/Group.jsp?group=Admin\">Admin</a>, "
+ "<a href=\"/test/Group.jsp?group=Art\">Art</a>, "
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/plugin/IfPluginTest.java b/jspwiki-main/src/test/java/org/apache/wiki/plugin/IfPluginTest.java
index 90eaff2..8879381 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/plugin/IfPluginTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/plugin/IfPluginTest.java
@@ -74,7 +74,7 @@ public class IfPluginTest {
WikiPage page = testEngine.getPageManager().getPage( "Test", WikiPageProvider.LATEST_VERSION );
WikiContext context = getJanneBasedWikiContextFor( page );
- String res = testEngine.getHTML( context, page );
+ String res = testEngine.getRenderingManager().getHTML( context, page );
Assertions.assertEquals( expected, res );
}
@@ -95,7 +95,7 @@ public class IfPluginTest {
WikiPage page = testEngine.getPageManager().getPage( "Test", WikiPageProvider.LATEST_VERSION );
WikiContext context = getJanneBasedWikiContextFor( page );
- String res = testEngine.getHTML( context, page );
+ String res = testEngine.getRenderingManager().getHTML( context, page );
Assertions.assertEquals( expected, res );
}
@@ -105,8 +105,7 @@ public class IfPluginTest {
* @throws WikiException test Assertions.failing.
*/
@Test
- public void testIfPluginIPAllowed() throws WikiException
- {
+ public void testIfPluginIPAllowed() throws WikiException {
String src = "[{IfPlugin ip='127.0.0.1'\n" +
"\n" +
"Content visible for 127.0.0.1}]";
@@ -116,7 +115,7 @@ public class IfPluginTest {
WikiPage page = testEngine.getPageManager().getPage( "Test", WikiPageProvider.LATEST_VERSION );
WikiContext context = getJanneBasedWikiContextFor( page );
- String res = testEngine.getHTML( context, page );
+ String res = testEngine.getRenderingManager().getHTML( context, page );
Assertions.assertEquals( expected, res );
}
@@ -126,8 +125,7 @@ public class IfPluginTest {
* @throws WikiException test Assertions.failing.
*/
@Test
- public void testIfPluginIPNotAllowed() throws WikiException
- {
+ public void testIfPluginIPNotAllowed() throws WikiException {
String src = "[{IfPlugin ip='!127.0.0.1'\n" +
"\n" +
"Content NOT visible for 127.0.0.1}]";
@@ -137,7 +135,7 @@ public class IfPluginTest {
WikiPage page = testEngine.getPageManager().getPage( "Test", WikiPageProvider.LATEST_VERSION );
WikiContext context = getJanneBasedWikiContextFor( page );
- String res = testEngine.getHTML( context, page );
+ String res = testEngine.getRenderingManager().getHTML( context, page );
Assertions.assertEquals( expected, res );
}
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/plugin/InsertPageTest.java b/jspwiki-main/src/test/java/org/apache/wiki/plugin/InsertPageTest.java
index 5d887cf..82cd0ce 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/plugin/InsertPageTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/plugin/InsertPageTest.java
@@ -18,14 +18,14 @@
*/
package org.apache.wiki.plugin;
-import java.util.Properties;
-
import org.apache.wiki.TestEngine;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.util.Properties;
+
public class InsertPageTest
{
@@ -57,7 +57,7 @@ public class InsertPageTest
// Just check that it contains a proper error message; don't bother do HTML
// checking.
- String res = testEngine.getHTML("ThisPage");
+ String res = testEngine.getRenderingManager().getHTML("ThisPage");
Assertions.assertTrue( res.indexOf("Circular reference") != -1 );
}
@@ -72,64 +72,56 @@ public class InsertPageTest
// Just check that it contains a proper error message; don't bother do HTML
// checking.
- Assertions.assertTrue( testEngine.getHTML("ThisPage").indexOf("Circular reference") != -1 );
+ Assertions.assertTrue( testEngine.getRenderingManager().getHTML("ThisPage").indexOf("Circular reference") != -1 );
}
@Test
- public void testMultiInvocation() throws Exception
- {
+ public void testMultiInvocation() throws Exception {
String src = "[{InsertPage page='ThisPage2'}] [{InsertPage page='ThisPage2'}]";
String src2 = "foo[{ALLOW view Anonymous}]";
testEngine.saveText("ThisPage",src);
testEngine.saveText("ThisPage2",src2);
- Assertions.assertTrue( testEngine.getHTML("ThisPage").indexOf("Circular reference") == -1, "got circ ref" );
-
- Assertions.assertEquals( "<div class=\"inserted-page \" >foo\n</div> <div class=\"inserted-page \" >foo\n</div>\n", testEngine.getHTML("ThisPage"), "found != 2" );
-
+ Assertions.assertTrue( testEngine.getRenderingManager().getHTML("ThisPage").indexOf("Circular reference") == -1, "got circ ref" );
+ Assertions.assertEquals( "<div class=\"inserted-page \" >foo\n</div> <div class=\"inserted-page \" >foo\n</div>\n",
+ testEngine.getRenderingManager().getHTML("ThisPage"), "found != 2" );
}
@Test
- public void testUnderscore() throws Exception
- {
+ public void testUnderscore() throws Exception {
String src = "[{InsertPage page='Test_Page'}]";
String src2 = "foo[{ALLOW view Anonymous}]";
testEngine.saveText("ThisPage",src);
testEngine.saveText("Test_Page",src2);
- Assertions.assertTrue( testEngine.getHTML("ThisPage").indexOf("Circular reference") == -1, "got circ ref" );
-
- Assertions.assertEquals( "<div class=\"inserted-page \" >foo\n</div>\n", testEngine.getHTML("ThisPage"), "found != 1" );
+ Assertions.assertTrue( testEngine.getRenderingManager().getHTML("ThisPage").indexOf("Circular reference") == -1, "got circ ref" );
+ Assertions.assertEquals( "<div class=\"inserted-page \" >foo\n</div>\n", testEngine.getRenderingManager().getHTML("ThisPage"), "found != 1" );
}
-
/**
* a link containing a blank should work if there is a page with exact the
* same name ('Test Page')
*/
@Test
- public void testWithBlanks1() throws Exception
- {
+ public void testWithBlanks1() throws Exception {
testEngine.saveText( "ThisPage", "[{InsertPage page='Test Page'}]" );
testEngine.saveText( "Test Page", "foo[{ALLOW view Anonymous}]" );
- Assertions.assertEquals( "<div class=\"inserted-page \" >foo\n</div>\n", testEngine.getHTML( "ThisPage" ), "found != 1" );
+ Assertions.assertEquals( "<div class=\"inserted-page \" >foo\n</div>\n", testEngine.getRenderingManager().getHTML( "ThisPage" ), "found != 1" );
}
/**
- * same as testWithBlanks1, but it should still work if the page does not
- * have the blank in it ( 'Test Page' should work if the included page is
- * called 'TestPage')
+ * same as testWithBlanks1, but it should still work if the page does not have the blank in it ( 'Test Page' should work if the
+ * included page is called 'TestPage')
*/
@Test
- public void testWithBlanks2() throws Exception
- {
+ public void testWithBlanks2() throws Exception {
testEngine.saveText( "ThisPage", "[{InsertPage page='Test Page'}]" );
testEngine.saveText( "TestPage", "foo[{ALLOW view Anonymous}]" );
- Assertions.assertEquals( "<div class=\"inserted-page \" >foo\n</div>\n", testEngine.getHTML( "ThisPage" ), "found != 1" );
+ Assertions.assertEquals( "<div class=\"inserted-page \" >foo\n</div>\n", testEngine.getRenderingManager().getHTML( "ThisPage" ), "found != 1" );
}
}
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/plugin/PageViewPluginTest.java b/jspwiki-main/src/test/java/org/apache/wiki/plugin/PageViewPluginTest.java
index d7a8f6b..2073349 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/plugin/PageViewPluginTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/plugin/PageViewPluginTest.java
@@ -71,9 +71,9 @@ public class PageViewPluginTest
WikiContext context2 = new WikiContext( testEngine, page2 );
// generate counts:
- testEngine.getHTML( context1, page1 );
- testEngine.getHTML( context2, page2 );
- testEngine.getHTML( context2, page2 );
+ testEngine.getRenderingManager().getHTML( context1, page1 );
+ testEngine.getRenderingManager().getHTML( context2, page2 );
+ testEngine.getRenderingManager().getHTML( context2, page2 );
// mind the double \n in the following string:
String pageViewPageContent = "[{PageViewPlugin show='list''\n\n* {1} ({2} views)\n}]";
@@ -82,7 +82,7 @@ public class PageViewPluginTest
WikiPage pageviews = testEngine.getPageManager().getPage( "PageViews" );
WikiContext contextPV = new WikiContext( testEngine, pageviews );
- String result = testEngine.getHTML( contextPV, pageviews );
+ String result = testEngine.getRenderingManager().getHTML( contextPV, pageviews );
// System.out.println( result );
Assertions.assertTrue( result.contains( "Test Page 01 (2 views)" ) );
@@ -101,9 +101,9 @@ public class PageViewPluginTest
WikiContext context2 = new WikiContext( testEngine, page2 );
// generate counts:
- testEngine.getHTML( context1, page1 );
- testEngine.getHTML( context2, page2 );
- testEngine.getHTML( context2, page2 );
+ testEngine.getRenderingManager().getHTML( context1, page1 );
+ testEngine.getRenderingManager().getHTML( context2, page2 );
+ testEngine.getRenderingManager().getHTML( context2, page2 );
// mind the double \n in the following string:
String pageViewPageContent = "[{PageViewPlugin show='list' exclude='TestPageExcl*' '\n\n* {1} ({2} views)\n}]";
@@ -112,7 +112,7 @@ public class PageViewPluginTest
WikiPage pageviews = testEngine.getPageManager().getPage( "PageViews" );
WikiContext contextPV = new WikiContext( testEngine, pageviews );
- String result = testEngine.getHTML( contextPV, pageviews );
+ String result = testEngine.getRenderingManager().getHTML( contextPV, pageviews );
// System.out.println( result );
Assertions.assertTrue( result.contains( "Test Page 01" ) );
@@ -132,9 +132,9 @@ public class PageViewPluginTest
WikiContext context2 = new WikiContext( testEngine, page2 );
// generate counts:
- testEngine.getHTML( context1, page1 );
- testEngine.getHTML( context2, page2 );
- testEngine.getHTML( context2, page2 );
+ testEngine.getRenderingManager().getHTML( context1, page1 );
+ testEngine.getRenderingManager().getHTML( context2, page2 );
+ testEngine.getRenderingManager().getHTML( context2, page2 );
// mind the double \n in the following string:
String pageViewPageContent = "[{PageViewPlugin show='list' sort=count '\n\n* {1} ({2} views)\n}]";
@@ -143,7 +143,7 @@ public class PageViewPluginTest
WikiPage pageviews = testEngine.getPageManager().getPage( "PageViews" );
WikiContext contextPV = new WikiContext( testEngine, pageviews );
- String result = testEngine.getHTML( contextPV, pageviews );
+ String result = testEngine.getRenderingManager().getHTML( contextPV, pageviews );
// System.out.println( result );
int start1 = result.indexOf( "Test Page 01" );
@@ -170,11 +170,11 @@ public class PageViewPluginTest
WikiContext context4 = new WikiContext( testEngine, page4 );
// generate counts:
- testEngine.getHTML( context1, page1 );
- testEngine.getHTML( context2, page2 );
- testEngine.getHTML( context2, page2 );
- testEngine.getHTML( context3, page3 );
- testEngine.getHTML( context4, page4 );
+ testEngine.getRenderingManager().getHTML( context1, page1 );
+ testEngine.getRenderingManager().getHTML( context2, page2 );
+ testEngine.getRenderingManager().getHTML( context2, page2 );
+ testEngine.getRenderingManager().getHTML( context3, page3 );
+ testEngine.getRenderingManager().getHTML( context4, page4 );
// mind the double \n in the following string:
String pageViewPageContent = "[{PageViewPlugin show='list' entries=3'\n\n* {1} ({2} views)\n}]";
@@ -183,7 +183,7 @@ public class PageViewPluginTest
WikiPage pageviews = testEngine.getPageManager().getPage( "PageViews" );
WikiContext contextPV = new WikiContext( testEngine, pageviews );
- String result = testEngine.getHTML( contextPV, pageviews );
+ String result = testEngine.getRenderingManager().getHTML( contextPV, pageviews );
// System.out.println( result );
Assertions.assertTrue( result.contains( "Test Page 03" ) );
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/render/RenderingManagerTest.java b/jspwiki-main/src/test/java/org/apache/wiki/render/RenderingManagerTest.java
index 3ba8e6d..436427a 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/render/RenderingManagerTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/render/RenderingManagerTest.java
@@ -85,6 +85,16 @@ public class RenderingManagerTest {
Assertions.assertEquals("This Is A Page", m_engine.getRenderingManager().beautifyTitle( src ) );
}
+ @Test
+ public void testGetHTML() throws Exception {
+ final String text = "''Foobar.''";
+ final String name = "Test1";
+ m_engine.saveText( name, text );
+
+ final String data = m_engine.getRenderingManager().getHTML( name );
+ Assertions.assertEquals( "<i>Foobar.</i>\n", data );
+ }
+
/**
* Tests the relative speed of the DOM cache with respect to
* page being parsed every single time.
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/stress/MassiveRepositoryTest.java b/jspwiki-main/src/test/java/org/apache/wiki/stress/MassiveRepositoryTest.java
index 0957019..b6cbe09 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/stress/MassiveRepositoryTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/stress/MassiveRepositoryTest.java
@@ -161,7 +161,7 @@ public class MassiveRepositoryTest {
{
String page = getName( random.nextInt( numPages ) );
- String content = engine.getHTML( page, WikiProvider.LATEST_VERSION );
+ String content = engine.getRenderingManager().getHTML( page, WikiProvider.LATEST_VERSION );
Assertions.assertNotNull(content);