]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
NOJIRA: Support both absolute paths and relative paths (relative to tomcat dir) value...
authorRichard Millet <remillet@yahoo.com>
Fri, 24 Aug 2018 22:23:06 +0000 (15:23 -0700)
committerRichard Millet <remillet@yahoo.com>
Fri, 24 Aug 2018 22:23:06 +0000 (15:23 -0700)
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java
services/common/src/main/java/org/collectionspace/services/common/blob/BlobInput.java

index 901113619267f0e9726e63eda8d7ddc5653b10e6..84269b43205a5a6de26df20ede9a2be9537be868 100644 (file)
@@ -101,6 +101,7 @@ public class ServiceMain {
     private static final String DROP_USER_SQL_CMD = "DROP USER";
     private static final String DROP_USER_IF_EXISTS_SQL_CMD = DROP_USER_SQL_CMD + " IF EXISTS %s;";
     private static final String DROP_OBJECTS_SQL_COMMENT = "-- drop all the objects before dropping roles";
+       private static final String CSPACE_JEESERVER_HOME = "CSPACE_JEESERVER_HOME";
 
     private ServiceMain() {
        // Intentionally blank
@@ -1438,4 +1439,14 @@ public class ServiceMain {
                }
 
        }
+
+       public static String getJeeContainPath() throws Exception {
+               String result = System.getenv(CSPACE_JEESERVER_HOME);
+               
+               if (result == null) {
+                       throw new Exception();
+               }
+               
+               return result;
+       }
 }
index 2d81e3cd8cddb71d504eec9595b5edaedc708497..6a7d3e8be871c0f905cc5a8745c1ef02bac3c595 100644 (file)
@@ -4,6 +4,8 @@ import java.io.File;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -12,6 +14,7 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.collectionspace.services.nuxeo.client.java.CommonList;
 import org.collectionspace.services.common.Download;
+import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.document.DocumentException;
 import org.collectionspace.services.common.imaging.nuxeo.NuxeoBlobUtils;
 
@@ -218,7 +221,14 @@ public class BlobInput {
                                throw new DocumentException(msg);
                        }
                } else if (blobUrl.getProtocol().equalsIgnoreCase("file")) {
-                       theBlobFile = FileUtils.toFile(blobUrl);
+                       if (blobUrl.getPath().startsWith("/")) {
+                               // full path
+                               theBlobFile = FileUtils.toFile(blobUrl);                        
+                       } else {
+                               // relative to JEE container (e.g. Apache Tomcat) path
+                               Path theBlobFilePath = Paths.get(ServiceMain.getJeeContainPath(), blobUrl.getPath());
+                               theBlobFile = new File(theBlobFilePath.toAbsolutePath().toString());
+                       }
                        if (theBlobFile.exists() == false || theBlobFile.canRead() == false) {
                                String msg = FILE_ACCESS_ERROR + theBlobFile.getAbsolutePath();
                                logger.error(msg);