[Ils-source] r1484 - trunk/src/com/resolutions/ils
scribe at crosswire.org
scribe at crosswire.org
Wed Jul 13 03:57:11 MST 2016
Author: scribe
Date: 2016-07-13 03:57:10 -0700 (Wed, 13 Jul 2016)
New Revision: 1484
Modified:
trunk/src/com/resolutions/ils/Utils.java
Log:
updated formatting to make consistent
Modified: trunk/src/com/resolutions/ils/Utils.java
===================================================================
--- trunk/src/com/resolutions/ils/Utils.java 2016-07-13 10:45:45 UTC (rev 1483)
+++ trunk/src/com/resolutions/ils/Utils.java 2016-07-13 10:57:10 UTC (rev 1484)
@@ -27,44 +27,44 @@
static Logger logger = Logger.getLogger(Utils.class);
- public static Properties getSysConfig(ServletContext context, int companyID) {
- Properties sysConfig = null;
- File propName = new File(context.getRealPath("/WEB-INF/sysconfig."+companyID+".properties"));
- if (!propName.exists()) {
- propName = new File(context.getRealPath("/WEB-INF/sysconfig.properties"));
- }
- if (propName.exists()) {
- try {
- FileInputStream propFile = new FileInputStream(propName);
- Properties p = new Properties();
- p.load(propFile);
- propFile.close();
- sysConfig = p;
- } catch (Exception e) {}
- }
- if (sysConfig == null) {
- logger.error("*** sysconfig.properties NOT PRESENT ON THE SYSTEM!!! ***");
- sysConfig = new Properties();
- }
- return sysConfig;
+ public static Properties getSysConfig(ServletContext context, int companyID) {
+ Properties sysConfig = null;
+ File propName = new File(context.getRealPath("/WEB-INF/sysconfig."+companyID+".properties"));
+ if (!propName.exists()) {
+ propName = new File(context.getRealPath("/WEB-INF/sysconfig.properties"));
+ }
+ if (propName.exists()) {
+ try {
+ FileInputStream propFile = new FileInputStream(propName);
+ Properties p = new Properties();
+ p.load(propFile);
+ propFile.close();
+ sysConfig = p;
+ } catch (Exception e) {}
+ }
+ if (sysConfig == null) {
+ logger.error("*** sysconfig.properties NOT PRESENT ON THE SYSTEM!!! ***");
+ sysConfig = new Properties();
+ }
+ return sysConfig;
}
-
- public static Properties getSysConfig(HttpSession session) {
- ILSSession ilsSession = (ILSSession)session.getAttribute("ilsSession");
- String sysConfigKey = "sysConfig" + ((ilsSession != null) ? "." + ilsSession.getCompanyID() : "");
- Properties sysConfig = (Properties) session.getAttribute(sysConfigKey);
- if (sysConfig == null) {
- sysConfig = getSysConfig(session.getServletContext(), (ilsSession != null ? ilsSession.getCompanyID() : 1));
- if (sysConfig != null) {
- session.setAttribute(sysConfigKey, sysConfig);
- }
- }
- return sysConfig;
- }
-
- public static String replaceParams(String inString, HashMap values) {
- int i = 1;
- for (int offset = inString.indexOf('{', i); offset > -1; offset = inString.indexOf('{', i)) {
+
+ public static Properties getSysConfig(HttpSession session) {
+ ILSSession ilsSession = (ILSSession)session.getAttribute("ilsSession");
+ String sysConfigKey = "sysConfig" + ((ilsSession != null) ? "." + ilsSession.getCompanyID() : "");
+ Properties sysConfig = (Properties) session.getAttribute(sysConfigKey);
+ if (sysConfig == null) {
+ sysConfig = getSysConfig(session.getServletContext(), (ilsSession != null ? ilsSession.getCompanyID() : 1));
+ if (sysConfig != null) {
+ session.setAttribute(sysConfigKey, sysConfig);
+ }
+ }
+ return sysConfig;
+ }
+
+ public static String replaceParams(String inString, HashMap values) {
+ int i = 1;
+ for (int offset = inString.indexOf('{', i); offset > -1; offset = inString.indexOf('{', i)) {
int end = inString.indexOf('}', offset);
if (end > -1) {
String paramName = inString.substring(offset + 1, end);
@@ -74,30 +74,30 @@
}
i = offset + 1;
}
- return inString;
- }
+ return inString;
+ }
- public static String getCompanyFromConfig(HttpSession session, String hostName) {
- Properties companyConfig = (Properties) session.getAttribute("companyConfig");
- if (companyConfig == null) {
- companyConfig = new Properties();
- File propName = new File(session.getServletContext().getRealPath("/WEB-INF/companies.properties"));
- if (propName.exists()) {
- try {
- FileInputStream propFile = new FileInputStream(propName);
- companyConfig.load(propFile);
- propFile.close();
- } catch (Exception e) {}
- }
- session.setAttribute("companyConfig", companyConfig);
- }
+ public static String getCompanyFromConfig(HttpSession session, String hostName) {
+ Properties companyConfig = (Properties) session.getAttribute("companyConfig");
+ if (companyConfig == null) {
+ companyConfig = new Properties();
+ File propName = new File(session.getServletContext().getRealPath("/WEB-INF/companies.properties"));
+ if (propName.exists()) {
+ try {
+ FileInputStream propFile = new FileInputStream(propName);
+ companyConfig.load(propFile);
+ propFile.close();
+ } catch (Exception e) {}
+ }
+ session.setAttribute("companyConfig", companyConfig);
+ }
for (String name: companyConfig.stringPropertyNames()) {
if (hostName.contains(name)) {
return companyConfig.getProperty(name);
}
}
- return null;
- }
+ return null;
+ }
public static Company getCompany(HttpServletRequest request) {
String requestURL = request.getRequestURL().toString() + "?" + request.getQueryString();
@@ -112,22 +112,22 @@
return company;
}
- public static String getVersionString() {
- String version = "";
- try {
- InputStream vin = Utils.class.getResourceAsStream("/versions.properties");
- Properties versions = new Properties();
+ public static String getVersionString() {
+ String version = "";
+ try {
+ InputStream vin = Utils.class.getResourceAsStream("/versions.properties");
+ Properties versions = new Properties();
versions.load(vin);
version = versions.getProperty("LMS");
} catch (Exception e) {
logger.error("Problem looking up version information from file versions.properties", e);
}
- return version;
- }
-
- public static Date parseDate(String text, int daysMin, int daysMax) {
- Date val = null;
- SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
+ return version;
+ }
+
+ public static Date parseDate(String text, int daysMin, int daysMax) {
+ Date val = null;
+ SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_YEAR, -1 * daysMin);
@@ -137,167 +137,166 @@
Date maxDate = cal.getTime();
try {
val = df.parse(text);
- if ((val != null) && (daysMin != -1) && (val.getTime() < minDate.getTime())) {
+ if ((val != null) && (daysMin != -1) && (val.getTime() < minDate.getTime())) {
val = null;
- }
- if ((val != null) && (daysMax != -1) && (val.getTime() > maxDate.getTime())) {
+ }
+ if ((val != null) && (daysMax != -1) && (val.getTime() > maxDate.getTime())) {
val = null;
- }
+ }
}
catch (Exception e) {}
- return val;
+ return val;
}
-
- private static String getSystemProperty(String key, String def) {
- try {
- return System.getProperty(key, def);
- } catch(Throwable e) { // MS-Java throws com.ms.security.SecurityExceptionEx
- return def;
- }
- }
+
+ private static String getSystemProperty(String key, String def) {
+ try {
+ return System.getProperty(key, def);
+ } catch(Throwable e) { // MS-Java throws com.ms.security.SecurityExceptionEx
+ return def;
+ }
+ }
- public static String substVars(String val, Properties props) throws
- IllegalArgumentException {
- return substVars(val, props, null);
- }
+ public static String substVars(String val, Properties props) throws
+ IllegalArgumentException {
+ return substVars(val, props, null);
+ }
- static String DELIM_START = "${";
- static char DELIM_STOP = '}';
- static int DELIM_START_LEN = 2;
- static int DELIM_STOP_LEN = 1;
+ static String DELIM_START = "${";
+ static char DELIM_STOP = '}';
+ static int DELIM_START_LEN = 2;
+ static int DELIM_STOP_LEN = 1;
- public static String substVars(String val, Properties props, HttpSession session) throws IllegalArgumentException {
+ public static String substVars(String val, Properties props, HttpSession session) throws IllegalArgumentException {
- StringBuffer sbuf = new StringBuffer();
+ StringBuffer sbuf = new StringBuffer();
- int i = 0;
- int j, k;
+ int i = 0;
+ int j, k;
- while(true) {
- j=val.indexOf(DELIM_START, i);
- if(j == -1) {
- // no more variables
- if(i==0) { // this is a simple string
- return val;
- } else { // add the tail string which contains no variables and return the result.
- sbuf.append(val.substring(i, val.length()));
- return sbuf.toString();
- }
- } else {
- sbuf.append(val.substring(i, j));
- k = val.indexOf(DELIM_STOP, j);
- if(k == -1) {
- throw new IllegalArgumentException('"'+val+
- "\" has no closing brace. Opening brace at position " + j
- + '.');
- } else {
- j += DELIM_START_LEN;
- String key = val.substring(j, k);
- // first try in System properties
- String replacement = getSystemProperty(key, null);
- // then try props parameter
- if(replacement == null && props != null) {
- replacement = props.getProperty(key);
- }
- if(replacement == null && session != null) {
- if ("webapp.home".equals(key)) {
- replacement = session.getServletContext().getRealPath("/yoyo");
- }
- else {
- replacement = session.getAttribute(key).toString();
- }
- }
+ while(true) {
+ j = val.indexOf(DELIM_START, i);
+ if (j == -1) {
+ // no more variables
+ if (i==0) { // this is a simple string
+ return val;
+ }
+ else { // add the tail string which contains no variables and return the result.
+ sbuf.append(val.substring(i, val.length()));
+ return sbuf.toString();
+ }
+ }
+ else {
+ sbuf.append(val.substring(i, j));
+ k = val.indexOf(DELIM_STOP, j);
+ if (k == -1) {
+ throw new IllegalArgumentException('"'+val+ "\" has no closing brace. Opening brace at position " + j + '.');
+ }
+ else {
+ j += DELIM_START_LEN;
+ String key = val.substring(j, k);
+ // first try in System properties
+ String replacement = getSystemProperty(key, null);
+ // then try props parameter
+ if (replacement == null && props != null) {
+ replacement = props.getProperty(key);
+ }
+ if (replacement == null && session != null) {
+ if ("webapp.home".equals(key)) {
+ replacement = session.getServletContext().getRealPath("/yoyo");
+ }
+ else {
+ replacement = session.getAttribute(key).toString();
+ }
+ }
- if(replacement != null) {
- // Do variable substitution on the replacement string
- // such that we can solve "Hello ${x2}" as "Hello p1"
- // the where the properties are
- // x1=p1
- // x2=${x1}
- String recursiveReplacement = substVars(replacement, props);
- sbuf.append(recursiveReplacement);
- }
- i = k + DELIM_STOP_LEN;
- }
- }
- }
- }
+ if (replacement != null) {
+ // Do variable substitution on the replacement string
+ // such that we can solve "Hello ${x2}" as "Hello p1"
+ // the where the properties are
+ // x1=p1
+ // x2=${x1}
+ String recursiveReplacement = substVars(replacement, props);
+ sbuf.append(recursiveReplacement);
+ }
+ i = k + DELIM_STOP_LEN;
+ }
+ }
+ }
+ }
- static Transport transport = null;
- static public void closeMailConnection() {
- try {
- if (transport != null) transport.close();
+ static Transport transport = null;
+ static public void closeMailConnection() {
+ try {
+ if (transport != null) transport.close();
} catch (Exception e) {
logger.error("Problem closing outgoing mail connection", e);
}
transport = null;
- }
-
- static public void sendEmail(Properties sysConfig, String from, String to, String subject, String body) {
- sendEmail(sysConfig, from, to, subject, body, false);
- }
-
- static public void sendEmail(HttpSession httpSession, String from, String to, String subject, String body) {
- sendEmail(httpSession, from, to, subject, body, false);
- }
-
- static public void sendEmail(HttpSession httpSession, String from, String to, String subject, String body, boolean leaveConnectionOpen) {
- Properties sysConfig = getSysConfig(httpSession);
- sendEmail(sysConfig, from, to, subject, body, false);
- }
-
+ }
+
+ static public void sendEmail(Properties sysConfig, String from, String to, String subject, String body) {
+ sendEmail(sysConfig, from, to, subject, body, false);
+ }
+
+ static public void sendEmail(HttpSession httpSession, String from, String to, String subject, String body) {
+ sendEmail(httpSession, from, to, subject, body, false);
+ }
+
+ static public void sendEmail(HttpSession httpSession, String from, String to, String subject, String body, boolean leaveConnectionOpen) {
+ Properties sysConfig = getSysConfig(httpSession);
+ sendEmail(sysConfig, from, to, subject, body, false);
+ }
+
-static public void sendEmail(Properties sysConfig, String from, String to, String subject, String body, boolean leaveConnectionOpen) {
- String server = sysConfig.getProperty("SendMailServer", "localhost");
- String userID = sysConfig.getProperty("SendMailUser", "");
- String passwd = sysConfig.getProperty("SendMailPasswd", "");
- try {
- Properties props = new Properties();
- props.put("mail.smtp.host", server);
- Session session = Session.getDefaultInstance(props, null);
- if (transport == null) {
- if (userID != null && passwd != null && userID.length() > 0 && passwd.length() > 0) {
- transport = session.getTransport("smtp");
- transport.connect(server, 25, userID, passwd);
- }
- }
+ static public void sendEmail(Properties sysConfig, String from, String to, String subject, String body, boolean leaveConnectionOpen) {
+ String server = sysConfig.getProperty("SendMailServer", "localhost");
+ String userID = sysConfig.getProperty("SendMailUser", "");
+ String passwd = sysConfig.getProperty("SendMailPasswd", "");
try {
- Message msg = new MimeMessage(session);
+ Properties props = new Properties();
+ props.put("mail.smtp.host", server);
+ Session session = Session.getDefaultInstance(props, null);
+ if (transport == null) {
+ if (userID != null && passwd != null && userID.length() > 0 && passwd.length() > 0) {
+ transport = session.getTransport("smtp");
+ transport.connect(server, 25, userID, passwd);
+ }
+ }
+ try {
+ Message msg = new MimeMessage(session);
- InternetAddress addr = new InternetAddress(to);
- msg.addRecipients(Message.RecipientType.TO, new InternetAddress[] { addr });
+ InternetAddress addr = new InternetAddress(to);
+ msg.addRecipients(Message.RecipientType.TO, new InternetAddress[] { addr });
- InternetAddress from_addr = new InternetAddress(from);
- msg.setFrom(from_addr);
+ InternetAddress from_addr = new InternetAddress(from);
+ msg.setFrom(from_addr);
- msg.setSubject(subject);
- msg.setContent(body, "text/plain");
+ msg.setSubject(subject);
+ msg.setContent(body, "text/plain");
- if (transport != null) transport.sendMessage(msg, msg.getAllRecipients());
- else Transport.send(msg);
+ if (transport != null) transport.sendMessage(msg, msg.getAllRecipients());
+ else Transport.send(msg);
+ }
+ catch (Exception e) {
+ logger.error("Problem sending email [" + subject + "] to: " + to, e);
+ }
}
catch (Exception e) {
logger.error("Problem sending email [" + subject + "] to: " + to, e);
}
- }
- catch (Exception e) {
- logger.error("Problem sending email [" + subject + "] to: " + to, e);
- }
- finally {
- if (!leaveConnectionOpen) {
- closeMailConnection();
+ finally {
+ if (!leaveConnectionOpen) {
+ closeMailConnection();
+ }
}
}
+
}
-
-
-
-}
More information about the Ils-source
mailing list