Index: JetspeedTool.java
===================================================================
RCS file: /home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/util/template/JetspeedTool.java,v
retrieving revision 1.19
diff -u -r1.19 JetspeedTool.java
--- JetspeedTool.java 29 Jul 2002 02:25:27 -0000 1.19
+++ JetspeedTool.java 5 Aug 2002 17:15:25 -0000
@@ -87,6 +87,7 @@
*
* @author Raphaël Luta
* @author David Sean Taylor
+ * @author Mark Orciuch
*
* @version $Id: JetspeedTool.java,v 1.19 2002/07/29 02:25:27 taylor Exp $
*/
@@ -312,6 +313,116 @@
return customizer;
}
+ /** This method retrieves the appropriate information portlet for the
+ * current portlet
+ *
+ * @param p the portlet to display information about
+ * @param data the RunData for this request
+ * @return the portlet object of the appropriate customizer
+ */
+ public static Portlet getPortletInfoPortlet(RunData data)
+ {
+ Portlet info = null;
+
+ String name = JetspeedResources.getString("PortletInfoPortlet.name", "PortletInfoPortlet");
+
+ try {
+
+ if (null != data)
+ {
+ JetspeedRunData jdata = (JetspeedRunData)data;
+ Profile profile = jdata.getProfile();
+
+ if (null == profile)
+ {
+ Log.warn("JetspeedTool: profile is null");
+ profile = Profiler.getProfile(jdata);
+ jdata.setProfile(profile);
+ }
+
+ Portlet source = findPortlet(data);
+ if (source != null) {
+ jdata.setPortlet(source.getName());
+ info = PortletFactory.getPortlet(name, "PortletInfoPortlet");
+ info.getPortletConfig().setPortletSkin(source.getPortletConfig().getPortletSkin());
+ PortletControl control = PortalToolkit.getControl((String)null);
+ if (control != null)
+ {
+ control.setPortlet(info);
+ control.init();
+ return control;
+ }
+ }
+ }
+ } catch (Exception e) {
+ Log.error(e);
+ }
+
+ return info;
+ }
+
+ /**
+ * Finds portlet identified by js_peid in the current user's profile
+ *
+ * @param rundata for this request
+ * @return portlet identified by js_peid
+ */
+ private static Portlet findPortlet(RunData rundata) {
+
+ Portlet found = null;
+ JetspeedRunData jdata = (JetspeedRunData)rundata;
+ String peid = jdata.getJs_peid();
+ if (peid != null)
+ {
+ Stack sets = new Stack();
+ sets.push(jdata.getProfile().getRootSet());
+
+ while ((found==null) && (sets.size() > 0))
+ {
+ PortletSet set = (PortletSet)sets.pop();
+
+ if (set.getID().equals(peid))
+ {
+ found = set;
+ }
+ else
+ {
+ Enumeration en = set.getPortlets();
+ while((found==null) && en.hasMoreElements())
+ {
+ Portlet p = (Portlet)en.nextElement();
+
+ // unstack the controls to find the real PortletSets
+ Portlet real = p;
+ while (real instanceof PortletControl)
+ {
+ real = ((PortletControl)p).getPortlet();
+ }
+
+ if (real instanceof PortletSet)
+ {
+ if (real.getID().equals(peid))
+ {
+ found=real;
+ }
+ else
+ {
+ // we'll explore this set afterwards
+ sets.push(real);
+ }
+ }
+ else if (p.getID().equals(peid))
+ {
+ found = p;
+ }
+ }
+ }
+ }
+ }
+
+ return found;
+ }
+
/**
* Return the content of a portal element given the id of the element.
*
@@ -437,4 +548,5 @@
return result;
}
+
}