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
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEvent
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventType
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
.InputData
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
.InputLine
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
26 * Trace event for custom text parsers.
28 * @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
, TmfEvent other
) {
53 super(definition
, other
);
64 * Timestamp of this event
66 * Source of this event
70 * Reference if this event
72 public CustomTxtEvent(CustomTxtTraceDefinition definition
,
73 ITmfTrace parentTrace
, ITmfTimestamp timestamp
, String source
,
74 TmfEventType type
, String reference
) {
75 super(definition
, parentTrace
, timestamp
, source
, type
, reference
);
79 public void setContent(ITmfEventField content
) {
80 super.setContent(content
);
84 * Process an entry in the trace file
87 * The input line to read
89 * The regex matcher to use
91 public void processGroups(InputLine input
, Matcher matcher
) {
92 if (input
.columns
== null) {
95 for (int i
= 0; i
< input
.columns
.size(); i
++) {
96 InputData column
= input
.columns
.get(i
);
97 if (i
< matcher
.groupCount() && matcher
.group(i
+ 1) != null) {
98 String value
= matcher
.group(i
+ 1).trim();
99 if (value
.length() == 0) {
102 String name
= column
.name
;
103 if (column
.action
== CustomTraceDefinition
.ACTION_SET
) {
104 fData
.put(name
, value
);
105 if (name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
106 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);
108 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
109 String s
= fData
.get(name
);
111 fData
.put(name
, s
+ value
);
113 fData
.put(name
, value
);
115 if (name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
116 String timeStampInputFormat
= fData
.get(TIMESTAMP_INPUT_FORMAT_KEY
);
117 if (timeStampInputFormat
!= null) {
118 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, timeStampInputFormat
+ column
.format
);
120 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);
123 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
124 String s
= fData
.get(name
);
126 fData
.put(name
, s
+ " | " + value
); //$NON-NLS-1$
128 fData
.put(name
, value
);
130 if (name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
131 String timeStampInputFormat
= fData
.get(TIMESTAMP_INPUT_FORMAT_KEY
);
132 if (timeStampInputFormat
!= null) {
133 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, timeStampInputFormat
+ " | " + column
.format
); //$NON-NLS-1$
135 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);