Search in sources :

Example 1 with CSVConverter

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);
}
Also used : CSVConverter(alma.acs.logging.tools.CSVConverter)

Example 2 with CSVConverter

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);
}
Also used : CSVConverter(alma.acs.logging.tools.CSVConverter)

Example 3 with CSVConverter

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("<", "&lt;");
            value = value.replaceAll(">", "&gt;");
            name = name.replaceAll("&", "&amp;");
            name = name.replaceAll("'", "&apos;");
            name = name.replaceAll("`", "&apos;");
            name = name.replaceAll("\"", "&quot;");
            name = name.replaceAll("<", "&lt;");
            name = name.replaceAll(">", "&gt;");
            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);
    }
}
Also used : TwikiTableConverter(alma.acs.logging.tools.TwikiTableConverter) CSVConverter(alma.acs.logging.tools.CSVConverter) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) XMLConverter(alma.acs.logging.tools.XMLConverter) UserInfoDlg(com.cosylab.logging.settings.UserInfoDlg) TextConverter(alma.acs.logging.tools.TextConverter)

Example 4 with CSVConverter

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);
}
Also used : TwikiTableConverter(alma.acs.logging.tools.TwikiTableConverter) CSVConverter(alma.acs.logging.tools.CSVConverter) XMLConverter(alma.acs.logging.tools.XMLConverter) TextConverter(alma.acs.logging.tools.TextConverter)

Example 5 with CSVConverter

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));
}
Also used : CSVConverter(alma.acs.logging.tools.CSVConverter)

Aggregations

CSVConverter (alma.acs.logging.tools.CSVConverter)6 TextConverter (alma.acs.logging.tools.TextConverter)2 TwikiTableConverter (alma.acs.logging.tools.TwikiTableConverter)2 XMLConverter (alma.acs.logging.tools.XMLConverter)2 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)1 UserInfoDlg (com.cosylab.logging.settings.UserInfoDlg)1