KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > webEditor > interfaces > configMode


1 /* $Id: configMode.java,v 1.14 2001/04/23 03:15:31 agarcia3 Exp $
2     webEditor. The new way in content management
3     Copyright (C) 2001 Alfredo Garcia
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     GNU General Public License for more details.
13 */

14
15 package webEditor.interfaces;
16
17 import java.io.*;
18 import java.lang.reflect.*;
19 import java.util.*;
20
21 import javax.servlet.*;
22 import javax.servlet.http.*;
23 import org.w3c.dom.*;
24
25 import webEditor.util.*;
26 import webEditor.core.*;
27
28 /**
29  * Configuration interface; This class shows the page with the editor parameters
30  * @author <a HREF="mailto:agarcia@mundofree.com">Alfredo Garcia</a>
31  */

32
33 public class configMode {
34
35    /**
36     * Configuration values
37     */

38    private configuration initValues;
39
40    /**
41     * Editor root
42     */

43    private String JavaDoc wEd_root;
44
45    /**
46     * Path for the data configuration files
47     */

48    private String JavaDoc dataDir;
49    
50    /**
51     * Path for the XSL template files
52     */

53    private String JavaDoc tplDir;
54
55    /**
56     * Configuration parser
57     */

58    private xml_parser confParser= null;
59
60    /**
61     * Presentation Management
62     */

63    private presentation myEditor= null;
64
65    /**
66     * Class constructor
67     * @param initParam Initial values
68     */

69     public configMode (configuration initParam) {
70     
71     this.initValues = initParam;
72     this.wEd_root = initParam.readValue ("webEditor_Root","wEd_root");
73
74     this.dataDir = initParam.readValue ("directories","dataDir");
75     this.dataDir = this.wEd_root + "/" + this.dataDir;
76
77     this.tplDir = initParam.readValue ("directories","tplDir");
78     this.tplDir = this.dataDir + "/" + this.tplDir;
79     }
80     
81    /**
82     * Operations over the configuration values
83     * @param request HTTP request
84     * @param out Servlet Output
85     * @return void
86     */

87     public void showConfig (HttpServletRequest request, PrintWriter out)
88     throws ServletException,
89            IOException {
90
91     String JavaDoc outputString = "";
92     this.confParser = new xml_parser ();
93     this.myEditor = new presentation (this.initValues);
94
95     String JavaDoc opCode = this.initValues.readValue ("HTTP Parameters", "code");
96     if (opCode == null) {
97         // Default operation mode
98
opCode = "show";
99     }
100
101 try {
102     // We use reflection to invoque the proper method
103
Method m = getClass().getMethod(opCode, new Class JavaDoc[] {HttpServletRequest.class, PrintWriter.class} );
104     m.invoke(this,new Object JavaDoc[] {request, out});
105 }
106 catch (Exception JavaDoc e) {
107     out.println ("Code not supported");
108 }
109
110     }
111     
112    /**
113     * Edition of the configuration values
114     * @param request HTTP request
115     * @param out Servlet Output
116     * @return void
117     */

118     public void edit (HttpServletRequest request, PrintWriter out)
119     throws ServletException, IOException
120     {
121         String JavaDoc action = this.initValues.readValue ("HTTP Parameters", "action");
122     if (action == null) {
123         action = "show";
124     }
125     configuration configValues = null;
126     if ( action.equals ("Save") ) {
127         // We load into the config hash the http parameters
128
Hashtable http_params = this.initValues.readCategory ("HTTP Parameters");
129
130         configValues = new configuration (this.wEd_root + "/general.xml");
131         Document oldConfig = this.confParser.writeDOM ("general",
132                     configValues.returnData());
133         // And then, we write the new http values ...
134
oldConfig = configValues.writeDoc (http_params, oldConfig);
135         configValues.saveConfig (this.wEd_root + "/general.xml", oldConfig);
136     }
137
138     configValues = new configuration (this.wEd_root + "/general.xml");
139     Document doc = this.confParser.writeDOM ("general", configValues.returnData());
140     String JavaDoc outputString = this.myEditor.showConfigEditor (doc);
141
142     out.println (outputString);
143     }
144
145    /**
146     * Simple configuration presentation
147     * @param request HTTP request
148     * @param out Servlet Output
149     * @return void
150     */

151     public void show (HttpServletRequest request, PrintWriter out)
152     throws ServletException, IOException
153     {
154     // With the content of the hash table, build a DOM tree
155
Document doc = this.confParser.writeDOM ("general", this.initValues.returnData());
156     String JavaDoc outputString = this.myEditor.showConfig (doc);
157     out.println (outputString);
158     }
159
160 }
161
Popular Tags