venice-main-classic/scripts/top.js

78 lines
3.1 KiB
JavaScript
Raw Permalink Normal View History

// 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 <http://www.mozilla.org/MPL/>.
//
// 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 <erbo@users.sf.net>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
importPackage(java.util);
importPackage(Packages.com.silverwrist.venice.except);
importPackage(Packages.com.silverwrist.venice.ui);
importPackage(Packages.com.silverwrist.venice.ui.helpers);
importPackage(Packages.com.silverwrist.venice.ui.view);
rinput = bsf.lookupBean("request");
rc = null;
try
{ // get the list of front page posts!
post_list = rinput.engine.getPublishedMessages(false);
// precalculate the message text and poster names of the front-page messages
poster_names = new ArrayList(post_list.size());
message_text = new ArrayList(post_list.size());
topic_names = new ArrayList(post_list.size());
topic_links = new ArrayList(post_list.size());
for (i=0; i<post_list.size(); i++)
{ // get the message text and creator name
msg = vlib.castTopicMessageContext(post_list.get(i));
poster_names.add(msg.getCreatorName());
message_text.add(msg.getBodyText());
topic = msg.getEnclosingTopic();
topic_names.add(topic.getName());
topic_links.add(topic.getPostLink());
} // end for
// save the lists as request variables so we can find them again
rinput.setRequestAttribute("top.fp_posts",post_list);
rinput.setRequestAttribute("top.fp_posts.names",poster_names);
rinput.setRequestAttribute("top.fp_posts.text",message_text);
rinput.setRequestAttribute("top.fp_posts.topics.names",topic_names);
rinput.setRequestAttribute("top.fp_posts.topics.links",topic_links);
// create a JSP view object that'll display all this
view = new JSPView("My Front Page","top_content.jsp");
view.menuSelector = Content.MENU_SELECTOR_TOP;
view.pageQID = "top";
// set it up to auto-refresh if configured to do that
ar = rinput.getConfigProperty("top.refresh");
if (ar!=null)
view.addHTTPMetadata("refresh",ar);
// wrap the JSP view in our sidebox view for return
rc = new SideBoxNestedView(rinput,view);
} // end try
catch (e)
{ // we caught something here - figure out what kind of error it is
etype = vlib.exceptionType(e) + "";
if (etype.match("DataException"))
rc = new ErrorBox("Database Error","Error loading front page: " + e.getMessage(),null);
else if (etype.match("AccessError"))
rc = new ErrorBox("Access Error",e.getMessage(),null);
else
rc = e;
} // end catch
vlib.output(rc); // all done!