001: package org.enhydra.dm.presentation;
002:
003: import java.util.Enumeration;
004: import java.util.Properties;
005:
006: import javax.naming.Context;
007: import javax.naming.InitialContext;
008: import javax.transaction.UserTransaction;
009:
010: import org.enhydra.dm.EnhydraDM;
011: import org.enhydra.dm.api.DocumentManager;
012: import org.enhydra.dm.api.DocumentStore;
013: import org.enhydra.dm.api.exceptions.BaseException;
014: import org.enhydra.xml.xmlc.html.HTMLObjectImpl;
015: import org.w3c.dom.Element;
016: import org.w3c.dom.html.HTMLInputElement;
017:
018: import com.lutris.appserver.server.httpPresentation.HttpPresentation;
019: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
020:
021: public abstract class Base implements HttpPresentation {
022:
023: /**
024: * User transaction
025: */
026: protected UserTransaction transaction = null;
027:
028: /**
029: * Document Manager
030: */
031: protected DocumentManager documentManager = null;
032:
033: /**
034: * Document Store
035: */
036: protected DocumentStore documentStore = null;
037:
038: public abstract void run(HttpPresentationComms comms)
039: throws Exception;
040:
041: /**
042: * Method initializes DB transation instance
043: */
044: protected void initTransaction() throws Exception {
045: Context ctx = new InitialContext();
046: transaction = (UserTransaction) ctx
047: .lookup(EnhydraDM.userTransactionJNDIPath);
048: if (transaction != null) {
049: transaction.begin();
050: }
051: }
052:
053: /**
054: * Method insures User presence
055: */
056: protected String getUser(HttpPresentationComms comms)
057: throws Exception {
058: String user = comms.request.getRemoteUser();
059: return user;
060: }
061:
062: /**
063: * Method commits DB transation instance
064: */
065: protected void commitTransaction() throws Exception {
066: if (transaction != null) {
067: transaction.commit();
068: }
069:
070: }
071:
072: /**
073: * Method rollback's DB transation instance
074: */
075: protected void rollbackTransaction() throws Exception {
076: if (transaction != null) {
077: transaction.rollback();
078: }
079: }
080:
081: /**
082: * Method sets lasbels names and button captions on proceeded page.
083: * It read label names fron proceeded properties object.
084: *
085: * @param prop - properties object with label names and button captions
086: * @param objectHTML - HTML page
087: * @throws Exception
088: */
089: protected void setI18n(Properties prop, HTMLObjectImpl objectHTML)
090: throws Exception {
091: String key = null;
092: String val = null;
093: Element element = null;
094:
095: Enumeration keys = prop.keys();
096:
097: if (prop != null) {
098: while (keys.hasMoreElements()) {
099: key = (String) keys.nextElement();
100: val = prop.getProperty(key);
101: element = objectHTML.getElementById(key);
102: if (val != null && element != null) {
103: if (element instanceof HTMLInputElement) {
104: element.setAttribute("value", val);
105: } else {
106: element.setTextContent(val);
107: }
108: }
109: }
110: } else {
111: throw new BaseException("Properties object is empty!");
112: }
113: }
114: }
|