1 package org.tigris.scarab.screens.admin; 2 3 49 50 import java.util.Collection ; 52 53 import org.apache.turbine.RunData; 55 import org.apache.turbine.TemplateContext; 56 import org.apache.commons.fileupload.FileItem; 57 58 import org.tigris.scarab.screens.Default; 60 import org.tigris.scarab.util.xmlissues.ScarabIssues; 61 import org.tigris.scarab.services.security.ScarabSecurity; 62 import org.tigris.scarab.om.ScarabUser; 63 import org.tigris.scarab.tools.ScarabRequestTool; 64 import org.tigris.scarab.om.Module; 65 import org.tigris.scarab.util.xmlissues.ImportIssues; 66 import org.tigris.scarab.tools.ScarabLocalizationTool; 67 68 74 public class XMLImportIssuesResults extends Default 75 { 76 private static final int MIN_XML_SIZE = 1; 77 private static final int RESULT_OK = 0; 78 private static final int RESULT_ERROR_EXCEPTION = 100; 79 private static final int RESULT_ERROR_XML_MISSING = 101; 80 private static final int RESULT_ERROR_UNAUTHORIZED = 102; 81 private static final int RESULT_ERROR_INVALID_ISSUE_DATA = 103; 82 83 91 public void doBuildTemplate(RunData data, TemplateContext context) 92 throws Exception 93 { 94 String resultString = ""; 95 int resultCode = RESULT_OK; 96 Collection importErrors = null; 97 ScarabIssues si = null; 98 99 super.doBuildTemplate(data, context); 100 ScarabLocalizationTool l10n = getLocalizationTool(context); 101 102 if (isImportAuthorized(data)) 103 { 104 FileItem issuesToImport = data.getParameters() 105 .getFileItem("issues"); 106 if (issuesToImport != null 107 && issuesToImport.getSize() >= MIN_XML_SIZE) 108 { 109 try 110 { 111 ImportIssues importIssues = new ImportIssues(); 112 ScarabRequestTool scarabR = getScarabRequestTool(context); 113 importErrors = importIssues.runImport(issuesToImport, 114 scarabR.getCurrentModule()); 115 si = importIssues.getScarabIssuesBeanReader(); 116 if (importErrors != null && !importErrors.isEmpty()) 117 { 118 resultCode = RESULT_ERROR_INVALID_ISSUE_DATA; 119 resultString = l10n.get("ProcessingErrors"); 120 } 121 } 122 catch (Exception e) 123 { 124 resultCode = RESULT_ERROR_EXCEPTION; 125 resultString = l10n.get("ProcessingErrors") + ": " 127 + e.getMessage(); 128 } 129 } 130 else 131 { 132 resultCode = RESULT_ERROR_XML_MISSING; 133 resultString = l10n.get("MissingXML"); 134 } 135 } 136 else 137 { 138 resultCode = RESULT_ERROR_UNAUTHORIZED; 139 resultString = l10n.get("Unauthorized"); 140 } 141 142 context.put("resultString", resultString); 143 context.put("resultCode", new Integer (resultCode)); 144 context.put("importErrors", importErrors); 145 context.put("issues", si); 146 147 String format = data.getParameters().getString("format"); 148 if (format != null && format.equals("xml")) 149 { 150 String result = org.apache.turbine.modules.Module.handleRequest 151 (context, "macros/XMLImportIssuesResultsMacro.vm"); 152 data.getResponse().setContentType("text/plain"); 153 data.getResponse().setContentLength(result.length()); 154 data.getResponse().getOutputStream().print(result); 155 156 data.setTarget(null); 158 } 159 } 160 161 174 protected boolean isAuthorized(RunData data) throws Exception 175 { 176 return (true); 177 } 178 179 186 private boolean isImportAuthorized(RunData data) 187 throws Exception 188 { 189 String perm = ScarabSecurity.getScreenPermission 190 ("admin.XMLImportIssuesResults.vm"); 191 TemplateContext context = getTemplateContext(data); 192 ScarabRequestTool scarabR = getScarabRequestTool(context); 193 Module currentModule = scarabR.getCurrentModule(); 194 ScarabUser user = (ScarabUser) data.getUser(); 195 boolean result = false; 196 197 if (perm != null) { 199 if (user.hasLoggedIn() && 200 user.hasPermission(perm, currentModule)) 201 { 202 result = true; } 204 } 205 else 206 { 207 result = true; } 209 210 return (result); 211 } 212 } 213 214 | Popular Tags |