ate         2004/09/29 00:33:00

  Added:       portals-bridges/struts/src/java/org/apache/portals/bridges/struts/taglib
                        RewriteTag.java
  Log:
  Provide Portlet support for Struts RewriteTag
  
  Revision  Changes    Path
  1.1                  
jakarta-jetspeed-2/portals-bridges/struts/src/java/org/apache/portals/bridges/struts/taglib/RewriteTag.java
  
  Index: RewriteTag.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.portals.bridges.struts.taglib;
  
  import javax.servlet.jsp.JspException;
  import java.net.MalformedURLException;
  import java.util.Map;
  import org.apache.struts.taglib.TagUtils;
  
  import org.apache.portals.bridges.struts.StrutsPortletURL;
  
  /**
   * RewriteTag
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Ate Douma</a>
   * @version $Id: RewriteTag.java,v 1.1 2004/09/29 07:33:00 ate Exp $
   */
  public class RewriteTag extends org.apache.struts.taglib.html.RewriteTag 
  {
      protected String renderURL = null;
          
      public String getRenderURL()
      {
          return renderURL;
      }
      public void setRenderURL(String renderURL)
      {
          this.renderURL = renderURL;
      }
      
      protected String calculateURL() throws JspException 
      {
          if ( renderURL == null || !renderURL.equalsIgnoreCase("true") )
          {
              return 
StrutsPortletURL.createActionURL(pageContext.getRequest(),super.calculateURL()).toString();
          }
          else
          {
              return 
StrutsPortletURL.createRenderURL(pageContext.getRequest(),super.calculateURL()).toString();
          }
      }
      
      /**
       * Overwrite of Struts RewriteTag.doStartTag()
       *
       * @exception JspException if a JSP exception has occurred
       */
      public int doStartTag() throws JspException {
  
          // Generate the hyperlink URL
          Map params = TagUtils.getInstance().computeParameters
              (pageContext, paramId, paramName, paramProperty, paramScope,
               name, property, scope, transaction);
               
          String url = null;
          try {
              // Note that we're encoding the & character to &amp; in XHTML mode only, 
              // otherwise the & is written as is to work in javascripts. 
              url =
                  TagUtils.getInstance().computeURLWithCharEncoding(
                      pageContext,
                      forward,
                      href,
                      page,
                      action,
                      module,
                      params,
                      anchor,
                      false,
                      this.isXhtml(),
                      useLocalEncoding);
                      
          } catch (MalformedURLException e) {
              TagUtils.getInstance().saveException(pageContext, e);
              throw new JspException
                  (messages.getMessage("rewrite.url", e.toString()));
          }
  
          // create StrutsPortletURL
          if ( renderURL == null || !renderURL.equalsIgnoreCase("true") )
          {
              url = 
StrutsPortletURL.createActionURL(pageContext.getRequest(),url).toString();
          }
          else
          {
              url = 
StrutsPortletURL.createRenderURL(pageContext.getRequest(),url).toString();
          }
          
          TagUtils.getInstance().write(pageContext, url);
  
          return (SKIP_BODY);
  
      }
  
      /**
       * Release any acquired resources.
       */
      public void release() {
  
          super.release();
          renderURL = null;
      }
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to