KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > applications > PersistantServletRequest


1 package org.jahia.services.applications;
2
3 import org.jahia.data.applications.ApplicationBean;
4 import org.jahia.data.applications.ApplicationContext;
5 import org.jahia.data.applications.ServletBean;
6 import org.jahia.registries.ServicesRegistry;
7 import org.jahia.services.usermanager.JahiaGroup;
8 import org.jahia.services.usermanager.JahiaUser;
9
10 import java.util.*;
11 import java.io.Serializable JavaDoc;
12
13 /**
14  * This class is used by the dispatching system to store in this information
15  * in a hashtable. Was not made an innerclass because these can cause problems,
16  * and this information might be interesting to store elsewhere.
17  */

18 public class PersistantServletRequest extends ServletBean implements Serializable JavaDoc {
19
20     private String JavaDoc appUniqueIDStr;
21     private String JavaDoc appURL;
22     private String JavaDoc appMethod;
23     private String JavaDoc appContextID;
24     private String JavaDoc servletMappingPattern;
25     private ApplicationBean appBean;
26
27
28     public PersistantServletRequest (ApplicationBean stdAppBean,
29                                      ServletBean servletBean,
30                                      String JavaDoc appUniqueIDStr,
31                                      String JavaDoc applicationURL,
32                                      String JavaDoc applicationMethod,
33                                      String JavaDoc applicationContextID) {
34
35         super (
36                 servletBean.getWebAppType (),
37                 servletBean.getName (),
38                 servletBean.getServletName (),
39                 servletBean.getservletsrc (),
40                 servletBean.getContext (),
41                 servletBean.getdesc ()
42         );
43
44         super.setLoaded (servletBean.isLoaded ());
45         super.setUrlMappingPattern (servletBean.getUrlMappingPattern ());
46         super.setWebAppType (servletBean.getWebAppType ());
47
48         this.appUniqueIDStr = appUniqueIDStr;
49         this.appURL = applicationURL;
50         this.appMethod = applicationMethod;
51         this.appContextID = applicationContextID;
52         this.appBean = stdAppBean;
53         this.servletMappingPattern = servletBean.getUrlMappingPattern ();
54     }
55
56     public String JavaDoc getUniqueIDStr () {
57         return appUniqueIDStr;
58     }
59
60     public String JavaDoc getURL () {
61         return appURL;
62     }
63
64     public void setURL (String JavaDoc value) {
65         appURL = value;
66     }
67
68     public String JavaDoc getMethod () {
69         return appMethod;
70     }
71
72     public String JavaDoc getContextID () {
73         return appContextID;
74     }
75
76     public String JavaDoc getServletMappingPattern () {
77         return servletMappingPattern;
78     }
79
80     public int getVisibleStatus () {
81         return appBean.getVisibleStatus ();
82     }
83
84     public ApplicationBean getApplicationBean () {
85         return appBean;
86     }
87
88     /**
89      * return a list of user names having a role with this application
90      * only on this context
91      *
92      * @author NK
93      * @todo FIXME it would be best if we returned a Set rather than a
94      * vector, but unfortunately existing applications use this method's
95      * result as a vector...
96      */

97     public Vector getAppContextUsers () {
98
99         Vector users = new Vector ();
100         Set addedUsers = new HashSet ();
101
102         if (appBean == null) {
103             return users;
104         }
105
106         Enumeration appRoles = null;
107         try {
108             ApplicationContext appContext = ServicesRegistry.getInstance ()
109                     .getJahiaApplicationContextService ()
110                     .getApplicationContext (appBean.getID ());
111
112             appRoles = appContext.getRoles ().elements ();
113         } catch (Throwable JavaDoc t) {
114             t.printStackTrace ();
115             return users;
116         }
117
118         if (appRoles == null) {
119             return users;
120         }
121
122         JahiaGroup roleGroup = null;
123         String JavaDoc role = null;
124         while (appRoles.hasMoreElements ()) {
125
126             role = (String JavaDoc) appRoles.nextElement ();
127
128             // Roles are mapped to Jahia groups.
129
StringBuffer JavaDoc buff = new StringBuffer JavaDoc (Integer.toString (appBean.getID ()));
130             buff.append ("_");
131             buff.append (this.appContextID);
132             buff.append ("_");
133             buff.append (role);
134
135             roleGroup = ServicesRegistry.getInstance ()
136                     .getJahiaGroupManagerService ()
137                     .lookupGroup (0, buff.toString ()); // Hollis all app group roles are in site 0
138
if (roleGroup != null) {
139
140                 Set userMembers = roleGroup.getRecursiveUserMembers ();
141                 Iterator userIterator = userMembers.iterator ();
142                 while (userIterator.hasNext ()) {
143                     JahiaUser curUser = (JahiaUser) userIterator.next ();
144                     if (!addedUsers.contains (curUser.getUserKey ())) {
145                         addedUsers.add (curUser.getUserKey ());
146                         users.add (curUser.getUsername ());
147                     }
148                 }
149             }
150         }
151
152         return users;
153     }
154
155 }
156
Popular Tags