From cb1bf4ef26ab3771315412ec432c87790d709bae Mon Sep 17 00:00:00 2001 From: Jan Materne Date: Thu, 20 Sep 2007 14:33:40 +0000 Subject: [PATCH] Factor removeSuffix() out. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@577772 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/taskdefs/optional/jsp/JspNameMangler.java | 11 +++-------- .../org/apache/tools/ant/util/StringUtils.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspNameMangler.java b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspNameMangler.java index 1de57635d..6aaae5c25 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspNameMangler.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspNameMangler.java @@ -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"); } diff --git a/src/main/org/apache/tools/ant/util/StringUtils.java b/src/main/org/apache/tools/ant/util/StringUtils.java index fc867355a..74c8adfc9 100644 --- a/src/main/org/apache/tools/ant/util/StringUtils.java +++ b/src/main/org/apache/tools/ant/util/StringUtils.java @@ -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 string with the suffix + */ + public static String removeSuffix(String string, String suffix) { + if (string.endsWith(suffix)) { + return string.substring(0, string.length() - suffix.length()); + } else { + return string; + } + } }