]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.runtime/src/org/argeo/slc/runtime/tasks/Echo.java
Massive Argeo APIs refactoring
[gpl/argeo-slc.git] / org.argeo.slc.runtime / src / org / argeo / slc / runtime / tasks / Echo.java
1 package org.argeo.slc.runtime.tasks;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.nio.file.Path;
6
7 import org.apache.commons.io.FileUtils;
8 import org.argeo.api.cms.CmsLog;
9 import org.argeo.slc.SlcException;
10
11 public class Echo implements Runnable {
12 private final static CmsLog defaultLog = CmsLog.getLog(Echo.class);
13 private Path writeTo = null;
14
15 private CmsLog log;
16 private Object message;
17
18 public void run() {
19 log().info(message);
20
21 if (writeTo != null) {
22 try {
23 File file = writeTo.toFile();
24 if (log().isDebugEnabled())
25 log().debug("Write to " + file);
26 if (message != null)
27 FileUtils.writeStringToFile(file, message.toString());
28 } catch (IOException e) {
29 throw new SlcException("Could not write to " + writeTo, e);
30 }
31 }
32 }
33
34 private CmsLog log() {
35 return log != null ? log : defaultLog;
36 }
37
38 public void setMessage(Object message) {
39 this.message = message;
40 }
41
42 public void setWriteTo(Path writeTo) {
43 this.writeTo = writeTo;
44 }
45
46 }