001: /* ExtendletContext.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Mon Aug 29 18:27:04 2005, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.web.util.resource;
020:
021: import java.util.Map;
022: import java.io.InputStream;
023: import java.io.UnsupportedEncodingException;
024: import java.net.URL;
025:
026: import javax.servlet.ServletContext;
027: import javax.servlet.ServletRequest;
028: import javax.servlet.ServletResponse;
029: import javax.servlet.ServletException;
030: import javax.servlet.RequestDispatcher;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: import org.zkoss.util.resource.Locator;
035:
036: /**
037: * This interface defines an extended context that
038: * {@link org.zkoss.web.servlet.Servlets#getRequestDispatcher} will try to
039: * resolve.
040: * When {@link org.zkoss.web.servlet.Servlets#getRequestDispatcher} is
041: * called, it detects whether ~xxx/ is specified.
042: * If specified, it looks up any extended context
043: * is registered as xxx. If found, the extend context is used.
044: * If not found, it looks up any servlet context called xxx.
045: *
046: * <p>To registers an extended context, use
047: * {@link org.zkoss.web.servlet.Servlets#addExtendletContext}.
048: *
049: * @author tomyeh
050: */
051: public interface ExtendletContext {
052: /** Returns the encoded URL.
053: * The returned URL is also encoded with HttpServletResponse.encodeURL.
054: *
055: * <p>It resolves "*" contained in URI, if any, to the proper Locale,
056: * and the browser code.
057: * Refer to {@link org.zkoss.web.servlet.Servlets#locate(javax.servlet.ServletContext, ServletRequest, String, org.zkoss.util.resource.Locator)}
058: * for details.
059: *
060: * @param uri it must be empty or starts with "/". It might contain
061: * "*" for current browser code and Locale.
062: * @return the complete URI (excluding the machine name).
063: * It includes the context path and the servelt to interpret
064: * this extended resource.
065: */
066: public String encodeURL(ServletRequest request,
067: ServletResponse response, String uri)
068: throws ServletException, UnsupportedEncodingException;
069:
070: /** Returns the encoded URL for send redirect.
071: * The URL is also encoded with HttpServletResposne.encodeRedirectURL.
072: */
073: public String encodeRedirectURL(HttpServletRequest request,
074: HttpServletResponse response, String uri, Map params,
075: int mode);
076:
077: /* Returns the request dispatcher that acts as a wrapper for
078: * the resource located at the given path, or null if not found.
079: */
080: public RequestDispatcher getRequestDispatcher(String uri);
081:
082: /** Returns the URL of the specified URI, or null if not found.
083: */
084: public URL getResource(String uri);
085:
086: /** Returns the resource of the specified URI as input stream,
087: * or null if not found.
088: */
089: public InputStream getResourceAsStream(String uri);
090:
091: /** Returns the servlet context.
092: */
093: public ServletContext getServletContext();
094:
095: /** Returns the locator of this context used to locate resorces.
096: */
097: public Locator getLocator();
098:
099: /** Tests whether to compress the specified extension, e.g, "js" and
100: * "css".
101: *
102: * <p>It returns false if the request is included by other Serlets.
103: */
104: public boolean shallCompress(ServletRequest request, String ext);
105: }
|