package org.argeo.slc.core.execution;
import java.io.File;
+import java.text.SimpleDateFormat;
import org.argeo.slc.execution.ExecutionContext;
+import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
-public class FileExecutionResources implements ExecutionResources {
+public class FileExecutionResources implements ExecutionResources,
+ InitializingBean {
private File baseDir;
private ExecutionContext executionContext;
+ private String prefixDatePattern = "yyyyMMdd_HHmmss_";
+ private SimpleDateFormat sdf = null;
- 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");
- }
+ public void afterPropertiesSet() throws Exception {
+ if (sdf == null)
+ sdf = new SimpleDateFormat(prefixDatePattern);
if (baseDir == null) {
- String tempDir = System.getProperty("java.io.tmpdir");
- baseDir = new File(tempDir + File.separator
- + "slcExecutionResources");
+ 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 File getFile(String relativePath) {
File executionDir = new File(baseDir.getPath() + File.separator
+ + sdf.format(executionContext.getCreationDate())
+ executionContext.getUuid());
if (!executionDir.exists())
executionDir.mkdirs();
this.executionContext = executionContext;
}
+ public void setPrefixDatePattern(String prefixDatePattern) {
+ this.prefixDatePattern = prefixDatePattern;
+ }
+
+ public void setSdf(SimpleDateFormat sdf) {
+ this.sdf = sdf;
+ }
+
}