/** Constructor for XMPPNotificationManager. */
  protected XMPPNotificationManager() {

    Map<String, String> mdc = Logging.getCopyOfContextMap();
    try {
      mdc.put(Logging.PREFIX_KEY, LOG4J_CATEGORY);

      // Load up some properties

      File config = null;
      try {
        config = ConfigFileConstants.getFile(ConfigFileConstants.XMPP_CONFIG_FILE_NAME);
      } catch (IOException e) {
        LOG.warn("{} not readable", ConfigFileConstants.XMPP_CONFIG_FILE_NAME, e);
      }
      if (Boolean.getBoolean("useSystemXMPPConfig") || !config.canRead()) {
        this.props.putAll(System.getProperties());
      } else {
        FileInputStream fis = null;
        try {
          fis = new FileInputStream(config);
          this.props.load(fis);
        } catch (FileNotFoundException e) {
          LOG.warn("unable to load {}", config, e);
        } catch (IOException e) {
          LOG.warn("unable to load {}", config, e);
        } finally {
          IOUtils.closeQuietly(fis);
        }
      }

      xmppServer = this.props.getProperty("xmpp.server");
      String xmppServiceName = this.props.getProperty("xmpp.servicename", xmppServer);
      xmppUser = this.props.getProperty("xmpp.user");
      xmppPassword = this.props.getProperty("xmpp.pass");
      xmppPort = Integer.valueOf(this.props.getProperty("xmpp.port", XMPP_PORT));

      ConnectionConfiguration xmppConfig =
          new ConnectionConfiguration(xmppServer, xmppPort, xmppServiceName);

      boolean debuggerEnabled = Boolean.parseBoolean(props.getProperty("xmpp.debuggerEnabled"));
      xmppConfig.setDebuggerEnabled(debuggerEnabled);

      xmppConfig.setSASLAuthenticationEnabled(
          Boolean.parseBoolean(props.getProperty("xmpp.SASLEnabled", "true")));
      xmppConfig.setSelfSignedCertificateEnabled(
          Boolean.parseBoolean(props.getProperty("xmpp.selfSignedCertificateEnabled")));

      if (Boolean.parseBoolean(props.getProperty("xmpp.TLSEnabled"))) {
        xmppConfig.setSecurityMode(SecurityMode.enabled);
      } else {
        xmppConfig.setSecurityMode(SecurityMode.disabled);
      }
      if (this.props.containsKey("xmpp.truststorePassword")) {
        xmppConfig.setTruststorePassword(this.props.getProperty("xmpp.truststorePassword"));
      } else {
        xmppConfig.setTruststorePassword(TRUST_STORE_PASSWORD);
      }

      LOG.debug("XMPP Manager connection config: {}", xmppConfig.toString());

      xmpp = new XMPPConnection(xmppConfig);

      // Connect to xmpp server
      connectToServer();
    } finally {
      Logging.setContextMap(mdc);
    }
  }
  /** Constructor for XMPPNotificationManager. */
  protected XMPPNotificationManager() {

    // get the category logger
    String oldPrefix = ThreadCategory.getPrefix();
    ThreadCategory.setPrefix(LOG4J_CATEGORY);

    try {
      // Load up some properties

      File config = null;
      try {
        config = ConfigFileConstants.getFile(ConfigFileConstants.XMPP_CONFIG_FILE_NAME);
      } catch (IOException e) {
        log().warn(ConfigFileConstants.XMPP_CONFIG_FILE_NAME + " not readable", e);
      }
      if (Boolean.getBoolean("useSystemXMPPConfig") || !config.canRead()) {
        this.props.putAll(System.getProperties());
      } else {
        FileInputStream fis = null;
        try {
          fis = new FileInputStream(config);
          this.props.load(fis);
        } catch (FileNotFoundException e) {
          log().warn("unable to load " + config, e);
        } catch (IOException e) {
          log().warn("unable to load " + config, e);
        } finally {
          IOUtils.closeQuietly(fis);
        }
      }

      xmppServer = this.props.getProperty("xmpp.server");
      xmppServiceName = this.props.getProperty("xmpp.servicename", xmppServer);
      xmppUser = this.props.getProperty("xmpp.user");
      xmppPassword = this.props.getProperty("xmpp.pass");
      xmppPort = Integer.valueOf(this.props.getProperty("xmpp.port", XMPP_PORT));

      xmppConfig = new ConnectionConfiguration(xmppServer, xmppPort, xmppServiceName);

      boolean debuggerEnabled = Boolean.parseBoolean(props.getProperty("xmpp.debuggerEnabled"));
      xmppConfig.setDebuggerEnabled(debuggerEnabled);
      if (debuggerEnabled) {
        log().setLevel(ThreadCategory.Level.DEBUG);
      }

      xmppConfig.setSASLAuthenticationEnabled(
          Boolean.parseBoolean(props.getProperty("xmpp.SASLEnabled", "true")));
      xmppConfig.setSelfSignedCertificateEnabled(
          Boolean.parseBoolean(props.getProperty("xmpp.selfSignedCertificateEnabled")));

      if (Boolean.parseBoolean(props.getProperty("xmpp.TLSEnabled"))) {
        xmppConfig.setSecurityMode(SecurityMode.enabled);
      } else {
        xmppConfig.setSecurityMode(SecurityMode.disabled);
      }
      if (this.props.containsKey("xmpp.truststorePassword")) {
        xmppConfig.setTruststorePassword(this.props.getProperty("xmpp.truststorePassword"));
      } else {
        xmppConfig.setTruststorePassword(TRUST_STORE_PASSWORD);
      }

      if (log().isDebugEnabled()) {
        log().debug("XMPP Manager connection config: " + xmppConfig.toString());
      }

      xmpp = new XMPPConnection(xmppConfig);

      // Connect to xmpp server
      connectToServer();
    } finally {
      ThreadCategory.setPrefix(oldPrefix);
    }
  }