Esempio n. 1
0
  REplican(String arguments[]) {
    JCLO jclo = new JCLO(args);

    if (arguments.length == 0) {
      System.out.println("Arguments:\n" + jclo.usage() + "URLs...");
      System.exit(1);
    }

    try {
      jclo.parse(arguments);
    } catch (IllegalArgumentException IAE) {
      System.err.println(IAE);
      System.err.println("Arguments:\n" + jclo.usage() + "URLs...");
      System.exit(0);
    }

    String logLevel = args.LogLevel;
    ConsoleHandler ch = new ConsoleHandler();

    if (logLevel != null) {
      Level level = JavaLN.getLevel(logLevel);
      ch.setLevel(level);
      ch.setFormatter(new LineNumberFormatter());
      logger.setLevel(level);
    } else {
      ch.setFormatter(new NullFormatter());
    }

    logger.addHandler(ch);
    logger.setUseParentHandlers(false);

    if (args.Version) {
      System.out.println(Version.getVersion());
      System.exit(0);
    }

    if (args.Help) {
      System.out.println("Arguments:\n" + jclo.usage() + "URLs...");
      System.exit(0);
    }

    cookies = new Cookies();

    setDefaults();

    if (args.LoadCookies != null) {
      for (int i = 0; i < args.LoadCookies.length; i++) {
        logger.config("Loading cookies from " + args.LoadCookies[i]);
        cookies.loadCookies(args.LoadCookies[i]);
      }
    }

    if (args.PlistCookies != null) {
      for (int i = 0; i < args.PlistCookies.length; i++) {
        logger.config("Loading cookies from " + args.PlistCookies[i]);
        new Plist("file:" + args.PlistCookies[i], cookies);
      }
    }

    if (args.CheckpointEvery != 0) {
      logger.config("Loading urls from " + args.CheckpointFile);

      try {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(args.CheckpointFile));
        urls = (Hashtable) ois.readObject();
        ois.close();
      } catch (IOException ioe) {
        logger.throwing(ioe);
      } catch (ClassNotFoundException cnfe) {
        logger.throwing(cnfe);
      }
    }

    if (args.FollowRedirects) HttpURLConnection.setFollowRedirects(false);
  }