]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java
Attachments management
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / core / execution / FileExecutionResources.java
diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java
new file mode 100644 (file)
index 0000000..e35ff00
--- /dev/null
@@ -0,0 +1,51 @@
+package org.argeo.slc.core.execution;
+
+import java.io.File;
+
+import org.argeo.slc.execution.ExecutionContext;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+
+public class FileExecutionResources implements ExecutionResources {
+       private File baseDir;
+       private ExecutionContext executionContext;
+
+       public FileExecutionResources() {
+               String osgiInstanceArea = System.getProperty("osgi.instance.area");
+               if (osgiInstanceArea != null) {
+                       if (osgiInstanceArea.startsWith("file:"))
+                               osgiInstanceArea = osgiInstanceArea.substring("file:".length());
+                       baseDir = new File(osgiInstanceArea + File.separator
+                                       + "executionResources");
+               }
+
+               if (baseDir == null) {
+                       String tempDir = System.getProperty("java.io.tmpdir");
+                       baseDir = new File(tempDir + File.separator
+                                       + "slcExecutionResources");
+               }
+       }
+
+       public Resource getWritableResource(String relativePath) {
+               File file = getFile(relativePath);
+               file.getParentFile().mkdirs();
+               return new FileSystemResource(file);
+       }
+
+       public File getFile(String relativePath) {
+               File executionDir = new File(baseDir.getPath() + File.separator
+                               + executionContext.getUuid());
+               if (!executionDir.exists())
+                       executionDir.mkdirs();
+               return new File(executionDir.getPath() + File.separator + relativePath);
+       }
+
+       public void setBaseDir(File baseDir) {
+               this.baseDir = baseDir;
+       }
+
+       public void setExecutionContext(ExecutionContext executionContext) {
+               this.executionContext = executionContext;
+       }
+
+}