KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > applications > actions > ViewDatabaseSettingsAction


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.deliver.applications.actions;
25
26 import java.io.File JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
31 import org.infoglue.cms.controllers.kernel.impl.simple.DatabaseDefinitionsController;
32 import org.infoglue.cms.io.FileHelper;
33 import org.infoglue.cms.util.CmsPropertyHandler;
34
35 /**
36  * This is the action that shows the application state and also can be used to set up surveilence.
37  * The idea is to have one command which allways returns a known resultpage if it's ok. Otherwise it prints
38  * an error-statement. This action is then called every x minutes by the surveilence and an alarm is raised if something is wrong.
39  * We also have a command which can list more status about the application.
40  *
41  * @author Mattias Bogeblad
42  */

43
44 public class ViewDatabaseSettingsAction extends InfoGlueAbstractAction
45 {
46     private String JavaDoc databasesXML = null;
47     
48     private Map JavaDoc databases = null;
49     
50     public String JavaDoc doExecute() throws Exception JavaDoc
51     {
52         String JavaDoc databaseDefinitions = CmsPropertyHandler.getContextRootPath() + File.separator + "WEB-INF" + File.separator + "classes" + File.separator + "databaseDefinitions.xml";
53         File JavaDoc file = new File JavaDoc(databaseDefinitions);
54         if(file.exists())
55             databasesXML = FileHelper.getFileAsString(file);
56         
57         databases = DatabaseDefinitionsController.getController().getDatabaseDefinitions();
58         
59         return SUCCESS;
60     }
61
62     /*
63     <?xml version="1.0" encoding="ISO-8859-1"?>
64 <databases>
65   <database id="default">
66     <property name="url" value="jdbc:mysql://localhost/infoglue20?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
67     <property name="driverClass" value="com.mysql.jdbc.Driver"/>
68     <property name="driverEngine" value="mysql"/>
69     <property name="user" value="root"/>
70     <property name="password" value="ijikal"/>
71     <property name="useUnicode" value="true"/>
72     <property name="encoding" value="UTF-8"/>
73     <property name="maxConnections" value="100"/>
74     <property name="mapping" value="mapping.xml"/>
75   </database>
76 </databases>
77      */

78     
79     public String JavaDoc doUpdate() throws Exception JavaDoc
80     {
81         String JavaDoc databaseDefinitions = CmsPropertyHandler.getContextRootPath() + File.separator + "WEB-INF" + File.separator + "classes" + File.separator + "databaseDefinitions.xml";
82         
83         File JavaDoc file = new File JavaDoc(databaseDefinitions);
84         
85         FileHelper.writeToFile(file, this.databasesXML, false);
86         
87         return SUCCESS;
88     }
89
90     public String JavaDoc getDatabasesXML()
91     {
92         return databasesXML;
93     }
94
95     public void setDatabasesXML(String JavaDoc databasesXML)
96     {
97         this.databasesXML = databasesXML;
98     }
99
100     public Map JavaDoc getDatabases()
101     {
102         return databases;
103     }
104
105 }
106
Popular Tags