Source Code Cross Referenced for InvitationsAction.java in  » Blogger-System » apache-roller-3.1 » org » apache » roller » ui » authoring » struts » actions » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Blogger System » apache roller 3.1 » org.apache.roller.ui.authoring.struts.actions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  The ASF licenses this file to You
004:         * under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.  For additional information regarding
015:         * copyright in this work, please see the NOTICE file in the top level
016:         * directory of this distribution.
017:         */
018:        package org.apache.roller.ui.authoring.struts.actions;
019:
020:        import java.net.MalformedURLException;
021:        import java.text.MessageFormat;
022:        import java.util.ArrayList;
023:        import java.util.List;
024:        import java.util.ResourceBundle;
025:        import javax.mail.MessagingException;
026:        import javax.mail.Session;
027:        import javax.naming.InitialContext;
028:        import javax.naming.NamingException;
029:        import javax.servlet.http.HttpServletRequest;
030:        import javax.servlet.http.HttpServletResponse;
031:
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:        import org.apache.struts.action.ActionForm;
035:        import org.apache.struts.action.ActionForward;
036:        import org.apache.struts.action.ActionMapping;
037:        import org.apache.struts.actions.DispatchAction;
038:        import org.apache.struts.util.RequestUtils;
039:        import org.apache.roller.RollerException;
040:        import org.apache.roller.config.RollerRuntimeConfig;
041:        import org.apache.roller.business.Roller;
042:        import org.apache.roller.business.RollerFactory;
043:        import org.apache.roller.business.UserManager;
044:        import org.apache.roller.pojos.PermissionsData;
045:        import org.apache.roller.pojos.UserData;
046:        import org.apache.roller.pojos.WebsiteData;
047:        import org.apache.roller.ui.authoring.struts.formbeans.InvitationsForm;
048:        import org.apache.roller.ui.core.BasePageModel;
049:        import org.apache.roller.ui.core.RollerContext;
050:        import org.apache.roller.ui.core.RollerRequest;
051:        import org.apache.roller.ui.core.RollerSession;
052:        import org.apache.roller.util.MailUtil;
053:        import org.apache.struts.action.ActionError;
054:        import org.apache.struts.action.ActionErrors;
055:        import org.apache.struts.action.ActionMessage;
056:        import org.apache.struts.action.ActionMessages;
057:
058:        /**
059:         * Allow viewing and deletion of invitations.
060:         *
061:         * @struts.action path="/roller-ui/authoring/invitations" parameter="method" name="invitationsForm"
062:         * @struts.action-forward name="invitations.page" path=".Invitations"
063:         */
064:        public class InvitationsAction extends DispatchAction {
065:            private static Log mLogger = LogFactory.getFactory().getInstance(
066:                    InvitationsAction.class);
067:
068:            /** If method param is not specified, use HTTP verb to pick method to call */
069:            public ActionForward unspecified(ActionMapping mapping,
070:                    ActionForm actionForm, HttpServletRequest request,
071:                    HttpServletResponse response) throws Exception {
072:                return view(mapping, actionForm, request, response);
073:            }
074:
075:            public ActionForward view(ActionMapping mapping,
076:                    ActionForm actionForm, HttpServletRequest request,
077:                    HttpServletResponse response) throws Exception {
078:                InvitationsPageModel pageModel = new InvitationsPageModel(
079:                        request, response, mapping);
080:                RollerSession rses = RollerSession.getRollerSession(request);
081:                if (pageModel.getWebsite() != null
082:                        && rses.isUserAuthorizedToAdmin(pageModel.getWebsite())) {
083:                    request.setAttribute("model", pageModel);
084:                    return mapping.findForward("invitations.page");
085:                }
086:                return mapping.findForward("access-denied");
087:            }
088:
089:            /** Forwads back to the member permissions page */
090:            public ActionForward cancel(ActionMapping mapping,
091:                    ActionForm actionForm, HttpServletRequest request,
092:                    HttpServletResponse response) throws Exception {
093:                return mapping.findForward("memberPermissions");
094:            }
095:
096:            public ActionForward revoke(ActionMapping mapping,
097:                    ActionForm actionForm, HttpServletRequest request,
098:                    HttpServletResponse response) throws Exception {
099:
100:                InvitationsForm invitationForm = (InvitationsForm) actionForm;
101:                Roller roller = RollerFactory.getRoller();
102:                UserManager umgr = roller.getUserManager();
103:                PermissionsData perms = umgr.getPermissions(invitationForm
104:                        .getPermissionId());
105:                ActionErrors errors = new ActionErrors();
106:                if (perms == null) {
107:                    errors.add(null, new ActionError(
108:                            "invitations.error.notFound"));
109:                    saveErrors(request, errors);
110:                    return view(mapping, actionForm, request, response);
111:                }
112:                RollerSession rses = RollerSession.getRollerSession(request);
113:                if (rses.isUserAuthorizedToAdmin(perms.getWebsite())) {
114:                    umgr.removePermissions(perms);
115:                    roller.flush();
116:                    try {
117:                        notifyInvitee(request, perms.getWebsite(), perms
118:                                .getUser());
119:                        ActionMessages msgs = new ActionMessages();
120:                        msgs.add(ActionMessages.GLOBAL_MESSAGE,
121:                                new ActionMessage("invitations.revoked"));
122:                        saveMessages(request, msgs);
123:                    } catch (RollerException e) {
124:                        errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
125:                                "error.untranslated", e.getMessage()));
126:                        saveErrors(request, errors);
127:                    }
128:                    return view(mapping, actionForm, request, response);
129:                }
130:                return mapping.findForward("access-denied");
131:            }
132:
133:            /**
134:             * Inform invitee that invitation has been revoked.
135:             */
136:            private void notifyInvitee(HttpServletRequest request,
137:                    WebsiteData website, UserData user) throws RollerException {
138:                try {
139:                    Roller roller = RollerFactory.getRoller();
140:                    UserManager umgr = roller.getUserManager();
141:                    javax.naming.Context ctx = (javax.naming.Context) new InitialContext()
142:                            .lookup("java:comp/env");
143:                    Session mailSession = (Session) ctx.lookup("mail/Session");
144:                    if (mailSession != null) {
145:                        String userName = user.getUserName();
146:                        String from = website.getEmailAddress();
147:                        String cc[] = new String[] { from };
148:                        String bcc[] = new String[0];
149:                        String to[] = new String[] { user.getEmailAddress() };
150:                        String subject;
151:                        String content;
152:
153:                        // Figure URL to entry edit page
154:                        RollerContext rc = RollerContext.getRollerContext();
155:                        String rootURL = RollerRuntimeConfig
156:                                .getAbsoluteContextURL();
157:                        if (rootURL == null || rootURL.trim().length() == 0) {
158:                            rootURL = RequestUtils.serverURL(request)
159:                                    + request.getContextPath();
160:                        }
161:
162:                        ResourceBundle resources = ResourceBundle.getBundle(
163:                                "ApplicationResources", website
164:                                        .getLocaleInstance());
165:                        StringBuffer sb = new StringBuffer();
166:                        sb.append(MessageFormat.format(resources
167:                                .getString("invitations.revokationSubject"),
168:                                new Object[] { website.getName(),
169:                                        website.getHandle() }));
170:                        subject = sb.toString();
171:                        sb = new StringBuffer();
172:                        sb
173:                                .append(MessageFormat
174:                                        .format(
175:                                                resources
176:                                                        .getString("invitations.revokationContent"),
177:                                                new Object[] {
178:                                                        website.getName(),
179:                                                        website.getHandle(),
180:                                                        user.getUserName() }));
181:                        content = sb.toString();
182:                        MailUtil.sendTextMessage(mailSession, from, to, cc,
183:                                bcc, subject, content);
184:                    }
185:                } catch (NamingException e) {
186:                    throw new RollerException(
187:                            "ERROR: Revokation email(s) not sent, "
188:                                    + "Roller's mail session not properly configured",
189:                            e);
190:                } catch (MessagingException e) {
191:                    throw new RollerException(
192:                            "ERROR: Revokation email(s) not sent, "
193:                                    + "due to Roller configuration or mail server problem.",
194:                            e);
195:                } catch (MalformedURLException e) {
196:                    throw new RollerException(
197:                            "ERROR: Revokation email(s) not sent, "
198:                                    + "Roller site URL is malformed?", e);
199:                } catch (RollerException e) {
200:                    throw new RuntimeException(
201:                            "FATAL ERROR: unable to find Roller object", e);
202:                }
203:            }
204:
205:            public static class InvitationsPageModel extends BasePageModel {
206:                private List pendings = new ArrayList();
207:
208:                public InvitationsPageModel(HttpServletRequest request,
209:                        HttpServletResponse response, ActionMapping mapping)
210:                        throws RollerException {
211:                    super ("invitations.title", request, response, mapping);
212:                    Roller roller = RollerFactory.getRoller();
213:                    RollerSession rollerSession = RollerSession
214:                            .getRollerSession(request);
215:                    RollerRequest rreq = RollerRequest
216:                            .getRollerRequest(request);
217:                    WebsiteData website = rreq.getWebsite();
218:                    pendings = roller.getUserManager().getPendingPermissions(
219:                            website);
220:                }
221:
222:                public List getPendings() {
223:                    return pendings;
224:                }
225:
226:                public void setPendings(List pendings) {
227:                    this.pendings = pendings;
228:                }
229:            }
230:        }
w__ww_.___ja__v__a__2___s___._co__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.