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
.io
.ByteArrayInputStream
;
16 import java
.text
.SimpleDateFormat
;
17 import java
.util
.List
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
20 import org
.xml
.sax
.EntityResolver
;
21 import org
.xml
.sax
.ErrorHandler
;
22 import org
.xml
.sax
.InputSource
;
23 import org
.xml
.sax
.SAXException
;
24 import org
.xml
.sax
.SAXParseException
;
27 * Base class for custom trace definitions.
29 * @author Patrick Tassé
31 public abstract class CustomTraceDefinition
{
34 public static final int ACTION_SET
= 0;
36 /** "append" action */
37 public static final int ACTION_APPEND
= 1;
39 /** "append with separator" action */
40 public static final int ACTION_APPEND_WITH_SEPARATOR
= 2;
43 public static final String TAG_TIMESTAMP
= Messages
.CustomTraceDefinition_timestampTag
;
46 public static final String TAG_MESSAGE
= Messages
.CustomTraceDefinition_messageTag
;
49 public static final String TAG_OTHER
= Messages
.CustomTraceDefinition_otherTag
;
51 /** Category of this trace definition */
52 public String categoryName
;
54 /** Name of this trace definition */
55 public String definitionName
;
57 /** List of output columns */
58 public List
<OutputColumn
> outputs
;
60 /** Timestamp format */
61 public String timeStampOutputFormat
;
64 * Definition of an output column
66 public static class OutputColumn
{
68 /** Name of this column */
72 * Default constructor (empty)
74 public OutputColumn() {}
79 * @param name Name of this output column
81 public OutputColumn(String name
) {
86 public String
toString() {
92 * Format a timestamp in this trace's current time stamp format.
95 * The timestamp to format
96 * @return The same timestamp as a formatted string
98 public String
formatTimeStamp(TmfTimestamp timestamp
) {
99 SimpleDateFormat simpleDateFormat
= new SimpleDateFormat(timeStampOutputFormat
);
100 return simpleDateFormat
.format(timestamp
.getValue());
104 * Save this custom trace in the default path.
106 public abstract void save();
109 * Save this custom trace in the supplied path.
112 * The path to save to
114 public abstract void save(String path
);
117 * Creates a new empty entity resolver
119 * @return a new entity resolver
121 protected static EntityResolver
createEmptyEntityResolver() {
122 return new EntityResolver() {
124 public InputSource
resolveEntity(String publicId
, String systemId
) {
125 String empty
= ""; //$NON-NLS-1$
126 ByteArrayInputStream bais
= new ByteArrayInputStream(empty
.getBytes());
127 return new InputSource(bais
);
133 * Creates an error handler for parse exceptions
135 * @return a new error handler
137 protected static ErrorHandler
createErrorHandler() {
138 return new ErrorHandler() {
140 public void error(SAXParseException saxparseexception
) throws SAXException
{
144 public void warning(SAXParseException saxparseexception
) throws SAXException
{
148 public void fatalError(SAXParseException saxparseexception
) throws SAXException
{
149 throw saxparseexception
;