/* * 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.Writer; import java.io.IOException; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import com.silverwrist.util.StringUtil; import com.silverwrist.venice.core.*; public class TopDisplay implements ContentRender, ColorSelectors { /*-------------------------------------------------------------------------------- * Static data values *-------------------------------------------------------------------------------- */ private static final String ATTR_NAME = "com.silverwrist.venice.TopDisplay"; /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ private ServletContext ctxt; private VeniceEngine engine; private UserContext uc; private List top_posts; private List descrs; private VeniceContent[] sideboxes; /*-------------------------------------------------------------------------------- * Constructor *-------------------------------------------------------------------------------- */ public TopDisplay(ServletContext ctxt, VeniceEngine engine, UserContext uc) throws DataException, AccessError, ErrorBox { // Stash some basic information. this.ctxt = ctxt; this.engine = engine; this.uc = uc; this.top_posts = engine.getPublishedMessages(false); this.descrs = uc.getSideBoxList(); // Create the arrays used to construct sideboxes. Class[] ctor_argtypes = new Class[2]; ctor_argtypes[0] = UserContext.class; ctor_argtypes[1] = String.class; Object[] ctor_args = new Object[2]; ctor_args[0] = uc; // Create the actual sideboxes. sideboxes = new VeniceContent[descrs.size()]; for (int i=0; i\n"); out.write("\n"); // The top content is a JSP page, so include it here. rdat.setRequestAttribute(ATTR_NAME,this); RequestDispatcher dispatcher = ctxt.getRequestDispatcher(rdat.getFormatJSPPath("top_content.jsp")); out.flush(); rdat.flushOutput(); // make sure the stuff to be output first is output try { // include me! rdat.includeDispatch(dispatcher); } // end try catch (ServletException se) { // since we can't throw ServletException, we throw IOException throw new IOException("Failure including top_content.jsp"); } // end catch rdat.flushOutput(); // now make sure the included page is properly flushed out.write("\n\n"); // break to the sidebox column for (int i=0; i" + "\n"); out.write(rdat.getStdFontTag(SIDEBOX_TITLE_FOREGROUND,3) + "" + StringUtil.encodeHTML(sideboxes[i].getPageTitle(rdat)) + "\n"); out.write("\n"); // Fill in the sidebox by calling down to the base. if (sideboxes[i] instanceof ContentRender) { // we have a direct-rendering component here - do it ContentRender cr = (ContentRender)(sideboxes[i]); cr.renderHere(out,rdat); } // end if else if (sideboxes[i] instanceof JSPRender) { // we have a JSP rendering component here - bounce to the appropriate JSP file JSPRender jr = (JSPRender)(sideboxes[i]); rdat.storeJSPRender(jr); dispatcher = ctxt.getRequestDispatcher(rdat.getFormatJSPPath(jr.getTargetJSPName())); out.flush(); rdat.flushOutput(); // make sure the stuff to be output first is output try { // include me! rdat.includeDispatch(dispatcher); } // end try catch (ServletException se) { // since we can't throw ServletException, we throw IOException out.write(rdat.getStdFontTag(SIDEBOX_CONTENT_FOREGROUND,2) + "failure rendering class " + sideboxes[i].getClass().getName() + ": " + StringUtil.encodeHTML(se.getMessage()) + "\n"); out.flush(); } // end catch rdat.flushOutput(); // now make sure the included page is properly flushed } // end else if else // this is bogus - just display a little error here out.write(rdat.getStdFontTag(SIDEBOX_CONTENT_FOREGROUND,2) + "cannot display sidebox of class: " + sideboxes[i].getClass().getName() + "\n"); // close up the framework of this sidebox out.write("

\n"); } // end for if (uc.isLoggedIn()) { // write the Configure button below the sideboxes out.write("\"Configure\"\n"); } // end if // Finish up. out.write("\n"); } // end renderHere /*-------------------------------------------------------------------------------- * External operations *-------------------------------------------------------------------------------- */ public static String getPosterName(TopicMessageContext msg) { try { // have to guard agains a DataException here return msg.getCreatorName(); } // end try catch (DataException de) { // just return "unknown" on failure return "(unknown)"; } // end catch } // end getPosterName public static String getMessageBodyText(TopicMessageContext msg) { try { // have to guard against a DataException here return msg.getBodyText(); } // end try catch (DataException de) { // just return an error message return "(Unable to retrieve message data: " + StringUtil.encodeHTML(de.getMessage()) + ")"; } // end catch } // end getMessageBodyText public int getNumTopPosts() { return top_posts.size(); } // end getNumTopPosts public TopicMessageContext getTopPost(int index) { return (TopicMessageContext)(top_posts.get(index)); } // end getTopPost public boolean displayWelcome() { return !(uc.isLoggedIn()); } // end displayWelcome } // end class TopDisplay