1 13 package info.magnolia.module.admininterface.pages; 14 15 import info.magnolia.cms.i18n.MessagesManager; 16 import info.magnolia.cms.module.ModuleUtil; 17 import info.magnolia.cms.util.AlertUtil; 18 import info.magnolia.cms.util.ClasspathResourcesUtil; 19 import info.magnolia.module.admininterface.TemplatedMVCHandler; 20 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 24 25 30 public class DeploymentUtilsPage extends TemplatedMVCHandler { 31 32 35 private int seconds; 36 37 class RedeployDeamon extends Thread { 38 39 int seconds; 40 41 public RedeployDeamon(int seconds) { 42 this.seconds = seconds; 43 this.setDaemon(true); 44 } 45 46 49 public void run() { 50 try { 51 while (true) { 52 redeployFiles(); 53 sleep(seconds * 1000); 54 } 55 } 56 catch (Exception e) { 57 e.printStackTrace(); 58 } 59 } 60 } 61 62 67 public DeploymentUtilsPage(String name, HttpServletRequest request, HttpServletResponse response) { 68 super(name, request, response); 69 } 70 71 public String redeploy() { 72 try { 73 redeployFiles(); 74 AlertUtil.setMessage("Redeployed"); 75 } 76 catch (Exception e) { 77 AlertUtil.setMessage("Can't redeploy files", e); 78 } 79 return this.show(); 80 } 81 82 85 protected static void redeployFiles() throws Exception { 86 String [] moduleFiles = ClasspathResourcesUtil.findResources(new ClasspathResourcesUtil.Filter() { 87 88 public boolean accept(String name) { 89 return name.startsWith("/mgnl-files/"); 90 } 91 }); 92 93 ModuleUtil.installFiles(moduleFiles, "/mgnl-files/"); 94 } 95 96 public String startDeamon() { 97 Thread deamon = new RedeployDeamon(this.getSeconds()); 98 deamon.setDaemon(true); 99 deamon.start(); 100 AlertUtil.setMessage("Deamon started!"); 101 return this.show(); 102 } 103 104 public String reloadI18nMessages() { 105 try { 106 MessagesManager.reload(); 107 AlertUtil.setMessage("AbstractMessagesImpl reloaded!"); 108 } 109 catch (Exception e) { 110 e.printStackTrace(); 111 AlertUtil.setMessage("Can't reload", e); 112 } 113 114 return this.show(); 115 } 116 117 120 public int getSeconds() { 121 return this.seconds; 122 } 123 124 127 public void setSeconds(int seconds) { 128 this.seconds = seconds; 129 } 130 131 } 132 | Popular Tags |