You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by mo...@apache.org on 2002/09/30 19:53:24 UTC

cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets IFramePortlet.java

morciuch    2002/09/30 10:53:24

  Modified:    src/java/org/apache/jetspeed/portal/portlets
                        IFramePortlet.java
  Log:
  Added support for align/marginwidth/marginheight properties of IFRAME tag + general clean up to satisfy the checkstyler
  
  Revision  Changes    Path
  1.2       +335 -108  jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/IFramePortlet.java
  
  Index: IFramePortlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/IFramePortlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IFramePortlet.java	25 Feb 2002 05:35:39 -0000	1.1
  +++ IFramePortlet.java	30 Sep 2002 17:53:24 -0000	1.2
  @@ -55,123 +55,148 @@
   package org.apache.jetspeed.portal.portlets;
   
   //Element Construction Set
  -import org.apache.ecs.html.*;
   import org.apache.ecs.ConcreteElement;
  -import org.apache.ecs.ElementContainer;
   import org.apache.ecs.StringElement;
   
   //Jetspeed stuff
  -import org.apache.jetspeed.portal.*;
  -import org.apache.jetspeed.util.*;
  -import org.apache.jetspeed.cache.disk.*;
  +import org.apache.jetspeed.portal.PortletException;
  +import org.apache.jetspeed.portal.PortletConfig;
   
   //turbine
  -import org.apache.turbine.util.*;
  +import org.apache.turbine.util.RunData;
  +import org.apache.turbine.util.Log;
  +import org.apache.turbine.util.ServerData;
  +import org.apache.turbine.services.servlet.TurbineServlet;
  +import org.apache.turbine.TurbineConstants;
  +import org.apache.turbine.util.DynamicURI;
   
  -//standard java stuff
  -import java.net.*;
  -import java.io.*;
  -
  -//ecs stuff
  -import org.apache.ecs.*;
  -import org.apache.ecs.html.*;
  +//JDK stuff
  +import java.util.Hashtable;
   
   /**
  - *  A Portlet that displays the contents of a source URL in an IFRAME tag.
  - *  portlets.xreg Usage example: 
  - *    <CODE>
  - *          <portlet-entry 
  - *            name="IFrame" 
  - *            hidden="false" 
  - *            type="abstract"
  - *              application="false" 
  - *        >
  - *              <classname>org.apache.jetspeed.portal.portlets.IFramePortlet</classname>
  - *          </portlet-entry> 
  - *    </CODE> 
  - *
  - * local-portlets.xreg Usage example: 
  - *    <CODE>
  - *          <portlet-entry 
  - *            name="SomeSite" 
  - *            hidden="false" 
  - *            type="ref"
  - *              parent="IFramePortlet" 
  - *            application="false" 
  - *        >
  - *            <meta-info> 
  - *                <title>SomeSite Info</title> 
  - *                <description>Navigate SomeSite within an IFRAME</description> 
  - *            </meta-info> 
  - *            <parameter name="source"
  - *                     value="http://somesite" 
  - *                   hidden="false"
  - *            />
  - *              <media-type ref="html"/> 
  - *        </portlet-entry> 
  - *    </CODE>
  - *
  - *    <P>The following parameters are accepted: </P>
  - *    <UL>
  - *        <LI> source - The target of the IFRAME, where it grabs it's content from.
  - *            Default is "http://127.0.0.1"
  - *        <LI> width - The width of the IFRAME, or null to let the browser decide.
  - *            Default is null.
  - *        <LI> height - The height of the IFRAME, or null to let the browser decide.
  - *            Default is null.
  - *        <LI> scrolling - How to display a scrollbar. 
  - *            Default is "auto", to let the browser decide.
  - *        <LI> frameborder - Whether or not to display a border around the IFRAME. 
  - *            Default is 1 (yes).
  - *    </UL>
  - *
  - *@author     <a href="mailto:wbarnhil@twcny.rr.com">Bill Barnhill</a>
  - *@created    February 23, 2002
  - *@see        AbstractPortlet
  + *   A Portlet that displays the contents of a source URL in an IFRAME tag.
  + *   portlets.xreg Usage example:
  + *     <PRE>
  + *           <portlet-entry name="IFrame" hidden="false" type="abstract" application="false">
  + *               <classname>org.apache.jetspeed.portal.portlets.IFramePortlet</classname>
  + *           </portlet-entry>
  + *     </PRE>
  + * 
  + *  local-portlets.xreg Usage example:
  + *     <PRE>
  + *           <portlet-entry name="SomeSite" hidden="false" type="ref" parent="IFramePortlet" application="false">
  + *             &lt;meta-info&gt;
  + *                 &lt;title&gt;SomeSite Info&lt;/title&gt;
  + *                 <description>Navigate SomeSite within an IFRAME</description>
  + *             &lt;/meta-info&gt;
  + *             <parameter name="source" value="http://somesite" hidden="false"/>
  + *             <media-type ref="html"/>
  + *           </portlet-entry>
  + *     </PRE>
  + * 
  + *     <P>The following parameters are accepted: </P>
  + *     <UL>
  + *         <LI> source - The target of the IFRAME, where it grabs it's content from. Can use ${webappRoot}.
  + *             Default is "http://127.0.0.1" </LI>
  + *         <LI> width - The width of the IFRAME, or null to let the browser decide.
  + *             Default is null.</LI>
  + *         <LI> height - The height of the IFRAME, or null to let the browser decide.
  + *             Default is null.</LI>
  + *         <LI> scrolling - How to display a scrollbar.
  + *             Default is "auto", to let the browser decide.</LI>
  + *         <LI> frameborder - Whether or not to display a border around the IFRAME.
  + *             Default is 1 (yes).</LI>
  + *         <LI> <code>refresh</code> - value in seconds to auto refresh contents of the IFRAME. </LI>
  + *         <LI> <code>align</code> - top | bottom | middle | left | <i>right</i> - How to align the IFRAME in relation to surrounding content.</LI>
  + *         <LI> <code>marginwidth</code> - size of the top and bottom margin inside the iframe. </LI>
  + *         <LI> <code>marginheight</code> - size of the left and right margin inside the iframe.</LI>
  + *     </UL>
  + * 
  + * @created February 23, 2002
  + * @author <a href="mailto:wbarnhil@twcny.rr.com">Bill Barnhill</a>
  + * @author <a href="mailto:morciuch@apache.org">Mark Orciuch</a>
  + * @see AbstractPortlet
    */
   
   public class IFramePortlet extends AbstractPortlet
   {
  -    final static String DEFAULT_NOTSUPP_MSG =
  -            "[Your user agent does not support inline frames or is currently" +
  -            " configured not to display frames.";
  -
  -    final static String DEFAULT_SOURCE = "http://127.0.0.1";
  -    final static String DEFAULT_WIDTH = null;
  -    final static String DEFAULT_HEIGHT = null;
  -    final static String DEFAULT_SCROLLING = "auto";
  -    final static String DEFAULT_FRAMEBORDER = "1";
  -
  -    final static String PARAM_SOURCE = "source";
  -    final static String PARAM_WIDTH = "width";
  -    final static String PARAM_HEIGHT = "height";
  -    final static String PARAM_SCROLLING = "scrolling";
  -    final static String PARAM_FRAMEBORDER = "frameborder";
  -
  -    String iSource = DEFAULT_SOURCE;
  -    String iWidth = DEFAULT_WIDTH;
  -    String iHeight = DEFAULT_HEIGHT;
  -    String iScrolling = DEFAULT_SCROLLING;
  -    String iFrameBorder = DEFAULT_FRAMEBORDER;
  -
  +    static final String DEFAULT_NOTSUPP_MSG =
  +            "[Your user agent does not support inline frames or is currently" 
  +            + " configured not to display frames]";
  +
  +    static final String DEFAULT_SOURCE = "http://127.0.0.1";
  +    static final String DEFAULT_WIDTH = null;
  +    static final String DEFAULT_HEIGHT = null;
  +    static final String DEFAULT_SCROLLING = "auto";
  +    static final String DEFAULT_FRAMEBORDER = "1";
  +
  +    static final String PARAM_SOURCE = "source";
  +    static final String PARAM_WIDTH = "width";
  +    static final String PARAM_HEIGHT = "height";
  +    static final String PARAM_SCROLLING = "scrolling";
  +    static final String PARAM_FRAMEBORDER = "frameborder";
  +    static final String PARAM_NAME = "name";
  +    static final String PARAM_STYLE = "style";    
  +    static final String PARAM_MARGINWIDTH = "marginwidth";
  +    static final String PARAM_MARGINHEIGHT = "marginheight";
  +    static final String PARAM_REFRESH = "refresh";
  +    static final String PARAM_ALIGN = "align";
  +    static final String WEBAPPROOT = "${" + TurbineConstants.WEBAPP_ROOT + "}";
  +
  +    private String iSource = DEFAULT_SOURCE;
  +    private String iWidth = DEFAULT_WIDTH;
  +    private String iHeight = DEFAULT_HEIGHT;
  +    private String iScrolling = DEFAULT_SCROLLING;
  +    private String iFrameBorder = DEFAULT_FRAMEBORDER;
  +    private String iMarginWidth = null;
  +    private String iMarginHeight = null;
  +    private String iStyle = null;
  +    private String iName = null;
  +    private String iRefresh = null;
  +    private String iAlign = null;
   
       /**
        *  Sets the source attribute of the IFramePortlet object
        *
  -     *@param  source  The new source value
  -     *@since
  +     * @param  source  The new source value
  +     * @since
        */
       public void setSource(String source)
       {
  -        iSource = source;
  -    }
  +        // Handle replacement variables
  +        Hashtable parms = new Hashtable();
  +        if (source.indexOf("${") >= 0) 
  +        {
  +            // Add all portlet parms
  +            parms.putAll(this.getPortletConfig().getInitParameters());
  +            // Add web app root variable replacement
  +            try 
  +            {
  +                ServerData sd = new ServerData(TurbineServlet.getServerName(),
  +                                            Integer.parseInt(TurbineServlet.getServerPort()),
  +                                            TurbineServlet.getServerScheme(),
  +                                            TurbineServlet.getContextPath(),
  +                                            TurbineServlet.getContextPath());
  +                DynamicURI uri = new DynamicURI(sd);                
  +                parms.put(TurbineConstants.WEBAPP_ROOT, uri.toString() + "/");
  +            } 
  +            catch (Exception e) 
  +            {
  +                Log.error(e);
  +            }
  +            // Add portlet name variable replacement
  +            parms.put("portlet", this.getName());
  +        }
  +    
  +        this.iSource = org.apache.jetspeed.util.StringUtils.replaceVars(source, parms);
   
  +    }
   
       /**
        *  Sets the scrolling attribute of the IFramePortlet object
        *
  -     *@param  scrolling  The new scrolling value
  -     *@since
  +     * @param  scrolling  The new scrolling value
  +     * @since
        */
       public void setScrolling(String scrolling)
       {
  @@ -182,8 +207,8 @@
       /**
        *  Sets the width attribute of the IFramePortlet object
        *
  -     *@param  width  The new width value
  -     *@since
  +     * @param  width  The new width value
  +     * @since
        */
       public void setWidth(String width)
       {
  @@ -194,8 +219,8 @@
       /**
        *  Sets the height attribute of the IFramePortlet object
        *
  -     *@param  height  The new height value
  -     *@since
  +     * @param  height  The new height value
  +     * @since
        */
       public void setHeight(String height)
       {
  @@ -206,20 +231,93 @@
       /**
        *  Sets the frameBorder attribute of the IFramePortlet object
        *
  -     *@param  frameBorder  The new frameBorder value
  -     *@since
  +     * @param  frameBorder  The new frameBorder value
  +     * @since
        */
       public void setFrameBorder(String frameBorder)
       {
           iFrameBorder = frameBorder;
       }
   
  +    /**
  +     *  Sets the width attribute of the IFramePortlet object
  +     * 
  +     * @param width  The new width value
  +     */
  +    public void setMarginWidth(String width) 
  +    {
  +
  +        iMarginWidth = width;
  +    }
  +
  +    /**
  +     *  Sets the marginheight attribute of the IFramePortlet object
  +     * 
  +     * @param height The new height value
  +     */
  +    public void setMarginHeight(String height) 
  +    {
  +
  +        iMarginHeight = height;
  +    }
  +
  +    /**
  +     *  Sets the marginheight attribute of the IFramePortlet object
  +     * 
  +     * @param height The new height value
  +     */
  +    public void setAlign(String value) 
  +    {
  +
  +        iAlign = value;
  +    }
  +
  +    /**
  +     *  Sets the refresh meta tag
  +     * 
  +     * @param value in seconds
  +     */
  +    public void setRefresh(String value) 
  +    {
  +
  +        iRefresh = value;
  +    }
  +
  +
  +    /**
  +     * Sets the style of iframe. Some useful style effects:
  +     * <UL>
  +     * <LI>border:5px dashed purple
  +     * <LI>border:5px dotted red
  +     * <LI>border:5px double red
  +     * <LI>border:5px inset red
  +     * </UL>
  +     * 
  +     * @param value
  +     */
  +    public void setStyle(String value) 
  +    {
  +
  +        iStyle = value;
  +    }
  +
  +    /**
  +     * Sets the name of iframe. This is useful when referencing
  +     * the iframe as a target from another link.
  +     * 
  +     * @param value
  +     */
  +    public void setFrameName(String value) 
  +    {
  +
  +        iName = value;
  +    }
   
       /**
        *  This methods outputs the content of the portlet for a given request.
        *
  -     *@param  runData  the RunData object for the request
  -     *@return          the content to be displayed to the user-agent
  +     * @param  runData  the RunData object for the request
  +     * @return          the content to be displayed to the user-agent
        */
       public ConcreteElement getContent(RunData runData)
       {
  @@ -233,10 +331,37 @@
           {
               text.append("width = \"" + getWidth() + "\" ");
           }
  +
           if (getHeight() != null)
           {
               text.append("height = \"" + getHeight() + "\" ");
           }
  +
  +        if (getFrameName() != null) 
  +        {
  +            text.append("name = \"" + getFrameName() + "\" ");
  +        }
  +
  +        if (getStyle() != null) 
  +        {
  +            text.append("style = \"" + getStyle() + "\" ");
  +        }
  +
  +        if (getMarginWidth() != null) 
  +        {
  +            text.append("marginwidth = \"" + getMarginWidth() + "\" ");
  +        }
  +
  +        if (getMarginHeight() != null) 
  +        {
  +            text.append("marginheight = \"" + getMarginHeight() + "\" ");
  +        }
  +
  +        if (getAlign() != null) 
  +        {
  +            text.append("align = \"" + getAlign() + "\" ");
  +        }
  +
           text.append("scrolling = \"" + getScrolling() + "\" ");
           text.append("frameborder = \"" + getFrameBorder() + "\" ");
           text.append(">");
  @@ -249,7 +374,7 @@
       /**
        *  Gets the source attribute of the IFramePortlet object
        *
  -     *@return    The source value
  +     * @return    The source value
        */
       public String getSource()
       {
  @@ -260,7 +385,7 @@
       /**
        *  Gets the scrolling attribute of the IFramePortlet object
        *
  -     *@return    The scrolling value
  +     * @return    The scrolling value
        */
       public String getScrolling()
       {
  @@ -271,7 +396,7 @@
       /**
        *  Gets the width attribute of the IFramePortlet object
        *
  -     *@return    The width value
  +     * @return    The width value
        */
       public String getWidth()
       {
  @@ -282,7 +407,7 @@
       /**
        *  Gets the height attribute of the IFramePortlet object
        *
  -     *@return    The height value
  +     * @return    The height value
        */
       public String getHeight()
       {
  @@ -293,7 +418,7 @@
       /**
        *  Gets whether to display a border around the IFRAME. "1" == yes.
        *
  -     *@return    The frameBorder value
  +     * @return    The frameBorder value
        */
       public String getFrameBorder()
       {
  @@ -305,19 +430,84 @@
        *  Gets the message displayed when IFRAME is not supported
        *  This includes when Frames are turned off.
        *
  -     *@todo        This should be localized
  -     *@return    The notSupportedMsg value
  +     * @todo        This should be localized
  +     * @return    The notSupportedMsg value
        */
       public String getNotSupportedMsg()
       {
           return DEFAULT_NOTSUPP_MSG;
       }
   
  +    /**
  +     *  Gets the aling attribute of the IFramePortlet object
  +     * 
  +     * @return The marginheight value
  +     */
  +    public String getAlign() 
  +    {
  +
  +        return iAlign;
  +    }
  +
  +    /**
  +     *  Gets iframe style
  +     * 
  +     * @return The style value
  +     */
  +    public String getStyle() 
  +    {
  +
  +        return iStyle;
  +    }
  +
  +    /**
  +     *  Gets iframe name
  +     * 
  +     * @return The name value
  +     */
  +    public String getFrameName() 
  +    {
  +
  +        return iName;
  +    }
  +
  +    /**
  +     *  Gets iframe refresh
  +     * 
  +     * @return The refresh value
  +     */
  +    public String getRefresh() 
  +    {
  +
  +        return iRefresh;
  +    }
  +
  +    /**
  +     *  Gets the marginheight attribute of the IFramePortlet object
  +     * 
  +     * @return The marginheight value
  +     */
  +    public String getMarginHeight() 
  +    {
  +
  +        return iMarginHeight;
  +    }
  +
  +    /**
  +     *  Gets the marginwidth attribute of the IFramePortlet object
  +     * 
  +     * @return The marginwidth value
  +     */
  +    public String getMarginWidth() 
  +    {
  +
  +        return iMarginWidth;
  +    }
   
       /**
        *  Initialize this portlet by setting inst. vars from InitParamaters.
        *
  -     *@throws  PortletException  Initialization failed
  +     * @throws  PortletException  Initialization failed
        */
       public void init() throws PortletException
       {
  @@ -358,6 +548,43 @@
               {
                   setFrameBorder(param);
               }
  +
  +            param = config.getInitParameter(PARAM_STYLE);
  +            if (param != null) 
  +            {
  +                setStyle(param);
  +            }
  +
  +            param = config.getInitParameter(PARAM_NAME);
  +            if (param != null) 
  +            {
  +                setFrameName(param);
  +            }
  +
  +            param = config.getInitParameter(PARAM_REFRESH);
  +            if (param != null) 
  +            {
  +                setRefresh(param);
  +            }
  +
  +            param = config.getInitParameter(PARAM_MARGINWIDTH);
  +            if (param != null) 
  +            {
  +                setMarginWidth(param);
  +            }
  +
  +            param = config.getInitParameter(PARAM_MARGINHEIGHT);
  +            if (param != null) 
  +            {
  +                setMarginHeight(param);
  +            }
  +
  +            param = config.getInitParameter(PARAM_ALIGN);
  +            if (param != null) 
  +            {
  +                setAlign(param);
  +            }
  +
           }
           catch (Exception e)
           {
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>