1 package org.jpublish.action; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 6 import com.anthonyeden.lib.util.MessageUtilities; 7 import com.opensymphony.xwork.config.providers.XmlConfigurationProvider; 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 import org.apache.commons.vfs.FileContent; 11 import org.apache.commons.vfs.FileObject; 12 import org.apache.commons.vfs.FileSystemException; 13 import org.jpublish.JPublishEngine; 14 15 20 21 public class VFSXmlConfigurationProvider extends XmlConfigurationProvider { 22 23 private static final Log LOG = LogFactory.getLog(VFSXmlConfigurationProvider.class); 24 25 private FileObject file; 26 private long lastModified = -1; 27 28 33 34 public VFSXmlConfigurationProvider(FileObject file) { 35 super(file.getName().getBaseName()); 36 this.file = file; 37 } 38 39 45 46 public boolean needsReload() { 47 try { 48 FileContent content = file.getContent(); 49 long fileLastModified = content.getLastModifiedTime(); 50 if (fileLastModified != lastModified) { 51 lastModified = fileLastModified; 52 return true; 53 } else { 54 return false; 55 } 56 } catch (FileSystemException e) { 57 LOG.warn("Could not determine last modified", e); 58 return true; 59 } 60 } 61 62 68 69 protected InputStream getInputStream(String fileName) { 70 try { 71 if (LOG.isDebugEnabled()) { 72 LOG.debug("Loading file: " + fileName); 73 } 74 FileObject fileObject = file.getParent().resolveFile(fileName); 75 FileContent content = fileObject.getContent(); 76 return content.getInputStream(); 77 } catch (IOException e) { 78 Object [] args = {fileName, e.getMessage()}; 79 String msg = MessageUtilities.getMessage(getClass(), 80 JPublishEngine.MESSAGE_PACKAGE, "ioError", args); 81 throw new RuntimeException (msg); 82 } 83 } 84 85 } 86 | Popular Tags |