private static void getStudentPass(String facultyNumber)
     throws IOException, JAXBException, SAXException, TransformerException,
         ParserConfigurationException {
   if (Pattern.matches("\\d{5,6}", facultyNumber)) {
     InputStream inputStream = new FileInputStream(Constants.CONFIG_FILE_PATH.toString());
     properties.load(inputStream);
     File protocolFile = new File(properties.getProperty("protocol"));
     ReadWriteUtils utils = new ReadWriteUtils(Protocol.class);
     Protocol protocol = (Protocol) utils.readFromXml(protocolFile);
     StudentPass studentPass = protocol.getStudentPass(Integer.parseInt(facultyNumber));
     utils.setType(StudentPass.class);
     File outputFile =
         new File(properties.getProperty("output") + "\\StudentPass" + facultyNumber + ".xml");
     if (outputFile.createNewFile()) System.out.println("File created!");
     utils.writeXml(studentPass, outputFile);
     utils.writeXml(studentPass, System.out);
     System.out.println(
         "Do you want to open the generated XML Document with your default viewing program?");
     if (awaitResponse()) Desktop.getDesktop().open(outputFile);
     System.out.println(
         "Do you want to transform the generated XML Document to html file and open with your default viewing program?");
     if (awaitResponse()) {
       Desktop.getDesktop()
           .open(transformXML(outputFile, new File(Constants.STUDENT_STYLE.toString())));
     }
     inputStream.close();
   } else throw new IllegalArgumentException("Invalid faculty number is entered!");
 }
 /**
  * 抓屏方法
  *
  * @see 该方法抓的是全屏,并且当传入的fileName参数为空时会将抓屏图片默认保存到用户桌面上
  * @param fileName 抓屏后的图片保存名称(含保存路径及后缀),传空时会把图片自动保存到桌面
  * @param isAutoOpenImage 是否自动打开图片
  * @return 抓屏成功返回true,反之false
  */
 public static boolean captureScreen(String fileName, boolean isAutoOpenImage) {
   if (isEmpty(fileName)) {
     String desktop = FileSystemView.getFileSystemView().getHomeDirectory().getPath();
     String separator = System.getProperty("file.separator");
     String imageName = "截屏_" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".png";
     fileName = desktop + separator + imageName;
   }
   String fileSuffix = fileName.substring(fileName.lastIndexOf(".") + 1);
   File file = new File(fileName);
   // 获取屏幕大小
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   Rectangle screenRectangle = new Rectangle(screenSize);
   try {
     Robot robot = new Robot();
     BufferedImage image = robot.createScreenCapture(screenRectangle);
     ImageIO.write(image, fileSuffix, file);
     // 自动打开图片
     if (isAutoOpenImage) {
       if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
         Desktop.getDesktop().open(file);
       }
     }
   } catch (AWTException e) {
     return false;
   } catch (IOException e) {
     return false;
   }
   return true;
 }
  @Override
  public void HUDAreaClicked(HUDArea ha) {
    HUDArea hudArea = null;

    for (int i = 0; i < hudAreas.size(); i++) {
      hudArea = hudAreas.get(i);
      if (hudArea == ha) {
        if (hudArea.getType().equals("single_player")) {
          hudManager.unloadHUD(name);
          hudManager.loadHUD(HUDManager.HUDType.ScreenCharacterSelection);
        } else if (hudArea.getType().equals("multi_player")) {
          if (hudManager.getIsOnline() && Game.VERSION.equals(hudManager.getCurrentVersion())) {
            hudManager.unloadHUD(name);
            hudManager.loadHUD(HUDManager.HUDType.ScreenMultiPlayer);
          } else {
            registry.showMessage(
                "Error",
                "Must be online and have latest version to play.  Try updating and restarting.");
          }
        } else if (hudArea.getType().equals("settings")) {
          hudManager.unloadHUD(name);
          hudManager.loadHUD(HUDManager.HUDType.ScreenSettings);
        } else if (hudArea.getType().equals("exit")) {
          hudManager.gameExit();
        } else if (hudArea.getType().equals("donate")) {
          String url = "http://www.epicinventor.com/donate.html";

          try {
            Desktop.getDesktop().browse(java.net.URI.create(url));
          } catch (Exception e) {
          }
        } else if (hudArea.getType().equals("help")) {
          String url = "http://www.epicinventor.com/help.html";

          try {
            Desktop.getDesktop().browse(java.net.URI.create(url));
          } catch (Exception e) {
          }
        } else if (hudArea.getType().equals("download")) {
          Process p = null;
          try {
            p = Runtime.getRuntime().exec("EpicInventorUpdater");
          } catch (IOException ex) {
          }

          if (p == null) {
            registry.showMessage(
                "Error", "Could not launch auto-updater, run manually from folder");
          } else {
            hudManager.gameExit();
          }
        }
      }
    }
  }
Beispiel #4
0
 /**
  * Attempts to open the default web browser to the given URL.
  *
  * @param url The URL to open
  * @throws IOException If the web browser could not be located or does not run
  */
 public static void openURL(String url) throws IOException {
   if (!(Desktop.isDesktopSupported()
       && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE))) {
     openURL_old(url);
   } else {
     try {
       Desktop.getDesktop().browse(new URI(url));
     } catch (URISyntaxException e) {
       log.error("Error opening url " + url, e);
     }
   }
 }
 /**
  * Tries to open a URL in the Browser
  *
  * @param url The URL
  * @param shiftUrl The URL to open when Shift is held
  */
 public static void openBrowser(String url, String shiftUrl) {
   try {
     if (Desktop.isDesktopSupported()) {
       if (shiftUrl.equals(url) || KeyUtil.isShiftPressed()) {
         Desktop.getDesktop().browse(new URI(shiftUrl));
       } else {
         Desktop.getDesktop().browse(new URI(url));
       }
     }
   } catch (Exception e) {
     ModUtil.LOGGER.error("Something bad happened when trying to open a URL!", e);
   }
 }
 private void pHbackground1MouseClicked(
     java.awt.event.MouseEvent evt) { // GEN-FIRST:event_pHbackground1MouseClicked
   Point p = evt.getPoint();
   try {
     if (p.x >= 17 && p.y >= 24 && p.x <= 452 && p.y <= 56) {
       Desktop.getDesktop()
           .browse(new URI("http://www.dig.com.pl/index.php?s=wyniki&rodz=9&id=15"));
     } else if (p.x >= 525 && p.y >= 22 && p.x <= 679 && p.y <= 51) {
       Desktop.getDesktop().browse(new URI("http://bazhum.muzhp.pl/"));
     } else if (p.x >= 738 && p.y >= 7 && p.x <= 788 && p.y <= 55) {
       Desktop.getDesktop().browse(new URI("http://www.muzhp.pl/"));
     }
   } catch (Exception e) {
   }
 } // GEN-LAST:event_pHbackground1MouseClicked
Beispiel #7
0
  private void facebookConnect() throws FacebookException {
    // auth.createToken returns a string
    // http://wiki.developers.facebook.com/index.php/Auth.createToken
    facebookAuthToken = facebookClient.executeQuery("auth.createToken", String.class);
    String url =
        "http://www.facebook.com/login.php"
            + "?api_key="
            + FACEBOOK_API_KEY
            + "&fbconnect=true"
            + "&v=1.0"
            + "&connect_display=page"
            + "&session_key_only=true"
            + "&req_perms=read_stream,publish_stream,offline_access"
            + "&auth_token="
            + facebookAuthToken;

    // Here we launch a browser with the above URL so the user can login to Facebook, grant our
    // requested permissions and send our token for pickup later
    if (Desktop.isDesktopSupported()) {
      Desktop desktop = Desktop.getDesktop();

      if (desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
          desktop.browse(new URI(url));
        } catch (IOException ioe) {
          ioe.printStackTrace();
        } catch (URISyntaxException use) {
          use.printStackTrace();
        }
      }
    }
  }
  private static void openBrowser(OAuthV1 oAuth) {

    String authorizationUrl = OAuthV1Client.generateAuthorizationURL(oAuth);

    System.out.println("Get verification code......");
    if (!java.awt.Desktop.isDesktopSupported()) {

      System.err.println("Desktop is not supported (fatal)");
      System.exit(1);
    }
    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
    if (desktop == null || !desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {

      System.err.println("Desktop doesn't support the browse action (fatal)");
      System.exit(1);
    }
    try {
      desktop.browse(new URI(authorizationUrl));
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    } catch (URISyntaxException e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
  public HyberLinkLabel(String text, String url) {
    this.text = text;
    this.url = url;
    try {
      this.isSupported =
          Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE);
    } catch (Exception e) {
      System.out.println("Browse is not supported");
      this.isSupported = false;
    }
    setActive(false);
    addMouseListener(
        new MouseAdapter() {
          public void mouseEntered(MouseEvent e) {
            setActive(isSupported);
            if (isSupported) setCursor(new Cursor(Cursor.HAND_CURSOR));
          }

          public void mouseExited(MouseEvent e) {
            setActive(false);
          }

          public void mouseClicked(MouseEvent e) {
            try {
              Desktop.getDesktop().browse(new java.net.URI(HyberLinkLabel.this.url));
            } catch (Exception ex) {
              System.out.println(ex.toString());
            }
          }
        });
  }
Beispiel #10
0
 // Opens default browser and loads this projects github page.
 public static void openGit() {
   try {
     Desktop.getDesktop().browse(new URL("https://github.com/skelegon/Vidor").toURI());
   } catch (URISyntaxException | IOException ex) {
     ex.printStackTrace();
   }
 }
Beispiel #11
0
 public void actionPerformed(ActionEvent event) {
   Logger log = Logger.getLogger(DebugShowLogFile.class);
   String logFile = Logging.getLogFile();
   if (logFile == null) {
     log.error("No file logger configured");
     JOptionPane.showMessageDialog(
         MainGUI.getMainGUI(),
         I18nUtils.localizedStringForKey("msg_no_log_file_config"),
         I18nUtils.localizedStringForKey("Error"),
         JOptionPane.ERROR_MESSAGE);
     return;
   }
   File f = new File(logFile);
   if (!f.isFile()) {
     log.error("Log file does not exists: " + f.getAbsolutePath());
     JOptionPane.showMessageDialog(
         MainGUI.getMainGUI(),
         String.format(I18nUtils.localizedStringForKey("msg_no_log_file"), f.getAbsolutePath()),
         I18nUtils.localizedStringForKey("Error"),
         JOptionPane.ERROR_MESSAGE);
     return;
   }
   try {
     Desktop.getDesktop().open(f);
   } catch (IOException e) {
     GUIExceptionHandler.processException(e);
   }
 }
Beispiel #12
0
 public void openFile(int index) {
   try {
     Desktop.getDesktop().open(new File(data.get(index).getFileURI()));
   } catch (IOException e) {
     logger.fatal("openFile:", e);
   }
 }
Beispiel #13
0
    @Override
    public void actionPerformed(ActionEvent e) {

      if (e.getSource() == start) {

        System.out.println("id List: " + Setup.getMainPanel().getTopLeftPanel().getIdsFile());
        System.out.println("Prize Log: " + Setup.getMainPanel().getTopLeftPanel().getPrizesFile());

        if (Setup.getMainPanel().getTopRightPanel().isGlobalSerEnabled()) {

          System.out.println(
              "Global serial: " + Setup.getMainPanel().getTopRightPanel().getGlobalSer());
        }

        Setup.dispose();
      }

      if (e.getSource() == help) {

        try {

          java.awt.Desktop.getDesktop()
              .browse(
                  java.net.URI.create(
                      "http://www.powerbot.org/community/topic/755991-squeal-of-fortune-spinner/"));

        } catch (IOException e1) {

          e1.printStackTrace();
        }
      }
    }
 private static void getProtocol()
     throws IOException, JAXBException, SAXException, ParserConfigurationException,
         TransformerException {
   InputStream inputStream = new FileInputStream(Constants.CONFIG_FILE_PATH.toString());
   properties.load(inputStream);
   File protocolFile = new File(properties.getProperty("protocol"));
   ReadWriteUtils utils = new ReadWriteUtils(Protocol.class);
   utils.writeXml(utils.readFromXml(protocolFile), System.out);
   System.out.println("Do you want to open protocol with your default viewing program?");
   if (awaitResponse()) Desktop.getDesktop().open(protocolFile);
   System.out.println(
       "Do you want to transform and open the protocol file with your default viewing program?");
   if (awaitResponse())
     Desktop.getDesktop()
         .open(transformXML(protocolFile, new File(Constants.PROTOCOL_STYLE.toString())));
 }
  // eventMenuPopup ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  private void eventMenuPopup() {

    try {

      URI uri = new URI(Data.WIKI_URL + underscoreName(getWikiTopic()));
      Desktop desktop = null;
      if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
      } // if

      if (desktop != null) {
        desktop.browse(uri);
      } // if

    } // try
    catch (IOException error) {
      JOptionPane.showMessageDialog(
          Data.getView(),
          "^Wiki Error: " + error.getMessage(),
          "Wiki Error: " + Data.APP_TITLE,
          JOptionPane.ERROR_MESSAGE);
    } // catch
    catch (URISyntaxException error) {
      JOptionPane.showMessageDialog(
          Data.getView(),
          "@Wiki Error: " + error.getMessage(),
          "Wiki Error: " + Data.APP_TITLE,
          JOptionPane.ERROR_MESSAGE);
    } // catch
  } // eventMenuPopup ----------------------------------------------------------
  public static Process launch(String path, boolean detached) throws InterruptedException {
    Process p = null;
    if (detached) {
      File f = new File(path);
      try {
        Desktop.getDesktop().open(f);
      } catch (IOException e) {
        e.printStackTrace();
      }
      return p;
    }

    // else
    try {
      p = Runtime.getRuntime().exec(path);
      new Thread(new ProcessDestroyWatcher(p)).start();
      // new Thread(new ProcessHandler(p, ProcessHandler.typeHandler.STANDARD)).start(); // Xming
      // n'utilise que la sortie d'erreur
      new Thread(new ProcessHandler(p, ProcessHandler.typeHandler.ERROR)).start();
      p.destroy();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return p;
  }
  // ******************* CONSTRUCTORS *******************
  public WordTemplateGenerator() {
    // Read and store course evaluation questions
    readQuestionsFromFile();

    // Used to open files
    desktop = Desktop.getDesktop();
  }
  public void SimpleReportDiretoPdf() {

    JasperPrint jp = null;
    try {

      JRDataSource customDs = new CustomBs();

      jp = JasperFillManager.fillReport(arq, null, customDs);

      JasperViewer jasperViewer = new JasperViewer(jp);

      jasperViewer.setBounds(50, 50, 320, 240);
      jasperViewer.setLocationRelativeTo(null);
      jasperViewer.setExtendedState(JFrame.MAXIMIZED_BOTH);

      jasperViewer.setVisible(true);

      JasperExportManager.exportReportToPdfFile(jp, OUT_PDF);

      JOptionPane.showMessageDialog(
          null,
          "<html>Arquivo exportado para PDF!<br><br>A aplicação vai pedir"
              + " ao Sistema operacional <br>para abrir com o visualizador"
              + " padrão.");

      Desktop.getDesktop().open(new File(OUT_PDF));

    } catch (JRException ex) {
      ex.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
 private static void openUpWebSite(String url) {
   Desktop d = Desktop.getDesktop();
   try {
     d.browse(new URI(url));
   } catch (Exception e) {
   }
 }
Beispiel #20
0
  void searchName(String nameToMatch) {
    URI url;

    try {
      // We should look up the miITIS_TSN status, but since we don't
      // have any options there ...
      url = new URI("http", "www.google.com", "/search", "q=" + nameToMatch);
      // I think the URI handles the URL encoding?

    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }

    try {
      Desktop desktop = Desktop.getDesktop();
      desktop.browse(url);

    } catch (IOException e) {
      MessageBox.messageBox(
          mainFrame,
          "Could not open URL '" + url + "'",
          "The following error occurred while looking up URL '" + url + "': " + e.getMessage(),
          MessageBox.ERROR);
    }
  }
Beispiel #21
0
  public boolean connect() throws InterruptedException {
    twitter = new TwitterFactory().getInstance();
    twitter.setOAuthConsumer(TwitterApp.CONSUMER_KEY, TwitterApp.CONSUMER_SECRET);
    Session session = HibernateUtil.openSession();
    while (true) {
      try {
        RequestToken requestToken = twitter.getOAuthRequestToken();
        AccessToken accessToken = getAccessToken(session, TwitterApp.TWITTER_USER);
        while (null == accessToken) {
          Desktop.getDesktop().browse(new URI(requestToken.getAuthorizationURL()));
          String pin =
              JOptionPane.showInputDialog(
                  null, "Insert OAuth Twitter PIN", "Twitter", JOptionPane.ERROR_MESSAGE);
          accessToken = twitter.getOAuthAccessToken(requestToken, pin);
          if (accessToken != null)
            saveAccessToken(session, accessToken.getToken(), accessToken.getTokenSecret());
        }

        twitter =
            new TwitterFactory()
                .getOAuthAuthorizedInstance(
                    TwitterApp.CONSUMER_KEY, TwitterApp.CONSUMER_SECRET, accessToken);
      } catch (Exception e) {
        System.err.println(e.getMessage());
        session.close();
        Thread.sleep(60000);
        return false;
      }
      session.close();
      return true;
    }
  }
Beispiel #22
0
  void lookUpTaxonID(String taxonID) {
    URI url;

    try {
      // We should look up the miITIS_TSN status, but since we don't
      // have any options there ...
      url =
          new URI(
              "http://www.itis.gov/servlet/SingleRpt/SingleRpt?search_topic=TSN&search_value="
                  + taxonID);
    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }

    try {
      Desktop desktop = Desktop.getDesktop();
      desktop.browse(url);

    } catch (IOException e) {
      MessageBox.messageBox(
          mainFrame,
          "Could not open URL '" + url + "'",
          "The following error occurred while looking up URL '" + url + "': " + e.getMessage(),
          MessageBox.ERROR);
    }
  }
  public static void openURL(String url) {

    try {
      // Since Java6 this is a much easier method to open the browser
      if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        desktop.browse(new URI(url));
      }

      // Only if desktop is not supported we try the old main specific code
      else {
        if (SystemInfo.OS == Os.MAC) {
          Class<?> fileMgr = Class.forName("com.apple.eio.FileManager");
          Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
          openURL.invoke(null, new Object[] {url});
        } else if (SystemInfo.OS == Os.WINDOWS)
          Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
        else { // assume Unix or Linux
          String[] browsers = {"firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape"};
          String browser = null;
          for (int count = 0; (count < browsers.length) && (browser == null); count++)
            if (Runtime.getRuntime().exec(new String[] {"which", browsers[count]}).waitFor() == 0)
              browser = browsers[count];
          if (browser == null) throw new Exception("Could not find web browser");
          else Runtime.getRuntime().exec(new String[] {browser, url});
        }
      }
    } catch (Exception e) {
      log.error("Error at opening the URL.", e);
    }
  }
 private void prepareMailAll() {
   // TODO Auto-generated method stub
   String list = "";
   for (DimensionsUser user : users) {
     //					list += user.getUserId()+"@ac.bankit.it";
     list += user.getUserId();
     list += ";";
   }
   GestConfFrame.getInstance().cmdOutAppend("\n" + list);
   Desktop desktop;
   if (Desktop.isDesktopSupported()
       && (desktop = Desktop.getDesktop()).isSupported(Desktop.Action.MAIL)) {
     URI mailto = null;
     try {
       mailto = new URI("mailto:" + list + "?subject=Hello%20World");
     } catch (URISyntaxException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     try {
       desktop.mail(mailto);
     } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   } else {
     // TODO fallback to some Runtime.exec(..) voodoo?
     throw new RuntimeException("desktop doesn't support mailto; mail is dead anyway ;)");
   }
   setVisible(false);
 }
Beispiel #25
0
  public static void main(String[] args) {

    if (!java.awt.Desktop.isDesktopSupported()) {

      System.err.println("Desktop is not supported (fatal)");
      System.exit(1);
    }

    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

    if (!desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {

      System.err.println("Desktop doesn't support the browse action (fatal)");
      System.exit(1);
    }

    try {

      java.net.URI uri = new java.net.URI("http://www.d3js.org");
      desktop.browse(uri);
    } catch (Exception e) {

      System.err.println(e.getMessage());
    }
  }
  public void EVENT_openfile(ActionEvent e) {
    int selection[] = table.getSelectedRows();

    if (selection == null || selection.length == 0) {
      return;
    }
    if (selection.length > 1) {
      OptionDialog.showErrorDialog(ui.getMainWindow(), "You can only open one folder or file");
      return;
    }

    Download d = rows.get(selection[0]).download;
    if (d.isComplete() == true) {
      String path =
          ui.getCore().getSettings().getInternal().getDownloadfolder()
              + "\\"
              + d.getAuxInfoFilename();
      try {
        Desktop.getDesktop().open(new File(path));
      } catch (IOException ex) {
        OptionDialog.showErrorDialog(
            ui.getMainWindow(), "This type of file hasn't been associated with any program");
      } catch (IllegalArgumentException ex) {
        OptionDialog.showErrorDialog(
            ui.getMainWindow(), "This type of file hasn't been associated with any program");
      } catch (UnsupportedOperationException ex) {
        OptionDialog.showErrorDialog(
            ui.getMainWindow(), "This operation is not supported on this architecture");
      }
    } else {
      OptionDialog.showErrorDialog(ui.getMainWindow(), "File hasn't been downloaded yet");
    }
  }
  private void moveCorruptedReplayFile(Path replayFile) throws IOException {
    Path corruptedReplaysDirectory = preferencesService.getCorruptedReplaysDirectory();
    Files.createDirectories(corruptedReplaysDirectory);

    Path target = corruptedReplaysDirectory.resolve(replayFile.getFileName());

    logger.debug("Moving corrupted replay file from {} to {}", replayFile, target);

    Files.move(replayFile, target);

    notificationService.addNotification(
        new PersistentNotification(
            i18n.get("corruptedReplayFiles.notification"),
            Severity.WARN,
            Collections.singletonList(
                new Action(
                    i18n.get("corruptedReplayFiles.show"),
                    event -> {
                      try {
                        // Argh, using AWT since JavaFX doesn't provide a proper method :-(
                        Desktop.getDesktop().open(corruptedReplaysDirectory.toFile());
                      } catch (IOException e) {
                        logger.warn("Could not reveal corrupted replay directory", e);
                      }
                    }))));
  }
  @Override
  protected final void doExecute(Application app) {
    if (Desktop.isDesktopSupported()) {
      Desktop desktop = Desktop.getDesktop();
      if (desktop.isSupported(getType())) {
        try {
          switch (getType()) {
            case BROWSE:
              desktop.browse(getURI(app));
              return;
            case MAIL:
              desktop.mail(getURI(app));
              return;
          }
        } catch (Exception e) {
          getLog().error("Invalid URI", e);
        }
      }
    }

    JOptionPane.showMessageDialog(
        app.getAppFrame(),
        String.format("Action %s is not supported", getType()),
        "",
        JOptionPane.WARNING_MESSAGE);
  }
Beispiel #29
0
  /** @param helpAddress */
  public OpenHelpUrl(String helpAddress) {

    if (!java.awt.Desktop.isDesktopSupported()) {

      System.err.println("Desktop is not supported (fatal)");
      System.exit(1);
    }

    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

    if (!desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {

      System.err.println("Desktop doesn't support the browse action (fatal)");
      System.exit(1);
    }

    try {

      java.net.URI uri = new java.net.URI(helpAddress);
      desktop.browse(uri);
    } catch (Exception e) {

      System.err.println(e.getMessage());
    }
  }
  public static void main(String[] args) throws Exception {
    disableJavaLogging();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    connector.setMaxIdleTime(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(determineServerPort());
    server.setConnectors(new Connector[] {connector});

    WebAppContext context = new WebAppContext();
    context.setServer(server);
    context.setContextPath("/");

    ProtectionDomain protectionDomain = Launcher.class.getProtectionDomain();
    URL location = protectionDomain.getCodeSource().getLocation();
    context.setWar(location.toExternalForm());

    server.setHandler(context);
    server.start();

    Desktop.getDesktop().browse(URI.create("http://localhost:" + connector.getPort() + "/"));

    server.join();
  }