1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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
) {
41 setType(new CustomTxtEventType(definition
));
45 * Construct a custom text event from an existing TmfEvent.
50 * The TmfEvent object to copy
52 public CustomTxtEvent(CustomTxtTraceDefinition definition
, @NonNull TmfEvent other
) {
53 super(definition
, other
);
64 * Timestamp of this event
68 public CustomTxtEvent(CustomTxtTraceDefinition definition
,
69 ITmfTrace parentTrace
, ITmfTimestamp timestamp
, TmfEventType type
) {
70 super(definition
, parentTrace
, timestamp
, type
);
74 public void setContent(ITmfEventField content
) {
75 super.setContent(content
);
79 * Process an entry in the trace file
82 * The input line to read
84 * The regex matcher to use
86 public void processGroups(InputLine input
, Matcher matcher
) {
87 if (input
.columns
== null) {
90 for (int i
= 0; i
< input
.columns
.size(); i
++) {
91 InputData column
= input
.columns
.get(i
);
92 if (i
< matcher
.groupCount() && matcher
.group(i
+ 1) != null) {
93 String value
= matcher
.group(i
+ 1).trim();
94 if (value
.length() == 0) {
97 String name
= column
.name
;
98 if (column
.action
== CustomTraceDefinition
.ACTION_SET
) {
99 fData
.put(name
, value
);
100 if (name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
101 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);
103 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
104 String s
= fData
.get(name
);
106 fData
.put(name
, s
+ value
);
108 fData
.put(name
, value
);
110 if (name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
111 String timeStampInputFormat
= fData
.get(TIMESTAMP_INPUT_FORMAT_KEY
);
112 if (timeStampInputFormat
!= null) {
113 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, timeStampInputFormat
+ column
.format
);
115 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);
118 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
119 String s
= fData
.get(name
);
121 fData
.put(name
, s
+ " | " + value
); //$NON-NLS-1$
123 fData
.put(name
, value
);
125 if (name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
126 String timeStampInputFormat
= fData
.get(TIMESTAMP_INPUT_FORMAT_KEY
);
127 if (timeStampInputFormat
!= null) {
128 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, timeStampInputFormat
+ " | " + column
.format
); //$NON-NLS-1$
130 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);