1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 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
.io
.ByteArrayInputStream
;
16 import java
.text
.SimpleDateFormat
;
17 import java
.util
.List
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
21 import org
.xml
.sax
.EntityResolver
;
22 import org
.xml
.sax
.ErrorHandler
;
23 import org
.xml
.sax
.InputSource
;
24 import org
.xml
.sax
.SAXException
;
25 import org
.xml
.sax
.SAXParseException
;
28 * Base class for custom trace definitions.
30 * @author Patrick Tassé
32 public abstract class CustomTraceDefinition
{
35 public static final int ACTION_SET
= 0;
37 /** "append" action */
38 public static final int ACTION_APPEND
= 1;
40 /** "append with separator" action */
41 public static final int ACTION_APPEND_WITH_SEPARATOR
= 2;
44 public static final String TAG_TIMESTAMP
= Messages
.CustomTraceDefinition_timestampTag
;
47 public static final String TAG_MESSAGE
= Messages
.CustomTraceDefinition_messageTag
;
50 public static final String TAG_OTHER
= Messages
.CustomTraceDefinition_otherTag
;
52 /** Category of this trace definition */
53 public String categoryName
;
55 /** Name of this trace definition */
56 public String definitionName
;
58 /** List of output columns */
59 public List
<OutputColumn
> outputs
;
61 /** Timestamp format */
62 public String timeStampOutputFormat
;
65 * Definition of an output column
67 public static class OutputColumn
{
69 /** Name of this column */
70 public @NonNull String name
;
73 * Default constructor (empty)
75 public OutputColumn() {
76 this(""); //$NON-NLS-1$
82 * @param name Name of this output column
84 public OutputColumn(@NonNull String name
) {
89 public String
toString() {
95 * Format a timestamp in this trace's current time stamp format.
98 * The timestamp to format
99 * @return The same timestamp as a formatted string
101 public String
formatTimeStamp(TmfTimestamp timestamp
) {
102 SimpleDateFormat simpleDateFormat
= new SimpleDateFormat(timeStampOutputFormat
);
103 return simpleDateFormat
.format(timestamp
.getValue());
107 * Save this custom trace in the default path.
109 public abstract void save();
112 * Save this custom trace in the supplied path.
115 * The path to save to
117 public abstract void save(String path
);
120 * Creates a new empty entity resolver
122 * @return a new entity resolver
124 protected static EntityResolver
createEmptyEntityResolver() {
125 return new EntityResolver() {
127 public InputSource
resolveEntity(String publicId
, String systemId
) {
128 String empty
= ""; //$NON-NLS-1$
129 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
130 return new InputSource(bais
);
136 * Creates an error handler for parse exceptions
138 * @return a new error handler
140 protected static ErrorHandler
createErrorHandler() {
141 return new ErrorHandler() {
143 public void error(SAXParseException saxparseexception
) throws SAXException
{
147 public void warning(SAXParseException saxparseexception
) throws SAXException
{
151 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
152 throw saxparseexception
;