Package util.io

Examples of util.io.ExecutionHandler


    return true;
  }

  public void sendToKNotify(final String titleFormat, final String descriptionFormat, final Program program) {
    try {
      final ExecutionHandler executionHandler = new ExecutionHandler("dcop",
          "which");
      executionHandler.execute(true);

      String dcopLocation = executionHandler.getOutput();

      if (dcopLocation != null) {
        dcopLocation = dcopLocation.trim();
        if (dcopLocation.length() > 0) {
          // create the notification message
          if (mParser == null) {
            mParser = new ParamParser();
          }
          final String title = mParser.analyse(titleFormat,program);
          final String message = mParser.analyse(descriptionFormat, program);

          // run the notification command
          final String[] command = { dcopLocation, "knotify", "Notify",
              "notify", "event", title, message, "", "", "16", "0" };
          new ExecutionHandler(command).execute();
        }
      }
      else {
        mLog.warning("'dcop' command not found");
      }
View Full Code Here


      file.deleteOnExit();
     
      ICalFile ical = new ICalFile();
      ical.export(file, programs, settings, formating);
     
      new ExecutionHandler("--merge " + file.getAbsolutePath(), "korganizer").execute();
      return true;
    } catch (IOException e) {
      ErrorHandler.handle("Could not export to KOrganizer.", e);
      e.printStackTrace();
    }
View Full Code Here

          ParamParser parser = new ParamParser();
          String fParam = parser.analyse(
              mSettings.getProperty("execparam", ""), reminder.getProgram());

          try {
            ExecutionHandler executionHandler = new ExecutionHandler(fParam,
                fName);
            executionHandler.execute();
          } catch (Exception exc) {
            String msg = mLocalizer.msg("error.2",
                "Error executing reminder program!\n({0})", fName, exc);
            ErrorHandler.handle(msg, exc);
          }
View Full Code Here

    OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(scriptFile), "UTF-8");
    writer.write(script);
    writer.close();

    ExecutionHandler executionHandler = new ExecutionHandler(scriptFile.getAbsolutePath(), "osascript");
    executionHandler.execute(true, "UTF-8");

    int time = 0;

    // wait until the process has exited, max MaxTimouts

    if (mTimeOut > 0) {
      while (time < mTimeOut * 1000) {
        try {
          Thread.sleep(100);
        } catch (InterruptedException e1) {
        }
        time += 100;
        try {
          executionHandler.exitValue();
          break;
        } catch (IllegalThreadStateException e) {
        }
      }
    } else {
      while (true) {
        try {
          Thread.sleep(100);
        } catch (InterruptedException e1) {
        }
        try {
          executionHandler.exitValue();
          break;
        } catch (IllegalThreadStateException e) {
        }
      }
    }

    while (time < mTimeOut * 1000) {
      try {
        Thread.sleep(100);
      } catch (InterruptedException e1) {
      }
      time += 100;
      try {
        executionHandler.exitValue();
        break;
      } catch (IllegalThreadStateException e) {
      }
    }

    // get the process output
    String output = "";

    if (!executionHandler.getInputStreamReaderThread().isAlive()) {
      output = executionHandler.getOutput();
    }

    mLog.info("AppleScript Output:");
    mLog.info(output);

    if (executionHandler.exitValue() >= 0) {
      return output;
    }

    try {
      scriptFile.delete();
View Full Code Here

        String params = Settings.propUserDefinedWebbrowserParams.getString().replace("{0}", url);

        // Test if the JVM is a Mac-VM and the Application is an .app-File.
        // These Files must be launched differently
        if ((getOs() == OS_MAC) && (browserExecutable.trim().toLowerCase().endsWith(".app"))) {
          new ExecutionHandler(new String[] { "open", "-a", browserExecutable, params }).execute();
        } else {
          new ExecutionHandler(new String[] { browserExecutable, params }).execute();
        }
      } else {
        boolean opened = false;
        // Java 6 specific code of how to run the browser
        if (Desktop.isDesktopSupported()) {
View Full Code Here

                    aeDesc = null// Encourage it to get disposed if it was created
                    browser = null; // Ditto
                }
                break;
            case MRJ_2_1:
                new ExecutionHandler(new String[] { (String) browser, url }).execute();
                break;
            case MRJ_3_0:
                int[] instance = new int[1];
                int result = ICStart(instance, 0);
                if (result == 0) {
                    int[] selectionStart = new int[] { 0 };
                    byte[] urlBytes = url.getBytes();
                    int[] selectionEnd = new int[] { urlBytes.length };
                    result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes,
                                            urlBytes.length, selectionStart,
                                            selectionEnd);
                    if (result == 0) {
                        // Ignore the return value; the URL was launched successfully
                        // regardless of what happens here.
                        ICStop(instance);
                    } else {
                        throw new IOException("Unable to launch URL: " + result);
                    }
                } else {
                    throw new IOException("Unable to create an Internet Config instance: " + result);
                }
                break;
            case MRJ_3_1:
            case MRJ_COCOA:
                try {
                    openURL.invoke(null, new Object[] { url });
                } catch (InvocationTargetException ite) {
                    throw new IOException("InvocationTargetException while calling openURL: " + ite.getMessage());
                } catch (IllegalAccessException iae) {
                    throw new IOException("IllegalAccessException while calling openURL: " + iae.getMessage());
                }
                break;
            case WINDOWS_NT:
            case WINDOWS_9x:
                // Add quotes around the URL to allow ampersands and other special
                // characters to work.
                String[] arguments;
                if (jvm == WINDOWS_9x) {
                    arguments = new String[] { (String) browser,
                                          FIRST_WINDOWS_PARAMETER,
                                          SECOND_WINDOWS_PARAMETER,
                                          null };
                } else {
                    arguments = new String[] { (String) browser,
                                          FIRST_WINDOWS_PARAMETER,
                                          SECOND_WINDOWS_PARAMETER,
                                          THIRD_WINDOWS_PARAMETER,
                                          null };
                }
                arguments[arguments.length - 1] = '"' + url + '"';
                ExecutionHandler executionHandler = new ExecutionHandler(arguments);
                executionHandler.execute();
               
                // This avoids a memory leak on some versions of Java on Windows.
                // That's hinted at in <http://developer.java.sun.com/developer/qow/archive/68/>.
                try {
                    executionHandler.getProcess().waitFor();
                    executionHandler.exitValue();
                } catch (InterruptedException ie) {
                    throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
                }
                break;
            case OTHER:
                // Assume that we're on Unix and that Netscape is installed
               
                // Attempt to open the URL in a currently running session of Netscape
                executionHandler = new ExecutionHandler(new String[] { (String) browser,
                                                    NETSCAPE_REMOTE_PARAMETER,
                                                    NETSCAPE_OPEN_PARAMETER_START +
                                                    url +
                                                    NETSCAPE_OPEN_PARAMETER_END });
                executionHandler.execute();
               
                try {
                    int exitCode = executionHandler.getProcess().waitFor();
                    if (exitCode != 0) {    // if Netscape was not open
                        new ExecutionHandler(new String[] { (String) browser, url }).execute();
                    }
                } catch (InterruptedException ie) {
                    throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
                }
                break;
            default:
                // This should never occur, but if it does, we'll try the simplest thing possible
                new ExecutionHandler(new String[] { (String) browser, url }).execute();
                break;
        }
    }
View Full Code Here

   * @param params
   *          Params for the Application
   * @return Output of Application
   */
  private String executeApplication(String params) {
    ExecutionHandler executionHandler;

    try {
      executionHandler = new ExecutionHandler(params, mData.getProgramPath());
      executionHandler.execute(true, true);
    } catch (Exception e) {
      ErrorHandler.handle(mLocalizer.msg("ProblemAtStart", "Problems while starting Application."), e);
      return null;
    }

    int time = 0;

    // wait until the process has exited, max MaxTimouts

    if (mData.getTimeout() > 0) {
      while (time < mData.getTimeout() * 1000) {
        try {
          Thread.sleep(100);
          time += 100;
          executionHandler.exitValue();
          break;
        } catch (Exception e) {
          // Empty
        }
      }
    } else {
      while (true) {
        try {
          Thread.sleep(100);
          executionHandler.exitValue();
          break;
        } catch (Exception e) {
          // Empty
        }
      }
    }

    while (time < mData.getTimeout() * 1000) {
      try {
        Thread.sleep(100);
        time += 100;
        executionHandler.exitValue();
        break;
      } catch (Exception e) {
        // Empty
      }
    }

    // get the process output
    String output = "";
    String errors = ""; // also capture STDERR output FSCHAECK - 2008-06-13

    if (!executionHandler.getInputStreamReaderThread().isAlive()) {
      output = executionHandler.getOutput();
    }

    // read STDERR output and add to return value if necessary - FSCHAECK -
    // 2008-06-13
    if (!executionHandler.getErrorStreamReaderThread().isAlive()) {
      errors = executionHandler.getOutput();
      if (errors.length() > 0) {
        if (output.length() > 0) {
          output = output + "\n\n" + errors;
        } else {
          output = errors;
        }
      }
    }

    mError = executionHandler.exitValue() != 0;
    mExitValue = executionHandler.exitValue();

    return output;
  }
View Full Code Here

      } else {
        application = mSettings.getApplication();
        execparam = getContentParameter(content);
      }

      new ExecutionHandler(execparam, application).execute();

      if (mSettings.getShowEmailOpened()) {
        showEMailOpenedDialog(parent);
      }
View Full Code Here

TOP

Related Classes of util.io.ExecutionHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.