From 96b6f27e2ce7fe9ff446375b33432a4d246a7abf Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Mon, 16 Jun 2003 00:45:33 +0000 Subject: [PATCH] added community home page - first step into community support --- conf-sso/sp/dynamo.xml | 4 + conf-sso/sp/web.xml | 16 ++++ conf/dynamo-venice.xml | 1 + conf/venice-db-init-mysql.sql | 24 +++-- conf/web-venice.xml | 18 +++- .../com/silverwrist/util/StringUtils.java | 12 +++ .../dynamo/except/ExternalException.java | 6 ++ .../except/ExternalRuntimeException.java | 6 ++ .../silverwrist/venice/VeniceNamespaces.java | 3 + .../venice/script/LibraryMessages.properties | 19 ++++ .../venice/script/LibraryVenice.java | 90 +++++++++++++++++++ .../venice/servlet/CommunityServlet.java | 63 +++++++++++++ venice-data/util/comm/homepage.js | 66 ++++++++++++++ .../velocity/sideboxes/community-list.vm | 2 +- 14 files changed, 319 insertions(+), 11 deletions(-) create mode 100644 src/venice-base/com/silverwrist/venice/script/LibraryMessages.properties create mode 100644 src/venice-base/com/silverwrist/venice/servlet/CommunityServlet.java create mode 100644 venice-data/util/comm/homepage.js diff --git a/conf-sso/sp/dynamo.xml b/conf-sso/sp/dynamo.xml index e140cf5..0bc5761 100644 --- a/conf-sso/sp/dynamo.xml +++ b/conf-sso/sp/dynamo.xml @@ -57,6 +57,10 @@ + + + + diff --git a/conf-sso/sp/web.xml b/conf-sso/sp/web.xml index 5483072..3ebf29c 100644 --- a/conf-sso/sp/web.xml +++ b/conf-sso/sp/web.xml @@ -164,6 +164,12 @@ com.silverwrist.venice.servlet.UserServlet + + Community + Displays the community homepage. + com.silverwrist.venice.servlet.CommunityServlet + + @@ -281,6 +287,16 @@ /user/* + + Community + /community/* + + + + Community + /sig/* + + diff --git a/conf/dynamo-venice.xml b/conf/dynamo-venice.xml index 4295452..3f08abe 100644 --- a/conf/dynamo-venice.xml +++ b/conf/dynamo-venice.xml @@ -40,6 +40,7 @@ veniceuser XYZZY0099 + diff --git a/conf/venice-db-init-mysql.sql b/conf/venice-db-init-mysql.sql index b949375..63de7df 100644 --- a/conf/venice-db-init-mysql.sql +++ b/conf/venice-db-init-mysql.sql @@ -1368,9 +1368,11 @@ INSERT INTO sbox_master (sbid, sb_nsid, sb_name, type_nsid, type_name, descr) VA (3, 18, 'test2', 18, 'test', 'Test Sidebox #2' ); INSERT INTO sbox_context (sbid, ctx_nsid, ctx_name) VALUES - (1, 17, 'top'), - (2, 17, 'top'), - (3, 17, 'top'); + (1, 17, 'top' ), + (2, 17, 'top' ), + (2, 17, 'community'), + (3, 17, 'top' ), + (3, 17, 'community'); INSERT INTO sbox_props (sbid, nsid, prop_name, prop_value) VALUES (1, 6, 'normal.title', '!Your Communities' ), @@ -1380,9 +1382,13 @@ INSERT INTO sbox_props (sbid, nsid, prop_name, prop_value) VALUES (1, 7, 'security.provider', '!srm' ); INSERT INTO sbox_deploy (uid, ctx_nsid, ctx_name, param, seq, sbid) VALUES - (1, 17, 'top', NULL, 0, 1), - (1, 17, 'top', NULL, 1, 2), - (1, 17, 'top', NULL, 2, 3), - (2, 17, 'top', NULL, 0, 1), - (2, 17, 'top', NULL, 1, 2), - (2, 17, 'top', NULL, 2, 3); + (1, 17, 'top', NULL, 0, 1), + (1, 17, 'top', NULL, 1, 2), + (1, 17, 'top', NULL, 2, 3), + (1, 17, 'community', '.Community:1', 0, 2), + (1, 17, 'community', '.Community:1', 1, 3), + (2, 17, 'top', NULL, 0, 1), + (2, 17, 'top', NULL, 1, 2), + (2, 17, 'top', NULL, 2, 3), + (2, 17, 'community', '.Community:1', 0, 2), + (2, 17, 'community', '.Community:1', 1, 3); diff --git a/conf/web-venice.xml b/conf/web-venice.xml index 47c8132..1e60e83 100644 --- a/conf/web-venice.xml +++ b/conf/web-venice.xml @@ -12,7 +12,7 @@ The Initial Developer of the Original Code is Eric J. Bowersox , for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. Contributor(s): --> @@ -157,6 +157,12 @@ com.silverwrist.venice.servlet.UserServlet + + Community + Displays the community homepage. + com.silverwrist.venice.servlet.CommunityServlet + + @@ -204,6 +210,16 @@ /user/* + + Community + /community/* + + + + Community + /sig/* + + 60 diff --git a/src/baseutil/com/silverwrist/util/StringUtils.java b/src/baseutil/com/silverwrist/util/StringUtils.java index a5da575..7b70cfe 100644 --- a/src/baseutil/com/silverwrist/util/StringUtils.java +++ b/src/baseutil/com/silverwrist/util/StringUtils.java @@ -313,6 +313,18 @@ public class StringUtils extends org.apache.commons.lang.StringUtils } // end split1 + /** + * Returns the string equivalent of this object, or null if the specified object is null. + * + * @param obj The object to be converted to a string. + * @return See above. + */ + public static final String stringize(Object obj) + { + return ((obj==null) ? null : obj.toString()); + + } // end stringize + /*-------------------------------------------------------------------------------- * Static initializer *-------------------------------------------------------------------------------- diff --git a/src/dynamo-framework/com/silverwrist/dynamo/except/ExternalException.java b/src/dynamo-framework/com/silverwrist/dynamo/except/ExternalException.java index b58109e..bb9aeab 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/except/ExternalException.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/except/ExternalException.java @@ -179,6 +179,12 @@ public class ExternalException extends DynamoException *-------------------------------------------------------------------------------- */ + public String getMessageID() + { + return m_message_id; + + } // end getMessageID + /** * Sets a replacement parameter for the message. * diff --git a/src/dynamo-framework/com/silverwrist/dynamo/except/ExternalRuntimeException.java b/src/dynamo-framework/com/silverwrist/dynamo/except/ExternalRuntimeException.java index 43b151b..8a99d44 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/except/ExternalRuntimeException.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/except/ExternalRuntimeException.java @@ -162,6 +162,12 @@ public class ExternalRuntimeException extends DynamoRuntimeException *-------------------------------------------------------------------------------- */ + public String getMessageID() + { + return m_message_id; + + } // end getMessageID + /** * Sets a replacement parameter for the message. * diff --git a/src/venice-base/com/silverwrist/venice/VeniceNamespaces.java b/src/venice-base/com/silverwrist/venice/VeniceNamespaces.java index b950104..dd82ee7 100644 --- a/src/venice-base/com/silverwrist/venice/VeniceNamespaces.java +++ b/src/venice-base/com/silverwrist/venice/VeniceNamespaces.java @@ -70,4 +70,7 @@ public interface VeniceNamespaces public static final String SIDEBOX_CONTEXT_NAMESPACE = "http://www.silverwrist.com/NS/venice/2003/05/31/sidebox.context.ids"; + public static final String COMMUNITY_NAMESPACE = + "http://www.silverwrist.com/NS/venice/2003/06/15/community"; + } // end interface VeniceNamespaces diff --git a/src/venice-base/com/silverwrist/venice/script/LibraryMessages.properties b/src/venice-base/com/silverwrist/venice/script/LibraryMessages.properties new file mode 100644 index 0000000..4131e58 --- /dev/null +++ b/src/venice-base/com/silverwrist/venice/script/LibraryMessages.properties @@ -0,0 +1,19 @@ +# 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) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +# +# Contributor(s): +# --------------------------------------------------------------------------------- +# This file has been localized for the en_US locale +invalid.cid=The specified community ID "{0}" is not a valid integer. +no.community=No community ID was specified for this operation. diff --git a/src/venice-base/com/silverwrist/venice/script/LibraryVenice.java b/src/venice-base/com/silverwrist/venice/script/LibraryVenice.java index 9bdcbac..8e88c26 100644 --- a/src/venice-base/com/silverwrist/venice/script/LibraryVenice.java +++ b/src/venice-base/com/silverwrist/venice/script/LibraryVenice.java @@ -25,7 +25,9 @@ import com.silverwrist.dynamo.except.*; import com.silverwrist.dynamo.iface.*; import com.silverwrist.dynamo.util.*; import com.silverwrist.venice.VeniceNamespaces; +import com.silverwrist.venice.community.CommunityService; import com.silverwrist.venice.content.*; +import com.silverwrist.venice.iface.*; import com.silverwrist.venice.session.SessionInfoParams; public class LibraryVenice @@ -85,6 +87,37 @@ public class LibraryVenice } // end constructor + /*-------------------------------------------------------------------------------- + * Internal operations + *-------------------------------------------------------------------------------- + */ + + private final int getCommunityParameter(Request req) throws ValidationException + { + Map pmap = req.getParameters(); + String cparam = StringUtils.stringize(pmap.get("cid")); + if (cparam==null) + cparam = StringUtils.stringize(pmap.get("cc")); + if (cparam==null) + cparam = StringUtils.stringize(pmap.get("sig")); + if (cparam==null) + return -1; // completely not-specified + + try + { // get the community ID + return Integer.parseInt(cparam.trim()); + + } // end try + catch (NumberFormatException e) + { // couldn't be parsed as an integer - damn! + ValidationException ve = new ValidationException(LibraryVenice.class,"LibraryMessages","invalid.cid",e); + ve.setParameter(0,cparam); + throw ve; + + } // end catch + + } // end getCommunityParameter + /*-------------------------------------------------------------------------------- * External operations *-------------------------------------------------------------------------------- @@ -101,6 +134,63 @@ public class LibraryVenice } // end dialogFrameTitle + public VeniceCommunity getCommunity(Request req) throws DatabaseException, ValidationException + { + VeniceCommunity rc = (VeniceCommunity)(PropertyUtils.getPropertyNoErr(req,VeniceNamespaces.COMMUNITY_NAMESPACE, + "current")); + if (rc==null) + { // get the value of the community ID parameter + int cid = getCommunityParameter(req); + if (cid==-1) + throw new ValidationException(LibraryVenice.class,"LibraryMessages","no.community"); + + // use that to get the community + ObjectProvider op = (ObjectProvider)(req.queryService(ObjectProvider.class)); + CommunityService csvc = (CommunityService)(op.getObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"communities")); + rc = csvc.getCommunity(cid); + + // save community reference for next time + req.setObject(VeniceNamespaces.COMMUNITY_NAMESPACE,"current",rc); + + } // end if + + return rc; + + } // end getCommunity + + public VeniceCommunity getCommunity(Request req, VeniceCommunity def) throws DatabaseException, ValidationException + { + VeniceCommunity rc = (VeniceCommunity)(PropertyUtils.getPropertyNoErr(req,VeniceNamespaces.COMMUNITY_NAMESPACE, + "current")); + if ((rc==null) && PropertyUtils.hasProperty(req,VeniceNamespaces.COMMUNITY_NAMESPACE,"is.null")) + return null; + if (rc==null) + { // get the value of the community ID parameter + int cid = getCommunityParameter(req); + if (cid!=-1) + { // use that to get the community + ObjectProvider op = (ObjectProvider)(req.queryService(ObjectProvider.class)); + CommunityService csvc = (CommunityService)(op.getObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"communities")); + rc = csvc.getCommunity(cid); + + } // end if + else + { // just employ the default community + rc = def; + if (rc==null) + req.setObject(VeniceNamespaces.COMMUNITY_NAMESPACE,"is.null",Boolean.TRUE); + + } // end else + + if (rc!=null) // save community reference for next time + req.setObject(VeniceNamespaces.COMMUNITY_NAMESPACE,"current",rc); + + } // end if + + return rc; + + } // end getCommunity + public String getLocation(Request req) { return (String)(req.getObject(SessionInfoParams.REQ_NAMESPACE,SessionInfoParams.RATTR_LOCATION)); diff --git a/src/venice-base/com/silverwrist/venice/servlet/CommunityServlet.java b/src/venice-base/com/silverwrist/venice/servlet/CommunityServlet.java new file mode 100644 index 0000000..cc760da --- /dev/null +++ b/src/venice-base/com/silverwrist/venice/servlet/CommunityServlet.java @@ -0,0 +1,63 @@ +/* + * 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) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.servlet; + +import com.silverwrist.dynamo.HttpStatusCode; +import com.silverwrist.dynamo.Namespaces; +import com.silverwrist.dynamo.except.*; +import com.silverwrist.dynamo.iface.*; +import com.silverwrist.dynamo.servlet.ServletBase; +import com.silverwrist.dynamo.util.*; +import com.silverwrist.venice.VeniceNamespaces; +import com.silverwrist.venice.community.CommunityService; +import com.silverwrist.venice.iface.*; + +public class CommunityServlet extends ServletBase +{ + /*-------------------------------------------------------------------------------- + * Abstract implementations from class ServletBase + *-------------------------------------------------------------------------------- + */ + + protected Object process(Request r, Application app) throws Exception + { + // Look up the community. + ObjectProvider op = (ObjectProvider)(r.queryService(ObjectProvider.class)); + CommunityService csvc = (CommunityService)(op.getObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"communities")); + VeniceCommunity comm = null; + try + { // get the community by its alias + comm = csvc.getCommunity(r.getExtraPath().substring(1)); + + } // end try + catch (DatabaseException e) + { // handle "not-found" errors in a special way + if (e.getMessageID().equals("cid.notFound")) + return new HttpErrorMessage(HttpStatusCode.E_NOTFOUND); + throw e; + + } // end catch + + // Execute the script that produces the value. + r.setObject(VeniceNamespaces.COMMUNITY_NAMESPACE,"current",comm); + ScriptExecute exec = (ScriptExecute)(r.queryService(ScriptExecute.class)); + return exec.executeScript(r,"/util/comm/homepage.js"); + + } // end process + +} // end class CommunityServlet diff --git a/venice-data/util/comm/homepage.js b/venice-data/util/comm/homepage.js new file mode 100644 index 0000000..db14d70 --- /dev/null +++ b/venice-data/util/comm/homepage.js @@ -0,0 +1,66 @@ +// 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) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +// +// Contributor(s): + +importPackage(Packages.com.silverwrist.dynamo.iface); +importPackage(Packages.com.silverwrist.dynamo.util); +importPackage(Packages.com.silverwrist.venice.iface); + +req = bsf.lookupBean("request"); +req_help = bsf.lookupBean("request_help"); +user = vlib.getUser(req); +comm = vlib.getCommunity(req); + +// Create the page content. +// BEGIN TEMPORARY STUFF + +// Find the standard content supplier. +scs = vcast.queryContentBlockProvider(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"venice-content")); + +// Get an instance of the content block representing the page title. +cblk = scs.getContentBlock("content.header"); +cblk.setContentParameter("title","Home Page"); +cblk.setContentParameter("subtitle",comm.getName()); + +lipsum = "

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore " + + "et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " + + "aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum " + + "dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " + + "officia deserunt mollit anim id est laborum.

"; + +// Put together a list of objects to render in order. +page_content = new ArrayList(); +page_content.add(cblk); +page_content.add(lipsum); + +// END TEMPORARY STUFF + +// Create the sidebox list. +sideboxes = vcast.querySideboxService(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"venice-sidebox")); +sidebox_list = sideboxes.getSideboxes(req,VeniceNamespaces.SIDEBOX_CONTEXT_NAMESPACE,"community",comm); + +// Create the master view and return it. +rc = new SideboxView(page_content,sidebox_list); +//rc.menuSelector = "community"; +rc.pageTitle = comm.getName() + ": Home"; +rc.pageQID = "community/" + comm.getAlias(); +if (!(user.isAnonymous())) +{ // they only get to configure if they're logged in + rc.configureURL = "TODO"; + rc.configureURLType = "SERVLET"; + +} // end if + +dynamo.scriptOutput(rc); diff --git a/venice-data/velocity/sideboxes/community-list.vm b/venice-data/velocity/sideboxes/community-list.vm index 11a4b0a..25e116f 100644 --- a/venice-data/velocity/sideboxes/community-list.vm +++ b/venice-data/velocity/sideboxes/community-list.vm @@ -27,7 +27,7 @@ #bullet() - #encodeHTML( ${c.Name} ) + #encodeHTML( ${c.Name} ) #if( ${c.isAdministrator($user)} ) ## user is administrator, include the "Host!" graphic  Host!