<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 6  文章 - 129  trackbacks - 0
    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    常用鏈接

    留言簿(14)

    隨筆檔案(6)

    文章分類(467)

    文章檔案(423)

    相冊

    收藏夾(18)

    JAVA

    搜索

    •  

    積分與排名

    • 積分 - 829297
    • 排名 - 49

    最新評論

    閱讀排行榜

    評論排行榜

    package com.apress.dwrprojects.instamail;


    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.IOException;
    import java.util.Properties;
    import javax.servlet.ServletContext;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;


    /**
     * This class deals with maintaining options, including the e-mail account.
     *
     * @author <a href="mailto:fzammetti@omnytex.com">Frank W. Zammetti</a>.
     */
    public class OptionsManager {


      /**
       * Log instance.
       */
      private static Log log = LogFactory.getLog(OptionsManager.class);


      /**
       * File name of the options file.
       */
      private static final String optionsFilename = "options.properties";


      /**
       * This method retrieves the options and returns them.  If no
       * optionsFilename file is found, a 'blank' DTO is returned.
       *
       * @param  sc ServletContext associates with the request.
       * @return    An OptionsDTO containing all the stored options.
       */
      public OptionsDTO retrieveOptions(ServletContext sc) {

        // Instantiate an OptionsDTO, and by default assume it will be configured.
        // This means the application has already been configured for use.  This
        // affects what the user can do when the app is accessed initially.
        OptionsDTO options = new OptionsDTO();
        options.setConfigured(true);

        // Read in the options.
        InputStream isFeedFile =
          sc.getResourceAsStream("/WEB-INF/" + optionsFilename);

        Properties props = new Properties();
        try {
          if (isFeedFile == null) {
            throw new IOException(optionsFilename + " not found");
          }
          props.load(isFeedFile);
          isFeedFile.close();
        } catch (IOException e) {
          log.info("No " + optionsFilename + " file, a blank DTO will " +
            "be returned.");
          // Make sure the OptionsDTO is set as unconfigured so that when the
          // index.jsp page is loaded, all the user will be allowed to do is go to
          // the Options views.
          options.setConfigured(false);
          props.setProperty("pop3Server", "");
          props.setProperty("pop3ServerRequiresLogin", "false");
          props.setProperty("pop3Username", "");
          props.setProperty("pop3Password", "");
          props.setProperty("smtpServer", "");
          props.setProperty("smtpServerRequiresLogin", "false");
          props.setProperty("smtpUsername", "");
          props.setProperty("smtpPassword", "");
          props.setProperty("fromAddress", "");
        }

        // Populate OptionsDTO from options Properties.
        options.setPop3Server(props.getProperty("pop3Server"));
        options.setPop3ServerRequiresLogin(
          props.getProperty("pop3ServerRequiresLogin"));
        options.setPop3Username(props.getProperty("pop3Username"));
        options.setPop3Password(props.getProperty("pop3Password"));
        options.setSmtpServer(props.getProperty("smtpServer"));
        options.setSmtpServerRequiresLogin(
          props.getProperty("smtpServerRequiresLogin"));
        options.setSmtpUsername(props.getProperty("smtpUsername"));
        options.setSmtpPassword(props.getProperty("smtpPassword"));
        options.setFromAddress(props.getProperty("fromAddress"));

        return options;

      } // End retrieveOptions().


      /**
       * This method saves the options.
       *
       * @param  pop3Server              The POP3 server address.
       * @param  pop3ServerRequiresLogin Does the POP3 server require login?
       * @param  pop3Username            The POP3 username.
       * @param  pop3Password            The POP3 password.
       * @param  smtpServer              The SMTP server address.
       * @param  smtpServerRequiresLogin Does the SMTP server require login?
       * @param  smtpUsername            The SMTP username.
       * @param  smtpPassword            The SMTP password.
       * @param  fromAddress             From address for outgoing messages.
       * @param  sc                      ServletContext associated with the request.
       * @return                         A message saying the save was OK.
       */
      public String saveOptions(String pop3Server, String pop3ServerRequiresLogin,
        String pop3Username, String pop3Password, String smtpServer,
        String smtpServerRequiresLogin, String smtpUsername,
        String smtpPassword, String fromAddress, ServletContext sc) {

          // Log what we received.
          log.info("\nSaving options:\n" +
          "pop3Server = " + pop3Server + "\n" +
            "pop3ServerRequiresLogin = " + pop3ServerRequiresLogin + "\n" +
            "pop3Username = " + pop3Username + "\n" +
            "pop3Password = " + pop3Password + "\n" +
            "smtpServer = " + smtpServer + "\n" +
            "smtpServerRequiresLogin = " + smtpServerRequiresLogin + "\n" +
            "smtpUsername = " + smtpUsername + "\n" +
            "smtpPassword = " + smtpPassword + "\n" +
            "fromAddress = " + fromAddress + "\n");

          String result = "";

          // Populate Properties structure.
          Properties props = new Properties();
          props.setProperty("pop3Server", pop3Server);
          props.setProperty("pop3ServerRequiresLogin",
            pop3ServerRequiresLogin);
          props.setProperty("pop3Username", pop3Username);
          props.setProperty("pop3Password", pop3Password);
          props.setProperty("smtpServer", smtpServer);
          props.setProperty("smtpServerRequiresLogin",
            smtpServerRequiresLogin);
          props.setProperty("smtpUsername", smtpUsername);
          props.setProperty("smtpPassword", smtpPassword);
          props.setProperty("fromAddress",  fromAddress);

          // Lastly, delete any existing optionsFilename file in WEB-INF and
          // write out a new version from the Properties object we just populated.
          // Return a message saying the operation was complete, or if any problems
          // occur, a message saying what went wrong.
          FileOutputStream fos = null;
          try {
            new File(sc.getRealPath("WEB-INF") + "/" + optionsFilename).delete();
            fos = new FileOutputStream(sc.getRealPath("WEB-INF") +
              "/" + optionsFilename);
            props.store(fos, null);
            fos.flush();
            result = "Options have been saved.";

          } catch (IOException e) {
            log.error("Error saving contact:");
            e.printStackTrace();
            result = "Options could not be saved.  " +
              "Please review logs for details.";
          } finally {
            try {
              if (fos != null) {
                fos.close();
              }
            } catch (IOException e) {
              log.error("Error closing fos: " + e);
            }
          }

          return result;

      } // End saveOptions().


    } // End class.



    posted on 2010-03-09 22:19 Ke 閱讀(509) 評論(0)  編輯  收藏 所屬分類: javaIO
    主站蜘蛛池模板: 亚洲国产精品18久久久久久| 精品一区二区三区高清免费观看| 国产一级淫片免费播放| 黄色视频在线免费观看| 亚洲视频精品在线观看| 国产又黄又爽又刺激的免费网址 | 久久精品国产亚洲精品2020| 无人在线观看免费高清视频| 一级做α爱过程免费视频| 亚洲成人一级电影| 精品亚洲成α人无码成α在线观看| 114级毛片免费观看| 免费国产a理论片| 亚洲国产理论片在线播放| 亚洲国模精品一区| 中国在线观看免费国语版| 精品国产免费人成网站| 亚洲熟妇av午夜无码不卡| 国产V亚洲V天堂A无码| 国产精品无码免费视频二三区| 小草在线看片免费人成视久网| 18禁亚洲深夜福利人口| 亚洲精品国产成人| 亚洲综合伊人久久综合| 日本无吗免费一二区| 99re在线视频免费观看| 72pao国产成视频永久免费| 亚洲熟妇av午夜无码不卡| 色播亚洲视频在线观看| 亚洲中文字幕视频国产| 卡一卡二卡三在线入口免费| 99免费观看视频| 两性色午夜视频免费播放| 日本系列1页亚洲系列| 日本亚洲精品色婷婷在线影院| 久久久久久亚洲精品中文字幕 | 在线观看无码的免费网站| 久久久久久国产精品免费无码| 香蕉视频在线免费看| 猫咪免费人成在线网站| 亚洲av无码专区在线电影天堂 |