View Javadoc

1   /*
2    * Copyright 2000-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.portals.bridges.struts.taglib;
17  
18  import javax.servlet.ServletRequest; // javadoc
19  import javax.servlet.jsp.JspException;
20  
21  import org.apache.portals.bridges.struts.PortletServlet;
22  
23  /***
24   * Supports the Struts html:image tag to be used within a Portlet context allowing relative
25   * img src paths.
26   * 
27   * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
28   * @version $Id: ImageTag.java 188222 2005-01-20 02:41:15 +0100 (Thu, 20 Jan 2005) ate $
29   */
30  public class ImageTag extends org.apache.struts.taglib.html.ImageTag 
31  {
32      /***
33       * Allow a relative img src path to be used within a PortletRequest context.
34       * <p>
35       * Temporarily modifies the {@link #src} attribute value (if defined and if within the
36       * context of a {@link PortletServlet#isPortletRequest(ServletRequest) PortletRequest}).<br/>
37       * A relative src path is changed to a context relative path using the current
38       * request uri.</p>
39       * @return {@link #EVAL_PAGE}
40       */
41      public int doEndTag() throws JspException
42      {
43          String src = getSrc();
44          if ( PortletServlet.isPortletRequest(pageContext.getRequest()) && src != null ) 
45          {
46              try
47              {
48                  setSrc(TagsSupport.getContextRelativeURL(pageContext,src,true));
49                  super.doEndTag();
50              }
51              finally
52              {
53                  setSrc(src);
54              }
55          }
56          else
57          {
58              super.doEndTag();
59          }
60          return (EVAL_PAGE);
61      }
62  }