]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/Echo.java
Add license headers
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / tasks / Echo.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.core.execution.tasks;
18
19 import java.io.File;
20 import java.io.IOException;
21
22 import org.apache.commons.io.FileUtils;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.argeo.slc.SlcException;
26 import org.springframework.core.io.Resource;
27
28 public class Echo implements Runnable {
29 private final static Log defaultLog = LogFactory.getLog(Echo.class);
30 private Resource writeTo = null;
31
32 private Log log;
33 private Object message;
34
35 public void run() {
36 log().info(message);
37
38 if (writeTo != null) {
39 try {
40 File file = writeTo.getFile();
41 if (log().isDebugEnabled())
42 log().debug("Write to " + file);
43 if (message != null)
44 FileUtils.writeStringToFile(file, message.toString());
45 } catch (IOException e) {
46 throw new SlcException("Could not write to " + writeTo, e);
47 }
48 }
49 }
50
51 private Log log() {
52 return log != null ? log : defaultLog;
53 }
54
55 public void setMessage(Object message) {
56 this.message = message;
57 }
58
59 public void setWriteTo(Resource writeTo) {
60 this.writeTo = writeTo;
61 }
62
63 }