|
What this is
Other links
The source code/* $Id: presentation.java,v 1.8 2001/04/30 20:50:08 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.core; import java.io.*; import org.w3c.dom.*; import org.apache.xerces.parsers.DOMParser; import org.apache.regexp.RE; import webEditor.util.*; /** * Presentation management * @author <a href="mailto:agarcia@mundofree.com">Alfredo Garcia */ public class presentation { /** * Editor root */ private String wEd_root; /** * DOM tree with the configuration values */ private Document configDoc = null; /** * Path for the data configuration files */ private String dataDir; /** * Path for the XSL template files */ private String tplDir; /** * Path for the edition XSL template files */ private String editTplDir; /** * Path for the presentation XSL template files */ private String showTplDir; /** * Path for the configuration XSL template files */ private String configTplDir; /** * Distinctive name of the web server. */ private String serverName; /** * Document root of the web server */ private String docRoot; public presentation (configuration initParam) { xml_parser confParser = new xml_parser (); this.configDoc = confParser.writeDOM ("general", initParam.returnData()); String categoryName = "directories"; this.wEd_root = initParam.readValue ("webEditor_Root","wEd_root"); this.dataDir = initParam.readValue (categoryName,"dataDir"); this.dataDir = this.wEd_root + "/" + this.dataDir; this.tplDir = initParam.readValue (categoryName,"tplDir"); this.tplDir = this.dataDir + "/" + this.tplDir; this.editTplDir = this.tplDir + "/editor"; this.showTplDir = this.tplDir + "/presentation"; this.configTplDir = this.tplDir + "/config"; } /** * Compose the news data input pages * @param newsDoc DOM tree of the document to edit * @param mode Edition mode (rich or simple) * @param browserType User-agent headers * @return String HTML output */ public String showTextEditor(Document newsDoc, String mode, String browserType) { String templateFile = "/editor.xsl"; try { RE r = new RE("MSIE"); if ( mode.equals ("rich") && (r.match (browserType)) ) { // You must use IE and enable the rich content edition // if you want to use this feature :-) templateFile = "/editor-ie.xsl"; // We also will try to escape special characters in the doc //escapeChars myChar = new escapeChars (); //newsDoc = myChar.escapeDoc (newsDoc); } // We must add the configuration tree to the document tree newsDoc = this.addConfiguration (newsDoc, this.configDoc); } catch (Exception e) { e.printStackTrace(); } String outputString = null; // The template name must be URL compilant String templateName = new File (this.editTplDir + templateFile).getAbsolutePath(); templateName = "file:" + templateName; try { xsl_transform transform = new xsl_transform (); outputString = transform.processDOM (newsDoc, templateName); } catch (Exception e) { e.printStackTrace(); } return (outputString); } /** * Compose the images input pages * @param newsDoc DOM tree of the document to edit * @param newsSection Section of the document * @return String HTML output */ public String showImgEditor(Document newsDoc, String newsSection) { String outputString = null; // The template name must be URL compilant String templateName = new File (this.editTplDir + "/image.xsl").getAbsolutePath(); templateName = "file:" + templateName; // We must add the configuration tree to the document tree newsDoc = this.addConfiguration (newsDoc, this.configDoc); try { xsl_transform transform = new xsl_transform (); outputString = transform.processDOM (newsDoc, templateName); } catch (Exception e) { e.printStackTrace(); } return (outputString); } /** * Compose the composition index page * @param newsDoc DOM tree of the index * @param mode Mode of presentation (basicaly "edit" or "presentation") * @return String HTML output */ public String showIndex (Document indexDoc, String mode) { String outputString = null; String templatePath = null; // The template name must be URL compilant if ( mode == "edit" ) { templatePath = this.editTplDir; } else { templatePath = this.showTplDir; } String templateName = new File (templatePath + "/index.xsl").getAbsolutePath(); templateName = "file:" + templateName; // We must add the configuration tree to the document tree indexDoc = this.addConfiguration (indexDoc, this.configDoc); try { xsl_transform transform = new xsl_transform (); outputString = transform.processDOM (indexDoc, templateName); } catch (Exception e) { e.printStackTrace(); } return (outputString); } /** * Compose the presentation of a news document * @param newsDoc DOM tree of the document * @param mode Mode of presentation (basicaly "show" or "publish") * @return String HTML output */ public String showDoc (Document newsDoc, String mode) { String outputString = null; String templateFile = null; // The template name must be URL compilant if ( mode == "show" ) { templateFile = "/doc.xsl"; } else { templateFile = "/htmldoc.xsl"; } String templateName = new File (this.showTplDir+ templateFile).getAbsolutePath(); templateName = "file:" + templateName; // We must add the configuration tree to the document tree newsDoc = this.addConfiguration (newsDoc, this.configDoc); try { xsl_transform transform = new xsl_transform (); outputString = transform.processDOM (newsDoc, templateName); } catch (Exception e) { e.printStackTrace(); } return (outputString); } /** * Compose the configuration screen * @param configDoc DOM tree of the configuration parameters * @return String HTML output */ public String showConfig (Document configDoc) { String outputString = null; // The template name must be URL compilant String templateName = new File (this.configTplDir + "/sample.xsl").getAbsolutePath(); templateName = "file:" + templateName; // We must add the configuration tree to the document tree configDoc = this.addConfiguration (configDoc, this.configDoc); try { xsl_transform transform = new xsl_transform (); outputString = transform.processDOM (configDoc, templateName); } catch (Exception e) { e.printStackTrace(); } return (outputString); } /** * Compose the configuration editor screen * @param configDoc DOM tree of the configuration parameters * @return String HTML output */ public String showConfigEditor (Document configDoc) { String outputString = null; // The template name must be URL compilant String templateName = new File (this.configTplDir + "/edit-config.xsl").getAbsolutePath(); templateName = "file:" + templateName; // We must add the configuration tree to the document tree configDoc = this.addConfiguration (configDoc, this.configDoc); try { xsl_transform transform = new xsl_transform (); outputString = transform.processDOM (configDoc, templateName); } catch (Exception e) { e.printStackTrace(); } return (outputString); } /** * Adds the current configuration to the DOM tree; * In this way, the templates can know the behavior of the page * @param doc Original DOM tree * @param config Configuration values * @return String HTML output */ public Document addConfiguration (Document doc, Document config) { // We get the document root Element root = doc.getDocumentElement(); Element item = doc.createElement ("configuration"); item.appendChild (doc.importNode (config.getDocumentElement(), true)); root.appendChild (item); return (doc); } } |
... 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.