/** * Gets the absolute path. * * @return the absolute path */ public String getAbsolutePath() { if (getFile() != null) { try { return XML.forwardSlash(getFile().getCanonicalPath()); } catch (IOException ex) { ex.printStackTrace(); } return getFile().getAbsolutePath(); } if (getURL() != null) { URL url = getURL(); String path = url.getPath(); // remove file protocol, if any if (path.startsWith("file:")) { // $NON-NLS-1$ path = path.substring(5); } // remove leading slash if drive is specified if (path.startsWith("/") && path.indexOf(":") > -1) { // $NON-NLS-1$ //$NON-NLS-2$ path = path.substring(1); } // replace "%20" with space int i = path.indexOf("%20"); // $NON-NLS-1$ while (i > -1) { String s = path.substring(0, i); path = s + " " + path.substring(i + 3); // $NON-NLS-1$ i = path.indexOf("%20"); // $NON-NLS-1$ } return path; } return null; }
public void init() { is_master = false; dyn_usr = 0; dyn_view = 0; id = (int) System.currentTimeMillis(); ClientApplet.client_applet = this; appletContext = getAppletContext(); hostsrv = getParameter("HOSTSRV"); String http_portString = getParameter("HTTP_PORT"); if (http_portString != null) { try { Integer port = Integer.valueOf(http_portString); http_port = port.intValue(); } catch (NumberFormatException e) { http_port = 50000; } } URL applet_url = this.getCodeBase(); String host = applet_url.getHost(); if (host != null) hostsrv = host; int port = applet_url.getPort(); if (port > 0) http_port = port; user_interface = new UserInterface(); user_interface.init(); }
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); } }
// Goes online to get user authentication from Flickr. public void getAuthentication() { AuthInterface authInterface = flickr.getAuthInterface(); try { frob = authInterface.getFrob(); } catch (Exception e) { e.printStackTrace(); } try { URL authURL = authInterface.buildAuthenticationUrl(Permission.WRITE, frob); // open the authentication URL in a browser open(authURL.toExternalForm()); } catch (Exception e) { e.printStackTrace(); } println("You have 15 seconds to approve the app!"); int startedWaiting = millis(); int waitDuration = 15 * 1000; // wait 10 seconds while ((millis() - startedWaiting) < waitDuration) { // just wait } println("Done waiting"); try { auth = authInterface.getToken(frob); println("Authentication success"); // This token can be used until the user revokes it. token = auth.getToken(); // save it for future use saveToken(token); } catch (Exception e) { e.printStackTrace(); } // complete authentication authenticateWithToken(token); }
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; }