From: Santi B. <san...@us...> - 2007-12-14 00:51:12
|
Update of /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv23586/modules/scanner/src/com/babeldoc/scanner/worker Modified Files: VFSScanner.java Log Message: Minor update Index: VFSScanner.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker/VFSScanner.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** VFSScanner.java 13 Dec 2007 17:21:43 -0000 1.2 --- VFSScanner.java 14 Dec 2007 00:51:12 -0000 1.3 *************** *** 109,115 **** public static final String MINIMUM_FILE_AGE = "minimumFileAge"; public static final String SCAN_NEW = "scanNew"; ! ! public static final String SCAN_NEW_DELETE ="delete"; ! public static final String SCAN_NEW_FOLDER ="doneFolder"; private LogService log = LogService.getInstance(this.getClass().getName()); --- 109,115 ---- public static final String MINIMUM_FILE_AGE = "minimumFileAge"; public static final String SCAN_NEW = "scanNew"; ! ! public static final String SCAN_NEW_DELETE = "delete"; ! public static final String SCAN_NEW_FOLDER = "doneFolder"; private LogService log = LogService.getInstance(this.getClass().getName()); *************** *** 141,145 **** * against incomplete reads when the writer of the file is "slow". */ ! private int minimumFileAge = 0; /** --- 141,145 ---- * against incomplete reads when the writer of the file is "slow". */ ! private long minimumFileAge = 0; /** *************** *** 174,178 **** setInDirectory(this.getInfo().getStrValue(IN_DIR)); ! if (!getInDirectory().exists() || !getInDirectory().isReadable() || getInDirectory().getType() != FileType.FOLDER) { throw new ScannerConfigurationException(I18n.get( "scanner.VFSScanner.error.notDir", IN_DIR, --- 174,179 ---- setInDirectory(this.getInfo().getStrValue(IN_DIR)); ! if (!getInDirectory().exists() || !getInDirectory().isReadable() ! || getInDirectory().getType() != FileType.FOLDER) { throw new ScannerConfigurationException(I18n.get( "scanner.VFSScanner.error.notDir", IN_DIR, *************** *** 190,194 **** // Check of the donedirectory actually is a directory ! if ( doneDirectory.getType() != FileType.FOLDER) { throw new ScannerConfigurationException(I18n.get( "scanner.VFSScanner.error.notDir", DONE_DIR, --- 191,195 ---- // Check of the donedirectory actually is a directory ! if (doneDirectory.getType() != FileType.FOLDER) { throw new ScannerConfigurationException(I18n.get( "scanner.VFSScanner.error.notDir", DONE_DIR, *************** *** 205,210 **** INCLUDE_SUB_DIRS))); ! setMinimumFileAge(this.getInfo().getIntValue(MINIMUM_FILE_AGE)); ! if (getMinimumFileAge() > 0) { LogService.getInstance().logInfo( --- 206,212 ---- INCLUDE_SUB_DIRS))); ! ! setMinimumFileAge(this.getInfo().getIntValue(MINIMUM_FILE_AGE)); ! if (getMinimumFileAge() > 0) { LogService.getInstance().logInfo( *************** *** 240,248 **** protected void moveFile(FileObject file) throws Exception { try { ! ! if (getDoneDirectory() != null ){ ! String path = file.getName().getPath(); ! FileObject outDir = fsManager.resolveFile(getDoneDirectory()+ getInDirectory().getName().getPathDecoded().toString()); // create out dir if not exist --- 242,252 ---- protected void moveFile(FileObject file) throws Exception { try { ! ! if (getDoneDirectory() != null) { ! String path = file.getName().getPath(); ! FileObject outDir = fsManager.resolveFile(getDoneDirectory() ! + getInDirectory().getName().getPathDecoded() ! .toString()); // create out dir if not exist *************** *** 250,270 **** outDir.createFolder(); } ! // create file with the same name (path) in out dir ! FileObject outfile = fsManager.resolveFile(outDir.getName().getURI() + file.getName().getBaseName()); ! // delete file it is already exists if (outfile.exists()) { outfile.delete(); } ! ! //copy ! outfile.getContent().getFile().copyFrom(file,null); ! // rename file ! /*if(!file.canRenameTo(outfile)) ! throw new ScannerException(I18n.get("scanner.VFSScanner.error.finishing")); ! */ ! } } catch (Exception e) { --- 254,277 ---- outDir.createFolder(); } ! // create file with the same name (path) in out dir ! FileObject outfile = fsManager.resolveFile(outDir.getName() ! .getURI() ! + file.getName().getBaseName()); ! // delete file it is already exists if (outfile.exists()) { outfile.delete(); } ! ! // copy ! outfile.getContent().getFile().copyFrom(file, null); ! // rename file ! /* ! * if(!file.canRenameTo(outfile)) throw new ! * ScannerException(I18n.get("scanner.VFSScanner.error.finishing")); ! * */ ! } } catch (Exception e) { *************** *** 272,293 **** .get("scanner.VFSScanner.error.finishing"), e); } ! ! if ( this.getInfo().getStrValue(SCAN_NEW) == VFSScanner.SCAN_NEW_DELETE ){ ! if(!file.delete()){ throw new ScannerException(I18n .get("scanner.VFSScanner.error.finishing"), null); ! //Exceptio no es podra saber si es nou pq no ha borrat!!! } return; } ! ! if ( this.getInfo().getStrValue(SCAN_NEW) == VFSScanner.SCAN_NEW_FOLDER ){ if (getDoneDirectory() == null) throw new ScannerException(I18n .get("scanner.VFSScanner.error.finishing"), null); ! // Exceptio no es podra saber si es nou pq no a mogut!!! return; ! ! } } --- 279,300 ---- .get("scanner.VFSScanner.error.finishing"), e); } ! ! if (this.getInfo().getStrValue(SCAN_NEW) == VFSScanner.SCAN_NEW_DELETE) { ! if (!file.delete()) { throw new ScannerException(I18n .get("scanner.VFSScanner.error.finishing"), null); ! // Exceptio no es podra saber si es nou pq no ha borrat!!! } return; } ! ! if (this.getInfo().getStrValue(SCAN_NEW) == VFSScanner.SCAN_NEW_FOLDER) { if (getDoneDirectory() == null) throw new ScannerException(I18n .get("scanner.VFSScanner.error.finishing"), null); ! // Exceptio no es podra saber si es nou pq no a mogut!!! return; ! ! } } *************** *** 298,314 **** * @param dir * DOCUMENT ME! ! * @throws FileSystemException */ private void processVFS(FileObject dir) throws FileSystemException { // inner class that implements FileFilter interface org.apache.commons.vfs.FileFilter filter = new org.apache.commons.vfs.FileFilter() { ! public boolean accept(FileSelectInfo current) { try { ! if (current.getFile().getType() == FileType.FOLDER) { // if iclude subDirs if it is scpecified return isIncludeSubDirs(); } else { // if file fulfils configured criteria ! return acceptFile(current); } } catch (FileSystemException e) { --- 305,322 ---- * @param dir * DOCUMENT ME! ! * @throws FileSystemException */ private void processVFS(FileObject dir) throws FileSystemException { // inner class that implements FileFilter interface org.apache.commons.vfs.FileFilter filter = new org.apache.commons.vfs.FileFilter() { ! public boolean accept(FileSelectInfo currentInfo) { ! FileObject currentFile = currentInfo.getFile(); try { ! if (currentFile.getType() == FileType.FOLDER) { // if iclude subDirs if it is scpecified return isIncludeSubDirs(); } else { // if file fulfils configured criteria ! return acceptFile(currentFile); } } catch (FileSystemException e) { *************** *** 330,334 **** try { processFile(files[i]); ! moveFile(files[i]); } catch (Exception ex) { log.logError( --- 338,342 ---- try { processFile(files[i]); ! moveFile(files[i]); } catch (Exception ex) { log.logError( *************** *** 353,362 **** try { ! FileContent fileContent= file.getContent(); ! //getting message from file byte[] data = new byte[1024]; ! long modified = new Date(fileContent.getLastModifiedTime()).getTime(); fis = fileContent.getInputStream(); ! baos = new ByteArrayOutputStream((int)fileContent.getSize()); int charsRead = 0; --- 361,371 ---- try { ! FileContent fileContent = file.getContent(); ! // getting message from file byte[] data = new byte[1024]; ! long modified = new Date(fileContent.getLastModifiedTime()) ! .getTime(); fis = fileContent.getInputStream(); ! baos = new ByteArrayOutputStream((int) fileContent.getSize()); int charsRead = 0; *************** *** 366,383 **** } ! this.enqueue( ! baos.toByteArray(), ! new NameValuePair[] { ! new NameValuePair(SCAN_MIMETYPE_KEY, ! PipelineDocument.getMimeTypeForFile(file.getName().getBaseName())), new NameValuePair(SCAN_DATE_KEY, Long.toString(modified)), new NameValuePair(SCAN_PATH_KEY, file.getName().getPath()), ! new NameValuePair(FILE_NAME_KEY, file.getName().getBaseName()), ! new NameValuePair(DONE_DIR_KEY, getDoneDirectory())}); } finally { fis.close(); baos.close(); } ! } --- 375,391 ---- } ! this.enqueue(baos.toByteArray(), new NameValuePair[] { ! new NameValuePair(SCAN_MIMETYPE_KEY, PipelineDocument ! .getMimeTypeForFile(file.getName().getBaseName())), new NameValuePair(SCAN_DATE_KEY, Long.toString(modified)), new NameValuePair(SCAN_PATH_KEY, file.getName().getPath()), ! new NameValuePair(FILE_NAME_KEY, file.getName() ! .getBaseName()), ! new NameValuePair(DONE_DIR_KEY, getDoneDirectory()) }); } finally { fis.close(); baos.close(); } ! } *************** *** 390,407 **** * The file to be checked against configuration * @return true If the file should be processed at this time ! * @throws FileSystemException */ ! private boolean acceptFile(FileSelectInfo fileInfo) throws FileSystemException { ! //Afegir if ( this.getInfo().getStrValue(SCAN_NEW) == VFSScanner.SCAN_NEW_DELETE ){ i FOLDER ! // Check name filter first, and then age. ! if (acceptEntry(FILTER_FILENAME, fileInfo.getFile().getName().toString())) { ! if (getMinimumFileAge() <= fileInfo.getFile().getContent().getLastModifiedTime() - getFileAge(fileInfo.getFile())) { return true; } else { if (log.isDebugEnabled()) ! log.logDebug("Ignoring " + fileInfo.getFile().getName().getPathDecoded() + " (age " ! + getFileAge(fileInfo.getFile()) + " < " + getMinimumFileAge() ! + ")"); } // Potentially add additional checks here. --- 398,416 ---- * The file to be checked against configuration * @return true If the file should be processed at this time ! * @throws FileSystemException */ ! private boolean acceptFile(FileObject file) throws FileSystemException { ! // Afegir if ( this.getInfo().getStrValue(SCAN_NEW) == ! // VFSScanner.SCAN_NEW_DELETE ){ i FOLDER ! // Check name filter first, and then age. ! if (acceptEntry(FILTER_FILENAME, file.getName().toString())) { ! if (getMinimumFileAge() <= getFileAge(file)) { return true; } else { if (log.isDebugEnabled()) ! log.logDebug("Ignoring " + file.getName().getPathDecoded() ! + " (age " + getFileAge(file) + " < " ! + getMinimumFileAge() + ")"); } // Potentially add additional checks here. *************** *** 416,420 **** * The file to get the age of. * @return long The age of the file in ms. ! * @throws FileSystemException */ private long getFileAge(FileObject file) throws FileSystemException { --- 425,429 ---- * The file to get the age of. * @return long The age of the file in ms. ! * @throws FileSystemException */ private long getFileAge(FileObject file) throws FileSystemException { *************** *** 428,432 **** public void setInDirectory(String inDirectory) throws FileSystemException { ! this.inDirectory = fsManager.resolveFile(this.getInfo().getStrValue(IN_DIR)); } --- 437,442 ---- public void setInDirectory(String inDirectory) throws FileSystemException { ! this.inDirectory = fsManager.resolveFile(this.getInfo().getStrValue( ! IN_DIR)); } *************** *** 449,457 **** } ! public int getMinimumFileAge() { return minimumFileAge; } ! public void setMinimumFileAge(int minimumFileAge) { if (minimumFileAge < 0) minimumFileAge = 0; --- 459,467 ---- } ! public long getMinimumFileAge() { return minimumFileAge; } ! public void setMinimumFileAge(long minimumFileAge) { if (minimumFileAge < 0) minimumFileAge = 0; *************** *** 508,516 **** IConfigOptionType.INTEGER, null, false, I18n .get("scanner.VFSScannerInfo.option.minimumFileAge"))); ! ! String[] scanNewTypes = { VFSScanner.SCAN_NEW_DELETE, VFSScanner.SCAN_NEW_FOLDER }; ! options.add(new ConfigOption(VFSScanner.SCAN_NEW, ! new ValueListConfigOptionType(scanNewTypes), VFSScanner.SCAN_NEW_DELETE, ! false, I18n.get("scanner.VfsScannerInfo.option.scanNew"))); return options; --- 518,528 ---- IConfigOptionType.INTEGER, null, false, I18n .get("scanner.VFSScannerInfo.option.minimumFileAge"))); ! ! String[] scanNewTypes = { VFSScanner.SCAN_NEW_DELETE, ! VFSScanner.SCAN_NEW_FOLDER }; ! options.add(new ConfigOption(VFSScanner.SCAN_NEW, ! new ValueListConfigOptionType(scanNewTypes), ! VFSScanner.SCAN_NEW_DELETE, false, I18n ! .get("scanner.VfsScannerInfo.option.scanNew"))); return options; |