A new Tag enum is added as part of the custom parser definition model.
The 'tag' attribute is added to the XML definition.
For backward compatibility if the 'tag' attribute is not present when
loading a definition from XML, the Tag is determined from the 'name'
attribute.
In the internal payload data map of the custom event, the map's key is
changed from a String to an Object that can either be the Tag, a String,
or an enum constant, to ensure there is no conflict of keys.
If the tag is OTHER, the wizards should ensure that the user-entered
name does not conflict with one of the built-in tag labels.
Change-Id: If9bf65fb32d646cda4f24f28bf41941f1f5c85f6
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/76257
Reviewed-by: Hudson CI
<InputLine>
<Cardinality max="2147483647" min="0"/>
<RegEx>(\S*\s\S*) (.*\S)</RegEx>
-<InputData action="0" format="dd/MM/yyyy HH:mm:ss:SSS" name="Time Stamp"/>
-<InputData action="0" format="" name="Message"/>
+<InputData action="0" format="dd/MM/yyyy HH:mm:ss:SSS" name="Timestamp" tag="TIMESTAMP"/>
+<InputData action="0" format="" name="Message" tag="MESSAGE"/>
<InputLine>
<Cardinality max="2147483647" min="0"/>
<RegEx>(.*\S)</RegEx>
-<InputData action="2" name="Message"/>
+<InputData action="2" tag="MESSAGE"/>
</InputLine>
</InputLine>
-<OutputColumn name="Time Stamp"/>
-<OutputColumn name="Message"/>
+<OutputColumn name="Time Stamp" tag="TIMESTAMP"/>
+<OutputColumn name="Message" tag="MESSAGE"/>
</Definition>
<Definition name="testtxtevname">
<TimeStampOutputFormat>dd/MM/yyyy HH:mm:ss:SSS</TimeStampOutputFormat>
<InputLine>
<Cardinality max="2147483647" min="0"/>
<RegEx>(\d*) (.*\S)</RegEx>
-<InputData action="0" format="Tn" name="Time Stamp"/>
-<InputData action="0" format="" name="Event type"/>
+<InputData action="0" format="Tn" name="Timestamp" tag="TIMESTAMP"/>
+<InputData action="0" name="Event type" tag="EVENT_TYPE"/>
<InputLine>
<Cardinality max="2147483647" min="0"/>
<RegEx>(.*\S)</RegEx>
-<InputData action="2" name="Message"/>
+<InputData action="2" name="Message" tag="MESSAGE"/>
</InputLine>
</InputLine>
-<OutputColumn name="Time Stamp"/>
-<OutputColumn name="Event type"/>
+<OutputColumn name="Timestamp" tag="TIMESTAMP"/>
+<OutputColumn name="Event type" tag="EVENT_TYPE"/>
</Definition>
</CustomTxtTraceDefinitionList>
<TimeStampOutputFormat>HH:mm:ss:SSS</TimeStampOutputFormat>
<InputElement name="trace">
<InputElement logentry="true" name="element">
-<InputData action="0" format="" name="Message"/>
+<InputData action="0" name="Message" tag="MESSAGE"/>
<Attribute name="time">
-<InputData action="0" format="dd/MM/yyyy HH:mm:ss:SSS" name="Time Stamp"/>
+<InputData action="0" format="dd/MM/yyyy HH:mm:ss:SSS" name="Timestamp" tag="TIMESTAMP"/>
</Attribute>
</InputElement>
</InputElement>
-<OutputColumn name="Time Stamp"/>
-<OutputColumn name="Message"/>
+<OutputColumn name="Timestamp" tag="TIMESTAMP"/>
+<OutputColumn name="Message" tag="MESSAGE"/>
</Definition>
<Definition name="xmlevname">
<TimeStampOutputFormat>HH:mm:ss:SSS</TimeStampOutputFormat>
<InputElement name="trace">
<InputElement logentry="true" name="element">
-<InputData action="0" format="" name="Event type"/>
+<InputData action="0" name="Event type" tag="EVENT_TYPE"/>
<Attribute name="time">
-<InputData action="0" format="Tn" name="Time Stamp"/>
+<InputData action="0" format="Tn" name="Timestamp" tag="TIMESTAMP"/>
</Attribute>
</InputElement>
</InputElement>
-<OutputColumn name="Time Stamp"/>
-<OutputColumn name="Event type"/>
+<OutputColumn name="Timestamp" tag="TIMESTAMP"/>
+<OutputColumn name="Event type" tag="EVENT_TYPE"/>
</Definition>
</CustomXMLTraceDefinitionList>
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
*/
public class CustomEvent extends TmfEvent {
- /** Input format key */
+ /** Payload data map key
+ * @since 2.1*/
+ protected enum Key {
+ /** Timestamp input format */
+ TIMESTAMP_INPUT_FORMAT
+ }
+
+ /** Input format key
+ * @deprecated Use {@link Key#TIMESTAMP_INPUT_FORMAT} instead. */
+ @Deprecated
protected static final String TIMESTAMP_INPUT_FORMAT_KEY = "CE_TS_I_F"; //$NON-NLS-1$
/** Empty message */
/** The trace to which this event belongs */
protected CustomTraceDefinition fDefinition;
- /** The payload data of this event, <field name, value> */
- protected Map<String, String> fData;
+ /**
+ * The payload data of this event, where the key is one of: the {@link Tag},
+ * the field name string if the tag is {@link Tag#OTHER}, or
+ * {@link Key#TIMESTAMP_INPUT_FORMAT}.
+ */
+ protected Map<Object, String> fData;
private TmfEventField[] fColumnData;
}
private void processData() {
- String timestampString = fData.get(CustomTraceDefinition.TAG_TIMESTAMP);
- String timestampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+ String timestampString = fData.get(Tag.TIMESTAMP);
+ String timestampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
ITmfTimestamp timestamp = null;
if (timestampInputFormat != null && timestampString != null) {
TmfTimestampFormat timestampFormat = new TmfTimestampFormat(timestampInputFormat);
}
// Update the custom event type of this event if set
- String eventName = fData.get(CustomTraceDefinition.TAG_EVENT_TYPE);
+ String eventName = fData.get(Tag.EVENT_TYPE);
ITmfEventType type = getType();
if (eventName != null && type instanceof CustomEventType) {
((CustomEventType) type).setName(eventName);
int i = 0;
fColumnData = new TmfEventField[fDefinition.outputs.size()];
for (OutputColumn outputColumn : fDefinition.outputs) {
- String value = fData.get(outputColumn.name);
- if (outputColumn.name.equals(CustomTraceDefinition.TAG_TIMESTAMP) && timestamp != null) {
+ Object key = (outputColumn.tag.equals(Tag.OTHER) ? outputColumn.name : outputColumn.tag);
+ String value = fData.get(key);
+ if (outputColumn.tag.equals(Tag.TIMESTAMP) && timestamp != null) {
TmfTimestampFormat timestampFormat = new TmfTimestampFormat(fDefinition.timeStampOutputFormat);
fColumnData[i++] = new TmfEventField(outputColumn.name, timestampFormat.format(timestamp.getValue()), null);
} else {
package org.eclipse.tracecompass.tmf.core.parsers.custom;
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
import java.io.ByteArrayInputStream;
import java.text.SimpleDateFormat;
+import java.util.AbstractMap.SimpleEntry;
import java.util.List;
+import java.util.Map.Entry;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+import org.w3c.dom.Element;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
/** "append with separator" action */
public static final int ACTION_APPEND_WITH_SEPARATOR = 2;
- /** Timestamp tag */
+ /**
+ * Input tag
+ *
+ * @since 2.1
+ */
+ public enum Tag {
+ /** Ignore */
+ IGNORE(Messages.CustomXmlTraceDefinition_ignoreTag),
+ /** Timestamp */
+ TIMESTAMP(TmfBaseAspects.getTimestampAspect().getName()),
+ /** Event type */
+ EVENT_TYPE(TmfBaseAspects.getEventTypeAspect().getName()),
+ /** Message */
+ MESSAGE(Messages.CustomTraceDefinition_messageTag),
+ /** Other */
+ OTHER(Messages.CustomTraceDefinition_otherTag);
+
+ private final String fLabel;
+
+ private Tag(String label) {
+ fLabel = label;
+ }
+
+ @Override
+ public String toString() {
+ return fLabel;
+ }
+
+ /**
+ * Get a tag from its label (toString).
+ *
+ * @param label
+ * the label
+ * @return the corresponding tag, or null
+ */
+ public static Tag fromLabel(String label) {
+ for (Tag tag : Tag.values()) {
+ if (tag.toString().equals(label)) {
+ return tag;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get a tag from its name (identifier).
+ *
+ * @param name
+ * the name
+ * @return the corresponding tag, or null
+ */
+ public static Tag fromName(String name) {
+ for (Tag tag : Tag.values()) {
+ if (tag.name().equals(name)) {
+ return tag;
+ }
+ }
+ return null;
+ }
+ }
+
+ /** Timestamp tag
+ * @deprecated Use {@link Tag#TIMESTAMP} instead. */
+ @Deprecated
public static final String TAG_TIMESTAMP = Messages.CustomTraceDefinition_timestampTag;
- /** Message tag */
+ /** Message tag
+ * @deprecated Use {@link Tag#MESSAGE} instead. */
+ @Deprecated
public static final String TAG_MESSAGE = Messages.CustomTraceDefinition_messageTag;
- /** "Other" tag */
+ /** "Other" tag
+ * @deprecated Use {@link Tag#OTHER} instead. */
+ @Deprecated
public static final String TAG_OTHER = Messages.CustomTraceDefinition_otherTag;
- /** Event type tag
- * @since 2.1*/
- public static final String TAG_EVENT_TYPE = Messages.CustomTraceDefinition_eventTypeTag;
-
/** Category of this trace definition */
public String categoryName;
*/
public static class OutputColumn {
+ /** Tag of this input
+ * @since 2.1*/
+ public @NonNull Tag tag;
+
/** Name of this column */
public @NonNull String name;
/**
* Default constructor (empty)
+ * @deprecated Use {@link OutputColumn#OutputColumn(Tag, String)}
+ * instead.
*/
+ @Deprecated
public OutputColumn() {
- this(""); //$NON-NLS-1$
+ this(Tag.IGNORE, ""); //$NON-NLS-1$
}
/**
* Constructor
*
- * @param name Name of this output column
+ * @param name
+ * Name of this output column
+ * @deprecated Use {@link OutputColumn#OutputColumn(Tag, String)}
+ * instead.
*/
+ @Deprecated
public OutputColumn(@NonNull String name) {
+ this.tag = Tag.OTHER;
+ this.name = name;
+ }
+
+ /**
+ * Constructor
+ *
+ * @param tag
+ * Tag of this output column
+ * @param name
+ * Name of this output column
+ * @since 2.1
+ */
+ public OutputColumn(@NonNull Tag tag, @NonNull String name) {
+ this.tag = tag;
this.name = name;
}
}
};
}
+
+ /**
+ * Extract the tag and name from an XML element
+ *
+ * @param element
+ * the XML element
+ * @param tagAttribute
+ * the tag attribute
+ * @param nameAttribute
+ * the name attribute
+ * @return an entry where the key is the tag and the value is the name
+ * @since 2.1
+ */
+ protected static Entry<@NonNull Tag, @NonNull String> extractTagAndName(Element element, String tagAttribute, String nameAttribute) {
+ Tag tag = Tag.fromName(element.getAttribute(tagAttribute));
+ String name = element.getAttribute(nameAttribute);
+ if (tag == null) {
+ // Backward compatibility
+ if (name.equals(Messages.CustomTraceDefinition_timestampTag)) {
+ tag = Tag.TIMESTAMP;
+ name = checkNotNull(Tag.TIMESTAMP.toString());
+ } else if (name.equals(Messages.CustomTraceDefinition_messageTag)) {
+ tag = Tag.MESSAGE;
+ name = checkNotNull(Tag.MESSAGE.toString());
+ } else if (name.equals(Messages.CustomXmlTraceDefinition_ignoreTag)) {
+ tag = Tag.IGNORE;
+ name = checkNotNull(Tag.IGNORE.toString());
+ } else {
+ tag = Tag.OTHER;
+ }
+ } else if (name.isEmpty()) {
+ name = checkNotNull(tag.toString());
+ }
+ return new SimpleEntry<>(tag, name);
+ }
}
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputLine;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
*/
public void processGroups(InputLine input, Matcher matcher) {
if (input.eventType != null) {
- fData.put(CustomTraceDefinition.TAG_EVENT_TYPE, input.eventType);
+ fData.put(Tag.EVENT_TYPE, input.eventType);
}
if (input.columns == null) {
return;
if (value.length() == 0) {
continue;
}
- String name = column.name;
+ Object key = (column.tag.equals(Tag.OTHER) ? column.name : column.tag);
if (column.action == CustomTraceDefinition.ACTION_SET) {
- fData.put(name, value);
- if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
+ fData.put(key, value);
+ if (key.equals(Tag.TIMESTAMP)) {
+ fData.put(Key.TIMESTAMP_INPUT_FORMAT, column.format);
}
} else if (column.action == CustomTraceDefinition.ACTION_APPEND) {
- String s = fData.get(name);
+ String s = fData.get(key);
if (s != null) {
- fData.put(name, s + value);
+ fData.put(key, s + value);
} else {
- fData.put(name, value);
+ fData.put(key, value);
}
- if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
- String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+ if (key.equals(Tag.TIMESTAMP)) {
+ String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
if (timeStampInputFormat != null) {
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + column.format);
+ fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + column.format);
} else {
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
+ fData.put(Key.TIMESTAMP_INPUT_FORMAT, column.format);
}
}
} else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
- String s = fData.get(name);
+ String s = fData.get(key);
if (s != null) {
- fData.put(name, s + " | " + value); //$NON-NLS-1$
+ fData.put(key, s + " | " + value); //$NON-NLS-1$
} else {
- fData.put(name, value);
+ fData.put(key, value);
}
- if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
- String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+ if (key.equals(Tag.TIMESTAMP)) {
+ String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
if (timeStampInputFormat != null) {
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$
+ fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$
} else {
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
+ fData.put(Key.TIMESTAMP_INPUT_FORMAT, column.format);
}
}
}
import java.util.Comparator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.internal.tmf.core.Activator;
import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
import org.w3c.dom.Document;
private static final String CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT = Messages.CustomTxtTraceDefinition_definitionRootElement;
private static final String DEFINITION_ELEMENT = Messages.CustomTxtTraceDefinition_definition;
private static final String CATEGORY_ATTRIBUTE = Messages.CustomTxtTraceDefinition_category;
+ private static final String TAG_ATTRIBUTE = Messages.CustomTxtTraceDefinition_tag;
private static final String NAME_ATTRIBUTE = Messages.CustomTxtTraceDefinition_name;
private static final String TIME_STAMP_OUTPUT_FORMAT_ELEMENT = Messages.CustomTxtTraceDefinition_timestampOutputFormat;
private static final String INPUT_LINE_ELEMENT = Messages.CustomTxtTraceDefinition_inputLine;
*/
public static class InputData {
- /** Name of this column */
+ /** Tag of this input
+ * @since 2.1*/
+ public Tag tag;
+
+ /** Name of this input for "Other" tag */
public String name;
/** Action id */
this.name = name;
this.action = action;
}
+
+ /**
+ * Constructor
+ *
+ * @param tag
+ * Tag
+ * @param action
+ * Action
+ * @since 2.1
+ */
+ public InputData(Tag tag, int action) {
+ this.tag = tag;
+ this.action = action;
+ }
}
/**
for (OutputColumn output : outputs) {
Element outputColumnElement = doc.createElement(OUTPUT_COLUMN_ELEMENT);
definitionElement.appendChild(outputColumnElement);
+ outputColumnElement.setAttribute(TAG_ATTRIBUTE, output.tag.name());
outputColumnElement.setAttribute(NAME_ATTRIBUTE, output.name);
}
}
for (InputData inputData : inputLine.columns) {
Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);
inputLineElement.appendChild(inputDataElement);
+ inputDataElement.setAttribute(TAG_ATTRIBUTE, inputData.tag.name());
inputDataElement.setAttribute(NAME_ATTRIBUTE, inputData.name);
inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(inputData.action));
if (inputData.format != null) {
}
} else if (nodeName.equals(OUTPUT_COLUMN_ELEMENT)) {
Element outputColumnElement = (Element) node;
- OutputColumn outputColumn = new OutputColumn();
- outputColumn.name = outputColumnElement.getAttribute(NAME_ATTRIBUTE);
+ Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(outputColumnElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE);
+ OutputColumn outputColumn = new OutputColumn(entry.getKey(), entry.getValue());
def.outputs.add(outputColumn);
}
}
} else if (nodeName.equals(INPUT_DATA_ELEMENT)) {
Element inputDataElement = (Element) node;
InputData inputData = new InputData();
- inputData.name = inputDataElement.getAttribute(NAME_ATTRIBUTE);
+ Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(inputDataElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE);
+ inputData.tag = checkNotNull(entry.getKey());
+ inputData.name = checkNotNull(entry.getValue());
inputData.action = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));
inputData.format = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);
inputLine.addColumn(inputData);
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
* @param name Name
* @param inputAction Input action
* @param inputFormat Input format
+ * @deprecated Use {@link #parseInput(String, Tag, String, int, String)} instead.
*/
+ @Deprecated
public void parseInput(String value, String name, int inputAction, String inputFormat) {
+ }
+
+ /**
+ * Parse an entry.
+ *
+ * @param value Value
+ * @param inputTag Input tag
+ * @param inputName Input name
+ * @param inputAction Input action
+ * @param inputFormat Input format
+ * @since 2.1
+ */
+ public void parseInput(String value, Tag inputTag, String inputName, int inputAction, String inputFormat) {
if (value.length() == 0) {
return;
}
+ Object key = (inputTag.equals(Tag.OTHER) ? inputName : inputTag);
if (inputAction == CustomTraceDefinition.ACTION_SET) {
- fData.put(name, value);
- if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);
+ fData.put(key, value);
+ if (key.equals(Tag.TIMESTAMP)) {
+ fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat);
}
} else if (inputAction == CustomTraceDefinition.ACTION_APPEND) {
- String s = fData.get(name);
+ String s = fData.get(key);
if (s != null) {
- fData.put(name, s + value);
+ fData.put(key, s + value);
} else {
- fData.put(name, value);
+ fData.put(key, value);
}
- if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
- String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+ if (key.equals(Tag.TIMESTAMP)) {
+ String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
if (timeStampInputFormat != null) {
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + inputFormat);
+ fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + inputFormat);
} else {
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);
+ fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat);
}
}
} else if (inputAction == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
- String s = fData.get(name);
+ String s = fData.get(key);
if (s != null) {
- fData.put(name, s + " | " + value); //$NON-NLS-1$
+ fData.put(key, s + " | " + value); //$NON-NLS-1$
} else {
- fData.put(name, value);
+ fData.put(key, value);
}
- if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
- String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+ if (key.equals(Tag.TIMESTAMP)) {
+ String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
if (timeStampInputFormat != null) {
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$
+ fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$
} else {
- fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);
+ fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat);
}
}
}
/*******************************************************************************
- * Copyright (c) 2014 Ericsson
+ * Copyright (c) 2014, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
*******************************************************************************/
package org.eclipse.tracecompass.tmf.core.parsers.custom;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
+
/**
* Wrapper for XML element attributes
*/
/** Name of the XML attribute */
private final String fAttributeName;
+ /** Input tag */
+ private final Tag fInputTag;
+
/** Input name */
private final String fInputName;
* Input action
* @param inputFormat
* Input format
+ * @deprecated Use
+ * {@link #CustomXmlInputAttribute(String, Tag, String, int, String)}
+ * instead.
*/
+ @Deprecated
public CustomXmlInputAttribute(String attributeName, String inputName,
int inputAction, String inputFormat) {
fAttributeName = attributeName;
+ fInputTag = Tag.IGNORE;
+ fInputName = inputName;
+ fInputAction = inputAction;
+ fInputFormat = inputFormat;
+ }
+
+ /**
+ * Constructor
+ *
+ * @param attributeName
+ * Name of the XML attribute
+ * @param inputTag
+ * Input tag
+ * @param inputName
+ * Input name
+ * @param inputAction
+ * Input action
+ * @param inputFormat
+ * Input format
+ * @since 2.1
+ */
+ public CustomXmlInputAttribute(String attributeName, Tag inputTag,
+ String inputName, int inputAction, String inputFormat) {
+ fAttributeName = attributeName;
+ fInputTag = inputTag;
fInputName = inputName;
fInputAction = inputAction;
fInputFormat = inputFormat;
return fAttributeName;
}
+ /**
+ * @return the inputTag
+ * @since 2.1
+ */
+ public Tag getInputTag() {
+ return fInputTag;
+ }
+
/**
* @return the inputName
*/
/*******************************************************************************
- * Copyright (c) 2014 Ericsson
+ * Copyright (c) 2014, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
+
/**
* Wrapper for input XML elements
*/
/** Indicates if this is a log entry */
private boolean fLogEntry;
+ /** Tag of the input element */
+ private Tag fInputTag;
+
/** Name of the input element */
private String fInputName;
* @param logEntry
* If this element is a log entry
* @param inputName
- * Name of the the input
+ * Name of the input
* @param inputAction
* Input action
* @param inputFormat
* Input format
* @param attributes
* XML attributes of this element
+ * @deprecated Use
+ * {@link #CustomXmlInputElement(String, boolean, Tag, String, int, String, List)}
+ * instead.
*/
+ @Deprecated
public CustomXmlInputElement(String elementName, boolean logEntry,
String inputName, int inputAction, String inputFormat,
List<CustomXmlInputAttribute> attributes) {
fAttributes = attributes;
}
+ /**
+ * Constructor
+ *
+ * @param elementName
+ * Element name
+ * @param logEntry
+ * If this element is a log entry
+ * @param inputTag
+ * Tag of the input
+ * @param inputName
+ * Name of the input
+ * @param inputAction
+ * Input action
+ * @param inputFormat
+ * Input format
+ * @param attributes
+ * XML attributes of this element
+ * @since 2.1
+ */
+ public CustomXmlInputElement(String elementName, boolean logEntry, Tag inputTag,
+ String inputName, int inputAction, String inputFormat,
+ List<CustomXmlInputAttribute> attributes) {
+ fElementName = elementName;
+ fLogEntry = logEntry;
+ fInputTag = inputTag;
+ fInputName = inputName;
+ fInputAction = inputAction;
+ fInputFormat = inputFormat;
+ fAttributes = attributes;
+ }
+
/**
* Add a XML attribute to the element
*
fLogEntry = logEntry;
}
+ /**
+ * @return the inputTag
+ * @since 2.1
+ */
+ public Tag getInputTag() {
+ return fInputTag;
+ }
+
+ /**
+ * @param inputTag
+ * the inputTag to set
+ * @since 2.1
+ */
+ public void setInputTag(Tag inputTag) {
+ fInputTag = inputTag;
+ }
+
/**
* @return the inputName
*/
import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
if (eventType != null && event.getType() instanceof CustomEventType) {
((CustomEventType) event.getType()).setName(eventType);
}
- if (inputElement.getInputName() != null && !inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
- event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.getInputName(), inputElement.getInputAction(), inputElement.getInputFormat());
+ if (!inputElement.getInputTag().equals(Tag.IGNORE)) {
+ event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.getInputTag(), inputElement.getInputName(), inputElement.getInputAction(), inputElement.getInputFormat());
}
if (inputElement.getAttributes() != null) {
for (final CustomXmlInputAttribute attribute : inputElement.getAttributes()) {
- event.parseInput(element.getAttribute(attribute.getAttributeName()), attribute.getInputName(), attribute.getInputAction(), attribute.getInputFormat());
+ event.parseInput(element.getAttribute(attribute.getAttributeName()), attribute.getInputTag(), attribute.getInputName(), attribute.getInputAction(), attribute.getInputFormat());
}
}
final NodeList childNodes = element.getChildNodes();
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.internal.tmf.core.Activator;
import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
import org.w3c.dom.Document;
*/
public class CustomXmlTraceDefinition extends CustomTraceDefinition {
- /** "ignore" tag */
+ /** Ignore tag
+ * @deprecated Use {@link Tag#IGNORE} instead. */
+ @Deprecated
public static final String TAG_IGNORE = Messages.CustomXmlTraceDefinition_ignoreTag;
/**
private static final String CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT = Messages.CustomXmlTraceDefinition_definitionRootElement;
private static final String DEFINITION_ELEMENT = Messages.CustomXmlTraceDefinition_definition;
private static final String CATEGORY_ATTRIBUTE = Messages.CustomXmlTraceDefinition_category;
+ private static final String TAG_ATTRIBUTE = Messages.CustomXmlTraceDefinition_tag;
private static final String NAME_ATTRIBUTE = Messages.CustomXmlTraceDefinition_name;
private static final String LOG_ENTRY_ATTRIBUTE = Messages.CustomXmlTraceDefinition_logEntry;
private static final String EVENT_TYPE_ATTRIBUTE = Messages.CustomXmlTraceDefinition_eventType;
for (OutputColumn output : outputs) {
Element outputColumnElement = doc.createElement(OUTPUT_COLUMN_ELEMENT);
definitionElement.appendChild(outputColumnElement);
+ outputColumnElement.setAttribute(TAG_ATTRIBUTE, output.tag.name());
outputColumnElement.setAttribute(NAME_ATTRIBUTE, output.name);
}
}
if (inputElement.getParentElement() != null) {
Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);
inputElementElement.appendChild(inputDataElement);
+ inputDataElement.setAttribute(TAG_ATTRIBUTE, inputElement.getInputTag().name());
inputDataElement.setAttribute(NAME_ATTRIBUTE, inputElement.getInputName());
inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(inputElement.getInputAction()));
- if (inputElement.getInputFormat() != null) {
- inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputElement.getInputFormat());
+ String inputFormat = inputElement.getInputFormat();
+ if (inputFormat != null && !inputFormat.isEmpty()) {
+ inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputFormat);
}
}
inputAttributeElement.setAttribute(NAME_ATTRIBUTE, attribute.getAttributeName());
Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);
inputAttributeElement.appendChild(inputDataElement);
+ inputDataElement.setAttribute(TAG_ATTRIBUTE, attribute.getInputTag().name());
inputDataElement.setAttribute(NAME_ATTRIBUTE, attribute.getInputName());
inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(attribute.getInputAction()));
- if (attribute.getInputFormat() != null) {
- inputDataElement.setAttribute(FORMAT_ATTRIBUTE, attribute.getInputFormat());
+ String inputFormat = attribute.getInputFormat();
+ if (inputFormat != null && !inputFormat.isEmpty()) {
+ inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputFormat);
}
}
}
}
} else if (nodeName.equals(OUTPUT_COLUMN_ELEMENT)) {
Element outputColumnElement = (Element) node;
- OutputColumn outputColumn = new OutputColumn();
- outputColumn.name = outputColumnElement.getAttribute(NAME_ATTRIBUTE);
+ Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(outputColumnElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE);
+ OutputColumn outputColumn = new OutputColumn(entry.getKey(), entry.getValue());
def.outputs.add(outputColumn);
}
}
String nodeName = node.getNodeName();
if (nodeName.equals(INPUT_DATA_ELEMENT)) {
Element inputDataElement = (Element) node;
- inputElement.setInputName(inputDataElement.getAttribute(NAME_ATTRIBUTE));
+ Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(inputDataElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE);
+ inputElement.setInputTag(entry.getKey());
+ inputElement.setInputName(entry.getValue());
inputElement.setInputAction(Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE)));
inputElement.setInputFormat(inputDataElement.getAttribute(FORMAT_ATTRIBUTE));
} else if (nodeName.equals(ATTRIBUTE_ELEMENT)) {
Element attributeElement = (Element) node;
String attributeName = attributeElement.getAttribute(NAME_ATTRIBUTE);
- String inputName = null;
- int inputAction = 0;
- String inputFormat = null;
NodeList attributeNodeList = attributeElement.getChildNodes();
for (int j = 0; j < attributeNodeList.getLength(); j++) {
Node attributeNode = attributeNodeList.item(j);
String attributeNodeName = attributeNode.getNodeName();
if (attributeNodeName.equals(INPUT_DATA_ELEMENT)) {
Element inputDataElement = (Element) attributeNode;
- inputName = inputDataElement.getAttribute(NAME_ATTRIBUTE);
- inputAction = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));
- inputFormat = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);
+ Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(inputDataElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE);
+ int action = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));
+ String format = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);
+ inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, entry.getKey(), entry.getValue(), action, format));
+ break;
}
}
- inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, inputName, inputAction, inputFormat));
} else if (nodeName.equals(INPUT_ELEMENT_ELEMENT)) {
Element childInputElementElement = (Element) node;
CustomXmlInputElement childInputElement = extractInputElement(childInputElementElement);
public static String CustomTxtTraceDefinition_name;
public static String CustomTxtTraceDefinition_outputColumn;
public static String CustomTxtTraceDefinition_regEx;
+ /** @since 2.1 */
+ public static String CustomTxtTraceDefinition_tag;
public static String CustomTxtTraceDefinition_timestampOutputFormat;
public static String CustomXmlTraceDefinition_action;
public static String CustomXmlTraceDefinition_attribute;
public static String CustomXmlTraceDefinition_logEntry;
public static String CustomXmlTraceDefinition_name;
public static String CustomXmlTraceDefinition_outputColumn;
+ /** @since 2.1 */
+ public static String CustomXmlTraceDefinition_tag;
public static String CustomXmlTraceDefinition_timestampOutputFormat;
static {
CustomTxtTraceDefinition_name=name
CustomTxtTraceDefinition_outputColumn=OutputColumn
CustomTxtTraceDefinition_regEx=RegEx
+CustomTxtTraceDefinition_tag=tag
CustomTxtTraceDefinition_timestampOutputFormat=TimeStampOutputFormat
CustomXmlTraceDefinition_action=action
CustomXmlTraceDefinition_attribute=Attribute
CustomXmlTraceDefinition_logEntry=logentry
CustomXmlTraceDefinition_name=name
CustomXmlTraceDefinition_outputColumn=OutputColumn
+CustomXmlTraceDefinition_tag=tag
CustomXmlTraceDefinition_timestampOutputFormat=TimeStampOutputFormat
/*******************************************************************************
- * Copyright (c) 2014, 2015 Ericsson
+ * Copyright (c) 2014, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
"<InputLine>\n" +
"<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
"<RegEx>\\s*(\\d\\d)\\s(.*\\S)</RegEx>\n" +
- "<InputData action=\"0\" format=\"ss\" name=\"Time Stamp\"/>\n" +
- "<InputData action=\"0\" name=\"Message\"/>\n" +
+ "<InputData action=\"0\" format=\"ss\" name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
+ "<InputData action=\"0\" name=\"Message\" tag=\"MESSAGE\"/>\n" +
"</InputLine>\n" +
"<InputLine>\n" +
"<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
"<RegEx>([^0-9]*)</RegEx>\n" +
- "<InputData action=\"2\" name=\"Message\"/>\n" +
+ "<InputData action=\"2\" name=\"Message\" tag=\"MESSAGE\"/>\n" +
"</InputLine>\n" +
- "<OutputColumn name=\"Time Stamp\"/>\n" +
- "<OutputColumn name=\"Message\"/>\n";
+ "<OutputColumn name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
+ "<OutputColumn name=\"Message\" tag=\"MESSAGE\"/>\n";
/**
* Test to create a custom txt trace and compare the xml
fBot.textWithLabel("Time Stamp format:").setText("ss");
// Fill Group 1 as time stamp
- fBot.comboBox(1).setSelection("Time Stamp");
+ fBot.comboBox(1).setSelection("Timestamp");
fBot.textWithLabel("format:").setText("ss");
// Click on the New group button
fBot.button(8).click();
"<InputLine>\n" +
"<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
"<RegEx>\\s*(\\d*)\\s(.*)</RegEx>\n" +
- "<InputData action=\"0\" format=\"sss\" name=\"Time Stamp\"/>\n" +
- "<InputData action=\"0\" name=\"Message\"/>\n" +
+ "<InputData action=\"0\" format=\"sss\" name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
+ "<InputData action=\"0\" name=\"Message\" tag=\"MESSAGE\"/>\n" +
"</InputLine>\n" +
- "<OutputColumn name=\"Time Stamp\"/>\n" +
- "<OutputColumn name=\"Message\"/>\n" +
+ "<OutputColumn name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
+ "<OutputColumn name=\"Message\" tag=\"MESSAGE\"/>\n" +
"</Definition>\n" +
"<Definition name=\"dmesg\">\n" +
"<TimeStampOutputFormat>sssssss.ssssss</TimeStampOutputFormat>\n" +
"<InputLine>\n" +
"<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
"<RegEx>^[([0-9]*\\.[0.9]*)]\\s(.*)</RegEx>\n" +
- "<InputData action=\"0\" format=\"sssss.sssss\" name=\"Time Stamp\"/>\n" +
- "<InputData action=\"0\" name=\"Message\"/>\n" +
+ "<InputData action=\"0\" format=\"sssss.sssss\" name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
+ "<InputData action=\"0\" name=\"Message\" tag=\"MESSAGE\"/>\n" +
"</InputLine>\n" +
- "<OutputColumn name=\"Time Stamp\"/>\n" +
- "<OutputColumn name=\"Message\"/>\n" +
+ "<OutputColumn name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
+ "<OutputColumn name=\"Message\" tag=\"MESSAGE\"/>\n" +
"</Definition>\n" +
"</CustomTxtTraceDefinitionList>";
fw.write(xmlContent);
fBot.textWithLabel("Time Stamp format:").setText("ss");
// update time stamp format
- fBot.comboBox(1).setSelection("Time Stamp");
+ fBot.comboBox(1).setSelection("Timestamp");
fBot.textWithLabel("format:").setText("ss");
fBot.button(2).click();
SWTBotTreeItem[] treeItems = fBot.tree().getAllItems();
"<TimeStampOutputFormat>ss</TimeStampOutputFormat>\n" +
"<InputElement name=\"trace\">\n" +
"<InputElement logentry=\"true\" name=\"event\">\n" +
- "<InputData action=\"0\" format=\"\" name=\"Ignore\"/>\n" +
+ "<InputData action=\"0\" name=\"Ignore\" tag=\"IGNORE\"/>\n" +
"<Attribute name=\"msg\">\n" +
- "<InputData action=\"0\" name=\"msg\"/>\n" +
+ "<InputData action=\"0\" name=\"msg\" tag=\"OTHER\"/>\n" +
"</Attribute>\n" +
"<Attribute name=\"time\">\n" +
- "<InputData action=\"0\" name=\"time\"/>\n" +
+ "<InputData action=\"0\" name=\"time\" tag=\"OTHER\"/>\n" +
"</Attribute>\n" +
"</InputElement>\n" +
"</InputElement>\n" +
- "<OutputColumn name=\"msg\"/>\n" +
- "<OutputColumn name=\"time\"/>\n";
+ "<OutputColumn name=\"msg\" tag=\"OTHER\"/>\n" +
+ "<OutputColumn name=\"time\" tag=\"OTHER\"/>\n";
/**
* Test to create a custom XML trace and compare the XML generated
public static String CustomXmlParserInputWizardPage_elementMissingTimestampFmtError;
public static String CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError;
public static String CustomXmlParserInputWizardPage_elementDuplicateNameError;
+ public static String CustomXmlParserInputWizardPage_elementReservedInputNameError;
public static String CustomXmlParserInputWizardPage_attributeMissingNameError;
public static String CustomXmlParserInputWizardPage_attributeMissingInputNameError;
public static String CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError;
public static String CustomXmlParserInputWizardPage_attributeInvalidTimestampFmtError;
public static String CustomXmlParserInputWizardPage_attributeDuplicateNameError;
+ public static String CustomXmlParserInputWizardPage_attributeReservedInputNameError;
public static String CustomXmlParserInputWizardPage_addAttribute;
public static String CustomXmlParserInputWizardPage_addChildElement;
public static String CustomXmlParserInputWizardPage_addDocumentEleemnt;
CustomXmlParserInputWizardPage_elementMissingTimestampFmtError=Enter the input format for the Time Stamp (Element {0}).
CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError=Enter a valid output format for the Time Stamp field (Element {0}).
CustomXmlParserInputWizardPage_elementDuplicateNameError=Duplicate element names (Element {0}).
+CustomXmlParserInputWizardPage_elementReservedInputNameError=Cannot use reserved name for the input (Element {0}).
CustomXmlParserInputWizardPage_attributeMissingNameError=Enter a name for the attribute (Attribute {0}: ?).
CustomXmlParserInputWizardPage_attributeMissingInputNameError=Enter a name for the input (Attribute {0}).
CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError=Enter the input format for the Time Stamp (Attribute {0}).
CustomXmlParserInputWizardPage_attributeInvalidTimestampFmtError=Enter a valid input format for the Time Stamp (Attribute {0}).
CustomXmlParserInputWizardPage_attributeDuplicateNameError=Duplicate attribute names (Attribute {0}).
+CustomXmlParserInputWizardPage_attributeReservedInputNameError=Cannot use reserved name for the input (Attribute {0}).
CustomXmlParserInputWizardPage_addAttribute=Add attribute
CustomXmlParserInputWizardPage_addChildElement=Add child element
CustomXmlParserInputWizardPage_addDocumentEleemnt=Add document element
/*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import java.io.InputStreamReader;
import java.net.URL;
import java.text.ParseException;
+import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.tracecompass.internal.tmf.ui.Activator;
import org.eclipse.tracecompass.internal.tmf.ui.Messages;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.Cardinality;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData;
if (definition == null) {
definition = new CustomTxtTraceDefinition();
definition.inputs.add(new InputLine(Cardinality.ZERO_OR_MORE, DEFAULT_REGEX,
- Arrays.asList(new InputData(CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.ACTION_SET))));
+ Arrays.asList(new InputData(Tag.MESSAGE, CustomTraceDefinition.ACTION_SET))));
}
loadDefinition(definition);
treeViewer.expandAll();
}
/**
- * Get the global list of input names.
+ * Get the global list of inputs.
*
- * @return The list of input names
+ * @return The list of inputs
*/
- public List<String> getInputNames() {
- List<String> inputs = new ArrayList<>();
+ public List<Entry<Tag, String>> getInputs() {
+ List<Entry<Tag, String>> inputs = new ArrayList<>();
for (InputLine inputLine : definition.inputs) {
- for (String inputName : getInputNames(inputLine)) {
- if (!inputs.contains(inputName)) {
- inputs.add(inputName);
+ for (Entry<Tag, String> input : getInputs(inputLine)) {
+ if (!inputs.contains(input)) {
+ inputs.add(input);
}
}
}
}
/**
- * Get the list of input names for the given input line.
+ * Get the list of inputs for the given input line, recursively.
*
* @param inputLine
* The input line
- * @return The list of input names
+ * @return The list of inputs
*/
- public List<String> getInputNames(InputLine inputLine) {
- List<String> inputs = new ArrayList<>();
+ private List<Entry<Tag, String>> getInputs(InputLine inputLine) {
+ List<Entry<Tag, String>> inputs = new ArrayList<>();
if (inputLine.columns != null) {
for (InputData inputData : inputLine.columns) {
- String inputName = inputData.name;
- if (!inputs.contains(inputName)) {
- inputs.add(inputName);
+ Entry<Tag, String> input = new SimpleEntry<>(inputData.tag, inputData.name);
+ if (!inputs.contains(input)) {
+ inputs.add(input);
}
}
}
if (inputLine.childrenInputs != null) {
for (InputLine childInputLine : inputLine.childrenInputs) {
- for (String inputName : getInputNames(childInputLine)) {
- if (!inputs.contains(inputName)) {
- inputs.add(inputName);
+ for (Entry<Tag, String> input : getInputs(childInputLine)) {
+ if (!inputs.contains(input)) {
+ inputs.add(input);
}
}
}
}
}
- Map<String, String> data = new HashMap<>();
+ Map<Object, String> data = new HashMap<>();
int rootLineMatches = 0;
String firstEntryTimeStamp = null;
String firstEntryTimeStampInputFormat = null;
timeStampFormat = null;
updatePreviewLine(rootInputLine, matcher, data, rawPos, rootLineMatches);
if (rootLineMatches == 1) {
- firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP);
+ firstEntryTimeStamp = data.get(Tag.TIMESTAMP);
firstEntryTimeStampInputFormat = timeStampFormat;
}
HashMap<InputLine, Integer> countMap = new HashMap<>();
}
if (rootLineMatches == 1) {
- firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP);
+ firstEntryTimeStamp = data.get(Tag.TIMESTAMP);
firstEntryTimeStampInputFormat = timeStampFormat;
}
if (firstEntryTimeStamp == null) {
timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noTimestampGroup);
if (selectedLine != null) {
for (InputGroup group : selectedLine.inputs) {
- if (group.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (group.tagCombo.getText().equals(Tag.TIMESTAMP.toString())) {
timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp);
break;
}
}
}
- private void updatePreviewLine(InputLine line, Matcher matcher, Map<String, String> data, int rawPos, int rootLineMatches) {
+ private void updatePreviewLine(InputLine line, Matcher matcher, Map<Object, String> data, int rawPos, int rootLineMatches) {
for (int i = 0; i < line.columns.size(); i++) {
InputData input = line.columns.get(i);
if (i < matcher.groupCount() && matcher.group(i + 1) != null) {
if (value.length() == 0) {
continue;
}
+ Object key = (input.tag.equals(Tag.OTHER) ? input.name : input.tag);
if (input.action == CustomTraceDefinition.ACTION_SET) {
- data.put(input.name, value);
- if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ data.put(key, value);
+ if (input.tag.equals(Tag.TIMESTAMP)) {
timeStampFormat = input.format;
}
} else if (input.action == CustomTraceDefinition.ACTION_APPEND) {
- String s = data.get(input.name);
+ String s = data.get(key);
if (s != null) {
- data.put(input.name, s + value);
+ data.put(key, s + value);
} else {
- data.put(input.name, value);
+ data.put(key, value);
}
- if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (input.tag.equals(Tag.TIMESTAMP)) {
if (timeStampFormat != null) {
timeStampFormat += input.format;
} else {
}
}
} else if (input.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
- String s = data.get(input.name);
+ String s = data.get(key);
if (s != null) {
- data.put(input.name, s + " | " + value); //$NON-NLS-1$
+ data.put(key, s + " | " + value); //$NON-NLS-1$
} else {
- data.put(input.name, value);
+ data.put(key, value);
}
- if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (input.tag.equals(Tag.TIMESTAMP)) {
if (timeStampFormat != null) {
timeStampFormat += " | " + input.format; //$NON-NLS-1$
} else {
if (inputLine.columns != null) {
for (InputData inputData : inputLine.columns) {
InputGroup inputGroup = new InputGroup(group, this, inputs.size() + 1);
- if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (inputData.tag.equals(Tag.TIMESTAMP)) {
inputGroup.tagCombo.select(0);
inputGroup.tagText.setText(inputData.format);
inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format);
inputGroup.tagLabel.setVisible(true);
inputGroup.tagText.setVisible(true);
inputGroup.tagText.addModifyListener(updateListener);
- } else if (inputData.name.equals(CustomTraceDefinition.TAG_EVENT_TYPE)) {
+ } else if (inputData.tag.equals(Tag.EVENT_TYPE)) {
inputGroup.tagCombo.select(1);
- } else if (inputData.name.equals(CustomTraceDefinition.TAG_MESSAGE)) {
+ } else if (inputData.tag.equals(Tag.MESSAGE)) {
inputGroup.tagCombo.select(2);
} else {
inputGroup.tagCombo.select(3);
for (int i = 0; i < inputs.size(); i++) {
InputGroup grp = inputs.get(i);
InputData inputData = new InputData();
- if (grp.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
+ inputData.tag = Tag.fromLabel(grp.tagCombo.getText());
+ if (inputData.tag.equals(Tag.OTHER)) {
inputData.name = grp.tagText.getText().trim();
} else {
- inputData.name = grp.tagCombo.getText();
- if (grp.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ inputData.name = inputData.tag.toString();
+ if (inputData.tag.equals(Tag.TIMESTAMP)) {
inputData.format = grp.tagText.getText().trim();
}
}
tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
- tagCombo.setItems(new String[] { CustomTraceDefinition.TAG_TIMESTAMP,
- CustomTraceDefinition.TAG_EVENT_TYPE,
- CustomTraceDefinition.TAG_MESSAGE,
- CustomTraceDefinition.TAG_OTHER});
+ tagCombo.setItems(new String[] {
+ Tag.TIMESTAMP.toString(),
+ Tag.EVENT_TYPE.toString(),
+ Tag.MESSAGE.toString(),
+ Tag.OTHER.toString()});
tagCombo.select(2);
tagCombo.addSelectionListener(new SelectionListener() {
@Override
if (line != null) {
group = line.inputs.get(i);
}
- if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (inputData.tag.equals(Tag.TIMESTAMP)) {
timestampFound = true;
if (inputData.format.length() == 0) {
errors.append("Enter the input format for the Time Stamp (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
}
- } else if (inputData.name.length() == 0) {
- errors.append("Enter a name for the data group (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- if (group != null) {
- group.tagText.setBackground(COLOR_LIGHT_RED);
+ } else if (inputData.tag.equals(Tag.OTHER)) {
+ if (inputData.name.isEmpty()) {
+ errors.append("Enter a name for the data group (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (group != null) {
+ group.tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else if (Tag.fromLabel(inputData.name) != null) {
+ errors.append("Cannot use reserved name for the data group (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (group != null) {
+ group.tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else {
+ if (group != null) {
+ group.tagText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
}
} else {
if (group != null) {
/*******************************************************************************
- * Copyright (c) 2010, 2015 Ericsson
+ * Copyright (c) 2010, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map.Entry;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.tracecompass.internal.tmf.ui.Messages;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
private void loadDefinition(final CustomTxtTraceDefinition def) {
for (final OutputColumn outputColumn : def.outputs) {
- final Output output = new Output(outputsContainer, outputColumn.name);
+ final Output output = new Output(outputsContainer, outputColumn.tag, outputColumn.name);
outputs.add(output);
}
}
public void setVisible(final boolean visible) {
if (visible) {
this.definition = wizard.inputPage.getDefinition();
- final List<String> outputNames = wizard.inputPage.getInputNames();
+ final List<Entry<Tag, String>> inputs = wizard.inputPage.getInputs();
// dispose outputs that have been removed in the input page
final Iterator<Output> iter = outputs.iterator();
while (iter.hasNext()) {
final Output output = iter.next();
boolean found = false;
- for (final String name : outputNames) {
- if (output.name.equals(name)) {
+ for (final Entry<Tag, String> input : inputs) {
+ if (output.tag.equals(input.getKey()) &&
+ output.name.equals(input.getValue())) {
found = true;
break;
}
}
// create outputs that have been added in the input page
- for (final String name : outputNames) {
+ for (final Entry<Tag, String> input : inputs) {
boolean found = false;
for (final Output output : outputs) {
- if (output.name.equals(name)) {
+ if (output.tag.equals(input.getKey()) &&
+ output.name.equals(input.getValue())) {
found = true;
break;
}
}
if (!found) {
- outputs.add(new Output(outputsContainer, name));
+ outputs.add(new Output(outputsContainer, input.getKey(), input.getValue()));
}
}
* @return The output columns
*/
public List<OutputColumn> extractOutputs() {
- int numColumns = 0;
- for (int i = 0; i < outputs.size(); i++) {
- if (outputs.get(i).enabledButton.getSelection()) {
- numColumns++;
- }
- }
- final List<OutputColumn> outputColumns = new ArrayList<>(numColumns);
- numColumns = 0;
- for (int i = 0; i < outputs.size(); i++) {
- final Output output = outputs.get(i);
+ final List<OutputColumn> outputColumns = new ArrayList<>();
+ for (Output output : outputs) {
if (output.enabledButton.getSelection()) {
- final OutputColumn column = new OutputColumn();
- column.name = checkNotNull(output.nameLabel.getText());
+ final OutputColumn column = new OutputColumn(checkNotNull(output.tag), checkNotNull(output.name));
outputColumns.add(column);
}
}
}
private class Output {
+ Tag tag;
String name;
Button enabledButton;
Text nameLabel;
Button upButton;
Button downButton;
- public Output(final Composite parent, final String name) {
+ public Output(final Composite parent, final Tag tag, final String name) {
+ this.tag = tag;
this.name = name;
enabledButton = new Button(parent, SWT.CHECK);
/*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import java.io.InputStreamReader;
import java.net.URL;
import java.text.ParseException;
+import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map.Entry;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.eclipse.tracecompass.internal.tmf.ui.Activator;
import org.eclipse.tracecompass.internal.tmf.ui.Messages;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputAttribute;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputElement;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace;
addChildButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
+ CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, Tag.IGNORE, Tag.IGNORE.toString(), 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
if (definition.rootInputElement == null) {
definition.rootInputElement = inputElement;
inputElement.setElementName(getChildNameSuggestion(null));
addNextButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
+ CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, Tag.IGNORE, Tag.IGNORE.toString(), 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
if (definition.rootInputElement == null) {
definition.rootInputElement = inputElement;
inputElement.setElementName(getChildNameSuggestion(null));
CustomXmlInputElement inputElement = null;
if (definition.rootInputElement == null) {
if (getChildNameSuggestion(null).length() != 0) {
- inputElement = new CustomXmlInputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$
+ inputElement = new CustomXmlInputElement(getChildNameSuggestion(null), false, Tag.IGNORE, Tag.IGNORE.toString(), 0, "", null); //$NON-NLS-1$
definition.rootInputElement = inputElement;
feelingLucky(inputElement);
} else {
if (attributeName.length() == 0) {
break;
}
- CustomXmlInputAttribute attribute = new CustomXmlInputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$
+ CustomXmlInputAttribute attribute = new CustomXmlInputAttribute(attributeName, Tag.OTHER, attributeName, 0, ""); //$NON-NLS-1$
inputElement.addAttribute(attribute);
}
while (true) {
if (childName.length() == 0) {
break;
}
- CustomXmlInputElement childElement = new CustomXmlInputElement(childName, false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$
+ CustomXmlInputElement childElement = new CustomXmlInputElement(childName, false, Tag.IGNORE, Tag.IGNORE.toString(), 0, "", null); //$NON-NLS-1$
inputElement.addChild(childElement);
feelingLucky(childElement);
}
}
/**
- * Get the global list of input names.
+ * Get the global list of inputs.
*
- * @return The list of input names
+ * @return The list of inputs
*/
- public List<String> getInputNames() {
- return getInputNames(definition.rootInputElement);
+ public List<Entry<Tag, String>> getInputs() {
+ return getInputs(definition.rootInputElement);
}
/**
- * Get the list of input names for a given element.
+ * Get the list of inputs for a given element, recursively.
*
* @param inputElement
* The element
- * @return The input names for this element
+ * @return The list of inputs
*/
- public List<String> getInputNames(CustomXmlInputElement inputElement) {
- List<String> inputs = new ArrayList<>();
- if (inputElement.getInputName() != null && !inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
- String inputName = inputElement.getInputName();
- if (!inputs.contains(inputName)) {
- inputs.add(inputName);
+ public List<Entry<Tag, String>> getInputs(CustomXmlInputElement inputElement) {
+ List<Entry<Tag, String>> inputs = new ArrayList<>();
+ if (inputElement.getInputTag() != null && !inputElement.getInputTag().equals(Tag.IGNORE)) {
+ Entry<Tag, String> input = new SimpleEntry<>(inputElement.getInputTag(), inputElement.getInputName());
+ if (!inputs.contains(input)) {
+ inputs.add(input);
}
}
if (inputElement.getAttributes() != null) {
for (CustomXmlInputAttribute attribute : inputElement.getAttributes()) {
- String inputName = attribute.getInputName();
- if (!inputs.contains(inputName)) {
- inputs.add(inputName);
+ Entry<Tag, String> input = new SimpleEntry<>(attribute.getInputTag(), attribute.getInputName());
+ if (!inputs.contains(input)) {
+ inputs.add(input);
}
}
}
if (inputElement.getChildElements() != null) {
for (CustomXmlInputElement childInputElement : inputElement.getChildElements()) {
- for (String inputName : getInputNames(childInputElement)) {
- if (!inputs.contains(inputName)) {
- inputs.add(inputName);
+ for (Entry<Tag, String> input : getInputs(childInputElement)) {
+ if (!inputs.contains(input)) {
+ inputs.add(input);
}
}
}
tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
- tagCombo.setItems(new String[] { CustomXmlTraceDefinition.TAG_IGNORE, CustomTraceDefinition.TAG_TIMESTAMP,
- CustomTraceDefinition.TAG_EVENT_TYPE, CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.TAG_OTHER });
+ tagCombo.setItems(new String[] {
+ Tag.IGNORE.toString(),
+ Tag.TIMESTAMP.toString(),
+ Tag.EVENT_TYPE.toString(),
+ Tag.MESSAGE.toString(),
+ Tag.OTHER.toString() });
tagCombo.setVisibleItemCount(tagCombo.getItemCount());
tagCombo.addSelectionListener(new SelectionListener() {
@Override
actionCombo.select(inputElement.getInputAction());
actionCombo.addSelectionListener(updateListener);
- if (inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
+ if (inputElement.getInputTag().equals(Tag.IGNORE)) {
tagCombo.select(0);
tagLabel.setVisible(false);
tagText.setVisible(false);
actionCombo.setVisible(false);
- } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ } else if (inputElement.getInputTag().equals(Tag.TIMESTAMP)) {
tagCombo.select(1);
tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
tagText.setText(inputElement.getInputFormat());
tagText.addModifyListener(updateListener);
- } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_EVENT_TYPE)) {
+ } else if (inputElement.getInputTag().equals(Tag.EVENT_TYPE)) {
tagCombo.select(2);
tagLabel.setVisible(false);
tagText.setVisible(false);
- } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_MESSAGE)) {
+ } else if (inputElement.getInputTag().equals(Tag.MESSAGE)) {
tagCombo.select(3);
tagLabel.setVisible(false);
tagText.setVisible(false);
logEntryButton.setSelection(false);
}
}
- if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {
+ if (tagCombo.getText().equals(Tag.TIMESTAMP.toString()) && logEntriesCount <= 1) {
String value = previewText.getText().trim();
if (value.length() != 0) {
if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) {
String value = element.getAttribute(attribute.attributeNameText.getText().trim());
if (value.length() != 0) {
attribute.previewText.setText(value);
- if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {
+ if (attribute.tagCombo.getText().equals(Tag.TIMESTAMP.toString()) && logEntriesCount <= 1) {
if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) {
timeStampValue = value;
timeStampFormat = attribute.tagText.getText().trim();
public void widgetSelected(SelectionEvent e) {
removeAddButton();
String attributeName = getAttributeNameSuggestion(inputElement);
- CustomXmlInputAttribute inputAttribute = new CustomXmlInputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$
+ CustomXmlInputAttribute inputAttribute = new CustomXmlInputAttribute(attributeName, Tag.OTHER, attributeName, 0, ""); //$NON-NLS-1$
attributes.add(new Attribute(group, ElementNode.this, inputAttribute, attributes.size() + 1));
createAddButton();
elementContainer.layout();
if (inputElement.getParentElement() != null) {
inputElement.setLogEntry(logEntryButton.getSelection());
inputElement.setEventType(eventTypeButton.getSelection() ? eventTypeText.getText().trim() : null);
- if (tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
+ Tag inputTag = Tag.fromLabel(tagCombo.getText());
+ inputElement.setInputTag(inputTag);
+ if (inputTag.equals(Tag.OTHER)) {
inputElement.setInputName(tagText.getText().trim());
} else {
- inputElement.setInputName(tagCombo.getText());
- if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ inputElement.setInputName(inputTag.toString());
+ if (inputTag.equals(Tag.TIMESTAMP)) {
inputElement.setInputFormat(tagText.getText().trim());
}
}
String inputFormat = null;
Attribute attribute = attributes.get(i);
String attributeName = attribute.attributeNameText.getText().trim();
- if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
+ Tag inputTag = Tag.fromLabel(attribute.tagCombo.getText());
+ if (inputTag.equals(Tag.OTHER)) {
inputName = attribute.tagText.getText().trim();
} else {
- inputName = attribute.tagCombo.getText();
- if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ inputName = inputTag.toString();
+ if (inputTag.equals(Tag.TIMESTAMP)) {
inputFormat = attribute.tagText.getText().trim();
}
}
int inputAction = attribute.actionCombo.getSelectionIndex();
- inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, inputName, inputAction, inputFormat));
+ inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, inputTag, inputName, inputAction, inputFormat));
}
}
}
tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
- tagCombo.setItems(new String[] { CustomTraceDefinition.TAG_TIMESTAMP, CustomTraceDefinition.TAG_EVENT_TYPE,
- CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.TAG_OTHER });
+ tagCombo.setItems(new String[] {
+ Tag.TIMESTAMP.toString(),
+ Tag.EVENT_TYPE.toString(),
+ Tag.MESSAGE.toString(),
+ Tag.OTHER.toString() });
tagCombo.select(3); // Other
tagCombo.addSelectionListener(new SelectionListener() {
@Override
actionCombo.select(inputAttribute.getInputAction());
actionCombo.addSelectionListener(updateListener);
- if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (inputAttribute.getInputTag().equals(Tag.TIMESTAMP)) {
tagCombo.select(0);
tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
tagText.setText(inputAttribute.getInputFormat());
tagText.addModifyListener(updateListener);
- } else if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_EVENT_TYPE)) {
+ } else if (inputAttribute.getInputTag().equals(Tag.EVENT_TYPE)) {
tagCombo.select(1);
tagLabel.setVisible(false);
tagText.setVisible(false);
- } else if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_MESSAGE)) {
+ } else if (inputAttribute.getInputTag().equals(Tag.MESSAGE)) {
tagCombo.select(2);
tagLabel.setVisible(false);
tagText.setVisible(false);
if (inputElement.isLogEntry()) {
logEntryFound = true;
}
- if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (inputElement.getInputTag().equals(Tag.TIMESTAMP)) {
timeStampFound = true;
if (inputElement.getInputFormat().length() == 0) {
errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementMissingTimestampFmtError, getName(inputElement)));
if (elementNode != null) {
elementNode.tagText.setBackground(COLOR_LIGHT_RED);
}
+ } else if (inputElement.getInputTag().equals(Tag.OTHER) && Tag.fromLabel(inputElement.getInputName()) != null) {
+ errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementReservedInputNameError, getName(inputElement)));
+ if (elementNode != null) {
+ elementNode.tagText.setBackground(COLOR_LIGHT_RED);
+ }
} else {
if (elementNode != null) {
elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);
elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED);
}
}
- if (attribute.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (attribute.getInputTag().equals(Tag.TIMESTAMP)) {
timeStampFound = true;
if (attribute.getInputFormat().length() == 0) {
errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError, getName(attribute, inputElement)));
if (elementNode != null) {
elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
}
+ } else if (attribute.getInputTag().equals(Tag.OTHER) && Tag.fromLabel(attribute.getInputName()) != null) {
+ errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeReservedInputNameError, getName(attribute, inputElement)));
+ if (elementNode != null) {
+ elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
+ }
} else {
if (elementNode != null) {
elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND);
/*******************************************************************************
- * Copyright (c) 2010, 2015 Ericsson
+ * Copyright (c) 2010, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map.Entry;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
private void loadDefinition(final CustomTraceDefinition def) {
for (final OutputColumn outputColumn : def.outputs) {
- final Output output = new Output(outputsContainer, outputColumn.name);
+ final Output output = new Output(outputsContainer, outputColumn.tag, outputColumn.name);
outputs.add(output);
}
}
public void setVisible(final boolean visible) {
if (visible) {
this.definition = wizard.inputPage.getDefinition();
- final List<String> outputNames = wizard.inputPage.getInputNames();
+ final List<Entry<Tag, String>> inputs = wizard.inputPage.getInputs();
// dispose outputs that have been removed in the input page
final Iterator<Output> iter = outputs.iterator();
while (iter.hasNext()) {
final Output output = iter.next();
boolean found = false;
- for (final String name : outputNames) {
- if (output.name.equals(name)) {
+ for (final Entry<Tag, String> input : inputs) {
+ if (output.tag.equals(input.getKey()) &&
+ output.name.equals(input.getValue())) {
found = true;
break;
}
}
// create outputs that have been added in the input page
- for (final String name : outputNames) {
+ for (final Entry<Tag, String> input : inputs) {
boolean found = false;
for (final Output output : outputs) {
- if (output.name.equals(name)) {
+ if (output.tag.equals(input.getKey()) &&
+ output.name.equals(input.getValue())) {
found = true;
break;
}
}
if (!found) {
- outputs.add(new Output(outputsContainer, name));
+ outputs.add(new Output(outputsContainer, input.getKey(), input.getValue()));
}
}
* @return The list of output columns
*/
public List<OutputColumn> extractOutputs() {
- int numColumns = 0;
- for (int i = 0; i < outputs.size(); i++) {
- if (outputs.get(i).enabledButton.getSelection()) {
- numColumns++;
- }
- }
- final List<OutputColumn> outputColumns = new ArrayList<>(numColumns);
- numColumns = 0;
- for (int i = 0; i < outputs.size(); i++) {
- final Output output = outputs.get(i);
+ final List<OutputColumn> outputColumns = new ArrayList<>();
+ for (Output output : outputs) {
if (output.enabledButton.getSelection()) {
- final OutputColumn column = new OutputColumn();
- column.name = checkNotNull(output.nameLabel.getText());
+ final OutputColumn column = new OutputColumn(checkNotNull(output.tag), checkNotNull(output.name));
outputColumns.add(column);
}
}
}
private class Output {
+ Tag tag;
String name;
Button enabledButton;
Text nameLabel;
Button upButton;
Button downButton;
- public Output(final Composite parent, final String name) {
+ public Output(final Composite parent, final Tag tag, final String name) {
+ this.tag = tag;
this.name = name;
enabledButton = new Button(parent, SWT.CHECK);