1 package org.tigris.scarab.screens; 2 3 48 49 import java.util.HashMap ; 50 import java.util.List ; 51 import java.util.Iterator ; 52 import java.util.Map ; 53 54 import org.apache.turbine.RunData; 55 import org.apache.turbine.TemplateContext; 56 57 import org.tigris.scarab.attribute.DateAttribute; 58 import org.tigris.scarab.om.ScarabUser; 59 import org.tigris.scarab.om.RModuleUserAttribute; 60 import org.tigris.scarab.om.Attribute; 61 import org.tigris.scarab.om.MITList; 62 import org.tigris.scarab.util.word.QueryResult; 63 import org.tigris.scarab.tools.ScarabRequestTool; 64 import org.tigris.scarab.tools.ScarabLocalizationTool; 65 66 75 public class IssueListExport extends DataExport 76 { 77 Map attributeTypes = new HashMap (); 78 TemplateContext ctx = null; 79 80 83 public void doBuildTemplate(RunData data, TemplateContext context) 84 throws Exception 85 { 86 super.doBuildTemplate(data, context); 87 ctx = context; 88 89 ScarabRequestTool scarabR = getScarabRequestTool(context); 90 ScarabLocalizationTool l10n = getLocalizationTool(context); 91 ScarabUser user = (ScarabUser)data.getUser(); 92 MITList mitlist = user.getCurrentMITList(); 93 TSVPrinter printer = new TSVPrinter(getWriter(data)); 94 List rmuas = scarabR.getRModuleUserAttributes(); 95 writeHeading(printer, mitlist, l10n, rmuas); 96 writeRows(printer, mitlist, l10n, scarabR, rmuas); 97 } 98 99 109 private void writeHeading(TSVPrinter printer, MITList mitlist, 110 ScarabLocalizationTool l10n, List rmuas) 111 throws Exception 112 { 113 if (mitlist != null) 114 { 115 if (!mitlist.isSingleModule()) 116 { 117 printer.print(l10n.get("CapModule")); 118 } 119 120 if (!mitlist.isSingleIssueType()) 121 { 122 printer.print(l10n.get("IssueType")); 123 } 124 } 125 126 printer.print(l10n.get("IssueId")); 127 128 if (containsElements(rmuas)) 130 { 131 int count=0; 132 for (Iterator i = rmuas.iterator(); i.hasNext();) 133 { 134 RModuleUserAttribute rmua = (RModuleUserAttribute)i.next(); 135 Attribute userAttribute = rmua.getAttribute(); 136 printer.print(userAttribute.getName()); 137 attributeTypes.put(Integer.toString(count), userAttribute.getAttributeType().getName()); 138 count++; 139 } 140 } 141 } 142 143 156 private void writeRows(TSVPrinter printer, MITList mitlist, 157 ScarabLocalizationTool l10n, ScarabRequestTool scarabR, List rmuas) 158 throws Exception 159 { 160 for (Iterator i = scarabR.getCurrentSearchResults();i.hasNext();) 161 { 162 printer.println(); 163 QueryResult queryResult = (QueryResult)i.next(); 164 writeRow(printer, mitlist, queryResult); 165 } 166 printer.println(); 169 } 170 171 182 private void writeRow(TSVPrinter printer, MITList mitlist, QueryResult queryResult) 183 throws Exception 184 { 185 if (mitlist != null) 186 { 187 if (!mitlist.isSingleModule()) 188 { 189 printer.print(queryResult.getModule().getRealName()); 190 } 191 192 if (!mitlist.isSingleIssueType()) 193 { 194 printer.print(queryResult.getRModuleIssueType().getDisplayName()); 195 } 196 } 197 198 printer.print(queryResult.getUniqueId()); 199 200 List values = queryResult.getAttributeValuesAsCSV(); 201 if (containsElements(values)) 202 { 203 int count=0; 204 for (Iterator itr = values.iterator();itr.hasNext();) 205 { 206 String val = (String )itr.next(); 207 String type = (String )attributeTypes.get(Integer.toString(count)); 208 count++; 209 if (type.equals("date")) 210 val = DateAttribute.dateFormat(val, getLocalizationTool(ctx).get("ShortDatePattern")); 211 if (val.length() == 0) 212 { 213 printer.print(NO_CONTENT); 214 } 215 else 216 { 217 printer.print(val); 218 } 219 } 220 } 221 } 222 } 223 | Popular Tags |