Object createAtomSeCollectionFromStrings( String[] arrayModels, SB loadScript, Map<String, Object> htParams, boolean isAppend) { if (!htParams.containsKey("isData")) { String oldSep = "\"" + viewer.getDataSeparator() + "\""; String tag = "\"" + (isAppend ? "append" : "model") + " inline\""; SB sb = new SB(); sb.append("set dataSeparator \"~~~next file~~~\";\ndata ").append(tag); for (int i = 0; i < arrayModels.length; i++) { if (i > 0) sb.append("~~~next file~~~"); sb.append(arrayModels[i]); } sb.append("end ").append(tag).append(";set dataSeparator ").append(oldSep); loadScript.appendSB(sb); } setLoadState(htParams); Logger.info("FileManager.getAtomSetCollectionFromStrings(string[])"); String[] fullPathNames = new String[arrayModels.length]; DataReader[] readers = new DataReader[arrayModels.length]; for (int i = 0; i < arrayModels.length; i++) { fullPathNames[i] = "string[" + i + "]"; readers[i] = newDataReader(arrayModels[i]); } JmolFilesReaderInterface filesReader = newFilesReader(fullPathNames, fullPathNames, null, readers, htParams, isAppend); filesReader.run(); return filesReader.getAtomSetCollection(); }
Object createAtomSetCollectionFromString( String strModel, Map<String, Object> htParams, boolean isAppend) { setLoadState(htParams); boolean isAddH = (strModel.indexOf(JC.ADD_HYDROGEN_TITLE) >= 0); String[] fnames = (isAddH ? getFileInfo() : null); FileReader fileReader = new FileReader( this, viewer, "string", "string", "string", null, JmolBinary.getBR(strModel), htParams, isAppend); fileReader.run(); if (fnames != null) setFileInfo(fnames); if (!isAppend && !(fileReader.getAtomSetCollection() instanceof String)) { viewer.zap(false, true, false); setFileInfo( new String[] {strModel == JC.MODELKIT_ZAP_STRING ? JC.MODELKIT_ZAP_TITLE : "string"}); } return fileReader.getAtomSetCollection(); }
/* * note -- createAtomSetCollectionFromXXX methods * were "openXXX" before refactoring 11/29/2008 -- BH * * The problem was that while they did open the file, they * (mostly) also closed them, and this was confusing. * * The term "clientFile" was replaced by "atomSetCollection" * here because that's what it is --- an AtomSetCollection, * not a file. The file is closed at this point. What is * returned is the atomSetCollection object. * * One could say this is just semantics, but there were * subtle bugs here, where readers were not always being * closed explicitly. In the process of identifying Out of * Memory Errors, I felt it was necessary to clarify all this. * * Apologies to those who feel the original clientFile notation * was more generalizable or understandable. * */ Object createAtomSetCollectionFromFile( String name, Map<String, Object> htParams, boolean isAppend) { if (htParams.get("atomDataOnly") == null) { setLoadState(htParams); } name = viewer.resolveDatabaseFormat(name); int pt = name.indexOf("::"); String nameAsGiven = (pt >= 0 ? name.substring(pt + 2) : name); String fileType = (pt >= 0 ? name.substring(0, pt) : null); Logger.info( "\nFileManager.getAtomSetCollectionFromFile(" + nameAsGiven + ")" + (name.equals(nameAsGiven) ? "" : " //" + name)); String[] names = classifyName(nameAsGiven, true); if (names.length == 1) return names[0]; String fullPathName = names[0]; String fileName = names[1]; htParams.put( "fullPathName", (fileType == null ? "" : fileType + "::") + fullPathName.replace('\\', '/')); if (viewer.getBoolean(T.messagestylechime) && viewer.getBoolean(T.debugscript)) viewer.scriptStatus("Requesting " + fullPathName); FileReader fileReader = new FileReader( this, viewer, fileName, fullPathName, nameAsGiven, fileType, null, htParams, isAppend); fileReader.run(); return fileReader.getAtomSetCollection(); }
Object createAtomSetCollectionFromFiles( String[] fileNames, Map<String, Object> htParams, boolean isAppend) { setLoadState(htParams); String[] fullPathNames = new String[fileNames.length]; String[] namesAsGiven = new String[fileNames.length]; String[] fileTypes = new String[fileNames.length]; for (int i = 0; i < fileNames.length; i++) { int pt = fileNames[i].indexOf("::"); String nameAsGiven = (pt >= 0 ? fileNames[i].substring(pt + 2) : fileNames[i]); String fileType = (pt >= 0 ? fileNames[i].substring(0, pt) : null); String[] names = classifyName(nameAsGiven, true); if (names.length == 1) return names[0]; fullPathNames[i] = names[0]; fileNames[i] = names[0].replace('\\', '/'); fileTypes[i] = fileType; namesAsGiven[i] = nameAsGiven; } htParams.put("fullPathNames", fullPathNames); htParams.put("fileTypes", fileTypes); JmolFilesReaderInterface filesReader = newFilesReader(fullPathNames, namesAsGiven, fileTypes, null, htParams, isAppend); filesReader.run(); return filesReader.getAtomSetCollection(); }