001: /**
002: * Title: OpenUSS - Open Source University Support System
003: * My Piggy Bank Example
004: * Description: Enhydra Presentation Object
005: * Copyright: Copyright (c) 2003 by B. Lofi Dewanto, T. Menzel
006: * Company: University of Muenster, HTWK Leipzig
007: * @author B. Lofi Dewanto, T. Menzel
008: * @version 1.1
009: */package net.sourceforge.ejosa.piggybank.presentation.enhydra;
010:
011: import com.lutris.appserver.server.httpPresentation.*;
012:
013: //import com.lutris.xml.xmlc.*;
014:
015: import java.io.*;
016:
017: import java.util.*;
018:
019: import net.sourceforge.ejosa.piggybank.spec.*;
020: import net.sourceforge.ejosa.piggybank.spec.business.*;
021: import net.sourceforge.ejosa.piggybank.spec.system.*;
022:
023: import org.openuss.presentation.enhydra.framework.*;
024:
025: import org.openuss.utility.*;
026:
027: import org.w3c.dom.*;
028: import org.w3c.dom.html.*;
029:
030: /**
031: * Smash Page
032: *
033: * @author B. Lofi Dewanto, T. Menzel
034: * @version 1.1
035: */
036: public class SmashPage extends FoundationPO {
037: // Page
038: private SmashHTML mPage;
039:
040: /**
041: * Default event. Just show the page.
042: */
043: public String handleDefault() throws HttpPresentationException {
044: // Create the page
045: mPage = (SmashHTML) this .getComms().xmlcFactory
046: .create(SmashHTML.class);
047:
048: // Look for an error
049: String errorMsg = this .getSessionData()
050: .getAndClearUserMessage();
051:
052: if (errorMsg == null) {
053: // No error
054: mPage.getElementTStatusbar().getParentNode().removeChild(
055: mPage.getElementTStatusbar());
056: } else {
057: // Error, put it in the statusbar
058: mPage.setTextTStatusbar(errorMsg);
059: }
060:
061: // Work with the page
062: return showLayout(mPage);
063: }
064:
065: /**
066: * Superclass method override.
067: */
068: public boolean loggedInUserRequired() {
069: // This page doesn't need a login
070: return false;
071: }
072:
073: /**
074: * Show the page, override the method.
075: */
076: public String showLayout(Object page) throws BasePOException {
077: // Format the statusbar and treebar
078: super .showLayout(mPage);
079:
080: // Show something
081: showSmash();
082:
083: // Return the result
084: return mPage.toDocument();
085: }
086:
087: /**
088: * Shows smash.
089: */
090: private void showSmash() throws FoundationPOException {
091: int cur = 0;
092: int sum = 0;
093:
094: // This method shows something
095: HTMLTableRowElement templateRow = mPage.getElementTemplateRow();
096: HTMLElement entryTemplate = mPage.getElementTEntry();
097: HTMLElement dateTemplate = mPage.getElementTDate();
098: HTMLElement amountTemplate = mPage.getElementTAmount();
099: HTMLElement balanceTemplate = mPage.getElementTBalance();
100: HTMLElement currencyTemplate = mPage.getElementTCurrency();
101:
102: templateRow.removeAttribute("id");
103: entryTemplate.removeAttribute("id");
104: dateTemplate.removeAttribute("id");
105: amountTemplate.removeAttribute("id");
106: balanceTemplate.removeAttribute("id");
107: currencyTemplate.removeAttribute("id");
108:
109: Node table = templateRow.getParentNode();
110:
111: // Business access
112: // !!!Only access to the specification!!!
113: try {
114: // Get the workflow object
115: CoinManager coinManager = CoinManagerFactory
116: .createCoinManager("net.sourceforge.ejosa.piggybank.business.session.CoinManagerImpl");
117:
118: //System.out.println("Coin: create a coin helper with the home interface!");
119: Vector coinList = coinManager.findAllCoins();
120: Coin fc;
121: for (int i = 0; i < coinList.size(); i++) {
122: fc = (Coin) coinList.elementAt(i);
123: //System.out.println("Coin number: " + i + " with coin amount " + fc.getAmount());
124: mPage.setTextVEntry("" + (i + 1));
125: mPage.setTextVDate(fc.getDate());
126: cur = Integer.parseInt(fc.getAmount());
127: sum = sum + cur;
128: mPage.setTextVAmount("" + cur);
129: mPage.setTextVBalance("" + sum);
130: mPage.setTextVCurrency("Dollar");
131: table.appendChild(templateRow.cloneNode(true));
132:
133: coinManager.removeCoin(fc.getId());
134: }
135:
136: //System.out.println(coinList.size() + " coins found in the piggy bank!");
137: } catch (Exception ex) {
138: System.out.println("EJB Error: " + ex);
139: ex.printStackTrace();
140: }
141:
142: table.removeChild(templateRow);
143:
144: mPage.setTextVCash("" + sum);
145: }
146: }
|