use of alma.acs.logging.tools.CSVConverter in project ACS by ACS-Community.
the class ConvertersTest method testSetSeparator.
/**
* Test the setting of the separator
*
* @throws Exception
*/
public void testSetSeparator() throws Exception {
CSVConverter converter = new CSVConverter();
assertNotNull(converter);
converter.setSeparator('!');
String ret = converter.convert(logToConvert);
converter.setSeparator('#');
String ret2 = converter.convert(logToConvert);
// ret and ret2 must be equals aparto of the separators
assertEquals(ret.replaceAll("!", "#"), ret2);
}
use of alma.acs.logging.tools.CSVConverter in project ACS by ACS-Community.
the class ConvertersTest method testSetWrongColumns.
/**
* Test the setting of a wrong columns string
* i.e. a string that does contain at least one invalid
* {@link LogField} ID.
*
* @throws Exception
*/
public void testSetWrongColumns() throws Exception {
String cols = "0123ABGXA4";
CSVConverter converter = new CSVConverter();
boolean exceptionOccurred = false;
try {
converter.setCols(cols);
} catch (IllegalArgumentException ie) {
exceptionOccurred = true;
}
assertTrue(exceptionOccurred);
}
use of alma.acs.logging.tools.CSVConverter in project ACS by ACS-Community.
the class TablePopupMenu method actionPerformed.
/**
* Handle the events from the menu
*
* @param e The event
*/
public void actionPerformed(ActionEvent e) {
if (textToCopy == null) {
return;
}
if (e.getSource() == copyClipXml) {
copyToClipboard(new XMLConverter());
} else if (e.getSource() == copyClipTxt) {
copyToClipboard(new TextConverter(null));
} else if (e.getSource() == copyClipTwikiTable) {
copyToClipboard(new TwikiTableConverter(null));
} else if (e.getSource() == copyClipCSV) {
copyToClipboard(new CSVConverter());
} else if (e.getSource() == addUserInfo) {
// Show the dialog
UserInfoDlg dlg = new UserInfoDlg();
if (dlg.okPressed()) {
String name = dlg.getInfoName();
String value = dlg.getInfo();
// Replace some chars potentially dangerous for xml
value = value.replaceAll("&", "&");
value = value.replaceAll("'", "'");
value = value.replaceAll("`", "'");
value = value.replaceAll("\"", """);
value = value.replaceAll("<", "<");
value = value.replaceAll(">", ">");
name = name.replaceAll("&", "&");
name = name.replaceAll("'", "'");
name = name.replaceAll("`", "'");
name = name.replaceAll("\"", """);
name = name.replaceAll("<", "<");
name = name.replaceAll(">", ">");
ILogEntry logEntry = model.getVisibleLogEntry(table.convertRowIndexToModel(row));
logEntry.addData(name, value);
model.replaceLog(table.convertRowIndexToModel(row), logEntry);
LogTableDataModel tableModel = (LogTableDataModel) table.getModel();
tableModel.fireTableRowsUpdated(table.convertRowIndexToModel(row), table.convertRowIndexToModel(row));
table.setRowSelectionInterval(row, row);
loggingClient.setLogDetailContent(logEntry);
}
} else if (e.getSource() == saveSelectedAsCSV) {
saveSelectedLogs(new CSVConverter(), saveCsvIcon, "txt");
} else if (e.getSource() == saveSelectedAsText) {
saveSelectedLogs(new TextConverter(null), saveTextIcon, "txt");
} else if (e.getSource() == saveSelectedAsTwiki) {
saveSelectedLogs(new TwikiTableConverter(null), saveTwikiTableIcon, "txt");
} else if (e.getSource() == saveSelectedAsXML) {
saveSelectedLogs(new XMLConverter(), saveXmlIcon, "xml");
} else if (e.getSource() == showErrorStack) {
if (stackId != null && !stackId.isEmpty()) {
loggingClient.addErrorTab(stackId);
}
} else if (e.getSource() == zoomOverSelected) {
Thread t = new Thread(new Runnable() {
public void run() {
table.zoom();
}
});
t.setDaemon(true);
t.setName("TablePopupMenu.actionPerformed.Zoom");
t.start();
} else if (e.getSource() == showsOnlyMI || e.getSource() == filtersOutMI) {
filters(e.getSource() == filtersOutMI);
} else {
System.err.println("Unhandled event " + e);
}
}
use of alma.acs.logging.tools.CSVConverter in project ACS by ACS-Community.
the class ConvertersTest method testGetHeader.
/**
* Check the generation of the header for the different
* log converters.
* @throws Exception
*/
public void testGetHeader() throws Exception {
String cols = "";
cols += LogField.TIMESTAMP.id;
cols += LogField.SOURCEOBJECT.id;
cols += LogField.LOGMESSAGE.id;
cols += LogField.ENTRYTYPE.id;
// CSV
CSVConverter csvConverter = new CSVConverter(cols);
assertNotNull(csvConverter);
String csvHdr = csvConverter.getHeader();
assertNotNull(csvHdr);
String expectedCsvHdr = "\"" + LogField.TIMESTAMP.name;
expectedCsvHdr += "\",\"" + LogField.SOURCEOBJECT.name;
expectedCsvHdr += "\",\"" + LogField.LOGMESSAGE.name;
expectedCsvHdr += "\",\"" + LogField.ENTRYTYPE.name + "\"\n";
assertEquals(expectedCsvHdr, csvHdr);
// XML
XMLConverter xmlConverter = new XMLConverter();
assertNotNull(xmlConverter);
String xmlHdr = xmlConverter.getHeader();
assertNotNull(xmlHdr);
assertTrue(xmlHdr.isEmpty());
// Text
TextConverter txtConverter = new TextConverter(cols);
assertNotNull(txtConverter);
String txtHdr = txtConverter.getHeader();
assertNotNull(txtHdr);
String expectedTxtHdr = LogField.TIMESTAMP.name;
expectedTxtHdr += " " + LogField.SOURCEOBJECT.name;
expectedTxtHdr += " " + LogField.LOGMESSAGE.name;
expectedTxtHdr += " " + LogField.ENTRYTYPE.name + "\n";
assertEquals(expectedTxtHdr, txtHdr);
// Twiki table
TwikiTableConverter ttConverter = new TwikiTableConverter(cols);
assertNotNull(ttConverter);
String ttHdr = ttConverter.getHeader();
assertNotNull(ttHdr);
String expectedTtHdr = "| *" + LogField.TIMESTAMP.name;
expectedTtHdr += "* | *" + LogField.SOURCEOBJECT.name;
expectedTtHdr += "* | *" + LogField.LOGMESSAGE.name;
expectedTtHdr += "* | *" + LogField.ENTRYTYPE.name + "* |\n";
assertEquals(expectedTtHdr, ttHdr);
}
use of alma.acs.logging.tools.CSVConverter in project ACS by ACS-Community.
the class ConvertersTest method testCVSSomeFields.
/**
* Test the CSV conversion in case a subset of fields is chosen
* @throws Exception
*/
public void testCVSSomeFields() throws Exception {
String cols = "";
cols += LogField.TIMESTAMP.id;
cols += LogField.LOGMESSAGE.id;
cols += LogField.AUDIENCE.id;
cols += LogField.TIMESTAMP.id;
assertNotNull(cols);
CSVConverter converter = new CSVConverter(cols, '$', false);
String str = converter.convert(logToConvert);
String[] parts = str.split("\\$");
assertNotNull(parts);
assertEquals(cols.length(), parts.length);
assertEquals(timeStamp.replaceAll("\"", ""), parts[0]);
assertEquals(message, parts[1]);
assertEquals(audience.replaceAll("\"", ""), parts[2]);
assertEquals(timeStamp.replaceAll("\"", ""), parts[3].subSequence(0, parts[3].length() - 1));
}
Aggregations