use of com.cosylab.logging.engine.FiltersVector in project ACS by ACS-Community.
the class FileHelper method setupFilters.
/**
* Create the filters for loading logs;:
* <UL>
* <LI>time range
* <LI>min and max log levels
* </UL>
* @return
*/
private FiltersVector setupFilters() throws ZoomException {
FiltersVector filters = new FiltersVector();
Filter dateFilter = null;
Filter levelFilter = null;
try {
dateFilter = new MinMaxFilter(LogField.TIMESTAMP, false, startTime, endTime, false);
levelFilter = new MinMaxFilter(LogField.ENTRYTYPE, false, minLogLevel, maxLogLevel, false);
} catch (InvalidFilterConstraintException e) {
throw new ZoomException("Error setting the filters", e);
}
filters.addFilter(dateFilter, true);
filters.addFilter(levelFilter, true);
return filters;
}
use of com.cosylab.logging.engine.FiltersVector in project ACS by ACS-Community.
the class FileHelper method loadLogs.
/**
* Load the logs for the file.
* <P>
* This method return errors in two ways:
* <UL>
* <LI>with an exception when the error arise while setting up the file and the filters for loading
* while reading the file
* <LI>returning <code>false</code> in case of errors parsing logs read from file
* </ul>
* <P>
* The error listener passed as parameter can be <code>null</code>.
* In fact the error listener gets the strings of the logs that returned an error
* while parsing. If the caller is not interested in those strings but only to
* know if there were parsing errors then it will be enough for the caller to check
* the value of the returned boolean.
*
* @param logListener The listener of the logs read from the file
* @param ioListener The listener for the progress of loading
* @param errorListener The listener of errors parsing logs (can'be <code>null</code>)
* @return <code>false</code> in case of errors loading logs;
* <code>true</code> otherwise
*
* @throws ZoomException In case of errors creating filters
* @throws FileNotFoundException If the file was not found
*/
public boolean loadLogs(ACSRemoteLogListener logListener, IOPorgressListener ioListener, ACSRemoteErrorListener errorListener) throws ZoomException, FileNotFoundException {
FiltersVector filters = setupFilters();
ioHelper.setFilters(filters);
errorParsingLogs = false;
externalErrorListener = errorListener;
FileReader fileReader = new FileReader(inputFile);
BufferedReader reader = new BufferedReader(fileReader);
try {
ioHelper.loadLogs(reader, logListener, null, this, ioListener);
} catch (Throwable t) {
throw new ZoomException("Error loading logs from file", t);
}
return !errorParsingLogs;
}
use of com.cosylab.logging.engine.FiltersVector in project ACS by ACS-Community.
the class FilterChooserDialog method loadFilters.
/**
* Load filters from a XML file The user chooses if the loaded filters
* substitutes the existing ones or merges with them
*/
private void loadFilters() {
boolean eraseOldFilters;
// Check if already exists filters
if (filterList.getItemsSize() > 0) {
int ret = JOptionPane.showConfirmDialog(this, "Do you want do discard existing filters?", "Merge filters?", JOptionPane.YES_NO_CANCEL_OPTION);
if (ret == JOptionPane.CANCEL_OPTION) {
return;
}
eraseOldFilters = (ret == JOptionPane.YES_OPTION);
} else {
// We have no filters so.. nothing to
eraseOldFilters = false;
// delete ;-)
}
// Show the dialog to choose the file to load
JFileChooser fileChooserDlg = new JFileChooser();
fileChooserDlg.setMultiSelectionEnabled(false);
fileChooserDlg.setDialogTitle("Load filters");
XmlFileFilter fileFilter = new XmlFileFilter();
fileChooserDlg.setFileFilter(fileFilter);
if (fileChooserDlg.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
// Load filters from file
File fileToLoad = fileChooserDlg.getSelectedFile();
if (fileToLoad != null) {
FiltersVector filters = new FiltersVector();
try {
filters.loadFilters(fileToLoad, eraseOldFilters, null);
} catch (Throwable t) {
JOptionPane.showMessageDialog(this, "Error: " + t.getMessage(), "Error loading filters", JOptionPane.ERROR_MESSAGE);
}
setupFields(filters, !eraseOldFilters);
modified = true;
filterFileName = fileToLoad.getAbsolutePath();
}
}
}
use of com.cosylab.logging.engine.FiltersVector in project ACS by ACS-Community.
the class FilterChooserDialog method saveFilters.
/**
* Save the filters to a XML files with a given name It create the File
* object then call overloaded method
*
* @param fileName The name of the xml file
*/
private void saveFilters(String fileName) {
if (fileName == null || fileName.length() == 0) {
throw new IllegalArgumentException("Inavlid file name: " + fileName);
}
// Check if the name terminate with xml
if (!fileName.toUpperCase().endsWith(".XML")) {
fileName = fileName + ".xml";
}
List<CheckListTableEntry> entries = filterList.getEntries();
FiltersVector filters = new FiltersVector();
for (CheckListTableEntry entry : entries) {
filters.addFilter((Filter) entry.getItem(), entry.isActive());
}
File f = new File(fileName);
try {
filters.saveFilters(f);
filterFileName = f.getAbsolutePath();
System.out.println("Saved " + filterFileName);
} catch (IOException e) {
System.err.println("Error opening " + fileName);
}
}
use of com.cosylab.logging.engine.FiltersVector in project ACS by ACS-Community.
the class FilterChooserDialog method applyFilters.
/**
* Apply the filters in the table of logs
*
*/
private void applyFilters() {
FiltersVector newFilters = new FiltersVector();
for (CheckListTableEntry entry : filterList.getEntries()) {
newFilters.addFilter((Filter) entry.getItem(), entry.isActive());
}
filterable.setFilters(newFilters, false);
}
Aggregations