List of usage examples for org.apache.commons.vfs FileListener FileListener
FileListener
From source file:com.collabnet.ccf.core.transformer.XsltProcessor.java
/** * Hook to perform any validation of the component properties required by * the implementation. Default behaviour should be a no-op. */// w w w . j a v a2 s. c om @SuppressWarnings("unchecked") public void validate(List exceptions) { // we have to make this map thread safe because it will be // updated asynchronously xsltFileNameTransformerMap = Collections.synchronizedMap(new HashMap<String, Transformer>()); if (isListenForFileUpdates()) { try { fsManager = VFS.getManager(); } catch (FileSystemException e) { exceptions .add(new ValidationException("could not initialize file manager: " + e.getMessage(), this)); return; } fileMonitor = new DefaultFileMonitor(new FileListener() { public void fileChanged(org.apache.commons.vfs.FileChangeEvent arg0) throws Exception { xsltFileNameTransformerMap.clear(); } public void fileCreated(FileChangeEvent arg0) throws Exception { xsltFileNameTransformerMap.clear(); } public void fileDeleted(FileChangeEvent arg0) throws Exception { xsltFileNameTransformerMap.clear(); } }); } String xsltDir = this.getXsltDir(); String xsltFile = this.getXsltFile(); if (!StringUtils.isEmpty(xsltDir)) { File xsltDirFile = new File(xsltDir); if (xsltDirFile.exists() && xsltDirFile.isDirectory()) { log.debug("xsltDir property " + xsltDir + " is a valid directory"); if (listenForFileUpdates) { FileObject fileObject = null; try { fileObject = fsManager.resolveFile(xsltDirFile.getAbsolutePath()); } catch (FileSystemException e) { exceptions.add(new ValidationException( "xsltDir property " + xsltDir + " is not a valid directory: " + e.getMessage(), this)); return; } fileMonitor.setRecursive(true); fileMonitor.addFile(fileObject); fileMonitor.start(); } } else { exceptions.add(new ValidationException( "xsltDir property " + xsltDir + " is not a valid directory...!", this)); return; } } else if (!StringUtils.isEmpty(xsltFile)) { File xsltFileFile = new File(xsltFile); if (xsltFileFile.exists() && xsltFileFile.isFile()) { log.debug("xsltFile property " + xsltFile + " is a valid file"); if (listenForFileUpdates) { FileObject fileObject = null; try { fileObject = fsManager.resolveFile(xsltFileFile.getAbsolutePath()); } catch (FileSystemException e) { exceptions.add(new ValidationException( "xsltFile property " + xsltFile + " is not a valid file...:" + e.getMessage(), this)); return; } fileMonitor.addFile(fileObject); fileMonitor.start(); } } else { exceptions.add(new ValidationException("xsltFile property " + xsltFile + " is not a valid file...!", this)); return; } } }
From source file:com.collabnet.ccf.core.transformer.DynamicXsltProcessor.java
/** * Hook to perform any validation of the component properties required by * the implementation. Default behaviour should be a no-op. *///w ww.j a v a2 s .c o m @SuppressWarnings("unchecked") public void validate(List exceptions) { // we have to make this map thread safe because it will be // updated asynchronously xsltFileNameTransformerMap = Collections.synchronizedMap(new HashMap<String, List<Transformer>>()); if (isListenForFileUpdates()) { try { fsManager = VFS.getManager(); } catch (FileSystemException e) { exceptions .add(new ValidationException("could not initialize file manager: " + e.getMessage(), this)); return; } fileMonitor = new DefaultFileMonitor(new FileListener() { public void fileChanged(org.apache.commons.vfs.FileChangeEvent arg0) throws Exception { xsltFileNameTransformerMap.clear(); } public void fileCreated(FileChangeEvent arg0) throws Exception { xsltFileNameTransformerMap.clear(); } public void fileDeleted(FileChangeEvent arg0) throws Exception { xsltFileNameTransformerMap.clear(); } }); } String xsltDir = this.getXsltDir(); String xsltFile = this.getXsltFile(); if (!StringUtils.isEmpty(xsltDir)) { File xsltDirFile = new File(xsltDir); if (xsltDirFile.exists() && xsltDirFile.isDirectory()) { log.debug("xsltDir property " + xsltDir + " is a valid directory"); if (listenForFileUpdates) { FileObject fileObject = null; try { fileObject = fsManager.resolveFile(xsltDirFile.getAbsolutePath()); } catch (FileSystemException e) { exceptions.add(new ValidationException( "xsltDir property " + xsltDir + " is not a valid directory: " + e.getMessage(), this)); return; } fileMonitor.setRecursive(true); fileMonitor.addFile(fileObject); fileMonitor.start(); } if (scriptProcessors.isEmpty()) { log.warn("No scripts supplied, so dynamic XSLT processor will not change data at all"); } } else { exceptions.add(new ValidationException( "xsltDir property " + xsltDir + " is not a valid directory...!", this)); return; } } else if (!StringUtils.isEmpty(xsltFile)) { File xsltFileFile = new File(xsltFile); if (xsltFileFile.exists() && xsltFileFile.isFile()) { log.debug("xsltFile property " + xsltFile + " is a valid file"); if (listenForFileUpdates) { FileObject fileObject = null; try { fileObject = fsManager.resolveFile(xsltFileFile.getAbsolutePath()); } catch (FileSystemException e) { exceptions.add(new ValidationException( "xsltFile property " + xsltFile + " is not a valid file...:" + e.getMessage(), this)); return; } fileMonitor.addFile(fileObject); fileMonitor.start(); } } else { exceptions.add(new ValidationException("xsltFile property " + xsltFile + " is not a valid file...!", this)); return; } } factory = TransformerFactory.newInstance(); if (isOnlyAllowWhiteListedJavaFunctionCalls()) { try { secureFactory = TransformerFactory.newInstance(); secureFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); secureFactory.setErrorListener(new XsltValidationErrorListener()); } catch (TransformerConfigurationException e) { exceptions.add(new ValidationException( "Setting secure processing feature on XSLT processor failed, bailing out since this feature is required by onlyAllowWhiteListedJavaFunctions property", this)); return; } } }
From source file:org.ambud.marauder.source.ids.IDSFileSource.java
@Override public void configure(Context context) { super.configure(context); context = new Context(context.getSubProperties(getPrefix())); this.watchDirectory = new File(context.getString(PROP_DIRECTORY, getDefaultDirectory())); this.logBaseName = context.getString(PROP_BASE_NAME, getDefaultFilename()); this.isSequential = context.getBoolean(PROP_IS_SEQUENTIAL, true); logger.info("Snort Source will spool/watch - " + this.watchDirectory.getAbsolutePath() + " for Snort log files whose names start with:" + this.logBaseName); FileSystemManager fsMgr = null;//w w w . j av a 2s . c o m try { fsMgr = VFS.getManager(); } catch (FileSystemException e) { Throwables.propagate(e); } try { this.watchObject = fsMgr.resolveFile(watchDirectory.getAbsolutePath()); } catch (FileSystemException e) { Throwables.propagate(e); } this.monitor = new DefaultFileMonitor(new FileListener() { @Override public void fileChanged(FileChangeEvent arg0) throws Exception { // ignore these } @Override public void fileCreated(FileChangeEvent fileEvent) throws Exception { if (acceptFile(fileEvent.getFile().getName().getBaseName())) { logger.info("Acknowledged new file:" + fileEvent.getFile().getName().getPath()); builderFileReader(fileEvent.getFile(), true); } } @Override public void fileDeleted(FileChangeEvent arg0) throws Exception { // acknowledge these } }); int bufferSize = context.getInteger(PROP_BUFFER_SIZE, 500); this.outputQueue = new ArrayBlockingQueue<MarauderIDSEvent>(bufferSize); }
From source file:org.ambud.marauder.source.readers.MarauderPollingTextFileReader.java
public MarauderPollingTextFileReader(File file, int pollingInterval) throws FileNotFoundException, FileSystemException { super(file);//from www . j ava 2 s . c o m FileSystemManager fsMgr = VFS.getManager(); FileObject fo = fsMgr.resolveFile(getFile().getAbsolutePath()); this.monitor = new DefaultFileMonitor(new FileListener() { @Override public void fileDeleted(FileChangeEvent arg0) throws Exception { // can't do anything since the file is closed closeReader(); } @Override public void fileCreated(FileChangeEvent arg0) throws Exception { // shouldn't happen if file already exist } @Override public void fileChanged(FileChangeEvent arg0) throws Exception { readFile(); } }); monitor.addFile(fo); monitor.setRecursive(false); monitor.setDelay(pollingInterval); }
From source file:org.ambud.marauder.source.snort.SnortSourceBack.java
@Override public void configure(Context context) { super.configure(context); context = new Context(context.getSubProperties(PROP_PREFIX)); this.watchDirectory = new File(context.getString(PROP_DIRECTORY, PROP_DEFAULT_DIR)); this.logBaseName = context.getString(PROP_BASE_NAME, PROP_DEFAULT_FILENAME); this.isSequential = context.getBoolean(PROP_IS_SEQUENTIAL, true); logger.info("Snort Source will spool/watch - " + this.watchDirectory.getAbsolutePath() + " for Snort log files whose names start with:" + this.logBaseName); FileSystemManager fsMgr = null;//from w w w . j av a 2s . co m try { fsMgr = VFS.getManager(); } catch (FileSystemException e) { Throwables.propagate(e); } try { this.watchObject = fsMgr.resolveFile(watchDirectory.getAbsolutePath()); } catch (FileSystemException e) { Throwables.propagate(e); } this.monitor = new DefaultFileMonitor(new FileListener() { @Override public void fileChanged(FileChangeEvent arg0) throws Exception { // ignore these } @Override public void fileCreated(FileChangeEvent fileEvent) throws Exception { if (acceptFile(fileEvent.getFile().getName().getBaseName())) { logger.info("Acknowledged new file:" + fileEvent.getFile().getName().getPath()); processFile(fileEvent.getFile(), true); } } @Override public void fileDeleted(FileChangeEvent arg0) throws Exception { // acknowledge these } }); int bufferSize = context.getInteger("buffer.size", 500); this.outputQueue = new ArrayBlockingQueue<MarauderIDSEvent>(bufferSize); }