Commit | Line | Data |
---|---|---|
6151d86c | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2010, 2013 Ericsson |
6151d86c PT |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom; | |
14 | ||
15 | import java.util.regex.Matcher; | |
16 | ||
17 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputData; | |
18 | import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine; | |
19 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; | |
6151d86c PT |
20 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
21 | import org.eclipse.linuxtools.tmf.core.event.TmfEventType; | |
3bd46eef | 22 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
6151d86c PT |
23 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
24 | ||
a0a88f65 AM |
25 | /** |
26 | * Trace event for custom text parsers. | |
27 | * | |
28 | * @author Patrick Tassé | |
29 | */ | |
6151d86c PT |
30 | public class CustomTxtEvent extends CustomEvent { |
31 | ||
a0a88f65 AM |
32 | /** |
33 | * Constructor | |
34 | * | |
35 | * @param definition | |
36 | * Trace definition | |
37 | */ | |
6151d86c PT |
38 | public CustomTxtEvent(CustomTxtTraceDefinition definition) { |
39 | super(definition); | |
40 | setType(new CustomTxtEventType(definition)); | |
41 | } | |
42 | ||
a0a88f65 AM |
43 | /** |
44 | * Construct a custom text event from an existing TmfEvent. | |
45 | * | |
46 | * @param definition | |
47 | * Trace definition | |
48 | * @param other | |
49 | * The TmfEvent object to copy | |
50 | */ | |
6151d86c PT |
51 | public CustomTxtEvent(CustomTxtTraceDefinition definition, TmfEvent other) { |
52 | super(definition, other); | |
53 | } | |
54 | ||
a0a88f65 AM |
55 | /** |
56 | * Full constructor. | |
57 | * | |
58 | * @param definition | |
59 | * Trace definition | |
60 | * @param parentTrace | |
61 | * Parent trace object | |
62 | * @param timestamp | |
63 | * Timestamp of this event | |
64 | * @param source | |
65 | * Source of this event | |
66 | * @param type | |
67 | * Event type | |
68 | * @param reference | |
69 | * Reference if this event | |
70 | */ | |
71 | public CustomTxtEvent(CustomTxtTraceDefinition definition, | |
72 | ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, | |
73 | TmfEventType type, String reference) { | |
6151d86c PT |
74 | super(definition, parentTrace, timestamp, source, type, reference); |
75 | } | |
76 | ||
77 | @Override | |
78 | public void setContent(ITmfEventField content) { | |
79 | super.setContent(content); | |
80 | } | |
81 | ||
a0a88f65 AM |
82 | /** |
83 | * Process an entry in the trace file | |
84 | * | |
85 | * @param input | |
86 | * The input line to read | |
87 | * @param matcher | |
88 | * The regex matcher to use | |
89 | */ | |
6151d86c PT |
90 | public void processGroups(InputLine input, Matcher matcher) { |
91 | if (input.columns == null) { | |
92 | return; | |
93 | } | |
94 | for (int i = 0; i < input.columns.size(); i++) { | |
95 | InputData column = input.columns.get(i); | |
96 | if (i < matcher.groupCount() && matcher.group(i + 1) != null) { | |
97 | String value = matcher.group(i + 1).trim(); | |
98 | if (value.length() == 0) { | |
99 | continue; | |
100 | } | |
101 | String name = column.name; | |
102 | if (column.action == CustomTraceDefinition.ACTION_SET) { | |
103 | fData.put(name, value); | |
104 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
105 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format); | |
106 | } | |
107 | } else if (column.action == CustomTraceDefinition.ACTION_APPEND) { | |
108 | String s = fData.get(name); | |
109 | if (s != null) { | |
110 | fData.put(name, s + value); | |
111 | } else { | |
112 | fData.put(name, value); | |
113 | } | |
114 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
115 | String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); | |
116 | if (timeStampInputFormat != null) { | |
117 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + column.format); | |
118 | } else { | |
119 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format); | |
120 | } | |
121 | } | |
122 | } else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { | |
123 | String s = fData.get(name); | |
124 | if (s != null) { | |
125 | fData.put(name, s + " | " + value); //$NON-NLS-1$ | |
126 | } else { | |
127 | fData.put(name, value); | |
128 | } | |
129 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
130 | String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); | |
131 | if (timeStampInputFormat != null) { | |
132 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$ | |
133 | } else { | |
134 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format); | |
135 | } | |
136 | } | |
137 | } | |
138 | } | |
139 | } | |
140 | } | |
141 | ||
142 | } |