Coverage report

  %line %branch
org.apache.jetspeed.portlet.IFrameGenericPortlet
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.portlet;
 18  
 
 19  
 import java.io.IOException;
 20  
 import java.util.HashMap;
 21  
 import java.util.Map;
 22  
 
 23  
 import javax.portlet.ActionRequest;
 24  
 import javax.portlet.ActionResponse;
 25  
 import javax.portlet.PortletConfig;
 26  
 import javax.portlet.PortletException;
 27  
 import javax.portlet.PortletPreferences;
 28  
 import javax.portlet.RenderRequest;
 29  
 import javax.portlet.RenderResponse;
 30  
 import javax.portlet.WindowState;
 31  
 
 32  
 import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
 33  
 
 34  
 /**
 35  
  * IFrameGenericPortlet
 36  
  * 
 37  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
 38  
  * @version $Id: IFrameGenericPortlet.java 578925 2007-09-24 19:22:58Z smilek $
 39  
  */
 40  0
 public class IFrameGenericPortlet extends GenericVelocityPortlet
 41  
 {
 42  
 
 43  0
     private Map attributes = new HashMap();
 44  
 
 45  0
     private Map maxAttributes = new HashMap();
 46  
 
 47  
     public void init(PortletConfig config) throws PortletException
 48  
     {
 49  0
         super.init(config);
 50  0
         attributes.put("SRC", "http://www.apache.org");
 51  0
         attributes.put("ALIGN", "BOTTOM");
 52  0
         attributes.put("CLASS", "");
 53  0
         attributes.put("FRAMEBORDER", "0");
 54  0
         attributes.put("ID", "");
 55  0
         attributes.put("MARGINHEIGHT", "0");
 56  0
         attributes.put("MARGINWIDTH", "0");
 57  0
         attributes.put("NAME", "");
 58  
 
 59  0
         attributes.put("HEIGHT", "");
 60  0
         attributes.put("WIDTH", "100%");
 61  0
         attributes.put("SCROLLING", "NO");
 62  0
         attributes.put("STYLE", "");
 63  
 
 64  0
         maxAttributes.put("HEIGHT", "800");
 65  0
         maxAttributes.put("WIDTH", "100%");
 66  0
         maxAttributes.put("SCROLLING", "AUTO");
 67  0
         maxAttributes.put("STYLE", "");
 68  0
     }
 69  
 
 70  
     private String getAttributePreference(PortletPreferences prefs, String attribute)
 71  
     {
 72  0
         return this.getMappedAttributePreference(prefs, attribute, attributes);
 73  
     }
 74  
 
 75  
     private String getMaxAttributePreference(PortletPreferences prefs, String attribute)
 76  
     {
 77  0
         return this.getMappedAttributePreference(prefs, "MAX-" + attribute, maxAttributes);
 78  
     }
 79  
 
 80  
     private String getMappedAttributePreference(PortletPreferences prefs, String attribute, Map map)
 81  
     {
 82  0
         return prefs.getValue(attribute, (String) map.get(attribute));
 83  
     }
 84  
 
 85  
     private void appendAttribute(PortletPreferences prefs, StringBuffer content, String attribute, Map map)
 86  
     {
 87  
         String value;
 88  
 
 89  0
         if (map == maxAttributes)
 90  0
             value = getMaxAttributePreference(prefs, attribute);
 91  
         else
 92  0
             value = getAttributePreference(prefs, attribute);
 93  
 
 94  0
         if (value == null || value.length() == 0) { return; }
 95  0
         content.append(" ").append(attribute).append("=\"").append(value).append("\"");
 96  0
     }
 97  
 
 98  
     private void appendAttribute(PortletPreferences prefs, StringBuffer content, String attribute)
 99  
     {
 100  0
         appendAttribute(prefs, content, attribute, attributes);
 101  0
     }
 102  
 
 103  
     private void appendMaxAttribute(PortletPreferences prefs, StringBuffer content, String attribute)
 104  
     {
 105  0
         appendAttribute(prefs, content, attribute, maxAttributes);
 106  0
     }
 107  
 
 108  
     public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
 109  
     {
 110  0
         String viewPage = (String)request.getAttribute(PARAM_VIEW_PAGE);
 111  0
         if (viewPage != null)
 112  
         {
 113  0
             super.doView(request, response);
 114  
         }
 115  
         else
 116  
         {
 117  0
             doIFrame(request, response);
 118  
         }
 119  0
     }
 120  
 
 121  
     public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException
 122  
     {
 123  0
         response.setContentType("text/html");
 124  0
         doPreferencesEdit(request, response);
 125  0
     }
 126  
 
 127  
     /**
 128  
      * Render IFRAME content
 129  
      */
 130  
     protected void doIFrame(RenderRequest request, RenderResponse response) throws IOException
 131  
     {
 132  0
         PortletPreferences prefs = request.getPreferences();
 133  0
         String source = getURLSource(request, response, prefs);
 134  
         // generate HTML IFRAME content
 135  0
         StringBuffer content = new StringBuffer(4096);
 136  
 
 137  
         // fix JS2-349
 138  0
         content.append("<TABLE CLASS='iframePortletTableContainer' WIDTH='100%'><TBODY CLASS='iframePortletTbodyContainer'><TR><TD>");
 139  
 
 140  0
         content.append("<IFRAME");
 141  
 
 142  
         // special case source
 143  0
         content.append(" ").append("SRC").append("=\"").append(source).append("\"");
 144  
 
 145  0
         appendAttribute(prefs, content, "ALIGN");
 146  0
         appendAttribute(prefs, content, "CLASS");
 147  0
         appendAttribute(prefs, content, "FRAMEBORDER");
 148  0
         appendAttribute(prefs, content, "ID");
 149  0
         appendAttribute(prefs, content, "MARGINHEIGHT");
 150  0
         appendAttribute(prefs, content, "MARGINWIDTH");
 151  0
         appendAttribute(prefs, content, "NAME");
 152  0
         if (request.getWindowState().equals(WindowState.MAXIMIZED))
 153  
         {
 154  0
             appendMaxAttribute(prefs, content, "HEIGHT");
 155  0
             appendMaxAttribute(prefs, content, "WIDTH");
 156  0
             appendMaxAttribute(prefs, content, "SCROLLING");
 157  0
             appendMaxAttribute(prefs, content, "STYLE");
 158  
         }
 159  
         else
 160  
         {
 161  0
             appendAttribute(prefs, content, "HEIGHT");
 162  0
             appendAttribute(prefs, content, "WIDTH");
 163  0
             appendAttribute(prefs, content, "SCROLLING");
 164  0
             appendAttribute(prefs, content, "STYLE");
 165  
         }
 166  0
         content.append(">");
 167  0
         content.append("<P STYLE=\"textAlign:center\"><A HREF=\"").append(source).append("\">").append(source).append(
 168  
                 "</A></P>");
 169  0
         content.append("</IFRAME>");
 170  
 
 171  
         // end fix JS2-349
 172  0
         content.append("</TD></TR></TBODY></TABLE>");
 173  
 
 174  
         // set required content type and write HTML IFRAME content
 175  0
         response.setContentType("text/html");
 176  0
         response.getWriter().print(content.toString());
 177  0
     }
 178  
 
 179  
     public String getURLSource(RenderRequest request, RenderResponse response, PortletPreferences prefs)
 180  
     {
 181  0
         String source = getAttributePreference(prefs, "SRC");
 182  0
         if (source == null) source = "";
 183  0
         return source;
 184  
     }
 185  
 
 186  
     /**
 187  
      * Save the prefs
 188  
      */
 189  
     public void processAction(ActionRequest request, ActionResponse actionResponse) throws PortletException,
 190  
             IOException
 191  
     {
 192  0
         processPreferencesAction(request, actionResponse);
 193  0
     }
 194  
 
 195  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.