예제 #1
0
 public static String fixFileNameVariables(String format, String fname) {
   String str = PT.simpleReplace(format, "%FILE", fname);
   if (str.indexOf("%LC") < 0) return str;
   fname = fname.toLowerCase();
   str = PT.simpleReplace(str, "%LCFILE", fname);
   if (fname.length() == 4) str = PT.simpleReplace(str, "%LC13", fname.substring(1, 3));
   return str;
 }
예제 #2
0
 public static String setScriptFileReferences(
     String script, String localPath, String remotePath, String scriptPath) {
   if (localPath != null) script = setScriptFileRefs(script, localPath, true);
   if (remotePath != null) script = setScriptFileRefs(script, remotePath, false);
   script = PT.simpleReplace(script, "\1\"", "\"");
   if (scriptPath != null) {
     while (scriptPath.endsWith("/"))
       scriptPath = scriptPath.substring(0, scriptPath.length() - 1);
     for (int ipt = 0; ipt < scriptFilePrefixes.length; ipt++) {
       String tag = scriptFilePrefixes[ipt];
       script = PT.simpleReplace(script, tag + ".", tag + scriptPath);
     }
   }
   return script;
 }
예제 #3
0
  private static String fixPath(String path) {
    path = path.replace('\\', '/');
    path = PT.simpleReplace(path, "/./", "/");
    int pt = path.lastIndexOf("//") + 1;
    if (pt < 1) pt = path.indexOf(":/") + 1;
    if (pt < 1) pt = path.indexOf("/");
    if (pt < 0) return null;
    String protocol = path.substring(0, pt);
    path = path.substring(pt);

    while ((pt = path.lastIndexOf("/../")) >= 0) {
      int pt0 = path.substring(0, pt).lastIndexOf("/");
      if (pt0 < 0) return PT.simpleReplace(protocol + path, "/../", "/");
      path = path.substring(0, pt0) + path.substring(pt + 3);
    }
    if (path.length() == 0) path = "/";
    return protocol + path;
  }
예제 #4
0
 public Object getBufferedInputStreamOrErrorMessageFromName(
     String name,
     String fullName,
     boolean showMsg,
     boolean checkOnly,
     byte[] outputBytes,
     boolean allowReader) {
   byte[] cacheBytes = null;
   if (outputBytes == null) {
     cacheBytes =
         (fullName == null || pngjCache == null
             ? null
             : JmolBinary.getCachedPngjBytes(this, fullName));
     if (cacheBytes == null) cacheBytes = (byte[]) cacheGet(name, true);
   }
   BufferedInputStream bis = null;
   Object ret = null;
   String errorMessage = null;
   try {
     if (cacheBytes == null) {
       boolean isPngjBinaryPost = (name.indexOf("?POST?_PNGJBIN_") >= 0);
       boolean isPngjPost = (isPngjBinaryPost || name.indexOf("?POST?_PNGJ_") >= 0);
       if (name.indexOf("?POST?_PNG_") > 0 || isPngjPost) {
         String[] errMsg = new String[1];
         byte[] bytes = viewer.getImageAsBytes(isPngjPost ? "PNGJ" : "PNG", 0, 0, -1, errMsg);
         if (errMsg[0] != null) return errMsg[0];
         if (isPngjBinaryPost) {
           outputBytes = bytes;
           name = PT.simpleReplace(name, "?_", "=_");
         } else {
           name = new SB().append(name).append("=").appendSB(Base64.getBase64(bytes)).toString();
         }
       }
       int iurl = urlTypeIndex(name);
       boolean isURL = (iurl >= 0);
       String post = null;
       if (isURL && (iurl = name.indexOf("?POST?")) >= 0) {
         post = name.substring(iurl + 6);
         name = name.substring(0, iurl);
       }
       boolean isApplet = (appletDocumentBaseURL != null);
       if (name.indexOf(".png") >= 0 && pngjCache == null && viewer.cachePngFiles())
         JmolBinary.cachePngjFile(this, null);
       if (isApplet || isURL) {
         if (isApplet && isURL && appletProxy != null)
           name = appletProxy + "?url=" + urlEncode(name);
         URL url =
             (isApplet
                 ? new URL(appletDocumentBaseURL, name, null)
                 : new URL((URL) null, name, null));
         if (checkOnly) return null;
         name = url.toString();
         if (showMsg && name.toLowerCase().indexOf("password") < 0)
           Logger.info("FileManager opening 1 " + name);
         ret = viewer.apiPlatform.getBufferedURLInputStream(url, outputBytes, post);
         byte[] bytes = null;
         if (ret instanceof SB) {
           SB sb = (SB) ret;
           if (allowReader && !JmolBinary.isBase64(sb)) return JmolBinary.getBR(sb.toString());
           bytes = JmolBinary.getBytesFromSB(sb);
         } else if (PT.isAB(ret)) {
           bytes = (byte[]) ret;
         }
         if (bytes != null) ret = JmolBinary.getBIS(bytes);
       } else if ((cacheBytes = (byte[]) cacheGet(name, true)) == null) {
         if (showMsg) Logger.info("FileManager opening 2 " + name);
         ret = viewer.apiPlatform.getBufferedFileInputStream(name);
       }
       if (ret instanceof String) return ret;
     }
     bis = (cacheBytes == null ? (BufferedInputStream) ret : JmolBinary.getBIS(cacheBytes));
     if (checkOnly) {
       bis.close();
       bis = null;
     }
     return bis;
   } catch (Exception e) {
     try {
       if (bis != null) bis.close();
     } catch (IOException e1) {
     }
     errorMessage = "" + e;
   }
   return errorMessage;
 }