[cvs] expresso commit by lhamel: add convenience for getting dbname
from
JCorporate Ltd
jcorp at jcorporate.com
Thu Dec 9 01:44:20 UTC 2004
Log Message:
-----------
add convenience for getting dbname from RequestRegistry
Modified Files:
--------------
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc:
EMailSender.java
Revision Data
-------------
Index: EMailSender.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java -u -r1.17 -r1.18
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/misc/EMailSender.java
@@ -70,6 +70,7 @@
package com.jcorporate.expresso.core.misc;
import com.jcorporate.expresso.core.db.DBException;
+import com.jcorporate.expresso.core.registry.RequestRegistry;
import com.jcorporate.expresso.services.dbobj.Setup;
import org.apache.log4j.Logger;
@@ -129,8 +130,7 @@
* EMailSender constructor
*/
public EMailSender() {
- super();
- } /* EMailSender() */
+ }
/**
* @return
@@ -153,7 +153,7 @@
StringUtil.notNull(user) + "'\n" + "Subject '" +
StringUtil.notNull(subject) + "'\n" + "Message '" +
StringUtil.notNull(text) + "'\n" + "Db/Context '" +
- StringUtil.notNull(dbName) + "'\n" + "With " + aCount +
+ StringUtil.notNull(getDataContext()) + "'\n" + "With " + aCount +
" file attachments and " + dsACount + " data source attachments.");
} /* messageDetails() */
@@ -238,18 +238,24 @@
* or "default" if not set.
*
* @return the data context
+ * @deprecated 12/2004, v5.6; use getDataContext instead
*/
public String getDBName() {
- String db = dbName;
+ return getDataContext();
+ }
- if ((db == null) || (db.trim().equals(""))) {
- db = "default";
+ /**
+ * This method returns the name of the DB context, either preset by the caller,
+ * or "default" if not set.
+ *
+ * @return the data context
+ */
+ public String getDataContext() {
+ if ((dbName == null) || (dbName.trim().equals(""))) {
+ dbName = RequestRegistry.getDataContext();
}
-
- dbName = db;
-
- return db;
- } /* getDBName() */
+ return dbName;
+ } /* getDataContext() */
/**
* This method returns the email address to be shown in the "From" header of the
@@ -265,7 +271,7 @@
try {
if (addr == null) {
- addr = Setup.getValueRequired(getDBName(), "MAILFrom");
+ addr = Setup.getValueRequired(getDataContext(), "MAILFrom");
}
} catch (DBException dex) {
log.error("DB exception getting MAILFrom:" + messageDetails(), dex);
@@ -293,7 +299,7 @@
try {
if (myHost.equals("")) {
- myHost = Setup.getValueRequired(getDBName(), "MAILServer");
+ myHost = Setup.getValueRequired(getDataContext(), "MAILServer");
}
} catch (DBException dex) {
log.error("DB exception getting MAILServer:" + messageDetails(),
@@ -318,14 +324,9 @@
*/
private String getSMTPPassword() {
String myPassword = password;
-
- try {
- if (myPassword == null) {
- myPassword = Setup.getValueRequired(getDBName(),
- "MAILPassword");
- }
- } catch (DBException dex) {
- myPassword = null;
+ if (myPassword == null) {
+ myPassword = Setup.getValueUnrequired(getDataContext(),
+ "MAILPassword");
}
password = myPassword;
@@ -345,7 +346,7 @@
try {
if (myUser.equals("")) {
- myUser = Setup.getValueRequired(getDBName(), "MAILUserName");
+ myUser = Setup.getValueRequired(getDataContext(), "MAILUserName");
}
} catch (DBException dex) {
myUser = null;
@@ -456,7 +457,7 @@
}
// Prints debug output to the console if "mailDebug=Y" in DB context
// properties file
- if (ConfigManager.getContext(getDBName()).mailDebug()) {
+ if (ConfigManager.getContext(getDataContext()).mailDebug()) {
session.setDebug(true);
}
} catch (Exception e) {
@@ -606,14 +607,24 @@
* This method sets the DB context name, used for looking up several Setup parameters
*
* @param newDBName String Name of DB context
+ * @deprecated 12/2004, v5.6; use setDataContext instead
*/
public void setDBName(String newDBName) {
+ setDataContext(newDBName);
+ } /* setDBName(String) */
+
+ /**
+ * This method sets the DB context name, used for looking up several Setup parameters
+ * Note: this class will use RequestRegistry context for db context value if none is set.
+ * @param newDBName String Name of DB context
+ */
+ public void setDataContext(String newDBName) {
dbName = StringUtil.notNull(newDBName);
if (dbName.equals("")) {
- dbName = "default";
+ dbName = "default"; // ?? leave null?
}
- } /* setDBName(String) */
+ }
/**
* This method sets the address to be used in the From header
@@ -634,26 +645,25 @@
}
/**
- * This method sets the address to be used in the From header
+ * This method sets the personal name to be used in the From header
*
- * @param from java.lang.String The from address
+ * @param personal The name
*/
public void setPersonal(String personal) {
this.personal = personal;
- } /* setFromAddress(String) */
+ }
/**
- * This method sets the address to be used in the From header
- *
- * @param from java.lang.String The from address
+ * This method gets the personal name to be used in the From header
+ * @return name; returns empty string if none found
*/
public String getPersonal() {
if (personal == null) {
- return new String("");
+ return "";
} else {
return this.personal;
}
- } /* setFromAddress(String) */
+ }
/**
More information about the cvs
mailing list