Servlet/PortletContextResource's getFile prefers "file:" URL resolution over calling getRealPath (SPR-8461)

This commit is contained in:
Juergen Hoeller
2011-11-28 16:51:52 +00:00
parent bfabd58106
commit 12e1784a99
2 changed files with 30 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ import org.springframework.core.io.AbstractFileResolvingResource;
import org.springframework.core.io.ContextResource;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.portlet.util.PortletUtils;
@@ -135,14 +136,23 @@ public class PortletContextResource extends AbstractFileResolvingResource implem
}
/**
* This implementation delegates to <code>PortletContext.getRealPath</code>,
* but throws a FileNotFoundException if not found or not resolvable.
* This implementation resolves "file:" URLs or alternatively delegates to
* <code>PortletContext.getRealPath</code>, throwing a FileNotFoundException
* if not found or not resolvable.
* @see javax.portlet.PortletContext#getResource(String)
* @see javax.portlet.PortletContext#getRealPath(String)
*/
@Override
public File getFile() throws IOException {
String realPath = PortletUtils.getRealPath(this.portletContext, this.path);
return new File(realPath);
URL url = getURL();
if (ResourceUtils.isFileURL(url)) {
// Proceed with file system resolution...
return super.getFile();
}
else {
String realPath = PortletUtils.getRealPath(this.portletContext, this.path);
return new File(realPath);
}
}
@Override