From 4551e7d5c8cc650724a899323b14bdbce1ad8cb2 Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Fri, 1 Oct 2021 18:01:11 +0200 Subject: [PATCH] JSPWIKI-1155 - String concat in StringBuilder --- .../apache/wiki/auth/SecurityVerifier.java | 28 +++++++++---------- .../org/apache/wiki/filters/SpamFilter.java | 2 +- .../XHtmlElementToWikiTranslator.java | 2 +- .../wiki/parser/JSPWikiMarkupParser.java | 2 +- .../wiki/plugin/AbstractReferralPlugin.java | 2 +- .../java/org/apache/wiki/plugin/Image.java | 24 ++++++++-------- .../org/apache/wiki/plugin/InsertPage.java | 8 +++--- .../apache/wiki/plugin/ListLocksPlugin.java | 14 ++++------ .../wiki/plugin/ReferredPagesPlugin.java | 13 +++++---- .../plugin/ReferringUndefinedPagesPlugin.java | 2 +- .../apache/wiki/plugin/TableOfContents.java | 10 +++---- .../org/apache/wiki/plugin/WeblogPlugin.java | 9 ++---- .../apache/wiki/tags/SetPaginationTag.java | 2 +- .../java/org/apache/wiki/tags/TabTag.java | 8 +++--- .../apache/wiki/ui/admin/SimpleAdminBean.java | 10 +++---- .../java/org/apache/wiki/util/FileUtil.java | 6 ++-- 16 files changed, 69 insertions(+), 73 deletions(-) diff --git a/jspwiki-main/src/main/java/org/apache/wiki/auth/SecurityVerifier.java b/jspwiki-main/src/main/java/org/apache/wiki/auth/SecurityVerifier.java index e17420034f..9b6d23c25c 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/auth/SecurityVerifier.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/SecurityVerifier.java @@ -217,14 +217,12 @@ public String policyRoleTable() // Write the table header s.append( "\n" ); s.append( " \n" ); - s.append( " \n" ); + s.append( " \n" ); s.append( " \n" ); s.append( " \n" ); for( int i = 0; i < rolesLength; i++ ) { - s.append( " \n" ); + s.append( " \n" ); } s.append( " \n" ); @@ -235,7 +233,7 @@ public String policyRoleTable() for( final String pageAction : pageActions ) { final String action = pageAction.substring( 0, 1 ); - s.append( " \n" ); + s.append( " \n" ); } } s.append( " \n" ); @@ -243,7 +241,7 @@ public String policyRoleTable() // Write page permission tests first for( final String page : pages ) { s.append( " \n" ); - s.append( " \n" ); + s.append( " \n" ); for( final Principal role : roles ) { for( final String pageAction : pageActions ) { final Permission permission = PermissionFactory.getPagePermission( wiki + ":" + page, pageAction ); @@ -256,7 +254,7 @@ public String policyRoleTable() // Now do the group tests for( final String group : groups ) { s.append( " \n" ); - s.append( " \n" ); + s.append( " \n" ); for( final Principal role : roles ) { for( final String groupAction : groupActions ) { Permission permission = null; @@ -274,7 +272,7 @@ public String policyRoleTable() final String[] wikiPerms = new String[] { "createGroups", "createPages", "login", "editPreferences", "editProfile" }; for( final String wikiPerm : wikiPerms ) { s.append( " \n" ); - s.append( " \n" ); + s.append( " \n" ); for( final Principal role : roles ) { final Permission permission = new WikiPermission( wiki, wikiPerm ); s.append( printPermissionTest( permission, role, pageActionsLength ) ); @@ -284,7 +282,7 @@ public String policyRoleTable() // Lastly, check for AllPermission s.append( " \n" ); - s.append( " \n" ); + s.append( " \n" ); for( final Principal role : roles ) { final Permission permission = new AllPermission( wiki ); @@ -306,11 +304,11 @@ public String policyRoleTable() private String printPermissionTest( final Permission permission, final Principal principal, final int cols ) { final StringBuilder s = new StringBuilder(); if( permission == null ) { - s.append( " \n" ); } else { final boolean allowed = verifyStaticPermission( principal, permission ); - s.append( " \n" ); s.append( " \n" ); - s.append( " \n" ); + s.append( " \n" ); s.append( " \n" ); s.append( " \n" ); s.append( " \n" ); for( final Principal role : roles ) { - s.append( " \n" ); + s.append( " \n" ); } s.append( "\n" ); s.append( "\n" ); @@ -380,8 +378,8 @@ public String containerRoleTable() throws WikiException { // Print whether the page is constrained for each role final boolean allowsAnonymous = !wca.isConstrained( jsp, Role.ALL ); s.append( " \n" ); - s.append( " \n" ); - s.append( " \n" ); + s.append( " \n" ); + s.append( " \n" ); s.append( "
Permission" - + roles[i].getName() + "" ).append( roles[i].getName() ).append( "
" + action + "" ).append( action ).append( "
PagePermission \"" + wiki + ":" + page + "\"PagePermission \"" ).append( wiki ).append( ":" ).append( page ).append( "\"
GroupPermission \"" + wiki + ":" + group + "\"GroupPermission \"" ).append( wiki ).append( ":" ).append( group ).append( "\"
WikiPermission \"" + wiki + "\",\"" + wikiPerm + "\"WikiPermission \"" ).append( wiki ).append( "\",\"" ).append( wikiPerm ).append( "\"
AllPermission \"" + wiki + "\"AllPermission \"" ).append( wiki ).append( "\"" ); + s.append( " " ); s.append( " \n" ); s.append( " ActionPageRolesRoles
Anonymous" + role.getName() + "" ).append( role.getName() ).append( "
" + action + "" + jsp + "" ).append( action ).append( "" ).append( jsp ).append( " links, final Str output.append( m_before ); // Make a Wiki markup link. See TranslatorReader. - output.append( "[" + m_engine.getManager( RenderingManager.class ).beautifyTitle(value) + "|" + value + "]" ); + output.append( "[" ).append( m_engine.getManager( RenderingManager.class ).beautifyTitle( value ) ).append( "|" ).append( value ).append( "]" ); count++; } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/Image.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/Image.java index ca353faf44..a025581a3f 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/Image.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/Image.java @@ -136,32 +136,32 @@ public String execute( final Context context, final Map params ) result.append( "\n" ); if( caption != null ) { - result.append( "\n" ); + result.append( "\n" ); } // move css class and style to the container of the image, so it doesn't affect the caption result.append( " params ) result.append( ">" ); if( link != null ) { - result.append(""); } - result.append( " params ) res.append("
"); res.append( engine.getManager( RenderingManager.class ).textToHTML( includedContext, pageData ) ); @@ -200,8 +200,8 @@ public String execute( final Context context, final Map params ) if( defaultstr != null ) { res.append( defaultstr ); } else { - res.append( "There is no page called '" + includedPage + "'. Would you like to " ); - res.append( "create it?" ); + res.append( "There is no page called '" ).append( includedPage ).append( "'. Would you like to " ); + res.append( "create it?" ); } } } else { diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/ListLocksPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/ListLocksPlugin.java index 91288d3646..c58884f351 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/ListLocksPlugin.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/ListLocksPlugin.java @@ -49,21 +49,19 @@ public String execute( final Context context, final Map< String, String > params final ResourceBundle rb = Preferences.getBundle( context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE ); result.append("
" + caption + "" ).append( caption ).append( "
\n"); result.append("\n"); - result.append( "\n" ); + result.append( "\n" ); result.append(""); if( locks.size() == 0 ) { - result.append( "\n" ); + result.append( "\n" ); } else { int rowNum = 1; for( final PageLock lock : locks ) { result.append( rowNum % 2 != 0 ? "" : "" ); - result.append( "" ); - result.append( "" ); - result.append( "" ); - result.append( "" ); + result.append( "" ); + result.append( "" ); + result.append( "" ); + result.append( "" ); result.append( "\n" ); rowNum++; } 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 607be49bc1..25c7e4ad66 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 @@ -145,9 +145,12 @@ public String execute( final Context context, final Map params ) ( m_formatSort ? " sort" : "" ) + "]"; m_result.append( "
\n" ); - m_result.append( "" + TextUtil.replaceEntities( rootname ) + "\n" ); + m_result.append( "" ) + .append( TextUtil.replaceEntities( rootname ) ) + .append( "\n" ); m_exists.add( rootname ); // pre compile all needed patterns @@ -235,7 +238,7 @@ private void handleLinks( final Context context, final Collection links, } //See https://www.w3.org/wiki/HTML_lists for proper nesting of UL and LI - m_result.append( "
  • " + TextUtil.replaceEntities(link) + "\n" ); + m_result.append( "
  • " ).append( TextUtil.replaceEntities( link ) ).append( "\n" ); getReferredPages( context, link, depth ); // added recursive call - on general request m_result.append( "\n
  • \n" ); } @@ -246,7 +249,7 @@ private void handleLinks( final Context context, final Collection links, } final String href = context.getURL( ContextEnum.PAGE_VIEW.getRequestContext(), link ); - m_result.append( "
  • " + TextUtil.replaceEntities(link) + "\n" ); + m_result.append( "
  • " ).append( TextUtil.replaceEntities( link ) ).append( "\n" ); m_exists.add( link ); getReferredPages( context, link, depth ); m_result.append( "\n
  • \n" ); diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferringUndefinedPagesPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferringUndefinedPagesPlugin.java index 3283723e64..aca7edefa3 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferringUndefinedPagesPlugin.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferringUndefinedPagesPlugin.java @@ -84,7 +84,7 @@ public String execute( final Context context, final Map params) final Object[] args = { "" + ( result.size() - items ) }; extras = MessageFormat.format( extras, args ); - resultHTML.append( "
    " + extras + "
    " ); + resultHTML.append( "
    " ).append( extras ).append( "
    " ); } return resultHTML.toString(); } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/TableOfContents.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/TableOfContents.java index 28aa978d7e..ae1f850f5a 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/TableOfContents.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/TableOfContents.java @@ -121,25 +121,25 @@ public void headingAdded( final Context context, final Heading hd ) { final String sectref = "#section-"+pageName+"-"+titleSection; - m_buf.append( "" ); + m_buf.append( "" ); if (m_usingNumberedList) { switch( hd.m_level ) { case Heading.HEADING_SMALL: - m_buf.append(m_prefix + m_level1Index + "." + m_level2Index + "."+ m_level3Index +" "); + m_buf.append( m_prefix ).append( m_level1Index ).append( "." ).append( m_level2Index ).append( "." ).append( m_level3Index ).append( " " ); break; case Heading.HEADING_MEDIUM: - m_buf.append(m_prefix + m_level1Index + "." + m_level2Index + " "); + m_buf.append( m_prefix ).append( m_level1Index ).append( "." ).append( m_level2Index ).append( " " ); break; case Heading.HEADING_LARGE: - m_buf.append(m_prefix + m_level1Index +" "); + m_buf.append( m_prefix ).append( m_level1Index ).append( " " ); break; default: throw new InternalWikiException("Unknown depth in toc! (Please submit a bug report.)"); } } - m_buf.append( TextUtil.replaceEntities(hd.m_titleText)+"\n" ); + m_buf.append( TextUtil.replaceEntities( hd.m_titleText ) ).append( "\n" ); m_lastLevel = hd.m_level; } 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 158f21d0fd..8311b1aac8 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 @@ -327,7 +327,7 @@ private void addEntryHTML( final Context context, final DateFormat entryFormat, } buffer.append(html.substring(0, cutoff)); if (hasBeenCutOff) { - buffer.append(" "+rb.getString("weblogentryplugin.more")+"\n"); + buffer.append( " " ).append( rb.getString( "weblogentryplugin.more" ) ).append( "\n" ); } } else { buffer.append(html); @@ -350,7 +350,7 @@ private void addEntryHTML( final Context context, final DateFormat entryFormat, } buffer.append( MessageFormat.format( rb.getString( "weblogentryplugin.postedby" ), author ) ); - buffer.append( "" + rb.getString("weblogentryplugin.permalink") + "" ); + buffer.append( "" ).append( rb.getString( "weblogentryplugin.permalink" ) ).append( "" ); final String commentPageName = TextUtil.replaceString( entry.getName(), "blogentry", "comments" ); if( hasComments ) { @@ -363,10 +363,7 @@ private void addEntryHTML( final Context context, final DateFormat entryFormat, final String addcomment = rb.getString("weblogentryplugin.addcomment"); - buffer.append( "" + - MessageFormat.format( addcomment, numComments ) + - "" ); + buffer.append( "" ).append( MessageFormat.format( addcomment, numComments ) ).append( "" ); } buffer.append("
    \n"); diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/SetPaginationTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/SetPaginationTag.java index 036068a067..6a3b2d3fd0 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/SetPaginationTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/SetPaginationTag.java @@ -137,7 +137,7 @@ public int doWikiStartTag() pagination.append( "
    " + rb.getString( "plugin.listlocks.page" ) + "" + rb.getString( "plugin.listlocks.locked.by" ) - + "" + rb.getString( "plugin.listlocks.acquired" ) + "" - + rb.getString( "plugin.listlocks.expires" ) + "" ).append( rb.getString( "plugin.listlocks.page" ) ).append( "" ).append( rb.getString( "plugin.listlocks.locked.by" ) ).append( "" ).append( rb.getString( "plugin.listlocks.acquired" ) ).append( "" ).append( rb.getString( "plugin.listlocks.expires" ) ).append( "
    " + rb.getString( "plugin.listlocks.no.locks.exist" ) + "
    " ).append( rb.getString( "plugin.listlocks.no.locks.exist" ) ).append( "
    " + lock.getPage() + "" + lock.getLocker() + "" + Preferences.renderDate( context, lock.getAcquisitionTime(), Preferences.TimeFormat.DATETIME ) + "" + Preferences.renderDate( context, lock.getExpiryTime(), Preferences.TimeFormat.DATETIME ) + "" ).append( lock.getPage() ).append( "" ).append( lock.getLocker() ).append( "" ).append( Preferences.renderDate( context, lock.getAcquisitionTime(), Preferences.TimeFormat.DATETIME ) ).append( "" ).append( Preferences.renderDate( context, lock.getExpiryTime(), Preferences.TimeFormat.DATETIME ) ).append( "