Servlet/PortletContextResource's "isReadable()" implementation returns false for directories (SPR-9067)

This commit is contained in:
Juergen Hoeller 2012-02-07 10:38:49 +01:00
parent 7a170e8005
commit f8238f5243
2 changed files with 46 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2011 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -107,6 +107,28 @@ public class PortletContextResource extends AbstractFileResolvingResource implem
} }
} }
/**
* This implementation delegates to <code>PortletContext.getResourceAsStream</code>,
* which returns <code>null</code> in case of a non-readable resource (e.g. a directory).
* @see javax.portlet.PortletContext#getResourceAsStream(String)
*/
@Override
public boolean isReadable() {
InputStream is = this.portletContext.getResourceAsStream(this.path);
if (is != null) {
try {
is.close();
}
catch (IOException ex) {
// ignore
}
return true;
}
else {
return false;
}
}
/** /**
* This implementation delegates to <code>PortletContext.getResourceAsStream</code>, * This implementation delegates to <code>PortletContext.getResourceAsStream</code>,
* but throws a FileNotFoundException if not found. * but throws a FileNotFoundException if not found.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2011 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -107,6 +107,28 @@ public class ServletContextResource extends AbstractFileResolvingResource implem
} }
} }
/**
* This implementation delegates to <code>ServletContext.getResourceAsStream</code>,
* which returns <code>null</code> in case of a non-readable resource (e.g. a directory).
* @see javax.servlet.ServletContext#getResourceAsStream(String)
*/
@Override
public boolean isReadable() {
InputStream is = this.servletContext.getResourceAsStream(this.path);
if (is != null) {
try {
is.close();
}
catch (IOException ex) {
// ignore
}
return true;
}
else {
return false;
}
}
/** /**
* This implementation delegates to <code>ServletContext.getResourceAsStream</code>, * This implementation delegates to <code>ServletContext.getResourceAsStream</code>,
* but throws a FileNotFoundException if no resource found. * but throws a FileNotFoundException if no resource found.