Author: julien(a)jboss.com
Date: 2007-04-05 18:06:33 -0400 (Thu, 05 Apr 2007)
New Revision: 6932
Removed:
trunk/theme/src/main/org/jboss/portal/theme/ThemeResult.java
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPageCommand.java
trunk/theme/src/main/org/jboss/portal/theme/PortalTheme.java
trunk/theme/src/main/org/jboss/portal/theme/ThemeConstants.java
trunk/theme/src/main/org/jboss/portal/theme/impl/WARTheme.java
trunk/theme/src/main/org/jboss/portal/theme/page/PageRendition.java
trunk/theme/src/main/org/jboss/portal/theme/page/PageResult.java
trunk/theme/src/main/org/jboss/portal/theme/tag/ThemeTagHandler.java
Log:
simplify theme header rendering
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPageCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPageCommand.java 2007-04-05
21:12:38 UTC (rev 6931)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPageCommand.java 2007-04-05
22:06:33 UTC (rev 6932)
@@ -44,7 +44,6 @@
import org.jboss.portal.theme.PortalTheme;
import org.jboss.portal.theme.ServerRegistrationID;
import org.jboss.portal.theme.ThemeConstants;
-import org.jboss.portal.theme.ThemeResult;
import org.jboss.portal.theme.ThemeService;
import org.jboss.portal.theme.PageService;
import org.jboss.portal.theme.page.PageResult;
@@ -158,8 +157,11 @@
{
//
PageService pageService = context.getController().getPageService();
+
+ // The theme for the page
PortalTheme theme = null;
+ //
if (personalizable)
{
ControllerContext controllerCtx = (ControllerContext)getContext();
@@ -178,9 +180,7 @@
// Name is not bound anymore, it could happen during a shutdown, we
don't do anything
}
-
- //String themeId = user.getTheme();
-
+ //
String themeId = (String)userProfileModule.getProperty(user,
User.INFO_USER_THEME);
if (themeId != null)
@@ -198,12 +198,21 @@
}
// Call the portlet container to create the markup fragment(s) for each portlet
that needs to render itself
- PageResult pageResult = new PageResult(getPage().getName(), new
HashMap(getPage().getDeclaredProperties()), new
HashMap(getPage().getPortal().getDeclaredProperties()));
+ PageResult pageResult = new PageResult(
+ getPage().getName(),
+ new HashMap(getPage().getDeclaredProperties()),
+ new HashMap(getPage().getPortal().getDeclaredProperties()));
// Set the layout uri
pageResult.setLayoutURI(layout.getLayoutInfo().getURI());
- // Render
+ // Set the theme on the result
+ if (theme != null)
+ {
+ pageResult.setTheme(theme);
+ }
+
+ // Render the windows
for (Iterator i = windows.iterator(); i.hasNext();)
{
PortalObject o = (PortalObject)i.next();
@@ -250,17 +259,8 @@
}
}
- // Make the theme available as servlet request attribute (needed for CM)
- if (theme != null)
- {
- // Render the theme markup and place it into the request so that the markup
assembler (theme tag) can pick it up there
- ThemeResult themeResult = theme.assembleResponse(sinv.getRequest(),
sinv.getResponse());
- pageResult.setTheme(theme);
- pageResult.setThemeResult(themeResult);
-
- //
- return new PageRendition(layout, pageResult, pageService);
- }
+ //
+ return new PageRendition(layout, pageResult, pageService);
}
catch (Exception e)
{
@@ -268,9 +268,8 @@
}
finally
{
- request.removeAttribute(ThemeConstants.ATTR_THEMESERVER);
+ request.removeAttribute(ThemeConstants.ATTR_THEME_SERVER);
request.removeAttribute(ThemeConstants.ATTR_THEME);
- request.removeAttribute(ThemeConstants.ATTR_THEMERESULT);
}
//
Modified: trunk/theme/src/main/org/jboss/portal/theme/PortalTheme.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/PortalTheme.java 2007-04-05 21:12:38 UTC
(rev 6931)
+++ trunk/theme/src/main/org/jboss/portal/theme/PortalTheme.java 2007-04-05 22:06:33 UTC
(rev 6932)
@@ -22,12 +22,8 @@
******************************************************************************/
package org.jboss.portal.theme;
-import org.jboss.portal.server.ServerRequest;
-import org.jboss.portal.server.ServerResponse;
+import java.util.Collection;
-import java.io.IOException;
-import java.io.Writer;
-
/**
* A portal theme is a collection of tags that will be injected into a layout to govern
the look and feel of a portal
* page. <p>Themes are links to css, javascript and image/resource files. A
theme's css needs to cooperate with the
@@ -50,25 +46,9 @@
{
}
- /**
- * create the markup that this theme wants to inject into the page
- *
- * @param request the current server request
- * @param response the current server response
- * @return a ThemeResult containing the markup to inject into the page
- * @throws IOException
- */
- public abstract ThemeResult assembleResponse(ServerRequest request, ServerResponse
response) throws IOException;
+ public abstract Collection getElements();
/**
- * create the markup that this theme wants to inject into the page, and write it to
the provided writer
- *
- * @param writer the writer to write the theme markup to
- * @throws IOException
- */
- public abstract void assembleResponse(Writer writer) throws IOException;
-
- /**
* Initialize the theme with a reference to the theme service and the theme meta data
*
* @param serviceInfo a theme service reference
Modified: trunk/theme/src/main/org/jboss/portal/theme/ThemeConstants.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/ThemeConstants.java 2007-04-05 21:12:38
UTC (rev 6931)
+++ trunk/theme/src/main/org/jboss/portal/theme/ThemeConstants.java 2007-04-05 22:06:33
UTC (rev 6932)
@@ -38,11 +38,8 @@
public static final String ATTR_THEME = "THEME";
/** Request attribute to propagate the theme service */
- public static final String ATTR_THEMESERVER = "THEMESERVER";
+ public static final String ATTR_THEME_SERVER = "THEMESERVER";
- /** Request attribute to propagate the rendered markup of the theme */
- public static final String ATTR_THEMERESULT = "THEMERESULT";
-
// Portal property keys
/** Key name to access the selected layout for the portal or page (via the portal or
page properties) */
Deleted: trunk/theme/src/main/org/jboss/portal/theme/ThemeResult.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/ThemeResult.java 2007-04-05 21:12:38 UTC
(rev 6931)
+++ trunk/theme/src/main/org/jboss/portal/theme/ThemeResult.java 2007-04-05 22:06:33 UTC
(rev 6932)
@@ -1,56 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, 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.theme;
-
-/**
- * The resulting markup of a theme assembly. <p>A theme consists of zero or more
links and scripts that together form
- * the markup to be injected into the head of the page. This result object holds the
rendered markup of the theme that
- * can be written into the page.</p>
- *
- * @author <a href="mailto:mholzner@novell.com">Martin Holzner</a>
- * @version $Revision$
- */
-public final class ThemeResult
-{
- private final String themeName;
- private final StringBuffer markup;
-
- public ThemeResult(String themeName, StringBuffer markup)
- {
- this.themeName = themeName;
- this.markup = markup;
- }
-
- /** @return the theme markup to inject */
- public StringBuffer getMarkup()
- {
- return markup;
- }
-
- /** @return the name of the theme that produced the markup */
- public String getThemeName()
- {
- return themeName;
- }
-}
Modified: trunk/theme/src/main/org/jboss/portal/theme/impl/WARTheme.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/impl/WARTheme.java 2007-04-05 21:12:38 UTC
(rev 6931)
+++ trunk/theme/src/main/org/jboss/portal/theme/impl/WARTheme.java 2007-04-05 22:06:33 UTC
(rev 6932)
@@ -23,17 +23,9 @@
package org.jboss.portal.theme.impl;
-import org.jboss.portal.server.ServerRequest;
-import org.jboss.portal.server.ServerResponse;
import org.jboss.portal.theme.PortalTheme;
-import org.jboss.portal.theme.ThemeElement;
-import org.jboss.portal.theme.ThemeResult;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.Iterator;
-import java.util.List;
+import java.util.Collection;
/**
* A theme implementation that gets its resources from a war file.
@@ -43,33 +35,8 @@
*/
public final class WARTheme extends PortalTheme
{
- /** @ see PortalTheme#assembleResponse(ServerRequest, ServerResponse) */
- public ThemeResult assembleResponse(ServerRequest request, ServerResponse response)
+ public Collection getElements()
{
- StringWriter out = new StringWriter();
- PrintWriter writer = new PrintWriter(out);
- List themeElements = getThemeInfo().getElements();
- for (Iterator i = themeElements.iterator(); i.hasNext();)
- {
- ThemeElement el = (ThemeElement)i.next();
- writer.println(el.getElement());
- }
- writer.flush();
- StringBuffer markup = out.getBuffer();
- return new ThemeResult(getThemeInfo().getName(), markup);
+ return getThemeInfo().getElements();
}
-
- /** @ see PortalTheme#assembleResponse(Writer) */
- public void assembleResponse(Writer writer)
- {
- PrintWriter buffer = new PrintWriter(writer);
-
- List themeElements = getThemeInfo().getElements();
- for (Iterator i = themeElements.iterator(); i.hasNext();)
- {
- ThemeElement el = (ThemeElement)i.next();
- buffer.println(el.getElement());
- }
- buffer.flush();
- }
}
Modified: trunk/theme/src/main/org/jboss/portal/theme/page/PageRendition.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/page/PageRendition.java 2007-04-05
21:12:38 UTC (rev 6931)
+++ trunk/theme/src/main/org/jboss/portal/theme/page/PageRendition.java 2007-04-05
22:06:33 UTC (rev 6932)
@@ -70,9 +70,8 @@
{
// Place a reference to the theme service into the request so that the theme tag
can get to a theme via a theme
// name (specified as tag attribute); this is useful if no theme was defined for
the portal or the page
- renderContext.setAttribute(ThemeConstants.ATTR_THEMESERVER,
pageService.getThemeService());
+ renderContext.setAttribute(ThemeConstants.ATTR_THEME_SERVER,
pageService.getThemeService());
renderContext.setAttribute(ThemeConstants.ATTR_THEME, pageResult.getTheme());
- renderContext.setAttribute(ThemeConstants.ATTR_THEMERESULT,
pageResult.getThemeResult());
//
renderContext.render(pageResult);
@@ -83,9 +82,8 @@
}
finally
{
- renderContext.setAttribute(ThemeConstants.ATTR_THEMESERVER, null);
+ renderContext.setAttribute(ThemeConstants.ATTR_THEME_SERVER, null);
renderContext.setAttribute(ThemeConstants.ATTR_THEME, null);
- renderContext.setAttribute(ThemeConstants.ATTR_THEMERESULT, null);
}
}
Modified: trunk/theme/src/main/org/jboss/portal/theme/page/PageResult.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/page/PageResult.java 2007-04-05 21:12:38
UTC (rev 6931)
+++ trunk/theme/src/main/org/jboss/portal/theme/page/PageResult.java 2007-04-05 22:06:33
UTC (rev 6932)
@@ -26,7 +26,6 @@
import org.jboss.portal.theme.render.PageRenderContext;
import org.jboss.portal.theme.render.RegionRenderContext;
import org.jboss.portal.theme.render.WindowRenderContext;
-import org.jboss.portal.theme.ThemeResult;
import org.jboss.portal.theme.PortalTheme;
import java.util.HashMap;
@@ -70,9 +69,6 @@
protected PortalRenderSet renderSet;
/** . */
- protected ThemeResult themeResult;
-
- /** . */
protected PortalTheme theme;
/** . */
@@ -94,16 +90,6 @@
this(pageName, new HashMap(), new HashMap());
}
- public ThemeResult getThemeResult()
- {
- return themeResult;
- }
-
- public void setThemeResult(ThemeResult themeResult)
- {
- this.themeResult = themeResult;
- }
-
public PortalTheme getTheme()
{
return theme;
Modified: trunk/theme/src/main/org/jboss/portal/theme/tag/ThemeTagHandler.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/tag/ThemeTagHandler.java 2007-04-05
21:12:38 UTC (rev 6931)
+++ trunk/theme/src/main/org/jboss/portal/theme/tag/ThemeTagHandler.java 2007-04-05
22:06:33 UTC (rev 6932)
@@ -25,9 +25,9 @@
import org.jboss.logging.Logger;
import org.jboss.portal.theme.PortalTheme;
import org.jboss.portal.theme.ThemeConstants;
-import org.jboss.portal.theme.ThemeResult;
import org.jboss.portal.theme.ThemeServiceInfo;
import org.jboss.portal.theme.LayoutConstants;
+import org.jboss.portal.theme.ThemeElement;
import org.jboss.portal.theme.render.RenderContext;
import javax.servlet.http.HttpServletRequest;
@@ -36,6 +36,7 @@
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
+import java.util.Iterator;
/**
* Tag handler for the theme tag. <p>The theme tag injects theme resource links
into the page. Themes are CSS files, and
@@ -52,7 +53,11 @@
public class ThemeTagHandler
extends SimpleTagSupport
{
+
+ /** . */
private static Logger log = Logger.getLogger(ThemeTagHandler.class);
+
+ /** . */
private String themeName;
/**
@@ -65,7 +70,7 @@
* @throws JspException
* @throws IOException
* @see org.jboss.portal.theme.ThemeConstants#ATTR_THEME
- * @see org.jboss.portal.theme.ThemeConstants#ATTR_THEMESERVER
+ * @see org.jboss.portal.theme.ThemeConstants#ATTR_THEME_SERVER
* @see org.jboss.portal.theme.PortalTheme
*/
public void doTag() throws JspException, IOException
@@ -80,73 +85,27 @@
PageContext app = (PageContext)getJspContext();
HttpServletRequest request = (HttpServletRequest)app.getRequest();
+ // Get the theme provided as a render context attribute
RenderContext renderContext =
(RenderContext)request.getAttribute(LayoutConstants.ATTR_RENDERCONTEXT);
+ PortalTheme theme =
(PortalTheme)renderContext.getAttribute(ThemeConstants.ATTR_THEME);
+ ThemeServiceInfo themeServer =
(ThemeServiceInfo)renderContext.getAttribute(ThemeConstants.ATTR_THEME_SERVER);
- ThemeResult result =
(ThemeResult)renderContext.getAttribute(ThemeConstants.ATTR_THEMERESULT);
-
- // was the result already prepared for us (in the MarkupCommand)?
- if (result != null)
+ // If no theme provided we use what may be on the tag
+ if (theme == null && themeServer != null && themeName != null
&& themeName.length() > 0)
{
- if (trace)
- {
- log.trace("Got valid theme result to render: " +
result.getThemeName());
- }
- JspWriter out = this.getJspContext().getOut();
- out.println(result.getMarkup().toString());
- out.flush();
+ theme = themeServer.getTheme(getThemeName(), false);
}
- else
+
+ //
+ if (theme != null)
{
- // no, then perhaps the theme was provided
- PortalTheme theme =
(PortalTheme)renderContext.getAttribute(ThemeConstants.ATTR_THEME);
- if (theme == null && getThemeName() != null &&
!"".equals(getThemeName()))
+ JspWriter out = this.getJspContext().getOut();
+ for (Iterator i = theme.getElements().iterator(); i.hasNext();)
{
- // if there is no theme in the request, see if we have one via a tag
attribute
- // which we treat as the default
- if (trace)
- {
- log.trace("requested theme not found. Is there a theme attribute in
the tag ? " + getThemeName());
- }
-
- // but in order to get the theme for the provided name, we need the theme
service
- ThemeServiceInfo themeServer =
(ThemeServiceInfo)renderContext.getAttribute(ThemeConstants.ATTR_THEMESERVER);
-
- if (themeServer == null)
- {
- return;
- }
-
- if (trace)
- {
- log.trace("Found theme server");
- }
-
- theme = themeServer.getTheme(getThemeName(), false);
+ ThemeElement el = (ThemeElement)i.next();
+ out.println(el.getElement());
}
-
- if (theme == null)
- {
- if (trace)
- {
- log.trace("No valid theme to render: " + themeName + "
[" + getThemeName() + "]");
- }
- return;
- }
-
- if (trace)
- {
- log.trace("Found valid theme to render: " +
theme.getThemeInfo().getName());
- }
-
- JspWriter out = this.getJspContext().getOut();
- theme.assembleResponse(out);
- out.flush();
}
-
- if (trace)
- {
- log.trace("done rendering theme");
- }
}
// ----- attribute handlers