WW-3044 Replace code by similar code in commons lang

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@755607 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Musachy Barroso
2009-03-18 14:41:00 +00:00
parent 526580cc2d
commit e6cfa82cd0
6 changed files with 16 additions and 84 deletions
@@ -21,6 +21,7 @@
package org.apache.struts2.convention;
import com.opensymphony.xwork2.inject.Inject;
import org.apache.commons.lang.xwork.StringUtils;
/**
* <p>
@@ -46,7 +47,7 @@ public class DefaultActionNameBuilder implements ActionNameBuilder {
*/
@Inject(value = "struts.convention.action.suffix", required = false)
public void setActionSuffix(String actionSuffix) {
if (!StringTools.isTrimmedEmpty(actionSuffix)) {
if (StringUtils.isNotBlank(actionSuffix)) {
this.actionSuffix = actionSuffix;
}
}
@@ -32,6 +32,7 @@ import javax.servlet.ServletContext;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.commons.lang.xwork.StringUtils;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.config.ConfigurationException;
@@ -440,9 +441,9 @@ public class DefaultResultMapBuilder implements ResultMapBuilder {
public ResultInfo(Result result, PackageConfig packageConfig, String resultPath,
Class<?> actionClass, Map<String, ResultTypeConfig> resultsByExtension) {
this.name = result.name();
if (!StringTools.isTrimmedEmpty(result.type())) {
if (StringUtils.isNotBlank(result.type())) {
this.type = result.type();
} else if (!StringTools.isTrimmedEmpty(result.location())) {
} else if (StringUtils.isNotBlank(result.location())) {
this.type = determineType(result.location(), packageConfig, resultsByExtension);
} else {
throw new ConfigurationException("The action class [" + actionClass + "] contains a " +
@@ -451,7 +452,7 @@ public class DefaultResultMapBuilder implements ResultMapBuilder {
}
// See if we can handle relative locations or not
if (!StringTools.isTrimmedEmpty(result.location())) {
if (StringUtils.isNotBlank(result.location())) {
if (relativeResultTypes.contains(this.type) && !result.location().startsWith("/")) {
location = resultPath + result.location();
} else {
@@ -146,7 +146,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
*/
@Inject("struts.convention.action.fileProtocols")
public void setFileProtocols(String fileProtocols) {
if (!StringTools.isTrimmedEmpty(fileProtocols)) {
if (StringUtils.isNotBlank(fileProtocols)) {
this.fileProtocols = TextParseUtil.commaDelimitedStringToSet(fileProtocols);
}
}
@@ -182,7 +182,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
*/
@Inject(value = "struts.convention.action.packages", required = false)
public void setActionPackages(String actionPackages) {
if (!StringTools.isTrimmedEmpty(actionPackages)) {
if (StringUtils.isNotBlank(actionPackages)) {
this.actionPackages = actionPackages.split("\\s*[,]\\s*");
}
}
@@ -202,7 +202,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
*/
@Inject(value = "struts.convention.action.suffix", required = false)
public void setActionSuffix(String actionSuffix) {
if (!StringTools.isTrimmedEmpty(actionSuffix)) {
if (StringUtils.isNotBlank(actionSuffix)) {
this.actionSuffix = actionSuffix;
}
}
@@ -213,7 +213,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
*/
@Inject(value = "struts.convention.exclude.packages", required = false)
public void setExcludePackages(String excludePackages) {
if (!StringTools.isTrimmedEmpty(excludePackages)) {
if (StringUtils.isNotBlank(excludePackages)) {
this.excludePackages = excludePackages.split("\\s*[,]\\s*");
}
}
@@ -681,7 +681,7 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
if (annotation != null) {
actionName = annotation.value() != null && annotation.value().equals(Action.DEFAULT_VALUE) ?
actionName : annotation.value();
actionName = StringTools.lastToken(actionName, "/");
actionName = StringUtils.contains(actionName, "/") ? StringUtils.substringAfterLast(actionName, "/") : actionName;
}
ActionConfig.Builder actionConfig = new ActionConfig.Builder(pkgCfg.getName(),
@@ -758,7 +758,8 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
if (LOG.isTraceEnabled()) {
LOG.trace("Using non-default action namespace from the Action annotation of [#0]", action.value());
}
actionNamespace = StringTools.upToLastToken(action.value(), "/");
String actionName = action.value();
actionNamespace = StringUtils.contains(actionName, "/") ? StringUtils.substringBeforeLast(actionName, "/") : StringUtils.EMPTY;
}
// Next grab the parent annotation from the class
@@ -23,6 +23,7 @@ package org.apache.struts2.convention;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.commons.lang.xwork.StringUtils;
/**
* <p>
@@ -51,7 +52,7 @@ public class SEOActionNameBuilder implements ActionNameBuilder {
*/
@Inject(value = "struts.convention.action.suffix", required = false)
public void setActionSuffix(String actionSuffix) {
if (!StringTools.isTrimmedEmpty(actionSuffix)) {
if (StringUtils.isNotBlank(actionSuffix)) {
this.actionSuffix = actionSuffix;
}
}
@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.Map;
import com.opensymphony.xwork2.config.ConfigurationException;
import org.apache.commons.lang.xwork.StringUtils;
/**
* <p>
@@ -31,19 +32,6 @@ import com.opensymphony.xwork2.config.ConfigurationException;
* </p>
*/
public class StringTools {
public static boolean isTrimmedEmpty(String s) {
return s == null || s.trim().length() == 0;
}
public static String lastToken(String str, String s) {
int index = str.lastIndexOf(s);
if (index >= 0) {
return str.substring(index + 1);
}
return str;
}
public static boolean contains(String[] strings, String value, boolean ignoreCase) {
if (strings != null) {
for (String string : strings) {
@@ -55,15 +43,6 @@ public class StringTools {
return false;
}
public static String upToLastToken(String str, String s) {
int index = str.lastIndexOf(s);
if (index >= 0) {
return str.substring(0, index);
}
return "";
}
public static Map<String, String> createParameterMap(String[] parms) {
Map<String, String> map = new HashMap<String, String>();
int subtract = parms.length % 2;
@@ -1,51 +0,0 @@
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2.convention;
import junit.framework.TestCase;
/**
* <p>
* This class tests the string tools.
* </p>
*/
public class StringToolsTest extends TestCase {
public void testEmpty() {
assertTrue(StringTools.isTrimmedEmpty(null));
assertTrue(StringTools.isTrimmedEmpty(""));
assertTrue(StringTools.isTrimmedEmpty(" "));
assertFalse(StringTools.isTrimmedEmpty("f"));
assertFalse(StringTools.isTrimmedEmpty(" f "));
}
public void testLastToken() {
assertEquals("bar", StringTools.lastToken("/foo/bar", "/"));
assertEquals("baz", StringTools.lastToken("/foo/bar/baz", "/"));
assertEquals("baz", StringTools.lastToken("baz", "/"));
}
public void testUpToLastToken() {
assertEquals("/foo", StringTools.upToLastToken("/foo/bar", "/"));
assertEquals("/foo/bar", StringTools.upToLastToken("/foo/bar/baz", "/"));
assertEquals("", StringTools.upToLastToken("/foo", "/"));
assertEquals("", StringTools.upToLastToken("foo", "/"));
}
}