1 20 21 package org.jahia.services.templates_deployer; 22 23 24 import java.io.File ; 25 import java.util.Enumeration ; 26 import java.util.Hashtable ; 27 import java.util.Vector ; 28 29 import org.jahia.data.templates.JahiaTemplatesPackage; 30 import org.jahia.exceptions.JahiaException; 31 import org.jahia.services.JahiaService; 32 import org.jahia.services.pages.JahiaPageDefinition; 33 import org.jahia.services.sites.JahiaSite; 34 35 36 42 public abstract class JahiaTemplatesDeployerService extends JahiaService { 43 44 45 46 47 protected static String m_TempFolderDiskPath = ""; 48 49 50 protected static String m_TempFolderPrefix = "todelete_" ; 51 52 59 protected static Hashtable m_TemplatesPackage = new Hashtable (); 60 61 62 63 private static final String TEMPLATES_XML = "templates.xml"; 64 65 66 67 76 public abstract boolean deploy(JahiaSite site, String rootFolder, String filePath, boolean moveTemplate) throws JahiaException ; 77 78 79 85 public abstract boolean undeploy(JahiaPageDefinition template) throws JahiaException ; 86 87 88 96 public abstract boolean deploy(JahiaSite site, Vector files) ; 97 98 99 105 public abstract String getTemplateRootPath() ; 106 107 108 114 public abstract String getTemplatesContext(); 115 116 117 123 public abstract String getNewTemplatesPath() ; 124 125 126 132 public abstract String getSharedTemplatesPath(); 133 134 135 143 public abstract JahiaTemplatesPackage loadTemplatesInfo(String path) ; 144 145 146 153 public abstract void registerTemplates( JahiaSite site, JahiaTemplatesPackage pack ) throws JahiaException ; 154 155 156 157 158 159 160 161 162 181 182 183 192 public boolean deletePackage(JahiaSite site, String path) { 193 194 195 synchronized(m_TemplatesPackage){ 196 197 File tmpFile = new File (path); 198 StringBuffer filename = new StringBuffer (site.getSiteKey()); 199 filename.append("_"); 200 filename.append(tmpFile.getName()); 201 202 204 if ( tmpFile != null && tmpFile.isFile() ){ 205 if (tmpFile.delete()){ 206 m_TemplatesPackage.remove(filename.toString()); 207 return true; 208 } else { 209 return false; 210 } 211 } else { 212 m_TemplatesPackage.remove(filename.toString()); 213 return true; 214 } 215 } 216 } 217 218 219 228 public void addNewFile(JahiaSite site, String path) { 229 230 231 synchronized(m_TemplatesPackage){ 232 233 File tmpFile = new File (path); 234 StringBuffer filename = new StringBuffer (site.getSiteKey()); 235 filename.append("_"); 236 filename.append(tmpFile.getName()); 237 238 JahiaTemplatesPackage pack = null; 239 240 if ( m_TemplatesPackage.get(filename.toString())==null ) { 241 242 pack = loadTemplatesInfo(path); 243 if ( pack != null ){ 244 m_TemplatesPackage.remove(filename.toString()); 245 m_TemplatesPackage.put(filename.toString(),pack); 246 } 247 } 248 } 249 } 250 251 252 258 public Enumeration getTemplatesPackageKeys(){ 259 260 synchronized(m_TemplatesPackage){ 261 return m_TemplatesPackage.keys(); 262 } 263 264 } 265 266 267 274 public Enumeration getTemplatesPackageKeys(String siteKey){ 275 276 Enumeration enumeration = null; 277 Vector result = new Vector (); 278 synchronized(m_TemplatesPackage){ 279 280 enumeration = m_TemplatesPackage.keys(); 281 String name = null; 282 String siteIdent = siteKey + "_"; 283 while ( enumeration.hasMoreElements() ){ 284 name = (String )enumeration.nextElement(); 285 if ( name.startsWith(siteIdent) ){ 286 result.add(siteIdent); 287 } 288 } 289 return result.elements(); 290 } 291 292 } 293 294 295 302 public Enumeration getTemplatesPackages(String siteKey){ 303 304 Enumeration enumeration = null; 305 Vector result = new Vector (); 306 synchronized(m_TemplatesPackage){ 307 308 enumeration = m_TemplatesPackage.keys(); 309 String name = null; 310 String siteIdent = siteKey + "_"; 311 while ( enumeration.hasMoreElements() ){ 312 name = (String )enumeration.nextElement(); 313 if ( name.startsWith(siteIdent) ){ 314 result.add(m_TemplatesPackage.get(name)); 315 } 316 } 317 return result.elements(); 318 } 319 } 320 321 322 329 public Object getTemplatesPackage(String theKey){ 330 331 synchronized(m_TemplatesPackage){ 332 return m_TemplatesPackage.get(theKey); 333 } 334 } 335 336 337 345 public void scanDirectory(String path) 346 throws JahiaException { 347 348 synchronized(m_TemplatesPackage){ 349 350 JahiaTemplatesPackage pack = null; 351 352 File dir = new File (path); 353 if ( dir != null && dir.isDirectory() ){ 354 355 File [] files = dir.listFiles(); 356 int size = files.length; 357 358 for ( int i=0; i<size ; i++ ){ 359 360 if ( files[i].canWrite() ){ 361 362 pack = loadTemplatesInfo(files[i].getAbsolutePath()); 363 if ( pack != null ){ 364 m_TemplatesPackage.remove(files[i].getName()); 367 m_TemplatesPackage.put(files[i].getName(),pack); 369 } 370 } 371 } 372 } 373 } 374 } 375 376 377 378 379 380 381 382 383 384 385 386 387 } | Popular Tags |