示例#1
0
  // ## operation Chemkin(double,double,String)
  public Chemkin(double p_rtol, double p_atol, String p_reactorType) {
    // #[ operation Chemkin(double,double,String)
    if (p_rtol < 0 || p_atol < 0)
      throw new InvalidChemkinParameterException("Negative rtol or atol!");
    if (p_reactorType == null) throw new NullPointerException();

    String dir = System.getProperty("RMG.workingDirectory");

    // create the documentTypesDefinitions
    File docFile = new File("chemkin/documentTypeDefinitions");
    docFile.mkdir();
    copyFiles(
        dir + "/software/reactorModel/documentTypeDefinitions/reactorInput.dtd",
        "chemkin/documentTypeDefinitions/reactorInput.dtd");
    copyFiles(
        dir + "/software/reactorModel/documentTypeDefinitions/reactorOutput.dtd",
        "chemkin/documentTypeDefinitions/reactorOutput.dtd");

    rtol = p_rtol;
    atol = p_atol;
    reactorType = p_reactorType;
  }
示例#2
0
文件: D4.java 项目: sarekautowerke/D4
  public void getFilesFromFolder(List filesAndFolders, String savePath) {
    // create a File object for the parent directory
    File downloadsDirectory = new File(savePath);
    // create the folder if needed.
    downloadsDirectory.mkdir();

    for (int i = 0; i < filesAndFolders.size(); i++) {
      Object links = filesAndFolders.get(i);
      List linksArray = (ArrayList) links;
      if (i == 0) {
        for (int j = 0; j < linksArray.size(); j += 2) {
          // We've got an array of file urls so download each one to a directory with the folder
          // name
          String fileURL = linksArray.get(j).toString();
          String fileName = linksArray.get(j + 1).toString();
          downloadFile(fileURL, savePath, fileName);
          progress++;
          Message msg = mHandler.obtainMessage();
          msg.arg1 = progress;
          mHandler.sendMessage(msg);
        }
      } else if (i == 1) {
        // we've got an array of folders so recurse down the levels, extracting subfolders and files
        // until we've downloaded everything.
        for (int j = 0; j < linksArray.size(); j += 2) {
          String folderURL = linksArray.get(j).toString();
          String folderName = linksArray.get(j + 1).toString();

          String page = getData(folderURL);
          List newFilesAndFolders = parsePage(page);
          String dlDirPath = savePath + folderName + "/";

          getFilesFromFolder(newFilesAndFolders, dlDirPath);
        }
      }
    }
  }
  public static boolean transform(
      File origXmlFileOrDir, File xslFile, File targetDir, String extension) {
    logger.logComment(
        "Going to transform " + origXmlFileOrDir + " into dir " + targetDir + " using: " + xslFile,
        true);

    if (!origXmlFileOrDir.exists()) {
      GuiUtils.showErrorMessage(
          logger,
          "Warning, XML file/directory: " + origXmlFileOrDir + " doesn't exist",
          null,
          null);
      return false;
    }

    if (!xslFile.exists()) {
      GuiUtils.showErrorMessage(
          logger, "Warning, XSL file: " + xslFile + " doesn't exist", null, null);
      return false;
    }

    if (!targetDir.exists()) {
      GuiUtils.showErrorMessage(
          logger, "Warning, target directory: " + targetDir + " doesn't exist", null, null);
      return false;
    }

    if (origXmlFileOrDir.isDirectory()) {
      logger.logComment("That file is a directory. Converting all of the XML files in it");
      File[] files = origXmlFileOrDir.listFiles();

      boolean totalSuccess = true;
      for (int i = 0; i < files.length; i++) {
        if (!files[i].isDirectory()
            && (files[i].getName().endsWith(".xml") || files[i].getName().endsWith(".XML"))) {
          boolean partialSuccess = transform(files[i], xslFile, targetDir, extension);

          totalSuccess = totalSuccess || partialSuccess;
        } else if (files[i].isDirectory() && !GeneralUtils.isVersionControlDir(files[i])) {
          File newFolder = new File(targetDir, files[i].getName());
          newFolder.mkdir();

          logger.logComment(
              "Found a sub folder. Going to convert all there into: " + newFolder + "...");

          transform(files[i], xslFile, newFolder, extension);
        }
      }
      return totalSuccess;
    }

    String result = transform(origXmlFileOrDir, xslFile);

    String newName = origXmlFileOrDir.getName();

    if (newName.endsWith(".xml") || newName.endsWith(".XML")) {
      newName = newName.substring(0, newName.length() - 4) + extension;
    }
    File targetFile = new File(targetDir, newName);

    try {
      FileWriter fw = new FileWriter(targetFile);
      fw.write(result);
      fw.close();
    } catch (IOException ex) {
      GuiUtils.showErrorMessage(logger, "Exception writing to file: " + targetFile, ex, null);
      return false;
    }

    logger.logComment("The result is in " + targetFile + " *************");

    return result != null;
  }