View Javadoc

1   package org.gnomekr.potron.web.tag;
2   
3   import javax.servlet.http.HttpServletRequest;
4   import javax.servlet.jsp.JspException;
5   import javax.servlet.jsp.JspWriter;
6   import javax.servlet.jsp.tagext.TagSupport;
7   
8   import org.apache.commons.logging.Log;
9   import org.apache.commons.logging.LogFactory;
10  
11  /***
12   * BaseTag.java
13   * @author Xavier Cho
14   * @version $Revision 1.1 $ $Date: 2005/07/07 15:20:15 $
15   * @jsp:tag
16   *      name="base"
17   *      body-content="empty"
18   */
19  public class BaseTag extends TagSupport {
20  
21      private static final long serialVersionUID = 3691043187980775476L;
22  
23      /***
24       * @see javax.servlet.jsp.tagext.Tag#doStartTag()
25       */
26      public int doStartTag() throws JspException {
27          try {
28              HttpServletRequest request = (HttpServletRequest) pageContext
29                      .getRequest();
30              String url = request.getRequestURL().toString();
31              url = url.substring(0, url.length()
32                      - request.getRequestURI().length()
33                      + request.getContextPath().length());
34  
35              JspWriter out = pageContext.getOut();
36              out.print("<base href=\"");
37              out.print(url);
38              out.print("/\"/>");
39          } catch (Exception e) {
40              String msg = "Unable to write tag content : " + e.getMessage();
41  
42              Log log = LogFactory.getLog(getClass());
43              if (log.isErrorEnabled()) {
44                  log.error(msg, e);
45              }
46  
47              throw new JspException(msg);
48          } finally {
49              release();
50          }
51  
52          return SKIP_BODY;
53      }
54  }