package nc.baseapp.util;
import java.awt.Desktop;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
public class BonesBrowserVisitUrl {
public static void openUrl(String ncservice_address, String ssoKey){
if(Desktop.isDesktopSupported()){
try {
URI uri = new URI("uclient://start/"+ncservice_address+"?ssoKey="+ssoKey+"&uiloader=nc.login.sso.ui.SSOLoader");
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(uri);
} catch (Exception e) {
if(e.getMessage().contains("连到系统上的设备没有发挥作用")){
openUrlWithIE(ncservice_address + "/login.jsp?ssoKey="+ssoKey);
} else {
ExceptionUtils.wrappBusinessException("nc客户端启动失败:" + e.getMessage());
}
}
} catch (URISyntaxException e) {
ExceptionUtils.wrappBusinessException("url初始化失败:" + e.getMessage());
}
}
}
public static void openUrlWithIE(String url){
String osName = System.getProperty("os.name", "");
if(osName != null){
if(osName.startsWith("Mac OS")){
try {
Class fileMgr = Class.forName("com.apple.eio.FileManager");
Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[]{String.class});
openURL.invoke(null, new Object[]{ url });
} catch (Exception e) {
ExceptionUtils.wrappBusinessException(e.getMessage());
}
} else if(osName.startsWith("Windows")){
try {
Runtime.getRuntime().exec("cmd /c start iexplore " + url);
} catch (IOException e) {
ExceptionUtils.wrappBusinessException(e.getMessage());
}
} else {
String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };
String browser = null;
for (int count = 0; count < browsers.length && browser == null; count++) {
try {
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) {
ExceptionUtils.wrappBusinessException(e.getMessage());
}
}
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)