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
.CustomTraceDefinition
.Tag
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
.InputData
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
.InputLine
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
28 * Trace event for custom text parsers.
30 * @author Patrick Tassé
32 public class CustomTxtEvent
extends CustomEvent
{
40 public CustomTxtEvent(CustomTxtTraceDefinition 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
.eventType
!= null) {
88 fData
.put(Tag
.EVENT_TYPE
, input
.eventType
);
90 if (input
.columns
== null) {
93 for (int i
= 0; i
< input
.columns
.size(); i
++) {
94 InputData column
= input
.columns
.get(i
);
95 if (i
< matcher
.groupCount() && matcher
.group(i
+ 1) != null) {
96 String value
= matcher
.group(i
+ 1).trim();
97 if (value
.length() == 0) {
100 Object key
= (column
.tag
.equals(Tag
.OTHER
) ? column
.name
: column
.tag
);
101 if (column
.action
== CustomTraceDefinition
.ACTION_SET
) {
102 fData
.put(key
, value
);
103 if (key
.equals(Tag
.TIMESTAMP
)) {
104 fData
.put(Key
.TIMESTAMP_INPUT_FORMAT
, column
.format
);
106 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
107 String s
= fData
.get(key
);
109 fData
.put(key
, s
+ value
);
111 fData
.put(key
, value
);
113 if (key
.equals(Tag
.TIMESTAMP
)) {
114 String timeStampInputFormat
= fData
.get(Key
.TIMESTAMP_INPUT_FORMAT
);
115 if (timeStampInputFormat
!= null) {
116 fData
.put(Key
.TIMESTAMP_INPUT_FORMAT
, timeStampInputFormat
+ column
.format
);
118 fData
.put(Key
.TIMESTAMP_INPUT_FORMAT
, column
.format
);
121 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
122 String s
= fData
.get(key
);
124 fData
.put(key
, s
+ " | " + value
); //$NON-NLS-1$
126 fData
.put(key
, value
);
128 if (key
.equals(Tag
.TIMESTAMP
)) {
129 String timeStampInputFormat
= fData
.get(Key
.TIMESTAMP_INPUT_FORMAT
);
130 if (timeStampInputFormat
!= null) {
131 fData
.put(Key
.TIMESTAMP_INPUT_FORMAT
, timeStampInputFormat
+ " | " + column
.format
); //$NON-NLS-1$
133 fData
.put(Key
.TIMESTAMP_INPUT_FORMAT
, column
.format
);