1 20 21 package org.jahia.services.deamons.filewatcher.templateobserver; 22 23 24 import org.jahia.exceptions.JahiaException; 25 import org.jahia.exceptions.JahiaInitializationException; 26 import org.jahia.registries.ServicesRegistry; 27 import org.jahia.services.deamons.filewatcher.JahiaFileWatcherService; 28 import org.jahia.services.pages.JahiaPageTemplateService; 29 import org.jahia.services.sites.JahiaSite; 30 import org.jahia.services.sites.JahiaSitesService; 31 import org.jahia.services.templates_deployer.JahiaTemplatesDeployerService; 32 33 import java.util.Observable ; 34 import java.util.Observer ; 35 import java.util.Vector ; 36 37 38 44 public class TemplatesObserver implements Observer { 45 46 private static org.apache.log4j.Logger logger = 47 org.apache.log4j.Logger.getLogger (TemplatesObserver.class); 48 49 50 private int mSiteID = -1; 51 52 53 private String mPath; 54 55 56 private boolean mCheckDate = false; 57 58 59 private long mInterval; 60 61 62 private boolean mFileOnly = true; 63 64 65 74 public TemplatesObserver (int siteID, 75 String path, 76 boolean checkDate, 77 long interval, 78 boolean fileOnly) throws JahiaException { 79 80 81 mSiteID = siteID; 82 mPath = path; 83 mCheckDate = checkDate; 84 mInterval = interval; 85 mFileOnly = fileOnly; 86 87 JahiaFileWatcherService fws = ServicesRegistry 88 .getInstance () 89 .getJahiaFileWatcherService (); 90 91 if (fws != null) { 92 93 try { 94 fws.addFileWatcher (mPath, 95 mPath, 96 mCheckDate, 97 mInterval, 98 mFileOnly); 99 100 fws.registerObserver (mPath, this); 101 fws.startFileWatcher (mPath); 102 103 } catch (Throwable t) { 104 105 logger.debug ("Error in templates observer initialization", t); 106 107 throw new JahiaInitializationException ("TemplatesObserver::init failed "); 108 } 109 } 110 } 111 112 113 117 public void update (Observable subject, 118 Object args) { 119 120 synchronized (args) { 121 122 JahiaPageTemplateService pts = ServicesRegistry.getInstance () 123 .getJahiaPageTemplateService (); 124 125 JahiaSitesService ss = ServicesRegistry.getInstance () 126 .getJahiaSitesService (); 127 128 JahiaTemplatesDeployerService tds = ServicesRegistry.getInstance () 129 .getJahiaTemplatesDeployerService (); 130 131 if (pts != null && pts.isInitialized () 132 && ss != null && ss.isInitialized () 133 && tds != null && tds.isInitialized ()) { 134 135 Vector files = (Vector ) args; 136 137 try { 138 JahiaSite site = ss.getSite (mSiteID); 139 if (site != null) { 140 tds.deploy (site, files); 141 } 142 org.jahia.services.database.ConnectionDispenser.terminateConnection (); 143 } catch (Throwable t) { 144 logger.error ("Error in templates observer initialization", t); 145 } 146 } 147 } 148 } 149 150 151 } | Popular Tags |