joerg 2003/05/30 17:06:30
Modified: src/java/org/apache/cocoon/components/language/markup/xsp XSPUtil.java Log: bug 15302 fixed: context.getResource(filename) on a non-existant file returns null, so testing for null and throwing a FileNotFoundException Revision Changes Path 1.5 +14 -9 cocoon-2.1/src/java/org/apache/cocoon/components/language/markup/xsp/XSPUtil.java Index: XSPUtil.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/language/markup/xsp/XSPUtil.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- XSPUtil.java 16 May 2003 07:04:55 -0000 1.4 +++ XSPUtil.java 31 May 2003 00:06:29 -0000 1.5 @@ -74,8 +74,10 @@ import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; +import java.io.FileNotFoundException; import java.net.URLDecoder; import java.net.URLEncoder; +import java.net.URL; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; @@ -136,14 +138,17 @@ return buffer.toString(); } - public static String relativeFilename(String filename, Map objectModel) - throws IOException { - File file = new File(filename); - if (file.isAbsolute() && file.exists()) { - return filename; - } - Context context = ObjectModelHelper.getContext(objectModel); - return NetUtils.getPath(context.getResource(filename).toExternalForm()); + public static String relativeFilename(String filename, Map objectModel) throws IOException { + File file = new File(filename); + if (file.isAbsolute() && file.exists()) { + return filename; + } + Context context = ObjectModelHelper.getContext(objectModel); + URL resource = context.getResource(filename); + if (resource == null) { + throw new FileNotFoundException("The file " + filename + " does not exist!"); + } + return NetUtils.getPath(resource.toExternalForm()); } public static boolean isAlphaNumeric(char c) {