]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java
Improve JCR
[gpl/argeo-slc.git] / runtime / org.argeo.slc.specs / src / main / java / org / argeo / slc / process / SlcExecutionStep.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.process;
18
19 import java.util.ArrayList;
20 import java.util.Date;
21 import java.util.List;
22 import java.util.StringTokenizer;
23 import java.util.UUID;
24
25 import org.argeo.slc.execution.ExecutionStep;
26
27 /**
28 * An atomic step to be notified in during an {@link SlcExecution}. Can be a log
29 * or the start/end of a phase, etc.
30 *
31 * @deprecated use {@link ExecutionStep} instead
32 */
33 public class SlcExecutionStep extends ExecutionStep {
34 private static final long serialVersionUID = -7308643628104726471L;
35
36 private String uuid = UUID.randomUUID().toString();
37 private List<String> logLines = new ArrayList<String>();
38
39 /** Empty constructor */
40 public SlcExecutionStep() {
41 }
42
43 /** Creates a step at the current date of type INFO */
44 public SlcExecutionStep(String log) {
45 this(new Date(), INFO, log);
46 }
47
48 /** Creates a step at the current date */
49 public SlcExecutionStep(String type, String log) {
50 this(new Date(), type, log);
51 }
52
53 /** Creates a step of the given type. */
54 public SlcExecutionStep(Date timestamp, String type, String log) {
55 this(timestamp, type, log, Thread.currentThread().getName());
56 }
57
58 public SlcExecutionStep(Date timestamp, String type, String log,
59 String thread) {
60 super("UNKOWN_LOCATION", timestamp, type, log, thread);
61 }
62
63 public String getUuid() {
64 return uuid;
65 }
66
67 public void setUuid(String uuid) {
68 this.uuid = uuid;
69 }
70
71 public void setType(String type) {
72 this.type = type;
73 }
74
75 public void setTimestamp(Date begin) {
76 this.timestamp = begin;
77 }
78
79 public void setThread(String thread) {
80 this.thread = thread;
81 }
82
83 public List<String> getLogLines() {
84 return logLines;
85 }
86
87 public void setLogLines(List<String> logLines) {
88 this.logLines = logLines;
89 }
90
91 /** public for legacy reasons */
92 public String addLog(String log) {
93 if (logLines == null)
94 logLines = new ArrayList<String>();
95
96 if (log == null)
97 return null;
98
99 StringTokenizer st = new StringTokenizer(log, "\n");
100 while (st.hasMoreTokens())
101 logLines.add(removeNonXmlChars(st.nextToken()));
102 return null;
103 }
104
105 /**
106 * Removes non XML compliant characters (from
107 * http://stackoverflow.com/questions
108 * /20762/how-do-you-remove-invalid-hexadecimal
109 * -characters-from-an-xml-based-data-source-pr)
110 */
111 private static String removeNonXmlChars(String inString) {
112 if (inString == null)
113 return null;
114
115 StringBuilder newString = new StringBuilder();
116 char ch;
117
118 for (int i = 0; i < inString.length(); i++) {
119
120 ch = inString.charAt(i);
121 // remove any characters outside the valid UTF-8 range as well as
122 // all control characters
123 // except tabs and new lines
124 if ((ch < 0x00FD && ch > 0x001F) || ch == '\t' || ch == '\n'
125 || ch == '\r') {
126 newString.append(ch);
127 }
128 }
129 return newString.toString();
130
131 }
132
133 @Override
134 public String toString() {
135 return getClass().getSimpleName() + "#" + uuid;
136 }
137
138 }