PenSynchManager.java

00001 package edu.stanford.hci.r3.pen.batch;
00002 
00003 import java.io.File;
00004 import java.util.ArrayList;
00005 import java.util.List;
00006 
00007 import edu.stanford.hci.r3.PaperToolkit;
00008 import edu.stanford.hci.r3.util.files.FileUtils;
00009 import edu.stanford.hci.r3.util.files.SortDirection;
00010 
00023 public class PenSynchManager {
00024 
00025         private File penSynchDataPath;
00026         private List<File> xmlFiles;
00027 
00028         public PenSynchManager() {
00029                 // get the XML data path, and check to see if there are any new files since we last checked.
00030                 // All we do is maintain a modification time of the last file we have processed, and we
00031                 // process any xml file that is newer than this lastModified date.
00032                 penSynchDataPath = PaperToolkit.getPenSynchDataPath();
00033 
00034                 // get list of XML files in the penSynch directory
00035                 xmlFiles = FileUtils.listVisibleFiles(penSynchDataPath, new String[] { "XML" });
00036 
00037                 // DebugUtils.println(xmlFiles);
00038         }
00039 
00040         public List<File> getFiles() {
00041                 SortDirection sortDir = SortDirection.NEW_TO_OLD;
00042                 List<File> files = new ArrayList<File>();
00043                 for (File f : xmlFiles) {
00044                         files.add(f);
00045                 }
00046                 FileUtils.sortByLastModified(files, sortDir);
00047                 return files;
00048         }
00049 
00056         public List<File> getFilesNewerThan(long lastModifiedTimestamp) {
00057                 List<File> newFiles = new ArrayList<File>();
00058                 for (File f : xmlFiles) {
00059                         if (f.lastModified() > lastModifiedTimestamp) {
00060                                 // DebugUtils.println(f.lastModified());
00061                                 newFiles.add(f);
00062                         }
00063                 }
00064                 FileUtils.sortByLastModified(newFiles, SortDirection.OLD_TO_NEW);
00065                 return newFiles;
00066         }
00067 }

Generated on Sat Apr 14 18:21:37 2007 for R3 Paper Toolkit by  doxygen 1.4.7