Skip to content

Commit

Permalink
bug fix for inconsistent behavior when using resource.dir
Browse files Browse the repository at this point in the history
  • Loading branch information
DevChu committed Oct 11, 2016
1 parent 3b3e4f3 commit 32b9ec1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
5 changes: 3 additions & 2 deletions zk/src/org/zkoss/zk/ui/http/WebManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ public WebManager(ServletContext ctx, String updateURI) {
_cwr.setCompress(new String[] {"js", "css", "html", "xml"});
String s = Library.getProperty("org.zkoss.web.util.resource.dir");
if (s != null && s.length() > 0) {
if (s.charAt(0) != '/') s = '/' + s;
_cwr.setExtraLocator(new ServletContextLocator(_ctx, null, s)); //for safety, not accept URL
if (s.charAt(0) != '/')
s = '/' + s;
_cwr.setExtraLocator(new ServletContextLocator(_ctx, null, s, false, ClassWebResource.PATH_PREFIX)); //for safety, not accept URL
}

String[] labellocs = config.getLabelLocations();
Expand Down
31 changes: 19 additions & 12 deletions zweb/src/org/zkoss/web/util/resource/ServletContextLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ public class ServletContextLocator implements Locator {
private final ServletContext _ctx;
private final String _dir, _prefix;
private final boolean _acceptURL;
private final String _externalPrefix;

/** Constructor.
* A short cut of ServletContextLocator(ctx, null, null, false)
*/
public ServletContextLocator(ServletContext ctx) {
this(ctx, null, null, false);
this(ctx, null, null, false, null);
}
/** Constructor.
* @param acceptURL whether to URL (such as file:/, http:// and
Expand All @@ -48,22 +49,29 @@ public ServletContextLocator(ServletContext ctx) {
* @since 5.0.7
*/
public ServletContextLocator(ServletContext ctx, boolean acceptURL) {
this(ctx, null, null, acceptURL);
this(ctx, null, null, acceptURL, null);
}
/** Constructor.
* A short of ServletContextLocator(ctx, dir, null, false).
* A short of ServletContextLocator(ctx, dir, null, false, null).
* @param dir the directory used when relative path is specified
* (for {@link #getResource} and {@link #getResourceAsStream}).
* It must be null, empty, or starts with /.
*/
public ServletContextLocator(ServletContext ctx, String dir) {
this(ctx, dir, null, false);
this(ctx, dir, null, false, null);
}
/** Constructor.
* A short cut of ServletContextLocator(ctx, dir, prefix, false).
* A short cut of ServletContextLocator(ctx, dir, prefix, false, null).
*/
public ServletContextLocator(ServletContext ctx, String dir, String prefix) {
this(ctx, dir, prefix, false);
this(ctx, dir, prefix, false, null);
}

/** Constructor.
* A short cut of ServletContextLocator(ctx, dir, prefix, acceptURL, null).
*/
public ServletContextLocator(ServletContext ctx, String dir, String prefix, boolean acceptURL) {
this(ctx, dir, prefix, acceptURL, null);
}
/** Constructor.
* For example, if prefix is "/WEB-INF/cwr", then getResource("/abc") will
Expand All @@ -82,8 +90,7 @@ public ServletContextLocator(ServletContext ctx, String dir, String prefix) {
* ftp://) are accepted. In other words, {@link Servlets#getResource}
* will be used.
*/
public ServletContextLocator(ServletContext ctx, String dir, String prefix,
boolean acceptURL) {
public ServletContextLocator(ServletContext ctx, String dir, String prefix, boolean acceptURL, String externalPrefix) {
if (ctx == null)
throw new IllegalArgumentException("null");
if (dir != null) {
Expand Down Expand Up @@ -113,6 +120,7 @@ else if (prefix.charAt(len - 1) == '/')
_dir = dir;
_prefix = prefix;
_acceptURL = acceptURL;
_externalPrefix = externalPrefix;
}

/** Returns the servlet context. */
Expand All @@ -121,10 +129,9 @@ public ServletContext getServletContext() {
}

private String fixName(String name, boolean prefix) {
name = name.length() > 0 && name.charAt(0) != '/' ?
_dir != null ? _dir + name:
prefix && _prefix != null ? '/' + name: name: name;
return prefix && _prefix != null ? _prefix + name: name;
name = name.length() > 0 && name.charAt(0) != '/'
? _dir != null ? _dir + name : prefix && _prefix != null ? '/' + name : name : name;
return prefix && _prefix != null ? _prefix + name : (_externalPrefix == null ? "" : _externalPrefix) + name;
}

//-- Locator --//
Expand Down

0 comments on commit 32b9ec1

Please sign in to comment.