added community home page - first step into community support
This commit is contained in:
@@ -313,6 +313,18 @@ public class StringUtils extends org.apache.commons.lang.StringUtils
|
||||
|
||||
} // end split1
|
||||
|
||||
/**
|
||||
* Returns the string equivalent of this object, or <CODE>null</CODE> if the specified object is <CODE>null</CODE>.
|
||||
*
|
||||
* @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
|
||||
*--------------------------------------------------------------------------------
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <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@silcom.com>,
|
||||
# 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.
|
||||
@@ -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));
|
||||
|
||||
@@ -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 <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@silcom.com>,
|
||||
* 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
|
||||
Reference in New Issue
Block a user