configuration.java

来自「一个用java写的mail.里面的代码值得我们去研究!学习。」· Java 代码 · 共 582 行 · 第 1/2 页

JAVA
582
字号
  removeProperty( String propName ) {    UserProperties.removeDynamicProperty( name_, propName );  }  public void  saveProperties() {    try {      UserProperties.saveDynamicProperties( name_ );    } catch ( IOException xex ) {      Object[] xargs = new Object[2];      xargs[0] = name_;      xargs[1] = xex.getMessage();      ComponentFactory.showDialog( ICEMail.getBundle(), "Configuration.SavingException",                                   0, JOptionPane.WARNING_MESSAGE, xargs );    }  }//............................................................// used by ICEMail.java  public void  checkEssentialProperties() {    this.haveWarned = false;    if ( ! isPropertySet( P_TEMP_DIR ) ) {      TempManagerDialog dlg = new TempManagerDialog( null );      dlg.show();    }    if ( ! isPropertySet( P_TRANSPORT_PROTO ) ) {      TransportDialog dlg = new TransportDialog( null );      dlg.show();    }    if ( isTransportSMTP() ) {      if ( ! isPropertySet( P_SMTP_HOSTNAME ) ) {        SMTPConfigDialog dlg = new SMTPConfigDialog( null );        dlg.show();      }    }    if ( ! isPropertySet( P_FROM_ADDRESS ) ) {      UserConfigDialog dlg = new UserConfigDialog( null );      dlg.show();    }    if ( ! isPropertySet( P_STORE_LIST ) ) {      StoreConfigDialog dlg = new StoreConfigDialog( null );      dlg.show();    }  }  private boolean  isTransportSMTP() {    String propValue = UserProperties.getProperty( P_TRANSPORT_PROTO, null );        if ( propValue != null && propValue.equalsIgnoreCase( "smtp" ) ) {      return true;    }    return false;  }  private boolean  isPropertySet( String propName ) {    boolean result = true;    String propValue = UserProperties.getProperty( propName, null );    if ( propValue == null ) {      if ( ! this.haveWarned ) {        ComponentFactory.showDialog( ICEMail.getBundle(), "Configuration.Warning",                                     0, JOptionPane.WARNING_MESSAGE, null );        this.haveWarned = true;      }      result = false;    }    return result;  }  private void  determineHomeDirectory() {    String userDirName = System.getProperty( "user.home", null );    if ( userDirName == null ) {      userDirName = System.getProperty( "user.dir", null );      if ( userDirName != null ) {        Object[] xargs = new Object[1];        xargs[0] = userDirName;        ComponentFactory.showDialog( ICEMail.getBundle(), "Configuration.HomeInformation",                                     0, JOptionPane.INFORMATION_MESSAGE, xargs );      }    }    if ( userDirName == null ) {      // REVIEW We are using a questionable algorithm here.      this.homeDir = new File( (File.separatorChar == ':') ? ":" : "." );      ComponentFactory.showDialog( ICEMail.getBundle(), "Configuration.HomeMissing",                                   0, JOptionPane.ERROR_MESSAGE, null );    } else {      this.homeDir = new File( userDirName );    }  }// used by ICEMail  public void  loadMailCap() {    if ( Package.DEBUG && Configuration.Debug_ > 0 ) {      System.out.println( "Configuration.loadMailCap(): " + mailcapFileName );    }    File capfile;    boolean ok = false;    if ( this.mailcapFileName != null ) {      capfile = new File( this.mailcapFileName );      ok = true;    } else {      // REVIEW We are using a questionable algorithm here.      String defMailcapFilename = (File.separatorChar == '/') ? ".icemailcap" : "icemailcap.txt";      String mailcapFileName = UserProperties.getProperty( "mailcap.fileName", defMailcapFilename );      if ( Package.DEBUG && Configuration.Debug_ > 0 ) {        System.out.println( "Configuration.loadMailCap(): " + mailcapFileName );      }      capfile = new File( this.homeDir, mailcapFileName );    }    if ( ! capfile.exists() ) {      Object[] xargs = new Object[1];      xargs[0] = capfile.getPath();      ComponentFactory.showDialog( ICEMail.getBundle(), "Configuration.MailcapCreate",                                   0, JOptionPane.WARNING_MESSAGE, xargs );      try {        ResourceUtilities.copyResourceToFile( "/org/icemail/mail/icemailcap.txt", capfile );      } catch ( IOException ex ) { }    }          if ( ! capfile.isFile() ) {      Object[] xargs = new Object[1];      xargs[0] = capfile.getPath();      ComponentFactory.showDialog( ICEMail.getBundle(), "Configuration.MailcapInvalid",                                   0, JOptionPane.ERROR_MESSAGE, xargs );    } else {      try {        CommandMap.setDefaultCommandMap( new MailcapCommandMap( new FileInputStream( capfile ) ) );        Configuration.getInstance().parseMailcap( capfile );        ok = true;      } catch ( FileNotFoundException xex ) {        Object[] xargs = new Object[2];        xargs[0] = capfile.getPath();        xargs[1] = xex.getMessage();        ComponentFactory.showDialog( ICEMail.getBundle(), "Configuration.MailcapMissing",                                     0, JOptionPane.ERROR_MESSAGE, xargs );      } catch ( IOException xex ) {        Object[] xargs = new Object[2];        xargs[0] = capfile.getPath();        xargs[1] = xex.getMessage();        ComponentFactory.showDialog( ICEMail.getBundle(), "Configuration.MailcapBad",                                     0, JOptionPane.ERROR_MESSAGE, xargs );      }    }    if ( ! ok ) {      if ( Package.DEBUG && Configuration.Debug_ > 0 ) {        System.out.println( "Configuration.loadMailCap(): bad, reseting defaults" );      }      CommandMap.setDefaultCommandMap( new MailcapCommandMap() );    }  }// used by ICEMail  public void  loadMimeTypes() {    if ( Package.DEBUG && Configuration.Debug_ > 0 ) {      System.out.println( "Configuration.loadMimeTypes(): " + mimeFileName );    }    File mimefile;    boolean ok = true;    if ( this.mimeFileName != null ) {      mimefile = new File( this.mimeFileName );    } else {    // REVIEW We are using a questionable algorithm here.      String defMimeFilename = (File.separatorChar == '/') ? ".icemime" : "icemime.txt";      String mimeFileName = UserProperties.getProperty( "mime.fileName", defMimeFilename );      if ( Package.DEBUG && Configuration.Debug_ > 0 ) {        System.out.println( "Configuration.loadMimeTypes(): " + mimeFileName );      }      mimefile = new File( this.homeDir, mimeFileName );    }    if ( ! mimefile.exists() ) {      Object[] xargs = new Object[1];      xargs[0] = mimefile.getPath();      ComponentFactory.showDialog( ICEMail.getBundle(), "Configuration.MimetypesCreate",                                   0, JOptionPane.WARNING_MESSAGE, xargs );      try {        ResourceUtilities.copyResourceToFile          ( "/org/icemail/mail/icemime.txt", mimefile );      } catch ( IOException ex ) { }    }    if ( ! mimefile.isFile() ) {      Object[] xargs = new Object[1];      xargs[0] = mimefile.getPath();      ComponentFactory.showDialog( ICEMail.getBundle(), "Configuration.MimetypesInvalid",                                   0, JOptionPane.ERROR_MESSAGE, xargs );      ok = false;    } else {      try {        FileTypeMap.setDefaultFileTypeMap( new MimetypesFileTypeMap(                                                 new FileInputStream( mimefile ) ) );      } catch ( FileNotFoundException xex ) {        Object[] xargs = new Object[2];        xargs[0] = mimefile.getPath();        xargs[1] = xex.getMessage();        ComponentFactory.showDialog( ICEMail.getBundle(), "Configuration.MimetypesMissing",                                     0, JOptionPane.ERROR_MESSAGE, xargs );        ok = false;      } catch ( IOException xex ) {        Object[] xargs = new Object[2];        xargs[0] = mimefile.getPath();        xargs[1] = xex.getMessage();        ComponentFactory.showDialog( ICEMail.getBundle(), "Configuration.MimetypesBad",                                     0, JOptionPane.ERROR_MESSAGE, xargs );        ok = false;      }    }    if ( ! ok ) {      if ( Package.DEBUG && Configuration.Debug_ > 0 ) {        System.out.println( "Configuration.loadMimeTypes(): bad, reseting defaults" );      }      FileTypeMap.setDefaultFileTypeMap( new MimetypesFileTypeMap() );    }  }  // HACK  // This is a horrible hack that is needed only because  // CommandMap does not allow us to ask for the list of  // known content types.  //  private void  parseMailcap( File capfile ) throws FileNotFoundException, IOException {    BufferedReader reader = new BufferedReader( new FileReader( capfile ) );    for ( ; ; ) {      String line = reader.readLine();      if ( line == null ) {        break;      }      if ( line.startsWith( "#" ) ) {        continue;      }      if ( line.startsWith( "!" ) ) {        continue;      }      int index = line.indexOf( ";" );      if ( index < 0 ) {        continue;      }      String baseType = line.substring( 0, index );      index = baseType.indexOf( "/" );      if ( index < 0 ) {        continue;      }      String subType = baseType.substring( index + 1 );      if ( subType.equals( "*" ) ) {        continue;      }      this.mailcapTypes.addElement( baseType );    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?