Browse Source

Factor removeSuffix() out.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@577772 13f79535-47bb-0310-9956-ffa450edef68
master
Jan Materne 17 years ago
parent
commit
cb1bf4ef26
2 changed files with 18 additions and 8 deletions
  1. +3
    -8
      src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspNameMangler.java
  2. +15
    -0
      src/main/org/apache/tools/ant/util/StringUtils.java

+ 3
- 8
src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspNameMangler.java View File

@@ -18,6 +18,8 @@
package org.apache.tools.ant.taskdefs.optional.jsp;
import java.io.File;

import org.apache.tools.ant.util.StringUtils;

/**
* This is a class derived from the Jasper code
* (org.apache.jasper.compiler.CommandLineCompiler) to map from a JSP filename
@@ -109,14 +111,7 @@ public class JspNameMangler implements JspMangler {
* @return file without any jsp extension
*/
private String stripExtension(File jspFile) {
String className;
String filename = jspFile.getName();
if (filename.endsWith(".jsp")) {
className = filename.substring(0, filename.length() - ".jsp".length());
} else {
className = filename;
}
return className;
return StringUtils.removeSuffix(jspFile.getName(), ".jsp");
}




+ 15
- 0
src/main/org/apache/tools/ant/util/StringUtils.java View File

@@ -241,4 +241,19 @@ public final class StringUtils {
}
return factor * Long.parseLong(humanSize);
}

/**
* Removes the suffix from a given string, if the string contains
* that suffix.
* @param string String for check
* @param suffix Suffix to remove
* @return the <i>string</i> with the <i>suffix</i>
*/
public static String removeSuffix(String string, String suffix) {
if (string.endsWith(suffix)) {
return string.substring(0, string.length() - suffix.length());
} else {
return string;
}
}
}

Loading…
Cancel
Save