KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > managementtool > actions > AdminReleaseAction


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.applications.managementtool.actions;
25
26 import java.io.IOException JavaDoc;
27
28 import org.apache.log4j.Logger;
29 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
30 import org.infoglue.cms.util.CmsPropertyHandler;
31
32 /**
33  */

34
35 public class AdminReleaseAction extends InfoGlueAbstractAction
36 {
37     private static final long serialVersionUID = 1L;
38     
39     private final static Logger logger = Logger.getLogger(AdminReleaseAction.class.getName());
40
41     private String JavaDoc adminCommand = "";
42     private String JavaDoc output = "";
43  
44     public String JavaDoc doExecute() throws Exception JavaDoc
45     {
46         output = ExecuteCommand(getAdminCommand());
47         return "success";
48     }
49
50     private static String JavaDoc executeUnix(String JavaDoc unixCmd) throws IOException JavaDoc
51     {
52         Process JavaDoc pr = Runtime.getRuntime().exec(unixCmd);
53         String JavaDoc str;
54         String JavaDoc op ="";
55
56         try {
57                java.io.InputStream JavaDoc is = pr.getInputStream();
58                java.io.InputStreamReader JavaDoc isr = new java.io.InputStreamReader JavaDoc(is);
59                java.io.BufferedReader JavaDoc br = new java.io.BufferedReader JavaDoc(isr);
60                while ((str = br.readLine()) != null) {
61                 logger.info(str);
62                     op+=str +"<br>";
63                }
64                is.close();
65                 op+="<font color='red'>";
66                is = pr.getErrorStream();
67                isr = new java.io.InputStreamReader JavaDoc(is);
68                br = new java.io.BufferedReader JavaDoc(isr);
69                
70                while ((str = br.readLine()) != null) {
71                 logger.info(str);
72                     op+=str +"<br>";
73                }
74                is.close();
75                 op+="</font>";
76                
77         }
78         catch (Exception JavaDoc e) {
79             logger.info("InterruptedException raised: "+e.getMessage());
80             op += e.getMessage();
81         }
82             
83         
84         return op;
85         
86     }
87
88
89     public static String JavaDoc ExecuteCommand (String JavaDoc cmd) throws Exception JavaDoc
90     {
91         String JavaDoc op = "RESULT OF ACTION:<br>";
92         String JavaDoc buildName = CmsPropertyHandler.getBuildName();
93         String JavaDoc admin_tools = CmsPropertyHandler.getAdminToolsPath();
94         String JavaDoc dbRelease = CmsPropertyHandler.getDbRelease();
95         String JavaDoc dbScriptPath = CmsPropertyHandler.getDbScriptPath();
96
97         logger.info("admin tools: " + admin_tools);
98         logger.info("cmd: " + cmd);
99         
100         if (admin_tools == null) return "error: cant find admintools";
101         
102         if (cmd.compareTo("MAKEDEFAULT")==0)
103         {
104             logger.info("Executing makedefault ");
105             String JavaDoc unixCmd = "sh " + admin_tools + "/makedefaultrelease.sh " + buildName;
106             try {
107                 op+=executeUnix(unixCmd);
108             }
109             catch (Exception JavaDoc e) {
110                 logger.info("Exception raised: "+e.getMessage());
111                 op += e.getMessage();
112             }
113         }
114
115         if (cmd.compareTo("RELOADDATA")==0)
116         {
117             // String unixCmd[] = {"sh", admin_tools + "/reloaddata.sh", dbScriptPath};
118
String JavaDoc unixCmd = "sh " + admin_tools + "/reloaddata.sh " + dbScriptPath;
119
120             logger.info("Executing reloaddata ");
121
122             try {
123                 op+=executeUnix(unixCmd);
124             }
125             catch (Exception JavaDoc e) {
126                 logger.info("Exception raised: "+e.getMessage());
127                 op += e.getMessage();
128             }
129             
130         }
131         
132         return op;
133         
134     }
135                
136
137     /**
138      * Returns the adminCommand.
139      * @return String
140      */

141     public String JavaDoc getAdminCommand()
142     {
143         return this.adminCommand;
144     }
145
146     /**
147      * Sets the adminCommand.
148      * @param adminCommand The adminCommand to set
149      */

150     public void setAdminCommand(String JavaDoc adminCommand)
151     {
152         this.adminCommand = adminCommand;
153     }
154
155     /**
156      * Returns the output.
157      * @return String
158      */

159     public String JavaDoc getOutput()
160     {
161         return output;
162     }
163
164     /**
165      * Sets the output.
166      * @param output The output to set
167      */

168     public void setOutput(String JavaDoc output)
169     {
170         this.output = output;
171     }
172
173 }
174
Popular Tags