02f3954c3d78b132ffe814b88273c6a36b705e2a
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomTxtEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 Ericsson
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.tracecompass.tmf.core.parsers.custom;
14
15 import java.util.regex.Matcher;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
19 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
20 import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
21 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData;
22 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputLine;
23 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
24 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
25
26 /**
27 * Trace event for custom text parsers.
28 *
29 * @author Patrick Tassé
30 */
31 public class CustomTxtEvent extends CustomEvent {
32
33 /**
34 * Constructor
35 *
36 * @param definition
37 * Trace definition
38 */
39 public CustomTxtEvent(CustomTxtTraceDefinition definition) {
40 super(definition);
41 }
42
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 */
51 public CustomTxtEvent(CustomTxtTraceDefinition definition, @NonNull TmfEvent other) {
52 super(definition, other);
53 }
54
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 type
65 * Event type
66 */
67 public CustomTxtEvent(CustomTxtTraceDefinition definition,
68 ITmfTrace parentTrace, ITmfTimestamp timestamp, TmfEventType type) {
69 super(definition, parentTrace, timestamp, type);
70 }
71
72 @Override
73 public void setContent(ITmfEventField content) {
74 super.setContent(content);
75 }
76
77 /**
78 * Process an entry in the trace file
79 *
80 * @param input
81 * The input line to read
82 * @param matcher
83 * The regex matcher to use
84 */
85 public void processGroups(InputLine input, Matcher matcher) {
86 if (input.columns == null) {
87 return;
88 }
89 for (int i = 0; i < input.columns.size(); i++) {
90 InputData column = input.columns.get(i);
91 if (i < matcher.groupCount() && matcher.group(i + 1) != null) {
92 String value = matcher.group(i + 1).trim();
93 if (value.length() == 0) {
94 continue;
95 }
96 String name = column.name;
97 if (column.action == CustomTraceDefinition.ACTION_SET) {
98 fData.put(name, value);
99 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
100 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
101 }
102 } else if (column.action == CustomTraceDefinition.ACTION_APPEND) {
103 String s = fData.get(name);
104 if (s != null) {
105 fData.put(name, s + value);
106 } else {
107 fData.put(name, value);
108 }
109 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
110 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
111 if (timeStampInputFormat != null) {
112 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + column.format);
113 } else {
114 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
115 }
116 }
117 } else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
118 String s = fData.get(name);
119 if (s != null) {
120 fData.put(name, s + " | " + value); //$NON-NLS-1$
121 } else {
122 fData.put(name, value);
123 }
124 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
125 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
126 if (timeStampInputFormat != null) {
127 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$
128 } else {
129 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
130 }
131 }
132 }
133 }
134 }
135 }
136
137 }
This page took 0.037733 seconds and 4 git commands to generate.