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 ta...@apache.org on 2002/02/25 06:35:39 UTC

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

taylor      02/02/24 21:35:39

  Added:       src/java/org/apache/jetspeed/portal/portlets
                        IFramePortlet.java
  Log:
  - IFramePortlet donated by Bill Barnhill
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/IFramePortlet.java
  
  Index: IFramePortlet.java
  ===================================================================
  /*
   *  ====================================================================
   *  The Apache Software License, Version 1.1
   *
   *  Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   *  reserved.
   *
   *  Redistribution and use in source and binary forms, with or without
   *  modification, are permitted provided that the following conditions
   *  are met:
   *
   *  1. Redistributions of source code must retain the above copyright
   *  notice, this list of conditions and the following disclaimer.
   *
   *  2. Redistributions in binary form must reproduce the above copyright
   *  notice, this list of conditions and the following disclaimer in
   *  the documentation and/or other materials provided with the
   *  distribution.
   *
   *  3. The end-user documentation included with the redistribution,
   *  if any, must include the following acknowledgment:
   *  "This product includes software developed by the
   *  Apache Software Foundation (http://www.apache.org/)."
   *  Alternately, this acknowledgment may appear in the software itself,
   *  if and wherever such third-party acknowledgments normally appear.
   *
   *  4. The names "Apache" and "Apache Software Foundation" and
   *  "Apache Jetspeed" must not be used to endorse or promote products
   *  derived from this software without prior written permission. For
   *  written permission, please contact apache@apache.org.
   *
   *  5. Products derived from this software may not be called "Apache" or
   *  "Apache Jetspeed", nor may "Apache" appear in their name, without
   *  prior written permission of the Apache Software Foundation.
   *
   *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   *  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   *  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   *  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   *  SUCH DAMAGE.
   *  ====================================================================
   *
   *  This software consists of voluntary contributions made by many
   *  individuals on behalf of the Apache Software Foundation.  For more
   *  information on the Apache Software Foundation, please see
   *  <http://www.apache.org/>.
   */
  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.*;
  
  //turbine
  import org.apache.turbine.util.*;
  
  //standard java stuff
  import java.net.*;
  import java.io.*;
  
  //ecs stuff
  import org.apache.ecs.*;
  import org.apache.ecs.html.*;
  
  /**
   *  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
   */
  
  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;
  
  
      /**
       *  Sets the source attribute of the IFramePortlet object
       *
       *@param  source  The new source value
       *@since
       */
      public void setSource(String source)
      {
          iSource = source;
      }
  
  
      /**
       *  Sets the scrolling attribute of the IFramePortlet object
       *
       *@param  scrolling  The new scrolling value
       *@since
       */
      public void setScrolling(String scrolling)
      {
          iScrolling = scrolling;
      }
  
  
      /**
       *  Sets the width attribute of the IFramePortlet object
       *
       *@param  width  The new width value
       *@since
       */
      public void setWidth(String width)
      {
          iWidth = width;
      }
  
  
      /**
       *  Sets the height attribute of the IFramePortlet object
       *
       *@param  height  The new height value
       *@since
       */
      public void setHeight(String height)
      {
          iHeight = height;
      }
  
  
      /**
       *  Sets the frameBorder attribute of the IFramePortlet object
       *
       *@param  frameBorder  The new frameBorder value
       *@since
       */
      public void setFrameBorder(String frameBorder)
      {
          iFrameBorder = frameBorder;
      }
  
  
      /**
       *  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
       */
      public ConcreteElement getContent(RunData runData)
      {
          StringBuffer text = new StringBuffer();
          String href = getPortletConfig().getInitParameter("url");
  
          text.append("<IFRAME ");
  
          text.append("src = \"" + getSource() + "\" ");
          if (getWidth() != null)
          {
              text.append("width = \"" + getWidth() + "\" ");
          }
          if (getHeight() != null)
          {
              text.append("height = \"" + getHeight() + "\" ");
          }
          text.append("scrolling = \"" + getScrolling() + "\" ");
          text.append("frameborder = \"" + getFrameBorder() + "\" ");
          text.append(">");
  
          text.append("</IFRAME>");
          return (new StringElement(text.toString()));
      }
  
  
      /**
       *  Gets the source attribute of the IFramePortlet object
       *
       *@return    The source value
       */
      public String getSource()
      {
          return iSource;
      }
  
  
      /**
       *  Gets the scrolling attribute of the IFramePortlet object
       *
       *@return    The scrolling value
       */
      public String getScrolling()
      {
          return iScrolling;
      }
  
  
      /**
       *  Gets the width attribute of the IFramePortlet object
       *
       *@return    The width value
       */
      public String getWidth()
      {
          return iWidth;
      }
  
  
      /**
       *  Gets the height attribute of the IFramePortlet object
       *
       *@return    The height value
       */
      public String getHeight()
      {
          return iHeight;
      }
  
  
      /**
       *  Gets whether to display a border around the IFRAME. "1" == yes.
       *
       *@return    The frameBorder value
       */
      public String getFrameBorder()
      {
          return iFrameBorder;
      }
  
  
      /**
       *  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
       */
      public String getNotSupportedMsg()
      {
          return DEFAULT_NOTSUPP_MSG;
      }
  
  
      /**
       *  Initialize this portlet by setting inst. vars from InitParamaters.
       *
       *@throws  PortletException  Initialization failed
       */
      public void init() throws PortletException
      {
          // first make sure we propagate init
          super.init();
  
          try
          {
              PortletConfig config = this.getPortletConfig();
              String param = null;
  
              param = config.getInitParameter(PARAM_SOURCE);
              if (param != null)
              {
                  setSource(param);
              }
  
              param = config.getInitParameter(PARAM_WIDTH);
              if (param != null)
              {
                  setWidth(param);
              }
  
              param = config.getInitParameter(PARAM_HEIGHT);
              if (param != null)
              {
                  setHeight(param);
              }
  
              param = config.getInitParameter(PARAM_SCROLLING);
              if (param != null)
              {
                  setScrolling(param);
              }
  
              param = config.getInitParameter(PARAM_FRAMEBORDER);
              if (param != null)
              {
                  setFrameBorder(param);
              }
          }
          catch (Exception e)
          {
              throw new PortletException(e.getMessage());
          }
      }
  }
  
  
  
  
  

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