import java.util.StringTokenizer;\r
import java.util.UUID;\r
\r
-public class SlcExecutionStep {\r
- public final static String TYPE_START = "START";\r
- public final static String TYPE_END = "END";\r
- public final static String TYPE_PHASE_START = "PHASE_START";\r
- public final static String TYPE_PHASE_END = "PHASE_END";\r
- public final static String TYPE_LOG = "LOG";\r
+import org.argeo.slc.execution.ExecutionStep;\r
+\r
+/**\r
+ * An atomic step to be notified in during an {@link SlcExecution}. Can be a log\r
+ * or the start/end of a phase, etc.\r
+ * \r
+ * @deprecated use {@link ExecutionStep} instead\r
+ */\r
+public class SlcExecutionStep extends ExecutionStep {\r
+ private static final long serialVersionUID = -7308643628104726471L;\r
\r
private String uuid = UUID.randomUUID().toString();\r
- private String type;\r
- private Date begin = new Date();\r
private List<String> logLines = new ArrayList<String>();\r
\r
/** Empty constructor */\r
public SlcExecutionStep() {\r
}\r
\r
- /** Creates a step of type LOG. */\r
+ /** Creates a step at the current date of type INFO */\r
public SlcExecutionStep(String log) {\r
- this(TYPE_LOG, log);\r
+ this(new Date(), INFO, log);\r
}\r
\r
- /** Creates a step of the given type. */\r
+ /** Creates a step at the current date */\r
public SlcExecutionStep(String type, String log) {\r
- this.type = type;\r
- addLog(log);\r
+ this(new Date(), type, log);\r
}\r
\r
+ /** Creates a step of the given type. */\r
+ public SlcExecutionStep(Date timestamp, String type, String log) {\r
+ this(timestamp, type, log, Thread.currentThread().getName());\r
+ }\r
+\r
+ public SlcExecutionStep(Date timestamp, String type, String log,\r
+ String thread) {\r
+ super(timestamp, type, log, thread);\r
+ }\r
+ \r
+ \r
+\r
public String getUuid() {\r
return uuid;\r
}\r
this.uuid = uuid;\r
}\r
\r
- public String getType() {\r
- return type;\r
- }\r
-\r
public void setType(String type) {\r
this.type = type;\r
}\r
\r
- public Date getBegin() {\r
- return begin;\r
+ public void setTimestamp(Date begin) {\r
+ this.timestamp = begin;\r
}\r
\r
- public void setBegin(Date begin) {\r
- this.begin = begin;\r
+ public void setThread(String thread) {\r
+ this.thread = thread;\r
}\r
\r
public List<String> getLogLines() {\r
this.logLines = logLines;\r
}\r
\r
- public void addLog(String log) {\r
+ /** public for legacy reasons*/\r
+ public String addLog(String log) {\r
+ if (logLines == null)\r
+ logLines = new ArrayList<String>();\r
+\r
if (log == null)\r
- return;\r
+ return null;\r
\r
StringTokenizer st = new StringTokenizer(log, "\n");\r
while (st.hasMoreTokens())\r
- logLines.add(st.nextToken());\r
+ logLines.add(removeNonXmlChars(st.nextToken()));\r
+ return null;\r
+ }\r
+\r
+ /**\r
+ * Removes non XML compliant characters (from\r
+ * http://stackoverflow.com/questions\r
+ * /20762/how-do-you-remove-invalid-hexadecimal\r
+ * -characters-from-an-xml-based-data-source-pr)\r
+ */\r
+ private static String removeNonXmlChars(String inString) {\r
+ if (inString == null)\r
+ return null;\r
+\r
+ StringBuilder newString = new StringBuilder();\r
+ char ch;\r
+\r
+ for (int i = 0; i < inString.length(); i++) {\r
+\r
+ ch = inString.charAt(i);\r
+ // remove any characters outside the valid UTF-8 range as well as\r
+ // all control characters\r
+ // except tabs and new lines\r
+ if ((ch < 0x00FD && ch > 0x001F) || ch == '\t' || ch == '\n'\r
+ || ch == '\r') {\r
+ newString.append(ch);\r
+ }\r
+ }\r
+ return newString.toString();\r
+\r
}\r
\r
@Override\r