Source Code Cross Referenced for EventAction.java in  » Content-Management-System » TransferCM » com » methodhead » event » 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 » Content Management System » TransferCM » com.methodhead.event 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright (C) 2006 Methodhead Software LLC.  All rights reserved.
003:         * 
004:         * This file is part of TransferCM.
005:         * 
006:         * TransferCM is free software; you can redistribute it and/or modify it under the
007:         * terms of the GNU General Public License as published by the Free Software
008:         * Foundation; either version 2 of the License, or (at your option) any later
009:         * version.
010:         * 
011:         * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012:         * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013:         * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
014:         * details.
015:         * 
016:         * You should have received a copy of the GNU General Public License along with
017:         * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018:         * Fifth Floor, Boston, MA  02110-1301  USA
019:         */
020:
021:        package com.methodhead.event;
022:
023:        import java.util.List;
024:
025:        import javax.servlet.http.HttpServletRequest;
026:        import javax.servlet.http.HttpServletResponse;
027:
028:        import org.apache.log4j.Logger;
029:
030:        import org.apache.struts.action.Action;
031:        import org.apache.struts.action.ActionForm;
032:        import org.apache.struts.action.ActionForward;
033:        import org.apache.struts.action.ActionMapping;
034:        import org.apache.struts.action.DynaActionForm;
035:        import com.methodhead.sitecontext.SiteContext;
036:        import com.methodhead.property.Property;
037:        import com.methodhead.util.OperationContext;
038:        import com.methodhead.util.StrutsUtil;
039:        import com.methodhead.auth.AuthUser;
040:        import com.methodhead.auth.AuthAction;
041:        import com.methodhead.auth.AuthUtil;
042:        import com.methodhead.test.TestUtils;
043:        import java.util.Date;
044:        import java.text.DateFormat;
045:        import java.text.ParseException;
046:        import java.util.Calendar;
047:        import java.util.GregorianCalendar;
048:        import org.apache.commons.lang.StringUtils;
049:
050:        /**
051:         * <p>
052:         *   Use <tt>EventAction</tt> to build a web interface to view logged
053:         *   events.  This action will respond to the mapping <tt>/listEvents</tt>,
054:         *   calling <tt>doListEvents()</tt>.
055:         * </p>
056:         * <p>
057:         *   The mapping's parameter can be used to set the page size of the
058:         *   returned list; the page size defaults to 50:
059:         * </p>
060:         * <xmp>
061:         *   <action
062:         *     path      = "/listEvents"
063:         *     type      = "com.methodhead.event.EventAction"
064:         *     scope     = "request"
065:         *     name      = "eventForm"
066:         *     validate  = "false"
067:         *     parameter = "25">
068:         *     <forward name="list" path="/events.jsp"/>
069:         *   </action>
070:         * </xmp>
071:         * <p>
072:         *   The action is expecting a <tt>DynaActionForm</tt> with at least
073:         *   the following configuration:
074:         * </p>
075:         * <xmp>  <form-bean
076:         *     name    = "eventForm"
077:         *     dynamic = "true"
078:         *     type    = "org.apache.struts.action.DynaActionForm">
079:         * 
080:         *     <form-property name="prev"   type="java.lang.String"/>
081:         *     <form-property name="next"   type="java.lang.String"/>
082:         *     <form-property name="page"   type="java.lang.String"/>
083:         *     <form-property name="events" type="java.util.List"  />
084:         *   </form-bean>
085:         * </xmp>
086:         * <p>
087:         *   The action will load the events for <tt>page</tt> (page 0 if
088:         *   <tt>page</tt> is not specified) and put them in <tt>events</tt>.  If a
089:         *   previous or next page is available, the corresponding form property is
090:         *   set to its page number.  The mapping's input is ignored; instead the
091:         *   <tt>list</tt> forward is returned.
092:         * </p>
093:         */
094:        public class EventAction extends AuthAction {
095:
096:            // constructors /////////////////////////////////////////////////////////////
097:
098:            // constants ////////////////////////////////////////////////////////////////
099:
100:            // classes //////////////////////////////////////////////////////////////////
101:
102:            // methods //////////////////////////////////////////////////////////////////
103:
104:            public ActionForward doListEvents(OperationContext op,
105:                    EventPolicy policy) throws Exception {
106:
107:                //
108:                // authorized?
109:                //
110:                String msg = policy.isListEventsAuthorized(op);
111:                if (msg != null) {
112:                    StrutsUtil.addMessage(op.request, msg, null, null, null);
113:                    return op.mapping.findForward("accessDenied");
114:                }
115:
116:                Date start = TestUtils.getCurrentDate();
117:                Date end = null;
118:                DateFormat format = DateFormat
119:                        .getDateInstance(DateFormat.SHORT);
120:
121:                //
122:                // date provided?
123:                //
124:                if (!StringUtils.isBlank((String) op.form.get("date"))) {
125:                    try {
126:                        start = format.parse((String) op.form.get("date"));
127:                    } catch (ParseException e) {
128:                        Logger.getLogger("EventAction").error(
129:                                "Couldn't parse page from \""
130:                                        + op.form.get("page") + "\"");
131:                    }
132:                }
133:
134:                //
135:                // calculate start and end date
136:                //
137:                Calendar cal = new GregorianCalendar();
138:                cal.setTime(start);
139:
140:                cal.set(Calendar.HOUR_OF_DAY, 0);
141:                cal.set(Calendar.MINUTE, 0);
142:                cal.set(Calendar.SECOND, 0);
143:                cal.set(Calendar.MILLISECOND, 0);
144:                start = cal.getTime();
145:
146:                cal.add(Calendar.DAY_OF_MONTH, 1);
147:                end = cal.getTime();
148:
149:                //
150:                // get the events
151:                //
152:                Event event = new Event();
153:                event.setSiteContext(SiteContext.getContext(op.request));
154:                op.form.set("events", event.getEvents(start, end));
155:
156:                //
157:                // set date, next, and prev
158:                //
159:                op.form.set("date", format.format(start));
160:                op.form.set("next", format.format(end));
161:
162:                cal.add(Calendar.DAY_OF_MONTH, -2);
163:                op.form.set("prev", format.format(cal.getTime()));
164:
165:                //
166:                // forward to list
167:                //
168:                return op.mapping.findForward("list");
169:            }
170:
171:            public ActionForward doExecute(ActionMapping mapping,
172:                    ActionForm form, HttpServletRequest request,
173:                    HttpServletResponse response) throws Exception {
174:
175:                //
176:                // get some things we'll need
177:                //
178:                DynaActionForm dynaForm = (DynaActionForm) form;
179:                EventPolicy policy = (EventPolicy) StrutsUtil
180:                        .getPolicy(mapping);
181:                AuthUser user = AuthUtil.getUser(request);
182:                OperationContext op = new OperationContext(mapping, dynaForm,
183:                        request, response, user);
184:
185:                if (mapping.getPath().equals("/listEvents"))
186:                    return doListEvents(op, policy);
187:
188:                throw new Exception("Unexpected mapping path \""
189:                        + mapping.getPath() + "\"");
190:            }
191:
192:            // properties ///////////////////////////////////////////////////////////////
193:
194:            // attributes ///////////////////////////////////////////////////////////////
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.