X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=runtime%2Forg.argeo.slc.support.simple%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2FFileExecutionResources.java;fp=runtime%2Forg.argeo.slc.support.simple%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2FFileExecutionResources.java;h=e032e6a0c3f69c0efc9426c21b98e7eabf7e4cc9;hb=45788cedce74d877422a5aaea446f6c949bbbfb8;hp=a023fc7f579ba99d30f96a37150752425dc4c443;hpb=4fa028eb5f09ce0609e496732fe6f4a90d6decfe;p=gpl%2Fargeo-slc.git 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 index a023fc7f5..e032e6a0c 100644 --- 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 @@ -1,10 +1,16 @@ package org.argeo.slc.core.execution; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.text.SimpleDateFormat; +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.argeo.slc.SlcException; import org.argeo.slc.execution.ExecutionContext; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; @@ -74,6 +80,43 @@ public class FileExecutionResources implements ExecutionResources { return resource; } + public String getAsOsPath(Resource resource, Boolean overwrite) { + File file = null; + try { + file = resource.getFile(); + return file.getCanonicalPath(); + } catch (IOException e) { + if (log.isTraceEnabled()) + log + .trace("Resource " + + resource + + " is not available on the file system. Retrieving it..."); + } + + InputStream in = null; + OutputStream out = null; + try { + String path = resource.getURL().getPath(); + file = getFile(path); + if (file.exists() && !overwrite) + return file.getCanonicalPath(); + + file.getParentFile().mkdirs(); + in = resource.getInputStream(); + out = new FileOutputStream(file); + IOUtils.copy(in, out); + if (log.isDebugEnabled()) + log.debug("Retrieved " + resource + " to OS file " + file); + return file.getCanonicalPath(); + } catch (IOException e) { + throw new SlcException("Could not make resource " + resource + + " an OS file.", e); + } finally { + IOUtils.closeQuietly(in); + IOUtils.closeQuietly(out); + } + } + public File getFile(String relativePath) { Assert.notNull(executionContext, "execution context is null");