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 74e8560d25dc2969e02c079ce5cf9e45e4feb559 Author: juanpablo <[email protected]> AuthorDate: Tue Jan 7 21:31:57 2020 +0100 JSPWIKI-120: move pageExist(..) methods to PageManager, renamed as wikiPageExist(..) pageExist(..) methods on PageManager look for pages on the underlying WikiPageProvider, whereas wikiPageExis(..) ones look for all kind of wiki pages: WiiPages, Attachments and special pages (i.e. certain kind of references without an underlying WikiPage) --- .../src/main/java/org/apache/wiki/WikiEngine.java | 117 +---------- .../org/apache/wiki/pages/DefaultPageManager.java | 52 ++++- .../java/org/apache/wiki/pages/PageManager.java | 55 ++++- .../org/apache/wiki/plugin/BugReportHandler.java | 224 ++++++++------------- .../main/java/org/apache/wiki/plugin/IfPlugin.java | 131 ++++++------ .../apache/wiki/plugin/RecentChangesPlugin.java | 2 +- .../apache/wiki/plugin/ReferredPagesPlugin.java | 150 +++++++------- .../java/org/apache/wiki/plugin/WeblogPlugin.java | 2 +- .../wiki/references/DefaultReferenceManager.java | 6 +- .../apache/wiki/tags/AttachmentsIteratorTag.java | 97 ++++----- .../main/java/org/apache/wiki/tags/AuthorTag.java | 47 ++--- .../java/org/apache/wiki/tags/BreadcrumbsTag.java | 8 +- .../java/org/apache/wiki/tags/CalendarTag.java | 2 +- .../java/org/apache/wiki/tags/CheckVersionTag.java | 90 +++------ .../java/org/apache/wiki/tags/DiffLinkTag.java | 2 +- .../org/apache/wiki/tags/HasAttachmentsTag.java | 28 +-- .../org/apache/wiki/tags/HistoryIteratorTag.java | 2 +- .../java/org/apache/wiki/tags/InsertPageTag.java | 2 +- .../java/org/apache/wiki/tags/NoSuchPageTag.java | 2 +- .../java/org/apache/wiki/tags/PageInfoLinkTag.java | 57 ++---- .../java/org/apache/wiki/tags/PageSizeTag.java | 3 +- .../java/org/apache/wiki/tags/WikiTagBase.java | 68 +++---- .../java/org/apache/wiki/tasks/TasksManager.java | 9 +- .../java/org/apache/wiki/xmlrpc/RPCHandler.java | 91 +++------ .../org/apache/wiki/xmlrpc/RPCHandlerUTF8.java | 4 +- .../test/java/org/apache/wiki/WikiEngineTest.java | 42 +--- .../wiki/attachment/AttachmentManagerTest.java | 10 +- .../apache/wiki/pages/DefaultPageManagerTest.java | 45 ++++- .../apache/wiki/workflow/ApprovalWorkflowTest.java | 8 +- jspwiki-war/src/main/webapp/Login.jsp | 3 +- jspwiki-war/src/main/webapp/UserPreferences.jsp | 4 +- jspwiki-war/src/main/webapp/rss.jsp | 2 +- 32 files changed, 565 insertions(+), 800 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 a6183f4..d6c94e9 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java @@ -701,8 +701,7 @@ public class WikiEngine { pages.addAll( m_attachmentManager.getAllAttachments() ); // Build a new manager with default key lists. - if( m_referenceManager == null ) - { + if( m_referenceManager == null ) { m_referenceManager = ClassUtil.getMappedObject(ReferenceManager.class.getName(), this ); m_referenceManager.initialize( pages ); } @@ -722,7 +721,6 @@ public class WikiEngine { * * @return The wiki properties */ - public Properties getWikiProperties() { return m_properties; @@ -977,18 +975,15 @@ public class WikiEngine { } /** - * Beautifies the title of the page by appending non-breaking spaces - * in suitable places. This is really suitable only for HTML output, + * Beautifies the title of the page by appending non-breaking spaces in suitable places. This is really suitable only for HTML output, * as it uses the &nbsp; -character. * * @param title The title to beautify * @return A beautified title. * @since 2.1.127 */ - public String beautifyTitleNoBreak( String title ) - { - if( m_beautifyTitle ) - { + public String beautifyTitleNoBreak( final String title ) { + if( m_beautifyTitle ) { return TextUtil.beautifyString( title, " " ); } @@ -996,112 +991,14 @@ public class WikiEngine { } /** - * Returns true, if the requested page (or an alias) exists. Will consider - * any version as existing. Will also consider attachments. - * - * @param page WikiName of the page. - * @return true, if page (or attachment) exists. - */ - public boolean pageExists( String page ) - { - Attachment att = null; - - try - { - if( m_commandResolver.getSpecialPageReference(page) != null ) return true; - - if( getFinalPageName( page ) != null ) - { - return true; - } - - att = getAttachmentManager().getAttachmentInfo( (WikiContext)null, page ); - } - catch( ProviderException e ) - { - log.debug("pageExists() failed to find attachments",e); - } - - return att != null; - } - - /** - * Returns true, if the requested page (or an alias) exists with the - * requested version. - * - * @param page Page name - * @param version Page version - * @return True, if page (or alias, or attachment) exists - * @throws ProviderException If the provider fails. - */ - public boolean pageExists( String page, int version ) - throws ProviderException - { - if( m_commandResolver.getSpecialPageReference(page) != null ) return true; - - String finalName = getFinalPageName( page ); - - boolean isThere = false; - - if( finalName != null ) - { - // - // Go and check if this particular version of this page - // exists. - // - isThere = m_pageManager.pageExists( finalName, version ); - } - - if( isThere == false ) - { - // - // Go check if such an attachment exists. - // - try - { - isThere = getAttachmentManager().getAttachmentInfo( (WikiContext)null, page, version ) != null; - } - catch( ProviderException e ) - { - log.debug("pageExists() failed to find attachments",e); - } - } - - return isThere; - } - - /** - * Returns true, if the requested page (or an alias) exists, with the - * specified version in the WikiPage. - * - * @param page A WikiPage object describing the name and version. - * @return true, if the page (or alias, or attachment) exists. - * @throws ProviderException If something goes badly wrong. - * @since 2.0 - */ - public boolean pageExists( WikiPage page ) - throws ProviderException - { - if( page != null ) - { - return pageExists( page.getName(), page.getVersion() ); - } - return false; - } - - /** - * Returns the correct page name, or null, if no such - * page can be found. Aliases are considered. This - * method simply delegates to + * Returns the correct page name, or null, if no such page can be found. Aliases are considered. This method simply delegates to * {@link org.apache.wiki.ui.CommandResolver#getFinalPageName(String)}. * @since 2.0 * @param page Page name. * @return The rewritten page name, or null, if the page does not exist. * @throws ProviderException If something goes wrong in the backend. */ - public String getFinalPageName( String page ) - throws ProviderException - { + public String getFinalPageName( final String page ) throws ProviderException { return m_commandResolver.getFinalPageName( page ); } @@ -1377,7 +1274,7 @@ public class WikiEngine { // Check if creation of empty pages is allowed; bail if not final boolean allowEmpty = TextUtil.getBooleanProperty( m_properties, PROP_ALLOW_CREATION_OF_EMPTY_PAGES, false ); - if ( !allowEmpty && !pageExists( page ) && text.trim().equals( "" ) ) { + if ( !allowEmpty && !m_pageManager.wikiPageExists( page ) && text.trim().equals( "" ) ) { return; } 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 d47f910..229889e 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 @@ -467,6 +467,56 @@ public class DefaultPageManager extends ModuleManager implements PageManager { /** * {@inheritDoc} + * @see org.apache.wiki.pages.PageManager#wikiPageExists(java.lang.String) + */ + public boolean wikiPageExists( final String page ) { + if( m_engine.getCommandResolver().getSpecialPageReference( page ) != null ) { + return true; + } + + Attachment att = null; + try { + if( m_engine.getFinalPageName( page ) != null ) { + return true; + } + + att = m_engine.getAttachmentManager().getAttachmentInfo( null, page ); + } catch( final ProviderException e ) { + LOG.debug( "pageExists() failed to find attachments", e ); + } + + return att != null; + } + + /** + * {@inheritDoc} + * @see org.apache.wiki.pages.PageManager#wikiPageExists(java.lang.String, int) + */ + public boolean wikiPageExists( final String page, final int version ) throws ProviderException { + if( m_engine.getCommandResolver().getSpecialPageReference( page ) != null ) { + return true; + } + + boolean isThere = false; + final String finalName = m_engine.getFinalPageName( page ); + if( finalName != null ) { + isThere = pageExists( finalName, version ); + } + + if( !isThere ) { + // Go check if such an attachment exists. + try { + isThere = m_engine.getAttachmentManager().getAttachmentInfo( null, page, version ) != null; + } catch( final ProviderException e ) { + LOG.debug( "wikiPageExists() failed to find attachments", e ); + } + } + + return isThere; + } + + /** + * {@inheritDoc} * @see org.apache.wiki.pages.PageManager#deleteVersion(org.apache.wiki.WikiPage) */ @Override @@ -474,7 +524,7 @@ public class DefaultPageManager extends ModuleManager implements PageManager { if( page instanceof Attachment ) { m_engine.getAttachmentManager().deleteVersion( ( Attachment )page ); } else { - m_provider.deleteVersion(page.getName(), page.getVersion()); + m_provider.deleteVersion( page.getName(), page.getVersion() ); // FIXME: If this was the latest, reindex Lucene, update RefMgr } } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/pages/PageManager.java b/jspwiki-main/src/main/java/org/apache/wiki/pages/PageManager.java index e3435fb..632e3b4 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/pages/PageManager.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/pages/PageManager.java @@ -261,7 +261,7 @@ public interface PageManager extends WikiEventListener { Set< WikiPage > getRecentChanges(); /** - * Returns true, if the page exists (any version). + * Returns true, if the page exists (any version) on the underlying WikiPageProvider. * * @param pageName Name of the page. * @return A boolean value describing the existence of a page @@ -270,7 +270,7 @@ public interface PageManager extends WikiEventListener { boolean pageExists( String pageName ) throws ProviderException; /** - * Checks for existence of a specific page and version. + * Checks for existence of a specific page and version on the underlying WikiPageProvider. * * @param pageName Name of the page * @param version The version to check @@ -281,6 +281,57 @@ public interface PageManager extends WikiEventListener { boolean pageExists( String pageName, int version ) throws ProviderException; /** + * Checks for existence of a specific page and version denoted by a WikiPage on the underlying WikiPageProvider. + * + * @param page A WikiPage object describing the name and version. + * @return true, if the page (or alias, or attachment) exists. + * @throws ProviderException If something goes badly wrong. + * @since 2.0 + */ + default boolean pageExists( final WikiPage page ) throws ProviderException { + if( page != null ) { + return pageExists( page.getName(), page.getVersion() ); + } + return false; + } + + /** + * Returns true, if the requested page (or an alias) exists. Will consider any version as existing. Will check for all types of + * WikiPages: wiki pages themselves, attachments and special pages (non-existant references to other pages). + * + * @param page WikiName of the page. + * @return true, if page (or attachment) exists. + */ + boolean wikiPageExists( String page ); + + /** + * Returns true, if the requested page (or an alias) exists with the requested version. Will check for all types of + * WikiPages: wiki pages themselves, attachments and special pages (non-existant references to other pages). + * + * @param page Page name + * @param version Page version + * @return True, if page (or alias, or attachment) exists + * @throws ProviderException If the provider fails. + */ + boolean wikiPageExists( String page, int version ) throws ProviderException; + + /** + * Returns true, if the requested page (or an alias) exists, with the specified version in the WikiPage. Will check for all types of + * WikiPages: wiki pages themselves, attachments and special pages (non-existant references to other pages). + * + * @param page A WikiPage object describing the name and version. + * @return true, if the page (or alias, or attachment) exists. + * @throws ProviderException If something goes badly wrong. + * @since 2.0 + */ + default boolean wikiPageExists( final WikiPage page ) throws ProviderException { + if( page != null ) { + return wikiPageExists( page.getName(), page.getVersion() ); + } + return false; + } + + /** * Deletes only a specific version of a WikiPage. * * @param page The page to delete. diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/BugReportHandler.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/BugReportHandler.java index 8fb20a3..8ad5f9b 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/BugReportHandler.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/BugReportHandler.java @@ -18,13 +18,6 @@ */ package org.apache.wiki.plugin; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.security.Principal; -import java.text.MessageFormat; -import java.text.SimpleDateFormat; -import java.util.*; - import org.apache.log4j.Logger; import org.apache.wiki.WikiContext; import org.apache.wiki.WikiEngine; @@ -36,6 +29,17 @@ import org.apache.wiki.api.plugin.WikiPlugin; import org.apache.wiki.parser.MarkupParser; import org.apache.wiki.preferences.Preferences; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.security.Principal; +import java.text.MessageFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; +import java.util.Properties; +import java.util.ResourceBundle; +import java.util.StringTokenizer; + /** * Provides a handler for bug reports. Still under construction. * @@ -49,10 +53,10 @@ import org.apache.wiki.preferences.Preferences; * </ul> * */ -public class BugReportHandler - implements WikiPlugin -{ - private static Logger log = Logger.getLogger( BugReportHandler.class ); +public class BugReportHandler implements WikiPlugin { + + private static final Logger log = Logger.getLogger( BugReportHandler.class ); + private static final String DEFAULT_DATEFORMAT = "dd-MMM-yyyy HH:mm:ss zzz"; /** Parameter name for setting the title. Value is <tt>{@value}</tt>. */ public static final String PARAM_TITLE = "title"; @@ -65,148 +69,105 @@ public class BugReportHandler /** Parameter name for setting the page. Value is <tt>{@value}</tt>. */ public static final String PARAM_PAGE = "page"; - private static final String DEFAULT_DATEFORMAT = "dd-MMM-yyyy HH:mm:ss zzz"; - /** * {@inheritDoc} */ - public String execute( WikiContext context, Map<String, String> params ) - throws PluginException - { - String title; - String description; - String version; - String submitter = null; - SimpleDateFormat format = new SimpleDateFormat( DEFAULT_DATEFORMAT ); - ResourceBundle rb = Preferences.getBundle( context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE ); - - title = params.get( PARAM_TITLE ); - description = params.get( PARAM_DESCRIPTION ); - version = params.get( PARAM_VERSION ); - - Principal wup = context.getCurrentUser(); - - if( wup != null ) - { + public String execute( final WikiContext context, final Map< String, String > params ) throws PluginException { + final String title = params.get( PARAM_TITLE ); + String description = params.get( PARAM_DESCRIPTION ); + String version = params.get( PARAM_VERSION ); + String submitter = null; + final SimpleDateFormat format = new SimpleDateFormat( DEFAULT_DATEFORMAT ); + final ResourceBundle rb = Preferences.getBundle( context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE ); + final Principal wup = context.getCurrentUser(); + + if( wup != null ) { submitter = wup.getName(); } - if( title == null ) throw new PluginException(rb.getString("bugreporthandler.titlerequired")); - if( title.length() == 0 ) return ""; + if( title == null ) { + throw new PluginException(rb.getString("bugreporthandler.titlerequired")); + } + if( title.length() == 0 ) { + return ""; + } - if( description == null ) description = ""; - if( version == null ) version = "unknown"; + if( description == null ) { + description = ""; + } + if( version == null ) { + version = "unknown"; + } - Properties mappings = parseMappings( params.get( PARAM_MAPPINGS ) ); + final Properties mappings = parseMappings( params.get( PARAM_MAPPINGS ) ); - // // Start things - // + try { + final StringWriter str = new StringWriter(); + final PrintWriter out = new PrintWriter( str ); + final Date d = new Date(); - try - { - StringWriter str = new StringWriter(); - PrintWriter out = new PrintWriter( str ); - - Date d = new Date(); - - // // Outputting of basic data - // - out.println("|"+mappings.getProperty(PARAM_TITLE,"Title")+"|"+title); - out.println("|"+mappings.getProperty("date","Date")+"|"+format.format(d)); - out.println("|"+mappings.getProperty(PARAM_VERSION,"Version")+"|"+version); - if( submitter != null ) - { - out.println("|"+mappings.getProperty("submitter","Submitter")+ - "|"+submitter); + out.println( "|" + mappings.getProperty(PARAM_TITLE,"Title" ) + "|" + title ); + out.println( "|" + mappings.getProperty("date","Date" ) + "|" + format.format( d ) ); + out.println( "|" + mappings.getProperty(PARAM_VERSION,"Version" ) + "|" + version ); + if( submitter != null ) { + out.println("|"+mappings.getProperty("submitter","Submitter") + "|" + submitter ); } - // // Outputting the other parameters added to this. - // - for( Iterator<Map.Entry<String, String>> i = params.entrySet().iterator(); i.hasNext(); ) - { - Map.Entry<String, String> entry = i.next(); - - if( entry.getKey().equals( PARAM_TITLE ) || - entry.getKey().equals( PARAM_DESCRIPTION ) || - entry.getKey().equals( PARAM_VERSION ) || - entry.getKey().equals( PARAM_MAPPINGS ) || - entry.getKey().equals( PARAM_PAGE ) || - entry.getKey().startsWith("_") ) - { - // Ignore this - } - else - { - // - // If no mapping has been defined, just ignore - // it. - // - String head = mappings.getProperty( entry.getKey(), entry.getKey() ); - if( head.length() > 0 ) - { - out.println("|"+head+ - "|"+entry.getValue()); + for( final Map.Entry< String, String > entry : params.entrySet() ) { + if( !( entry.getKey().equals( PARAM_TITLE ) || + entry.getKey().equals( PARAM_DESCRIPTION ) || + entry.getKey().equals( PARAM_VERSION ) || + entry.getKey().equals( PARAM_MAPPINGS ) || + entry.getKey().equals( PARAM_PAGE ) || + entry.getKey().startsWith( "_" ) + ) ) { + // If no mapping has been defined, just ignore it. + final String head = mappings.getProperty( entry.getKey(), entry.getKey() ); + if( head.length() > 0 ) { + out.println( "|" + head + "|" + entry.getValue() ); } } } out.println(); out.println( description ); - out.close(); - // // Now create a new page for this bug report - // - String pageName = findNextPage( context, title, params.get( PARAM_PAGE ) ); - - WikiPage newPage = new WikiPage( context.getEngine(), pageName ); - WikiContext newContext = (WikiContext)context.clone(); + final String pageName = findNextPage( context, title, params.get( PARAM_PAGE ) ); + final WikiPage newPage = new WikiPage( context.getEngine(), pageName ); + final WikiContext newContext = (WikiContext)context.clone(); newContext.setPage( newPage ); + context.getEngine().saveText( newContext, str.toString() ); - context.getEngine().saveText( newContext, - str.toString() ); - - MessageFormat formatter = new MessageFormat(""); + final MessageFormat formatter = new MessageFormat(""); formatter.applyPattern( rb.getString("bugreporthandler.new") ); - String[] args = { "<a href=\""+context.getViewURL(pageName)+"\">"+pageName+"</a>" }; + final String[] args = { "<a href=\""+context.getViewURL(pageName)+"\">"+pageName+"</a>" }; return formatter.format( args ); - } - catch( RedirectException e ) - { + } catch( final RedirectException e ) { log.info("Saving not allowed, reason: '"+e.getMessage()+"', can't redirect to "+e.getRedirect()); - throw new PluginException("Saving not allowed, reason: "+e.getMessage()); - } - catch( WikiException e ) - { - log.error("Unable to save page!",e); - - return rb.getString("bugreporthandler.unable"); + } catch( final WikiException e ) { + log.error( "Unable to save page!", e ); + return rb.getString("bugreporthandler.unable" ); } } /** - * Finds a free page name for adding the bug report. Tries to construct a page, - * and if it's found, adds a number to it and tries again. + * Finds a free page name for adding the bug report. Tries to construct a page, and if it's found, adds a number to it + * and tries again. */ - private synchronized String findNextPage( WikiContext context, - String title, - String baseName ) - { - String basicPageName = ((baseName != null)?baseName:"Bug")+MarkupParser.cleanLink(title); - - WikiEngine engine = context.getEngine(); + private synchronized String findNextPage( final WikiContext context, final String title, final String baseName ) { + final String basicPageName = ( ( baseName != null ) ? baseName : "Bug" ) + MarkupParser.cleanLink( title ); + final WikiEngine engine = context.getEngine(); String pageName = basicPageName; long lastbug = 2; - - while( engine.pageExists( pageName ) ) - { + while( engine.getPageManager().wikiPageExists( pageName ) ) { pageName = basicPageName + lastbug++; } @@ -218,37 +179,30 @@ public class BugReportHandler * <p> * FIXME: Should probably be in TextUtil or somewhere. */ - private Properties parseMappings( String mappings ) - { - Properties props = new Properties(); - - if( mappings == null ) return props; - - StringTokenizer tok = new StringTokenizer( mappings, ";" ); - - while( tok.hasMoreTokens() ) - { - String t = tok.nextToken(); - - int colon = t.indexOf("="); + private Properties parseMappings( final String mappings ) { + final Properties props = new Properties(); + if( mappings == null ) { + return props; + } - String key; - String value; + final StringTokenizer tok = new StringTokenizer( mappings, ";" ); + while( tok.hasMoreTokens() ) { + final String t = tok.nextToken(); + final int colon = t.indexOf("="); + final String key; + final String value; - if( colon > 0 ) - { + if( colon > 0 ) { key = t.substring(0,colon); value = t.substring(colon+1); - } - else - { + } else { key = t; value = ""; } props.setProperty( key, value ); } - return props; } + } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/IfPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/IfPlugin.java index a4902f7..64305d0 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/IfPlugin.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/IfPlugin.java @@ -188,62 +188,60 @@ public class IfPlugin implements WikiPlugin return include; } - private static boolean checkExists( WikiContext context, String page, String exists ) - { - if( exists == null ) return false; - return !context.getEngine().pageExists(page) ^ TextUtil.isPositive(exists); + private static boolean checkExists( final WikiContext context, final String page, final String exists ) { + if( exists == null ) { + return false; + } + return !context.getEngine().getPageManager().wikiPageExists( page ) ^ TextUtil.isPositive(exists); } - private static boolean checkVarExists( String varContent, String exists ) - { - if( exists == null ) return false; - return (varContent == null ) ^ TextUtil.isPositive(exists); + private static boolean checkVarExists( final String varContent, final String exists ) { + if( exists == null ) { + return false; + } + return varContent == null ^ TextUtil.isPositive( exists ); } - private static boolean checkGroup( WikiContext context, String group ) - { - if( group == null ) return false; - String[] groupList = StringUtils.split(group,'|'); + private static boolean checkGroup( final WikiContext context, final String group ) { + if( group == null ) { + return false; + } + final String[] groupList = StringUtils.split(group,'|'); boolean include = false; - for( int i = 0; i < groupList.length; i++ ) - { - String gname = groupList[i]; + for( final String grp : groupList ) { + String gname = grp; boolean invert = false; - if( groupList[i].startsWith("!") ) - { - if( groupList[i].length() > 1 ) - { - gname = groupList[i].substring( 1 ); + if( grp.startsWith( "!" ) ) { + if( grp.length() > 1 ) { + gname = grp.substring( 1 ); } invert = true; } - Principal g = context.getEngine().getAuthorizationManager().resolvePrincipal(gname); + final Principal g = context.getEngine().getAuthorizationManager().resolvePrincipal( gname ); include |= context.getEngine().getAuthorizationManager().isUserInRole( context.getWikiSession(), g ) ^ invert; } return include; } - private static boolean checkUser( WikiContext context, String user ) - { - if( user == null || context.getCurrentUser() == null ) return false; + private static boolean checkUser( final WikiContext context, final String user ) { + if( user == null || context.getCurrentUser() == null ) { + return false; + } - String[] list = StringUtils.split(user,'|'); + final String[] list = StringUtils.split(user,'|'); boolean include = false; - for( int i = 0; i < list.length; i++ ) - { - String userToCheck = list[i]; + for( final String usr : list ) { + String userToCheck = usr; boolean invert = false; - if( list[i].startsWith("!") ) - { + if( usr.startsWith( "!" ) ) { invert = true; // strip ! - if( user.length() > 1 ) - { - userToCheck = list[i].substring( 1 ); + if( user.length() > 1 ) { + userToCheck = usr.substring( 1 ); } } @@ -253,67 +251,56 @@ public class IfPlugin implements WikiPlugin } // TODO: Add subnetwork matching, e.g. 10.0.0.0/8 - private static boolean checkIP( WikiContext context, String ipaddr ) - { - if( ipaddr == null || context.getHttpRequest() == null ) return false; + private static boolean checkIP( final WikiContext context, final String ipaddr ) { + if( ipaddr == null || context.getHttpRequest() == null ) { + return false; + } - - String[] list = StringUtils.split(ipaddr,'|'); + final String[] list = StringUtils.split(ipaddr,'|'); boolean include = false; - for( int i = 0; i < list.length; i++ ) - { - String ipaddrToCheck = list[i]; + for( final String ip : list ) { + String ipaddrToCheck = ip; boolean invert = false; - if( list[i].startsWith("!") ) - { + if( ip.startsWith( "!" ) ) { invert = true; // strip ! - if( list[i].length() > 1 ) - { - ipaddrToCheck = list[i].substring( 1 ); + if( ip.length() > 1 ) { + ipaddrToCheck = ip.substring( 1 ); } } - include |= ipaddrToCheck.equals( HttpUtil.getRemoteAddress(context.getHttpRequest()) ) ^ invert; + include |= ipaddrToCheck.equals( HttpUtil.getRemoteAddress( context.getHttpRequest() ) ) ^ invert; } return include; } - private static boolean doMatch( String content, String pattern ) - throws PluginException - { - PatternCompiler compiler = new Perl5Compiler(); - PatternMatcher matcher = new Perl5Matcher(); + private static boolean doMatch( final String content, final String pattern ) throws PluginException { + final PatternCompiler compiler = new Perl5Compiler(); + final PatternMatcher matcher = new Perl5Matcher(); - try - { - Pattern matchp = compiler.compile( pattern, Perl5Compiler.SINGLELINE_MASK ); - // m_exceptPattern = compiler.compile( exceptPattern, Perl5Compiler.SINGLELINE_MASK ); + try { + final Pattern matchp = compiler.compile( pattern, Perl5Compiler.SINGLELINE_MASK ); return matcher.matches( content, matchp ); - } - catch( MalformedPatternException e ) - { - throw new PluginException("Faulty pattern "+pattern); + } catch( final MalformedPatternException e ) { + throw new PluginException( "Faulty pattern " + pattern ); } } - private static boolean checkContains( String pagecontent, String matchPattern ) - throws PluginException - { - if( pagecontent == null || matchPattern == null ) return false; + private static boolean checkContains( final String pagecontent, final String matchPattern ) throws PluginException { + if( pagecontent == null || matchPattern == null ) { + return false; + } return doMatch( pagecontent, ".*"+matchPattern+".*" ); } - private static boolean checkIs( String content, String matchPattern ) - throws PluginException - { - if( content == null || matchPattern == null ) return false; - - matchPattern = "^"+matchPattern+"$"; - - return doMatch(content, matchPattern); + private static boolean checkIs( final String content, final String matchPattern ) throws PluginException { + if( content == null || matchPattern == null ) { + return false; + } + return doMatch( content, "^" + matchPattern + "$"); } + } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/RecentChangesPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/RecentChangesPlugin.java index 16c1d41..642041c 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/RecentChangesPlugin.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/RecentChangesPlugin.java @@ -182,7 +182,7 @@ public class RecentChangesPlugin extends AbstractReferralPlugin implements WikiP authorinfo.setAttribute( XHTML.ATTR_class, "author" ); if( author != null ) { - if( engine.pageExists( author ) ) { + if( engine.getPageManager().wikiPageExists( author ) ) { authorinfo.addContent( XhtmlUtil.link( context.getURL( WikiContext.VIEW, author ), author ) ); } else { authorinfo.addContent( author ); diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferredPagesPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferredPagesPlugin.java index a586057..a284660 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferredPagesPlugin.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferredPagesPlugin.java @@ -36,7 +36,6 @@ import org.apache.wiki.util.TextUtil; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; -import java.util.Iterator; import java.util.Map; @@ -56,7 +55,7 @@ import java.util.Map; */ public class ReferredPagesPlugin implements WikiPlugin { - private static Logger log = Logger.getLogger( ReferredPagesPlugin.class ); + private static final Logger log = Logger.getLogger( ReferredPagesPlugin.class ); private WikiEngine m_engine; private int m_depth; private HashSet<String> m_exists = new HashSet<>(); @@ -94,20 +93,29 @@ public class ReferredPagesPlugin implements WikiPlugin { /** * {@inheritDoc} */ - public String execute( WikiContext context, Map<String, String> params ) throws PluginException { + public String execute( final WikiContext context, final Map<String, String> params ) throws PluginException { m_engine = context.getEngine(); - - WikiPage page = context.getPage(); - if( page == null ) return ""; + final WikiPage page = context.getPage(); + if( page == null ) { + return ""; + } // parse parameters String rootname = params.get( PARAM_ROOT ); - if( rootname == null ) rootname = page.getName() ; + if( rootname == null ) { + rootname = page.getName() ; + } String format = params.get( PARAM_FORMAT ); - if( format == null) format = ""; - if( format.indexOf( "full" ) >=0 ) m_formatCompact = false ; - if( format.indexOf( "sort" ) >=0 ) m_formatSort = true ; + if( format == null) { + format = ""; + } + if( format.contains( "full" ) ) { + m_formatCompact = false ; + } + if( format.contains( "sort" ) ) { + m_formatSort = true ; + } m_depth = TextUtil.parseIntParameter( params.get( PARAM_DEPTH ), MIN_DEPTH ); if( m_depth > MAX_DEPTH ) m_depth = MAX_DEPTH; @@ -126,43 +134,34 @@ public class ReferredPagesPlugin implements WikiPlugin { // // do the actual work // - String href = context.getViewURL(rootname); - String title = "ReferredPagesPlugin: depth["+m_depth+ - "] include["+includePattern+"] exclude["+excludePattern+ - "] format["+(m_formatCompact ? "compact" : "full") + - (m_formatSort ? " sort" : "") + "]"; - - m_result.append("<div class=\"ReferredPagesPlugin\">\n"); - m_result.append("<a class=\"wikipage\" href=\""+ href + - "\" title=\"" + TextUtil.replaceEntities(title) + - "\">" + TextUtil.replaceEntities(rootname) + "</a>\n"); - m_exists.add(rootname); + final String href = context.getViewURL( rootname ); + final String title = "ReferredPagesPlugin: depth[" + m_depth + + "] include[" + includePattern + "] exclude[" + excludePattern + + "] format[" + ( m_formatCompact ? "compact" : "full" ) + + ( m_formatSort ? " sort" : "" ) + "]"; + + m_result.append( "<div class=\"ReferredPagesPlugin\">\n" ); + m_result.append( "<a class=\"wikipage\" href=\""+ href + + "\" title=\"" + TextUtil.replaceEntities( title ) + + "\">" + TextUtil.replaceEntities( rootname ) + "</a>\n" ); + m_exists.add( rootname ); // pre compile all needed patterns // glob compiler : * is 0..n instance of any char -- more convenient as input // perl5 compiler : .* is 0..n instances of any char -- more powerful //PatternCompiler g_compiler = new GlobCompiler(); - PatternCompiler compiler = new Perl5Compiler(); - - try - { - m_includePattern = compiler.compile(includePattern); - - m_excludePattern = compiler.compile(excludePattern); - } - catch( MalformedPatternException e ) - { - if (m_includePattern == null ) - { - throw new PluginException("Illegal include pattern detected."); - } - else if (m_excludePattern == null ) - { - throw new PluginException("Illegal exclude pattern detected."); - } - else - { - throw new PluginException("Illegal internal pattern detected."); + final PatternCompiler compiler = new Perl5Compiler(); + + try { + m_includePattern = compiler.compile( includePattern ); + m_excludePattern = compiler.compile( excludePattern ); + } catch( final MalformedPatternException e ) { + if( m_includePattern == null ) { + throw new PluginException( "Illegal include pattern detected." ); + } else if( m_excludePattern == null ) { + throw new PluginException( "Illegal exclude pattern detected." ); + } else { + throw new PluginException( "Illegal internal pattern detected." ); } } @@ -179,41 +178,50 @@ public class ReferredPagesPlugin implements WikiPlugin { /** * Retrieves a list of all referred pages. Is called recursively depending on the depth parameter. */ - private void getReferredPages( WikiContext context, String pagename, int depth ) { - if( depth >= m_depth ) return; // end of recursion - if( pagename == null ) return; - if( !m_engine.pageExists(pagename) ) return; - - ReferenceManager mgr = m_engine.getReferenceManager(); - - Collection<String> allPages = mgr.findRefersTo( pagename ); + private void getReferredPages( final WikiContext context, final String pagename, int depth ) { + if( depth >= m_depth ) { + return; // end of recursion + } + if( pagename == null ) { + return; + } + if( !m_engine.getPageManager().wikiPageExists(pagename) ) { + return; + } + final ReferenceManager mgr = m_engine.getReferenceManager(); + final Collection< String > allPages = mgr.findRefersTo( pagename ); handleLinks( context, allPages, ++depth, pagename ); } - private void handleLinks(WikiContext context,Collection<String> links, int depth, String pagename) { + private void handleLinks( final WikiContext context, final Collection<String> links, final int depth, final String pagename) { boolean isUL = false; - HashSet<String> localLinkSet = new HashSet<>(); // needed to skip multiple + final HashSet< String > localLinkSet = new HashSet<>(); // needed to skip multiple // links to the same page - localLinkSet.add(pagename); + localLinkSet.add( pagename ); - ArrayList<String> allLinks = new ArrayList<>(); + final ArrayList< String > allLinks = new ArrayList<>(); if( links != null ) allLinks.addAll( links ); if( m_formatSort ) context.getEngine().getPageManager().getPageSorter().sort( allLinks ); - for( Iterator<String> i = allLinks.iterator(); i.hasNext(); ) { - String link = i.next() ; - - if( localLinkSet.contains( link ) ) continue; // skip multiple links to the same page + for( final String link : allLinks ) { + if( localLinkSet.contains( link ) ) { + continue; // skip multiple links to the same page + } localLinkSet.add( link ); - if( !m_engine.pageExists( link ) ) continue; // hide links to non existing pages - - if( m_matcher.matches( link , m_excludePattern ) ) continue; - if( !m_matcher.matches( link , m_includePattern ) ) continue; + if( !m_engine.getPageManager().wikiPageExists( link ) ) { + continue; // hide links to non existing pages + } + if( m_matcher.matches( link , m_excludePattern ) ) { + continue; + } + if( !m_matcher.matches( link , m_includePattern ) ) { + continue; + } if( m_exists.contains( link ) ) { if( !m_formatCompact ) { @@ -223,12 +231,9 @@ public class ReferredPagesPlugin implements WikiPlugin { } //See https://www.w3.org/wiki/HTML_lists for proper nesting of UL and LI - m_result.append("<li> " + TextUtil.replaceEntities(link) + "\n"); - + m_result.append( "<li> " + TextUtil.replaceEntities(link) + "\n" ); getReferredPages( context, link, depth ); // added recursive call - on general request - - m_result.append("\n</li>\n"); - + m_result.append( "\n</li>\n" ); } } else { if( !isUL ) { @@ -236,16 +241,11 @@ public class ReferredPagesPlugin implements WikiPlugin { m_result.append("<ul>\n"); } - String href = context.getURL(WikiContext.VIEW,link); - m_result.append("<li><a class=\"wikipage\" href=\""+ href + "\">" - + TextUtil.replaceEntities(link) + "</a>\n" ); - + final String href = context.getURL( WikiContext.VIEW, link ); + m_result.append( "<li><a class=\"wikipage\" href=\"" + href + "\">" + TextUtil.replaceEntities(link) + "</a>\n" ); m_exists.add( link ); - getReferredPages( context, link, depth ); - - m_result.append("\n</li>\n"); - + m_result.append( "\n</li>\n" ); } } 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 63e3cd8..cb719e3 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 @@ -404,7 +404,7 @@ public class WeblogPlugin if( author != null ) { - if( engine.pageExists(author) ) + if( engine.getPageManager().wikiPageExists(author) ) { author = "<a href=\""+entryCtx.getURL( WikiContext.VIEW, author )+"\">"+engine.beautifyTitle(author)+"</a>"; } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/references/DefaultReferenceManager.java b/jspwiki-main/src/main/java/org/apache/wiki/references/DefaultReferenceManager.java index 8d867cb..803484f 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/references/DefaultReferenceManager.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/references/DefaultReferenceManager.java @@ -468,7 +468,7 @@ public class DefaultReferenceManager extends BasicPageFilter implements Referenc // We won't put it back again if it becomes empty and does not exist. It will be added // later on anyway, if it becomes referenced again. - if( !( refBy.isEmpty() && !m_engine.pageExists( referredPageName ) ) ) { + if( !( refBy.isEmpty() && !m_engine.getPageManager().wikiPageExists( referredPageName ) ) ) { m_referredBy.put( referredPageName, refBy ); } } @@ -604,7 +604,7 @@ public class DefaultReferenceManager extends BasicPageFilter implements Referenc // If the page is referred to by no one AND it doesn't even exist, we might just as well forget about this // entry. It will be added again elsewhere if new references appear. - if( ( oldRefBy == null || oldRefBy.isEmpty() ) && !m_engine.pageExists( referredPage ) ) { + if( ( oldRefBy == null || oldRefBy.isEmpty() ) && !m_engine.getPageManager().wikiPageExists( referredPage ) ) { m_referredBy.remove( referredPage ); } } @@ -728,7 +728,7 @@ public class DefaultReferenceManager extends BasicPageFilter implements Referenc for( final Collection<String> refs : allReferences ) { if( refs != null ) { for( final String aReference : refs ) { - if( !m_engine.pageExists( aReference ) ) { + if( !m_engine.getPageManager().wikiPageExists( aReference ) ) { uncreated.add( aReference ); } } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/AttachmentsIteratorTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/AttachmentsIteratorTag.java index f3e301c..232e4ca 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/AttachmentsIteratorTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/AttachmentsIteratorTag.java @@ -18,12 +18,6 @@ */ package org.apache.wiki.tags; -import java.io.IOException; -import java.util.List; - -import javax.servlet.jsp.JspWriter; -import javax.servlet.jsp.PageContext; - import org.apache.log4j.Logger; import org.apache.wiki.WikiContext; import org.apache.wiki.WikiEngine; @@ -32,6 +26,12 @@ import org.apache.wiki.api.exceptions.ProviderException; import org.apache.wiki.attachment.Attachment; import org.apache.wiki.attachment.AttachmentManager; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.PageContext; +import java.io.IOException; +import java.util.List; + + /** * Iterates through the list of attachments one has. * @@ -42,27 +42,21 @@ import org.apache.wiki.attachment.AttachmentManager; * * @since 2.0 */ - // FIXME: Too much in common with IteratorTag - REFACTOR -public class AttachmentsIteratorTag - extends IteratorTag -{ +public class AttachmentsIteratorTag extends IteratorTag { private static final long serialVersionUID = 0L; - static Logger log = Logger.getLogger( AttachmentsIteratorTag.class ); + private static final Logger log = Logger.getLogger( AttachmentsIteratorTag.class ); /** * {@inheritDoc} */ @Override - public final int doStartTag() - { - m_wikiContext = (WikiContext) pageContext.getAttribute( WikiTagBase.ATTR_CONTEXT, - PageContext.REQUEST_SCOPE ); - - WikiEngine engine = m_wikiContext.getEngine(); - AttachmentManager mgr = engine.getAttachmentManager(); - WikiPage page; + public final int doStartTag() { + m_wikiContext = (WikiContext) pageContext.getAttribute( WikiTagBase.ATTR_CONTEXT, PageContext.REQUEST_SCOPE ); + final WikiEngine engine = m_wikiContext.getEngine(); + final AttachmentManager mgr = engine.getAttachmentManager(); + final WikiPage page; page = m_wikiContext.getPage(); @@ -71,14 +65,11 @@ public class AttachmentsIteratorTag return SKIP_BODY; } - try - { - if( page != null && engine.pageExists(page) ) - { - List< Attachment > atts = mgr.listAttachments( page ); + try { + if( page != null && engine.getPageManager().wikiPageExists(page) ) { + final List< Attachment > atts = mgr.listAttachments( page ); - if( atts == null ) - { + if( atts == null ) { log.debug("No attachments to display."); // There are no attachments included return SKIP_BODY; @@ -86,32 +77,21 @@ public class AttachmentsIteratorTag m_iterator = atts.iterator(); - if( m_iterator.hasNext() ) - { - Attachment att = (Attachment) m_iterator.next(); - - WikiContext context = (WikiContext)m_wikiContext.clone(); + if( m_iterator.hasNext() ) { + final Attachment att = (Attachment) m_iterator.next(); + final WikiContext context = (WikiContext)m_wikiContext.clone(); context.setPage( att ); - pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT, - context, - PageContext.REQUEST_SCOPE ); - + pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE ); pageContext.setAttribute( getId(), att ); - } - else - { + } else { return SKIP_BODY; } - } - else - { + } else { return SKIP_BODY; } return EVAL_BODY_BUFFERED; - } - catch( ProviderException e ) - { + } catch( final ProviderException e ) { log.fatal("Provider failed while trying to iterator through history",e); // FIXME: THrow something. } @@ -123,33 +103,23 @@ public class AttachmentsIteratorTag * {@inheritDoc} */ @Override - public final int doAfterBody() - { - if( bodyContent != null ) - { - try - { - JspWriter out = getPreviousOut(); + public final int doAfterBody() { + if( bodyContent != null ) { + try { + final JspWriter out = getPreviousOut(); out.print(bodyContent.getString()); bodyContent.clearBody(); - } - catch( IOException e ) - { + } catch( final IOException e ) { log.error("Unable to get inner tag text", e); // FIXME: throw something? } } - if( m_iterator != null && m_iterator.hasNext() ) - { - Attachment att = (Attachment) m_iterator.next(); - - WikiContext context = (WikiContext)m_wikiContext.clone(); + if( m_iterator != null && m_iterator.hasNext() ) { + final Attachment att = ( Attachment )m_iterator.next(); + final WikiContext context = ( WikiContext )m_wikiContext.clone(); context.setPage( att ); - pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT, - context, - PageContext.REQUEST_SCOPE ); - + pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE ); pageContext.setAttribute( getId(), att ); return EVAL_BODY_BUFFERED; @@ -157,4 +127,5 @@ public class AttachmentsIteratorTag return SKIP_BODY; } + } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/AuthorTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/AuthorTag.java index 444d187..caac8e3 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/AuthorTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/AuthorTag.java @@ -18,8 +18,6 @@ */ package org.apache.wiki.tags; -import java.io.IOException; - import org.apache.wiki.WikiEngine; import org.apache.wiki.WikiPage; import org.apache.wiki.i18n.InternationalizationManager; @@ -29,21 +27,19 @@ import org.apache.wiki.preferences.Preferences; import org.apache.wiki.render.RenderingManager; import org.apache.wiki.util.TextUtil; +import java.io.IOException; + /** - * Writes the author name of the current page, including a link to that page, - * if that page exists. + * Writes the author name of the current page, including a link to that page, if that page exists. * * @since 2.0 */ -public class AuthorTag - extends WikiTagBase -{ +public class AuthorTag extends WikiTagBase { private static final long serialVersionUID = 0L; - public String m_format = ""; - public void setFormat( String format ) + public void setFormat( final String format ) { m_format = format; //empty or "plain" } @@ -52,40 +48,29 @@ public class AuthorTag * {@inheritDoc} */ @Override - public final int doWikiStartTag() - throws IOException - { - WikiEngine engine = m_wikiContext.getEngine(); - WikiPage page = m_wikiContext.getPage(); - + public final int doWikiStartTag() throws IOException { + final WikiEngine engine = m_wikiContext.getEngine(); + final WikiPage page = m_wikiContext.getPage(); String author = page.getAuthor(); - if( author != null && author.length() > 0 ) - { + if( author != null && author.length() > 0 ) { author = TextUtil.replaceEntities(author); - if( engine.pageExists(author) && !( "plain".equalsIgnoreCase( m_format ) ) ) - { - // FIXME: It's very boring to have to do this. - // Slow, too. - - RenderingManager mgr = engine.getRenderingManager(); - - MarkupParser p = mgr.getParser( m_wikiContext, "["+author+"|"+author+"]" ); - - WikiDocument d = p.parse(); - + if( engine.getPageManager().wikiPageExists(author) && !( "plain".equalsIgnoreCase( m_format ) ) ) { + // FIXME: It's very boring to have to do this. Slow, too. + final RenderingManager mgr = engine.getRenderingManager(); + final MarkupParser p = mgr.getParser( m_wikiContext, "["+author+"|"+author+"]" ); + final WikiDocument d = p.parse(); author = mgr.getHTML( m_wikiContext, d ); } pageContext.getOut().print( author ); - } - else - { + } else { pageContext.getOut().print( Preferences.getBundle( m_wikiContext, InternationalizationManager.CORE_BUNDLE ) .getString( "common.unknownauthor" ) ); } return SKIP_BODY; } + } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/BreadcrumbsTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/BreadcrumbsTag.java index dcdd7d8..0ffa258 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/BreadcrumbsTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/BreadcrumbsTag.java @@ -18,14 +18,12 @@ */ package org.apache.wiki.tags; +import org.apache.log4j.Logger; import org.apache.wiki.WikiContext; import org.apache.wiki.util.TextUtil; import javax.servlet.http.HttpSession; import javax.servlet.jsp.JspWriter; - -import org.apache.log4j.Logger; - import java.io.IOException; import java.io.Serializable; import java.util.LinkedList; @@ -124,7 +122,7 @@ public class BreadcrumbsTag extends WikiTagBase } else { // check if page still exists (could be deleted/renamed by another user) for (int i = 0;i<trail.size();i++) { - if (!m_wikiContext.getEngine().pageExists(trail.get(i))) { + if (!m_wikiContext.getEngine().getPageManager().wikiPageExists(trail.get(i))) { trail.remove(i); } } @@ -132,7 +130,7 @@ public class BreadcrumbsTag extends WikiTagBase if (m_wikiContext.getRequestContext().equals(WikiContext.VIEW)) { - if (m_wikiContext.getEngine().pageExists(page)) + if (m_wikiContext.getEngine().getPageManager().wikiPageExists(page)) { if (trail.isEmpty()) { diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/CalendarTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/CalendarTag.java index f8f19ae..cbfd2f0 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/CalendarTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/CalendarTag.java @@ -144,7 +144,7 @@ public class CalendarTag extends WikiTagBase { if( m_pageFormat != null ) { final String pagename = m_pageFormat.format( day.getTime() ); - if( engine.pageExists( pagename ) ) { + if( engine.getPageManager().wikiPageExists( pagename ) ) { if( m_urlFormat != null ) { final String url = m_urlFormat.format( day.getTime() ); result = "<td class=\"link\"><a href=\""+url+"\">"+day.get( Calendar.DATE )+"</a></td>"; diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/CheckVersionTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/CheckVersionTag.java index 2e170c1..c51bf6f 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/CheckVersionTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/CheckVersionTag.java @@ -21,9 +21,6 @@ package org.apache.wiki.tags; import org.apache.wiki.InternalWikiException; import org.apache.wiki.WikiEngine; import org.apache.wiki.WikiPage; -import org.apache.wiki.api.exceptions.ProviderException; - -import java.io.IOException; /** * Does a version check on the page. Mode is as follows: @@ -37,13 +34,11 @@ import java.io.IOException; * * @since 2.0 */ -public class CheckVersionTag - extends WikiTagBase -{ +public class CheckVersionTag extends WikiTagBase { + private static final long serialVersionUID = 0L; - private static enum VersionMode - { + private enum VersionMode { LATEST, NOTLATEST, FIRST, NOTFIRST } @@ -53,8 +48,7 @@ public class CheckVersionTag * {@inheritDoc} */ @Override - public void initTag() - { + public void initTag() { super.initTag(); m_mode = VersionMode.LATEST; } @@ -64,22 +58,14 @@ public class CheckVersionTag * * @param arg The mode to set. */ - public void setMode( String arg ) - { - if( "latest".equals(arg) ) - { + public void setMode( final String arg ) { + if( "latest".equals(arg) ) { m_mode = VersionMode.LATEST; - } - else if( "notfirst".equals(arg) ) - { + } else if( "notfirst".equals(arg) ) { m_mode = VersionMode.NOTFIRST; - } - else if( "first".equals(arg) ) - { + } else if( "first".equals(arg) ) { m_mode = VersionMode.FIRST; - } - else - { + } else { m_mode = VersionMode.NOTLATEST; } } @@ -88,52 +74,28 @@ public class CheckVersionTag * {@inheritDoc} */ @Override - public final int doWikiStartTag() - throws IOException, - ProviderException - { - WikiEngine engine = m_wikiContext.getEngine(); - WikiPage page = m_wikiContext.getPage(); - - if( page != null && engine.pageExists(page.getName()) ) - { - int version = page.getVersion(); - boolean include = false; - - WikiPage latest = engine.getPageManager().getPage( page.getName() ); - - //log.debug("Doing version check: this="+page.getVersion()+ - // ", latest="+latest.getVersion()); - - switch( m_mode ) - { - case LATEST: - include = (version < 0) || (latest.getVersion() == version); - break; - - case NOTLATEST: - include = (version > 0) && (latest.getVersion() != version); - break; - - case FIRST: - include = (version == 1 ) || (version < 0 && latest.getVersion() == 1); - break; - - case NOTFIRST: - include = version > 1; - break; - - default: - throw new InternalWikiException("Mode which is not available!"); + public final int doWikiStartTag() { + final WikiEngine engine = m_wikiContext.getEngine(); + final WikiPage page = m_wikiContext.getPage(); + + if( page != null && engine.getPageManager().wikiPageExists(page.getName()) ) { + final int version = page.getVersion(); + final boolean include; + final WikiPage latest = engine.getPageManager().getPage( page.getName() ); + + switch( m_mode ) { + case LATEST : include = (version < 0) || (latest.getVersion() == version); break; + case NOTLATEST : include = (version > 0) && (latest.getVersion() != version); break; + case FIRST : include = (version == 1 ) || (version < 0 && latest.getVersion() == 1); break; + case NOTFIRST : include = version > 1; break; + default: throw new InternalWikiException("Mode which is not available!"); } - if( include ) - { - // log.debug("INCLD"); + if( include ) { return EVAL_BODY_INCLUDE; } } - return SKIP_BODY; } + } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/DiffLinkTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/DiffLinkTag.java index 3e9a827..d660c46 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/DiffLinkTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/DiffLinkTag.java @@ -97,7 +97,7 @@ public class DiffLinkTag extends WikiLinkTag { int r2; // In case the page does not exist, we fail silently. - if( !engine.pageExists( pageName ) ) { + if( !engine.getPageManager().wikiPageExists( pageName ) ) { return SKIP_BODY; } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/HasAttachmentsTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/HasAttachmentsTag.java index 3b27a3f..0192b7d 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/HasAttachmentsTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/HasAttachmentsTag.java @@ -18,8 +18,6 @@ */ package org.apache.wiki.tags; -import java.io.IOException; - import org.apache.log4j.Logger; import org.apache.wiki.WikiEngine; import org.apache.wiki.WikiPage; @@ -37,29 +35,23 @@ public class HasAttachmentsTag extends WikiTagBase { private static final long serialVersionUID = 0L; private static final Logger log = Logger.getLogger( HasAttachmentsTag.class ); - public final int doWikiStartTag() - throws IOException - { - WikiEngine engine = m_wikiContext.getEngine(); - WikiPage page = m_wikiContext.getPage(); - AttachmentManager mgr = engine.getAttachmentManager(); - - try - { - if( page != null && engine.pageExists(page) && mgr.attachmentsEnabled() ) - { - if( mgr.hasAttachments(page) ) - { + public final int doWikiStartTag() { + final WikiEngine engine = m_wikiContext.getEngine(); + final WikiPage page = m_wikiContext.getPage(); + final AttachmentManager mgr = engine.getAttachmentManager(); + + try { + if( page != null && engine.getPageManager().wikiPageExists(page) && mgr.attachmentsEnabled() ) { + if( mgr.hasAttachments(page) ) { return EVAL_BODY_INCLUDE; } } - } - catch( ProviderException e ) - { + } catch( final ProviderException e ) { log.fatal("Provider failed while trying to check for attachements",e); // FIXME: THrow something. } return SKIP_BODY; } + } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/HistoryIteratorTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/HistoryIteratorTag.java index 694b4a5..5134cfa 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/HistoryIteratorTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/HistoryIteratorTag.java @@ -52,7 +52,7 @@ public class HistoryIteratorTag extends IteratorTag { final WikiPage page = m_wikiContext.getPage(); try { - if( page != null && engine.pageExists( page ) ) { + if( page != null && engine.getPageManager().wikiPageExists( page ) ) { final List< WikiPage > versions = engine.getPageManager().getVersionHistory( page.getName() ); if( versions == null ) { 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 e7f62d5..2f547b6 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 @@ -94,7 +94,7 @@ public class InsertPageTag extends WikiTagBase { if( m_pageName == null ) { insertedPage = m_wikiContext.getPage(); - if( !engine.pageExists(insertedPage) ) return SKIP_BODY; + if( !engine.getPageManager().wikiPageExists(insertedPage) ) return SKIP_BODY; } else { insertedPage = engine.getPageManager().getPage( m_pageName ); } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/NoSuchPageTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/NoSuchPageTag.java index 8fca495..40bfdb0 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/NoSuchPageTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/NoSuchPageTag.java @@ -60,7 +60,7 @@ public class NoSuchPageTag extends WikiTagBase { page = engine.getPageManager().getPage( m_pageName ); } - if( page != null && engine.pageExists( page.getName(), page.getVersion() ) ) { + if( page != null && engine.getPageManager().wikiPageExists( page.getName(), page.getVersion() ) ) { return SKIP_BODY; } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/PageInfoLinkTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/PageInfoLinkTag.java index 6de2e22..bcc170b 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/PageInfoLinkTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/PageInfoLinkTag.java @@ -18,13 +18,13 @@ */ package org.apache.wiki.tags; -import java.io.IOException; -import javax.servlet.jsp.JspWriter; - import org.apache.wiki.WikiContext; import org.apache.wiki.WikiEngine; import org.apache.wiki.WikiPage; +import javax.servlet.jsp.JspWriter; +import java.io.IOException; + /** * Writes a link to the Wiki PageInfo. Body of the link becomes the actual text. * @@ -38,63 +38,46 @@ import org.apache.wiki.WikiPage; * @since 2.0 */ // FIXME: Refactor together with LinkToTag and EditLinkTag. -public class PageInfoLinkTag - extends WikiLinkTag -{ +public class PageInfoLinkTag extends WikiLinkTag { + private static final long serialVersionUID = 0L; public String m_title = ""; public String m_accesskey = ""; - public void setTitle( String title ) + public void setTitle( final String title ) { m_title = title; } - public void setAccesskey( String access ) + public void setAccesskey( final String access ) { m_accesskey = access; } - public final int doWikiStartTag() - throws IOException - { - WikiEngine engine = m_wikiContext.getEngine(); + public final int doWikiStartTag() throws IOException { + final WikiEngine engine = m_wikiContext.getEngine(); String pageName = m_pageName; - if( m_pageName == null ) - { - WikiPage p = m_wikiContext.getPage(); - - if( p != null ) - { + if( m_pageName == null ) { + final WikiPage p = m_wikiContext.getPage(); + if( p != null ) { pageName = p.getName(); - } - else - { + } else { return SKIP_BODY; } } - if( engine.pageExists(pageName) ) - { - JspWriter out = pageContext.getOut(); - - String url = m_wikiContext.getURL( WikiContext.INFO, pageName ); + if( engine.getPageManager().wikiPageExists(pageName) ) { + final JspWriter out = pageContext.getOut(); + final String url = m_wikiContext.getURL( WikiContext.INFO, pageName ); - switch( m_format ) - { - case ANCHOR: - out.print("<a class=\"pageinfo\" href=\""+url+"\" accesskey=\"" - + m_accesskey + "\" title=\"" + m_title + "\">"); - break; - case URL: - out.print( url ); - break; + switch( m_format ) { + case ANCHOR: out.print("<a class=\"pageinfo\" href=\""+url+"\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\">"); break; + case URL: out.print( url ); break; } - return EVAL_BODY_INCLUDE; } - return SKIP_BODY; } + } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/PageSizeTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/PageSizeTag.java index 617a7ad..0e5764f 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/PageSizeTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/PageSizeTag.java @@ -43,7 +43,7 @@ public class PageSizeTag extends WikiTagBase { if( page != null ) { long size = page.getSize(); - if( size == -1 && engine.pageExists(page) ) { // should never happen with attachments + if( size == -1 && engine.getPageManager().wikiPageExists( page ) ) { // should never happen with attachments size = engine.getPageManager().getPureText( page.getName(), page.getVersion() ).length(); page.setSize( size ); } @@ -57,4 +57,5 @@ public class PageSizeTag extends WikiTagBase { return SKIP_BODY; } + } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/WikiTagBase.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/WikiTagBase.java index a078059..8d2b0be 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/WikiTagBase.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/WikiTagBase.java @@ -18,78 +18,59 @@ */ package org.apache.wiki.tags; +import org.apache.log4j.Logger; +import org.apache.wiki.WikiContext; +import org.apache.wiki.util.TextUtil; + import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.TagSupport; import javax.servlet.jsp.tagext.TryCatchFinally; -import org.apache.log4j.Logger; - -import org.apache.wiki.WikiContext; -import org.apache.wiki.util.TextUtil; /** - * Base class for JSPWiki tags. You do not necessarily have - * to derive from this class, since this does some initialization. + * Base class for JSPWiki tags. You do not necessarily have to derive from this class, since this does some initialization. * <P> - * This tag is only useful if you're having an "empty" tag, with - * no body content. + * This tag is only useful if you're having an "empty" tag, with no body content. * * @since 2.0 */ -public abstract class WikiTagBase - extends TagSupport - implements TryCatchFinally -{ +public abstract class WikiTagBase extends TagSupport implements TryCatchFinally { + private static final long serialVersionUID = -1409836349293777141L; + private static final Logger log = Logger.getLogger( WikiTagBase.class ); public static final String ATTR_CONTEXT = "jspwiki.context"; - private static final Logger log = Logger.getLogger( WikiTagBase.class ); - protected WikiContext m_wikiContext; /** - * This method calls the parent setPageContext() but it also - * provides a way for a tag to initialize itself before - * any of the setXXX() methods are called. + * This method calls the parent setPageContext() but it also provides a way for a tag to initialize itself before + * any of the setXXX() methods are called. */ - public void setPageContext(PageContext arg0) - { - super.setPageContext(arg0); - + public void setPageContext( final PageContext arg0 ) { + super.setPageContext( arg0 ); initTag(); } /** - * This method is called when the tag is encountered within a new request, - * but before the setXXX() methods are called. + * This method is called when the tag is encountered within a new request, but before the setXXX() methods are called. * The default implementation does nothing. * @since 2.3.92 */ - public void initTag() - { + public void initTag() { m_wikiContext = null; - return; } - public int doStartTag() - throws JspException - { - try - { - m_wikiContext = (WikiContext) pageContext.getAttribute( ATTR_CONTEXT, - PageContext.REQUEST_SCOPE ); - - if( m_wikiContext == null ) - { + public int doStartTag() throws JspException { + try { + m_wikiContext = ( WikiContext )pageContext.getAttribute( ATTR_CONTEXT, PageContext.REQUEST_SCOPE ); + if( m_wikiContext == null ) { throw new JspException("WikiContext may not be NULL - serious internal problem!"); } return doWikiStartTag(); - } - catch( Exception e ) - { + } catch( final Exception e ) { log.error( "Tag failed", e ); throw new JspException( "Tag failed, check logs: "+e.getMessage() ); } @@ -101,14 +82,11 @@ public abstract class WikiTagBase */ public abstract int doWikiStartTag() throws Exception; - public int doEndTag() - throws JspException - { + public int doEndTag() throws JspException { return EVAL_PAGE; } - public void doCatch( Throwable th ) throws Throwable - { + public void doCatch( final Throwable th ) throws Throwable { log.error( th.getMessage(), th ); } @@ -117,7 +95,7 @@ public abstract class WikiTagBase m_wikiContext = null; } - public void setId(String id) + public void setId( final String id) { super.setId( TextUtil.replaceEntities( id ) ); } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tasks/TasksManager.java b/jspwiki-main/src/main/java/org/apache/wiki/tasks/TasksManager.java index 70ab717..f2a7b61 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tasks/TasksManager.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tasks/TasksManager.java @@ -18,19 +18,18 @@ */ package org.apache.wiki.tasks; -import java.security.Principal; -import java.util.Locale; - import org.apache.wiki.WikiContext; import org.apache.wiki.WikiEngine; import org.apache.wiki.workflow.Step; -import org.apache.wiki.workflow.Task; + +import java.security.Principal; +import java.util.Locale; /** * Manager responsible of creation of the different JSPWiki {@link Step}s. * * Instances of classes generated by this TasksManager are assumed to have been added to an approval workflow via - * {@link org.apache.wiki.workflow.WorkflowBuilder#buildApprovalWorkflow(Principal, String, Task, String, org.apache.wiki.workflow.Fact[], Task, String)}; + * {@link org.apache.wiki.workflow.WorkflowBuilder#buildApprovalWorkflow(Principal, String, Step, String, org.apache.wiki.workflow.Fact[], Step, String)}; * they will not function correctly otherwise. */ public interface TasksManager { 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 3ab3355..b197d1d 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 @@ -34,7 +34,6 @@ import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.Hashtable; -import java.util.Iterator; import java.util.Set; import java.util.Vector; @@ -43,21 +42,10 @@ import java.util.Vector; * * @since 1.6.6 */ -// We could use WikiEngine directly, but because of introspection it would -// show just too many methods to be safe. -public class RPCHandler - extends AbstractRPCHandler -{ - private static Logger log = Logger.getLogger( RPCHandler.class ); +// We could use WikiEngine directly, but because of introspection it would show just too many methods to be safe. +public class RPCHandler extends AbstractRPCHandler { - /** - * {@inheritDoc} - */ - @Override - public void initialize( WikiContext ctx ) - { - super.initialize( ctx ); - } + private static final Logger log = Logger.getLogger( RPCHandler.class ); /** * Converts Java string into RPC string. @@ -83,23 +71,19 @@ public class RPCHandler return src.getBytes( StandardCharsets.UTF_8 ); } - public String getApplicationName() - { + public String getApplicationName() { checkPermission( PagePermission.VIEW ); return toRPCString(m_engine.getApplicationName()); } - public Vector getAllPages() - { + public Vector getAllPages() { checkPermission( PagePermission.VIEW ); Collection< WikiPage > pages = m_engine.getPageManager().getRecentChanges(); Vector<String> result = new Vector<>(); - for( WikiPage p : pages ) - { - if( !(p instanceof Attachment) ) - { - result.add( toRPCString(p.getName()) ); + for( final WikiPage p : pages ) { + if( !( p instanceof Attachment ) ) { + result.add( toRPCString( p.getName() ) ); } } @@ -181,7 +165,7 @@ public class RPCHandler { pagename = fromRPCString( pagename ); - if( !m_engine.pageExists(pagename) ) + if( !m_engine.getPageManager().wikiPageExists(pagename) ) { throw new XmlRpcException( ERR_NOPAGE, "No such page '"+pagename+"' found, o master." ); } @@ -229,17 +213,13 @@ public class RPCHandler return toRPCBase64( m_engine.getHTML( pagename ) ); } - public byte[] getPageHTMLVersion( String pagename, int version ) - throws XmlRpcException - { + public byte[] getPageHTMLVersion( String pagename, int version ) throws XmlRpcException { pagename = parsePageCheckCondition( pagename ); return toRPCBase64( m_engine.getHTML( pagename, version ) ); } - public Vector listLinks( String pagename ) - throws XmlRpcException - { + public Vector listLinks( String pagename ) throws XmlRpcException { pagename = parsePageCheckCondition( pagename ); WikiPage page = m_engine.getPageManager().getPage( pagename ); @@ -252,21 +232,15 @@ public class RPCHandler WikiContext context = new WikiContext( m_engine, page ); context.setVariable( WikiEngine.PROP_REFSTYLE, "absolute" ); - m_engine.textToHTML( context, - pagedata, - localCollector, - extCollector, - attCollector ); + m_engine.textToHTML( context, pagedata, localCollector, extCollector, attCollector ); Vector<Hashtable<String, String>> result = new Vector<>(); // // Add local links. // - for( Iterator< String > i = localCollector.getLinks().iterator(); i.hasNext(); ) - { - String link = i.next(); - Hashtable< String, String > ht = new Hashtable<>(); + for( final String link : localCollector.getLinks() ) { + Hashtable<String, String> ht = new Hashtable<>(); ht.put( "page", toRPCString( link ) ); ht.put( "type", LINK_LOCAL ); @@ -277,17 +251,13 @@ public class RPCHandler // // - // FIXME: The current link collector interface is not very good, since - // it causes this. + // FIXME: The current link collector interface is not very good, since it causes this. // - if( m_engine.pageExists(link) ) - { - ht.put( "href", context.getURL(WikiContext.VIEW,link) ); - } - else - { - ht.put( "href", context.getURL(WikiContext.EDIT,link) ); + if( m_engine.getPageManager().wikiPageExists( link ) ) { + ht.put( "href", context.getURL( WikiContext.VIEW, link ) ); + } else { + ht.put( "href", context.getURL( WikiContext.EDIT, link ) ); } result.add( ht ); @@ -296,37 +266,26 @@ public class RPCHandler // // Add links to inline attachments // - for( Iterator< String > i = attCollector.getLinks().iterator(); i.hasNext(); ) - { - String link = i.next(); - - Hashtable< String, String > ht = new Hashtable< >(); - + for( String link : attCollector.getLinks() ) { + Hashtable<String, String> ht = new Hashtable<>(); ht.put( "page", toRPCString( link ) ); ht.put( "type", LINK_LOCAL ); ht.put( "href", context.getURL( WikiContext.ATTACH, link ) ); - result.add( ht ); } // - // External links don't need to be changed into XML-RPC strings, - // simply because URLs are by definition ASCII. + // External links don't need to be changed into XML-RPC strings, simply because URLs are by definition ASCII. // - - for( Iterator< String > i = extCollector.getLinks().iterator(); i.hasNext(); ) - { - String link = i.next(); - - Hashtable< String, String > ht = new Hashtable< >(); - + for( String link : extCollector.getLinks() ) { + Hashtable<String, String> ht = new Hashtable<>(); ht.put( "page", link ); ht.put( "type", LINK_EXTERNAL ); ht.put( "href", link ); - result.add( ht ); } return result; } + } 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 0390aff..b5a5c0f 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 @@ -126,7 +126,7 @@ public class RPCHandlerUTF8 extends AbstractRPCHandler { * @throws XmlRpcException, if there is something wrong with the page. */ private String parsePageCheckCondition( final String pagename ) throws XmlRpcException { - if( !m_engine.pageExists(pagename) ) { + if( !m_engine.getPageManager().wikiPageExists(pagename) ) { throw new XmlRpcException( ERR_NOPAGE, "No such page '"+pagename+"' found, o master." ); } @@ -189,7 +189,7 @@ public class RPCHandlerUTF8 extends AbstractRPCHandler { ht.put( "page", link ); ht.put( "type", LINK_LOCAL ); - if( m_engine.pageExists( link ) ) { + if( m_engine.getPageManager().wikiPageExists( link ) ) { ht.put( "href", context.getViewURL( link ) ); } else { ht.put( "href", context.getURL( WikiContext.EDIT, link ) ); 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 6ecffce..d2718b0 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java @@ -25,7 +25,6 @@ import org.apache.wiki.attachment.AttachmentManager; import org.apache.wiki.pages.PageManager; import org.apache.wiki.providers.FileSystemProvider; import org.apache.wiki.references.ReferenceManager; -import org.apache.wiki.util.TextUtil; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -76,23 +75,6 @@ public class WikiEngineTest { f.delete(); } - /** - * Check that calling pageExists( String ) works. - */ - @Test - public void testNonExistentPage() { - Assertions.assertFalse( m_engine.pageExists( NAME1 ), "Page already exists" ); - } - - /** - * Check that calling pageExists( WikiPage ) works. - */ - @Test - public void testNonExistentPage2() throws Exception { - final WikiPage page = new WikiPage(m_engine, NAME1 ); - Assertions.assertFalse( m_engine.pageExists( page ), "Page already exists" ); - } - @Test public void testFinalPageName() throws Exception { m_engine.saveText( "Foobar", "1" ); @@ -370,8 +352,8 @@ public class WikiEngineTest { final WikiContext ctx = new WikiContext( m_engine, m_engine.getPageManager().getPage("OldNameTestPage") ); m_engine.getPageRenamer().renamePage( ctx, "OldNameTestPage", "NewNameTestPage", true ); - Assertions.assertFalse( m_engine.pageExists( "OldNameTestPage"), "did not vanish" ); - Assertions.assertTrue( m_engine.pageExists( "NewNameTestPage"), "did not appear" ); + Assertions.assertFalse( m_engine.getPageManager().wikiPageExists( "OldNameTestPage"), "did not vanish" ); + Assertions.assertTrue( m_engine.getPageManager().wikiPageExists( "NewNameTestPage"), "did not appear" ); pages = m_engine.getReferenceManager().findReferrers( "RenameBugTestPage" ); Assertions.assertEquals( 1, pages.size(), "wrong # of referrers" ); @@ -396,24 +378,4 @@ public class WikiEngineTest { Assertions.assertNull( p3.getAttribute( WikiPage.CHANGENOTE ) ); } - @Test - public void testCreatePage() throws Exception { - final String text = "Foobar.\r\n"; - final String name = "mrmyxpltz"; - Assertions.assertFalse( m_engine.pageExists( name ), "page should not exist right now" ); - - m_engine.saveText( name, text ); - Assertions.assertTrue( m_engine.pageExists( name ), "page does not exist" ); - } - - @Test - public void testCreateEmptyPage() throws Exception { - final String text = ""; - final String name = "mrmxyzptlk"; - Assertions.assertFalse( m_engine.pageExists( name ), "page should not exist right now" ); - - m_engine.saveText( name, text ); - Assertions.assertFalse( m_engine.pageExists( name ), "page should not exist right now neither" ); - } - } diff --git a/jspwiki-main/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java b/jspwiki-main/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java index 8128b47..46a5ece 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java @@ -289,7 +289,7 @@ public class AttachmentManagerTest m_manager.storeAttachment( att, makeAttachmentFile() ); - Assertions.assertTrue( m_engine.pageExists( NAME1+"/test1" ), "attachment disappeared" ); + Assertions.assertTrue( m_engine.getPageManager().wikiPageExists( NAME1+"/test1" ), "attachment disappeared" ); } @Test @@ -301,7 +301,7 @@ public class AttachmentManagerTest m_manager.storeAttachment( att, makeAttachmentFile() ); - Assertions.assertTrue( m_engine.pageExists( att.getName() ), "attachment disappeared" ); + Assertions.assertTrue( m_engine.getPageManager().wikiPageExists( att.getName() ), "attachment disappeared" ); } @Test @@ -313,7 +313,7 @@ public class AttachmentManagerTest m_manager.storeAttachment( att, makeAttachmentFile() ); - Assertions.assertTrue( m_engine.pageExists( NAME1+"/test file.bin" ), "attachment disappeared" ); + Assertions.assertTrue( m_engine.getPageManager().wikiPageExists( NAME1+"/test file.bin" ), "attachment disappeared" ); } @Test @@ -325,7 +325,7 @@ public class AttachmentManagerTest m_manager.storeAttachment( att, makeAttachmentFile() ); - Assertions.assertTrue( m_engine.pageExists( att.getName() ), "attachment disappeared" ); + Assertions.assertTrue( m_engine.getPageManager().wikiPageExists( att.getName() ), "attachment disappeared" ); } @Test @@ -337,7 +337,7 @@ public class AttachmentManagerTest m_manager.storeAttachment( att, makeAttachmentFile() ); - Assertions.assertTrue( m_engine.pageExists( att.getName() ), "attachment disappeared" ); + Assertions.assertTrue( m_engine.getPageManager().wikiPageExists( att.getName() ), "attachment disappeared" ); } @Test 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 6d934e4..1897db6 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 @@ -57,6 +57,23 @@ public class DefaultPageManagerTest { CacheManager.getInstance().removeAllCaches(); } + /** + * Check that calling pageExists( String ) works. + */ + @Test + public void testNonExistentPage() { + Assertions.assertFalse( engine.getPageManager().wikiPageExists( NAME1 ), "Page already exists" ); + } + + /** + * Check that calling pageExists( WikiPage ) works. + */ + @Test + public void testNonExistentPage2() throws Exception { + final WikiPage page = new WikiPage( engine, NAME1 ); + Assertions.assertFalse( engine.getPageManager().wikiPageExists( page ), "Page already exists" ); + } + @Test public void testPageCacheExists() throws Exception { engine.getWikiProperties().setProperty( "jspwiki.usePageCache", "true" ); @@ -231,12 +248,32 @@ public class DefaultPageManagerTest { } @Test + public void testCreatePage() throws Exception { + final String text = "Foobar.\r\n"; + final String name = "mrmyxpltz"; + Assertions.assertFalse( engine.getPageManager().wikiPageExists( name ), "page should not exist right now" ); + + engine.saveText( name, text ); + Assertions.assertTrue( engine.getPageManager().wikiPageExists( name ), "page does not exist" ); + } + + @Test + public void testCreateEmptyPage() throws Exception { + final String text = ""; + final String name = "mrmxyzptlk"; + Assertions.assertFalse( engine.getPageManager().wikiPageExists( name ), "page should not exist right now" ); + + engine.saveText( name, text ); + Assertions.assertFalse( engine.getPageManager().wikiPageExists( name ), "page should not exist right now neither" ); + } + + @Test public void testPutPage() throws Exception { final String text = "Foobar.\r\n"; final String name = NAME1; engine.saveText( name, text ); - Assertions.assertTrue( engine.pageExists( name ), "page does not exist" ); + Assertions.assertTrue( engine.getPageManager().wikiPageExists( name ), "page does not exist" ); Assertions.assertEquals( text, engine.getPageManager().getText( name ), "wrong content" ); } @@ -246,7 +283,7 @@ public class DefaultPageManagerTest { final String name = NAME1; engine.saveText( name, text ); - Assertions.assertTrue( engine.pageExists( name ), "page does not exist" ); + Assertions.assertTrue( engine.getPageManager().wikiPageExists( name ), "page does not exist" ); Assertions.assertEquals( "Foobar. &quot;\r\n", engine.getPageManager().getText( name ), "wrong content" ); } @@ -259,7 +296,7 @@ public class DefaultPageManagerTest { final String name = NAME1; engine.saveText( name, text ); - Assertions.assertTrue( engine.pageExists( name ), "page does not exist" ); + Assertions.assertTrue( engine.getPageManager().wikiPageExists( name ), "page does not exist" ); Assertions.assertEquals( "Foobar. "\r\n", engine.getPageManager().getText( name ), "wrong content" ); } @@ -269,7 +306,7 @@ public class DefaultPageManagerTest { final String name = NAME1; engine.saveText( name, text ); - Assertions.assertTrue( engine.pageExists( name ), "page does not exist" ); + Assertions.assertTrue( engine.getPageManager().wikiPageExists( name ), "page does not exist" ); // saveText uses normalizePostData to assure it conforms to certain rules Assertions.assertEquals( TextUtil.normalizePostData( text ), engine.getPageManager().getText( name ), "wrong content" ); diff --git a/jspwiki-main/src/test/java/org/apache/wiki/workflow/ApprovalWorkflowTest.java b/jspwiki-main/src/test/java/org/apache/wiki/workflow/ApprovalWorkflowTest.java index 5e03505..a149a57 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/workflow/ApprovalWorkflowTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/workflow/ApprovalWorkflowTest.java @@ -194,7 +194,7 @@ public class ApprovalWorkflowTest { } // How do we know the workflow works? Well, first of all the page shouldn't exist yet... - Assertions.assertFalse( m_engine.pageExists(pageName)); + Assertions.assertFalse( m_engine.getPageManager().wikiPageExists(pageName)); // Second, GroupPrincipal Admin should see a Decision in its queue Collection< Decision > decisions = m_dq.getActorDecisions( m_engine.adminSession() ); @@ -203,7 +203,7 @@ public class ApprovalWorkflowTest { // Now, approve the decision and it should go away, and page should appear. Decision decision = (Decision)decisions.iterator().next(); decision.decide(Outcome.DECISION_APPROVE); - Assertions.assertTrue( m_engine.pageExists(pageName)); + Assertions.assertTrue( m_engine.getPageManager().wikiPageExists(pageName)); decisions = m_dq.getActorDecisions( m_engine.adminSession() ); Assertions.assertEquals(0, decisions.size()); @@ -227,7 +227,7 @@ public class ApprovalWorkflowTest { } // How do we know the workflow works? Well, first of all the page shouldn't exist yet... - Assertions.assertFalse( m_engine.pageExists(pageName)); + Assertions.assertFalse( m_engine.getPageManager().wikiPageExists(pageName)); // ...and there should be a Decision in GroupPrincipal Admin's queue Collection< Decision > decisions = m_dq.getActorDecisions( m_engine.adminSession() ); @@ -236,7 +236,7 @@ public class ApprovalWorkflowTest { // Now, DENY the decision and the page should still not exist... Decision decision = (Decision)decisions.iterator().next(); decision.decide(Outcome.DECISION_DENY); - Assertions.assertFalse( m_engine.pageExists(pageName) ); + Assertions.assertFalse( m_engine.getPageManager().wikiPageExists(pageName) ); // ...but there should also be a notification decision in Janne's queue decisions = m_dq.getActorDecisions( m_engine.janneSession() ); diff --git a/jspwiki-war/src/main/webapp/Login.jsp b/jspwiki-war/src/main/webapp/Login.jsp index 8d44a3a..35d0ec2 100644 --- a/jspwiki-war/src/main/webapp/Login.jsp +++ b/jspwiki-war/src/main/webapp/Login.jsp @@ -179,8 +179,7 @@ // If wiki page was "Login", redirect to main, otherwise use the page supplied String redirectPage = request.getParameter( "redirect" ); - if( !wiki.pageExists( redirectPage ) ) - { + if( !wiki.getPageManager().wikiPageExists( redirectPage ) ) { redirectPage = wiki.getFrontPage(); } String viewUrl = ( "Login".equals( redirectPage ) ) ? "Wiki.jsp" : wiki.getViewURL( redirectPage ); diff --git a/jspwiki-war/src/main/webapp/UserPreferences.jsp b/jspwiki-war/src/main/webapp/UserPreferences.jsp index 700d0b0..7f58ded 100644 --- a/jspwiki-war/src/main/webapp/UserPreferences.jsp +++ b/jspwiki-war/src/main/webapp/UserPreferences.jsp @@ -97,7 +97,7 @@ { String redirectPage = request.getParameter( "redirect" ); - if( !wiki.pageExists( redirectPage ) ) + if( !wiki.getPageManager().wikiPageExists( redirectPage ) ) { redirectPage = wiki.getFrontPage(); } @@ -116,7 +116,7 @@ CookieAssertionLoginModule.setUserCookie( response, assertedName ); String redirectPage = request.getParameter( "redirect" ); - if( !wiki.pageExists( redirectPage ) ) + if( !wiki.getPageManager().wikiPageExists( redirectPage ) ) { redirectPage = wiki.getFrontPage(); } diff --git a/jspwiki-war/src/main/webapp/rss.jsp b/jspwiki-war/src/main/webapp/rss.jsp index 95f1570..0adb70c 100644 --- a/jspwiki-war/src/main/webapp/rss.jsp +++ b/jspwiki-war/src/main/webapp/rss.jsp @@ -61,7 +61,7 @@ return; } - if( wikipage == null || !wiki.pageExists(wikipage.getName()) ) + if( wikipage == null || !wiki.getPageManager().wikiPageExists(wikipage.getName()) ) { response.sendError( 404, "No such page "+wikipage.getName() ); return;
