Package org.parosproxy.paros.model

Examples of org.parosproxy.paros.model.FileCopier


        return staticSP;
    }


    public Constant() {
        FileCopier copier = new FileCopier();
        File f = null;
        Log log = null;
       
        String userhome = System.getProperty("user.home");
       
        // default to use application directory 'log'
        System.setProperty(SYSTEM_PAROS_USER_LOG, "log");

        if (userhome != null && !userhome.equals("")) {
            userhome += System.getProperty("file.separator")+"paros";
            f = new File(userhome);
            userhome += System.getProperty("file.separator");
            FILE_CONFIG = userhome+FILE_CONFIG;
            FOLDER_SESSION = userhome+FOLDER_SESSION;
            DBNAME_UNTITLED = userhome+DBNAME_UNTITLED;
            ACCEPTED_LICENSE = userhome+ACCEPTED_LICENSE;

            try {
               
                System.setProperty(SYSTEM_PAROS_USER_LOG, userhome);
                System.setProperty("log4j.configuration","xml/log4j.properties");
               
                if (!f.isDirectory()) {
                    f.mkdir();
                    log = LogFactory.getLog(Constant.class);
                    log.info("Created directory "+userhome);

                } else {
                    log = LogFactory.getLog(Constant.class);
                   
                }
               
                f=new File(FILE_CONFIG);
                if (!f.isFile()) {
                    log.info("Copying defaults from "+FILE_CONFIG_DEFAULT+" to "+FILE_CONFIG);
                    copier.copy(new File(FILE_CONFIG_DEFAULT),f);

                } else {
                    try {
                       
                        XMLConfiguration config = new XMLConfiguration(FILE_CONFIG);
                        config.setAutoSave(false);
                        config.load();

                        long ver = config.getLong("version");
                        if (VERSION_TAG > ver) {
                            // overwrite previous configuration file
                            copier.copy(new File(FILE_CONFIG_DEFAULT),f);                       
                        }
                    } catch (ConfigurationException e) {
                        //  if there is any error in config file (eg config file not exist),
                        //  overwrite previous configuration file
                        copier.copy(new File(FILE_CONFIG_DEFAULT),f);                       

                    } catch (NoSuchElementException e) {
                        //  overwrite previous configuration file if config file corrupted
                        copier.copy(new File(FILE_CONFIG_DEFAULT),f);                       
                       
                    }

                }
               
View Full Code Here


    setAcceleratorKeys();
  }
 
  private void initializeFilesAndDirectories() {
 
    FileCopier copier = new FileCopier();
    File f = null;
    Log log = null;
   
    String userhome = System.getProperty("user.home");
   
    // default to use application directory 'log'
    System.setProperty(SYSTEM_PAROS_USER_LOG, "log");

    if (userhome != null && !userhome.equals("")) {
     
      if (isLinux() || isSolaris()) {
        userhome += FILE_SEPARATOR + "." + PROGRAM_NAME;
      } else if (isOSX()) {
        userhome += FILE_SEPARATOR + "Library" + FILE_SEPARATOR
          + "Application Support" + FILE_SEPARATOR + PROGRAM_NAME;
      } else {
        // Windows System
        userhome += FILE_SEPARATOR + PROGRAM_NAME;
      }
     
      f = new File(userhome);
      userhome += FILE_SEPARATOR;
      FILE_CONFIG = userhome + FILE_CONFIG;
      FOLDER_SESSION = userhome + FOLDER_SESSION;
      DBNAME_UNTITLED = userhome + DBNAME_UNTITLED;
      ACCEPTED_LICENSE = userhome + ACCEPTED_LICENSE;

      try {

        System.setProperty(SYSTEM_PAROS_USER_LOG, userhome);
        System.setProperty("log4j.configuration", "xml/log4j.properties");

        if (!f.isDirectory()) {
                    if (! f.mkdir() ) {
                      // ZAP: report failure to create directory
                      System.out.println("Failed to create directory " + f.getAbsolutePath());
                    }
          log = LogFactory.getLog(Constant.class);
          log.info("Created directory " + userhome);

        } else {
          log = LogFactory.getLog(Constant.class);

        }

        f = new File(FILE_CONFIG);
        if (!f.isFile()) {
          log.info("Copying defaults from " + FILE_CONFIG_DEFAULT + " to " + FILE_CONFIG);
          copier.copy(new File(FILE_CONFIG_DEFAULT), f);

        } else {
          try {

            XMLConfiguration config = new XMLConfiguration(FILE_CONFIG);
            config.setAutoSave(false);
            config.load();

            long ver = config.getLong("version");
            if (VERSION_TAG > ver) {
              // overwrite previous configuration file
              copier.copy(new File(FILE_CONFIG_DEFAULT), f);
            }
          } catch (ConfigurationException e) {
            // if there is any error in config file (eg config file
            // not exist), overwrite previous configuration file
            copier.copy(new File(FILE_CONFIG_DEFAULT), f);

          } catch (NoSuchElementException e) {
            // overwrite previous configuration file if config file
            // corrupted
            copier.copy(new File(FILE_CONFIG_DEFAULT), f);

          }

        }
View Full Code Here

TOP

Related Classes of org.parosproxy.paros.model.FileCopier

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.