📄 externallauncher.java
字号:
if (videoString != null) { mediaFiles.add(absolutePath(IMDIString, videoString)); } if (audioString != null) { mediaFiles.add(absolutePath(IMDIString, audioString)); } //new ElanFrame2(eafString, mediaFiles); FrameManager.getInstance().createFrame(eafString, mediaFiles); } } } } /** * Convert a path to a file URL string. Takes care of Samba related problems * file:///path works for all files except for samba file systems, there we need file://machine/path, * i.e. 2 slashes instead of 3 * * What's with relative paths? */ private static String pathToURLString(String path) { // replace all back slashes by forward slashes String pathURL = path.replace('\\', '/'); boolean isFileURL = pathURL.startsWith("file:"); if (isFileURL) { pathURL = pathURL.substring(5); // remove leading slashes and count them int n = 0; while (pathURL.charAt(0) == '/') { pathURL = pathURL.substring(1); n++; } // add the file:// or file:/// prefix if (n == 2) { if (pathURL.charAt(1) == ':') { // local drive return "file:///" + pathURL; } else { // samba share return "file://" + pathURL; } } else { return "file:///" + pathURL; } } else { // this can still be a local file... return pathURL; } } /** * Creates an absolute path for a file. * If the file name is not an absolute path, an absolute path is created * by resolving from the base document's path. * * @param fromDoc the base file * @param fileName the file to create an absolute path for * @return an absolute path as a String, or null */ private static String absolutePath(String fromDoc, String fileName) { if (fileName == null) { return null; } fileName = fileName.replace('\\', '/'); URI fileUri = null; try { fileUri = new URI(fileName); if (fileUri.isAbsolute()) { String resString = fileUri.toString(); if (resString.startsWith("file:") || resString.startsWith("//")) { return fileUri.getSchemeSpecificPart(); } else { return resString; } } else { if (fromDoc == null) { // give it a try return fileUri.getSchemeSpecificPart(); } else { URI baseUri = null; try { baseUri = new URI(fromDoc); fileUri = new URI(stripLeadingSlashes(fileName)); URI resolved = baseUri.resolve(fileUri.getSchemeSpecificPart()); //stripLeadingSlashes(fileUri.getSchemeSpecificPart())); String resString = resolved.toString(); if (resString.startsWith("file:") || resString.startsWith("//")) { return resolved.getSchemeSpecificPart(); } else { return resString; } } catch (URISyntaxException ue) { LOG.warning("URI: no context for relative file path\n" + LogUtil.formatStackTrace(ue)); return fileUri.getSchemeSpecificPart(); } } } } catch (URISyntaxException ue) { LOG.warning("URI: invalid file path\n" + LogUtil.formatStackTrace(ue)); } return null; } /** * Strip leading forward slashes from relative paths. * @param in the path * @return the stripped path, or null */ private static String stripLeadingSlashes(String in) { if (in == null) { return null; } String strip = in; while (strip.charAt(0) == '/') { strip = strip.substring(1); } return strip; } /** * Shows a warning/error dialog with the specified message string. * * @param message the message to display */ private static void showWarningDialog(String message) { JOptionPane.showMessageDialog(null, message, "Warning", JOptionPane.WARNING_MESSAGE); } /** * Makes sure the listener thread is stopped. Clean up by calling stop() * * @see #stop() */ public void finalize() { ExternalLauncher.stop(); } /** * A thread that periodically checks for changes in an exchange file. * * @author Han Sloetjes * @version 1.0 */ private static class LaunchThread extends Thread { private int delay; /** * Creates a new LaunchThread instance * * @param delay the delay period */ LaunchThread(int delay) { this.delay = delay; } /** * Implements Runnable run method. */ public void run() { while (running) { ExternalLauncher.checkChange(); try { sleep(delay); } catch (InterruptedException ie) { LOG.info("Launch thread interrupted..."); } } } } /** * Test thread. * * @author Han Sloetjes * @version 1.0 */ private static class TestLauncher extends Thread { /** Holds value of property number of test runs */ final int num = 1; /** * Implements Runnable run method. */ public void run() { int i = 0; while (i < num) { try { sleep(5000); } catch (InterruptedException ie) { ie.printStackTrace(); } try { File launchFl = new File(Constants.ELAN_DATA_DIR, exchangeFile); if (!launchFl.exists()) { boolean success = launchFl.createNewFile(); if (!success) { LOG.severe("Could not create file: " + launchFl.getAbsolutePath()); return; } } FileWriter writer = new FileWriter(launchFl); writer.write( "IMDI_Session: file:/D:/Dev_MPI/resources/testdata/elan/test.imdi"); //writer.write( // "IMDI_Session: //Nt04/users1/hasloe/test.imdi"); //writer.write( "IMDI_Session: C:/tmp/test.imdi"); writer.close(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } i++; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -