Author: julien(a)jboss.com
Date: 2008-02-10 09:56:47 -0500 (Sun, 10 Feb 2008)
New Revision: 9920
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/HeaderPortlet.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/HeadersTag.java
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PortalRenderResponse.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortalSimpleTagSupport.java
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/portlet.xml
modules/portlet/trunk/test/src/test/resources/simple-portal-war/WEB-INF/portal.tld
modules/portlet/trunk/test/src/test/resources/simple-portal-war/demo/demo3.jsp
modules/portlet/trunk/test/src/test/resources/simple-portal-war/layouts/header.jsp
Log:
start to add support for headers, need to work on resource with a content type different
from text/html
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/HeaderPortlet.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/HeaderPortlet.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/HeaderPortlet.java 2008-02-10
14:56:47 UTC (rev 9920)
@@ -0,0 +1,63 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.portal.samples.basic;
+
+import org.w3c.dom.Element;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import javax.portlet.ResourceURL;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class HeaderPortlet extends GenericPortlet
+{
+ public void render(RenderRequest req, RenderResponse resp) throws PortletException,
IOException
+ {
+ ResourceURL resourceURL = resp.createResourceURL();
+
+ //
+ Element elt = resp.createElement("script");
+ elt.setAttribute("type", "text/javascript");
+ elt.setAttribute("src", resourceURL.toString());
+ elt.appendChild(elt.getOwnerDocument().createTextNode(""));
+ resp.addProperty("script", elt);
+ }
+
+ public void serveResource(ResourceRequest req, ResourceResponse resp) throws
PortletException, IOException
+ {
+// String namespace =resp.getNamespace();
+ resp.setContentType("text/javascript");
+ PrintWriter writer = resp.getWriter();
+ writer.print("alert('shouldwork');");
+ writer.close();
+ }
+}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PortalRenderResponse.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PortalRenderResponse.java 2008-02-10
13:49:29 UTC (rev 9919)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/PortalRenderResponse.java 2008-02-10
14:56:47 UTC (rev 9920)
@@ -110,6 +110,11 @@
return pageState;
}
+ public Set<String> getWindowIds()
+ {
+ return windowResults.keySet();
+ }
+
public WindowResult getWindowResult(String windowId)
{
return windowResults.get(windowId);
@@ -211,6 +216,15 @@
}
}
+ public boolean isMaximizedWindow(String windowId)
+ {
+ if (windowId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ return windowId.equals(getMaximizedWindowId());
+ }
+
public String getMaximizedWindowId()
{
if (pageState != null)
Added:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/HeadersTag.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/HeadersTag.java
(rev 0)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/HeadersTag.java 2008-02-10
14:56:47 UTC (rev 9920)
@@ -0,0 +1,105 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.test.jsp.taglib;
+
+import org.jboss.portal.portlet.test.jsp.PortalRenderResponse;
+import org.jboss.portal.portlet.test.jsp.WindowResult;
+import org.jboss.portal.portlet.test.jsp.PortalPrepareResponse;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.response.FragmentResponse;
+import org.jboss.portal.portlet.invocation.response.ResponseProperties;
+import org.jboss.portal.common.util.MultiValuedPropertyMap;
+import org.jboss.portal.common.xml.XMLTools;
+import org.w3c.dom.Element;
+
+import javax.servlet.jsp.JspException;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class HeadersTag extends PortalSimpleTagSupport
+{
+
+ public HeadersTag()
+ {
+ super(false);
+ }
+
+ public void doTag(PortalPrepareResponse prepareResponse) throws JspException,
IOException
+ {
+ }
+
+ public void doTag(PortalRenderResponse renderResponse) throws JspException,
IOException
+ {
+ String maxmizedWindowId = renderResponse.getMaximizedWindowId();
+
+ //
+ for (String windowId : renderResponse.getWindowIds())
+ {
+ if (maxmizedWindowId == null || maxmizedWindowId.equals(windowId))
+ {
+ WindowResult result = renderResponse.getWindowResult(windowId);
+
+ //
+ if (result != null)
+ {
+ PortletInvocationResponse response = result.getResponse();
+
+ //
+ if (response instanceof FragmentResponse)
+ {
+ FragmentResponse fragmentResponse = (FragmentResponse)response;
+
+ //
+ ResponseProperties properties = fragmentResponse.getProperties();
+
+ //
+ if (properties != null)
+ {
+ MultiValuedPropertyMap<Element> markupHeaders =
properties.getMarkupHeaders();
+ for (String key : markupHeaders.keySet())
+ {
+ List<Element> headElement = markupHeaders.getValues(key);
+ for (Element headerValue : headElement)
+ {
+ try
+ {
+ String serializedElement = XMLTools.toString(headerValue);
+ getJspContext().getOut().print(serializedElement);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortalSimpleTagSupport.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortalSimpleTagSupport.java 2008-02-10
13:49:29 UTC (rev 9919)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortalSimpleTagSupport.java 2008-02-10
14:56:47 UTC (rev 9920)
@@ -38,19 +38,49 @@
*/
public class PortalSimpleTagSupport extends SimpleTagSupport
{
+
+ private final boolean pageScoped;
+
+ public PortalSimpleTagSupport()
+ {
+ this(true);
+ }
+
+ public PortalSimpleTagSupport(boolean pageScoped)
+ {
+ this.pageScoped = pageScoped;
+ }
+
+ public boolean isPageScoped()
+ {
+ return pageScoped;
+ }
+
private PortalResponse getPortalResponse()
{
PageContext pageContext = (PageContext)getJspContext();
return (PortalResponse)pageContext.getResponse();
}
- public final void doTag() throws JspException, IOException
+ protected final boolean isActive()
{
- PageTag pageTag = (PageTag)findAncestorWithClass(this, PageTag.class);
+ if (pageScoped)
+ {
+ PageTag pageTag = (PageTag)findAncestorWithClass(this, PageTag.class);
- //
- if (pageTag != null && pageTag.status == PageTag.Status.ACTIVE)
+ //
+ return pageTag != null && pageTag.status == PageTag.Status.ACTIVE;
+ }
+ else
{
+ return false;
+ }
+ }
+
+ public final void doTag() throws JspException, IOException
+ {
+ if (isActive())
+ {
PortalResponse portalResponse = getPortalResponse();
//
Modified:
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/portlet.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/portlet.xml 2008-02-10
13:49:29 UTC (rev 9919)
+++
modules/portlet/trunk/test/src/test/resources/portal/samples/basic-war/WEB-INF/portlet.xml 2008-02-10
14:56:47 UTC (rev 9920)
@@ -38,4 +38,16 @@
</portlet-info>
</portlet>
+ <portlet>
+ <portlet-name>HeaderPortlet</portlet-name>
+
<portlet-class>org.jboss.portal.portlet.portal.samples.basic.HeaderPortlet</portlet-class>
+ <supports>
+ <mime-type>text/html</mime-type>
+ <mime-type>text/javascript</mime-type>
+ </supports>
+ <portlet-info>
+ <title>HeaderPortlet</title>
+ </portlet-info>
+ </portlet>
+
</portlet-app>
Modified:
modules/portlet/trunk/test/src/test/resources/simple-portal-war/WEB-INF/portal.tld
===================================================================
---
modules/portlet/trunk/test/src/test/resources/simple-portal-war/WEB-INF/portal.tld 2008-02-10
13:49:29 UTC (rev 9919)
+++
modules/portlet/trunk/test/src/test/resources/simple-portal-war/WEB-INF/portal.tld 2008-02-10
14:56:47 UTC (rev 9920)
@@ -127,4 +127,10 @@
</attribute>
</tag>
+ <tag>
+ <name>headers</name>
+
<tag-class>org.jboss.portal.portlet.test.jsp.taglib.HeadersTag</tag-class>
+ <body-content>empty</body-content>
+ </tag>
+
</taglib>
Modified: modules/portlet/trunk/test/src/test/resources/simple-portal-war/demo/demo3.jsp
===================================================================
---
modules/portlet/trunk/test/src/test/resources/simple-portal-war/demo/demo3.jsp 2008-02-10
13:49:29 UTC (rev 9919)
+++
modules/portlet/trunk/test/src/test/resources/simple-portal-war/demo/demo3.jsp 2008-02-10
14:56:47 UTC (rev 9920)
@@ -17,6 +17,7 @@
</jsp:attribute>
<jsp:attribute name="rightcol">
<jbp:portlet name="ExceptionPortlet"
applicationName="samples-basic"/>
+ <jbp:portlet name="HeaderPortlet"
applicationName="samples-basic"/>
</jsp:attribute>
</jbp:layout1>
</portal:page>
Modified:
modules/portlet/trunk/test/src/test/resources/simple-portal-war/layouts/header.jsp
===================================================================
---
modules/portlet/trunk/test/src/test/resources/simple-portal-war/layouts/header.jsp 2008-02-10
13:49:29 UTC (rev 9919)
+++
modules/portlet/trunk/test/src/test/resources/simple-portal-war/layouts/header.jsp 2008-02-10
14:56:47 UTC (rev 9920)
@@ -1,3 +1,4 @@
+<%@ taglib uri="/WEB-INF/portal.tld" prefix="portal" %>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
@@ -6,6 +7,7 @@
<head>
<title>Portlet Container 2.0</title>
<link rel="stylesheet"
href="${pageContext.request.contextPath}/css/master.css"
type="text/css"/>
+<portal:headers/>
</head>
<body>