org.zkoss.web.util.resource
Class ServletContextLocator

java.lang.Object
  extended by org.zkoss.web.util.resource.ServletContextLocator
All Implemented Interfaces:
org.zkoss.util.resource.Locator

public class ServletContextLocator
extends Object
implements org.zkoss.util.resource.Locator

Locator based on ServletContext.

Author:
tomyeh

Constructor Summary
ServletContextLocator(javax.servlet.ServletContext ctx)
          Constructor.
ServletContextLocator(javax.servlet.ServletContext ctx, boolean acceptURL)
          Constructor.
ServletContextLocator(javax.servlet.ServletContext ctx, String dir)
          Constructor.
ServletContextLocator(javax.servlet.ServletContext ctx, String dir, String prefix)
          Constructor.
ServletContextLocator(javax.servlet.ServletContext ctx, String dir, String prefix, boolean acceptURL)
          Constructor.
 
Method Summary
 boolean equals(Object o)
           
 String getDirectory()
           
 URL getResource(String name)
           
 InputStream getResourceAsStream(String name)
           
 javax.servlet.ServletContext getServletContext()
          Returns the servlet context.
 int hashCode()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletContextLocator

public ServletContextLocator(javax.servlet.ServletContext ctx)
Constructor. A short cut of ServletContextLocator(ctx, null, null, false)


ServletContextLocator

public ServletContextLocator(javax.servlet.ServletContext ctx,
                             boolean acceptURL)
Constructor.

Parameters:
acceptURL - whether to URL (such as file:/, http:// and ftp://) are accepted. In other words, Servlets.getResource(javax.servlet.ServletContext, java.lang.String) will be used.
Since:
5.0.7
See Also:
Servlets.getResource(javax.servlet.ServletContext, java.lang.String)

ServletContextLocator

public ServletContextLocator(javax.servlet.ServletContext ctx,
                             String dir)
Constructor. A short of ServletContextLocator(ctx, dir, null, false).

Parameters:
dir - the directory used when relative path is specified (for getResource(java.lang.String) and getResourceAsStream(java.lang.String)). It must be null, empty, or starts with /.

ServletContextLocator

public ServletContextLocator(javax.servlet.ServletContext ctx,
                             String dir,
                             String prefix)
Constructor. A short cut of ServletContextLocator(ctx, dir, prefix, false).


ServletContextLocator

public ServletContextLocator(javax.servlet.ServletContext ctx,
                             String dir,
                             String prefix,
                             boolean acceptURL)
Constructor. For example, if prefix is "/WEB-INF/cwr", then getResource("/abc") will look for "/WEB-INF/cwr/abc" first, and then "/abc".

Another example, if prefix is "/WEB-INF/cwr" and dir is "/subdir", then getResource("abc") will look for "/WEB-INF/cwr/subdir/abc".

Parameters:
dir - the directory used when relative path is specified (for getResource(java.lang.String) and getResourceAsStream(java.lang.String)). It must be null, empty, or starts with /.
prefix - the directory to prefix each directory specified (for getResource(java.lang.String) and getResourceAsStream(java.lang.String)). It must be null, empty, or starts with /.
acceptURL - whether to URL (such as file:/, http:// and ftp://) are accepted. In other words, Servlets.getResource(javax.servlet.ServletContext, java.lang.String) will be used.
Method Detail

getServletContext

public javax.servlet.ServletContext getServletContext()
Returns the servlet context.


getDirectory

public String getDirectory()
Specified by:
getDirectory in interface org.zkoss.util.resource.Locator

getResource

public URL getResource(String name)
Specified by:
getResource in interface org.zkoss.util.resource.Locator

getResourceAsStream

public InputStream getResourceAsStream(String name)
Specified by:
getResourceAsStream in interface org.zkoss.util.resource.Locator

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object


Copyright © 2015. All rights reserved.