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


001:        package org.tigris.scarab.screens.admin;
002:
003:        /*
004:         *  ================================================================
005:         *  Copyright (c) 2000-2002 CollabNet.  All rights reserved.
006:         *
007:         *  Redistribution and use in source and binary forms, with or without
008:         *  modification, are permitted provided that the following conditions are
009:         *  met:
010:         *
011:         *  1. Redistributions of source code must retain the above copyright
012:         *  notice, this list of conditions and the following disclaimer.
013:         *
014:         *  2. Redistributions in binary form must reproduce the above copyright
015:         *  notice, this list of conditions and the following disclaimer in the
016:         *  documentation and/or other materials provided with the distribution.
017:         *
018:         *  3. The end-user documentation included with the redistribution, if
019:         *  any, must include the following acknowlegement: "This product includes
020:         *  software developed by Collab.Net <http://www.Collab.Net/>."
021:         *  Alternately, this acknowlegement may appear in the software itself, if
022:         *  and wherever such third-party acknowlegements normally appear.
023:         *
024:         *  4. The hosted project names must not be used to endorse or promote
025:         *  products derived from this software without prior written
026:         *  permission. For written permission, please contact info@collab.net.
027:         *
028:         *  5. Products derived from this software may not use the "Tigris" or
029:         *  "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
030:         *  prior written permission of Collab.Net.
031:         *
032:         *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
033:         *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
034:         *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
035:         *  IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
036:         *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
037:         *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
038:         *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
039:         *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
040:         *  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
041:         *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
042:         *  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
043:         *
044:         *  ====================================================================
045:         *
046:         *  This software consists of voluntary contributions made by many
047:         *  individuals on behalf of Collab.Net.
048:         */
049:
050:        // Core Java Stuff
051:        import java.util.Collection;
052:
053:        // Turbine & Apache Commons Stuff
054:        import org.apache.turbine.RunData;
055:        import org.apache.turbine.TemplateContext;
056:        import org.apache.commons.fileupload.FileItem;
057:
058:        // Scarab Stuff
059:        import org.tigris.scarab.screens.Default;
060:        import org.tigris.scarab.util.xmlissues.ScarabIssues;
061:        import org.tigris.scarab.services.security.ScarabSecurity;
062:        import org.tigris.scarab.om.ScarabUser;
063:        import org.tigris.scarab.tools.ScarabRequestTool;
064:        import org.tigris.scarab.om.Module;
065:        import org.tigris.scarab.util.xmlissues.ImportIssues;
066:        import org.tigris.scarab.tools.ScarabLocalizationTool;
067:
068:        /**
069:         * Loads XML into Scarab via import, returning XML-formatted results
070:         *
071:         * @author <a href="mailto:mmurphy@collab.net">Mark L. Murphy</a>
072:         * @version $Id: XMLImportIssuesResults.java 10004 2006-02-03 21:29:55Z hair $
073:         */
074:        public class XMLImportIssuesResults extends Default {
075:            private static final int MIN_XML_SIZE = 1;
076:            private static final int RESULT_OK = 0;
077:            private static final int RESULT_ERROR_EXCEPTION = 100;
078:            private static final int RESULT_ERROR_XML_MISSING = 101;
079:            private static final int RESULT_ERROR_UNAUTHORIZED = 102;
080:            private static final int RESULT_ERROR_INVALID_ISSUE_DATA = 103;
081:
082:            /**
083:             * Builds up the context for display of variables on the page.
084:             *
085:             * Runs import of POSTed issue.
086:             *
087:             * @param data Turbine run data
088:             * @param context Velocity template context
089:             */
090:            public void doBuildTemplate(final RunData data,
091:                    final TemplateContext context) throws Exception {
092:
093:                String resultString = "";
094:                int resultCode = RESULT_OK;
095:                Collection importErrors = null;
096:                ScarabIssues si = null;
097:
098:                super .doBuildTemplate(data, context);
099:                final ScarabLocalizationTool l10n = getLocalizationTool(context);
100:
101:                if (isImportAuthorized(data)) {
102:                    final FileItem issuesToImport = data.getParameters()
103:                            .getFileItem("issues");
104:
105:                    if (issuesToImport != null
106:                            && issuesToImport.getSize() >= MIN_XML_SIZE) {
107:                        try {
108:                            final ImportIssues importIssues = new ImportIssues();
109:                            final ScarabRequestTool scarabR = getScarabRequestTool(context);
110:                            final String type = data.getParameters().getString(
111:                                    "xmlFormat");
112:
113:                            importErrors = importIssues.runImport(
114:                                    issuesToImport, scarabR.getCurrentModule(),
115:                                    ImportIssues.ImportType.valueOf(type));
116:
117:                            si = importIssues.getScarabIssuesBeanReader();
118:                            if (importErrors != null && !importErrors.isEmpty()) {
119:                                resultCode = RESULT_ERROR_INVALID_ISSUE_DATA;
120:                                resultString = l10n.get("ProcessingErrors");
121:                            }
122:                        } catch (Exception e) {
123:                            resultCode = RESULT_ERROR_EXCEPTION;
124:                            // TODO: Improve localizability of this text.
125:                            resultString = l10n.get("ProcessingErrors") + ": "
126:                                    + e.getMessage();
127:                        }
128:                    } else {
129:                        resultCode = RESULT_ERROR_XML_MISSING;
130:                        resultString = l10n.get("MissingXML");
131:                    }
132:                } else {
133:                    resultCode = RESULT_ERROR_UNAUTHORIZED;
134:                    resultString = l10n.get("Unauthorized");
135:                }
136:
137:                context.put("resultString", resultString);
138:                context.put("resultCode", new Integer(resultCode));
139:                context.put("importErrors", importErrors);
140:                context.put("issues", si);
141:
142:                final String format = data.getParameters().getString("format");
143:                if (format != null && format.equals("xml")) {
144:                    final String result = org.apache.turbine.modules.Module
145:                            .handleRequest(context,
146:                                    "macros/XMLImportIssuesResultsMacro.vm");
147:                    data.getResponse().setContentType("text/plain");
148:                    data.getResponse().setContentLength(result.length());
149:                    data.getResponse().getOutputStream().print(result);
150:
151:                    // we already sent the response, there is no target to render
152:                    data.setTarget(null);
153:                }
154:            }
155:
156:            /**
157:             * Indicates if this request is authorized. 
158:             * 
159:             * Overridden so we always return XML for this request, with that XML
160:             * containing an error message if unauthorized. Otherwise, requesting this
161:             * page might sometimes return HTML (error page) and sometimes return XML
162:             * (authorized request), which will make parsing by automation clients
163:             * difficult.
164:             *
165:             * @param data Turbine run data.
166:             *
167:             * @return Boolean indicating if authorized.
168:             */
169:            protected boolean isAuthorized(RunData data) throws Exception {
170:                return (true);
171:            }
172:
173:            /**
174:             * Indicates if this import request is authorized
175:             *
176:             * @param data Turbine run data.
177:             *
178:             * @return Boolean indicating whether or not authorized.
179:             */
180:            private boolean isImportAuthorized(RunData data) throws Exception {
181:                String perm = ScarabSecurity
182:                        .getScreenPermission("admin.XMLImportIssuesResults.vm");
183:                TemplateContext context = getTemplateContext(data);
184:                ScarabRequestTool scarabR = getScarabRequestTool(context);
185:                Module currentModule = scarabR.getCurrentModule();
186:                ScarabUser user = (ScarabUser) data.getUser();
187:                boolean result = false;
188:
189:                if (perm != null) // Is there is a permission for this?
190:                {
191:                    if (user.hasLoggedIn()
192:                            && user.hasPermission(perm, currentModule)) {
193:                        result = true; // Confirmed user has permission
194:                    }
195:                } else {
196:                    result = true; // No permission = unsecured
197:                }
198:
199:                return (result);
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.