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 1683e30e960db97addabf47b7292dd176fadb328 Author: juanpablo <[email protected]> AuthorDate: Mon Jan 13 21:52:36 2020 +0100 JSPWIKI-120: move beautifyTitle and beautifyTitleNoBreak from WikiEngine to PageManager --- .../src/main/java/org/apache/wiki/WikiEngine.java | 54 ------------- .../apache/wiki/plugin/AbstractReferralPlugin.java | 2 +- .../org/apache/wiki/plugin/PageViewPlugin.java | 2 +- .../apache/wiki/plugin/RecentChangesPlugin.java | 93 ++++++++++------------ .../main/java/org/apache/wiki/plugin/Search.java | 20 ++--- .../java/org/apache/wiki/plugin/WeblogPlugin.java | 2 +- .../wiki/render/DefaultRenderingManager.java | 40 ++++++++++ .../org/apache/wiki/render/RenderingManager.java | 26 +++++- .../java/org/apache/wiki/tags/PageNameTag.java | 30 +++---- .../org/apache/wiki/tags/ParentPageNameTag.java | 48 +++++------ .../test/java/org/apache/wiki/WikiEngineTest.java | 45 ----------- .../wiki/parser/JSPWikiMarkupParserTest.java | 24 +++--- .../apache/wiki/render/RenderingManagerTest.java | 45 +++++++++++ 13 files changed, 204 insertions(+), 227 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 0cae15a..fb9bdc5 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java @@ -28,7 +28,6 @@ import org.apache.wiki.api.engine.PluginManager; import org.apache.wiki.api.exceptions.FilterException; 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.AuthenticationManager; import org.apache.wiki.auth.AuthorizationManager; @@ -62,12 +61,6 @@ import org.apache.wiki.util.ClassUtil; import org.apache.wiki.util.PropertyReader; import org.apache.wiki.util.TextUtil; import org.apache.wiki.variables.VariableManager; -import org.apache.wiki.workflow.Decision; -import org.apache.wiki.workflow.DecisionRequiredException; -import org.apache.wiki.workflow.Fact; -import org.apache.wiki.workflow.Step; -import org.apache.wiki.workflow.Workflow; -import org.apache.wiki.workflow.WorkflowBuilder; import org.apache.wiki.workflow.WorkflowManager; import javax.servlet.ServletConfig; @@ -82,7 +75,6 @@ import java.net.URLDecoder; import java.net.URLEncoder; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.security.Principal; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -149,9 +141,6 @@ public class WikiEngine { /** The name for the property which allows you to set the current reference style. The value is {@value}. */ public static final String PROP_REFSTYLE = "jspwiki.referenceStyle"; - /** Property name for the "spaces in titles" -hack. */ - public static final String PROP_BEAUTIFYTITLE = "jspwiki.breakTitleWithSpaces"; - /** Property name for where the jspwiki work directory should be. If not specified, reverts to ${java.tmpdir}. */ public static final String PROP_WORKDIR = "jspwiki.workDir"; @@ -491,7 +480,6 @@ public class WikiEngine { m_saveUserInfo = TextUtil.getBooleanProperty( props, PROP_STOREUSERNAME, m_saveUserInfo ); m_useUTF8 = StandardCharsets.UTF_8.name().equals( TextUtil.getStringProperty( props, PROP_ENCODING, StandardCharsets.ISO_8859_1.name() ) ); - m_beautifyTitle = TextUtil.getBooleanProperty( props, PROP_BEAUTIFYTITLE, m_beautifyTitle ); m_templateDir = TextUtil.getStringProperty( props, PROP_TEMPLATEDIR, "default" ); enforceValidTemplateDirectory(); m_frontPage = TextUtil.getStringProperty( props, PROP_FRONTPAGE, "Main" ); @@ -875,48 +863,6 @@ public class WikiEngine { } /** - * Beautifies the title of the page by appending spaces in suitable places, if the user has so decreed in the properties when - * constructing this WikiEngine. However, attachment names are only beautified by the name. - * - * @param title The title to beautify - * @return A beautified title (or, if beautification is off, returns the title without modification) - * @since 1.7.11 - */ - public String beautifyTitle( final String title ) { - if( m_beautifyTitle ) { - try { - final Attachment att = m_attachmentManager.getAttachmentInfo( title ); - if( att == null ) { - return TextUtil.beautifyString( title ); - } - - final String parent = TextUtil.beautifyString( att.getParentName() ); - return parent + "/" + att.getFileName(); - } catch( final ProviderException e ) { - return title; - } - } - - return title; - } - - /** - * 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( final String title ) { - if( m_beautifyTitle ) { - return TextUtil.beautifyString( title, " " ); - } - - return title; - } - - /** * 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 diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/AbstractReferralPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/AbstractReferralPlugin.java index 5bc2871..3260cb8 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/AbstractReferralPlugin.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/AbstractReferralPlugin.java @@ -385,7 +385,7 @@ public abstract class AbstractReferralPlugin implements WikiPlugin output.append( m_before ); // Make a Wiki markup link. See TranslatorReader. - output.append( "[" + m_engine.beautifyTitle(value) + "|" + value + "]" ); + output.append( "[" + m_engine.getRenderingManager().beautifyTitle(value) + "|" + value + "]" ); count++; } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/PageViewPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/PageViewPlugin.java index 266297a..12f312b 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/PageViewPlugin.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/PageViewPlugin.java @@ -506,7 +506,7 @@ public class PageViewPlugin extends AbstractReferralPlugin implements WikiPlugin if( use ) { - args[1] = engine.beautifyTitle( name ); + args[1] = engine.getRenderingManager().beautifyTitle( name ); args[2] = entry.getValue(); fmt.format( args, buf, null ); 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 f768f2a..d68b0db 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 @@ -40,7 +40,6 @@ import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.GregorianCalendar; -import java.util.Iterator; import java.util.Map; @@ -75,26 +74,26 @@ public class RecentChangesPlugin extends AbstractReferralPlugin implements WikiP /** * {@inheritDoc} */ - public String execute( WikiContext context, Map<String, String> params ) throws PluginException { - int since = TextUtil.parseIntParameter( params.get( "since" ), DEFAULT_DAYS ); - String spacing = "4"; - boolean showAuthor = true; - boolean showChangenote = true; - String tablewidth = "4"; + public String execute( final WikiContext context, final Map< String, String > params ) throws PluginException { + final int since = TextUtil.parseIntParameter( params.get( "since" ), DEFAULT_DAYS ); + String spacing = "4"; + boolean showAuthor = true; + boolean showChangenote = true; + String tablewidth = "4"; - WikiEngine engine = context.getEngine(); + final WikiEngine engine = context.getEngine(); // // Which format we want to see? // - if( "compact".equals( params.get(PARAM_FORMAT) ) ) { + if( "compact".equals( params.get( PARAM_FORMAT ) ) ) { spacing = "0"; showAuthor = false; showChangenote = false; tablewidth = "2"; } - Calendar sincedate = new GregorianCalendar(); + final Calendar sincedate = new GregorianCalendar(); sincedate.add( Calendar.DAY_OF_MONTH, -since ); log.debug("Calculating recent changes from "+sincedate.getTime()); @@ -107,24 +106,23 @@ public class RecentChangesPlugin extends AbstractReferralPlugin implements WikiP if ( changes != null ) { Date olddate = new Date( 0 ); - DateFormat fmt = getDateFormat( context, params ); - DateFormat tfmt = getTimeFormat( context, params ); + final DateFormat fmt = getDateFormat( context, params ); + final DateFormat tfmt = getTimeFormat( context, params ); - Element rt = XhtmlUtil.element( XHTML.table ); + final Element rt = XhtmlUtil.element( XHTML.table ); rt.setAttribute( XHTML.ATTR_class, "recentchanges" ); rt.setAttribute( XHTML.ATTR_cellpadding, spacing ); - - for( Iterator< WikiPage > i = changes.iterator(); i.hasNext(); ) { - WikiPage pageref = i.next(); - Date lastmod = pageref.getLastModified(); + + for( final WikiPage pageref : changes ) { + final Date lastmod = pageref.getLastModified(); if( lastmod.before( sincedate.getTime() ) ) { break; } - + if( !isSameDay( lastmod, olddate ) ) { - Element row = XhtmlUtil.element( XHTML.tr ); - Element col = XhtmlUtil.element( XHTML.td ); + final Element row = XhtmlUtil.element( XHTML.tr ); + final Element col = XhtmlUtil.element( XHTML.td ); col.setAttribute( XHTML.ATTR_colspan, tablewidth ); col.setAttribute( XHTML.ATTR_class, "date" ); col.addContent( XhtmlUtil.element( XHTML.b, fmt.format( lastmod ) ) ); @@ -134,16 +132,13 @@ public class RecentChangesPlugin extends AbstractReferralPlugin implements WikiP olddate = lastmod; } - String href = context.getURL( pageref instanceof Attachment ? WikiContext.ATTACH : WikiContext.VIEW, - pageref.getName() ) ; - - Element link = XhtmlUtil.link( href, engine.beautifyTitle( pageref.getName() ) ); - - Element row = XhtmlUtil.element( XHTML.tr ); - Element col = XhtmlUtil.element( XHTML.td ); + final String href = context.getURL( pageref instanceof Attachment ? WikiContext.ATTACH : WikiContext.VIEW, pageref.getName() ); + Element link = XhtmlUtil.link( href, engine.getRenderingManager().beautifyTitle( pageref.getName() ) ); + final Element row = XhtmlUtil.element( XHTML.tr ); + final Element col = XhtmlUtil.element( XHTML.td ); col.setAttribute( XHTML.ATTR_width, "30%" ); col.addContent( link ); - + // // Add the direct link to the attachment info. // @@ -151,7 +146,7 @@ public class RecentChangesPlugin extends AbstractReferralPlugin implements WikiP link = XhtmlUtil.link( context.getURL( WikiContext.INFO, pageref.getName() ), null ); link.setAttribute( XHTML.ATTR_class, "infolink" ); - Element img = XhtmlUtil.img( context.getURL( WikiContext.NONE, "images/attachment_small.png" ), null ); + final Element img = XhtmlUtil.img( context.getURL( WikiContext.NONE, "images/attachment_small.png" ), null ); link.addContent( img ); col.addContent( link ); @@ -159,28 +154,28 @@ public class RecentChangesPlugin extends AbstractReferralPlugin implements WikiP row.addContent( col ); rt.addContent( row ); - + if( pageref instanceof Attachment ) { - Element td = XhtmlUtil.element( XHTML.td, tfmt.format( lastmod ) ); + final Element td = XhtmlUtil.element( XHTML.td, tfmt.format( lastmod ) ); td.setAttribute( XHTML.ATTR_class, "lastchange" ); row.addContent( td ); } else { - Element infocol = XhtmlUtil.element( XHTML.td ); + final Element infocol = XhtmlUtil.element( XHTML.td ); infocol.setAttribute( XHTML.ATTR_class, "lastchange" ); - infocol.addContent( XhtmlUtil.link( context.getURL( WikiContext.DIFF, pageref.getName(), "r1=-1" ), tfmt.format( lastmod ) ) ); + infocol.addContent( XhtmlUtil.link( context.getURL( WikiContext.DIFF, pageref.getName(), "r1=-1" ), + tfmt.format( lastmod ) ) ); row.addContent( infocol ); } // // Display author information. // - if( showAuthor ) { - String author = pageref.getAuthor(); + final String author = pageref.getAuthor(); - Element authorinfo = XhtmlUtil.element( XHTML.td ); + final Element authorinfo = XhtmlUtil.element( XHTML.td ); authorinfo.setAttribute( XHTML.ATTR_class, "author" ); - + if( author != null ) { if( engine.getPageManager().wikiPageExists( author ) ) { authorinfo.addContent( XhtmlUtil.link( context.getURL( WikiContext.VIEW, author ), author ) ); @@ -189,7 +184,7 @@ public class RecentChangesPlugin extends AbstractReferralPlugin implements WikiP } } else { authorinfo.addContent( Preferences.getBundle( context, InternationalizationManager.CORE_BUNDLE ) - .getString( "common.unknownauthor" ) ); + .getString( "common.unknownauthor" ) ); } row.addContent( authorinfo ); @@ -202,7 +197,7 @@ public class RecentChangesPlugin extends AbstractReferralPlugin implements WikiP td_changenote.setAttribute( XHTML.ATTR_class, "changenote" ); row.addContent( td_changenote ); } - + // Revert note /* if( context.hasAdminPermissions() ) @@ -217,9 +212,9 @@ public class RecentChangesPlugin extends AbstractReferralPlugin implements WikiP } - private boolean isSameDay( Date a, Date b ) { - Calendar aa = Calendar.getInstance(); aa.setTime( a ); - Calendar bb = Calendar.getInstance(); bb.setTime( b ); + private boolean isSameDay( final Date a, final Date b ) { + final Calendar aa = Calendar.getInstance(); aa.setTime( a ); + final Calendar bb = Calendar.getInstance(); bb.setTime( b ); return aa.get( Calendar.YEAR ) == bb.get( Calendar.YEAR ) && aa.get( Calendar.DAY_OF_YEAR ) == bb.get( Calendar.DAY_OF_YEAR ); @@ -230,9 +225,8 @@ public class RecentChangesPlugin extends AbstractReferralPlugin implements WikiP // locale, but that is at odds with the 1st version of this plugin. We seek to preserve the // behaviour of that first version, so to get the default format, the user must explicitly do // something like: dateFormat='' timeformat='' which is a odd, but probably okay. - private DateFormat getTimeFormat( WikiContext context, Map<String, String> params ) { - String formatString = get( params, DEFAULT_TIME_FORMAT, PARAM_TIME_FORMAT ); - + private DateFormat getTimeFormat( final WikiContext context, final Map< String, String > params ) { + final String formatString = get( params, DEFAULT_TIME_FORMAT, PARAM_TIME_FORMAT ); if( StringUtils.isBlank( formatString ) ) { return Preferences.getDateFormat( context, TimeFormat.TIME ); } @@ -240,9 +234,8 @@ public class RecentChangesPlugin extends AbstractReferralPlugin implements WikiP return new SimpleDateFormat( formatString ); } - private DateFormat getDateFormat( WikiContext context, Map< String, String > params ) { - String formatString = get( params, DEFAULT_DATE_FORMAT, PARAM_DATE_FORMAT ); - + private DateFormat getDateFormat( final WikiContext context, final Map< String, String > params ) { + final String formatString = get( params, DEFAULT_DATE_FORMAT, PARAM_DATE_FORMAT ); if( StringUtils.isBlank( formatString ) ) { return Preferences.getDateFormat( context, TimeFormat.DATE ); } @@ -250,8 +243,8 @@ public class RecentChangesPlugin extends AbstractReferralPlugin implements WikiP return new SimpleDateFormat( formatString ); } - private String get( Map< String, String > params, String defaultValue, String paramName ) { - String value = params.get( paramName ); + private String get( final Map< String, String > params, final String defaultValue, final String paramName ) { + final String value = params.get( paramName ); return value == null ? defaultValue : value; } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/Search.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/Search.java index c8ffb3b..571189d 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/Search.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/Search.java @@ -46,32 +46,28 @@ import java.util.Map; * * @since */ -public class Search implements WikiPlugin -{ - static Logger log = Logger.getLogger(Search.class); +public class Search implements WikiPlugin { + + private static final Logger log = Logger.getLogger(Search.class); /** Parameter name for setting the query string. Value is <tt>{@value}</tt>. */ public static final String PARAM_QUERY = "query"; - /** Parameter name for setting the name of the set where the results are stored. - * Value is <tt>{@value}</tt>. - */ + /** Parameter name for setting the name of the set where the results are stored. Value is <tt>{@value}</tt>. */ public static final String PARAM_SET = "set"; /** The default name of the result set. */ public static final String DEFAULT_SETNAME = "_defaultSet"; - /** The parameter name for setting the how many results will be fetched. - * Value is <tt>{@value}</tt>. - */ + /** The parameter name for setting the how many results will be fetched. Value is <tt>{@value}</tt>. */ public static final String PARAM_MAX = "max"; /** * {@inheritDoc} */ @SuppressWarnings("unchecked") - public String execute( WikiContext context, Map<String, String> params ) throws PluginException - { + @Override + public String execute( WikiContext context, Map<String, String> params ) throws PluginException { int maxItems = Integer.MAX_VALUE; Collection<SearchResult> results = null; @@ -150,7 +146,7 @@ public class Search implements WikiPlugin name.setAttribute(XHTML.ATTR_width,"30%"); name.addContent( XhtmlUtil.link(context.getURL( WikiContext.VIEW, sr.getPage().getName()), - engine.beautifyTitle(sr.getPage().getName())) ); + engine.getRenderingManager().beautifyTitle(sr.getPage().getName())) ); row.addContent(name); 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 cb719e3..b62b58b 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 @@ -406,7 +406,7 @@ public class WeblogPlugin { if( engine.getPageManager().wikiPageExists(author) ) { - author = "<a href=\""+entryCtx.getURL( WikiContext.VIEW, author )+"\">"+engine.beautifyTitle(author)+"</a>"; + author = "<a href=\""+entryCtx.getURL( WikiContext.VIEW, author )+"\">"+engine.getRenderingManager().beautifyTitle(author)+"</a>"; } } else diff --git a/jspwiki-main/src/main/java/org/apache/wiki/render/DefaultRenderingManager.java b/jspwiki-main/src/main/java/org/apache/wiki/render/DefaultRenderingManager.java index 4f55840..d34405a 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/render/DefaultRenderingManager.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/render/DefaultRenderingManager.java @@ -24,7 +24,9 @@ import net.sf.ehcache.Element; import org.apache.log4j.Logger; import org.apache.wiki.WikiContext; import org.apache.wiki.WikiEngine; +import org.apache.wiki.api.exceptions.ProviderException; import org.apache.wiki.api.exceptions.WikiException; +import org.apache.wiki.attachment.Attachment; import org.apache.wiki.event.WikiEvent; import org.apache.wiki.event.WikiEventListener; import org.apache.wiki.event.WikiEventUtils; @@ -35,6 +37,7 @@ import org.apache.wiki.parser.MarkupParser; import org.apache.wiki.parser.WikiDocument; import org.apache.wiki.providers.WikiPageProvider; import org.apache.wiki.util.ClassUtil; +import org.apache.wiki.util.TextUtil; import java.io.IOException; import java.io.StringReader; @@ -62,6 +65,8 @@ public class DefaultRenderingManager implements RenderingManager { private WikiEngine m_engine; private boolean m_useCache = true; + /** If true, all titles will be cleaned. */ + private boolean m_beautifyTitle = false; /** The capacity of the caches, if you want something else, tweak ehcache.xml. */ private static final int DEFAULT_CACHESIZE = 1_000; @@ -95,6 +100,7 @@ public class DefaultRenderingManager implements RenderingManager { log.info( "Using " + m_markupParserClass + " as markup parser." ); m_useCache = "true".equals( properties.getProperty( PageManager.PROP_USECACHE ) ); + m_beautifyTitle = TextUtil.getBooleanProperty( properties, PROP_BEAUTIFYTITLE, m_beautifyTitle ); if( m_useCache ) { final String documentCacheName = engine.getApplicationName() + "." + DOCUMENTCACHE_NAME; @@ -138,6 +144,40 @@ public class DefaultRenderingManager implements RenderingManager { } /** + * {@inheritDoc} + */ + @Override + public String beautifyTitle( final String title ) { + if( m_beautifyTitle ) { + try { + final Attachment att = m_engine.getAttachmentManager().getAttachmentInfo( title ); + if( att == null ) { + return TextUtil.beautifyString( title ); + } + + final String parent = TextUtil.beautifyString( att.getParentName() ); + return parent + "/" + att.getFileName(); + } catch( final ProviderException e ) { + return title; + } + } + + return title; + } + + /** + * {@inheritDoc} + */ + @Override + public String beautifyTitleNoBreak( final String title ) { + if( m_beautifyTitle ) { + return TextUtil.beautifyString( title, " " ); + } + + return title; + } + + /** * {@inheritDoc} */ @Override diff --git a/jspwiki-main/src/main/java/org/apache/wiki/render/RenderingManager.java b/jspwiki-main/src/main/java/org/apache/wiki/render/RenderingManager.java index ad209cc..36fef32 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/render/RenderingManager.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/render/RenderingManager.java @@ -44,14 +44,16 @@ import java.util.Properties; public interface RenderingManager extends WikiEventListener, InternalModule { /** markup parser property. */ - String PROP_PARSER = "jspwiki.renderingManager.markupParser"; + String PROP_PARSER = "jspwiki.renderingManager.markupParser"; /** default renderer property. */ - String PROP_RENDERER = "jspwiki.renderingManager.renderer"; + String PROP_RENDERER = "jspwiki.renderingManager.renderer"; /** default wysiwyg renderer property. */ String PROP_WYSIWYG_RENDERER = "jspwiki.renderingManager.renderer.wysiwyg"; + String PROP_BEAUTIFYTITLE = "jspwiki.breakTitleWithSpaces"; + /** Name of the regular page cache. */ String DOCUMENTCACHE_NAME = "jspwiki.renderingCache"; @@ -68,6 +70,26 @@ public interface RenderingManager extends WikiEventListener, InternalModule { void initialize( WikiEngine engine, Properties properties ) throws WikiException; /** + * Beautifies the title of the page by appending spaces in suitable places, if the user has so decreed in the properties when + * constructing this WikiEngine. However, attachment names are only beautified by the name. + * + * @param title The title to beautify + * @return A beautified title (or, if beautification is off, returns the title without modification) + * @since 1.7.11, moved to PageManager on 2.11.0 + */ + String beautifyTitle( final String title ); + + /** + * 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 + */ + String beautifyTitleNoBreak( final String title ); + + /** * Returns the wiki Parser * @param pagedata the page data * @return A MarkupParser instance. diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/PageNameTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/PageNameTag.java index 7727d1e..4372b04 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/PageNameTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/PageNameTag.java @@ -18,41 +18,35 @@ */ package org.apache.wiki.tags; -import java.io.IOException; - import org.apache.wiki.WikiEngine; import org.apache.wiki.WikiPage; import org.apache.wiki.attachment.Attachment; import org.apache.wiki.util.TextUtil; +import java.io.IOException; + /** * Returns the currently requested page name. * * @since 2.0 */ -public class PageNameTag - extends WikiTagBase -{ +public class PageNameTag extends WikiTagBase { + private static final long serialVersionUID = 0L; - 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(); - if( page != null ) - { - if( page instanceof Attachment ) - { + if( page != null ) { + if( page instanceof Attachment ) { pageContext.getOut().print( TextUtil.replaceEntities( ((Attachment)page).getFileName() ) ); - } - else - { - pageContext.getOut().print( engine.beautifyTitle( m_wikiContext.getName() ) ); + } else { + pageContext.getOut().print( engine.getRenderingManager().beautifyTitle( m_wikiContext.getName() ) ); } } return SKIP_BODY; } + } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/ParentPageNameTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/ParentPageNameTag.java index 87fa96e..6f32d83 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/ParentPageNameTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/ParentPageNameTag.java @@ -18,61 +18,49 @@ */ package org.apache.wiki.tags; -import java.io.IOException; - import org.apache.wiki.WikiEngine; import org.apache.wiki.WikiPage; import org.apache.wiki.attachment.Attachment; +import java.io.IOException; + /** - * Returns the parent of the currently requested page. Weblog entries are recognized - * as subpages of the weblog page. + * Returns the parent of the currently requested page. Weblog entries are recognized as subpages of the weblog page. * * @since 2.0 */ -public class ParentPageNameTag - extends WikiTagBase -{ +public class ParentPageNameTag extends WikiTagBase { + private static final long serialVersionUID = 0L; /** * {@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(); - if( page != null ) - { - if( page instanceof Attachment ) - { - pageContext.getOut().print( engine.beautifyTitle( ((Attachment)page).getParentName()) ); - } - else - { + if( page != null ) { + if( page instanceof Attachment ) { + pageContext.getOut().print( engine.getRenderingManager().beautifyTitle( ((Attachment)page).getParentName()) ); + } else { String name = page.getName(); - - int entrystart = name.indexOf("_blogentry_"); - - if( entrystart != -1 ) - { + final int entrystart = name.indexOf("_blogentry_"); + if( entrystart != -1 ) { name = name.substring( 0, entrystart ); } - int commentstart = name.indexOf("_comments_"); - - if( commentstart != -1 ) - { + final int commentstart = name.indexOf("_comments_"); + if( commentstart != -1 ) { name = name.substring( 0, commentstart ); } - pageContext.getOut().print( engine.beautifyTitle(name) ); + pageContext.getOut().print( engine.getRenderingManager().beautifyTitle(name) ); } } return SKIP_BODY; } + } 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 779e7d7..7eb97c2 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java @@ -125,51 +125,6 @@ public class WikiEngineTest { Assertions.assertEquals( "A%E2%89%A2%CE%91.", engine.encodeName(name) ); } - @Test - public void testBeautifyTitle() { - final String src = "WikiNameThingy"; - Assertions.assertEquals("Wiki Name Thingy", m_engine.beautifyTitle( src ) ); - } - - /** - * Acronyms should be treated wisely. - */ - @Test - public void testBeautifyTitleAcronym() { - final String src = "JSPWikiPage"; - Assertions.assertEquals("JSP Wiki Page", m_engine.beautifyTitle( src ) ); - } - - /** - * Acronyms should be treated wisely. - */ - @Test - public void testBeautifyTitleAcronym2() { - final String src = "DELETEME"; - Assertions.assertEquals("DELETEME", m_engine.beautifyTitle( src ) ); - } - - @Test - public void testBeautifyTitleAcronym3() { - final String src = "JSPWikiFAQ"; - Assertions.assertEquals("JSP Wiki FAQ", m_engine.beautifyTitle( src ) ); - } - - @Test - public void testBeautifyTitleNumbers() { - final String src = "TestPage12"; - Assertions.assertEquals("Test Page 12", m_engine.beautifyTitle( src ) ); - } - - /** - * English articles too. - */ - @Test - public void testBeautifyTitleArticle() { - final String src = "ThisIsAPage"; - Assertions.assertEquals("This Is A Page", m_engine.beautifyTitle( src ) ); - } - /** * Checks, if ReferenceManager is informed of new attachments. */ diff --git a/jspwiki-main/src/test/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java b/jspwiki-main/src/test/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java index b7c864a..36894d3 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java @@ -18,17 +18,7 @@ */ package org.apache.wiki.parser; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.StringReader; -import java.util.Collection; -import java.util.Iterator; -import java.util.Properties; -import java.util.Vector; - -import javax.servlet.ServletException; - +import net.sf.ehcache.CacheManager; import org.apache.wiki.LinkCollector; import org.apache.wiki.TestEngine; import org.apache.wiki.WikiContext; @@ -46,7 +36,15 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import net.sf.ehcache.CacheManager; +import javax.servlet.ServletException; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.StringReader; +import java.util.Collection; +import java.util.Iterator; +import java.util.Properties; +import java.util.Vector; public class JSPWikiMarkupParserTest { @@ -806,7 +804,7 @@ public class JSPWikiMarkupParserTest testEngine2.getAttachmentManager().storeAttachment( att, testEngine.makeAttachmentFile() ); - String src = "["+testEngine2.beautifyTitle("TestPage/TestAtt.txt")+"]"; + String src = "["+testEngine2.getRenderingManager().beautifyTitle("TestPage/TestAtt.txt")+"]"; Assertions.assertEquals( "<a class=\"attachment\" href=\"/test/attach/TestPage/TestAtt.txt\">Test Page/TestAtt.txt</a>"+ "<a href=\"/test/PageInfo.jsp?page=TestPage/TestAtt.txt\" class=\"infolink\"><img src=\"/test/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>", diff --git a/jspwiki-main/src/test/java/org/apache/wiki/render/RenderingManagerTest.java b/jspwiki-main/src/test/java/org/apache/wiki/render/RenderingManagerTest.java index 35e2948..3ba8e6d 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/render/RenderingManagerTest.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/render/RenderingManagerTest.java @@ -40,6 +40,51 @@ public class RenderingManagerTest { CacheManager.getInstance().removeAllCaches(); } + @Test + public void testBeautifyTitle() { + final String src = "WikiNameThingy"; + Assertions.assertEquals("Wiki Name Thingy", m_engine.getRenderingManager().beautifyTitle( src ) ); + } + + /** + * Acronyms should be treated wisely. + */ + @Test + public void testBeautifyTitleAcronym() { + final String src = "JSPWikiPage"; + Assertions.assertEquals("JSP Wiki Page", m_engine.getRenderingManager().beautifyTitle( src ) ); + } + + /** + * Acronyms should be treated wisely. + */ + @Test + public void testBeautifyTitleAcronym2() { + final String src = "DELETEME"; + Assertions.assertEquals("DELETEME", m_engine.getRenderingManager().beautifyTitle( src ) ); + } + + @Test + public void testBeautifyTitleAcronym3() { + final String src = "JSPWikiFAQ"; + Assertions.assertEquals("JSP Wiki FAQ", m_engine.getRenderingManager().beautifyTitle( src ) ); + } + + @Test + public void testBeautifyTitleNumbers() { + final String src = "TestPage12"; + Assertions.assertEquals("Test Page 12", m_engine.getRenderingManager().beautifyTitle( src ) ); + } + + /** + * English articles too. + */ + @Test + public void testBeautifyTitleArticle() { + final String src = "ThisIsAPage"; + Assertions.assertEquals("This Is A Page", m_engine.getRenderingManager().beautifyTitle( src ) ); + } + /** * Tests the relative speed of the DOM cache with respect to * page being parsed every single time.
