From: paspes <pa...@us...> - 2007-12-14 02:01:25
|
Update of /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15709/modules/scanner/src/com/babeldoc/scanner/worker Modified Files: VFSScanner.java Log Message: Pujat falta accept segons parametre scan Index: VFSScanner.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/scanner/src/com/babeldoc/scanner/worker/VFSScanner.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** VFSScanner.java 13 Dec 2007 00:02:02 -0000 1.1 --- VFSScanner.java 13 Dec 2007 17:21:43 -0000 1.2 *************** *** 66,74 **** package com.babeldoc.scanner.worker; import java.io.InputStream; - import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; import org.apache.commons.vfs.FileObject; import org.apache.commons.vfs.FileSelectInfo; --- 66,76 ---- package com.babeldoc.scanner.worker; + import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; + import java.util.Date; + import org.apache.commons.vfs.FileContent; import org.apache.commons.vfs.FileObject; import org.apache.commons.vfs.FileSelectInfo; *************** *** 84,87 **** --- 86,90 ---- import com.babeldoc.core.option.ConfigOption; import com.babeldoc.core.option.IConfigOptionType; + import com.babeldoc.core.option.ValueListConfigOptionType; import com.babeldoc.core.pipeline.PipelineDocument; import com.babeldoc.scanner.ScannerConfigurationException; *************** *** 105,108 **** --- 108,115 ---- public static final String FILTER_FILENAME = "filter"; 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()); *************** *** 167,171 **** setInDirectory(this.getInfo().getStrValue(IN_DIR)); ! if (getInDirectory().getType() != FileType.FOLDER) { throw new ScannerConfigurationException(I18n.get( "scanner.VFSScanner.error.notDir", IN_DIR, --- 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, *************** *** 183,187 **** // Check of the donedirectory actually is a directory ! if (doneDirectory.getType() != FileType.FOLDER) { throw new ScannerConfigurationException(I18n.get( "scanner.VFSScanner.error.notDir", DONE_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, *************** *** 233,267 **** protected void moveFile(FileObject file) throws Exception { try { ! if (getDoneDirectory() == null) { ! file.delete(); ! return; ! } ! ! String path = file.getName().getPath(); ! ! FileObject outDir = fsManager.resolveFile(getDoneDirectory()+ getInDirectory().getName().getPathDecoded().toString()); ! ! // create out dir if not exist ! if (!outDir.exists()) { ! outDir.createFolder(); ! } ! ! // create file with the same name (path) in out dir ! FileObject outfile = fsManager.resolveFile(outDir.getName().toString() + file.getName().getBaseName()); ! // delete file it is already exists ! if (outfile.exists()) { ! outfile.delete(); } - - // rename file - if(!file.canRenameTo(outfile)) - throw new ScannerException(I18n.get("scanner.VFSScanner.error.finishing")); - //TODO Probably can do that more simply with a moveTo() - // } catch (Exception e) { throw new ScannerException(I18n .get("scanner.VFSScanner.error.finishing"), e); } } --- 240,294 ---- 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 ! if (!outDir.exists()) { ! 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) { throw new ScannerException(I18n .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; + + } + } *************** *** 303,307 **** try { processFile(files[i]); ! moveFile(files[i]); } catch (Exception ex) { log.logError( --- 330,334 ---- try { processFile(files[i]); ! moveFile(files[i]); } catch (Exception ex) { log.logError( *************** *** 323,334 **** private void processFile(FileObject file) throws Exception { InputStream fis = null; ! OutputStream baos = null; try { ! // getting message from file byte[] data = new byte[1024]; ! long modified = file.getContent().getLastModifiedTime(); ! fis = file.getContent().getInputStream(); ! baos = file.getContent().getOutputStream(); int charsRead = 0; --- 350,362 ---- private void processFile(FileObject file) throws Exception { InputStream fis = null; ! ByteArrayOutputStream baos = null; 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; *************** *** 338,352 **** } ! 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(); } } --- 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(); } + } *************** *** 362,365 **** --- 393,398 ---- */ 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())) { *************** *** 439,443 **** */ public String getDescription() { ! return I18n.get("scanner.VFSScannerInfo.description"); } --- 472,476 ---- */ public String getDescription() { ! return I18n.get("scanner.VfsScannerInfo.description"); } *************** *** 475,478 **** --- 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; |