KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > actions > ReportListAction


1 /*
2  * Copyright (C) 2002 Erik Swenson - eswenson@opensourcesoft.net
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */

19
20 package org.efs.openreports.actions;
21
22 import java.util.Collections JavaDoc;
23 import java.util.List JavaDoc;
24
25 import com.opensymphony.xwork.ActionContext;
26 import com.opensymphony.xwork.ActionSupport;
27
28 import org.apache.log4j.Logger;
29
30 import org.efs.openreports.ORStatics;
31 import org.efs.openreports.objects.ReportGroup;
32 import org.efs.openreports.objects.ReportUser;
33 import org.efs.openreports.providers.GroupProvider;
34 import org.efs.openreports.providers.GroupProviderAware;
35 import org.efs.openreports.util.LocalStrings;
36
37 public class ReportListAction
38     extends ActionSupport
39     implements GroupProviderAware
40 {
41     protected static Logger log = Logger.getLogger(ReportListAction.class);
42
43     private int groupId = Integer.MIN_VALUE;
44
45     private List JavaDoc reports;
46
47     private GroupProvider groupProvider;
48
49     public List JavaDoc getReports()
50     {
51         return reports;
52     }
53
54     public String JavaDoc execute()
55     {
56         try
57         {
58             ReportGroup reportGroup = null;
59
60             if (groupId == Integer.MIN_VALUE)
61             {
62                 reportGroup =
63                     (ReportGroup) ActionContext.getContext().getSession().get(
64                         ORStatics.REPORT_GROUP);
65             }
66             else
67             {
68                 ReportUser reportUser =
69                     (ReportUser) ActionContext.getContext().getSession().get(
70                         ORStatics.REPORT_USER);
71
72                 reportGroup =
73                     groupProvider.getReportGroup(new Integer JavaDoc(groupId));
74
75                 if (reportUser.isValidGroup(reportGroup))
76                 {
77                     ActionContext.getContext().getSession().put(
78                         ORStatics.REPORT_GROUP,
79                         reportGroup);
80                 }
81                 else
82                 {
83                     addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORTGROUP_NOTAUTHORIZED));
84                     return ERROR;
85                 }
86             }
87
88             if (reportGroup != null)
89             {
90                 reports = reportGroup.getReportsForDisplay();
91                 Collections.sort(reports);
92             }
93
94             return SUCCESS;
95         }
96         catch (Exception JavaDoc e)
97         {
98             addActionError(e.toString());
99             return ERROR;
100         }
101     }
102
103     public int getGroupId()
104     {
105         return groupId;
106     }
107
108     public void setGroupId(int groupId)
109     {
110         this.groupId = groupId;
111     }
112
113     public void setGroupProvider(GroupProvider groupProvider)
114     {
115         this.groupProvider = groupProvider;
116     }
117 }
Popular Tags