Commit | Line | Data |
---|---|---|
6151d86c PT |
1 | /******************************************************************************* |
2 | * Copyright (c) 2010 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom; | |
14 | ||
15 | import java.util.regex.Matcher; | |
16 | ||
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.ITmfTimestamp; | |
21 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; | |
22 | import org.eclipse.linuxtools.tmf.core.event.TmfEventType; | |
23 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
24 | ||
25 | public class CustomTxtEvent extends CustomEvent { | |
26 | ||
27 | public CustomTxtEvent(CustomTxtTraceDefinition definition) { | |
28 | super(definition); | |
29 | setType(new CustomTxtEventType(definition)); | |
30 | } | |
31 | ||
32 | public CustomTxtEvent(CustomTxtTraceDefinition definition, TmfEvent other) { | |
33 | super(definition, other); | |
34 | } | |
35 | ||
36 | public CustomTxtEvent(CustomTxtTraceDefinition definition, ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) { | |
37 | super(definition, parentTrace, timestamp, source, type, reference); | |
38 | } | |
39 | ||
40 | @Override | |
41 | public void setContent(ITmfEventField content) { | |
42 | super.setContent(content); | |
43 | } | |
44 | ||
45 | public void processGroups(InputLine input, Matcher matcher) { | |
46 | if (input.columns == null) { | |
47 | return; | |
48 | } | |
49 | for (int i = 0; i < input.columns.size(); i++) { | |
50 | InputData column = input.columns.get(i); | |
51 | if (i < matcher.groupCount() && matcher.group(i + 1) != null) { | |
52 | String value = matcher.group(i + 1).trim(); | |
53 | if (value.length() == 0) { | |
54 | continue; | |
55 | } | |
56 | String name = column.name; | |
57 | if (column.action == CustomTraceDefinition.ACTION_SET) { | |
58 | fData.put(name, value); | |
59 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
60 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format); | |
61 | } | |
62 | } else if (column.action == CustomTraceDefinition.ACTION_APPEND) { | |
63 | String s = fData.get(name); | |
64 | if (s != null) { | |
65 | fData.put(name, s + value); | |
66 | } else { | |
67 | fData.put(name, value); | |
68 | } | |
69 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
70 | String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); | |
71 | if (timeStampInputFormat != null) { | |
72 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + column.format); | |
73 | } else { | |
74 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format); | |
75 | } | |
76 | } | |
77 | } else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { | |
78 | String s = fData.get(name); | |
79 | if (s != null) { | |
80 | fData.put(name, s + " | " + value); //$NON-NLS-1$ | |
81 | } else { | |
82 | fData.put(name, value); | |
83 | } | |
84 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { | |
85 | String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); | |
86 | if (timeStampInputFormat != null) { | |
87 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$ | |
88 | } else { | |
89 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format); | |
90 | } | |
91 | } | |
92 | } | |
93 | } | |
94 | } | |
95 | } | |
96 | ||
97 | } |