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&up_mylang=en&synd=open&w=320&h=46&title=Wikipedia&lang=en&country=ALL&border=%23ffffff%7C3px%2C1px+solid+%23999999&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);
}
}