static void openURL( JopSession session, String name, boolean newFrame, String frameName, String bookmark) { System.out.println("openURL " + name); Object root = session.getRoot(); // Replace any URL symbol name = replaceUrlSymbol(session, name); try { String url_str = null; if (name.substring(0, 5).equals("http:")) { url_str = name; if (url_str.lastIndexOf(".html") == -1 && url_str.lastIndexOf(".shtml") == -1 && url_str.lastIndexOf(".htm") == -1 && url_str.lastIndexOf(".pdf") == -1) url_str = url_str + ".html"; } else if (name.startsWith("$pwr_doc/")) { URL current = ((JApplet) root).getDocumentBase(); String current_str = current.toString(); int idx1 = current_str.indexOf('/'); if (idx1 != -1 && current_str.length() > idx1 + 1) { idx1 = current_str.indexOf('/', idx1 + 1); if (idx1 != -1 && current_str.length() > idx1 + 1) { idx1 = current_str.indexOf('/', idx1 + 1); if (idx1 != -1 && current_str.length() > idx1 + 1) { url_str = current_str.substring(0, idx1 + 1) + "pwr_doc/" + name.substring(9); if (url_str.lastIndexOf(".html") == -1 && url_str.lastIndexOf(".shtml") == -1 && url_str.lastIndexOf(".htm") == -1 && url_str.lastIndexOf(".pdf") == -1) url_str = url_str + ".html"; } } } } else { URL current = ((JApplet) root).getCodeBase(); String current_str = current.toString(); int idx1 = current_str.lastIndexOf('/'); int idx2 = current_str.lastIndexOf(':'); int idx = idx1; if (idx2 > idx) idx = idx2; String path = current_str.substring(0, idx + 1); if (name.lastIndexOf(".html") == -1 && name.lastIndexOf(".shtml") == -1 && name.lastIndexOf(".htm") == -1 && name.lastIndexOf(".pdf") == -1) url_str = new String(path + name + ".html"); else url_str = new String(path + name); if (bookmark != null) url_str += "#" + bookmark; } System.out.println("Opening URL: " + url_str); URL url = new URL(url_str); AppletContext appCtx = ((JApplet) root).getAppletContext(); if (newFrame) appCtx.showDocument(url, "_blank"); else if (frameName != null) appCtx.showDocument(url, frameName); else appCtx.showDocument(url, "_self"); } catch (MalformedURLException e) { System.out.println("MalformedURL : " + name); } }
/** * Loads a font based on URL Path * * @param String filePath * @param float fontSize * @param FontStyle fontStyle * @throws FontFormatException * @throws IOException */ public INFont(URL filePath, float fontSize, FontStyle fontStyle) throws FontFormatException, IOException { File fontFile = new File(filePath.toString()); this.loadedFont = Font.createFont(Font.TRUETYPE_FONT, fontFile); this.loadedFont = this.loadedFont.deriveFont(fontSize); this.style = fontStyle; this.size = fontSize; switch (fontStyle) { case BOLD: this.loadedFont = this.loadedFont.deriveFont(Font.BOLD); break; case ITALIC: this.loadedFont = this.loadedFont.deriveFont(Font.ITALIC); break; case PLAIN: this.loadedFont = this.loadedFont.deriveFont(Font.PLAIN); break; case BOLDANDITALIC: this.loadedFont = this.loadedFont.deriveFont(Font.BOLD + Font.ITALIC); break; } }
@Override public InputSource resolveEntity(String publicId, String systemId) { if (systemId != null && systemId.endsWith("dtd")) { URL url = FileFuncs.getResource(RuntimeProperties.PACKAGE_DTD, true); if (url != null) { return new InputSource(url.toString()); } // if unable to find dtd in local fs, try getting it from web return new InputSource(RuntimeProperties.SCHEMA_LOC + RuntimeProperties.PACKAGE_DTD); } return null; }
public AppFrame() { super(); GlobalData.oFrame = this; this.setSize(this.width, this.height); this.toolkit = Toolkit.getDefaultToolkit(); Dimension w = toolkit.getScreenSize(); int fx = (int) w.getWidth(); int fy = (int) w.getHeight(); int wx = (fx - this.width) / 2; int wy = (fy - this.getHeight()) / 2; setLocation(wx, wy); this.tracker = new MediaTracker(this); String sHost = ""; try { localAddr = InetAddress.getLocalHost(); if (localAddr.isLoopbackAddress()) { localAddr = LinuxInetAddress.getLocalHost(); } sHost = localAddr.getHostAddress(); } catch (UnknownHostException ex) { sHost = "你的IP地址错误"; } // this.textLines[0] = "服务器正在运行."; this.textLines[1] = ""; this.textLines[2] = "你的IP地址: " + sHost; this.textLines[3] = ""; this.textLines[4] = "请打开你的手机客户端"; this.textLines[5] = ""; this.textLines[6] = "输入屏幕上显示的IP地址."; // try { URL fileURL = this.getClass().getProtectionDomain().getCodeSource().getLocation(); String sBase = fileURL.toString(); if ("jar".equals(sBase.substring(sBase.length() - 3, sBase.length()))) { jar = new JarFile(new File(fileURL.toURI())); } else { basePath = System.getProperty("user.dir") + "\\res\\"; } } catch (Exception ex) { this.textLines[1] = "exception: " + ex.toString(); } }
/** ** Sets the 'port' */ public boolean setPort(int _port) { String uri = this.getURI(); if ((_port > 0) && URIArg.isAbsoluteURL(uri)) { try { URL oldURI = new URL(uri); String proto = oldURI.getProtocol(); String host = oldURI.getHost(); int port = _port; String file = oldURI.getFile(); URL newURI = new URL(proto, host, port, file); this._setURI(newURI.toString()); return true; } catch (MalformedURLException mue) { // error } } return false; }
/** Remove data component data JAR from cache */ public static void removeInstallerComponent() { DownloadService downloadService = Config.getDownloadService(); if (downloadService != null) { String component = Config.getInstallerLocation(); String version = Config.getInstallerVersion(); try { URL codebase = Config.getBasicService().getCodeBase(); URL url = new URL(codebase, component); component = url.toString(); Config.trace("Removing: " + component + "/" + version); downloadService.removeResource(url, version); } catch (IOException ioe) { Config.trace("Unable to remove " + component + "/" + version); } } else { Config.trace("No download service found"); } }
/** Download data component JAR */ public static boolean downloadInstallerComponent() { DownloadService downloadService = Config.getDownloadService(); DownloadServiceListener listener = downloadService.getDefaultProgressWindow(); String compName = Config.getInstallerLocation(); String compVer = Config.getInstallerVersion(); try { URL codebase = Config.getBasicService().getCodeBase(); URL url = new URL(codebase, compName); String urlstr = url.toString(); if (!downloadService.isResourceCached(url, compVer)) { // The installFailed string is only for debugging. No localization needed Config.trace("Downloading: " + urlstr); // Do download downloadService.loadResource(url, compVer, listener); } } catch (IOException ioe) { Config.trace("Unable to download: " + compName + "/" + compVer); return false; } return true; }
// implemented for HyperlinkListener public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane ep = (JEditorPane) (e.getSource()); // handle frame events properly if (e instanceof HTMLFrameHyperlinkEvent) { HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e; HTMLDocument doc = (HTMLDocument) (ep.getDocument()); doc.processHTMLFrameHyperlinkEvent(evt); } else // handle normal links { try { URL currentLoc = new URL(location); URL newLoc = new URL(currentLoc, e.getDescription()); setBrowserLocation(newLoc.toString()); } catch (MalformedURLException malUrl) { JOptionPane.showMessageDialog( this, "Malformed URL", "Browser Error", JOptionPane.ERROR_MESSAGE); return; } } } }
public static Image getImage(JopSession session, String image) { String fullName; if (session.getRoot() instanceof JopApplet) { String name; try { URL current = ((JApplet) session.getRoot()).getCodeBase(); String current_str = current.toString(); int idx1 = current_str.lastIndexOf('/'); int idx2 = current_str.lastIndexOf(':'); int idx = idx1; if (idx2 > idx) idx = idx2; String path = current_str.substring(0, idx + 1); String url_str; // String url_str = new String( path + name); if (image.substring(0, 5).compareTo("jpwr/") == 0) { idx = image.lastIndexOf('/'); name = image.substring(5, idx); url_str = new String("jar:" + path + "pwr_" + name + ".jar!/" + image); } else { idx = image.lastIndexOf('/'); if (idx == -1) name = new String(image); else name = image.substring(idx + 1); url_str = new String("jar:" + path + "pwrp_" + systemName + "_web.jar!/" + name); } System.out.println("Opening URL: " + url_str); URL url = new URL(url_str); return Toolkit.getDefaultToolkit().getImage(url); } catch (MalformedURLException e) { } return null; } else { // Add default directory /pwrp/img System.out.println("Image: " + image); // int idx = image.lastIndexOf('/'); // if ( idx == -1) // fullName = new String("/pwrp/img/" + image); // else fullName = new String(image); // return Toolkit.getDefaultToolkit().getImage( fullName); try { String name; String url_str; int idx; String path = new String("file://"); if (image.substring(0, 5).compareTo("jpwr/") == 0) { idx = image.lastIndexOf('/'); name = image.substring(5, idx); url_str = new String("$pwr_lib/pwr_" + name + ".jar"); url_str = Gdh.translateFilename(url_str); url_str = new String("jar:" + path + url_str + "!/" + image); } else { idx = image.lastIndexOf('/'); if (idx == -1) name = new String(image); else name = image.substring(idx + 1); url_str = new String("$pwrp_lib/pwrp_" + systemName + ".jar"); System.out.println("java: " + url_str); url_str = Gdh.translateFilename(url_str); url_str = new String("jar:" + path + url_str + "!/" + name); } System.out.println("Opening URL: " + url_str); URL url = new URL(url_str); return Toolkit.getDefaultToolkit().getImage(url); } catch (MalformedURLException e) { } } return null; }