1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.argeo.slc.core.execution.tasks;
17
18 import java.io.File;
19 import java.io.IOException;
20
21 import org.apache.commons.io.FileUtils;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.argeo.slc.SlcException;
25 import org.springframework.core.io.Resource;
26
27 public class Echo implements Runnable {
28 private final static Log defaultLog = LogFactory.getLog(Echo.class);
29 private Resource writeTo = null;
30
31 private Log log;
32 private Object message;
33
34 public void run() {
35 log().info(message);
36
37 if (writeTo != null) {
38 try {
39 File file = writeTo.getFile();
40 if (log().isDebugEnabled())
41 log().debug("Write to " + file);
42 if (message != null)
43 FileUtils.writeStringToFile(file, message.toString());
44 } catch (IOException e) {
45 throw new SlcException("Could not write to " + writeTo, e);
46 }
47 }
48 }
49
50 private Log log() {
51 return log != null ? log : defaultLog;
52 }
53
54 public void setMessage(Object message) {
55 this.message = message;
56 }
57
58 public void setWriteTo(Resource writeTo) {
59 this.writeTo = writeTo;
60 }
61
62 }