>I've implemented a simple taglib class to support URL rewriting for 
>the <frame> tag.
>
>It's a simple subclass of LinkTag overriding doStartTag to include 
>added attributes and put the URI in "src" instead of "href".  It 
>supports all of the attributes in HTML 4.0 
><http://www.w3.org/TR/REC-html40/present/frames.html#h-16.2.2>
>
>One question I would consider open is how to best handle "longdesc" 
>-- this is an HTML 4.0 attribute (which I'd never heard of before) 
>which is supposed to take a URI.  I simply put it in as an attribute 
>which would be copied over, but probably it should support all of 
>the same URL rewriting that other URIs can get.  Coming up with a 
>graceful solution to that is more than I have time for right now.

Here is the code, followed by the <tag> fragment for struts-html.tld


--------begin (org.apache.struts.taglib.html) FrameTag.java -------------
package org.apache.struts.taglib.html;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionForwards;
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.RequestUtils;
import org.apache.struts.util.ResponseUtils;

/**
  * Provide URL Rewriting for Frame tags.  The frame <code>src</code> attribute
  * value is constructed using the same attributes as those used in
  * <code>LinkTag</code> to render <code>href</code>.  Additionally, 
the HTML 4.0
  * frame tag attributes <code>noresize</code>, <code>scrolling</code>,
  * <code>marginheight</code>, <code>marginwidth</code>,
  * <code>frameborder</code>, and <code>longdesc</code> are supported. 
The frame
  * <code>name</code> attribute is rendered based on the <code>frameName</code>
  * property.
  *
  * Note that the value of <code>longdesc</code> is intended to be a URI, but
  * currently no rewriting is supported.  The attribute is set directly from
  * the property value.
  *
  * @author Joe Germuska
  */
public class FrameTag extends LinkTag
{


     /**
      * Render the appropriately encoded URI.
      *
      * @exception JspException if a JSP exception has occurred
      */
     public int doStartTag() throws JspException {

        // Generate the hyperlink URL
         Map params = RequestUtils.computeParameters
             (pageContext, paramId, paramName, paramProperty, paramScope,
              name, property, scope, transaction);
         String url = null;
         try {
             url = RequestUtils.computeURL(pageContext, forward, href,
                                           page, params, anchor, false);
         } catch (MalformedURLException e) {
             RequestUtils.saveException(pageContext, e);
             throw new JspException
                 (messages.getMessage("rewrite.url", e.toString()));
         }

        // Print this element to our output writer
         StringBuffer results = new StringBuffer("<frame ");
         results.append("src=\"");
         results.append(url);
         results.append("\"");
         if (frameName != null)
         {
            results.append(" name=\"");
            results.append(frameName);
            results.append("\"");
         }
         if (noresize != null)
         {
            results.append(" noresize");
         }
         if (scrolling != null)
         {
            results.append(" scrolling=\"");
            results.append(scrolling);
            results.append("\"");
         }
         if (marginheight != null)
         {
            results.append(" marginheight=\"");
            results.append(marginheight);
            results.append("\"");
         }
         if (marginwidth != null)
         {
            results.append(" marginwidth=\"");
            results.append(marginwidth);
            results.append("\"");
         }
         if (frameborder != null)
         {
            results.append(" frameborder=\"");
            results.append(frameborder);
            results.append("\"");
         }
         if (longdesc != null)
         {
            results.append(" longdesc=\"");
            results.append(frameborder);
            results.append("\"");
         }
         results.append(prepareStyles());
         results.append(">");
         ResponseUtils.write(pageContext,results.toString());

        // Skip the body of this tag
        return (SKIP_BODY);

     }

     /**
      * Ignore the end of this tag.
      *
      * @exception JspException if a JSP exception has occurred
      */
     public int doEndTag() throws JspException {

         return (EVAL_PAGE);

     }
   public String getNoresize()
   {
     return noresize;
   }
   public void setNoresize(String noresize)
   {
     this.noresize = noresize;
   }
   public void setScrolling(String scrolling)
   {
     this.scrolling = scrolling;
   }
   public String getScrolling()
   {
     return scrolling;
   }
   public void setMarginheight(String marginheight)
   {
     this.marginheight = marginheight;
   }
   public String getMarginheight()
   {
     return marginheight;
   }
   public void setMarginwidth(String marginwidth)
   {
     this.marginwidth = marginwidth;
   }
   public String getMarginwidth()
   {
     return marginwidth;
   }
   public void setFrameName(String frameName)
   {
     this.frameName = frameName;
   }
   public String getFrameName()
   {
     return frameName;
   }
   public void setFrameborder(String frameborder)
   {
     this.frameborder = frameborder;
   }
   public String getFrameborder()
   {
     return frameborder;
   }
   public void setLongdesc(String longdesc)
   {
     this.longdesc = longdesc;
   }
   public String getLongdesc()
   {
     return longdesc;
   }

   private String noresize;
   private String scrolling;
   private String marginheight;
   private String marginwidth;
   private String frameName;
   private String frameborder;
   private String longdesc;


}
------- end (org.apache.struts.taglib.html) FrameTag.java -------
------- begin fragment for struts-html.tld -------
<tag>
<name>frame</name>
<tagclass>org.apache.struts.taglib.html.FrameTag</tagclass>
<attribute>
<name>anchor</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>forward</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>href</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>frameName</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>longdesc</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>page</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>paramId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>paramName</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>paramProperty</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>paramScope</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>property</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>scope</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>transaction</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>style</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>styleClass</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>styleId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>title</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
------- begin fragment for struts-html.tld -------

-- 
--
* Joe Germuska    { [EMAIL PROTECTED] }
"It's pitiful, sometimes, if they've got it bad. Their eyes get 
glazed, they go white, their hands tremble.... As I watch them I 
often feel that a dope peddler is a gentleman compared with the man 
who sells records."
        --Sam Goody, 1956
tune in posse radio: <http://www.live365.com/stations/289268>

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

Reply via email to