1
14
15 package com.liferay.portal.kernel.util;
16
17 import javax.portlet.PortletRequest;
18 import javax.portlet.PortletSession;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpSession;
22
23
28 public class ProgressTracker {
29
30 public static final String PERCENT =
31 ProgressTracker.class.getName() + "_PERCENT";
32
33 public ProgressTracker(HttpServletRequest request, String progressId) {
34 _request = request;
35 _progressId = progressId;
36 }
37
38 public ProgressTracker(PortletRequest portletRequest, String progressId) {
39 _portletRequest = portletRequest;
40 _progressId = progressId;
41 }
42
43 public int getProgress() {
44 if (_request != null) {
45 HttpSession session = _request.getSession();
46
47 return (Integer)session.getAttribute(PERCENT + _progressId);
48 }
49 else {
50 PortletSession portletSession = _portletRequest.getPortletSession();
51
52 return (Integer)portletSession.getAttribute(PERCENT + _progressId);
53 }
54 }
55
56 public void start() {
57 updateProgress(1);
58 }
59
60 public void updateProgress(int percentage) {
61 if (_request != null) {
62 HttpSession session = _request.getSession();
63
64 session.setAttribute(
65 PERCENT + _progressId, new Integer(percentage));
66 }
67 else {
68 PortletSession portletSession = _portletRequest.getPortletSession();
69
70 portletSession.setAttribute(
71 PERCENT + _progressId, new Integer(percentage),
72 PortletSession.APPLICATION_SCOPE);
73 }
74 }
75
76 public void finish() {
77 if (_request != null) {
78 HttpSession session = _request.getSession();
79
80 session.removeAttribute(PERCENT + _progressId);
81 }
82 else {
83 PortletSession portletSession = _portletRequest.getPortletSession();
84
85 portletSession.removeAttribute(
86 PERCENT + _progressId, PortletSession.APPLICATION_SCOPE);
87 }
88 }
89
90 private HttpServletRequest _request;
91 private PortletRequest _portletRequest;
92 private String _progressId;
93
94 }