KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > admininterface > pages > DeploymentUtilsPage


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

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 JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23
24
25 /**
26  * Used to redeploy the files in the classpath (jsps and stuff).
27  * @author Philipp Bracher
28  * @version $Revision: 6341 $ ($Author: philipp $)
29  */

30 public class DeploymentUtilsPage extends TemplatedMVCHandler {
31
32     /**
33      * The interval of the deamon
34      */

35     private int seconds;
36
37     class RedeployDeamon extends Thread JavaDoc {
38
39         int seconds;
40
41         public RedeployDeamon(int seconds) {
42             this.seconds = seconds;
43             this.setDaemon(true);
44         }
45
46         /**
47          * @see java.lang.Thread#run()
48          */

49         public void run() {
50             try {
51                 while (true) {
52                     redeployFiles();
53                     sleep(seconds * 1000);
54                 }
55             }
56             catch (Exception JavaDoc e) {
57                 e.printStackTrace();
58             }
59         }
60     }
61
62     /**
63      * @param name
64      * @param request
65      * @param response
66      */

67     public DeploymentUtilsPage(String JavaDoc name, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
68         super(name, request, response);
69     }
70
71     public String JavaDoc redeploy() {
72         try {
73             redeployFiles();
74             AlertUtil.setMessage("Redeployed");
75         }
76         catch (Exception JavaDoc e) {
77             AlertUtil.setMessage("Can't redeploy files", e);
78         }
79         return this.show();
80     }
81
82     /**
83      * @throws Exception
84      */

85     protected static void redeployFiles() throws Exception JavaDoc {
86         String JavaDoc[] moduleFiles = ClasspathResourcesUtil.findResources(new ClasspathResourcesUtil.Filter() {
87
88             public boolean accept(String JavaDoc name) {
89                 return name.startsWith("/mgnl-files/");
90             }
91         });
92
93         ModuleUtil.installFiles(moduleFiles, "/mgnl-files/");
94     }
95
96     public String JavaDoc startDeamon() {
97         Thread JavaDoc 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 JavaDoc reloadI18nMessages() {
105         try {
106             MessagesManager.reload();
107             AlertUtil.setMessage("AbstractMessagesImpl reloaded!");
108         }
109         catch (Exception JavaDoc e) {
110             e.printStackTrace();
111             AlertUtil.setMessage("Can't reload", e);
112         }
113
114         return this.show();
115     }
116
117     /**
118      * @return Returns the seconds.
119      */

120     public int getSeconds() {
121         return this.seconds;
122     }
123
124     /**
125      * @param seconds The seconds to set.
126      */

127     public void setSeconds(int seconds) {
128         this.seconds = seconds;
129     }
130
131 }
132
Popular Tags