|
What this is
Other links
The source code/* $Id: wEd.java,v 1.26 2001/04/27 17:28:31 agarcia3 Exp $ webEditor. The new way in content management Copyright (C) 2001 Alfredo Garcia This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ package webEditor; import java.io.*; import java.lang.reflect.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import org.w3c.dom.*; import webEditor.core.*; import webEditor.util.*; import webEditor.interfaces.*; /** * webEditor main class * * We will try to mantaing this class simply as a * dispatcher for the rest of the classes in the package * * @author <a href="mailto:agarcia@mundofree.com">Alfredo Garcia */ public class wEd extends HttpServlet { // Location of the general configuration file for this editor // You must set this property to the proper value for your system String wEd_root = null; String tmpDir = null; configuration initConfig = null; /** * Performs the initial variables load. * @param initTable Initial values * @return void */ public void initialLoad (configuration initTable) { /* Load conf parameteres into variables */ this.tmpDir = initTable.readValue ("directories", "tmpDir"); } /** * The servlet engine will call this method to handle the request. * @param request HTTP request * @param response HTTP response * @return void */ public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out; HttpParameterParser myParser = new HttpParameterParser (request); Hashtable parameters = new Hashtable (); Hashtable headers = new Hashtable (); // set content type and other response header fields first response.setContentType("text/html"); // then write the data of the response out = response.getWriter(); // Parse the conf file and load the conf values in a Hash table this.wEd_root = this.getInitParameter("wEd_root"); if (this.wEd_root == null) { // Ok, no wEd_root variable, so we rise an application Exception this.wEd_error ("wEd_root environment variable not defined",out); return; } // We check now for the existence of the configuration file File checker = new File (this.wEd_root + "/general.xml"); if ( !checker.exists() ) { this.wEd_error ("webEditor configuration file (" + this.wEd_root + "/general.xml) doesn't exists",out); return; } this.initConfig = new configuration (this.wEd_root + "/general.xml"); this.initialLoad (this.initConfig); // We are going to store the wEd_root variable in a new config category this.initConfig.storeValue ("webEditor_Root", "wEd_root", this.wEd_root); // Now, we check the servlet parameters & HTTP headers parameters = myParser.getAllParameters (this.tmpDir); this.initConfig.storeCategory ("HTTP Parameters", parameters); headers = myParser.getAllHeaders (); this.initConfig.storeCategory ("HTTP Headers", headers); String opMode = this.initConfig.readValue ("HTTP Parameters", "mode"); if (opMode == null) { // Default operation mode opMode = "composition"; } try { // We use reflection to invoque the proper method Method m = getClass().getMethod(opMode, new Class[] {HttpServletRequest.class, PrintWriter.class} ); m.invoke(this,new Object[] {request, out}); } catch (Exception e) { out.println ("Method not supported"); } out.close(); } /** * The servlet engine will call this method to handle the request. * @param request HTTP request * @param response HTTP response * @return void */ public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet (request , response); } /** * Handler of the composition interface. * @param request HTTP request * @param out Output of the servlet * @return void */ public void composition (HttpServletRequest request, PrintWriter out) throws ServletException, IOException { compositionMode myIndex = new compositionMode (this.initConfig); myIndex.presentation (request, out); } /** * Handler of the configuration interface. * @param request HTTP request * @param out Output of the servlet * @return void */ public void config (HttpServletRequest request, PrintWriter out) throws ServletException, IOException { configMode myConfig = new configMode(this.initConfig); myConfig.showConfig (request, out); } /** * Handler of the edition interface. * @param request HTTP request * @param out Output of the servlet * @return void */ public void edit (HttpServletRequest request, PrintWriter out) throws ServletException, IOException { editMode myEditor = new editMode (initConfig); myEditor.edition (request, out); } /** * Handler of the presentation interface. * @param request HTTP request * @param out Output of the servlet * @return void */ public void presentation (HttpServletRequest request, PrintWriter out) throws ServletException, IOException { presentationMode myIndex = new presentationMode (this.initConfig); myIndex.presentation (request, out); } /** * Handler of the images interface. * @param request HTTP request * @param out Output of the servlet * @return void */ public void images (HttpServletRequest request, PrintWriter out) throws ServletException, IOException { imageMode myImage = new imageMode (this.initConfig); myImage.edition (request, out); } /** * Shows the error screen * @param request HTTP request * @return void */ public void wEd_error (String errorString, PrintWriter out) { String outputString = "<center>" + errorString + "</font>"; out.println (outputString); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.