]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ResourceSpecAttribute.java
Make tree test results serializable so that it can be used with ObjectList.
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / core / execution / ResourceSpecAttribute.java
1 package org.argeo.slc.core.execution;
2
3 import java.io.IOException;
4
5 import org.argeo.slc.SlcException;
6 import org.springframework.core.io.Resource;
7
8 // TODO: offer the ability to read the resource
9 public class ResourceSpecAttribute extends AbstractSpecAttribute {
10 public final static String TYPE_PATH = "path";
11 public final static String TYPE_URL = "url";
12 public final static String TYPE_STREAM = "stream";
13
14 private Resource resource;
15 private String type = TYPE_PATH;
16
17 public Object getValue() {
18 return convertResource(resource);
19 }
20
21 public void setResource(Resource resource) {
22 this.resource = resource;
23 }
24
25 public Object convertResource(Resource resource) {
26 try {
27 if (TYPE_PATH.equals(type))
28 return resource.getFile().getCanonicalPath();
29 else if (TYPE_URL.equals(type))
30 return resource.getURL().toString();
31 else if (TYPE_STREAM.equals(type))
32 return resource.getInputStream();
33 else
34 throw new SlcException("Unkown type " + type);
35 } catch (IOException e) {
36 throw new SlcException("Cannot convert resource " + resource, e);
37 }
38 }
39
40 public void setType(String type) {
41 this.type = type;
42 }
43
44 public String getType() {
45 return type;
46 }
47
48 }