1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 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
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
;
15 import java
.util
.regex
.Matcher
;
17 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.InputData
;
18 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
.InputLine
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventType
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
26 * Trace event for custom text parsers.
28 * @author Patrick Tassé
30 public class CustomTxtEvent
extends CustomEvent
{
38 public CustomTxtEvent(CustomTxtTraceDefinition definition
) {
40 setType(new CustomTxtEventType(definition
));
44 * Construct a custom text event from an existing TmfEvent.
49 * The TmfEvent object to copy
51 public CustomTxtEvent(CustomTxtTraceDefinition definition
, TmfEvent other
) {
52 super(definition
, other
);
63 * Timestamp of this event
65 * Source of this event
69 * Reference if this event
71 public CustomTxtEvent(CustomTxtTraceDefinition definition
,
72 ITmfTrace parentTrace
, ITmfTimestamp timestamp
, String source
,
73 TmfEventType type
, String reference
) {
74 super(definition
, parentTrace
, timestamp
, source
, type
, reference
);
78 public void setContent(ITmfEventField content
) {
79 super.setContent(content
);
83 * Process an entry in the trace file
86 * The input line to read
88 * The regex matcher to use
90 public void processGroups(InputLine input
, Matcher matcher
) {
91 if (input
.columns
== null) {
94 for (int i
= 0; i
< input
.columns
.size(); i
++) {
95 InputData column
= input
.columns
.get(i
);
96 if (i
< matcher
.groupCount() && matcher
.group(i
+ 1) != null) {
97 String value
= matcher
.group(i
+ 1).trim();
98 if (value
.length() == 0) {
101 String name
= column
.name
;
102 if (column
.action
== CustomTraceDefinition
.ACTION_SET
) {
103 fData
.put(name
, value
);
104 if (name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
105 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);
107 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND
) {
108 String s
= fData
.get(name
);
110 fData
.put(name
, s
+ value
);
112 fData
.put(name
, value
);
114 if (name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
115 String timeStampInputFormat
= fData
.get(TIMESTAMP_INPUT_FORMAT_KEY
);
116 if (timeStampInputFormat
!= null) {
117 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, timeStampInputFormat
+ column
.format
);
119 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);
122 } else if (column
.action
== CustomTraceDefinition
.ACTION_APPEND_WITH_SEPARATOR
) {
123 String s
= fData
.get(name
);
125 fData
.put(name
, s
+ " | " + value
); //$NON-NLS-1$
127 fData
.put(name
, value
);
129 if (name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
)) {
130 String timeStampInputFormat
= fData
.get(TIMESTAMP_INPUT_FORMAT_KEY
);
131 if (timeStampInputFormat
!= null) {
132 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, timeStampInputFormat
+ " | " + column
.format
); //$NON-NLS-1$
134 fData
.put(TIMESTAMP_INPUT_FORMAT_KEY
, column
.format
);