Index: JetspeedTool.java
===================================================================
RCS file: /home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/util/template/JetspeedTool.java,v
retrieving revision 1.20
diff -u -r1.20 JetspeedTool.java
--- JetspeedTool.java 7 Aug 2002 06:02:15 -0000 1.20
+++ JetspeedTool.java 8 Aug 2002 17:31:41 -0000
@@ -549,4 +549,70 @@
return result;
}
+
+ /**
+ * Return the content of a portlet using the portlet's name. This portlet is sought in
+ * the registry. This is useful when you want to get portlet's content without
+ * actually having the portlet in user's profile (for example, to preview a portlet
+ * before adding it to the profile).
+ *
+ * If a control name is specified to the portlet description, returns the defined
+ * portlet and control, otherwise use the default control.
+ *
+ * Issues to resolve:
+ *
+ * - is new portlet instance created everytime someone previews the same portlet?
+ *
- should use the same skin as the current pane
+ *
- if TitlePortletControl is used, the action icons (max, min, etc) are not functional.
+ * Also, customize icon should not be present.
+ *
- interactive portlets (such as DatabaseBrowser) lose functionality (such as sorting
+ * in DatabaseBrowser).
+ *
+ * @param portletName
+ * Name of the portlet as defined in registry
+ * @param controlName
+ * Optional control name to use in displaying the portlet
+ * @return the rendered content of the portlet
+ */
+ public ConcreteElement getPortletFromRegistry(String portletName, String controlName)
+ {
+
+ ConcreteElement result = null;
+ Portlet p = null;
+
+ try {
+ // Always set portlet id to "preview" so each preview request gets it from the cache.
+ // At least, I think that's how it works.
+ p = PortletFactory.getPortlet(portletName, "preview");
+ PortletControl control = controlName == null ? PortalToolkit.getControl((String)null) :
+ PortalToolkit.getControl(controlName);
+ if (control != null)
+ {
+ JetspeedRunData jdata = (JetspeedRunData)rundata;
+ // Use the profile's skin
+ p.getPortletConfig().setSkin(PortalToolkit.getSkin(jdata.getProfile().getDocument().getPortlets().getSkin()));
+ control.setPortlet(p);
+ control.init();
+ result = control.getContent(rundata);
+ }
+ else if (p!=null)
+ {
+ result = p.getContent(rundata);
+ }
+ }
+ catch (Exception e)
+ {
+ Log.error(e);
+ result = new ConcreteElement();
+ }
+
+ if (result == null)
+ {
+ //the customizer already streamed its content, return a stub
+ result = new ConcreteElement();
+ }
+
+ return result;
+ }
+
}