Esempio n. 1
0
 public static String getV2DataDirPath() {
   File f =
       new File(
           FileUtil.getWorkingDirPath() + File.separator + "data" + File.separator + "v2Meta");
   if ((!f.exists()) || (!f.isDirectory())) f.mkdirs();
   return f.getAbsolutePath();
   // return getV2DataDirPath(null);
 }
Esempio n. 2
0
  public static String getV2DataDirPath(Component parent) {
    File f =
        new File(
            FileUtil.getWorkingDirPath() + File.separator + "data" + File.separator + "v2Meta");
    if ((!f.exists()) || (!f.isDirectory())) {
      if (parent == null) return null;

      String display =
          "HL7 v2 meta Directory isn't created yet.\nPress 'Yes' button if you want to create directory.\nIt may takes some minutes.";
      // JOptionPane.showMessageDialog(parent, "Making V2 Meta Directory", display,
      // JOptionPane.WARNING_MESSAGE);
      // System.out.println("CCCCV : " + display);
      int res =
          JOptionPane.showConfirmDialog(
              parent,
              display,
              "Create v2 Meta Directory",
              JOptionPane.YES_NO_OPTION,
              JOptionPane.INFORMATION_MESSAGE);

      if (res != JOptionPane.YES_OPTION) return "";

      ClassLoaderUtil loaderUtil = null;
      try {
        loaderUtil = new ClassLoaderUtil("v2Meta");
      } catch (IOException ie) {
        JOptionPane.showMessageDialog(
            parent,
            ie.getMessage() + ".\n Check the resourceV2.zip file in the library.",
            "Creating V2 Meta Directory failure",
            JOptionPane.WARNING_MESSAGE);
        // System.err.println("Make V2 Meta Directory : " + ie.getMessage());
        return null;
      }

      for (int i = 0; i < loaderUtil.getSizeOfFiles(); i++) {
        String path = loaderUtil.getPath(i);
        if (!path.trim().toLowerCase().endsWith(".dat")) continue;
        path = path.replace("/", File.separator);
        path = FileUtil.getWorkingDirPath() + File.separator + "data" + File.separator + path;
        int index = -1;
        for (int j = path.length(); j > 0; j--) {
          String achar = path.substring(j - 1, j);
          if (achar.equals(File.separator)) {
            index = j;
            break;
          }
        }
        // System.out.println("V2 Meta : " + path);
        if (index <= 0) {
          JOptionPane.showMessageDialog(
              parent,
              "V2 Meta file is invalid : " + path,
              "Creating V2 Meta Directory failure",
              JOptionPane.WARNING_MESSAGE);

          // System.err.println("V2 Meta file is invalid : " + path);
          return null;
        }
        File dir = new File(path.substring(0, (index - 1)));
        if ((!dir.exists()) || (!dir.isDirectory())) {
          if (!dir.mkdirs()) {
            JOptionPane.showMessageDialog(
                parent,
                "V2 Meta directory making failure : " + dir,
                "Creating V2 Meta Directory failure",
                JOptionPane.WARNING_MESSAGE);

            // System.err.println("V2 Meta directory making failure : " + dir);
            return null;
          }
        }
        File datFile = new File(loaderUtil.getFileName(i));
        if ((!datFile.exists()) || (!datFile.isFile())) {
          JOptionPane.showMessageDialog(
              parent,
              "Not Found This V2 Meta temporary file : " + path,
              "Creating V2 Meta Directory failure",
              JOptionPane.WARNING_MESSAGE);

          continue;
        }
        if (!datFile.renameTo(new File(path)))
          System.err.println("V2 Meta rename failure : " + path);
      }
    }
    return f.getAbsolutePath();
  }