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
.columns
== null) {
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) {
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
);
102 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
103 String s
= fData
.get(name
);
105 fData
.put(name
, s
+ value
);
107 fData
.put(name
, value
);
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
);
114 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);
117 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
118 String s
= fData
.get(name
);
120 fData
.put(name
, s
+ " | " + value
); //$NON-NLS-1$
122 fData
.put(name
, value
);
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$
129 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);