1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
;
15 import java
.util
.regex
.Matcher
;
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
;
27 * Trace event for custom text parsers.
29 * @author Patrick Tassé
31 public class CustomTxtEvent
extends CustomEvent
{
39 public CustomTxtEvent(CustomTxtTraceDefinition definition
) {
44 * Construct a custom text event from an existing TmfEvent.
49 * The TmfEvent object to copy
51 public CustomTxtEvent(CustomTxtTraceDefinition definition
, @NonNull TmfEvent other
) {
52 super(definition
, other
);
63 * Timestamp of this event
67 public CustomTxtEvent(CustomTxtTraceDefinition definition
,
68 ITmfTrace parentTrace
, ITmfTimestamp timestamp
, TmfEventType type
) {
69 super(definition
, parentTrace
, timestamp
, type
);
73 public void setContent(ITmfEventField content
) {
74 super.setContent(content
);
78 * Process an entry in the trace file
81 * The input line to read
83 * The regex matcher to use
85 public void processGroups(InputLine input
, Matcher matcher
) {
86 if (input
.eventType
!= null) {
87 fData
.put(CustomTraceDefinition
.TAG_EVENT_TYPE
, input
.eventType
);
89 if (input
.columns
== null) {
92 for (int i
= 0; i
< input
.columns
.size(); i
++) {
93 InputData column
= input
.columns
.get(i
);
94 if (i
< matcher
.groupCount() && matcher
.group(i
+ 1) != null) {
95 String value
= matcher
.group(i
+ 1).trim();
96 if (value
.length() == 0) {
99 String name
= column
.name
;
100 if (column
.action
== CustomTraceDefinition
.ACTION_SET
) {
101 fData
.put(name
, value
);
102 if (name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
103 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);
105 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
106 String s
= fData
.get(name
);
108 fData
.put(name
, s
+ value
);
110 fData
.put(name
, value
);
112 if (name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
113 String timeStampInputFormat
= fData
.get(TIMESTAMP_INPUT_FORMAT_KEY
);
114 if (timeStampInputFormat
!= null) {
115 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, timeStampInputFormat
+ column
.format
);
117 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);
120 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
121 String s
= fData
.get(name
);
123 fData
.put(name
, s
+ " | " + value
); //$NON-NLS-1$
125 fData
.put(name
, value
);
127 if (name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
128 String timeStampInputFormat
= fData
.get(TIMESTAMP_INPUT_FORMAT_KEY
);
129 if (timeStampInputFormat
!= null) {
130 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, timeStampInputFormat
+ " | " + column
.format
); //$NON-NLS-1$
132 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);