1 22 package org.cofax.taglibs; 23 24 import javax.servlet.*; 25 import javax.servlet.jsp.*; 26 import javax.servlet.jsp.tagext.*; 27 import java.util.*; 28 import org.cofax.*; 29 30 61 public class PackageTag extends TagSupport { 62 63 private String action; 65 66 private String nameSpace; 68 69 private boolean addToGlossary = false; 71 72 private Glossary myGlossary = new Glossary(); 74 75 private List packageData; 77 78 private int currentRow = 0; 80 81 private int totalRows = 0; 83 84 private int startRow = 1; 86 87 private int numRows = 0; 88 89 private boolean showPackageTag = false; 91 92 private String noConnection = "Can't get DataStore Connection for this packageTag = "; 93 94 private String noPackageTag = "Store Procedure does not exist for this packageTag = "; 95 96 private HashMap rowData; 97 98 private boolean hasRowData; 99 100 private boolean outOfBound = false; 102 private Iterator rows; 103 104 private int showRows = 0; 105 106 private boolean noRows = false; 107 108 ServletRequest req; 109 110 JspWriter out; 111 112 CofaxPage cofaxPage; 113 114 117 public boolean getHasRowData() { 118 return hasRowData; 119 } 120 121 124 public void setShowPackageTag(String v) { 125 if (v.equalsIgnoreCase("true")) { 126 this.showPackageTag = true; 127 } else { 128 this.showPackageTag = false; 129 } 130 } 131 132 135 public String getShowPackageTag() { 136 if (showPackageTag) { 137 return "true"; 138 } else { 139 return "false"; 140 } 141 } 142 143 146 public void setAddToGlossary(String v) { 147 if (v.equalsIgnoreCase("true")) { 148 this.addToGlossary = true; 149 } else { 150 this.addToGlossary = false; 151 } 152 } 153 154 157 public String getAddToGlossary() { 158 if (addToGlossary) { 159 return "true"; 160 } else { 161 return "false"; 162 } 163 } 164 165 168 public void setNameSpace(String nameSpace) { 169 if (!nameSpace.equals("")) { 170 this.nameSpace = nameSpace; 171 } else { 172 this.nameSpace = action; 173 } 174 } 175 176 179 public String getNameSpace() { 180 return (nameSpace); 181 } 182 183 186 public void setAction(String action) { 187 if (!action.equals("")) { 188 this.action = action; 189 } else { 190 this.action = ""; 191 } 192 } 193 194 197 public String getAction() { 198 return (action); 199 } 200 201 204 public void setStartrow(String startRow) { 205 try { 206 this.startRow = Integer.parseInt(startRow); 207 if (this.startRow < 1) { 208 this.startRow = 1; 209 } 210 } catch (NumberFormatException nfe) { 211 this.startRow = 1; 212 } 213 } 214 215 219 public int getStartRow() { 220 return (startRow); 221 } 222 223 226 public void setNumberrows(String numberRows) { 227 228 try { 229 this.numRows = Integer.parseInt(numberRows); 230 if (this.numRows < 1) { 231 this.numRows = 0; } 233 234 } catch (NumberFormatException nfe) { 235 this.numRows = 0; } 237 } 238 239 242 public int getNumberRows() { 243 return (numRows); 244 } 245 246 249 public void setGlossaryValue(String key, String value) { 250 myGlossary.putString(key, value); 251 } 252 253 256 public String getGlossaryValue(String key) { 257 return myGlossary.getString(key); 258 } 259 260 263 public int getTotalRows() { 264 return totalRows; 265 } 266 267 270 public void setTotalRows(int totalRows) { 271 this.totalRows = totalRows; 272 } 273 274 277 public int getCurrentRow() { 278 return currentRow; 279 } 280 281 284 public boolean hasNext() { 285 return rows.hasNext(); 286 } 287 288 291 public boolean getNoRows() { 292 return noRows; 293 } 294 295 298 public void nextRow() { 299 300 if (outOfBound) { hasRowData = false; 302 } else { 303 304 if (currentRow >= startRow) { 305 showRows++; } 307 308 if ((rows.hasNext()) && (showRows <= numRows)) { 309 rowData = (HashMap) rows.next(); 310 hasRowData = true; 311 currentRow++; 312 } else { 313 hasRowData = false; 314 } 315 } 316 } 318 322 public void execute() throws JspException { 323 324 DataStore db = null; 325 String tagDefinition = null; 326 try { 327 328 db = cofaxPage.getDataStore(); if (db == null) { 330 printMessage(noConnection + nameSpace); 331 } else { 332 333 tagDefinition = db.getPackageTag(action, myGlossary.getKeyValues(), cofaxPage.getServingPage(), cofaxPage.getServingClient()); 334 335 if (tagDefinition == null || tagDefinition.equals("")) { 336 printMessage(noPackageTag + "action is " + action + ", nameSpace is " + nameSpace); 337 338 } else { 339 packageData = db.getPackageData(getNameSpace(), tagDefinition, cofaxPage.getServingPage(), cofaxPage.getServingClient()); 340 341 } 342 } 343 344 } catch (Exception e) { 345 cofaxPage.setErrorMsg("Connection failed in PackageTag = " + nameSpace + " /n Error = " + e.getMessage()); 346 } finally { 347 348 cofaxPage.disconnectDataStore(); } 350 351 if (showPackageTag) { 353 cofaxPage.putGlossaryValue(getNameSpace() + ":packageTagDefinition", tagDefinition); 354 cofaxPage.putGlossaryValue(getNameSpace() + ":packageTagRowsReturned", packageData.size() + ""); 355 cofaxPage.putGlossaryValue(getNameSpace() + ":packageTagErrorsReturned", db.getLastError()); 356 } 357 358 if (packageData == null || (packageData.size() == 0)) { 359 noRows = true; 360 setTotalRows(totalRows); 361 cofaxPage.putGlossaryValue(getNameSpace() + ":TOTAL_ROWS", "0"); 362 } else { 363 364 totalRows = packageData.size(); 365 cofaxPage.putGlossaryValue(getNameSpace() + ":TOTAL_ROWS", packageData.size() + ""); 367 368 rows = packageData.iterator(); 369 370 if ((totalRows - startRow) > 0) { if (numRows == 0) { 373 numRows = totalRows; } 375 } else if ((totalRows - startRow) == 0) { numRows = 1; 377 } else if ((totalRows - startRow) < 0) { numRows = 0; 379 outOfBound = true; 380 } 381 382 if (!outOfBound) { 383 noRows = false; 384 385 currentRow = 1; 386 while ((currentRow <= startRow) && (!outOfBound)) { 387 if (rows.hasNext()) { 388 nextRow(); 389 } 390 } 391 392 if (addToGlossary) { 394 HashMap oneRow = new HashMap(rowData); 395 cofaxPage.addToGlossary(oneRow); 396 397 } 398 399 } else { 400 401 noRows = true; 402 403 } 404 405 } 407 } 409 412 public boolean fieldExists(String name) { 413 414 if (packageData != null && totalRows > 0) { 415 417 if (rowData.containsKey(name)) { 418 return true; 419 } else { 420 return false; 421 } 422 } else { 423 return false; 424 } 425 } 426 427 430 public HashMap getRowData() { 431 return rowData; 432 } 433 434 437 public String getField(String name) { 438 439 if (packageData != null && totalRows > 0) { 440 442 if (rowData.containsKey(name)) { 443 String data; 444 if (rowData.get(name) != null) { 445 data = rowData.get(name).toString(); 446 } else { 447 data = "null"; 448 } 449 return data; 450 } else { 451 return "NA"; 452 } 453 } else { 454 return "NA"; 455 } 456 } 457 458 461 public void printMessage(String message) throws JspException { 462 463 try { 464 out.print(message); 465 } catch (Exception ex) { 466 throw new JspException("IO problems printMessage() " + ex); 467 } 468 return; 469 } 470 471 474 public int doStartTag() throws JspException { 475 476 req = pageContext.getRequest(); 477 out = pageContext.getOut(); 478 cofaxPage = (CofaxPage) req.getAttribute("cofaxPage"); 479 480 myGlossary.setKeyValues(new HashMap(cofaxPage.getGlossary().getKeyValues())); 481 482 if ((nameSpace == null) || (nameSpace.equals(""))) { 483 nameSpace = action; 484 setNameSpace(action); 485 } 486 487 return EVAL_BODY_INCLUDE; 488 489 } 491 494 public int doEndTag() { 495 currentRow = 0; 497 totalRows = 0; 498 startRow = 1; 499 numRows = 0; 500 showRows = 0; 501 502 rowData = null; 503 packageData = null; 504 505 return EVAL_PAGE; 506 } 507 508 } 510 | Popular Tags |