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/02/27 15:10:26 UTC
[jspwiki] 01/20: JSPWIKI-120: ModuleManager and implementing
classes use Engine instead of WikiEngine
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 910e586975e3929c1929bad927c1fac3bfc0dab1
Author: juanpablo <ju...@apache.org>
AuthorDate: Wed Feb 26 13:11:14 2020 +0100
JSPWIKI-120: ModuleManager and implementing classes use Engine instead of WikiEngine
---
.../apache/wiki/filters/DefaultFilterManager.java | 18 +--
.../org/apache/wiki/modules/ModuleManager.java | 45 +++----
.../org/apache/wiki/pages/DefaultPageManager.java | 101 +++++++-------
.../apache/wiki/plugin/DefaultPluginManager.java | 148 ++++++++++-----------
.../java/org/apache/wiki/ui/EditorManager.java | 5 +-
.../java/org/apache/wiki/ui/TemplateManager.java | 4 +-
6 files changed, 161 insertions(+), 160 deletions(-)
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/filters/DefaultFilterManager.java b/jspwiki-main/src/main/java/org/apache/wiki/filters/DefaultFilterManager.java
index 6409ee0..b0004ef 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/filters/DefaultFilterManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/filters/DefaultFilterManager.java
@@ -20,7 +20,7 @@ package org.apache.wiki.filters;
import org.apache.log4j.Logger;
import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiEngine;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.engine.FilterManager;
import org.apache.wiki.api.exceptions.FilterException;
import org.apache.wiki.api.exceptions.WikiException;
@@ -100,7 +100,7 @@ public class DefaultFilterManager extends ModuleManager implements FilterManager
* @param props Properties to initialize the FilterManager with
* @throws WikiException If something goes wrong.
*/
- public DefaultFilterManager( final WikiEngine engine, final Properties props ) throws WikiException {
+ public DefaultFilterManager( final Engine engine, final Properties props ) throws WikiException {
super( engine );
initialize( props );
}
@@ -116,7 +116,7 @@ public class DefaultFilterManager extends ModuleManager implements FilterManager
* @param priority The priority in which position to add it in.
* @throws IllegalArgumentException If the PageFilter is null or invalid.
*/
- public void addPageFilter( final PageFilter f, final int priority ) throws IllegalArgumentException {
+ @Override public void addPageFilter( final PageFilter f, final int priority ) throws IllegalArgumentException {
if( f == null ) {
throw new IllegalArgumentException("Attempt to provide a null filter - this should never happen. Please check your configuration (or if you're a developer, check your own code.)");
}
@@ -240,7 +240,7 @@ public class DefaultFilterManager extends ModuleManager implements FilterManager
*
* @see PageFilter#preTranslate(WikiContext, String)
*/
- public String doPreTranslateFiltering( final WikiContext context, String pageData ) throws FilterException {
+ @Override public String doPreTranslateFiltering( final WikiContext context, String pageData ) throws FilterException {
fireEvent( WikiPageEvent.PRE_TRANSLATE_BEGIN, context );
for( final PageFilter f : m_pageFilters ) {
pageData = f.preTranslate( context, pageData );
@@ -260,7 +260,7 @@ public class DefaultFilterManager extends ModuleManager implements FilterManager
* @return The modified HTML
* @see PageFilter#postTranslate(WikiContext, String)
*/
- public String doPostTranslateFiltering( final WikiContext context, String htmlData ) throws FilterException {
+ @Override public String doPostTranslateFiltering( final WikiContext context, String htmlData ) throws FilterException {
fireEvent( WikiPageEvent.POST_TRANSLATE_BEGIN, context );
for( final PageFilter f : m_pageFilters ) {
htmlData = f.postTranslate( context, htmlData );
@@ -280,7 +280,7 @@ public class DefaultFilterManager extends ModuleManager implements FilterManager
* @return The modified WikiMarkup
* @see PageFilter#preSave(WikiContext, String)
*/
- public String doPreSaveFiltering( final WikiContext context, String pageData ) throws FilterException {
+ @Override public String doPreSaveFiltering( final WikiContext context, String pageData ) throws FilterException {
fireEvent( WikiPageEvent.PRE_SAVE_BEGIN, context );
for( final PageFilter f : m_pageFilters ) {
pageData = f.preSave( context, pageData );
@@ -300,7 +300,7 @@ public class DefaultFilterManager extends ModuleManager implements FilterManager
*
* @see PageFilter#postSave(WikiContext, String)
*/
- public void doPostSaveFiltering( final WikiContext context, final String pageData ) throws FilterException {
+ @Override public void doPostSaveFiltering( final WikiContext context, final String pageData ) throws FilterException {
fireEvent( WikiPageEvent.POST_SAVE_BEGIN, context );
for( final PageFilter f : m_pageFilters ) {
// log.info("POSTSAVE: "+f.toString() );
@@ -316,7 +316,7 @@ public class DefaultFilterManager extends ModuleManager implements FilterManager
*
* @return A List of PageFilter objects
*/
- public List< PageFilter > getFilterList()
+ @Override public List< PageFilter > getFilterList()
{
return m_pageFilters;
}
@@ -326,7 +326,7 @@ public class DefaultFilterManager extends ModuleManager implements FilterManager
* Notifies PageFilters to clean up their ressources.
*
*/
- public void destroy() {
+ @Override public void destroy() {
for( final PageFilter f : m_pageFilters ) {
f.destroy( m_engine );
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/modules/ModuleManager.java b/jspwiki-main/src/main/java/org/apache/wiki/modules/ModuleManager.java
index e0e5b82..a59e401 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/modules/ModuleManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/modules/ModuleManager.java
@@ -18,28 +18,24 @@
*/
package org.apache.wiki.modules;
+import org.apache.wiki.Release;
+import org.apache.wiki.api.core.Engine;
+
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
-import org.apache.wiki.Release;
-import org.apache.wiki.WikiEngine;
-
/**
* Superclass for all JSPWiki managers for modules (plugins, etc).
*/
-public abstract class ModuleManager
-{
+public abstract class ModuleManager {
- /**
- * Location of the property-files of plugins.
- * (Each plugin should include this property-file in its jar-file)
- */
+ /** Location of the property-files of plugins. (Each plugin should include this property-file in its jar-file) */
public static final String PLUGIN_RESOURCE_LOCATION = "ini/jspwiki_module.xml";
- protected WikiEngine m_engine;
+ protected Engine m_engine;
private boolean m_loadIncompatibleModules = false;
@@ -48,8 +44,7 @@ public abstract class ModuleManager
*
* @param engine The WikiEngine which owns this manager.
*/
- public ModuleManager( WikiEngine engine )
- {
+ public ModuleManager( final Engine engine ) {
m_engine = engine;
}
@@ -59,12 +54,10 @@ public abstract class ModuleManager
* @param info The module to check
* @return True, if the module is compatible.
*/
- public boolean checkCompatibility( WikiModuleInfo info )
- {
- if( !m_loadIncompatibleModules )
- {
- String minVersion = info.getMinVersion();
- String maxVersion = info.getMaxVersion();
+ public boolean checkCompatibility( final WikiModuleInfo info ) {
+ if( !m_loadIncompatibleModules ) {
+ final String minVersion = info.getMinVersion();
+ final String maxVersion = info.getMaxVersion();
return Release.isNewerOrEqual( minVersion ) && Release.isOlderOrEqual( maxVersion );
}
@@ -81,12 +74,13 @@ public abstract class ModuleManager
*/
public abstract Collection< WikiModuleInfo > modules();
- protected < T extends WikiModuleInfo > Collection< WikiModuleInfo > modules( Iterator< T > iterator ) {
- Set< WikiModuleInfo > ls = new TreeSet<>();
-
- for( Iterator< T > i = iterator; i.hasNext(); ) {
- WikiModuleInfo wmi = i.next();
- if( !ls.contains( wmi ) ) ls.add( wmi );
+ protected < T extends WikiModuleInfo > Collection< WikiModuleInfo > modules( final Iterator< T > iterator ) {
+ final Set< WikiModuleInfo > ls = new TreeSet<>();
+ for( final Iterator< T > i = iterator; i.hasNext(); ) {
+ final WikiModuleInfo wmi = i.next();
+ if( !ls.contains( wmi ) ) {
+ ls.add( wmi );
+ }
}
return ls;
@@ -94,8 +88,9 @@ public abstract class ModuleManager
/**
* Returns the {@link WikiModuleInfo} information about the provided moduleName.
+ *
* @param moduleName
* @return The wikiModuleInfo
*/
- public abstract WikiModuleInfo getModuleInfo(String moduleName);
+ public abstract WikiModuleInfo getModuleInfo( final String moduleName );
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/pages/DefaultPageManager.java b/jspwiki-main/src/main/java/org/apache/wiki/pages/DefaultPageManager.java
index 8dcaa8f..fbbedc7 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/pages/DefaultPageManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/pages/DefaultPageManager.java
@@ -25,15 +25,18 @@ import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiPage;
import org.apache.wiki.WikiProvider;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.exceptions.ProviderException;
import org.apache.wiki.api.exceptions.WikiException;
import org.apache.wiki.attachment.Attachment;
+import org.apache.wiki.attachment.AttachmentManager;
import org.apache.wiki.auth.WikiPrincipal;
import org.apache.wiki.auth.WikiSecurityException;
import org.apache.wiki.auth.acl.Acl;
import org.apache.wiki.auth.acl.AclEntry;
import org.apache.wiki.auth.acl.AclEntryImpl;
+import org.apache.wiki.auth.acl.AclManager;
import org.apache.wiki.auth.user.UserProfile;
import org.apache.wiki.diff.DifferenceManager;
import org.apache.wiki.event.WikiEvent;
@@ -45,6 +48,9 @@ import org.apache.wiki.modules.WikiModuleInfo;
import org.apache.wiki.providers.RepositoryModifiedException;
import org.apache.wiki.providers.WikiPageProvider;
import org.apache.wiki.references.ReferenceManager;
+import org.apache.wiki.search.SearchManager;
+import org.apache.wiki.tasks.TasksManager;
+import org.apache.wiki.ui.CommandResolver;
import org.apache.wiki.util.ClassUtil;
import org.apache.wiki.util.TextUtil;
import org.apache.wiki.workflow.Decision;
@@ -103,21 +109,17 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
* @throws NoSuchElementException {@value #PROP_PAGEPROVIDER} property not found on WikiEngine properties
* @throws WikiException If anything goes wrong, you get this.
*/
- public DefaultPageManager(final WikiEngine engine, final Properties props) throws NoSuchElementException, WikiException {
+ public DefaultPageManager(final Engine engine, final Properties props) throws NoSuchElementException, WikiException {
super(engine);
final String classname;
- m_engine = engine;
- final boolean useCache = "true".equals(props.getProperty(PROP_USECACHE));
+ final boolean useCache = "true".equals( props.getProperty( PROP_USECACHE ) );
+ m_expiryTime = TextUtil.parseIntParameter( props.getProperty( PROP_LOCKEXPIRY ), 60 );
- m_expiryTime = TextUtil.parseIntParameter(props.getProperty(PROP_LOCKEXPIRY), 60);
-
- //
// If user wants to use a cache, then we'll use the CachingProvider.
- //
- if (useCache) {
+ if( useCache ) {
classname = "org.apache.wiki.providers.CachingProvider";
} else {
- classname = TextUtil.getRequiredProperty(props, PROP_PAGEPROVIDER);
+ classname = TextUtil.getRequiredProperty( props, PROP_PAGEPROVIDER );
}
pageSorter.initialize( props );
@@ -187,7 +189,7 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
final WikiPage p = m_provider.getPageInfo( pageName, version );
m_engine.getManager( ReferenceManager.class ).updateReferences( p );
- m_engine.getSearchManager().reindexPage( p );
+ m_engine.getManager( SearchManager.class ).reindexPage( p );
text = m_provider.getPageText( pageName, version );
}
@@ -243,8 +245,8 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
// messages will appear in his/her workflow inbox.
final WorkflowBuilder builder = WorkflowBuilder.getBuilder( m_engine );
final Principal submitter = context.getCurrentUser();
- final Step prepTask = m_engine.getTasksManager().buildPreSaveWikiPageTask( context, proposedText );
- final Step completionTask = m_engine.getTasksManager().buildSaveWikiPageTask();
+ final Step prepTask = m_engine.getManager( TasksManager.class ).buildPreSaveWikiPageTask( context, proposedText );
+ final Step completionTask = m_engine.getManager( TasksManager.class ).buildSaveWikiPageTask();
final String diffText = m_engine.getManager( DifferenceManager.class ).makeDiff( context, oldText, proposedText );
final boolean isAuthenticated = context.getWikiSession().isAuthenticated();
final Fact[] facts = new Fact[ 5 ];
@@ -261,7 +263,7 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
facts,
completionTask,
rejectKey );
- m_engine.getWorkflowManager().start( workflow );
+ m_engine.getManager( WorkflowManager.class ).start( workflow );
// Let callers know if the page-save requires approval
if ( workflow.getCurrentStep() instanceof Decision ) {
@@ -274,7 +276,7 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
*
* @return The WikiEngine object.
*/
- protected WikiEngine getEngine() {
+ protected Engine getEngine() {
return m_engine;
}
@@ -377,7 +379,7 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
try {
WikiPage p = getPageInfo( pagereq, version );
if( p == null ) {
- p = m_engine.getAttachmentManager().getAttachmentInfo( null, pagereq );
+ p = m_engine.getManager( AttachmentManager.class ).getAttachmentInfo( null, pagereq );
}
return p;
@@ -419,17 +421,17 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
* {@inheritDoc}
* @see org.apache.wiki.pages.PageManager#getVersionHistory(java.lang.String)
*/
- @Override
+ @Override @SuppressWarnings( "unchecked" )
public < T extends WikiPage > List< T > getVersionHistory( final String pageName ) {
List< T > c = null;
try {
if( pageExists( pageName ) ) {
- c = (List< T >)m_provider.getVersionHistory( pageName );
+ c = ( List< T > )m_provider.getVersionHistory( pageName );
}
if( c == null ) {
- c = (List< T >)m_engine.getAttachmentManager().getVersionHistory( pageName );
+ c = ( List< T > )m_engine.getManager( AttachmentManager.class ).getVersionHistory( pageName );
}
} catch( final ProviderException e ) {
LOG.error( "ProviderException requesting version history for " + pageName, e );
@@ -442,15 +444,17 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
* {@inheritDoc}
* @see org.apache.wiki.pages.PageManager#getCurrentProvider()
*/
- @Override public String getCurrentProvider() {
+ @Override
+ public String getCurrentProvider() {
return getProvider().getClass().getName();
}
/**
* {@inheritDoc}
+ *
* @see org.apache.wiki.pages.PageManager#getProviderDescription()
*/
- @Override
+ @Override
public String getProviderDescription() {
return m_provider.getProviderInfo();
}
@@ -478,7 +482,7 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
try {
final TreeSet< WikiPage > sortedPages = new TreeSet<>( new PageTimeComparator() );
sortedPages.addAll( getAllPages() );
- sortedPages.addAll( m_engine.getAttachmentManager().getAllAttachments() );
+ sortedPages.addAll( m_engine.getManager( AttachmentManager.class ).getAllAttachments() );
return sortedPages;
} catch( final ProviderException e ) {
@@ -506,23 +510,24 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
*/
@Override
public boolean pageExists( final String pageName, final int version ) throws ProviderException {
- if (pageName == null || pageName.length() == 0) {
- throw new ProviderException("Illegal page name");
+ if( pageName == null || pageName.length() == 0 ) {
+ throw new ProviderException( "Illegal page name" );
}
- if (version == WikiProvider.LATEST_VERSION) {
- return pageExists(pageName);
+ if( version == WikiProvider.LATEST_VERSION ) {
+ return pageExists( pageName );
}
- return m_provider.pageExists(pageName, version);
+ return m_provider.pageExists( pageName, version );
}
/**
* {@inheritDoc}
* @see org.apache.wiki.pages.PageManager#wikiPageExists(java.lang.String)
*/
- @Override public boolean wikiPageExists( final String page ) {
- if( m_engine.getCommandResolver().getSpecialPageReference( page ) != null ) {
+ @Override
+ public boolean wikiPageExists( final String page ) {
+ if( m_engine.getManager( CommandResolver.class ).getSpecialPageReference( page ) != null ) {
return true;
}
@@ -532,7 +537,7 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
return true;
}
- att = m_engine.getAttachmentManager().getAttachmentInfo( null, page );
+ att = m_engine.getManager( AttachmentManager.class ).getAttachmentInfo( null, page );
} catch( final ProviderException e ) {
LOG.debug( "pageExists() failed to find attachments", e );
}
@@ -544,8 +549,9 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
* {@inheritDoc}
* @see org.apache.wiki.pages.PageManager#wikiPageExists(java.lang.String, int)
*/
- @Override public boolean wikiPageExists( final String page, final int version ) throws ProviderException {
- if( m_engine.getCommandResolver().getSpecialPageReference( page ) != null ) {
+ @Override
+ public boolean wikiPageExists( final String page, final int version ) throws ProviderException {
+ if( m_engine.getManager( CommandResolver.class ).getSpecialPageReference( page ) != null ) {
return true;
}
@@ -558,7 +564,7 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
if( !isThere ) {
// Go check if such an attachment exists.
try {
- isThere = m_engine.getAttachmentManager().getAttachmentInfo( null, page, version ) != null;
+ isThere = m_engine.getManager( AttachmentManager.class ).getAttachmentInfo( null, page, version ) != null;
} catch( final ProviderException e ) {
LOG.debug( "wikiPageExists() failed to find attachments", e );
}
@@ -574,7 +580,7 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
@Override
public void deleteVersion( final WikiPage page ) throws ProviderException {
if( page instanceof Attachment ) {
- m_engine.getAttachmentManager().deleteVersion( ( Attachment )page );
+ m_engine.getManager( AttachmentManager.class ).deleteVersion( ( Attachment )page );
} else {
m_provider.deleteVersion( page.getName(), page.getVersion() );
// FIXME: If this was the latest, reindex Lucene, update RefMgr
@@ -585,23 +591,24 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
* {@inheritDoc}
* @see org.apache.wiki.pages.PageManager#deletePage(java.lang.String)
*/
- @Override public void deletePage( final String pageName ) throws ProviderException {
+ @Override
+ public void deletePage( final String pageName ) throws ProviderException {
final WikiPage p = getPage( pageName );
if( p != null ) {
if( p instanceof Attachment ) {
- m_engine.getAttachmentManager().deleteAttachment( ( Attachment )p );
+ m_engine.getManager( AttachmentManager.class ).deleteAttachment( ( Attachment )p );
} else {
final Collection< String > refTo = m_engine.getManager( ReferenceManager.class ).findRefersTo( pageName );
// May return null, if the page does not exist or has not been indexed yet.
- if( m_engine.getAttachmentManager().hasAttachments( p ) ) {
- final List< Attachment > attachments = m_engine.getAttachmentManager().listAttachments( p );
+ if( m_engine.getManager( AttachmentManager.class ).hasAttachments( p ) ) {
+ final List< Attachment > attachments = m_engine.getManager( AttachmentManager.class ).listAttachments( p );
for( final Attachment attachment : attachments ) {
if( refTo != null ) {
refTo.remove( attachment.getName() );
}
- m_engine.getAttachmentManager().deleteAttachment( attachment );
+ m_engine.getManager( AttachmentManager.class ).deleteAttachment( attachment );
}
}
deletePage( p );
@@ -632,9 +639,9 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
*
* @param engine WikiEngine to own this thread.
*/
- public LockReaper( final WikiEngine engine) {
- super(engine, 60);
- setName("JSPWiki Lock Reaper");
+ public LockReaper( final Engine engine) {
+ super( engine, 60 );
+ setName( "JSPWiki Lock Reaper" );
}
@Override
@@ -720,7 +727,7 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
if( aclChanged ) {
// If the Acl needed changing, change it now
try {
- m_engine.getAclManager().setPermissions( page, page.getAcl() );
+ m_engine.getManager( AclManager.class ).setPermissions( page, page.getAcl() );
} catch( final WikiSecurityException e ) {
LOG.error("Could not change page ACL for page " + page.getName() + ": " + e.getMessage(), e);
}
@@ -753,18 +760,18 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
final Collection< AclEntry > entriesToRemove = new ArrayList<>();
while( entries.hasMoreElements() ) {
final AclEntry entry = entries.nextElement();
- if( ArrayUtils.contains(oldPrincipals, entry.getPrincipal() ) ) {
+ if( ArrayUtils.contains( oldPrincipals, entry.getPrincipal() ) ) {
// Create new entry
final AclEntry newEntry = new AclEntryImpl();
newEntry.setPrincipal( newPrincipal );
- final Enumeration<Permission> permissions = entry.permissions();
+ final Enumeration< Permission > permissions = entry.permissions();
while( permissions.hasMoreElements() ) {
final Permission permission = permissions.nextElement();
- newEntry.addPermission(permission);
+ newEntry.addPermission( permission );
}
pageChanged = true;
- entriesToRemove.add(entry);
- entriesToAdd.add(newEntry);
+ entriesToRemove.add( entry );
+ entriesToAdd.add( newEntry );
}
}
for( final AclEntry entry : entriesToRemove ) {
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/DefaultPluginManager.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/DefaultPluginManager.java
index 90c8131..55b6d6b 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/DefaultPluginManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/DefaultPluginManager.java
@@ -34,6 +34,7 @@ import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
import org.apache.wiki.ajax.WikiAjaxDispatcherServlet;
import org.apache.wiki.ajax.WikiAjaxServlet;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.engine.PluginManager;
import org.apache.wiki.api.exceptions.PluginException;
import org.apache.wiki.api.plugin.InitializablePlugin;
@@ -59,7 +60,6 @@ import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
@@ -185,22 +185,22 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* @param engine WikiEngine which owns this manager.
* @param props Contents of a "jspwiki.properties" file.
*/
- public DefaultPluginManager( WikiEngine engine, Properties props ) {
+ public DefaultPluginManager( final WikiEngine engine, final Properties props ) {
super( engine );
- String packageNames = props.getProperty( PROP_SEARCHPATH );
+ final String packageNames = props.getProperty( PROP_SEARCHPATH );
if ( packageNames != null ) {
- StringTokenizer tok = new StringTokenizer( packageNames, "," );
+ final StringTokenizer tok = new StringTokenizer( packageNames, "," );
while( tok.hasMoreTokens() ) {
m_searchPath.add( tok.nextToken().trim() );
}
}
- String externalJars = props.getProperty( PROP_EXTERNALJARS );
+ final String externalJars = props.getProperty( PROP_EXTERNALJARS );
if( externalJars != null ) {
- StringTokenizer tok = new StringTokenizer( externalJars, "," );
+ final StringTokenizer tok = new StringTokenizer( externalJars, "," );
while( tok.hasMoreTokens() ) {
m_externalJars.add( tok.nextToken().trim() );
@@ -215,11 +215,11 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
m_searchPath.add( DEFAULT_PACKAGE );
m_searchPath.add( DEFAULT_FORMS_PACKAGE );
- PatternCompiler compiler = new Perl5Compiler();
+ final PatternCompiler compiler = new Perl5Compiler();
try {
m_pluginPattern = compiler.compile( PLUGIN_INSERT_PATTERN );
- } catch( MalformedPatternException e ) {
+ } catch( final MalformedPatternException e ) {
log.fatal( "Internal error: someone messed with pluginmanager patterns.", e );
throw new InternalWikiException( "PluginManager patterns are broken" , e);
}
@@ -230,7 +230,7 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* {@inheritDoc}
*/
@Override
- public void enablePlugins( boolean enabled ) {
+ public void enablePlugins( final boolean enabled ) {
m_pluginsEnabled = enabled;
}
@@ -268,30 +268,29 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
*
* @throws ClassNotFoundException if no such class exists.
*/
- private Class< ? > findPluginClass( String classname ) throws ClassNotFoundException {
+ private Class< ? > findPluginClass( final String classname ) throws ClassNotFoundException {
return ClassUtil.findClass( m_searchPath, m_externalJars, classname );
}
/**
* Outputs a HTML-formatted version of a stack trace.
*/
- private String stackTrace( Map<String,String> params, Throwable t )
+ private String stackTrace( final Map<String,String> params, final Throwable t )
{
- Element div = XhtmlUtil.element(XHTML.div,"Plugin execution failed, stack trace follows:");
+ final Element div = XhtmlUtil.element(XHTML.div,"Plugin execution failed, stack trace follows:");
div.setAttribute(XHTML.ATTR_class,"debug");
- StringWriter out = new StringWriter();
+ final StringWriter out = new StringWriter();
t.printStackTrace(new PrintWriter(out));
div.addContent(XhtmlUtil.element(XHTML.pre,out.toString()));
div.addContent(XhtmlUtil.element(XHTML.b,"Parameters to the plugin"));
- Element list = XhtmlUtil.element(XHTML.ul);
+ final Element list = XhtmlUtil.element(XHTML.ul);
- for( Iterator<Map.Entry<String,String>> i = params.entrySet().iterator(); i.hasNext(); ) {
- Map.Entry<String,String> e = i.next();
- String key = e.getKey();
- list.addContent(XhtmlUtil.element(XHTML.li,key + "'='" + e.getValue()));
+ for( final Map.Entry< String, String > e : params.entrySet() ) {
+ final String key = e.getKey();
+ list.addContent( XhtmlUtil.element( XHTML.li, key + "'='" + e.getValue() ) );
}
div.addContent(list);
@@ -318,18 +317,18 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* @since 2.0
*/
@Override
- public String execute( WikiContext context, String classname, Map< String, String > params ) throws PluginException {
+ public String execute( final WikiContext context, final String classname, final Map< String, String > params ) throws PluginException {
if( !m_pluginsEnabled ) {
return "";
}
- ResourceBundle rb = Preferences.getBundle( context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE );
- boolean debug = TextUtil.isPositive( params.get( PARAM_DEBUG ) );
+ final ResourceBundle rb = Preferences.getBundle( context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE );
+ final boolean debug = TextUtil.isPositive( params.get( PARAM_DEBUG ) );
try {
//
// Create...
//
- WikiPlugin plugin = newWikiPlugin( classname, rb );
+ final WikiPlugin plugin = newWikiPlugin( classname, rb );
if( plugin == null ) {
return "Plugin '" + classname + "' not compatible with this version of JSPWiki";
}
@@ -339,14 +338,14 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
//
try {
return plugin.execute( context, params );
- } catch( PluginException e ) {
+ } catch( final PluginException e ) {
if( debug ) {
return stackTrace( params, e );
}
// Just pass this exception onward.
throw ( PluginException )e.fillInStackTrace();
- } catch( Throwable t ) {
+ } catch( final Throwable t ) {
// But all others get captured here.
log.info( "Plugin failed while executing:", t );
if( debug ) {
@@ -356,7 +355,7 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
throw new PluginException( rb.getString( "plugin.error.failed" ), t );
}
- } catch( ClassCastException e ) {
+ } catch( final ClassCastException e ) {
throw new PluginException( MessageFormat.format( rb.getString( "plugin.error.notawikiplugin" ), classname ), e );
}
}
@@ -382,23 +381,22 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* @throws IOException If the parsing fails.
*/
@Override
- public Map< String, String > parseArgs( String argstring ) throws IOException {
- Map< String, String > arglist = new HashMap< >();
+ public Map< String, String > parseArgs( final String argstring ) throws IOException {
+ final Map< String, String > arglist = new HashMap<>();
- //
// Protection against funny users.
- //
- if( argstring == null ) return arglist;
+ if( argstring == null ) {
+ return arglist;
+ }
arglist.put( PARAM_CMDLINE, argstring );
- StringReader in = new StringReader(argstring);
- StreamTokenizer tok = new StreamTokenizer(in);
+ final StringReader in = new StringReader(argstring);
+ final StreamTokenizer tok = new StreamTokenizer(in);
int type;
-
String param = null;
- String value = null;
+ String value;
tok.eolIsSignificant( true );
@@ -406,7 +404,7 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
boolean quit = false;
while( !quit ) {
- String s;
+ final String s;
type = tok.nextToken();
switch( type ) {
@@ -461,10 +459,10 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
// Now, we'll check the body.
//
if( potentialEmptyLine ) {
- StringWriter out = new StringWriter();
+ final StringWriter out = new StringWriter();
FileUtil.copyContents( in, out );
- String bodyContent = out.toString();
+ final String bodyContent = out.toString();
if( bodyContent != null ) {
arglist.put( PARAM_BODY, bodyContent );
@@ -489,32 +487,32 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* @throws PluginException From the plugin itself, it propagates, waah!
*/
@Override
- public String execute( WikiContext context, String commandline ) throws PluginException {
+ public String execute( final WikiContext context, final String commandline ) throws PluginException {
if( !m_pluginsEnabled ) {
return "";
}
- ResourceBundle rb = Preferences.getBundle( context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE );
- PatternMatcher matcher = new Perl5Matcher();
+ final ResourceBundle rb = Preferences.getBundle( context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE );
+ final PatternMatcher matcher = new Perl5Matcher();
try {
if( matcher.contains( commandline, m_pluginPattern ) ) {
- MatchResult res = matcher.getMatch();
+ final MatchResult res = matcher.getMatch();
- String plugin = res.group(2);
- String args = commandline.substring(res.endOffset(0),
+ final String plugin = res.group(2);
+ final String args = commandline.substring(res.endOffset(0),
commandline.length() -
(commandline.charAt(commandline.length()-1) == '}' ? 1 : 0 ) );
- Map<String, String> arglist = parseArgs( args );
+ final Map<String, String> arglist = parseArgs( args );
return execute( context, plugin, arglist );
}
- } catch( NoSuchElementException e ) {
- String msg = "Missing parameter in plugin definition: "+commandline;
+ } catch( final NoSuchElementException e ) {
+ final String msg = "Missing parameter in plugin definition: "+commandline;
log.warn( msg, e );
throw new PluginException( MessageFormat.format( rb.getString( "plugin.error.missingparameter" ), commandline ) );
- } catch( IOException e ) {
- String msg = "Zyrf. Problems with parsing arguments: "+commandline;
+ } catch( final IOException e ) {
+ final String msg = "Zyrf. Problems with parsing arguments: "+commandline;
log.warn( msg, e );
throw new PluginException( MessageFormat.format( rb.getString( "plugin.error.parsingarguments" ), commandline ) );
}
@@ -528,7 +526,7 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
/**
* Register a plugin.
*/
- private void registerPlugin( WikiPluginInfo pluginClass ) {
+ private void registerPlugin( final WikiPluginInfo pluginClass ) {
String name;
// Registrar the plugin with the className without the package-part
@@ -557,16 +555,16 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
private void registerPlugins() {
log.info( "Registering plugins" );
- List< Element > plugins = XmlUtil.parse( PLUGIN_RESOURCE_LOCATION, "/modules/plugin" );
+ final List< Element > plugins = XmlUtil.parse( PLUGIN_RESOURCE_LOCATION, "/modules/plugin" );
//
// Register all plugins which have created a resource containing its properties.
//
// Get all resources of all plugins.
//
- for( Element pluginEl : plugins ) {
- String className = pluginEl.getAttributeValue( "class" );
- WikiPluginInfo pluginInfo = WikiPluginInfo.newInstance( className, pluginEl ,m_searchPath, m_externalJars);
+ for( final Element pluginEl : plugins ) {
+ final String className = pluginEl.getAttributeValue( "class" );
+ final WikiPluginInfo pluginInfo = WikiPluginInfo.newInstance( className, pluginEl ,m_searchPath, m_externalJars);
if( pluginInfo != null ) {
registerPlugin( pluginInfo );
@@ -601,10 +599,10 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* @param externalJars the list of external jars to search
* @return A WikiPluginInfo object.
*/
- protected static WikiPluginInfo newInstance( String className, Element el, List<String> searchPath, List<String> externalJars ) {
+ protected static WikiPluginInfo newInstance( final String className, final Element el, final List<String> searchPath, final List<String> externalJars ) {
if( className == null || className.length() == 0 ) return null;
- WikiPluginInfo info = new WikiPluginInfo( className );
+ final WikiPluginInfo info = new WikiPluginInfo( className );
info.initializeFromXML( el );
return info;
}
@@ -618,24 +616,24 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* @param searchPath A List of Strings, containing different package names.
* @param externalJars the list of external jars to search
*/
- protected void initializePlugin( WikiPluginInfo info, WikiEngine engine , List<String> searchPath, List<String> externalJars) {
+ protected void initializePlugin( final WikiPluginInfo info, final Engine engine , final List<String> searchPath, final List<String> externalJars) {
if( !m_initialized ) {
// This makes sure we only try once per class, even if init fails.
m_initialized = true;
try {
- WikiPlugin p = newPluginInstance(searchPath, externalJars);
+ final WikiPlugin p = newPluginInstance(searchPath, externalJars);
if( p instanceof InitializablePlugin ) {
( ( InitializablePlugin )p ).initialize( engine );
}
if( p instanceof WikiAjaxServlet ) {
WikiAjaxDispatcherServlet.registerServlet( (WikiAjaxServlet) p );
- String ajaxAlias = info.getAjaxAlias();
+ final String ajaxAlias = info.getAjaxAlias();
if (StringUtils.isNotBlank(ajaxAlias)) {
WikiAjaxDispatcherServlet.registerServlet( info.getAjaxAlias(), (WikiAjaxServlet) p );
}
}
- } catch( Exception e ) {
+ } catch( final Exception e ) {
log.info( "Cannot initialize plugin " + m_className, e );
}
}
@@ -645,7 +643,7 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* {@inheritDoc}
*/
@Override
- protected void initializeFromXML( Element el ) {
+ protected void initializeFromXML( final Element el ) {
super.initializeFromXML( el );
m_alias = el.getChildText( "alias" );
m_ajaxAlias = el.getChildText( "ajaxAlias" );
@@ -657,16 +655,16 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* @param clazz The class to check
* @return A WikiPluginInfo instance
*/
- protected static WikiPluginInfo newInstance( Class< ? > clazz ) {
+ protected static WikiPluginInfo newInstance( final Class< ? > clazz ) {
return new WikiPluginInfo( clazz.getName() );
}
- private WikiPluginInfo( String className ) {
+ private WikiPluginInfo( final String className ) {
super( className );
setClassName( className );
}
- private void setClassName( String fullClassName ) {
+ private void setClassName( final String fullClassName ) {
m_name = ClassUtils.getShortClassName( fullClassName );
m_className = fullClassName;
}
@@ -707,7 +705,7 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* @throws IllegalAccessException If the class cannot be accessed.
*/
- public WikiPlugin newPluginInstance(List<String> searchPath, List<String> externalJars) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
+ public WikiPlugin newPluginInstance( final List<String> searchPath, final List<String> externalJars) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
if( m_clazz == null ) {
m_clazz = ClassUtil.findClass(searchPath, externalJars ,m_className);
}
@@ -721,14 +719,14 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* @param type Either "script" or "stylesheet"
* @return Text, or an empty string, if there is nothing to be included.
*/
- public String getIncludeText( String type ) {
+ public String getIncludeText( final String type ) {
try {
if( "script".equals( type ) ) {
return getScriptText();
} else if( "stylesheet".equals( type ) ) {
return getStylesheetText();
}
- } catch( Exception ex ) {
+ } catch( final Exception ex ) {
// We want to fail gracefully here
return ex.getMessage();
}
@@ -747,7 +745,7 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
try {
m_scriptText = getTextResource(m_scriptLocation);
- } catch( IOException ex ) {
+ } catch( final IOException ex ) {
// Only throw this exception once!
m_scriptText = "";
throw ex;
@@ -767,7 +765,7 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
try {
m_stylesheetText = getTextResource(m_stylesheetLocation);
- } catch( IOException ex ) {
+ } catch( final IOException ex ) {
// Only throw this exception once!
m_stylesheetText = "";
throw ex;
@@ -799,7 +797,7 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* {@inheritDoc}
*/
@Override
- public WikiPluginInfo getModuleInfo(String moduleName) {
+ public WikiPluginInfo getModuleInfo( final String moduleName) {
return m_pluginClassMap.get(moduleName);
}
@@ -812,7 +810,7 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
* @throws PluginException if there is a problem building the {@link WikiPlugin}.
*/
@Override
- public WikiPlugin newWikiPlugin( String pluginName, ResourceBundle rb ) throws PluginException {
+ public WikiPlugin newWikiPlugin( final String pluginName, final ResourceBundle rb ) throws PluginException {
WikiPlugin plugin = null;
WikiPluginInfo pluginInfo = m_pluginClassMap.get( pluginName );
try {
@@ -822,18 +820,18 @@ public class DefaultPluginManager extends ModuleManager implements PluginManager
}
if( !checkCompatibility( pluginInfo ) ) {
- String msg = "Plugin '" + pluginInfo.getName() + "' not compatible with this version of JSPWiki";
+ final String msg = "Plugin '" + pluginInfo.getName() + "' not compatible with this version of JSPWiki";
log.info( msg );
} else {
plugin = pluginInfo.newPluginInstance(m_searchPath, m_externalJars);
}
- } catch( ClassNotFoundException e ) {
+ } catch( final ClassNotFoundException e ) {
throw new PluginException( MessageFormat.format( rb.getString( "plugin.error.couldnotfind" ), pluginName ), e );
- } catch( InstantiationException e ) {
+ } catch( final InstantiationException e ) {
throw new PluginException( MessageFormat.format( rb.getString( "plugin.error.cannotinstantiate" ), pluginName ), e );
- } catch( IllegalAccessException e ) {
+ } catch( final IllegalAccessException e ) {
throw new PluginException( MessageFormat.format( rb.getString( "plugin.error.notallowed" ), pluginName ), e );
- } catch( Exception e ) {
+ } catch( final Exception e ) {
throw new PluginException( MessageFormat.format( rb.getString( "plugin.error.instantationfailed" ), pluginName ), e );
}
return plugin;
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/EditorManager.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/EditorManager.java
index 217c1bd..0d2f5f3 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/ui/EditorManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/EditorManager.java
@@ -26,6 +26,7 @@ import org.apache.wiki.modules.ModuleManager;
import org.apache.wiki.modules.WikiModuleInfo;
import org.apache.wiki.preferences.Preferences;
import org.apache.wiki.util.XmlUtil;
+import org.apache.wiki.variables.VariableManager;
import org.jdom2.Element;
import javax.servlet.jsp.PageContext;
@@ -147,7 +148,7 @@ public class EditorManager extends ModuleManager {
if( editor == null ) {
// or use the default editor in jspwiki.properties
try {
- editor = m_engine.getVariableManager().getValue( context, PROP_EDITORTYPE );
+ editor = m_engine.getManager( VariableManager.class ).getValue( context, PROP_EDITORTYPE );
} catch( final NoSuchVariableException e ) {} // This is fine
}
@@ -224,7 +225,7 @@ public class EditorManager extends ModuleManager {
return info;
}
- protected void initializeFromXML( final Element el ) {
+ @Override protected void initializeFromXML( final Element el ) {
super.initializeFromXML( el );
m_path = el.getChildText("path");
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/TemplateManager.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/TemplateManager.java
index c2db396..68441f9 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/ui/TemplateManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/TemplateManager.java
@@ -22,7 +22,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.apache.wiki.InternalWikiException;
import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiEngine;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.i18n.InternationalizationManager;
import org.apache.wiki.modules.ModuleManager;
import org.apache.wiki.modules.WikiModuleInfo;
@@ -122,7 +122,7 @@ public class TemplateManager extends ModuleManager {
* @param engine The owning engine.
* @param properties The property list used to initialize this.
*/
- public TemplateManager( final WikiEngine engine, final Properties properties ) {
+ public TemplateManager( final Engine engine, final Properties properties ) {
super( engine );
//