X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.specs%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fprocess%2FSlcExecutionStep.java;h=ed52f64ee8412ff5828d56c83965c86409f233fb;hb=30f4c6af6c20077e5e36b61faf5edb22c1aae6c6;hp=5c54b2c6d9c5a0c8498a918fdeb4553917e0cad9;hpb=719f374a748e531ae706115252978e06ad72c308;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java index 5c54b2c6d..ed52f64ee 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java @@ -1,38 +1,72 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.argeo.slc.process; -import java.io.IOException; -import java.io.StringReader; +import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.StringTokenizer; import java.util.UUID; -import org.apache.commons.io.IOUtils; +public class SlcExecutionStep implements Serializable { + private static final long serialVersionUID = -7308643628104726471L; -public class SlcExecutionStep { - public final static String TYPE_START = "START"; - public final static String TYPE_END = "END"; - public final static String TYPE_PHASE_START = "PHASE_START"; - public final static String TYPE_PHASE_END = "PHASE_END"; - public final static String TYPE_LOG = "LOG"; + public final static String START = "START"; + public final static String END = "END"; + public final static String PHASE_START = "PHASE_START"; + public final static String PHASE_END = "PHASE_END"; + public final static String ERROR = "ERROR"; + public final static String WARNING = "WARNING"; + public final static String INFO = "INFO"; + public final static String DEBUG = "DEBUG"; + public final static String TRACE = "TRACE"; private String uuid = UUID.randomUUID().toString(); private String type; - private Date begin = new Date(); + private String thread; + private Date timestamp = new Date(); private List logLines = new ArrayList(); /** Empty constructor */ public SlcExecutionStep() { + thread = Thread.currentThread().getName(); } - /** Creates a step of type LOG. */ + /** Creates a step at the current date of type INFO */ public SlcExecutionStep(String log) { - this(TYPE_LOG, log); + this(new Date(), INFO, log); } - /** Creates a step of the given type. */ + /** Creates a step at the current date */ public SlcExecutionStep(String type, String log) { + this(new Date(), type, log); + } + + /** Creates a step of the given type. */ + public SlcExecutionStep(Date timestamp, String type, String log) { + this(timestamp, type, log, Thread.currentThread().getName()); + } + + public SlcExecutionStep(Date timestamp, String type, String log, + String thread) { this.type = type; + this.timestamp = timestamp; + this.thread = thread; addLog(log); } @@ -52,12 +86,20 @@ public class SlcExecutionStep { this.type = type; } - public Date getBegin() { - return begin; + public Date getTimestamp() { + return timestamp; } - public void setBegin(Date begin) { - this.begin = begin; + public void setTimestamp(Date begin) { + this.timestamp = begin; + } + + public String getThread() { + return thread; + } + + public void setThread(String thread) { + this.thread = thread; } public List getLogLines() { @@ -68,17 +110,41 @@ public class SlcExecutionStep { this.logLines = logLines; } - @SuppressWarnings(value = { "unchecked" }) public void addLog(String log) { if (log == null) return; - try { - List lines = IOUtils.readLines(new StringReader(log)); - logLines.addAll(lines); - } catch (IOException e) { - throw new RuntimeException("Cannot add log", e); + StringTokenizer st = new StringTokenizer(log, "\n"); + while (st.hasMoreTokens()) + logLines.add(removeNonXmlChars(st.nextToken())); + } + + /** + * Removes non XML compliant characters (from + * http://stackoverflow.com/questions + * /20762/how-do-you-remove-invalid-hexadecimal + * -characters-from-an-xml-based-data-source-pr) + */ + private static String removeNonXmlChars(String inString) { + if (inString == null) + return null; + + StringBuilder newString = new StringBuilder(); + char ch; + + for (int i = 0; i < inString.length(); i++) { + + ch = inString.charAt(i); + // remove any characters outside the valid UTF-8 range as well as + // all control characters + // except tabs and new lines + if ((ch < 0x00FD && ch > 0x001F) || ch == '\t' || ch == '\n' + || ch == '\r') { + newString.append(ch); + } } + return newString.toString(); + } @Override