Author: mwringe
Date: 2009-12-14 17:48:47 -0500 (Mon, 14 Dec 2009)
New Revision: 1012
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/RequestContext.java
portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/workspace/UIPortalApplication.gtmpl
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletRequestContext.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
Log:
Add portlet support for html markup headers (GTNPORTAL-321).
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/RequestContext.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/RequestContext.java 2009-12-14
22:48:01 UTC (rev 1011)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/RequestContext.java 2009-12-14
22:48:47 UTC (rev 1012)
@@ -119,6 +119,11 @@
{
return parentAppRequestContext_.getWriter();
}
+
+ public void setWriter (Writer writer)
+ {
+ parentAppRequestContext_.setWriter(writer);
+ }
final public Object getAttribute(String name)
{
Modified:
portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/workspace/UIPortalApplication.gtmpl
===================================================================
---
portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/workspace/UIPortalApplication.gtmpl 2009-12-14
22:48:01 UTC (rev 1011)
+++
portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/workspace/UIPortalApplication.gtmpl 2009-12-14
22:48:47 UTC (rev 1012)
@@ -18,10 +18,10 @@
def title = rcontext.getTitle();
def metaInformation = rcontext.getMetaInformation();
%>
-
+<% uicomponent.processChildren();%>
<html
xmlns="http://www.w3.org/1999/xhtml" xml:lang="$lang"
lang="$lang" dir="$dir">
<head id="head">
- <title><%=title%></title>
+ <title><%=rcontext.getTitle()%></title>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8"/>
<%
if(metaInformation!= null) {
@@ -87,6 +87,17 @@
</script>
<script type="text/javascript"
src="/eXoResources/javascript/eXo/i18n/I18NMessage.js"></script>
<script type="text/javascript"
src="/eXoResources/javascript/eXo/i18n/MessageResource_<%=lang%>.js"></script>
+
+ <%
+ def headerElements = rcontext.getExtraMarkupHeaders();
+ if (headerElements != null)
+ {
+ for (element in headerElements)
+ { %>
+ <%=element%>
+ <% }
+ }
+ %>
</head>
<body style="height: 100%;">
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletRequestContext.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletRequestContext.java 2009-12-14
22:48:01 UTC (rev 1011)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/portlet/PortletRequestContext.java 2009-12-14
22:48:47 UTC (rev 1012)
@@ -151,6 +151,11 @@
{
return writer_;
}
+
+ public void setWriter(Writer writer)
+ {
+ this.writer_ = writer;
+ }
final public boolean useAjax()
{
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2009-12-14
22:48:01 UTC (rev 1011)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2009-12-14
22:48:47 UTC (rev 1012)
@@ -37,6 +37,7 @@
import org.exoplatform.webui.application.WebuiApplication;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.core.lifecycle.HtmlValidator;
+import org.w3c.dom.Element;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -44,8 +45,10 @@
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.URLDecoder;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -97,6 +100,8 @@
private Writer writer_;
protected JavascriptManager jsmanager_ = new JavascriptManager();
+
+ private List<Element> extraMarkupHeaders;
public JavascriptManager getJavascriptManager()
{
@@ -293,6 +298,11 @@
}
return writer_;
}
+
+ final public void setWriter(Writer writer)
+ {
+ this.writer_ = writer;
+ }
final public boolean useAjax()
{
@@ -336,5 +346,28 @@
response_.setHeader(key, headers.get(key));
}
}
+
+ /**
+ * Get the extra markup headers to add to the head of the html.
+ * @return The markup to be added.
+ */
+ public List<Element> getExtraMarkupHeaders()
+ {
+ return this.extraMarkupHeaders;
+ }
+
+ /**
+ * Add an extra markup to the head of the html page.
+ * @param element The element to add
+ */
+ public void addExtraMarkupHeader(Element element)
+ {
+ if (this.extraMarkupHeaders == null)
+ {
+ this.extraMarkupHeaders = new ArrayList<Element>();
+ }
+ this.extraMarkupHeaders.add(element);
+ }
+
}
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java 2009-12-14
22:48:01 UTC (rev 1011)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortletLifecycle.java 2009-12-14
22:48:47 UTC (rev 1012)
@@ -40,12 +40,13 @@
import org.gatein.pc.api.invocation.response.ErrorResponse;
import org.gatein.pc.api.invocation.response.FragmentResponse;
import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.w3c.dom.Element;
import java.io.Serializable;
import java.nio.charset.Charset;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.List;
+import javax.portlet.MimeResponse;
import javax.portlet.PortletMode;
import javax.portlet.WindowState;
@@ -176,37 +177,63 @@
PortletInvocationResponse response =
uicomponent.invoke(renderInvocation);
if (response instanceof FragmentResponse)
{
- FragmentResponse fragmentResponse = (FragmentResponse)response;
- switch (fragmentResponse.getType())
- {
- case FragmentResponse.TYPE_CHARS:
- markup = Text.create(fragmentResponse.getContent());
- break;
- case FragmentResponse.TYPE_BYTES:
- markup = Text.create(fragmentResponse.getBytes(),
Charset.forName("UTF-8"));
- break;
- case FragmentResponse.TYPE_EMPTY:
- markup = Text.create("");
- break;
- }
- portletTitle = fragmentResponse.getTitle();
- if (fragmentResponse.getProperties() != null
- && fragmentResponse.getProperties().getTransportHeaders()
!= null)
- {
- MultiValuedPropertyMap<String> transportHeaders =
- fragmentResponse.getProperties().getTransportHeaders();
- Map<String, String> headers = new HashMap<String,
String>();
+ FragmentResponse fragmentResponse = (FragmentResponse)response;
+ switch (fragmentResponse.getType())
+ {
+ case FragmentResponse.TYPE_CHARS:
+ markup = Text.create(fragmentResponse.getContent());
+ break;
+ case FragmentResponse.TYPE_BYTES:
+ markup = Text.create(fragmentResponse.getBytes(),
Charset.forName("UTF-8"));
+ break;
+ case FragmentResponse.TYPE_EMPTY:
+ markup = Text.create("");
+ break;
+ }
+ portletTitle = fragmentResponse.getTitle();
- for (String key : transportHeaders.keySet())
- {
- for (String value : transportHeaders.getValues(key))
- {
- headers.put(key, value);
- }
- }
- prcontext.setHeaders(headers);
- }
+ // setup portlet properties
+ if (fragmentResponse.getProperties() != null)
+ {
+ //setup transport headers
+ if (fragmentResponse.getProperties().getTransportHeaders() != null)
+ {
+ MultiValuedPropertyMap<String> transportHeaders =
+ fragmentResponse.getProperties().getTransportHeaders();
+ for (String key : transportHeaders.keySet())
+ {
+ for (String value : transportHeaders.getValues(key))
+ {
+ prcontext.getResponse().setHeader(key, value);
+ }
+ }
+ }
+ //setup markup headers
+ if (fragmentResponse.getProperties().getMarkupHeaders() != null)
+ {
+ MultiValuedPropertyMap<Element> markupHeaders =
+ fragmentResponse.getProperties().getMarkupHeaders();
+
+ List<Element> markupElements =
markupHeaders.getValues(MimeResponse.MARKUP_HEAD_ELEMENT);
+ if (markupElements != null)
+ {
+ for (Element element : markupElements)
+ {
+ if ("title".equals(element.getNodeName().toLowerCase())
&& element.getFirstChild() != null)
+ {
+ String title = element.getFirstChild().getTextContent();
+
prcontext.getRequest().setAttribute(PortalRequestContext.REQUEST_TITLE, title);
+ }
+ else
+ {
+ prcontext.addExtraMarkupHeader(element);
+ }
+ }
+ }
+ }
+ }
+
}
else
{
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2009-12-14
22:48:01 UTC (rev 1011)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2009-12-14
22:48:47 UTC (rev 1012)
@@ -39,6 +39,7 @@
import org.exoplatform.services.resources.LocaleConfig;
import org.exoplatform.services.resources.LocaleConfigService;
import org.exoplatform.services.resources.Orientation;
+import org.exoplatform.web.application.RequestContext;
import org.exoplatform.web.application.javascript.JavascriptConfigService;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.config.annotation.ComponentConfig;
@@ -48,6 +49,9 @@
import org.exoplatform.webui.core.UIContainer;
import org.exoplatform.webui.event.Event;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
@@ -99,6 +103,11 @@
private UserPortalConfig userPortalConfig_;
private boolean isSessionOpen = false;
+
+ /**
+ * Stores the child html markup
+ */
+ private String childMarkup;
/**
* The constructor of this class is used to build the tree of UI components
@@ -400,7 +409,44 @@
super.processDecode(context);
}
+
+
/**
+ * Process the child elements storing the generated markup to be used
+ * when calling renderChildren().
+ * @throws Exception
+ */
+ public void processChildren() throws Exception
+ {
+ RequestContext context = RequestContext.getCurrentInstance();
+ Writer oldWriter = context.getWriter();
+
+ Writer writer = new CharArrayWriter();
+
+ context.setWriter(writer);
+ super.renderChildren();
+ context.setWriter(oldWriter);
+
+ childMarkup = writer.toString();
+ }
+
+ /**
+ * This method will not do any processing of the child elements. It will take
+ * the previously processed html markup for the children (see processChildren)
+ * and write this to the RequestContext writer.
+ */
+ public void renderChildren() throws Exception
+ {
+ if (childMarkup != null && !childMarkup.isEmpty())
+ {
+ RequestContext context = RequestContext.getCurrentInstance();
+ Writer writer = context.getWriter();
+
+ writer.write(childMarkup);
+ }
+ }
+
+ /**
* The processrender() method handles the creation of the returned HTML either
* for a full page render or in the case of an AJAX call The first request,
* Ajax is not enabled (means no ajaxRequest parameter in the request) and