001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.servlet;
022:
023: import java.io.FileInputStream;
024: import java.io.InputStream;
025:
026: import java.util.Properties;
027:
028: import javax.servlet.ServletContext;
029:
030: import javax.servlet.http.HttpServlet;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: import com.methodhead.mail.Mail;
035:
036: /**
037: * <p>
038: * A servlet that initializes {@link
039: * com.methodhead.mail.Mail Mail} singleton. The
040: * following init-param may be specified:
041: * </p>
042: * <ul>
043: * <li>
044: * <strong>mailproperties</strong>: the path of a properties file containing
045: * the properties <tt>Mail</tt> expects.
046: * If the path begins with a forward slash it is assumed to be an absolute
047: * path, otherwise it is assumed to be a path relative to the context's
048: * root. For example: <tt>WEB-INF/mail.properties</tt> or
049: * <tt>/etc/mail.properties</tt>. If this parameter is not specified, it
050: * defaults to <tt>WEB-INF/mail.properties</tt>.
051: * </li>
052: * </ul>
053: */
054: public class MailServlet extends HttpServlet {
055:
056: // constructors /////////////////////////////////////////////////////////////
057:
058: // constants ////////////////////////////////////////////////////////////////
059:
060: // classes //////////////////////////////////////////////////////////////////
061:
062: // methods //////////////////////////////////////////////////////////////////
063:
064: public void init() {
065: try {
066: String path = getInitParameter("mailproperties");
067:
068: if (path == null) {
069: path = getServletContext().getRealPath(
070: "WEB-INF/mail.properties");
071: }
072:
073: if (!path.startsWith("/")) {
074: path = getServletContext().getRealPath(path);
075:
076: if (path == null) {
077: getServletContext()
078: .log(
079: "MailServlet: Couldn't get real path for "
080: + path
081: + "; defaulting to WEB-INF/mail.properties.");
082:
083: path = getServletContext().getRealPath(
084: "WEB-INF/mail.properties");
085: }
086: }
087:
088: InputStream in = new FileInputStream(path);
089:
090: Properties props = new Properties();
091: props.load(in);
092:
093: in.close();
094:
095: Mail.init(props);
096: } catch (Exception e) {
097: getServletContext()
098: .log(
099: "MailServlet: Unexpected exception while initializing "
100: + "MailServlet with init param mailproperties = "
101: + getInitParameter("mailproperties")
102: + ": " + e);
103: }
104: }
105:
106: public void doGet(HttpServletRequest req, HttpServletResponse res) {
107: }
108:
109: // properties ///////////////////////////////////////////////////////////////
110:
111: // attributes ///////////////////////////////////////////////////////////////
112: }
|