KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > webEditor > interfaces > editMode


1 /* $Id: editMode.java,v 1.15 2001/04/25 22:17:15 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.util.Hashtable JavaDoc;
19 import java.lang.reflect.*;
20
21 import javax.servlet.*;
22 import javax.servlet.http.*;
23 import org.w3c.dom.*;
24
25 import webEditor.core.*;
26
27 /**
28  * Edition interface; This class manage all the edition phases
29  * @author <a HREF="mailto:agarcia@mundofree.com">Alfredo Garcia</a>
30  */

31
32 public class editMode {
33
34    /**
35     * Initial configuration values
36     */

37    private configuration initValues;
38
39    /**
40     * Name of the document to edit
41     */

42    private String JavaDoc myDocName;
43
44    /**
45     * Presentation management
46     */

47    private presentation myEditor= null;
48
49    /**
50     * HomePage management
51     */

52    private page myPage= null;
53
54    /**
55     * Articles management
56     */

57    private article myDocument= null;
58
59    /**
60     * Class constructor
61     * @param initParam Initial values
62     */

63     public editMode (configuration initParam) {
64         // We are going to use the values in the hash table when we
65
// create another kind of core object
66
this.initValues = initParam;
67     }
68
69    /**
70     * Interface for the edition operations
71     * @param request HTTP request
72     * @param out Servlet Output
73     * @return void
74     */

75     public void edition (HttpServletRequest request, PrintWriter out)
76     throws ServletException,
77            IOException {
78
79         String JavaDoc outputString = null;
80     this.myEditor = new presentation (this.initValues);
81     this.myDocument = new article (this.initValues);
82     this.myPage = new page (this.initValues);
83
84     this.myDocName = this.initValues.readValue("HTTP Parameters", "docID");
85     String JavaDoc opCode = this.initValues.readValue ("HTTP Parameters", "code");
86     
87     if (this.myDocName == null) {
88         // We are editing a new document
89
this.myDocName = "document.xml";
90     }
91     // We check the 'Write' param (it's an image form component)
92
String JavaDoc imgWrite = this.initValues.readValue
93                 ("HTTP Parameters", "Write.x");
94     if (imgWrite != null) {
95         opCode = "Write";
96     }
97
98
99     if (opCode != null) {
100 try {
101     // We use reflection to invoque the proper method
102
Method m = getClass().getMethod(opCode, new Class JavaDoc[0]);
103     m.invoke(this,new Object JavaDoc[0]);
104 }
105 catch (Exception JavaDoc e) {
106     out.println (opCode + " : Code not supported");
107 }
108     }
109
110     Document doc = this.myDocument.docRead (this.myDocName);
111
112     // The last step is to choose witch kind of edition to use
113
String JavaDoc editionMode = this.initValues.readValue("directories", "editionMode");
114     String JavaDoc browserType = this.initValues.readValue("HTTP Headers", "user-agent");
115     if ( browserType == null ) {
116         // Maybe we are using Tomcat (different header names)
117
browserType = this.initValues.readValue("HTTP Headers", "User-Agent");
118     }
119     outputString = this.myEditor.showTextEditor (doc, editionMode, browserType);
120
121     out.println (outputString);
122     }
123
124    /**
125     * Modifies the given article
126     * @return void
127     */

128     public void Write ()
129     throws ServletException, IOException
130     {
131     // We load into the config hash the http parameters
132
Hashtable JavaDoc http_params = this.initValues.readCategory ("HTTP Parameters");
133
134     Document doc = null;
135     if (this.myDocName.equals ("new")) {
136         // xml and html document name
137
this.myDocName = this.myDocument.newDocID ();
138         Hashtable JavaDoc dataStream = new Hashtable JavaDoc();
139         dataStream.put ("docID" , this.myDocName);
140
141         String JavaDoc htmlDocName = this.myDocument.getHTMLname (this.myDocName);
142         dataStream.put ("HTMLname" , htmlDocName);
143         //We write the new docID in the document structure.
144
doc = this.myDocument.docRead ("document.xml");
145         doc = this.myDocument.writeDoc (dataStream, doc, "root");
146         //And we insert this document in the homePage
147
this.myPage.insertDoc (this.myDocName);
148     }
149     else {
150         doc = this.myDocument.docRead (this.myDocName);
151     }
152
153     // And then, we write the new http values ...
154
doc = this.myDocument.writeDoc (http_params, doc, "content");
155     this.myDocument.saveFile (this.myDocName, doc);
156     // ... and the HTML content
157
String JavaDoc htmlContent = this.myEditor.showDoc (doc, "publish");
158     this.myDocument.saveHtmlFile (this.myDocName, htmlContent);
159     }
160
161 }
162
Popular Tags