alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*  $Id: editMode.java,v 1.15 2001/04/25 22:17:15 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.interfaces;

import java.io.*;
import java.util.Hashtable;
import java.lang.reflect.*;

import javax.servlet.*;
import javax.servlet.http.*;
import org.w3c.dom.*;

import webEditor.core.*;

/**
 * Edition interface; This class manage all the edition phases
 * @author <a href="mailto:agarcia@mundofree.com">Alfredo Garcia
 */

public class editMode {

   /**
    * Initial configuration values 
    */
   private configuration initValues;

   /**
    * Name of the document to edit
    */
   private String myDocName;

   /**
    * Presentation management
    */
   private presentation myEditor= null;

   /**
    * HomePage management
    */
   private page myPage= null;

   /**
    * Articles management
    */
   private article myDocument= null;

   /**
    * Class constructor
    * @param initParam		Initial values
    */
    public editMode (configuration initParam) { 
    	// We are going to use the values in the hash table when we
	// create another kind of core object
   	this.initValues = initParam;
    }

   /**
    * Interface for the edition operations
    * @param request		HTTP request
    * @param out		Servlet Output
    * @return void
    */ 
    public void edition (HttpServletRequest request, PrintWriter out) 
    throws ServletException, 
    	   IOException {

    	String outputString = null;
	this.myEditor = new presentation (this.initValues);
	this.myDocument = new article (this.initValues);
	this.myPage = new page (this.initValues);

	this.myDocName = this.initValues.readValue("HTTP Parameters", "docID");
	String opCode = this.initValues.readValue ("HTTP Parameters", "code");
	
	if (this.myDocName == null) {
		// We are editing a new document
		this.myDocName = "document.xml";
	}
	// We check the 'Write' param (it's an image form component)
	String imgWrite = this.initValues.readValue 
				("HTTP Parameters", "Write.x");
	if (imgWrite != null)  {
		opCode = "Write";	
	}


	if (opCode != null) {
try { 
	// We use reflection to invoque the proper method
	Method m = getClass().getMethod(opCode, new Class[0]); 
	m.invoke(this,new Object[0]); 
} 
catch (Exception e) { 
	out.println (opCode + " : Code not supported");
} 
	}

	Document doc = this.myDocument.docRead (this.myDocName);

	// The last step is to choose witch kind of edition to use
	String editionMode = this.initValues.readValue("directories", "editionMode");
	String browserType = this.initValues.readValue("HTTP Headers", "user-agent");
	if ( browserType == null ) {
		// Maybe we are using Tomcat (different header names)
		browserType = this.initValues.readValue("HTTP Headers", "User-Agent");
	}
	outputString = this.myEditor.showTextEditor (doc, editionMode, browserType);

	out.println (outputString);
    }

   /**
    * Modifies the given article
    * @return void
    */
    public void Write ()
	throws ServletException, IOException 
    {
	// We load into the config hash the http parameters
	Hashtable http_params = this.initValues.readCategory ("HTTP Parameters");

	Document doc = null;
	if (this.myDocName.equals ("new")) {
		// xml and html document name
		this.myDocName = this.myDocument.newDocID ();
		Hashtable dataStream = new Hashtable();
		dataStream.put ("docID" , this.myDocName);

		String htmlDocName = this.myDocument.getHTMLname (this.myDocName);
		dataStream.put ("HTMLname" , htmlDocName);
		//We write the new docID in the document structure.
		doc = this.myDocument.docRead ("document.xml");
		doc = this.myDocument.writeDoc (dataStream, doc, "root");
		//And we insert this document in the homePage
		this.myPage.insertDoc (this.myDocName);
	}
	else {
		doc = this.myDocument.docRead (this.myDocName);
	}

	// And then, we write the new http values ...
	doc = this.myDocument.writeDoc (http_params, doc, "content");
	this.myDocument.saveFile (this.myDocName, doc);
	// ... and the HTML content
	String htmlContent = this.myEditor.showDoc (doc, "publish");
	this.myDocument.saveHtmlFile (this.myDocName, htmlContent);
    }

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.