Source Code Cross Referenced for RequireLoginFirstAction.java in  » Issue-Tracking » scarab-0.21 » org » tigris » scarab » actions » base » 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 » Issue Tracking » scarab 0.21 » org.tigris.scarab.actions.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.tigris.scarab.actions.base;
002:
003:        /* ================================================================
004:         * Copyright (c) 2000-2002 CollabNet.  All rights reserved.
005:         * 
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions are
008:         * met:
009:         * 
010:         * 1. Redistributions of source code must retain the above copyright
011:         * notice, this list of conditions and the following disclaimer.
012:         * 
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         * notice, this list of conditions and the following disclaimer in the
015:         * documentation and/or other materials provided with the distribution.
016:         * 
017:         * 3. The end-user documentation included with the redistribution, if
018:         * any, must include the following acknowlegement: "This product includes
019:         * software developed by Collab.Net <http://www.Collab.Net/>."
020:         * Alternately, this acknowlegement may appear in the software itself, if
021:         * and wherever such third-party acknowlegements normally appear.
022:         * 
023:         * 4. The hosted project names must not be used to endorse or promote
024:         * products derived from this software without prior written
025:         * permission. For written permission, please contact info@collab.net.
026:         * 
027:         * 5. Products derived from this software may not use the "Tigris" or 
028:         * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without 
029:         * prior written permission of Collab.Net.
030:         * 
031:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034:         * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035:         * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036:         * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037:         * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039:         * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040:         * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041:         * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042:         *
043:         * ====================================================================
044:         * 
045:         * This software consists of voluntary contributions made by many
046:         * individuals on behalf of Collab.Net.
047:         */
048:
049:        // Java Stuff
050:        import java.util.List;
051:
052:        import org.apache.fulcrum.intake.Retrievable;
053:        import org.apache.fulcrum.intake.model.Field;
054:        import org.apache.fulcrum.intake.model.Group;
055:        import org.apache.fulcrum.parser.ParameterParser;
056:        import org.apache.log4j.Logger;
057:        import org.apache.turbine.RunData;
058:        import org.apache.turbine.TemplateContext;
059:        import org.apache.turbine.TemplateSecureAction;
060:        import org.apache.turbine.tool.IntakeTool;
061:        import org.tigris.scarab.om.Module;
062:        import org.tigris.scarab.om.ScarabUser;
063:        import org.tigris.scarab.screens.Default;
064:        import org.tigris.scarab.services.security.ScarabSecurity;
065:        import org.tigris.scarab.tools.ScarabLocalizationTool;
066:        import org.tigris.scarab.tools.ScarabRequestTool;
067:        import org.tigris.scarab.tools.localization.L10NKeySet;
068:        import org.tigris.scarab.tools.localization.LocalizationKey;
069:        import org.tigris.scarab.util.ScarabConstants;
070:
071:        /**
072:         * This is a badly named class which is essentially equivalent to the 
073:         * Default.java Screen except that it has a few helper methods.
074:         *
075:         * @author <a href="mailto:jon@collab.net">Jon S. Stevens</a>
076:         * @version $Id: RequireLoginFirstAction.java 9280 2004-11-27 01:11:13Z jorgeuriarte $    
077:         */
078:        public abstract class RequireLoginFirstAction extends
079:                TemplateSecureAction {
080:            private static final Logger LOG = Logger
081:                    .getLogger("org.tigris.scarab");
082:
083:            protected static final LocalizationKey ERROR_MESSAGE = L10NKeySet.MoreInformationWasRequired;
084:            protected static final LocalizationKey NO_PERMISSION_MESSAGE = L10NKeySet.YouDoNotHavePermissionToAction;
085:            protected static final LocalizationKey DEFAULT_MSG = L10NKeySet.YourChangesWereSaved;
086:            protected static final LocalizationKey EMAIL_ERROR = L10NKeySet.CouldNotSendEmail;
087:            protected static final LocalizationKey EMAIL_ERROR2 = L10NKeySet.CouldNotSendEmail2;
088:            protected static final LocalizationKey NO_CHANGES_MADE = L10NKeySet.NoChangesMade;
089:
090:            /**
091:             * sets the template to template.login if the user hasn't logged in yet
092:             */
093:            protected boolean isAuthorized(RunData data) throws Exception {
094:                boolean auth = false;
095:                String perm = getRequiredPermission(data);
096:                TemplateContext context = getTemplateContext(data);
097:                ScarabRequestTool scarabR = getScarabRequestTool(context);
098:                ScarabLocalizationTool l10n = getLocalizationTool(context);
099:                Module currentModule = scarabR.getCurrentModule();
100:                ScarabUser user = (ScarabUser) data.getUser();
101:
102:                if (ScarabSecurity.NONE.equals(perm)) {
103:                    if (!user.hasLoggedIn()) {
104:                        scarabR
105:                                .setInfoMessage(L10NKeySet.LoginToAccountWithPermissions);
106:                        Default.setTargetLogin(data);
107:                        scarabR.setCurrentModule(null);
108:                    } else {
109:                        auth = true;
110:                    }
111:                } else if (perm == null) {
112:                    scarabR
113:                            .setAlertMessage(L10NKeySet.ActionNotAssignedPermission);
114:                } else {
115:                    if (currentModule == null) {
116:                        scarabR.setInfoMessage(L10NKeySet.SelectModuleToWorkIn);
117:                        Default.setTargetSelectModule(data);
118:                    } else if (!user.hasLoggedIn()
119:                            || !user.hasPermission(perm, currentModule)) {
120:                        scarabR
121:                                .setInfoMessage(L10NKeySet.LoginToAccountWithPermissions);
122:
123:                        Default.setTargetLogin(data);
124:                        scarabR.setCurrentModule(null);
125:                    } else {
126:                        auth = true;
127:                    }
128:                }
129:                return auth;
130:            }
131:
132:            /**
133:             * Helper method to retrieve the IntakeTool from the Context
134:             */
135:            public IntakeTool getIntakeTool(TemplateContext context) {
136:                return (IntakeTool) context.get(ScarabConstants.INTAKE_TOOL);
137:            }
138:
139:            /**
140:             * Helper method to retrieve the ScarabLocalizationTool from the Context
141:             */
142:            protected final ScarabLocalizationTool getLocalizationTool(
143:                    TemplateContext context) {
144:                return (ScarabLocalizationTool) context
145:                        .get(ScarabConstants.LOCALIZATION_TOOL);
146:            }
147:
148:            /**
149:             * Helper method to retrieve the ScarabRequestTool from the Context
150:             */
151:            public ScarabRequestTool getScarabRequestTool(
152:                    TemplateContext context) {
153:                return (ScarabRequestTool) context
154:                        .get(ScarabConstants.SCARAB_REQUEST_TOOL);
155:            }
156:
157:            /**
158:             * Returns the current template that is being executed, otherwisse
159:             * it returns null
160:             */
161:            public String getCurrentTemplate(RunData data) {
162:                return data.getParameters().getString(ScarabConstants.TEMPLATE,
163:                        null);
164:            }
165:
166:            /**
167:             * Returns the current template that is being executed, otherwisse
168:             * it returns defaultValue.
169:             */
170:            public String getCurrentTemplate(RunData data, String defaultValue) {
171:                return data.getParameters().getString(ScarabConstants.TEMPLATE,
172:                        defaultValue);
173:            }
174:
175:            /**
176:             * Returns the nextTemplate to be executed. Otherwise returns null.
177:             */
178:            public String getNextTemplate(RunData data) {
179:                return data.getParameters().getString(
180:                        ScarabConstants.NEXT_TEMPLATE, null);
181:            }
182:
183:            /**
184:             * Returns the nextTemplate to be executed. Otherwise returns defaultValue.
185:             */
186:            public String getNextTemplate(RunData data, String defaultValue) {
187:                return data.getParameters().getString(
188:                        ScarabConstants.NEXT_TEMPLATE, defaultValue);
189:            }
190:
191:            /**
192:             * Returns the last template to be cancelled back to.
193:             */
194:            public String getLastTemplate(RunData data) {
195:                return data.getParameters().getString(
196:                        ScarabConstants.LAST_TEMPLATE, null);
197:            }
198:
199:            /**
200:             * Returns the cancelTemplate to be executed. Otherwise returns null.
201:             */
202:            public String getCancelTemplate(RunData data) {
203:                return data.getParameters().getString(
204:                        ScarabConstants.CANCEL_TEMPLATE, null);
205:            }
206:
207:            /**
208:             * Returns the cancelTemplate to be executed. 
209:             * Otherwise returns defaultValue.
210:             */
211:            public String getCancelTemplate(RunData data, String defaultValue) {
212:                return data.getParameters().getString(
213:                        ScarabConstants.CANCEL_TEMPLATE, defaultValue);
214:            }
215:
216:            /**
217:             * Returns the backTemplate to be executed. Otherwise returns null.
218:             */
219:            public String getBackTemplate(RunData data) {
220:                return data.getParameters().getString(
221:                        ScarabConstants.BACK_TEMPLATE, null);
222:            }
223:
224:            /**
225:             * Returns the backTemplate to be executed. 
226:             * Otherwise returns defaultValue.
227:             */
228:            public String getBackTemplate(RunData data, String defaultValue) {
229:                return data.getParameters().getString(
230:                        ScarabConstants.BACK_TEMPLATE, defaultValue);
231:            }
232:
233:            /**
234:             * Returns the other template that is being executed, otherwise
235:             * it returns null.
236:             */
237:            public String getOtherTemplate(RunData data) {
238:                return data.getParameters().getString(
239:                        ScarabConstants.OTHER_TEMPLATE);
240:            }
241:
242:            public void doSave(RunData data, TemplateContext context)
243:                    throws Exception {
244:            }
245:
246:            public void doGonext(RunData data, TemplateContext context)
247:                    throws Exception {
248:                setTarget(data, getNextTemplate(data));
249:            }
250:
251:            public void doGotoothertemplate(RunData data,
252:                    TemplateContext context) throws Exception {
253:                data.getParameters().setString(ScarabConstants.CANCEL_TEMPLATE,
254:                        getCurrentTemplate(data));
255:                setTarget(data, getOtherTemplate(data));
256:            }
257:
258:            public void doRefresh(RunData data, TemplateContext context)
259:                    throws Exception {
260:                setTarget(data, getCurrentTemplate(data));
261:            }
262:
263:            public void doRefreshresultsperpage(RunData data,
264:                    TemplateContext context) throws Exception {
265:                ParameterParser params = data.getParameters();
266:                int oldResultsPerPage = params.getInt("oldResultsPerPage");
267:                int newResultsPerPage = params.getInt("resultsPerPage");
268:                int oldPageNum = params.getInt("pageNum");
269:
270:                //
271:                // We want to display whichever page contains the first issue
272:                // on the old page.
273:                //
274:                int firstItem = (oldPageNum - 1) * oldResultsPerPage + 1;
275:                int newPageNum = (firstItem / newResultsPerPage) + 1;
276:                params.remove("oldResultsPerPage");
277:                params.remove("pageNum");
278:                params.add("pageNum", newPageNum);
279:                setTarget(data, getCurrentTemplate(data));
280:            }
281:
282:            public void doReset(RunData data, TemplateContext context)
283:                    throws Exception {
284:                IntakeTool intake = getIntakeTool(context);
285:                intake.removeAll();
286:                setTarget(data, getCurrentTemplate(data));
287:            }
288:
289:            public void doCancel(RunData data, TemplateContext context)
290:                    throws Exception {
291:                setTarget(data, getCancelTemplate(data));
292:            }
293:
294:            public void doDone(RunData data, TemplateContext context)
295:                    throws Exception {
296:                doSave(data, context);
297:                doCancel(data, context);
298:            }
299:
300:            protected Logger log() {
301:                return LOG;
302:            }
303:
304:            /**
305:             * Flag that marks the action as requiring a permission mapping in
306:             * Scarab.properties.  The default is true, so actions that only
307:             * require login (or only require a permission given some critieria
308:             * available in the arguments), should override this method.
309:             *
310:             * @param data a <code>RunData</code> value
311:             * @return a <code>boolean</code> value
312:             */
313:            protected String getRequiredPermission(RunData data) {
314:                return ScarabSecurity.getActionPermission(data.getAction());
315:            }
316:
317:            /**
318:             * Check if the objects have duplicate sequence numbers set
319:             * @param list List of 'om' objects that need to be checked for duplicate
320:             *                                                          sequence.
321:             * @param intake IntakeTool
322:             * @param groupName Intake group name
323:             * @param fieldName Intake field name
324:             * @param dedupeSeq sequence number set for Duplicate Check element in the
325:             *                   case of attribute groups
326:             * @return boolean TRUE if there are duplicate sequence numbers.
327:             */
328:            public boolean areThereDupeSequences(List list, IntakeTool intake,
329:                    String groupName, String fieldName, int dedupeSeq)
330:                    throws Exception {
331:                boolean dupeSequenceFound = false;
332:                int listSize = (list == null) ? 0 : list.size();
333:                Field order1 = null;
334:                Field order2 = null;
335:                for (int i = 0; i < listSize && !dupeSequenceFound; i++) {
336:                    Retrievable obj1 = (Retrievable) list.get(i);
337:                    Group group1 = intake.get(groupName, obj1.getQueryKey(),
338:                            false);
339:                    order1 = group1.get(fieldName);
340:
341:                    if (dedupeSeq > 0
342:                            && order1.toString().equals(
343:                                    Integer.toString(dedupeSeq))) {
344:                        dupeSequenceFound = true;
345:                    }
346:
347:                    for (int j = i - 1; j >= 0 && !dupeSequenceFound; j--) {
348:                        Retrievable obj2 = (Retrievable) list.get(j);
349:                        Group group2 = intake.get(groupName,
350:                                obj2.getQueryKey(), false);
351:                        order2 = group2.get(fieldName);
352:                        if (order1.toString().equals(order2.toString())) {
353:                            dupeSequenceFound = true;
354:                        }
355:                    }
356:                }
357:                return dupeSequenceFound;
358:            }
359:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.