use of alma.acs.logging.tools.XMLConverter 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.XMLConverter 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.XMLConverter in project ACS by ACS-Community.
the class ConvertersTest method testXML.
/**
* Test the XML conversion
*
* @throws Exception
*/
public void testXML() throws Exception {
XMLConverter converter = new XMLConverter();
assertNotNull(converter);
String ret = converter.convert(logToConvert);
assertNotNull(ret);
ParserTypes type = ParserTypes.VTD;
ACSLogParser parser = ACSLogParserFactory.getParser(type);
ILogEntry log = parser.parse(ret);
assertNotNull(log);
for (LogField f : LogField.values()) {
Object original = logToConvert.getField(f);
Object converted = log.getField(f);
assertEquals(original, converted);
}
Vector<AdditionalData> originalData = logToConvert.getAdditionalData();
assertNotNull(originalData);
Vector<AdditionalData> convertedData = log.getAdditionalData();
assertNotNull(convertedData);
assertEquals(originalData.size(), convertedData.size());
for (AdditionalData ad : originalData) {
boolean found = false;
String name = ad.name;
String val = ad.value;
for (AdditionalData adConverted : convertedData) {
if (name.equals(adConverted.name)) {
found = true;
assertEquals(val, adConverted.value);
break;
}
}
assertTrue("Additional data not found", found);
}
}
Aggregations