Changeset 60e85e2fcb6975011b9f339476ac4aa9f427b5ba
- Timestamp:
- 01/28/07 13:03:34
(2 years ago)
- Author:
- Christopher Jung <bktheg@web.de>
- git-committer:
- Christopher Jung <bktheg@web.de> 1169985814 +0100
- git-parent:
[ca2809a16e4654a73ac73bb9e83b50057c84c221]
- git-author:
- Christopher Jung <bktheg@web.de> 1169985814 +0100
- Message:
Kommentare ergaenzt sowie Warnungen gefixt
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rca46c31 |
r60e85e2 |
|
| 43 | 43 | */ |
|---|
| 44 | 44 | public abstract class DSGenerator extends Generator { |
|---|
| | 45 | /** |
|---|
| | 46 | * Die verschiedenen Aufrufarten |
|---|
| | 47 | * |
|---|
| | 48 | */ |
|---|
| 45 | 49 | public enum ActionType { |
|---|
| | 50 | /** |
|---|
| | 51 | * Eine normale HTTP-Request mit HTML-Anwort |
|---|
| | 52 | */ |
|---|
| 46 | 53 | DEFAULT("Action"), |
|---|
| | 54 | /** |
|---|
| | 55 | * Eine Ajax-Request |
|---|
| | 56 | */ |
|---|
| 47 | 57 | AJAX("AjaxAct"); |
|---|
| 48 | 58 | |
|---|
| … | … | |
| 53 | 63 | } |
|---|
| 54 | 64 | |
|---|
| | 65 | /** |
|---|
| | 66 | * Gibt den Postfix der Aktionsmethoden zurueck |
|---|
| | 67 | * @return Der Postfix der Aktionsmethoden |
|---|
| | 68 | */ |
|---|
| 55 | 69 | public String getActionExt() { |
|---|
| 56 | 70 | return type; |
|---|
| … | … | |
| 59 | 73 | |
|---|
| 60 | 74 | protected abstract class FWOutputHelper { |
|---|
| | 75 | /** |
|---|
| | 76 | * Gibt den Header aus |
|---|
| | 77 | * |
|---|
| | 78 | */ |
|---|
| 61 | 79 | public abstract void printHeader(); |
|---|
| | 80 | /** |
|---|
| | 81 | * Gibt den Footer aus |
|---|
| | 82 | * |
|---|
| | 83 | */ |
|---|
| 62 | 84 | public abstract void printFooter(); |
|---|
| | 85 | /** |
|---|
| | 86 | * Gibt die Fehlerliste aus |
|---|
| | 87 | * |
|---|
| | 88 | */ |
|---|
| 63 | 89 | public abstract void printErrorList(); |
|---|
| 64 | 90 | } |
|---|
| … | … | |
| 67 | 93 | @Override |
|---|
| 68 | 94 | public void printHeader() { |
|---|
| 69 | | if( !getParameter("_style").equals("xml") ) { |
|---|
| | 95 | if( !getString("_style").equals("xml") ) { |
|---|
| 70 | 96 | StringBuffer sb = getResponse().getContent(); |
|---|
| 71 | 97 | String url = Configuration.getSetting("URL")+"/"; |
|---|
| … | … | |
| 115 | 141 | @Override |
|---|
| 116 | 142 | public void printFooter() { |
|---|
| 117 | | if( !template.equals("") ) { |
|---|
| 118 | | getTemplateEngine().parse( "OUT", masterTemplateID ); |
|---|
| | 143 | if( getTemplateID().length() > 0 ) { |
|---|
| | 144 | getTemplateEngine().parse( "OUT", getTemplateID() ); |
|---|
| 119 | 145 | |
|---|
| 120 | 146 | getTemplateEngine().p("OUT"); |
|---|
| 121 | 147 | } |
|---|
| 122 | | if( !getParameter("_style").equals("xml") ) { |
|---|
| | 148 | if( !getString("_style").equals("xml") ) { |
|---|
| 123 | 149 | StringBuffer sb = getResponse().getContent(); |
|---|
| 124 | 150 | if( !getDisableDebugOutput() ) { |
|---|
| … | … | |
| 178 | 204 | private FWOutputHelper actionTypeHandler; |
|---|
| 179 | 205 | |
|---|
| 180 | | private String template; |
|---|
| 181 | 206 | private TemplateEngine templateEngine; |
|---|
| 182 | 207 | private String masterTemplateID; |
|---|
| 183 | | |
|---|
| 184 | | private boolean noActionBlocking; |
|---|
| 185 | | private boolean updateLastAction; |
|---|
| 186 | 208 | |
|---|
| 187 | 209 | private boolean disableDefaultCSS; |
|---|
| … | … | |
| 196 | 218 | private List<String> preloadUserValues; |
|---|
| 197 | 219 | |
|---|
| 198 | | |
|---|
| | 220 | /** |
|---|
| | 221 | * Konstruktor |
|---|
| | 222 | * @param context Der Kontext |
|---|
| | 223 | */ |
|---|
| 199 | 224 | public DSGenerator(Context context) { |
|---|
| 200 | 225 | super(context); |
|---|
| 201 | 226 | |
|---|
| 202 | | setDisableActionBlocking(false); |
|---|
| 203 | | |
|---|
| 204 | 227 | parameter = new HashMap<String,Object>(); |
|---|
| 205 | 228 | subParameter = ""; |
|---|
| … | … | |
| 222 | 245 | preloadUserValues.add("id"); |
|---|
| 223 | 246 | |
|---|
| 224 | | template = ""; |
|---|
| 225 | 247 | templateEngine = null; |
|---|
| 226 | 248 | masterTemplateID = ""; |
|---|
| 227 | | |
|---|
| 228 | | updateLastAction = true; |
|---|
| | 249 | |
|---|
| 229 | 250 | setActionType(ActionType.DEFAULT); |
|---|
| 230 | 251 | |
|---|
| … | … | |
| 242 | 263 | this.browser = browser; |
|---|
| 243 | 264 | } |
|---|
| 244 | | |
|---|
| 245 | | @Deprecated |
|---|
| 246 | | protected void requireUserProperty( String value ) { |
|---|
| 247 | | /*if( !preloadUserValues.contains(value) ) { |
|---|
| 248 | | preloadUserValues.add(value); |
|---|
| 249 | | }*/ |
|---|
| 250 | | } |
|---|
| 251 | | |
|---|
| 252 | | @Deprecated |
|---|
| 253 | | protected void requireUserProperty( String ... values ) { |
|---|
| 254 | | for( String value : values ) { |
|---|
| 255 | | requireUserProperty(value); |
|---|
| 256 | | } |
|---|
| 257 | | } |
|---|
| 258 | | |
|---|
| | 265 | |
|---|
| | 266 | /** |
|---|
| | 267 | * Gibt den aktiven User zurueck. Falls kein User eingeloggt ist |
|---|
| | 268 | * wird <code>null</code> zurueckgegeben |
|---|
| | 269 | * @return Der User oder <code>null</code> |
|---|
| | 270 | */ |
|---|
| 259 | 271 | public User getUser() { |
|---|
| 260 | 272 | return getActiveUser(); |
|---|
| 261 | 273 | } |
|---|
| 262 | 274 | |
|---|
| 263 | | public Object getParameter( String parameter ) { |
|---|
| | 275 | private Object getParameter( String parameter ) { |
|---|
| 264 | 276 | if( subParameter.equals("") ) { |
|---|
| 265 | 277 | return this.parameter.get(parameter); |
|---|
| … | … | |
| 355 | 367 | } |
|---|
| 356 | 368 | |
|---|
| 357 | | public void parameterArray( String parameter, String[] subparams, String[] types ) { |
|---|
| 358 | | HashMap<String,Object> map = new HashMap<String,Object>(); |
|---|
| 359 | | |
|---|
| 360 | | for( int i=0; i < subparams.length; i++ ) { |
|---|
| 361 | | if( "number".equals(types[i]) ) { |
|---|
| 362 | | String val = getRequest().getParameter(parameter+"["+subparams[i]+"]"); |
|---|
| 363 | | if( val != null ) { |
|---|
| 364 | | try { |
|---|
| 365 | | map.put(subparams[i], Common.getNumberFormat().parse(val)); |
|---|
| 366 | | } |
|---|
| 367 | | catch( ParseException e ) { |
|---|
| 368 | | addError("Parameter "+parameter+"["+subparams[i]+"] ist keine gültige Zahl"); |
|---|
| 369 | | map.put(subparams[i], 0d); |
|---|
| 370 | | } |
|---|
| 371 | | } |
|---|
| 372 | | else { |
|---|
| 373 | | map.put(subparams[i], 0d); |
|---|
| 374 | | } |
|---|
| 375 | | } |
|---|
| 376 | | else if( "string".equals(types[i]) ) { |
|---|
| 377 | | map.put(subparams[i], getRequest().getParameter(parameter+"["+subparams[i])+"]"); |
|---|
| 378 | | } |
|---|
| 379 | | } |
|---|
| 380 | | this.parameter.put(parameter, map); |
|---|
| 381 | | } |
|---|
| 382 | | |
|---|
| 383 | 369 | private void createTemplateEngine() { |
|---|
| 384 | 370 | if( templateEngine != null ) { |
|---|
| … | … | |
| 435 | 421 | */ |
|---|
| 436 | 422 | public void setTemplate( String file ) { |
|---|
| 437 | | if( !file.equals("") ) { |
|---|
| 438 | | template = file; |
|---|
| 439 | | |
|---|
| | 423 | if( !file.equals("") ) { |
|---|
| 440 | 424 | if( templateEngine == null ) { |
|---|
| 441 | 425 | createTemplateEngine(); |
|---|
| … | … | |
| 452 | 436 | if( !templateEngine.set_file( masterTemplateID, file ) ) { |
|---|
| 453 | 437 | masterTemplateID = ""; |
|---|
| 454 | | template = ""; |
|---|
| 455 | 438 | } |
|---|
| 456 | 439 | } |
|---|
| 457 | 440 | else { |
|---|
| 458 | | template = ""; |
|---|
| 459 | 441 | masterTemplateID = ""; |
|---|
| 460 | 442 | } |
|---|
| … | … | |
| 486 | 468 | } |
|---|
| 487 | 469 | |
|---|
| | 470 | /** |
|---|
| | 471 | * Fueht die angegebene Aktion aus |
|---|
| | 472 | * @param action Der Name der Aktion |
|---|
| | 473 | * @param actionType Der Typ der Aktion |
|---|
| | 474 | */ |
|---|
| 488 | 475 | public void handleAction( String action, ActionType actionType ) { |
|---|
| 489 | 476 | setActionType( actionType ); |
|---|
| … | … | |
| 499 | 486 | |
|---|
| 500 | 487 | if( getErrorList().length != 0 ) { |
|---|
| 501 | | template = ""; |
|---|
| 502 | | |
|---|
| | 488 | masterTemplateID = ""; |
|---|
| 503 | 489 | actionTypeHandler.printHeader(); |
|---|
| 504 | 490 | |
|---|
| … | … | |
| 552 | 538 | } |
|---|
| 553 | 539 | } |
|---|
| 554 | | else { |
|---|
| 555 | | template = ""; |
|---|
| | 540 | else { |
|---|
| | 541 | masterTemplateID = ""; |
|---|
| 556 | 542 | } |
|---|
| 557 | 543 | parseSubParameter(""); |
|---|
| … | … | |
| 579 | 565 | } |
|---|
| 580 | 566 | |
|---|
| | 567 | /** |
|---|
| | 568 | * Gibt an, ob fuer die Ausfuehrung einer Aktion eine gueltige Session |
|---|
| | 569 | * erforderlich ist (also, dass der Benutzer angemeldet ist) |
|---|
| | 570 | * @param value <code>true</code>, falls eine gueltige Session erforderlich ist |
|---|
| | 571 | */ |
|---|
| 581 | 572 | public void requireValidSession( boolean value ) { |
|---|
| 582 | 573 | requireValidSession = value; |
|---|
| 583 | 574 | } |
|---|
| 584 | 575 | |
|---|
| | 576 | /** |
|---|
| | 577 | * (De)aktiviert die Debug-Ausgaben |
|---|
| | 578 | * @param value <code>true</code> zur Deaktivierung |
|---|
| | 579 | */ |
|---|
| 585 | 580 | public void setDisableDebugOutput( boolean value ) { |
|---|
| 586 | 581 | disableDebugOutput = value; |
|---|
| 587 | 582 | } |
|---|
| 588 | 583 | |
|---|
| | 584 | /** |
|---|
| | 585 | * Gibt zurueck, ob die Debugausgabe deaktiviert ist |
|---|
| | 586 | * @return <code>true</code>, falls sie deaktiviert ist |
|---|
| | 587 | */ |
|---|
| 589 | 588 | public boolean getDisableDebugOutput() { |
|---|
| 590 | 589 | return disableDebugOutput; |
|---|
| 591 | 590 | } |
|---|
| 592 | 591 | |
|---|
| | 592 | /** |
|---|
| | 593 | * (De)aktiviert die Default-CSS-Stile |
|---|
| | 594 | * @param value <code>true</code> zur Deaktivierung |
|---|
| | 595 | */ |
|---|
| 593 | 596 | public void setDisableDefaultCSS( boolean value ) { |
|---|
| 594 | 597 | disableDefaultCSS = value; |
|---|
| 595 | 598 | } |
|---|
| 596 | 599 | |
|---|
| | 600 | /** |
|---|
| | 601 | * Gibt zurueck, ob die Default-CSS-Stile deaktiviert sind |
|---|
| | 602 | * @return <code>true</code>, falls sie deaktiviert sind |
|---|
| | 603 | */ |
|---|
| 597 | 604 | public boolean getDisableDefaultCSS() { |
|---|
| 598 | 605 | return disableDefaultCSS; |
|---|
| 599 | 606 | } |
|---|
| 600 | 607 | |
|---|
| 601 | | @Deprecated |
|---|
| 602 | | public void setDisableActionBlocking( boolean value ) { |
|---|
| 603 | | noActionBlocking = value; |
|---|
| 604 | | } |
|---|
| 605 | | |
|---|
| 606 | | @Deprecated |
|---|
| 607 | | public void setDisableLastActionUpdate( boolean value ) { |
|---|
| 608 | | updateLastAction = !value; |
|---|
| 609 | | } |
|---|
| 610 | | |
|---|
| | 608 | /** |
|---|
| | 609 | * Gibt den Startzeitpunkt der Verarbeitung zurueck |
|---|
| | 610 | * @return Der Startzeitpunkt der Verarbeitung |
|---|
| | 611 | */ |
|---|
| 611 | 612 | public long getStartTime() { |
|---|
| 612 | 613 | return startTime; |
|---|
| 613 | 614 | } |
|---|
| 614 | 615 | |
|---|
| | 616 | /** |
|---|
| | 617 | * Gibt das <code>onLoad</code>-Attribut des HTML-Body-Tags zurueck |
|---|
| | 618 | * @return Das <code>onLoad</code>-Attribut |
|---|
| | 619 | */ |
|---|
| 615 | 620 | public String getOnLoadText() { |
|---|
| 616 | 621 | if( onLoadFunctions.size() > 0 ) { |
|---|
| … | … | |
| 625 | 630 | } |
|---|
| 626 | 631 | |
|---|
| | 632 | /** |
|---|
| | 633 | * Fuegt eine Javascript-Funktion zum <code>onLoad</code>-Aufruf des Body-Tags hinzu |
|---|
| | 634 | * @param func Der Javascript-Funktionsaufruf |
|---|
| | 635 | */ |
|---|
| 627 | 636 | public void addOnLoadFunction( String func ) { |
|---|
| 628 | 637 | onLoadFunctions.add(func); |
|---|
| 629 | 638 | } |
|---|
| 630 | 639 | |
|---|
| | 640 | /** |
|---|
| | 641 | * Gibt weitere HTML-Body-Tag-Attribute zurueck |
|---|
| | 642 | * @return Weitere HTML-Body-Tag-Attribute |
|---|
| | 643 | * @see #getOnLoadText() |
|---|
| | 644 | */ |
|---|
| 631 | 645 | public String getBodyParameters() { |
|---|
| 632 | 646 | StringBuilder text = new StringBuilder(); |
|---|
| … | … | |
| 641 | 655 | } |
|---|
| 642 | 656 | |
|---|
| | 657 | /** |
|---|
| | 658 | * Fuegt ein weiteres HTML-Body-Tag-Attribut hinzu. |
|---|
| | 659 | * Sollte das Attribut bereits gesetzt seit, so wird es |
|---|
| | 660 | * ueberschrieben |
|---|
| | 661 | * @param parameter Der Name des Attributs |
|---|
| | 662 | * @param value Der Wert |
|---|
| | 663 | */ |
|---|
| 643 | 664 | public void addBodyParameter( String parameter, String value ) { |
|---|
| 644 | 665 | bodyParameters.put(parameter,value); |
|---|
| 645 | 666 | } |
|---|
| 646 | 667 | |
|---|
| | 668 | /** |
|---|
| | 669 | * Gibt den Identifikationsstring des Browsers des Spielers zurueck |
|---|
| | 670 | * @return Der Identifikationsstring des Browsers |
|---|
| | 671 | */ |
|---|
| 647 | 672 | public String getBrowser() { |
|---|
| 648 | 673 | return browser; |
|---|
| … | … | |
| 662 | 687 | protected abstract boolean validateAndPrepare(String action); |
|---|
| 663 | 688 | |
|---|
| | 689 | /** |
|---|
| | 690 | * Die Default-Ajax-Aktion |
|---|
| | 691 | * |
|---|
| | 692 | */ |
|---|
| 664 | 693 | public void defaultAjaxAct() { |
|---|
| 665 | 694 | defaultAction(); |
|---|
| 666 | 695 | } |
|---|
| 667 | 696 | |
|---|
| | 697 | /** |
|---|
| | 698 | * Die Default-HTML-Aktion |
|---|
| | 699 | * |
|---|
| | 700 | */ |
|---|
| 668 | 701 | public void defaultAction() { |
|---|
| 669 | 702 | getResponse().getContent().append("DEFAULT"); |
|---|