use of alma.acs.logging.tools.TextConverter in project ACS by ACS-Community.
the class ConvertersTest method testTextConverter.
/**
* Test the text converter.
* <P>
* The test is done on a subset of the columns: it is enough
* because the conversion is delegated to the already tested
* {@link CSVConverter}
*
* @throws Exception
*/
public void testTextConverter() throws Exception {
String cols = "";
cols += LogField.AUDIENCE.id;
cols += LogField.ARRAY.id;
cols += LogField.SOURCEOBJECT.id;
cols += LogField.ANTENNA.id;
cols += LogField.LINE.id;
TextConverter converter = new TextConverter(cols);
assertNotNull(converter);
String txt = converter.convert(logToConvert);
String expected = audience.replaceAll("\"", "");
expected += " " + array.replaceAll("\"", "");
expected += " " + sourceObject.replaceAll("\"", "");
expected += " " + antenna.replaceAll("\"", "");
expected += " " + line.replaceAll("\"", "") + "\n";
assertEquals(expected, txt);
}
use of alma.acs.logging.tools.TextConverter 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.TextConverter in project ACS by ACS-Community.
the class ConvertersTest method testColumnsVector.
/**
* Test the setting of the columns with a collection of {@link LogField}
*
* @throws Exception
*/
public void testColumnsVector() throws Exception {
Vector<LogField> cols = new Vector<LogField>();
assertNotNull(cols);
cols.add(LogField.URI);
cols.add(LogField.CONTEXT);
TextConverter converter = new TextConverter(null);
assertNotNull(converter);
converter.setCols(cols, false);
String ret = converter.convert(logToConvert);
assertNotNull(ret);
String expected = uri.replaceAll("\"", "") + " " + context.replaceAll("\"", "") + "\n";
assertEquals(expected, ret);
}
use of alma.acs.logging.tools.TextConverter 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);
}
Aggregations