1 package dinamica; 2 3 15 public class GenericOutput 16 extends AbstractModule 17 implements IRowEvent 18 { 19 20 21 private int rowColor = 0; 22 23 39 public void print(TemplateEngine te, GenericTransaction data) throws Throwable  40 { 41 42 43 if (data!=null) 44 { 45 Recordset rs = _config.getPrintCommands(); 46 47 while (rs.next()) 48 { 49 50 String nullExpr = null; 51 if (_config.contentType.equals("text/html")) 52 nullExpr = " "; 53 else 54 nullExpr = ""; 55 56 String pagesize = getRequest().getParameter("pagesize"); 58 if (pagesize!=null && pagesize.trim().equals("")) 59 pagesize=null; 60 61 if (pagesize==null) 62 pagesize = (String )rs.getValue("pagesize"); 63 65 String mode = (String )rs.getValue("mode"); 66 String tag = (String )rs.getValue("tag"); 67 String control = (String )rs.getValue("control"); 68 String rsname = (String )rs.getValue("recordset"); 69 String altColors = (String )rs.getValue("alternate-colors"); 70 String nullValue = (String )rs.getValue("null-value"); 71 72 if (nullValue!=null) 73 nullExpr = nullValue; 74 75 if (mode.equals("table")) 76 { 77 Recordset x = data.getRecordset(rsname); 78 if (pagesize!=null && !rs.isNull("pagesize")) 79 { 80 int page = 0; 81 82 if (x.getPageCount()==0) 84 x.setPageSize(Integer.parseInt(pagesize)); 85 87 String pageNumber = getRequest().getParameter("pagenumber"); 88 if (pageNumber==null || pageNumber.equals("")) 89 { 90 page = x.getPageNumber(); 91 if (page==0) 92 page = 1; 93 } 94 else 95 { 96 page = Integer.parseInt(pageNumber); 97 } 98 x = x.getPage(page); 99 } 100 101 if (altColors!=null && altColors.equals("true")) 102 te.setRowEventObject(this); 103 104 te.replace(x,nullExpr,tag); 105 } 106 else if (mode.equals("form")) 107 { 108 nullExpr = ""; 109 Recordset x = data.getRecordset(rsname); 110 if (x.getRecordCount()>0 && x.getRecordNumber()<0) 111 x.first(); 112 113 if (x.getRecordCount()==0) 115 throw new Throwable ("Recordset [" + rsname + "] has no records; can't print (mode=form) using an empty Recordset."); 116 117 te.replace(x, nullExpr); 118 } 119 else if (mode.equals("combo")) 120 { 121 if (control==null) 122 throw new Throwable ("'control' attribute cannot be null when print-mode='combo'"); 123 Recordset x = data.getRecordset(rsname); 124 if (x.getRecordCount()>1) 125 te.setComboValue(control,x); 126 else 127 if (x.getRecordCount()>0 && x.getRecordNumber()<0) 128 x.first(); 129 te.setComboValue(control,String.valueOf(x.getValue(control))); 130 } 131 else if (mode.equals("checkbox")) 132 { 133 if (control==null) 134 throw new Throwable ("'control' attribute cannot be null when print-mode='checkbox'"); 135 Recordset x = data.getRecordset(rsname); 136 te.setCheckbox(control,x); 137 } 138 else if (mode.equals("radio")) 139 { 140 if (control==null) 141 throw new Throwable ("'control' attribute cannot be null when print-mode='radio'"); 142 Recordset x = data.getRecordset(rsname); 143 if (x.getRecordCount()>0 && x.getRecordNumber()<0) 144 x.first(); 145 te.setRadioButton(control, String.valueOf(x.getValue(control))); 146 } 147 else if (mode.equals("clear")) 148 { 149 te.clearFieldMarkers(); 150 } 151 else 152 { 153 throw new Throwable ("Unkown print mode attribute in config.xml: " + _config.path); 154 } 155 156 } 157 158 } 159 160 } 161 162 169 public void print(GenericTransaction data) throws Throwable  170 { 171 } 172 173 181 public String onNewRow(Recordset rs, String rowTemplate) throws Throwable  182 { 183 184 190 191 String style1 = getContext().getInitParameter("def-color1"); 192 String style2 = getContext().getInitParameter("def-color2"); 193 String currentStyle=""; 194 195 if (rowColor==0) 196 { 197 rowColor=1; 198 currentStyle = style1; 199 } 200 else 201 { 202 rowColor=0; 203 currentStyle = style2; 204 } 205 206 rowTemplate = StringUtil.replace(rowTemplate, "${fld:_rowStyle}", currentStyle); 207 208 return rowTemplate; 209 210 } 211 212 218 protected void resetRowColor() 219 { 220 this.rowColor = 0; 221 } 222 223 } 224
| Popular Tags
|