/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at .
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox ,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.xml.parsers.*;
import org.apache.log4j.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import com.silverwrist.util.DOMElementHelper;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.core.ConfigException;
import com.silverwrist.venice.core.UserContext;
import com.silverwrist.venice.servlets.Variables;
public class RenderConfig
{
/*--------------------------------------------------------------------------------
* Static data values
*--------------------------------------------------------------------------------
*/
protected static final String ATTR_NAME = "com.silverwrist.venice.servlets.RenderConfig";
protected static final String CONFIG_FILE_PARAM = "render.config";
private static Category logger = Category.getInstance(RenderConfig.class.getName());
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private Document config;
private String site_title;
private boolean want_comments;
private boolean allow_gzip;
private String font_face;
private String image_url;
private String static_url;
private String site_logo;
private Hashtable stock_messages;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
protected RenderConfig(String config_file) throws ConfigException
{
config = loadConfiguration(config_file);
// Make sure the configuration is valid...
Element root = config.getDocumentElement();
if (!(root.getTagName().equals("render-config")))
{ // not the correct root tag name
logger.fatal("config document is not a document (root tag: <"
+ root.getTagName() + "/>)");
throw new ConfigException("document is not a document",root);
} // end if
// Get the site name.
DOMElementHelper root_h = new DOMElementHelper(root);
site_title = root_h.getSubElementText("site-name");
if (site_title==null)
{ // no section - bail out now!
logger.fatal("config document has no element");
throw new ConfigException("no section found in config file",root);
} // end if
if (logger.isDebugEnabled())
logger.debug("Site title: " + site_title);
Element render_sect = root_h.getSubElement("rendering");
if (render_sect==null)
{ // no section - bail out now!
logger.fatal("config document has no section");
throw new ConfigException("no section found in config file",root);
} // end if
DOMElementHelper render_sect_h = new DOMElementHelper(render_sect);
want_comments = render_sect_h.hasChildElement("html-comments");
allow_gzip = render_sect_h.hasChildElement("gzip-output");
if (logger.isDebugEnabled())
{ // log the read values
logger.debug("Use HTML comments: " + String.valueOf(want_comments));
logger.debug("Use GZIP encoding: " + String.valueOf(allow_gzip));
} // end if
font_face = render_sect_h.getSubElementText("font");
if (font_face==null)
{ // no tag - bail out now!
logger.fatal(" section has no element");
throw new ConfigException("no found in section",render_sect);
} // end if
if (logger.isDebugEnabled())
logger.debug("Font face: " + font_face);
Element paths_sect = root_h.getSubElement("paths");
if (paths_sect==null)
{ // no section - bail out now!
logger.fatal("config document has no section");
throw new ConfigException("no section found in config file",root);
} // end if
DOMElementHelper paths_sect_h = new DOMElementHelper(paths_sect);
image_url = paths_sect_h.getSubElementText("image");
if (image_url==null)
{ // no tag - bail out now!
logger.fatal(" section has no element");
throw new ConfigException("no found in section",paths_sect);
} // end if
if (logger.isDebugEnabled())
logger.debug("Image path: " + image_url);
static_url = paths_sect_h.getSubElementText("static");
if (static_url==null)
{ // no tag - bail out now!
logger.fatal(" section has no element");
throw new ConfigException("no found in section",paths_sect);
} // end if
if (logger.isDebugEnabled())
logger.debug("Static files path: " + static_url);
site_logo = paths_sect_h.getSubElementText("site-logo");
if (site_logo==null)
{ // no tag - bail out now!
logger.fatal(" section has no element");
throw new ConfigException("no found in section",paths_sect);
} // end if
if (logger.isDebugEnabled())
logger.debug("Site logo: " + image_url);
Element msg_sect = root_h.getSubElement("messages");
if (msg_sect==null)
{ // no section - bail out now!
logger.fatal("config document has no section");
throw new ConfigException("no section found in config file",root);
} // end if
// Initialize the stock messages list.
stock_messages = new Hashtable();
NodeList msg_nodes = msg_sect.getChildNodes();
for (int i=0; i").append(specific).append(" - ").append(site_title).append("");
return buf.toString();
} // end getTitleTag
String getSiteImageTag(int hspace, int vspace)
{
StringBuffer buf = new StringBuffer();
buf.append("0)
buf.append(" HSPACE=").append(hspace);
if (vspace>0)
buf.append(" VSPACE=").append(vspace);
buf.append('>');
return buf.toString();
} // end getSiteImageTag
String getStdFontTag(String color, int size)
{
StringBuffer buf = new StringBuffer("');
return buf.toString();
} // end getStdFontTag
String getStdBaseFontTag(int size)
{
StringBuffer buf = new StringBuffer("*");
return buf.toString();
} // end getRequiredBullet
void writeFooter(Writer out) throws IOException
{
out.write("\n