public class ApplicationPortlet implements Portlet {\r
// The application to show\r
protected String app = null;\r
- // some applications might require that the height is specified\r
- protected String height = null; // e.g "200px"\r
-\r
- private PortletConfig config;\r
+ // some applications might require forced height (and, more seldom, width)\r
+ protected String style = null; // e.g "height:500px;"\r
+ protected String widgetset = null;\r
\r
public void destroy() {\r
- config = null;\r
+\r
}\r
\r
public void init(PortletConfig config) throws PortletException {\r
- this.config = config;\r
app = config.getInitParameter("application");\r
if (app == null) {\r
app = "PortletDemo";\r
}\r
- height = config.getInitParameter("height");\r
+ style = config.getInitParameter("style");\r
+ widgetset = config.getInitParameter("widgetset");\r
}\r
\r
public void processAction(ActionRequest request, ActionResponse response)\r
protected void writeAjaxWindow(RenderRequest request,\r
RenderResponse response) throws IOException {\r
\r
- response.setContentType("text/html");\r
- PrintWriter out = response.getWriter();\r
-\r
if (app != null) {\r
PortletSession sess = request.getPortletSession();\r
PortletApplicationContext ctx = PortletApplicationContext\r
.getApplicationContext(sess);\r
\r
- /*- TODO store som info somewhere?\r
- PortletInfo pi = ctx.setPortletInfo(request.getContextPath() + "/"\r
- + app + (app.endsWith("/") ? "" : "/"), request\r
- .getPortletMode(), request.getWindowState(), request\r
- .getUserPrincipal(), (Map) request\r
- .getAttribute(PortletRequest.USER_INFO), config);\r
- -*/\r
-\r
PortletRequestDispatcher dispatcher = sess.getPortletContext()\r
.getRequestDispatcher("/" + app);\r
\r
try {\r
- // TODO height\r
+ request.setAttribute(ApplicationServlet.REQUEST_FRAGMENT,\r
+ "true");\r
+ if (widgetset != null) {\r
+ request.setAttribute(ApplicationServlet.REQUEST_WIDGETSET,\r
+ widgetset);\r
+ }\r
+ if (style != null) {\r
+ request.setAttribute(ApplicationServlet.REQUEST_APPSTYLE,\r
+ style);\r
+ }\r
dispatcher.include(request, response);\r
\r
} catch (PortletException e) {\r
+ response.setContentType("text/html");\r
+ PrintWriter out = response.getWriter();\r
out.print("<h1>Servlet include failed!</h1>");\r
out.print("<div>" + e + "</div>");\r
ctx.setPortletApplication(this, null);\r
VERSION_BUILD = digits[2];
}
+ /**
+ * If the attribute is present in the request, a html fragment will be
+ * written instead of a whole page.
+ */
+ public static final String REQUEST_FRAGMENT = ApplicationServlet.class
+ .getName()
+ + ".fragment";
+ /**
+ * This request attribute forces widgetset used; e.g for portlets that can
+ * not have different widgetsets.
+ */
+ public static final String REQUEST_WIDGETSET = ApplicationServlet.class
+ .getName()
+ + ".widgetset";
+ /**
+ * This request attribute is used to add styles to the main element. E.g
+ * "height:500px" generates a style="height:500px" to the main element,
+ * useful from some embedding situations (e.g portlet include.)
+ */
+ public static final String REQUEST_APPSTYLE = ApplicationServlet.class
+ .getName()
+ + ".style";
+
// Configurable parameter names
private static final String PARAMETER_DEBUG = "Debug";
HttpServletResponse response, Window window, String themeName,
Application application) throws IOException, MalformedURLException {
- // Portlets only want a html fragment
- // TODO own (itmill) attribute for this e.g
- // ApplicationServlet.class.getName()+".writeFragment"
- boolean fragment = (request.getAttribute("javax.portlet.request") != null);
+ // e.g portlets only want a html fragment
+ boolean fragment = (request.getAttribute(REQUEST_FRAGMENT) != null);
if (fragment) {
request.setAttribute(Application.class.getName(), application);
}
String title = ((window == null || window.getCaption() == null) ? "IT Mill Toolkit 5"
: window.getCaption());
- String widgetset = applicationProperties
- .getProperty(PARAMETER_WIDGETSET);
+ String widgetset = null;
+ // request widgetset takes precedence (e.g portlet include)
+ Object reqParam = request.getAttribute(REQUEST_WIDGETSET);
+ try {
+ widgetset = (String) reqParam;
+ } catch (Exception e) {
+ System.err.println("Warning: request param " + REQUEST_WIDGETSET
+ + " could not be used (not a String?)" + e);
+ }
+ if (widgetset == null) {
+ widgetset = applicationProperties.getProperty(PARAMETER_WIDGETSET);
+ }
if (widgetset == null) {
widgetset = DEFAULT_WIDGETSET;
}
page.write("//]]>\n</script>\n");
}
- page.write("<div id=\"" + appId + "\" class=\"i-app\"></div>\n");
+ String style = null;
+ reqParam = request.getAttribute(REQUEST_APPSTYLE);
+ if (reqParam != null) {
+ style = "style=\"" + reqParam + "\"";
+ }
+ page.write("<div id=\"" + appId + "\" class=\"i-app\" "
+ + (style != null ? style : "") + "></div>\n");
if (!fragment) {
page.write("</body>\n</html>\n");
}
-
page.close();
}