mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
Merge pull request #194 from sdutry/sonar/string-optimize-single-characters
used char instead of a single character string
This commit is contained in:
@@ -56,7 +56,7 @@ public class AllowedMethods {
|
||||
if (isPattern && !method.startsWith("regex:") && !strictMethodInvocation) {
|
||||
allowedMethods.add(new PatternAllowedMethod(methodPattern.toString(), method));
|
||||
} else if (method.startsWith("regex:")) {
|
||||
String pattern = method.substring(method.indexOf(":") + 1);
|
||||
String pattern = method.substring(method.indexOf(':') + 1);
|
||||
allowedMethods.add(new PatternAllowedMethod(pattern, method));
|
||||
} else if (method.contains("*") && !method.startsWith("regex:") && !strictMethodInvocation) {
|
||||
String pattern = method.replace("*", defaultRegex);
|
||||
|
||||
@@ -171,8 +171,8 @@ public class GlobalLocalizedTextProvider extends AbstractLocalizedTextProvider {
|
||||
|
||||
indexedTextName = aTextName;
|
||||
|
||||
while ((i = indexedTextName.indexOf("[", i + 1)) != -1) {
|
||||
int j = indexedTextName.indexOf("]", i);
|
||||
while ((i = indexedTextName.indexOf('[', i + 1)) != -1) {
|
||||
int j = indexedTextName.indexOf(']', i);
|
||||
String a = indexedTextName.substring(0, i);
|
||||
String b = indexedTextName.substring(j);
|
||||
indexedTextName = a + "[*" + b;
|
||||
|
||||
@@ -232,8 +232,8 @@ public class StrutsLocalizedTextProvider extends AbstractLocalizedTextProvider {
|
||||
|
||||
indexedTextName = aTextName;
|
||||
|
||||
while ((i = indexedTextName.indexOf("[", i + 1)) != -1) {
|
||||
int j = indexedTextName.indexOf("]", i);
|
||||
while ((i = indexedTextName.indexOf('[', i + 1)) != -1) {
|
||||
int j = indexedTextName.indexOf(']', i);
|
||||
String a = indexedTextName.substring(0, i);
|
||||
String b = indexedTextName.substring(j);
|
||||
indexedTextName = a + "[*" + b;
|
||||
@@ -293,14 +293,14 @@ public class StrutsLocalizedTextProvider extends AbstractLocalizedTextProvider {
|
||||
}
|
||||
|
||||
// see if it's a child property
|
||||
int idx = aTextName.indexOf(".");
|
||||
int idx = aTextName.indexOf('.');
|
||||
|
||||
if (idx != -1) {
|
||||
String newKey = null;
|
||||
String prop = null;
|
||||
|
||||
if (aTextName.startsWith(XWorkConverter.CONVERSION_ERROR_PROPERTY_PREFIX)) {
|
||||
idx = aTextName.indexOf(".", XWorkConverter.CONVERSION_ERROR_PROPERTY_PREFIX.length());
|
||||
idx = aTextName.indexOf('.', XWorkConverter.CONVERSION_ERROR_PROPERTY_PREFIX.length());
|
||||
|
||||
if (idx != -1) {
|
||||
prop = aTextName.substring(XWorkConverter.CONVERSION_ERROR_PROPERTY_PREFIX.length(), idx);
|
||||
|
||||
@@ -189,7 +189,7 @@ public interface ClassFinder {
|
||||
}
|
||||
|
||||
public String getPackageName(){
|
||||
return name.indexOf(".") > 0 ? name.substring(0, name.lastIndexOf(".")) : "" ;
|
||||
return name.indexOf('.') > 0 ? name.substring(0, name.lastIndexOf('.')) : "" ;
|
||||
}
|
||||
|
||||
public List<MethodInfo> getConstructors() {
|
||||
|
||||
@@ -89,8 +89,8 @@ public class ServletUrlRenderer implements UrlRenderer {
|
||||
|
||||
// We don't include the request parameters cause they would have been
|
||||
// prioritised before this [in start(Writer) method]
|
||||
if (_value != null && _value.indexOf("?") > 0) {
|
||||
_value = _value.substring(0, _value.indexOf("?"));
|
||||
if (_value != null && _value.indexOf('?') > 0) {
|
||||
_value = _value.substring(0, _value.indexOf('?'));
|
||||
}
|
||||
result = urlHelper.buildUrl(_value, urlComponent.getHttpServletRequest(), urlComponent.getHttpServletResponse(), urlComponent.getParameters(), scheme, urlComponent.isIncludeContext(), urlComponent.isEncode(), urlComponent.isForceAddSchemeHostAndPort(), urlComponent.isEscapeAmp());
|
||||
}
|
||||
@@ -150,10 +150,10 @@ public class ServletUrlRenderer implements UrlRenderer {
|
||||
}
|
||||
|
||||
Map actionParams = null;
|
||||
if (action != null && action.indexOf("?") > 0) {
|
||||
String queryString = action.substring(action.indexOf("?") + 1);
|
||||
if (action != null && action.indexOf('?') > 0) {
|
||||
String queryString = action.substring(action.indexOf('?') + 1);
|
||||
actionParams = urlHelper.parseQueryString(queryString, false);
|
||||
action = action.substring(0, action.indexOf("?"));
|
||||
action = action.substring(0, action.indexOf('?'));
|
||||
}
|
||||
|
||||
ActionMapping nameMapping = actionMapper.getMappingFromActionName(action);
|
||||
@@ -322,7 +322,7 @@ public class ServletUrlRenderer implements UrlRenderer {
|
||||
// where the parameters specified in value attribute takes priority.
|
||||
|
||||
if (StringUtils.contains(value, "?")) {
|
||||
String queryString = value.substring(value.indexOf("?") + 1);
|
||||
String queryString = value.substring(value.indexOf('?') + 1);
|
||||
|
||||
mergedParams = urlHelper.parseQueryString(queryString, false);
|
||||
for (Map.Entry<String, Object> entry : contextParameters.entrySet()) {
|
||||
|
||||
@@ -142,7 +142,7 @@ public abstract class BaseTemplateEngine implements TemplateEngine {
|
||||
|
||||
protected String getFinalTemplateName(Template template) {
|
||||
String t = template.toString();
|
||||
if (t.indexOf(".") <= 0) {
|
||||
if (t.indexOf('.') <= 0) {
|
||||
return t + "." + getSuffix();
|
||||
}
|
||||
return t;
|
||||
|
||||
@@ -163,8 +163,8 @@ public class DefaultActionMapper implements ActionMapper {
|
||||
}
|
||||
}
|
||||
if (!allowSlashesInActionNames && !allowActionCrossNamespaceAccess) {
|
||||
if (actionName.lastIndexOf("/") != -1) {
|
||||
actionName = actionName.substring(actionName.lastIndexOf("/") + 1);
|
||||
if (actionName.lastIndexOf('/') != -1) {
|
||||
actionName = actionName.substring(actionName.lastIndexOf('/') + 1);
|
||||
}
|
||||
}
|
||||
mapping.setName(actionName);
|
||||
@@ -271,7 +271,7 @@ public class DefaultActionMapper implements ActionMapper {
|
||||
ActionMapping mapping = new ActionMapping();
|
||||
String uri = RequestUtils.getUri(request);
|
||||
|
||||
int indexOfSemicolon = uri.indexOf(";");
|
||||
int indexOfSemicolon = uri.indexOf(';');
|
||||
uri = (indexOfSemicolon > -1) ? uri.substring(0, indexOfSemicolon) : uri;
|
||||
|
||||
uri = dropExtension(uri, mapping);
|
||||
@@ -291,7 +291,7 @@ public class DefaultActionMapper implements ActionMapper {
|
||||
if (allowDynamicMethodCalls) {
|
||||
// handle "name!method" convention.
|
||||
String name = mapping.getName();
|
||||
int exclamation = name.lastIndexOf("!");
|
||||
int exclamation = name.lastIndexOf('!');
|
||||
if (exclamation != -1) {
|
||||
mapping.setName(name.substring(0, exclamation));
|
||||
|
||||
@@ -341,7 +341,7 @@ public class DefaultActionMapper implements ActionMapper {
|
||||
*/
|
||||
protected void parseNameAndNamespace(String uri, ActionMapping mapping, ConfigurationManager configManager) {
|
||||
String namespace, name;
|
||||
int lastSlash = uri.lastIndexOf("/");
|
||||
int lastSlash = uri.lastIndexOf('/');
|
||||
if (lastSlash == -1) {
|
||||
namespace = "";
|
||||
name = uri;
|
||||
|
||||
+2
-2
@@ -131,8 +131,8 @@ public abstract class AbstractMultiPartRequest implements MultiPartRequest {
|
||||
protected String getCanonicalName(final String originalFileName) {
|
||||
String fileName = originalFileName;
|
||||
|
||||
int forwardSlash = fileName.lastIndexOf("/");
|
||||
int backwardSlash = fileName.lastIndexOf("\\");
|
||||
int forwardSlash = fileName.lastIndexOf('/');
|
||||
int backwardSlash = fileName.lastIndexOf('\\');
|
||||
if (forwardSlash != -1 && forwardSlash > backwardSlash) {
|
||||
fileName = fileName.substring(forwardSlash + 1, fileName.length());
|
||||
} else {
|
||||
|
||||
@@ -137,8 +137,8 @@ public class ServletDispatcherResult extends StrutsResultSupport {
|
||||
|
||||
//add parameters passed on the location to #parameters
|
||||
// see WW-2120
|
||||
if (StringUtils.isNotEmpty(finalLocation) && finalLocation.indexOf("?") > 0) {
|
||||
String queryString = finalLocation.substring(finalLocation.indexOf("?") + 1);
|
||||
if (StringUtils.isNotEmpty(finalLocation) && finalLocation.indexOf('?') > 0) {
|
||||
String queryString = finalLocation.substring(finalLocation.indexOf('?') + 1);
|
||||
HttpParameters parameters = getParameters(invocation);
|
||||
Map<String, Object> queryParams = urlHelper.parseQueryString(queryString, true);
|
||||
if (queryParams != null && !queryParams.isEmpty()) {
|
||||
|
||||
@@ -271,7 +271,7 @@ public class ServletRedirectResult extends StrutsResultSupport implements Reflec
|
||||
try {
|
||||
String rawUrl = url;
|
||||
if (url.contains("?")) {
|
||||
rawUrl = url.substring(0, url.indexOf("?"));
|
||||
rawUrl = url.substring(0, url.indexOf('?'));
|
||||
}
|
||||
URI uri = URI.create(rawUrl.replaceAll(" ", "%20"));
|
||||
if (uri.isAbsolute()) {
|
||||
|
||||
@@ -98,7 +98,7 @@ public class TagUtils {
|
||||
// last part (/foo/bar/baz.xyz -> /foo/bar)
|
||||
|
||||
String path = RequestUtils.getServletPath(request);
|
||||
return path.substring(0, path.lastIndexOf("/"));
|
||||
return path.substring(0, path.lastIndexOf('/'));
|
||||
}
|
||||
} else {
|
||||
return invocation.getProxy().getNamespace();
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ public abstract class AbstractDirective extends Directive {
|
||||
// node.value uses the StrutsValueStack to evaluate the directive's value parameter
|
||||
String param = node.value(contextAdapter).toString();
|
||||
|
||||
int idx = param.indexOf("=");
|
||||
int idx = param.indexOf('=');
|
||||
|
||||
if (idx != -1) {
|
||||
String property = param.substring(0, idx);
|
||||
|
||||
Reference in New Issue
Block a user