From: <ha...@us...> - 2008-08-16 20:28:16
|
Revision: 9743 http://jmol.svn.sourceforge.net/jmol/?rev=9743&view=rev Author: hansonr Date: 2008-08-16 20:28:11 +0000 (Sat, 16 Aug 2008) Log Message: ----------- version=11.6.RC8_dev code cleanup Modified Paths: -------------- trunk/Jmol/src/org/jmol/viewer/Eval.java trunk/Jmol/src/org/jmol/viewer/FileManager.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Eval.java 2008-08-16 18:58:44 UTC (rev 9742) +++ trunk/Jmol/src/org/jmol/viewer/Eval.java 2008-08-16 20:28:11 UTC (rev 9743) @@ -491,33 +491,11 @@ if (filename.toLowerCase().indexOf("javascript:") == 0) return loadScript(filename, viewer.eval(filename.substring(11)), debugScript); - Object t = viewer.getBufferedReaderOrErrorMessageFromName(filename, null, false); - if (!(t instanceof BufferedReader)) - return loadError((String) t); - BufferedReader reader = (BufferedReader) t; - StringBuffer script = new StringBuffer(); - try { - while (true) { - String command = reader.readLine(); - if (command == null) - break; - script.append(command); - script.append("\n"); - } - } catch (IOException e) { - try { - reader.close(); - reader = null; - } catch (IOException ioe) { - } - return ioError(filename); - } - try { - reader.close(); - reader = null; - } catch (IOException ioe) { - } - return loadScript(filename, script.toString(), debugScript); + String[] data = new String[2]; + data[0] = filename; + if (!viewer.getFileAsString(data)) + return loadError("io error reading " + data[0] + ": " + data[1]); + return loadScript(filename, data[1], debugScript); } private boolean loadError(String msg) { @@ -526,10 +504,6 @@ return false; } - private boolean ioError(String filename) { - return loadError("io error reading:" + filename); - } - public String toString() { StringBuffer str = new StringBuffer(); str.append("Eval\n pc:"); @@ -5103,6 +5077,7 @@ if (getToken(1).tok != Token.string) error(ERROR_filenameExpected); filename = theScript; + theScript = null; if (filename.equalsIgnoreCase("inline")) { theScript = parameterExpression(2, 0, "_script", false).toString(); i = iToken + 1; @@ -5146,12 +5121,8 @@ if (isCheck) isSyntaxCheck = isScriptCheck = true; pushContext(null); - boolean isOK; - if (theScript != null) - isOK = loadScript(null, theScript, false); - else - isOK = loadScriptFileInternal(filename); - if (isOK) { + if (theScript == null ? loadScriptFileInternal(filename) + : loadScript(null, theScript, false)) { this.pcEnd = pcEnd; this.lineEnd = lineEnd; while (pc < lineNumbers.length && lineNumbers[pc] < lineNumber) Modified: trunk/Jmol/src/org/jmol/viewer/FileManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/FileManager.java 2008-08-16 18:58:44 UTC (rev 9742) +++ trunk/Jmol/src/org/jmol/viewer/FileManager.java 2008-08-16 20:28:11 UTC (rev 9743) @@ -308,15 +308,19 @@ /** * - * @param name - * @return file contents; directory listing for a ZIP/JAR file + * @param data [0] initially path name, but returned as full path name; [1]file contents (directory listing for a ZIP/JAR file) or error string + * @return true if successful; false on error */ - public String getFileAsString(String name) { + boolean getFileDataOrErrorAsString(String[] data) { + data[1] = ""; + String name = data[0]; if (name == null) - return ""; - Object t = getBufferedReaderOrErrorMessageFromName(name, null, false); - if (t instanceof String) - return (String) t; + return false; + Object t = getBufferedReaderOrErrorMessageFromName(name, data, false); + if (t instanceof String) { + data[1] = (String) t; + return false; + } try { BufferedReader br = (BufferedReader) t; StringBuffer sb = new StringBuffer(8192); @@ -326,9 +330,11 @@ sb.append('\n'); } br.close(); - return sb.toString(); + data[1] = sb.toString(); + return true; } catch (Exception ioe) { - return ioe.getMessage(); + data[1] = ioe.getMessage(); + return false; } } Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2008-08-16 18:58:44 UTC (rev 9742) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2008-08-16 20:28:11 UTC (rev 9743) @@ -1809,14 +1809,9 @@ String pathName = modelManager.getModelSetPathName(); if (pathName == null) return null; - return fileManager.getFileAsString(pathName); + return getFileAsString(pathName); } - public String getFileAsString(String pathName) { - return (pathName == null ? getCurrentFileAsString() : fileManager - .getFileAsString(pathName)); - } - public String getFullPathName() { return fileManager.getFullPathName(); } @@ -1825,6 +1820,20 @@ return fileManager.getFileName(); } + public String getFileAsString(String name) { + if (name == null) + return getCurrentFileAsString(); + String[] data = new String[2]; + data[0] = name; + // ignore error completely + getFileAsString(data); + return data[1]; + } + + boolean getFileAsString(String[] data) { + return fileManager.getFileDataOrErrorAsString(data); + } + String[] getFileInfo() { return fileManager.getFileInfo(); } @@ -6420,7 +6429,7 @@ if (fileOrText.length() == 0) fileOrText = null; else if (isFile) - fileOrText = fileManager.getFileAsString(fileOrText); + fileOrText = getFileAsString(fileOrText); statusManager.setCallbackFunction("menu", fileOrText); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |