1 package org.tigris.scarab.screens.admin; 2 3 48 49 import java.util.Iterator ; 51 import java.util.List ; 52 import java.util.ArrayList ; 53 54 import org.apache.velocity.VelocityContext; 55 import org.apache.fulcrum.velocity.TurbineVelocity; 56 import org.apache.turbine.RunData; 57 import org.apache.turbine.TemplateContext; 58 import org.apache.turbine.Turbine; 59 60 import org.tigris.scarab.tools.ScarabRequestTool; 61 import org.tigris.scarab.tools.ScarabLocalizationTool; 62 import org.tigris.scarab.screens.Default; 63 import org.tigris.scarab.om.Issue; 64 import org.tigris.scarab.om.IssueManager; 65 import org.tigris.scarab.util.xmlissues.ImportIssues; 66 67 73 public class ViewXMLExportIssues extends Default 74 { 75 78 public void doBuildTemplate(RunData data, TemplateContext context) 79 throws Exception 80 { 81 super.doBuildTemplate(data, context); 82 83 String filename = data.getParameters().getString("filename"); 86 if (filename == null 87 || filename.length() == 0 88 || filename.indexOf('/') > 0 89 || filename.indexOf(':') > 0 90 || filename.indexOf(';') > 0) 91 { 92 filename = "scarab-issues-export.xml"; 93 } 94 95 ScarabRequestTool scarabR = getScarabRequestTool(context); 96 org.tigris.scarab.om.Module currentModule = scarabR.getCurrentModule(); 97 ScarabLocalizationTool l10n = getLocalizationTool(context); 98 String ids = data.getParameters().getString("exportissues"); 99 context.put("exportissues", ids); 100 if (ids == null || ids.length() == 0) 101 { 102 data.setTarget("admin,XMLExportIssues.vm"); 103 scarabR.setAlertMessage(l10n.get("EnterIssues")); 104 return; 105 } 106 else 107 { 108 List allIdList = null; 109 try 110 { 111 allIdList = Issue.parseIssueList(currentModule, ids); 114 } 115 catch (Exception e) 116 { 117 data.setTarget("admin,XMLExportIssues.vm"); 118 scarabR.setAlertMessage(l10n.getMessage(e)); 119 return; 120 } 121 List issueIdList = new ArrayList (); 122 List badIdList = new ArrayList (); 123 Integer currentModuleId = currentModule.getModuleId(); 124 String defaultCode = currentModule.getCode(); 125 for (Iterator itr = allIdList.iterator(); itr.hasNext();) 126 { 127 String tmp = (String ) itr.next(); 128 Issue issue = IssueManager.getIssueById(tmp, defaultCode); 129 if (issue != null && !issue.getDeleted() 133 && issue.getModuleId().equals(currentModuleId)) 134 { 135 issueIdList.add(tmp); 136 } 137 else 138 { 139 badIdList.add(tmp); 140 } 141 } 142 if (issueIdList.isEmpty()) 143 { 144 data.setTarget("admin,XMLExportIssues.vm"); 145 scarabR.setAlertMessage(l10n.get("NoValidIssuesCouldBeLocated")); 146 return; 147 } 148 else if (!badIdList.isEmpty()) 149 { 150 data.setTarget("admin,XMLExportIssues.vm"); 151 scarabR.setAlertMessage( 152 l10n.format("FollowingIssueIdsAreInvalid", 153 badIdList.toString())); 154 return; 155 } 156 157 String contentType; 158 String contentDisposition; 159 if ("1".equals(data.getParameters().getString("downloadtype"))) 160 { 161 contentType = "text/xml"; 163 contentDisposition = "inline"; 164 } 165 else 166 { 167 contentType = "application/octet-stream"; 174 contentDisposition = "attachment"; 175 } 176 data.getResponse().setContentType(contentType); 177 data.getParameters().add("content-type", contentType); 178 contentDisposition += "; filename=" + filename; 179 data.getParameters().add("content-dispostion", contentDisposition); 180 data.getResponse().setHeader("Content-Disposition", 181 contentDisposition); 182 183 context.put("issueIdList", issueIdList); 184 VelocityContext vc = new VelocityContext(); 185 for (Iterator keys = context.keySet().iterator(); keys.hasNext(); ) 186 { 187 String key = (String ) keys.next(); 188 vc.put(key, context.get(key)); 189 } 190 vc.put("dtdURI", ImportIssues.SYSTEM_DTD_URI); 191 192 String encoding = Turbine.getConfiguration() 193 .getString("scarab.dataexport.encoding"); 194 if (encoding != null && !encoding.equals("")) 195 { 196 TurbineVelocity.handleRequest 197 (vc, "macros/XMLExportIssuesMacro.vm", 198 data.getResponse().getOutputStream(), encoding, encoding); 199 } 200 else 201 { 202 TurbineVelocity.handleRequest 203 (vc, "macros/XMLExportIssuesMacro.vm", 204 data.getResponse().getOutputStream()); 205 } 206 207 data.setTarget(null); 209 } 210 } 211 } 212 | Popular Tags |