Example #1
0
 public static String getLocalPathForWritingFile(Viewer viewer, String file) {
   if (file.indexOf("file:/") == 0) return file.substring(6);
   if (file.indexOf("/") == 0 || file.indexOf(":") >= 0) return file;
   GenericFileInterface dir = null;
   try {
     dir = getLocalDirectory(viewer, false);
   } catch (Exception e) {
     // access control for unsigned applet
   }
   return (dir == null ? file : fixPath(dir.toString() + "/" + file));
 }
Example #2
0
 public static GenericFileInterface getLocalDirectory(Viewer viewer, boolean forDialog) {
   String localDir =
       (String) viewer.getParameter(forDialog ? "currentLocalPath" : "defaultDirectoryLocal");
   if (forDialog && localDir.length() == 0)
     localDir = (String) viewer.getParameter("defaultDirectoryLocal");
   if (localDir.length() == 0)
     return (viewer.isApplet()
         ? null
         : viewer.apiPlatform.newFile(System.getProperty("user.dir", ".")));
   if (viewer.isApplet() && localDir.indexOf("file:/") == 0) localDir = localDir.substring(6);
   GenericFileInterface f = viewer.apiPlatform.newFile(localDir);
   try {
     return f.isDirectory() ? f : f.getParentAsFile();
   } catch (Exception e) {
     return null;
   }
 }
Example #3
0
 /**
  * [0] and [2] may return same as [1] in the case of a local unsigned applet.
  *
  * @param name
  * @param isFullLoad false only when just checking path
  * @return [0] full path name, [1] file name without path, [2] full URL
  */
 private String[] classifyName(String name, boolean isFullLoad) {
   if (name == null) return new String[] {null};
   boolean doSetPathForAllFiles = (pathForAllFiles.length() > 0);
   if (name.startsWith("?")) {
     if ((name = viewer.dialogAsk("Load", name.substring(1))) == null)
       return new String[] {isFullLoad ? "#CANCELED#" : null};
     doSetPathForAllFiles = false;
   }
   GenericFileInterface file = null;
   URL url = null;
   String[] names = null;
   if (name.startsWith("cache://")) {
     names = new String[3];
     names[0] = names[2] = name;
     names[1] = stripPath(names[0]);
     return names;
   }
   name = viewer.resolveDatabaseFormat(name);
   if (name.indexOf(":") < 0 && name.indexOf("/") != 0)
     name = addDirectory(viewer.getDefaultDirectory(), name);
   if (appletDocumentBaseURL == null) {
     // This code is for the app or signed local applet
     // -- no local file reading for headless
     if (urlTypeIndex(name) >= 0
         || viewer.haveAccess(ACCESS.NONE)
         || viewer.haveAccess(ACCESS.READSPT) && !name.endsWith(".spt") && !name.endsWith("/")) {
       try {
         url = new URL((URL) null, name, null);
       } catch (MalformedURLException e) {
         return new String[] {isFullLoad ? e.toString() : null};
       }
     } else {
       file = viewer.apiPlatform.newFile(name);
       String s = file.getFullPath();
       // local unsigned applet may have access control issue here and get a null return
       String fname = file.getName();
       names =
           new String[] {
             (s == null ? fname : s), fname, (s == null ? fname : "file:/" + s.replace('\\', '/'))
           };
     }
   } else {
     // This code is only for the non-local applet
     try {
       if (name.indexOf(":\\") == 1 || name.indexOf(":/") == 1) name = "file:/" + name;
       //        else if (name.indexOf("/") == 0 && viewer.isSignedApplet())
       //        name = "file:" + name;
       url = new URL(appletDocumentBaseURL, name, null);
     } catch (MalformedURLException e) {
       return new String[] {isFullLoad ? e.toString() : null};
     }
   }
   if (url != null) {
     names = new String[3];
     names[0] = names[2] = url.toString();
     names[1] = stripPath(names[0]);
   }
   if (doSetPathForAllFiles) {
     String name0 = names[0];
     names[0] = pathForAllFiles + names[1];
     Logger.info("FileManager substituting " + name0 + " --> " + names[0]);
   }
   if (isFullLoad && (file != null || urlTypeIndex(names[0]) == URL_LOCAL)) {
     String path = (file == null ? PT.trim(names[0].substring(5), "/") : names[0]);
     int pt = path.length() - names[1].length() - 1;
     if (pt > 0) {
       path = path.substring(0, pt);
       setLocalPath(viewer, path, true);
     }
   }
   return names;
 }