Skip to content

Commit

Permalink
JSPWIKI-1155 - String concat in StringBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
arturobernalg committed Oct 1, 2021
1 parent 8e063af commit 4551e7d
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,12 @@ public String policyRoleTable()
// Write the table header
s.append( "<table class=\"wikitable\" border=\"1\">\n" );
s.append( " <colgroup span=\"1\" width=\"33%\"/>\n" );
s.append( " <colgroup span=\"" + pageActionsLength * rolesLength + "\" width=\"" + colWidth
+ "\" align=\"center\"/>\n" );
s.append( " <colgroup span=\"" ).append( pageActionsLength * rolesLength ).append( "\" width=\"" ).append( colWidth ).append( "\" align=\"center\"/>\n" );
s.append( " <tr>\n" );
s.append( " <th rowspan=\"2\" valign=\"bottom\">Permission</th>\n" );
for( int i = 0; i < rolesLength; i++ )
{
s.append( " <th colspan=\"" + pageActionsLength + "\" title=\"" + roles[i].getClass().getName() + "\">"
+ roles[i].getName() + "</th>\n" );
s.append( " <th colspan=\"" ).append( pageActionsLength ).append( "\" title=\"" ).append( roles[i].getClass().getName() ).append( "\">" ).append( roles[i].getName() ).append( "</th>\n" );
}
s.append( " </tr>\n" );

Expand All @@ -235,15 +233,15 @@ public String policyRoleTable()
for( final String pageAction : pageActions )
{
final String action = pageAction.substring( 0, 1 );
s.append( " <th title=\"" + pageAction + "\">" + action + "</th>\n" );
s.append( " <th title=\"" ).append( pageAction ).append( "\">" ).append( action ).append( "</th>\n" );
}
}
s.append( " </tr>\n" );

// Write page permission tests first
for( final String page : pages ) {
s.append( " <tr>\n" );
s.append( " <td>PagePermission \"" + wiki + ":" + page + "\"</td>\n" );
s.append( " <td>PagePermission \"" ).append( wiki ).append( ":" ).append( page ).append( "\"</td>\n" );
for( final Principal role : roles ) {
for( final String pageAction : pageActions ) {
final Permission permission = PermissionFactory.getPagePermission( wiki + ":" + page, pageAction );
Expand All @@ -256,7 +254,7 @@ public String policyRoleTable()
// Now do the group tests
for( final String group : groups ) {
s.append( " <tr>\n" );
s.append( " <td>GroupPermission \"" + wiki + ":" + group + "\"</td>\n" );
s.append( " <td>GroupPermission \"" ).append( wiki ).append( ":" ).append( group ).append( "\"</td>\n" );
for( final Principal role : roles ) {
for( final String groupAction : groupActions ) {
Permission permission = null;
Expand All @@ -274,7 +272,7 @@ public String policyRoleTable()
final String[] wikiPerms = new String[] { "createGroups", "createPages", "login", "editPreferences", "editProfile" };
for( final String wikiPerm : wikiPerms ) {
s.append( " <tr>\n" );
s.append( " <td>WikiPermission \"" + wiki + "\",\"" + wikiPerm + "\"</td>\n" );
s.append( " <td>WikiPermission \"" ).append( wiki ).append( "\",\"" ).append( wikiPerm ).append( "\"</td>\n" );
for( final Principal role : roles ) {
final Permission permission = new WikiPermission( wiki, wikiPerm );
s.append( printPermissionTest( permission, role, pageActionsLength ) );
Expand All @@ -284,7 +282,7 @@ public String policyRoleTable()

// Lastly, check for AllPermission
s.append( " <tr>\n" );
s.append( " <td>AllPermission \"" + wiki + "\"</td>\n" );
s.append( " <td>AllPermission \"" ).append( wiki ).append( "\"</td>\n" );
for( final Principal role : roles )
{
final Permission permission = new AllPermission( wiki );
Expand All @@ -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( " <td colspan=\"" + cols + "\" align=\"center\" title=\"N/A\">" );
s.append( " <td colspan=\"" ).append( cols ).append( "\" align=\"center\" title=\"N/A\">" );
s.append( "&nbsp;</td>\n" );
} else {
final boolean allowed = verifyStaticPermission( principal, permission );
s.append( " <td colspan=\"" + cols + "\" align=\"center\" title=\"" );
s.append( " <td colspan=\"" ).append( cols ).append( "\" align=\"center\" title=\"" );
s.append( allowed ? "ALLOW: " : "DENY: " );
s.append( permission.getClass().getName() );
s.append( " &quot;" );
Expand Down Expand Up @@ -361,12 +359,12 @@ public String containerRoleTable() throws WikiException {
s.append( " <tr>\n" );
s.append( " <th rowspan=\"2\">Action</th>\n" );
s.append( " <th rowspan=\"2\">Page</th>\n" );
s.append( " <th colspan=\"" + roles.length + 1 + "\">Roles</th>\n" );
s.append( " <th colspan=\"" ).append( roles.length ).append( 1 ).append( "\">Roles</th>\n" );
s.append( " </tr>\n" );
s.append( " <tr>\n" );
s.append( " <th>Anonymous</th>\n" );
for( final Principal role : roles ) {
s.append( " <th>" + role.getName() + "</th>\n" );
s.append( " <th>" ).append( role.getName() ).append( "</th>\n" );
}
s.append( "</tr>\n" );
s.append( "</thead>\n" );
Expand All @@ -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( " <tr>\n" );
s.append( " <td>" + action + "</td>\n" );
s.append( " <td>" + jsp + "</td>\n" );
s.append( " <td>" ).append( action ).append( "</td>\n" );
s.append( " <td>" ).append( jsp ).append( "</td>\n" );
s.append( " <td title=\"" );
s.append( allowsAnonymous ? "ALLOW: " : "DENY: " );
s.append( jsp );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ private static Change getChange( final Context context, final String newText ) {

// And author as well
if( page.getAuthor() != null ) {
change.append( "\r\n" + page.getAuthor() );
change.append( "\r\n" ).append( page.getAuthor() );
}

ch.m_change = change.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ private String augmentedWikiLinkMapToString(final Map attributesMap )
final String attributeName = (String)entry.getKey();
final String attributeValue = (String)entry.getValue();

sb.append( " " + attributeName + "='" + attributeValue + "'" );
sb.append( " " ).append( attributeName ).append( "='" ).append( attributeValue ).append( "'" );
}

return sb.toString().trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2273,7 +2273,7 @@ private String cleanupSuspectData( final String s )
final char c = s.charAt(i);

if( Verifier.isXMLCharacter( c ) ) sb.append( c );
else sb.append( "0x"+Integer.toString(c,16).toUpperCase() );
else sb.append( "0x" ).append( Integer.toString( c, 16 ).toUpperCase() );
}

return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ protected String wikitizeCollection( final Collection< String > 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++;
}

Expand Down
24 changes: 12 additions & 12 deletions jspwiki-main/src/main/java/org/apache/wiki/plugin/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,32 +136,32 @@ public String execute( final Context context, final Map<String, String> params )
result.append( "<table border=\"0\" class=\"imageplugin\"" );

if( title != null ) {
result.append( " title=\"" + title + "\"" );
result.append( " title=\"" ).append( title ).append( "\"" );
}

if( align != null ) {
if( align.equals( "center" ) ) {
result.append( " style=\"margin-left: auto; margin-right: auto; text-align:center; vertical-align:middle;\"" );
} else {
result.append( " style=\"float:" + align + ";\"" );
result.append( " style=\"float:" ).append( align ).append( ";\"" );
}
}

result.append( ">\n" );

if( caption != null ) {
result.append( "<caption>" + caption + "</caption>\n" );
result.append( "<caption>" ).append( caption ).append( "</caption>\n" );
}

// move css class and style to the container of the image, so it doesn't affect the caption
result.append( "<tr><td" );

if( cssclass != null ) {
result.append(" class=\""+cssclass+"\"");
result.append( " class=\"" ).append( cssclass ).append( "\"" );
}

if( style != null ) {
result.append(" style=\""+style);
result.append( " style=\"" ).append( style );

// Make sure that we add a ";" to the end of the style string
if( result.charAt( result.length()-1 ) != ';' ) result.append(";");
Expand All @@ -172,26 +172,26 @@ public String execute( final Context context, final Map<String, String> params )
result.append( ">" );

if( link != null ) {
result.append("<a href=\""+link+"\"");
result.append( "<a href=\"" ).append( link ).append( "\"" );
if( target != null ) {
result.append(" target=\""+target+"\"");
result.append( " target=\"" ).append( target ).append( "\"" );
}
result.append(">");
}

result.append( "<img src=\""+src+"\"" );
result.append( "<img src=\"" ).append( src ).append( "\"" );

if( ht != null ) {
result.append(" height=\""+ht+"\"");
result.append( " height=\"" ).append( ht ).append( "\"" );
}
if( wt != null ) {
result.append(" width=\""+wt+"\"");
result.append( " width=\"" ).append( wt ).append( "\"" );
}
if( alt != null ) {
result.append(" alt=\""+alt+"\"");
result.append( " alt=\"" ).append( alt ).append( "\"" );
}
if( border != null ) {
result.append(" border=\""+border+"\"");
result.append( " border=\"" ).append( border ).append( "\"" );
}
// if( map != null ) result.append(" map=\""+map+"\"");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public String execute( final Context context, final Map<String, String> params )

res.append("<div class=\"inserted-page ");
if( clazz != null ) res.append( clazz );
if( !style.equals(DEFAULT_STYLE) ) res.append("\" style=\""+style );
if( showOnce ) res.append("\" data-once=\""+cookieName );
if( !style.equals(DEFAULT_STYLE) ) res.append( "\" style=\"" ).append( style );
if( showOnce ) res.append( "\" data-once=\"" ).append( cookieName );
res.append("\" >");

res.append( engine.getManager( RenderingManager.class ).textToHTML( includedContext, pageData ) );
Expand All @@ -200,8 +200,8 @@ public String execute( final Context context, final Map<String, String> params )
if( defaultstr != null ) {
res.append( defaultstr );
} else {
res.append( "There is no page called '" + includedPage + "'. Would you like to " );
res.append( "<a href=\"" + context.getURL( ContextEnum.PAGE_EDIT.getRequestContext(), includedPage ) + "\">create it?</a>" );
res.append( "There is no page called '" ).append( includedPage ).append( "'. Would you like to " );
res.append( "<a href=\"" ).append( context.getURL( ContextEnum.PAGE_EDIT.getRequestContext(), includedPage ) ).append( "\">create it?</a>" );
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("<table class=\"wikitable\">\n");
result.append("<tr>\n");
result.append( "<th>" + rb.getString( "plugin.listlocks.page" ) + "</th><th>" + rb.getString( "plugin.listlocks.locked.by" )
+ "</th><th>" + rb.getString( "plugin.listlocks.acquired" ) + "</th><th>"
+ rb.getString( "plugin.listlocks.expires" ) + "</th>\n" );
result.append( "<th>" ).append( rb.getString( "plugin.listlocks.page" ) ).append( "</th><th>" ).append( rb.getString( "plugin.listlocks.locked.by" ) ).append( "</th><th>" ).append( rb.getString( "plugin.listlocks.acquired" ) ).append( "</th><th>" ).append( rb.getString( "plugin.listlocks.expires" ) ).append( "</th>\n" );
result.append("</tr>");

if( locks.size() == 0 ) {
result.append( "<tr><td colspan=\"4\" class=\"odd\">" + rb.getString( "plugin.listlocks.no.locks.exist" ) + "</td></tr>\n" );
result.append( "<tr><td colspan=\"4\" class=\"odd\">" ).append( rb.getString( "plugin.listlocks.no.locks.exist" ) ).append( "</td></tr>\n" );
} else {
int rowNum = 1;
for( final PageLock lock : locks ) {
result.append( rowNum % 2 != 0 ? "<tr class=\"odd\">" : "<tr>" );
result.append( "<td>" + lock.getPage() + "</td>" );
result.append( "<td>" + lock.getLocker() + "</td>" );
result.append( "<td>" + Preferences.renderDate( context, lock.getAcquisitionTime(), Preferences.TimeFormat.DATETIME ) + "</td>" );
result.append( "<td>" + Preferences.renderDate( context, lock.getExpiryTime(), Preferences.TimeFormat.DATETIME ) + "</td>" );
result.append( "<td>" ).append( lock.getPage() ).append( "</td>" );
result.append( "<td>" ).append( lock.getLocker() ).append( "</td>" );
result.append( "<td>" ).append( Preferences.renderDate( context, lock.getAcquisitionTime(), Preferences.TimeFormat.DATETIME ) ).append( "</td>" );
result.append( "<td>" ).append( Preferences.renderDate( context, lock.getExpiryTime(), Preferences.TimeFormat.DATETIME ) ).append( "</td>" );
result.append( "</tr>\n" );
rowNum++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,12 @@ public String execute( final Context context, final Map<String, String> params )
( 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_result.append( "<a class=\"wikipage\" href=\"" )
.append( href ).append( "\" title=\"" )
.append( TextUtil.replaceEntities( title ) )
.append( "\">" )
.append( TextUtil.replaceEntities( rootname ) )
.append( "</a>\n" );
m_exists.add( rootname );

// pre compile all needed patterns
Expand Down Expand Up @@ -235,7 +238,7 @@ private void handleLinks( final Context context, final Collection<String> links,
}

//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> " ).append( TextUtil.replaceEntities( link ) ).append( "\n" );
getReferredPages( context, link, depth ); // added recursive call - on general request
m_result.append( "\n</li>\n" );
}
Expand All @@ -246,7 +249,7 @@ private void handleLinks( final Context context, final Collection<String> links,
}

final String href = context.getURL( ContextEnum.PAGE_VIEW.getRequestContext(), link );
m_result.append( "<li><a class=\"wikipage\" href=\"" + href + "\">" + TextUtil.replaceEntities(link) + "</a>\n" );
m_result.append( "<li><a class=\"wikipage\" href=\"" ).append( href ).append( "\">" ).append( TextUtil.replaceEntities( link ) ).append( "</a>\n" );
m_exists.add( link );
getReferredPages( context, link, depth );
m_result.append( "\n</li>\n" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public String execute( final Context context, final Map<String, String> params)
final Object[] args = { "" + ( result.size() - items ) };
extras = MessageFormat.format( extras, args );

resultHTML.append( "<br/>" + extras + "<br/>" );
resultHTML.append( "<br/>" ).append( extras ).append( "<br/>" );
}
return resultHTML.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,25 @@ public void headingAdded( final Context context, final Heading hd ) {

final String sectref = "#section-"+pageName+"-"+titleSection;

m_buf.append( "<a class=\"wikipage\" href=\"" + sectref + "\">" );
m_buf.append( "<a class=\"wikipage\" href=\"" ).append( sectref ).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)+"</a></li>\n" );
m_buf.append( TextUtil.replaceEntities( hd.m_titleText ) ).append( "</a></li>\n" );

m_lastLevel = hd.m_level;
}
Expand Down
Loading

0 comments on commit 4551e7d

Please sign in to comment.