portals-portalapps-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r832770 - /portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/webwidget/WebWidgetIFramePortlet.java
Date Wed, 04 Nov 2009 15:40:57 GMT
Author: woonsan
Date: Wed Nov  4 15:40:57 2009
New Revision: 832770

URL: http://svn.apache.org/viewvc?rev=832770&view=rev
Log:
APA-21: Allowing normal iframe src

Modified:
    portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/webwidget/WebWidgetIFramePortlet.java

Modified: portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/webwidget/WebWidgetIFramePortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/webwidget/WebWidgetIFramePortlet.java?rev=832770&r1=832769&r2=832770&view=diff
==============================================================================
--- portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/webwidget/WebWidgetIFramePortlet.java
(original)
+++ portals/applications/gems/trunk/src/main/java/org/apache/portals/gems/webwidget/WebWidgetIFramePortlet.java
Wed Nov  4 15:40:57 2009
@@ -45,7 +45,7 @@
 public class WebWidgetIFramePortlet extends GenericVelocityPortlet
 {
     
-    private static final String DEFAULT_WEB_WIDGET_CODE = 
+    private static final String DEFAULT_WEB_WIDGET_SOURCE = 
         "<script src=\"http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/wikipedia.xml&amp;up_mylang=en&amp;synd=open&amp;w=320&amp;h=46&amp;title=Wikipedia&amp;lang=en&amp;country=ALL&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js\"></script>";
     
     private Map<String, String> attributes = new HashMap<String, String>();
@@ -71,7 +71,7 @@
         attributes.put("SCROLLING", "NO");
         attributes.put("STYLE", "");
 
-        attributes.put("WIDGETCODE", DEFAULT_WEB_WIDGET_CODE);
+        attributes.put("WIDGETSOURCE", DEFAULT_WEB_WIDGET_SOURCE);
         
         maxAttributes.put("HEIGHT", "800");
         maxAttributes.put("WIDTH", "100%");
@@ -188,7 +188,6 @@
     protected void doIFrame(RenderRequest request, RenderResponse response) throws IOException
     {
         PortletPreferences prefs = request.getPreferences();
-        String source = response.createResourceURL().toString();
         // generate HTML IFRAME content
         StringBuilder content = new StringBuilder(256);
         
@@ -196,8 +195,22 @@
         content.append("<TABLE CLASS='iframePortletTableContainer' WIDTH='100%'><TBODY
CLASS='iframePortletTbodyContainer'><TR><TD>");
 
         content.append("<IFRAME");
-
-        // special case source
+        
+        // IFrame source can be a portlet resource url or a simple direct url.
+        // In the former case, the serveResource() method will write the widget source.
+        // (the resource url is invoked from the generated IFrame.)
+        // In the latter case, the direct url will serve the widget directly.
+        String source = response.createResourceURL().toString();
+        String widgetSource = getAttributePreference(request.getPreferences(), "WIDGETSOURCE");
+        if (!StringUtils.isBlank(widgetSource))
+        {
+            String trimmedWidgetSource = widgetSource.trim();
+            if (!StringUtils.startsWithIgnoreCase(trimmedWidgetSource, "<script ") &&
!StringUtils.startsWithIgnoreCase(trimmedWidgetSource, "<iframe "))
+            {
+                source = trimmedWidgetSource;
+            }
+        }
+        
         content.append(" ").append("SRC").append("=\"").append(source).append("\"");
 
         appendAttribute(prefs, content, "ALIGN");
@@ -264,12 +277,12 @@
     @Override
     public void serveResource(ResourceRequest request, ResourceResponse response) throws
PortletException, IOException 
     {
-        String widgetCode = getAttributePreference(request.getPreferences(), "WIDGETCODE");
+        String widgetSource = getAttributePreference(request.getPreferences(), "WIDGETSOURCE");
         
-        if (!StringUtils.isBlank(widgetCode))
+        if (!StringUtils.isEmpty(widgetSource))
         {
             response.setContentType("text/html");
-            response.getWriter().print(widgetCode);
+            response.getWriter().print(widgetSource);
         }
     }
     



Mime
View raw message