/** Writes the data provenance into xml formatted file */
  public void writeXML() throws IOException {
    FileWriter fw;
    if (file.exists() == true) {
      file.delete();
      file = new File(fileDir + File.separator + fileName);
    }

    try {

      fw = new FileWriter(file);
      bw = new BufferedWriter(fw);

      Vector<XMLAttributes> atVector = new Vector<XMLAttributes>();

      bw.write(XML_HEADER);
      bw.newLine();
      bw.write(DATA_PROVENANCE);
      bw.newLine();

      openTag("provenance", true);

      int numEntries = pHolder.size();

      ProvenanceEntry entry;

      for (int i = 0; i < numEntries; i++) {
        entry = pHolder.elementAt(i);

        openTag("processStep", true);

        atVector.add(new XMLAttributes("version", entry.getMipavVersion()));
        this.closedTag("program", entry.getProgramName(), atVector);

        atVector.add(new XMLAttributes("inputs", entry.getProgramInputs()));
        closedTag("programArguments", entry.getAction(), atVector);

        closedTag("timeStamp", entry.getTimeStamp());

        closedTag("user", entry.getUser());

        closedTag("hostName", entry.getHostName());

        closedTag("architecture", entry.getArchitecture());

        atVector.add(new XMLAttributes("version", entry.getPlatformVersion()));
        closedTag("platform", entry.getPlatform(), atVector);

        atVector.add(new XMLAttributes("version", entry.getJavaVersion()));
        closedTag("compiler", "java", atVector);

        openTag("processStep", false);
      }

      openTag("provenance", false);
      bw.close();
    } catch (Exception e) {
      System.err.println("CAUGHT EXCEPTION WITHIN writeXML() of FileDataProvenance");
      e.printStackTrace();
    }
  }
Beispiel #2
0
  public void execute() throws Exception {
    getNewCount();
    File executable = new File(getEXEPath());
    if (!executable.exists())
      throw new FileNotFoundException("executable file does not exist! " + executable);
    workingDir = getWorkingDirectory(executable);
    initExecution();

    instruction = getInstructionFileName(workingDir);
    output = getOutputFileName(workingDir);
    createInstructionFile(instruction);
    // Profiler pofiler = new Profiler();
    // profiler.start("exec-ilink-search " + xmlFileName, "exec-ilink-search " + xmlFileName);
    ExecShell shell = new ExecShell();
    shell.setExecutable(executable.getAbsolutePath());
    shell.setWorkingDirectory(workingDir);
    setArguments(shell);
    shell.addCommandLineArgument(executable.getParent());
    shell.execute();

    // profiler.start("exec-ilink-search " + xmlFileName, "shell-wait-for");
    exitCode = shell.timeout(timeout);
    // profiler.stop("exec-ilink-search " + xmlFileName, "shell-wait-for");
    // instructionFile.delete();
    handleResponse(output);
    finishExecution();
    if (zws.Server.debugMode()) return;
    // cleanup
    File[] contents = workingDir.listFiles();
    for (int idx = 0; idx < contents.length; contents[idx++].delete()) ;
    workingDir.delete();
  }
 public boolean accept(File pathname) {
   if (pathname.isDirectory()) return true;
   else {
     if (pathname.getName().indexOf(".scl") != -1) return true;
     else return false;
   }
 }
Beispiel #4
0
  private void tidyUnicode(String filename) {
    FileInputStream in = null;
    FileOutputStream out = null;
    InputStreamReader reader = null;
    OutputStreamWriter writer = null;
    File f0 = new File(filename + "0");
    File f1 = new File(filename);
    f1.renameTo(f0);
    try {
      in = new FileInputStream(f0);
      reader = new InputStreamReader(in);
      out = new FileOutputStream(f1);
      writer = new OutputStreamWriter(out);
      UTF8Tidy u = new UTF8Tidy(reader, writer);
      u.execute();
    } catch (Exception e) {
      {
      } // System.out.println("e: " + e ); }

    } finally {
      try {
        reader.close();
        writer.close();
      } catch (Exception ex) {
        ex.printStackTrace();
      }
      f0.delete();
    }
  }
Beispiel #5
0
 public void load(File xml, File mapping)
     throws SAXException, ParserConfigurationException, IOException {
   System.out.println("Loading " + xml.getPath() + " with " + mapping.getPath());
   XMLValidator.validate(xml, false);
   TagMap loader = new TagMap();
   loader.load(mapping, actionMap, targetMap, attributeMaps);
   getParser(false).parse(xml, new Parser(actionMap, targetMap, attributeMaps));
   {
   } // System.out.println("---------------------------------------------------------------------------------------");
 }
 /**
  * Write the component descriptors to the file.
  *
  * @param components
  * @param file
  * @throws SCRDescriptorException
  */
 public static void write(Components components, File file, boolean isScrPrivateFile)
     throws SCRDescriptorException {
   try {
     generateXML(components, IOUtils.getSerializer(file), isScrPrivateFile);
   } catch (TransformerException e) {
     throw new SCRDescriptorException("Unable to write xml", file.toString(), 0, e);
   } catch (SAXException e) {
     throw new SCRDescriptorException("Unable to generate xml", file.toString(), 0, e);
   } catch (IOException e) {
     throw new SCRDescriptorException("Unable to write xml", file.toString(), 0, e);
   }
 }
Beispiel #7
0
  /**
   * EPML2PNML
   *
   * @param args String[]
   */
  private static void EPML2PNML(String[] args) {
    if (args.length != 2) {
      System.out.println("���ṩEPML�ļ�·����PNML���Ŀ¼!");
      System.exit(-1);
    }
    epmlImport epml = new epmlImport();
    // load the single epml file
    String filename = args[0];
    try {
      EPCResult epcRes = (EPCResult) epml.importFile(new FileInputStream(filename));
      // convert all epc models to pnml files
      ArrayList<ConfigurableEPC> alEPCs = epcRes.getAllEPCs();
      PnmlExport export = new PnmlExport();
      for (ConfigurableEPC epc : alEPCs) {
        String id = epc.getIdentifier();
        if (id.equals("1An_klol")
            || id.equals("1An_l1y8")
            || id.equals("1Ex_dzq9")
            || id.equals("1Ex_e6dx")
            || id.equals("1Ku_9soy")
            || id.equals("1Ku_a4cg")
            || id.equals("1Or_lojl")
            || id.equals("1Pr_d1ur")
            || id.equals("1Pr_djki")
            || id.equals("1Pr_dkfa")
            || id.equals("1Pr_dl73")
            || id.equals("1Ve_musj")
            || id.equals("1Ve_mvwz")) continue;
        // save pnml files to the same folder
        File outFile = new File(args[1] + "/" + id + ".pnml");
        if (outFile.exists()) continue;
        FileOutputStream fos = new FileOutputStream(outFile);
        PetriNet petri = AMLtoPNML.convert(epc);
        try {
          export.export(new ProvidedObject("PetriNet", new Object[] {petri}), fos);
        } catch (Exception ex1) {
          ex1.printStackTrace(System.out);
        }
      }
    } catch (IOException ex) {
      ex.printStackTrace(System.out);
    }

    System.out.println("EPML Conversion Done");
  }
Beispiel #8
0
 private static InputSource getConfigSource(Class pAppClass) throws DataNotFoundException {
   URL resource = pAppClass.getResource(CONFIG_FILE_NAME);
   String resourceFileName = resource.toExternalForm();
   File resourceFile = new File(resourceFileName);
   InputStream configResourceStream = pAppClass.getResourceAsStream(CONFIG_FILE_NAME);
   if (null == configResourceStream) {
     throw new DataNotFoundException(
         "unable to find XML configuration file resource: "
             + CONFIG_FILE_NAME
             + " for class: "
             + pAppClass.getName());
   }
   InputSource inputSource = new InputSource(configResourceStream);
   if (!resourceFile.exists()) {
     inputSource.setSystemId(resourceFileName);
   }
   return (inputSource);
 }
Beispiel #9
0
  public static AppConfig get(Class pAppClass, String pAppDir)
      throws DataNotFoundException, InvalidInputException, FileNotFoundException {

    AppConfig appConfig = null;
    if (null == pAppDir) {
      // we don't know where we are installed, so punt and look for
      // the config file as a class resource:
      appConfig = new AppConfig(pAppClass);
    } else {
      File appDirFile = new File(pAppDir);
      if (!appDirFile.exists()) {
        throw new DataNotFoundException("could not find application directory: " + pAppDir);
      }
      String configFileName =
          appDirFile.getAbsolutePath() + "/config/" + AppConfig.CONFIG_FILE_NAME;
      appConfig = new AppConfig(new File(configFileName));
    }
    return appConfig;
  }
Beispiel #10
0
 private void execExtractor() throws Exception {
   ExecShell shell = new ExecShell();
   File f = new File(Config.getProperty(Config.EXE_ILINK_SEARCH));
   if (!f.exists())
     throw new Exception(
         "executable file does not exist! " + Config.getProperty(Config.EXE_ILINK_SEARCH));
   shell.setExecutable(f.getAbsolutePath());
   shell.setWorkingDirectory(f.getParent());
   shell.addCommandLineArgument(criteria);
   shell.addCommandLineArgument(String.valueOf(maxCount));
   shell.addCommandLineArgument(releaseLevel);
   shell.addCommandLineArgument(metadataSpec);
   shell.addCommandLineArgument(username);
   shell.addCommandLineArgument(password);
   shell.addCommandLineArgument(outputFile);
   shell.addCommandLineArgument(proiTkEnv);
   shell.execute();
   exitCode = shell.waitFor();
 }
Beispiel #11
0
 private File getWorkingDirectory(File f) {
   try {
     File workingDir =
         new File(
             Properties.get(Names.WORKING_DIR)
                 + Names.PATH_SEPARATOR
                 + getOpType()
                 + Names.PATH_SEPARATOR
                 + "work"
                 + getNewCount());
     if (!workingDir.exists()) workingDir.mkdirs();
     FileUtil.deleteContents(workingDir);
     return workingDir;
   } catch (Exception ignore) {
     // ++ notify of error - maybe out of disk space
     ignore.printStackTrace();
     return null;
   }
 }
Beispiel #12
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");
  }
Beispiel #13
0
  /**
   * opens existing file
   *
   * @param a_file
   */
  public GlyphFile(File a_file) {
    super();

    m_fileName = a_file;

    URL url = null;

    try {
      url = a_file.toURI().toURL();
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }

    init(url);
  }
Beispiel #14
0
 public String getShortFileName() {
   return m_fileName.getName();
 }
 public void saveUnsaved() throws SaveAbortedException {
   if (!saved) {
     int option = 0;
     if (loadedFile == null)
       option =
           JOptionPane.showConfirmDialog(
               this,
               new JLabel("Save changes to UNTITLED?"),
               "Warning",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.WARNING_MESSAGE);
     else
       option =
           JOptionPane.showConfirmDialog(
               this,
               new JLabel("Save changes to " + loadedFile.getName() + "?"),
               "Warning",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.WARNING_MESSAGE);
     if (option == JOptionPane.YES_OPTION) {
       if (loadedFile == null) // SAVE NEW FILE
       {
         if (nameTF.getText().equals("")) {
           JOptionPane.showMessageDialog(
               this,
               new JLabel("Please type in the Scale Name"),
               "Warning",
               JOptionPane.WARNING_MESSAGE);
           throw new SaveAbortedException();
         }
         fileChooser.setFileFilter(filter);
         int option2 = fileChooser.showSaveDialog(this);
         if (option2 == JFileChooser.APPROVE_OPTION) {
           File target = fileChooser.getSelectedFile();
           try {
             PrintStream stream = new PrintStream(new FileOutputStream(target), true);
             save(stream);
             stream.close();
           } catch (Exception ex) {
             JOptionPane.showMessageDialog(
                 this,
                 new JLabel("Error: " + ex.getMessage()),
                 "Error",
                 JOptionPane.ERROR_MESSAGE);
           }
         } else throw new SaveAbortedException();
         ;
       } else // save LOADED FILE
       {
         try {
           PrintStream stream = new PrintStream(new FileOutputStream(loadedFile), true);
           save(stream);
           stream.close();
         } catch (Exception ex) {
           JOptionPane.showMessageDialog(
               this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
         }
       }
     } else if (option == JOptionPane.CANCEL_OPTION) throw new SaveAbortedException();
     ;
   }
 }
Beispiel #16
0
 protected String getInstructionFileName(File f) {
   return f.getAbsolutePath() + Names.PATH_SEPARATOR + "instruction.xml";
 }
Beispiel #17
0
 protected String getOutputFileName(File f) {
   return f.getAbsolutePath() + Names.PATH_SEPARATOR + "response.xml";
 }
 /**
  * Initializes the <code>TextTransition</code> by the File <code>file</code>.
  *
  * @param file
  * @exception IOException
  * @exception SAXException
  * @exception ParserConfigurationException
  */
 public void setup(File file) throws IOException, SAXException, ParserConfigurationException {
   setup(file.toURL());
 }
  public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource();
    if (b.getText() == "PLAY") {
      if (scoreP != null) scoreP.playScale(sp.getScale(), tempoP.getValue());
    } else if (b.getText() == "New") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      sp.notes.removeAllElements();
      sp.repaint();
      nameTF.setText("");
      loadedFile = null;
    } else if (b.getText() == "Save") {
      if (nameTF.getText().equals("")) {
        JOptionPane.showMessageDialog(
            this,
            new JLabel("Please type in the Scale Name"),
            "Warning",
            JOptionPane.WARNING_MESSAGE);
        return;
      }
      fileChooser.setFileFilter(filter);
      int option = fileChooser.showSaveDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        File target = fileChooser.getSelectedFile();
        if (target.getName().indexOf(".scl") == -1) target = new File(target.getPath() + ".scl");
        try {
          PrintStream stream = new PrintStream(new FileOutputStream(target), true);
          save(stream);
          stream.close();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
        }
      }
    } else if (b.getText() == "Load") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      fileChooser.setFileFilter(filter);
      int option = fileChooser.showOpenDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        loadedFile = fileChooser.getSelectedFile();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        ScaleParser handler = new ScaleParser(false);
        try {
          SAXParser parser = factory.newSAXParser();
          parser.parse(loadedFile, handler);
          // System.out.println("success");
        } catch (Exception ex) {
          // System.out.println("no!!!!!! exception: "+e);
          // System.out.println(ex.getMessage());
          ex.printStackTrace();
        }
        // -----now :P:P---------------
        System.out.println("name: " + handler.getName());
        nameTF.setText(handler.getName());
        sp.notes.removeAllElements();
        int[] scale = handler.getScale();
        for (int i = 0; i < scale.length; i++) {
          sp.addNote(scale[i]);
        }
        sp.repaint();
      } else loadedFile = null;
    }
  }