Package net.datacrow.util.launcher

Source Code of net.datacrow.util.launcher.URLLauncher

package net.datacrow.util.launcher;

import java.awt.Desktop;
import java.net.URL;

import net.datacrow.core.DcRepository;
import net.datacrow.core.resources.DcResources;
import net.datacrow.settings.DcSettings;
import net.datacrow.util.DcSwingUtilities;
import net.datacrow.util.Utilities;

import org.apache.log4j.Logger;

public class URLLauncher extends Launcher {

  private static Logger logger = Logger.getLogger(URLLauncher.class.getName());
 
  private URL url;
 
  public URLLauncher(URL url) {
    super();
    this.url = url;
  }

  @Override
  public void launch() {

    boolean launched = false;
   
    String browserPath = DcSettings.getString(DcRepository.Settings.stBrowserPath);
   
    if (!Utilities.isEmpty(browserPath)) {
      try {
        runCmd(browserPath + " " + url);
        launched = true;
      } catch (Exception e) {}
    }
   
    if (!launched) {
      Desktop desktop = getDesktop();
          if (desktop != null) {
              try {
                desktop.browse(url.toURI());
                launched = true;
              } catch (Exception exp) {
                logger.debug("Could not launch URL using the Dekstop class [" + url + "]", exp);
               
                if (!Utilities.isEmpty(browserPath))
                      DcSwingUtilities.displayWarningMessage(DcResources.getText("msgCannotLaunchURLNoBrowserPath", url.toString()));
                else
                        DcSwingUtilities.displayWarningMessage(DcResources.getText("msgCannotLaunchURL", url.toString()));
              }
          }
    }
  }
}
TOP

Related Classes of net.datacrow.util.launcher.URLLauncher

TOP
Copyright © 2018 www.massapi.com. 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.