Author: julien(a)jboss.com
Date: 2008-02-10 12:51:37 -0500 (Sun, 10 Feb 2008)
New Revision: 9922
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/spi/PortletInvocationContext.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/api/portletcontext/ServerInfoTestCase.java
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/controller/AbstractPortletControllerContext.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortalSimpleTagSupport.java
Log:
- make javascript serveable from a resource
- fix a bug in the portal side that was not sending the correct window id during the
different life cycle phase and so the getNamespace() value was not correct in
render/resource
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java 2008-02-10
15:10:14 UTC (rev 9921)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java 2008-02-10
17:51:37 UTC (rev 9922)
@@ -28,9 +28,12 @@
import org.jboss.portal.portlet.invocation.response.RevalidateMarkupResponse;
import org.jboss.portal.portlet.info.PortletInfo;
import org.jboss.portal.portlet.info.CacheInfo;
+import org.jboss.portal.portlet.info.CapabilitiesInfo;
+import org.jboss.portal.portlet.info.ModeInfo;
import org.jboss.portal.portlet.cache.CacheScope;
import org.jboss.portal.common.util.MediaType;
import org.jboss.portal.common.util.ContentInfo;
+import org.jboss.portal.Mode;
import javax.portlet.MimeResponse;
import javax.portlet.PortletURL;
@@ -41,6 +44,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.util.Locale;
+import java.util.Set;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -119,17 +123,36 @@
MediaType requestedMediaType = MediaType.parseMimeType(contentType);
// Get the response media type
- ContentInfo info = invocation.getContext().getMarkupInfo();
- MediaType responseMediaType = info.getContentType();
+// ContentInfo info = invocation.getContext().getMarkupInfo();
+// MediaType responseMediaType = info.getContentType();
// Check if the requested media type is allowed as a subtype of the main
response
- if (!responseMediaType.isAllowedSubType(requestedMediaType))
+// if (!responseMediaType.isAllowedSubType(requestedMediaType))
+// {
+// throw new IllegalArgumentException("Content type not accepted");
+// }
+
+ //
+ Mode currentMode = preq.invocation.getMode();
+
+ PortletInfo info = preq.container.getInfo();
+ CapabilitiesInfo capabilities = info.getCapabilities();
+ Set<ModeInfo> compatibleModes = capabilities.getModes(contentType);
+ for (ModeInfo modeInfo : compatibleModes)
{
- throw new IllegalArgumentException("Content type not accepted");
+ if (currentMode.equals(modeInfo.getMode()))
+ {
+ // Set the content type
+ fragment.setContentType(contentType);
+
+ //
+ return;
+ }
}
- // Set the content type
- fragment.setContentType(contentType);
+ //
+ throw new IllegalArgumentException("Mime type " + contentType + "
not accepted as content type");
+
}
catch (MimeTypeParseException e)
{
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/spi/PortletInvocationContext.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/spi/PortletInvocationContext.java 2008-02-10
15:10:14 UTC (rev 9921)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/spi/PortletInvocationContext.java 2008-02-10
17:51:37 UTC (rev 9922)
@@ -40,6 +40,8 @@
{
/**
+ * todo : move me to client content // see if it is still needed with CC/PP
+ *
* Return information about the underlying http wire this invocation is performed.
*
* @return the stream info
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/api/portletcontext/ServerInfoTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/api/portletcontext/ServerInfoTestCase.java 2008-02-10
15:10:14 UTC (rev 9921)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr168/api/portletcontext/ServerInfoTestCase.java 2008-02-10
17:51:37 UTC (rev 9922)
@@ -46,7 +46,7 @@
{
/** . */
- private static final String VERSION_REGEX = "JBossPortal/[0-9]+\\.[0-9]+";
+ private static final String VERSION_REGEX =
"JBossPortletContainer/[0-9]+\\.[0-9]+";
/** . */
private static final Pattern VERSION_PATTERN = Pattern.compile(VERSION_REGEX,
Pattern.CASE_INSENSITIVE);
Modified:
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 2008-02-10
15:10:14 UTC (rev 9921)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/portal/samples/basic/HeaderPortlet.java 2008-02-10
17:51:37 UTC (rev 9922)
@@ -50,14 +50,19 @@
elt.setAttribute("src", resourceURL.toString());
elt.appendChild(elt.getOwnerDocument().createTextNode(""));
resp.addProperty("script", elt);
+
+ //
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ writer.print("<a href='javascript:" + resp.getNamespace() +
"_handle()'>Click me to trigger script</a>");
}
public void serveResource(ResourceRequest req, ResourceResponse resp) throws
PortletException, IOException
{
-// String namespace =resp.getNamespace();
+ String namespace =resp.getNamespace();
resp.setContentType("text/javascript");
PrintWriter writer = resp.getWriter();
- writer.print("alert('shouldwork');");
+ writer.print("function " + namespace + "_handle() { alert('Some
alert'); }");
writer.close();
}
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java 2008-02-10
15:10:14 UTC (rev 9921)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java 2008-02-10
17:51:37 UTC (rev 9922)
@@ -318,7 +318,7 @@
actionInvocation.setServerContext(new AbstractServerContext(req, resp));
actionInvocation.setInstanceContext(instanceContext);
actionInvocation.setUserContext(new AbstractUserContext(req));
- actionInvocation.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
+ actionInvocation.setWindowContext(new AbstractWindowContext(windowId));
actionInvocation.setPortalContext(new TestPortalContext());
actionInvocation.setSecurityContext(new AbstractSecurityContext(req));
actionInvocation.setRequestContext(new AbstractRequestContext(req));
@@ -355,7 +355,7 @@
resourceInvocation.setServerContext(new AbstractServerContext(req, resp));
resourceInvocation.setInstanceContext(instanceContext);
resourceInvocation.setUserContext(new AbstractUserContext(req));
- resourceInvocation.setWindowContext(new
AbstractWindowContext(portlet.getContext().getId()));
+ resourceInvocation.setWindowContext(new AbstractWindowContext(windowId));
resourceInvocation.setPortalContext(new TestPortalContext());
resourceInvocation.setSecurityContext(new AbstractSecurityContext(req));
resourceInvocation.setRequestContext(new AbstractRequestContext(req));
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
15:10:14 UTC (rev 9921)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/PortalSimpleTagSupport.java 2008-02-10
17:51:37 UTC (rev 9922)
@@ -73,7 +73,7 @@
}
else
{
- return false;
+ return true;
}
}