protected void determineProjectName() throws ASExternalImporterException {
    String exceptionMessage = null;

    if (projectType == ProjectType.IPR) {
      // We are sure that determineProjectType() didn't throw exception, so iprFile is not null and
      // it represents *.ipr file
      projectName = iprFile.getName().replaceFirst("\\.ipr$", "");
    } else if (projectType == ProjectType.IDEA) {
      File nameFile = new File(ideaDir.getPath(), ".name");
      try {
        BufferedReader reader = new BufferedReader(new FileReader(nameFile));
        String name = reader.readLine();
        if (StringUtils.isWhitespace(name)) {
          exceptionMessage = ".name file in path " + nameFile.getPath() + " is empty";
        }
        projectName = name.trim();
      } catch (FileNotFoundException e) {
        exceptionMessage = "Cannot find .name file in path " + nameFile.getPath();
      } catch (IOException e) {
        exceptionMessage = "Cannot read .name file in path " + nameFile.getPath();
      }
    } else {
      // Actually unreachable (see setProject())
      exceptionMessage = "Project type was not determined";
    }

    if (exceptionMessage != null) {
      resetStateAndThrowException(exceptionMessage);
    }
  }
  private void determineProjectType() throws ASExternalImporterException {
    File dir = new File(projectPath);

    File[] files =
        dir.listFiles(
            new FilenameFilter() {
              @Override
              public boolean accept(File dir, String name) {
                return name.endsWith(".ipr");
              }
            });
    if (files != null && files.length > 0) {
      iprFile = files[0];
      projectType = ProjectType.IPR;

      File iws = new File(projectPath, iprFile.getName().replaceFirst("\\.ipr$", ".iws"));
      if (!iws.exists()) {
        resetStateAndThrowException(
            "Cannot find " + iws.getName() + " file in path " + projectPath);
      }
      iwsFile = iws;

      return;
    }

    files =
        dir.listFiles(
            new FilenameFilter() {
              @Override
              public boolean accept(File dir, String name) {
                return name.equals(".idea");
              }
            });
    if (files != null && files.length > 0) {
      ideaDir = files[0];
      projectType = ProjectType.IDEA;
      return;
    }

    // If neither *.ipr file, nor .idea directory is found
    resetStateAndThrowException(
        "Cannot find neither *.ipr file, nor .idea directory in path " + projectPath);
  }
Beispiel #3
0
  private static void AML2PNML(String[] args) {
    if (args.length != 3) {
      System.out.println("���ṩAML����Ŀ¼��PNML���Ŀ¼�Լ��ֵ��ļ�!");
      System.exit(-1);
    }
    System.out.println("����Ŀ¼��" + args[0]);
    System.out.println("���Ŀ¼��" + args[1]);
    System.out.println("�ֵ��ļ���" + args[2]);
    // load the dict
    AMLtoPNML.loadDict(args[2]);
    File srcDir = new File(args[0]);
    File[] lstAML = srcDir.listFiles();
    PnmlExport export = new PnmlExport();
    for (int i = 0; i < lstAML.length; i++) {
      if (lstAML[i].isDirectory()) {
        continue;
      }
      System.out.print(lstAML[i].getName() + "==>");
      try {
        FileInputStream fis = new FileInputStream(lstAML[i]);
        int idx = lstAML[i].getName().indexOf(".xml");
        File outFile = new File(args[1] + "/" + lstAML[i].getName().substring(0, idx) + ".pnml");
        FileOutputStream fos = new FileOutputStream(outFile);
        EPCResult epcRes = (EPCResult) AMLtoPNML.importFile(fis);
        ConfigurableEPC epc = epcRes.getMainEPC();
        PetriNet petri = AMLtoPNML.convert(epc);
        export.export(new ProvidedObject("PetriNet", new Object[] {petri}), fos);
        System.out.println(outFile.getName());
      } catch (FileNotFoundException ex) {
        ex.printStackTrace(System.out);
      } catch (IOException ioe) {
        ioe.printStackTrace(System.out);
      } catch (Exception e) {
        e.printStackTrace(System.out);
      }
    }

    System.out.println("Conversion Done");
  }
 public String getShortFileName() {
   return m_fileName.getName();
 }
Beispiel #5
0
  // -----------------------------------------------------
  // Description: Determine if a template exists for the
  // given file and return true on success.
  // -----------------------------------------------------
  boolean templateExistFor(String fileName, String destinationDirectory) {

    templateIdentified = false;

    // from template
    int intOriginX = 0;
    int intOriginY = 0;

    // from template
    int intX = 0;
    int intY = 0;
    int intWidth = 0;
    int intHeight = 0;

    // calculated
    int viaTemplateX = 0;
    int viaTemplateY = 0;
    int viaTemplatePlusWidth = 0;
    int viaTemplatePlusHeight = 0;

    String fileName_woext = fileName.substring(0, fileName.lastIndexOf('.'));
    String pathPlusFileName_woext =
        destinationDirectory + File.separator + fileName_woext + File.separator + fileName_woext;

    try {

      File folder = new File(templateLocation);
      File[] listOfFiles = folder.listFiles();

      long startTime = System.currentTimeMillis();

      for (File file : listOfFiles) {

        if (file.isFile()) {

          templateName = "";

          DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
          DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
          Document doc = dBuilder.parse(file);
          doc.getDocumentElement().normalize();

          System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
          NodeList nList = doc.getElementsByTagName("condition");

          for (int temp = 0; temp < nList.getLength(); temp++) {

            Node nNode = nList.item(temp);
            if (nNode.getNodeType() == Node.ELEMENT_NODE) {

              Element eElement = (Element) nNode;

              String myX = getTagValue("x", eElement);
              String myY = getTagValue("y", eElement);
              String myWidth = getTagValue("width", eElement);
              String myHeight = getTagValue("height", eElement);
              String mySuffix = getTagValue("suffix", eElement);
              String myRequirements = getTagValue("required", eElement);

              intX = Integer.parseInt(myX);
              intY = Integer.parseInt(myY);
              intWidth = Integer.parseInt(myWidth);
              intHeight = Integer.parseInt(myHeight);

              viaTemplateX = intX - (intOriginX - pageX);
              viaTemplateY = intY - (intOriginY - pageY);
              viaTemplatePlusWidth = viaTemplateX + intWidth;
              viaTemplatePlusHeight = viaTemplateY + intHeight;

              Spawn.execute(
                  Settings.Programs.CONVERT.path(),
                  pathPlusFileName_woext + "_trim.png",
                  "-crop",
                  String.format("%dx%d+%d+%d", intWidth, intHeight, viaTemplateX, viaTemplateY),
                  "+repage",
                  pathPlusFileName_woext + "_" + mySuffix + ".png");
              Spawn.execute(
                  Settings.Programs.CONVERT.path(),
                  pathPlusFileName_woext + "_trim.png",
                  "-fill",
                  "none",
                  "-stroke",
                  "red",
                  "-strokewidth",
                  "3",
                  "-draw",
                  String.format(
                      "rectangle %d,%d %d,%d",
                      viaTemplateX, viaTemplateY, viaTemplatePlusWidth, viaTemplatePlusHeight),
                  "+repage",
                  pathPlusFileName_woext + "_draw.png");
              Spawn.execute(
                  Settings.Programs.TESSERACT.path(),
                  pathPlusFileName_woext + "_" + mySuffix + ".png",
                  pathPlusFileName_woext + "_" + mySuffix);

              String line = ""; // String that holds current file line
              String accumulate = "";

              try {
                FileReader input = new FileReader(pathPlusFileName_woext + "_" + mySuffix + ".txt");
                BufferedReader bufRead = new BufferedReader(input);

                line = bufRead.readLine();

                while (line != null) {
                  accumulate += line;
                  line = bufRead.readLine();
                }

                bufRead.close();
                input.close();

              } catch (IOException e) {
                e.printStackTrace();
              }

              String[] requirements = myRequirements.split("#");
              for (String requirement : requirements) {
                if (requirement.equals(accumulate.trim())) {
                  templateName = file.getName();
                  templateIdentified = true;
                  return templateIdentified;
                }
              }
            }
          }
        }
      }

      // record end time
      long endTime = System.currentTimeMillis();
      System.out.println(
          "Template Search [" + fileName + "] " + (endTime - startTime) / 1000 + " seconds");

    } catch (Exception e) {
      e.printStackTrace();
    }

    return templateIdentified;
  }
  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;
  }