1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portlets.tracking;
18
19 import java.io.IOException;
20 import java.util.ArrayList;
21 import java.util.Enumeration;
22 import java.util.HashMap;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Map;
26
27 import javax.portlet.ActionRequest;
28 import javax.portlet.ActionResponse;
29 import javax.portlet.PortletConfig;
30 import javax.portlet.PortletContext;
31 import javax.portlet.PortletException;
32 import javax.portlet.RenderRequest;
33 import javax.portlet.RenderResponse;
34
35 import org.apache.jetspeed.CommonPortletServices;
36 import org.apache.jetspeed.aggregator.PortletTrackingManager;
37 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
38 import org.apache.pluto.om.window.PortletWindow;
39 import org.apache.portals.bridges.velocity.GenericVelocityPortlet;
40 import org.apache.velocity.context.Context;
41
42 public class PortletTrackingPortlet extends GenericVelocityPortlet
43 {
44 private PortletTrackingManager trackingManager;
45
46
47
48
49
50 public void init(PortletConfig config) throws PortletException
51 {
52 super.init(config);
53 PortletContext context = getPortletContext();
54 trackingManager = (PortletTrackingManager)context.getAttribute(CommonPortletServices.CPS_PORTLET_TRACKING_MANAGER);
55 }
56
57 public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
58 {
59 List outOfService = createList();
60 Context context = getContext(request);
61 context.put("outOfService", outOfService);
62 context.put("count", new Integer(outOfService.size()));
63 super.doView(request, response);
64 }
65
66 protected List createList()
67 {
68 List result = new ArrayList();
69 Iterator outOfService = trackingManager.getOutOfServiceList().iterator();
70 Map portlets = new HashMap();
71 while (outOfService.hasNext())
72 {
73 PortletWindow window = (PortletWindow)outOfService.next();
74 String id = window.getId().toString();
75 PortletDefinitionComposite pd = (PortletDefinitionComposite)window.getPortletEntity().getPortletDefinition();
76 String uniqueName = pd.getUniqueName();
77 if (!portlets.containsKey(uniqueName))
78 {
79 portlets.put(uniqueName, id);
80 result.add(pd);
81 }
82 }
83 return result;
84 }
85
86 public void processAction(ActionRequest request, ActionResponse actionResponse)
87 throws PortletException, IOException
88 {
89 List result = new ArrayList();
90 Enumeration e = request.getParameterNames();
91 while (e.hasMoreElements())
92 {
93 String param = (String)e.nextElement();
94 if (param.indexOf("::") > 0)
95 {
96 String[] values = request.getParameterValues(param);
97 if (values[0] != null)
98 {
99 result.add(param);
100 }
101 }
102 }
103 if (result.size() > 0)
104 {
105 trackingManager.putIntoService(result);
106 }
107
108 }
109 }