Ejemplo n.º 1
0
  /**
   * This method will read the standard input and save the content to a temporary. source file since
   * the source file will be parsed mutiple times. The HTML source file is parsed and checked for
   * Charset in HTML tags at first time, then source file is parsed again for the converting The
   * temporary file is read from standard input and saved in current directory and will be deleted
   * after the conversion has completed.
   *
   * @return the vector of the converted temporary source file name
   */
  public Vector getStandardInput() throws FileAccessException {
    byte[] buf = new byte[2048];
    int len = 0;
    FileInputStream fis = null;
    FileOutputStream fos = null;
    File tempSourceFile;
    String tmpSourceName = ".tmpSource_stdin";

    File outFile = new File(tmpSourceName);

    tempSourceFile = new File(System.getProperty("user.dir") + sep + tmpSourceName);
    if (!tempSourceFile.exists()) {
      try {
        fis = new FileInputStream(FileDescriptor.in);
        fos = new FileOutputStream(outFile);
        while ((len = fis.read(buf, 0, 2048)) != -1) fos.write(buf, 0, len);
      } catch (IOException e) {
        System.out.println(ResourceHandler.getMessage("plugin_converter.write_permission"));
        return null;
      }
    } else {
      throw new FileAccessException(ResourceHandler.getMessage("plugin_converter.overwrite"));
    }
    tempSourceFile = new File(System.getProperty("user.dir") + sep + tmpSourceName);
    if (tempSourceFile.exists()) {
      fileSpecs.add(tmpSourceName);
      return fileSpecs;
    } else {
      throw new FileAccessException(
          ResourceHandler.getMessage("plugin_converter.write_permission"));
    }
  }
Ejemplo n.º 2
0
  /**
   * This method will take in a string which will be a directory. It will make sure that the
   * directory exists and return the absolute path
   *
   * @return the value of the absolute directory
   */
  private String doesExistAndAbsolute(String dir) {

    File tempDirFile = new File(dir);
    try {
      if (tempDirFile.exists()) {
        if (tempDirFile.isAbsolute()) {
          return dir;
        } else {
          tempDirFile = new File(System.getProperty("user.dir") + sep + dir);
          if (tempDirFile.exists()) {
            return tempDirFile.getAbsolutePath();
          } else {
            throw new NotDirectoryException(
                ResourceHandler.getMessage("caption.reldirnotfound")
                    + ":  "
                    + tempDirFile.getAbsolutePath());
          }
        }
      } else {
        throw new NotDirectoryException(
            ResourceHandler.getMessage("caption.absdirnotfound")
                + ":  "
                + tempDirFile.getAbsolutePath());
      }

    } catch (NotDirectoryException e) {
      System.out.println(
          ResourceHandler.getMessage("caption.absdirnotfound")
              + ":  "
              + tempDirFile.getAbsolutePath());
      return null; // this is just so it would compile
    }
  }
Ejemplo n.º 3
0
  /**
   * This will make sure the destination path isn't the same as the backup directory, the
   * application will terminate if they are the same
   */
  private void checkForProblems() throws CommandLineException {

    if ((backupStr != null) && (destStr != null)) {
      File fBackupTemp = new File(backupStr);
      File fDestTemp = new File(destStr);

      if ((fDestTemp.getAbsolutePath()).equals(fBackupTemp.getAbsolutePath())) {
        System.out.println(ResourceHandler.getMessage("illegal_source_and_backup.info"));
        throw new CommandLineException();
      }
    }
  }
Ejemplo n.º 4
0
  /**
   * This will take in the string given at the command line by the user find if it is null and calls
   * readline().
   *
   * @param s[] holds the given command line string
   */
  public CommandLine(String s[]) throws CommandLineException, IndexOutOfBoundsException {
    if (s == null || s.length == 0) { // there are no params
      params = false;
    } else {
      params = true;
      commandLine = s;
      readLine();
      //
      // If no files are specified, default.
      //

      if ((isStdIn() == false) && fileSpecs.isEmpty()) {

        String specs = ResourceHandler.getMessage("converter_gui.lablel2");
        StringTokenizer st = new StringTokenizer(specs, " ,");
        while (st.hasMoreTokens()) {
          fileSpecs.add(st.nextToken());
        }
      }
      checkForProblems();
    }
  }
Ejemplo n.º 5
0
 public static void bindResource(String rs) {
   bindTexture(ResourceHandler.getResource(rs));
 }