added the Sidebox Manager code for the generation of sideboxes on the front
page and the eventual community front pages
This commit is contained in:
parent
15035c2fe6
commit
d6bff8a745
|
@ -165,6 +165,10 @@
|
|||
|
||||
<object name="venice-auditor" classname="com.silverwrist.venice.app.StartupShutdownAuditor" priority="100"/>
|
||||
|
||||
<object name="venice-sidebox" classname="com.silverwrist.venice.sidebox.SideboxManager" priority="100">
|
||||
<database connection="data" namespaces="nscache"/>
|
||||
</object>
|
||||
|
||||
<object name="categories" classname="com.silverwrist.venice.community.CategoryManager" priority="100">
|
||||
<database connection="data"/>
|
||||
</object>
|
||||
|
|
|
@ -164,6 +164,10 @@
|
|||
|
||||
<object name="venice-auditor" classname="com.silverwrist.venice.app.StartupShutdownAuditor" priority="100"/>
|
||||
|
||||
<object name="venice-sidebox" classname="com.silverwrist.venice.sidebox.SideboxManager" priority="100">
|
||||
<database connection="data" namespaces="nscache"/>
|
||||
</object>
|
||||
|
||||
<object name="categories" classname="com.silverwrist.venice.community.CategoryManager" priority="100">
|
||||
<database connection="data"/>
|
||||
</object>
|
||||
|
|
|
@ -306,6 +306,47 @@ CREATE TABLE commprops (
|
|||
PRIMARY KEY (cid, nsid, prop_name)
|
||||
);
|
||||
|
||||
# The master table of sideboxes.
|
||||
CREATE TABLE sbox_master (
|
||||
sbid INT NOT NULL PRIMARY KEY AUTO_INCREMENT, # sidebox identifier
|
||||
sb_nsid INT NOT NULL, # namespace ID of the sidebox
|
||||
sb_name VARCHAR(255) BINARY NOT NULL, # name of the sidebox
|
||||
type_nsid INT NOT NULL, # namespace ID of the type of the sidebox
|
||||
type_name VARCHAR(255) BINARY NOT NULL, # name of the type of the sidebox
|
||||
descr TINYTEXT NOT NULL, # description of the sidebox
|
||||
UNIQUE INDEX by_name (sb_nsid, sb_name)
|
||||
);
|
||||
|
||||
# This table indicates in what contexts a sidebox may be used.
|
||||
CREATE TABLE sbox_context (
|
||||
sbid INT NOT NULL, # sidebox identifier
|
||||
ctx_nsid INT NOT NULL, # namespace ID of the context
|
||||
ctx_name VARCHAR(128) BINARY NOT NULL, # name of the context
|
||||
PRIMARY KEY (sbid, ctx_nsid, ctx_name),
|
||||
UNIQUE INDEX by_ctx (ctx_nsid, ctx_name, sbid)
|
||||
);
|
||||
|
||||
# Properties to be applied to sideboxes when they are created.
|
||||
CREATE TABLE sbox_props (
|
||||
sbid INT NOT NULL, # sidebox identifier
|
||||
nsid INT NOT NULL, # property namespace identifier
|
||||
prop_name VARCHAR(255) BINARY NOT NULL, # property name
|
||||
prop_value VARCHAR(255), # property value
|
||||
PRIMARY KEY (sbid, nsid, prop_name)
|
||||
);
|
||||
|
||||
# Sidebox deployment table.
|
||||
CREATE TABLE sbox_deploy (
|
||||
uid INT NOT NULL, # user ID
|
||||
ctx_nsid INT NOT NULL, # namespace ID of the context
|
||||
ctx_name VARCHAR(128) BINARY NOT NULL, # name of the context
|
||||
param VARCHAR(255), # context parameter (property serialized)
|
||||
seq INT NOT NULL, # sequence counter
|
||||
sbid INT NOT NULL, # sidebox ID
|
||||
UNIQUE INDEX by_seq (uid, ctx_nsid, ctx_name, param, seq),
|
||||
UNIQUE INDEX by_sbid (uid, ctx_nsid, ctx_name, param, sbid)
|
||||
);
|
||||
|
||||
##############################################################################
|
||||
# Set table access rights
|
||||
##############################################################################
|
||||
|
@ -339,7 +380,9 @@ INSERT INTO namespaces (nsid, namespace) VALUES
|
|||
(13, 'http://www.silverwrist.com/NS/venice/2003/05/24/system.permissions' ),
|
||||
(14, 'http://www.silverwrist.com/NS/venice/2003/05/28/community.permissions'),
|
||||
(15, 'http://www.silverwrist.com/NS/venice/2003/05/29/community.profile' ),
|
||||
(16, 'http://www.silverwrist.com/NS/venice/2003/05/30/community.globals' );
|
||||
(16, 'http://www.silverwrist.com/NS/venice/2003/05/30/community.globals' ),
|
||||
(17, 'http://www.silverwrist.com/NS/venice/2003/05/31/sidebox.context.ids' ),
|
||||
(18, 'http://www.silverwrist.com/NS/venice/2003/05/31/test.sideboxes' );
|
||||
|
||||
# Initial global properties setup
|
||||
INSERT INTO globalprop (nsid, prop_name, prop_value) VALUES
|
||||
|
@ -1138,3 +1181,17 @@ INSERT INTO menuitems (menuid, sequence, itemtype, text, linktype, link) VALUES
|
|||
(4, 1, 'TEXT', 'Users', 'SERVLET', 'find_users.js.vs' ),
|
||||
(4, 2, 'TEXT', 'Categories', 'SERVLET', 'find_categories.js.vs' );
|
||||
UPDATE menuitems SET ifdef_var = 'use_categories' WHERE menuid = 4 AND sequence = 2;
|
||||
|
||||
# Create the sideboxes tables.
|
||||
INSERT INTO sbox_master (sbid, sb_nsid, sb_name, type_nsid, type_name, descr) VALUES
|
||||
(1, 18, 'test1', 18, 'test', 'Test Sidebox #1'),
|
||||
(2, 18, 'test2', 18, 'test', 'Test Sidebox #2');
|
||||
INSERT INTO sbox_context (sbid, ctx_nsid, ctx_name) VALUES
|
||||
(1, 17, 'top'),
|
||||
(2, 17, 'top');
|
||||
|
||||
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),
|
||||
(2, 17, 'top', NULL, 0, 1),
|
||||
(2, 17, 'top', NULL, 1, 2);
|
||||
|
|
|
@ -67,4 +67,7 @@ public interface VeniceNamespaces
|
|||
public static final String COMMUNITY_GLOBALS_NAMESPACE =
|
||||
"http://www.silverwrist.com/NS/venice/2003/05/30/community.globals";
|
||||
|
||||
public static final String SIDEBOX_CONTEXT_NAMESPACE =
|
||||
"http://www.silverwrist.com/NS/venice/2003/05/31/sidebox.context.ids";
|
||||
|
||||
} // end interface VeniceNamespaces
|
||||
|
|
|
@ -34,8 +34,112 @@ import com.silverwrist.venice.SearchMode;
|
|||
import com.silverwrist.venice.VeniceNamespaces;
|
||||
import com.silverwrist.venice.iface.*;
|
||||
|
||||
public class CommunityManager implements NamedObject, ComponentInitialize, ComponentShutdown, CommunityService
|
||||
public class CommunityManager
|
||||
implements NamedObject, ComponentInitialize, ComponentShutdown, CommunityService, CommunityProxyService
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal class implementing community proxies
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private class MyCommunityProxy extends CommunityProxy
|
||||
{
|
||||
/*====================================================================
|
||||
* Attributes
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
private VeniceCommunity m_real_community = null;
|
||||
|
||||
/*====================================================================
|
||||
* Constructors
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
MyCommunityProxy(int cid)
|
||||
{
|
||||
super(cid);
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*====================================================================
|
||||
* Abstract implementations from class CommunityProxy
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
protected synchronized VeniceCommunity getRealCommunity()
|
||||
{
|
||||
if (m_real_community==null)
|
||||
{ // need to retrieve the real community...
|
||||
try
|
||||
{ // get the real community...
|
||||
m_real_community = CommunityManager.this.getCommunity(m_id);
|
||||
|
||||
} // end try
|
||||
catch (DatabaseException e)
|
||||
{ // wrap it in a runtime exception type
|
||||
throw new ProxyException(e);
|
||||
|
||||
} // end catch
|
||||
|
||||
} // end if
|
||||
|
||||
return m_real_community;
|
||||
|
||||
} // end getRealCommunity
|
||||
|
||||
} // end class MyCommunityProxy
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal property serializer class
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private class CommunitySerializer implements PropertySerializer
|
||||
{
|
||||
/*====================================================================
|
||||
* Constructor
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
CommunitySerializer()
|
||||
{ // do nothing
|
||||
} // end constructor
|
||||
|
||||
/*====================================================================
|
||||
* Implementations from interface PropertySerializer
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
public String serializeProperty(Object value)
|
||||
{
|
||||
if (value instanceof VeniceCommunity)
|
||||
return "Community:" + String.valueOf(((VeniceCommunity)value).getCID());
|
||||
|
||||
return null;
|
||||
|
||||
} // end serializeProperty
|
||||
|
||||
public Object deserializeProperty(String value)
|
||||
{
|
||||
try
|
||||
{ // look for our known prefixes
|
||||
if (value.startsWith("Community:"))
|
||||
return getCommunityProxy(Integer.parseInt(value.substring(10)));
|
||||
|
||||
return null;
|
||||
|
||||
} // end try
|
||||
catch (NumberFormatException e)
|
||||
{ // number parse blew up...
|
||||
return null;
|
||||
|
||||
} // end catch
|
||||
|
||||
} // end deserializeProperty
|
||||
|
||||
} // end class CommunitySerializer
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
|
@ -58,6 +162,7 @@ public class CommunityManager implements NamedObject, ComponentInitialize, Compo
|
|||
private CategoryService m_cats; // category service object
|
||||
private ReferenceMap m_id_to_comm; // ReferenceMap of community IDs to communities
|
||||
private ReferenceMap m_alias_to_comm; // ReferenceMap of community aliases to communities
|
||||
private ComponentShutdown m_pszreg; // property serializer registration
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
|
@ -193,6 +298,11 @@ public class CommunityManager implements NamedObject, ComponentInitialize, Compo
|
|||
// Get the dynamic update poster.
|
||||
m_post = (PostDynamicUpdate)(services.queryService(PostDynamicUpdate.class));
|
||||
|
||||
// Register our property serializer to let Community objects be serialized.
|
||||
PropertySerializerRegistration psreg =
|
||||
(PropertySerializerRegistration)(services.queryService(PropertySerializerRegistration.class));
|
||||
m_pszreg = psreg.registerPropertySerializer(new CommunitySerializer());
|
||||
|
||||
} // end initialize
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
|
@ -202,8 +312,12 @@ public class CommunityManager implements NamedObject, ComponentInitialize, Compo
|
|||
|
||||
public void shutdown()
|
||||
{
|
||||
m_pszreg.shutdown();
|
||||
m_pszreg = null;
|
||||
m_id_to_comm.clear();
|
||||
m_alias_to_comm.clear();
|
||||
m_post = null;
|
||||
m_alook = null;
|
||||
m_cats = null;
|
||||
m_users = null;
|
||||
m_srm = null;
|
||||
|
@ -370,4 +484,21 @@ public class CommunityManager implements NamedObject, ComponentInitialize, Compo
|
|||
|
||||
} // end getNumCommunitiesInCategory
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface CommunityProxyService
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public synchronized VeniceCommunity getCommunityProxy(int cid)
|
||||
{
|
||||
Integer key = new Integer(cid);
|
||||
VeniceCommunity rc = (VeniceCommunity)(m_id_to_comm.get(key));
|
||||
if (rc!=null)
|
||||
m_alias_to_comm.put(rc.getAlias(),(CommunityImpl)rc);
|
||||
else
|
||||
rc = new MyCommunityProxy(cid);
|
||||
return rc;
|
||||
|
||||
} // end getCommunityProxy
|
||||
|
||||
} // end class CommunityManager
|
||||
|
|
|
@ -0,0 +1,313 @@
|
|||
/*
|
||||
* 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.community;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.security.acl.AclNotFoundException;
|
||||
import java.util.*;
|
||||
import com.silverwrist.dynamo.except.*;
|
||||
import com.silverwrist.dynamo.iface.*;
|
||||
import com.silverwrist.venice.CommunityVisibility;
|
||||
import com.silverwrist.venice.iface.*;
|
||||
|
||||
abstract class CommunityProxy implements VeniceCommunity, DynamicWrapper
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
protected int m_id;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
CommunityProxy(int cid)
|
||||
{
|
||||
m_id = cid;
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Abstract operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
protected abstract VeniceCommunity getRealCommunity();
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Overrides from class Object
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (o==null)
|
||||
return false;
|
||||
if (o instanceof VeniceCommunity)
|
||||
return (((VeniceCommunity)o).getCID()==m_id);
|
||||
return false;
|
||||
|
||||
} // end equals
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
return m_id;
|
||||
|
||||
} // end hashCode
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Community #" + m_id;
|
||||
|
||||
} // end toString
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface NamedObject
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the name of this community.
|
||||
*
|
||||
* @return The name of this community.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return getRealCommunity().getName();
|
||||
|
||||
} // end getName
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface ObjectProvider
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Retrieves an object from this <CODE>ObjectProvider</CODE>.
|
||||
*
|
||||
* @param namespace The namespace to interpret the name relative to.
|
||||
* @param name The name of the object to be retrieved.
|
||||
* @return The object reference specified.
|
||||
*/
|
||||
public Object getObject(String namespace, String name)
|
||||
{
|
||||
return getRealCommunity().getObject(namespace,name);
|
||||
|
||||
} // end getObject
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface SecureObjectStore
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public Object setObject(DynamoUser caller, String namespace, String name, Object value)
|
||||
throws DatabaseException, DynamoSecurityException
|
||||
{
|
||||
return getRealCommunity().setObject(caller,namespace,name,value);
|
||||
|
||||
} // end setObject
|
||||
|
||||
public Object removeObject(DynamoUser caller, String namespace, String name)
|
||||
throws DatabaseException, DynamoSecurityException
|
||||
{
|
||||
return getRealCommunity().removeObject(caller,namespace,name);
|
||||
|
||||
} // end removeObject
|
||||
|
||||
public Collection getNamespaces() throws DatabaseException
|
||||
{
|
||||
return getRealCommunity().getNamespaces();
|
||||
|
||||
} // end getNamespaces
|
||||
|
||||
public Collection getNamesForNamespace(String namespace) throws DatabaseException
|
||||
{
|
||||
return getRealCommunity().getNamesForNamespace(namespace);
|
||||
|
||||
} // end getNamesForNamespace
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface VeniceCommunity
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public int getCID()
|
||||
{
|
||||
return m_id;
|
||||
|
||||
} // end getCID
|
||||
|
||||
public int getMemberGID()
|
||||
{
|
||||
return getRealCommunity().getMemberGID();
|
||||
|
||||
} // end getMemberGID
|
||||
|
||||
public DynamoGroup getMemberGroup() throws DatabaseException
|
||||
{
|
||||
return getRealCommunity().getMemberGroup();
|
||||
|
||||
} // end getMemberGroup
|
||||
|
||||
public int getHostGID()
|
||||
{
|
||||
return getRealCommunity().getHostGID();
|
||||
|
||||
} // end getHostGID
|
||||
|
||||
public DynamoGroup getHostGroup() throws DatabaseException
|
||||
{
|
||||
return getRealCommunity().getHostGroup();
|
||||
|
||||
} // end getHostGroup
|
||||
|
||||
public int getHostUID()
|
||||
{
|
||||
return getRealCommunity().getHostUID();
|
||||
|
||||
} // end getHostUID
|
||||
|
||||
public DynamoUser getHostUser() throws DatabaseException
|
||||
{
|
||||
return getRealCommunity().getHostUser();
|
||||
|
||||
} // end getHostUser
|
||||
|
||||
public DynamoAcl getAcl() throws DatabaseException, AclNotFoundException
|
||||
{
|
||||
return getRealCommunity().getAcl();
|
||||
|
||||
} // end getAcl
|
||||
|
||||
public int getCategoryID()
|
||||
{
|
||||
return getRealCommunity().getCategoryID();
|
||||
|
||||
} // end getCategoryID
|
||||
|
||||
public VeniceCategory getCategory() throws DatabaseException
|
||||
{
|
||||
return getRealCommunity().getCategory();
|
||||
|
||||
} // end getCategory
|
||||
|
||||
public synchronized void setCategoryID(DynamoUser caller, int catid)
|
||||
throws DatabaseException, DynamoSecurityException
|
||||
{
|
||||
getRealCommunity().setCategoryID(caller,catid);
|
||||
|
||||
} // end setCategoryID
|
||||
|
||||
public void setCategory(DynamoUser caller, VeniceCategory cat) throws DatabaseException, DynamoSecurityException
|
||||
{
|
||||
this.setCategoryID(caller,cat.getCategoryID());
|
||||
|
||||
} // end setCategory
|
||||
|
||||
public CommunityVisibility getVisibility()
|
||||
{
|
||||
return getRealCommunity().getVisibility();
|
||||
|
||||
} // end getVisibility
|
||||
|
||||
public synchronized void setVisibility(DynamoUser caller, CommunityVisibility vis)
|
||||
throws DatabaseException, DynamoSecurityException
|
||||
{
|
||||
getRealCommunity().setVisibility(caller,vis);
|
||||
|
||||
} // end setVisibility
|
||||
|
||||
public synchronized void setName(DynamoUser caller, String name) throws DatabaseException, DynamoSecurityException
|
||||
{
|
||||
getRealCommunity().setName(caller,name);
|
||||
|
||||
} // end setName
|
||||
|
||||
public String getAlias()
|
||||
{
|
||||
return getRealCommunity().getAlias();
|
||||
|
||||
} // end getAlias
|
||||
|
||||
public synchronized void setAlias(DynamoUser caller, String alias) throws DatabaseException, DynamoSecurityException
|
||||
{
|
||||
getRealCommunity().setAlias(caller,alias);
|
||||
|
||||
} // end setAlias
|
||||
|
||||
public java.util.Date getCreationDate()
|
||||
{
|
||||
return getRealCommunity().getCreationDate();
|
||||
|
||||
} // end getCreationDate
|
||||
|
||||
public java.util.Date getLastAccessDate()
|
||||
{
|
||||
return getRealCommunity().getLastAccessDate();
|
||||
|
||||
} // end getLastAccessDate
|
||||
|
||||
public synchronized void setLastAccessDate(DynamoUser caller, java.util.Date date)
|
||||
throws DatabaseException, DynamoSecurityException
|
||||
{
|
||||
getRealCommunity().setLastAccessDate(caller,date);
|
||||
|
||||
} // end setLastAccessedDate
|
||||
|
||||
public java.util.Date getLastUpdateDate()
|
||||
{
|
||||
return getRealCommunity().getLastUpdateDate();
|
||||
|
||||
} // end getLastUpdateDate
|
||||
|
||||
public synchronized void setLastUpdateDate(DynamoUser caller, java.util.Date date)
|
||||
throws DatabaseException, DynamoSecurityException
|
||||
{
|
||||
getRealCommunity().setLastUpdateDate(caller,date);
|
||||
|
||||
} // end setLastUpdateDate
|
||||
|
||||
public void grantAccess(DynamoUser caller, Principal subject, String auth_namespace, String auth_name,
|
||||
String source_info, String auth_info, boolean single_use)
|
||||
throws AuthenticationException, DatabaseException, DynamoSecurityException
|
||||
{
|
||||
getRealCommunity().grantAccess(caller,subject,auth_namespace,auth_name,source_info,auth_info,single_use);
|
||||
|
||||
} // end grantAccess
|
||||
|
||||
public void revokeAccess(DynamoUser caller, Principal subject) throws DatabaseException, DynamoSecurityException
|
||||
{
|
||||
getRealCommunity().revokeAccess(caller,subject);
|
||||
|
||||
} // end revokeAccess
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface DynamicWrapper
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public Object unwrap()
|
||||
{
|
||||
return getRealCommunity();
|
||||
|
||||
} // end unwrap
|
||||
|
||||
} // end class CommunityProxy
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* 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.community;
|
||||
|
||||
import com.silverwrist.venice.iface.VeniceCommunity;
|
||||
|
||||
public interface CommunityProxyService
|
||||
{
|
||||
public VeniceCommunity getCommunityProxy(int cid);
|
||||
|
||||
} // end interface CommunityProxyService
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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.except;
|
||||
|
||||
import com.silverwrist.dynamo.except.ExternalException;
|
||||
|
||||
public class SideboxException extends ExternalException
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructors
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructs a new <CODE>SideboxException</CODE> instance.
|
||||
*
|
||||
* @param caller The classname of the class that's creating the exception. Its class loader
|
||||
* and package name will be used, together with <CODE>bundle</CODE>, to find the
|
||||
* resource bundle.
|
||||
* @param bundle The name of the resource bundle to be loaded.
|
||||
* @param message_id The identifier of the message to be loaded from the bundle.
|
||||
*/
|
||||
public SideboxException(Class caller, String bundle, String message_id)
|
||||
{
|
||||
super(caller,bundle,message_id);
|
||||
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Constructs a new <CODE>SideboxException</CODE> instance.
|
||||
*
|
||||
* @param caller The classname of the class that's creating the exception. Its class loader
|
||||
* and package name will be used, together with <CODE>bundle</CODE>, to find the
|
||||
* resource bundle.
|
||||
* @param bundle The name of the resource bundle to be loaded.
|
||||
* @param message_id The identifier of the message to be loaded from the bundle.
|
||||
* @param inner The exception to be nested inside this one.
|
||||
*/
|
||||
public SideboxException(Class caller, String bundle, String message_id, Throwable inner)
|
||||
{
|
||||
super(caller,bundle,message_id,inner);
|
||||
|
||||
} // end constructor
|
||||
|
||||
} // end class SideboxException
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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.iface;
|
||||
|
||||
import com.silverwrist.dynamo.except.DynamoException;
|
||||
import com.silverwrist.dynamo.iface.Request;
|
||||
|
||||
public interface SideboxFactory
|
||||
{
|
||||
public Sidebox createSidebox(Request req) throws DynamoException;
|
||||
|
||||
} // end interface SideboxFactory
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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.iface;
|
||||
|
||||
import com.silverwrist.dynamo.except.DynamoException;
|
||||
import com.silverwrist.dynamo.iface.ObjectProvider;
|
||||
|
||||
public interface SideboxTypeFactory
|
||||
{
|
||||
public SideboxFactory createFactory(String type_namespace, String type_name, String box_namespace, String box_name,
|
||||
ObjectProvider properties) throws DynamoException;
|
||||
|
||||
} // end interface SideboxTypeFactory
|
|
@ -24,6 +24,7 @@ import com.silverwrist.venice.app.AdvancedUserService;
|
|||
import com.silverwrist.venice.community.CategoryService;
|
||||
import com.silverwrist.venice.community.CommunityService;
|
||||
import com.silverwrist.venice.iface.*;
|
||||
import com.silverwrist.venice.sidebox.SideboxService;
|
||||
|
||||
public class LibraryVeniceCast
|
||||
{
|
||||
|
@ -125,6 +126,12 @@ public class LibraryVeniceCast
|
|||
|
||||
} // end queryRenderImage
|
||||
|
||||
public final SideboxService querySideboxService(Object obj)
|
||||
{
|
||||
return (SideboxService)query(obj,SideboxService.class);
|
||||
|
||||
} // end querySideboxService
|
||||
|
||||
public final UserDefaultPropertyNamespace queryUserDefaultPropertyNamespace(Object obj)
|
||||
{
|
||||
return (UserDefaultPropertyNamespace)query(obj,UserDefaultPropertyNamespace.class);
|
||||
|
|
|
@ -0,0 +1,360 @@
|
|||
/*
|
||||
* 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.sidebox;
|
||||
|
||||
import java.util.*;
|
||||
import org.apache.commons.collections.*;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.w3c.dom.*;
|
||||
import com.silverwrist.util.xml.*;
|
||||
import com.silverwrist.dynamo.db.NamespaceCache;
|
||||
import com.silverwrist.dynamo.except.*;
|
||||
import com.silverwrist.dynamo.iface.*;
|
||||
import com.silverwrist.dynamo.util.*;
|
||||
import com.silverwrist.venice.except.*;
|
||||
import com.silverwrist.venice.iface.*;
|
||||
import com.silverwrist.venice.session.SessionInfoParams;
|
||||
import com.silverwrist.venice.sidebox.test.TestSideboxes;
|
||||
|
||||
public class SideboxManager implements NamedObject, ComponentInitialize, ComponentShutdown, SideboxService
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal class implementing ObjectProvider to initialize SideboxFactory
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private class InitProps implements ObjectProvider
|
||||
{
|
||||
/*====================================================================
|
||||
* Attributes
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
private int m_sbid; // sidebox identifier
|
||||
private ReferenceMap m_properties; // property cache
|
||||
|
||||
/*====================================================================
|
||||
* Constructor
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
InitProps(int sbid)
|
||||
{
|
||||
m_sbid = sbid;
|
||||
m_properties = new ReferenceMap(ReferenceMap.HARD,ReferenceMap.SOFT);
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*====================================================================
|
||||
* Overrides from class Object
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "Sidebox Properties For Sidebox #" + m_sbid;
|
||||
|
||||
} // end toString
|
||||
|
||||
/*====================================================================
|
||||
* Implementations from interface ObjectProvider
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
public Object getObject(String namespace, String name)
|
||||
{
|
||||
try
|
||||
{ // convert the namespace name to an ID here
|
||||
PropertyKey key = new PropertyKey(m_ns_cache.namespaceNameToId(namespace),name);
|
||||
Object rc = null;
|
||||
synchronized (this)
|
||||
{ // start by looking in the properties map
|
||||
rc = m_properties.get(key);
|
||||
if (rc==null)
|
||||
{ // no use - need to try the database
|
||||
rc = m_ops.getSideboxProperty(m_sbid,key);
|
||||
if (rc!=null)
|
||||
{ // found in the database
|
||||
m_properties.put(key,rc);
|
||||
logger.debug("value found in database");
|
||||
|
||||
} // end if
|
||||
|
||||
} // end if
|
||||
else
|
||||
logger.debug("value found in cache");
|
||||
|
||||
} // end synchronized block
|
||||
|
||||
if (rc==null)
|
||||
{ // the object was not found
|
||||
logger.debug("value not found");
|
||||
throw new NoSuchObjectException(this.toString(),namespace,name);
|
||||
|
||||
} // end if
|
||||
|
||||
return rc;
|
||||
|
||||
} // end try
|
||||
catch (DatabaseException e)
|
||||
{ // translate into our NoSuchObjectException but retain the DatabaseException
|
||||
logger.debug("Database exception while doing find",e);
|
||||
throw new NoSuchObjectException(this.toString(),namespace,name,e);
|
||||
|
||||
} // end catch
|
||||
|
||||
} // end getObject
|
||||
|
||||
} // end class InitProps
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private static Logger logger = Logger.getLogger(SideboxManager.class);
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private String m_name; // this object's name
|
||||
private SideboxOps m_ops; // operations object
|
||||
private NamespaceCache m_ns_cache; // namespace cache object
|
||||
private Hashtable m_qnk_to_tf; // maps QualifiedNameKey to SideboxTypeFactory
|
||||
private Hashtable m_ns_to_tf; // maps namespace to SideboxTypeFactory
|
||||
private ReferenceMap m_pk_to_fact; // maps PropertyKey to SideboxFactory
|
||||
private ReferenceMap m_id_to_type; // maps sidebox IDs to types
|
||||
private ReferenceMap m_id_to_name; // maps sidebox IDs to names
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public SideboxManager()
|
||||
{
|
||||
m_qnk_to_tf = new Hashtable();
|
||||
m_ns_to_tf = new Hashtable();
|
||||
m_pk_to_fact = new ReferenceMap(ReferenceMap.HARD,ReferenceMap.SOFT);
|
||||
m_id_to_type = new ReferenceMap(ReferenceMap.HARD,ReferenceMap.SOFT);
|
||||
m_id_to_name = new ReferenceMap(ReferenceMap.HARD,ReferenceMap.SOFT);
|
||||
m_ns_to_tf.put(TestSideboxes.NAMESPACE,new TestSideboxes());
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface NamedObject
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return m_name;
|
||||
|
||||
} // end getName
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface ComponentInitialize
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initialize the component.
|
||||
*
|
||||
* @param config_root Pointer to the section of the Dynamo XML configuration file that configures this
|
||||
* particular component. This is to be considered "read-only" by the component.
|
||||
* @param services An implementation of {@link com.silverwrist.dynamo.iface.ServiceProvider ServiceProvider}
|
||||
* which provides initialization services to the component. This will include an implementation
|
||||
* of {@link com.silverwrist.dynamo.iface.ObjectProvider ObjectProvider} which may be used to
|
||||
* get information about other objects previously initialized by the application.
|
||||
* @exception com.silverwrist.dynamo.except.ConfigException If an error is encountered in the component
|
||||
* configuration.
|
||||
*/
|
||||
public void initialize(Element config_root, ServiceProvider services) throws ConfigException
|
||||
{
|
||||
logger.info("SideboxManager initializing");
|
||||
|
||||
XMLLoader loader = XMLLoader.get();
|
||||
String name_pool = null, name_nscache = null;
|
||||
try
|
||||
{ // verify the right node name
|
||||
loader.verifyNodeName(config_root,"object");
|
||||
|
||||
// get the object's name
|
||||
m_name = loader.getAttribute(config_root,"name");
|
||||
|
||||
// get the name of the database pool and namespace cache
|
||||
DOMElementHelper config_root_h = new DOMElementHelper(config_root);
|
||||
Element foo = loader.getSubElement(config_root_h,"database");
|
||||
name_pool = loader.getAttribute(foo,"connection");
|
||||
name_nscache = loader.getAttribute(foo,"namespaces");
|
||||
|
||||
} // end try
|
||||
catch (XMLLoadException e)
|
||||
{ // error loading XML config data
|
||||
logger.fatal("XML loader exception in CommunityManager",e);
|
||||
throw new ConfigException(e);
|
||||
|
||||
} // end catch
|
||||
|
||||
// Get the database connection pool.
|
||||
DBConnectionPool pool = GetObjectUtils.getDatabaseConnection(services,name_pool);
|
||||
|
||||
// Get the database operations object.
|
||||
m_ops = SideboxOps.get(pool);
|
||||
|
||||
// Get the namespace cache.
|
||||
m_ns_cache = (NamespaceCache)(GetObjectUtils.getDynamoComponent(services,NamespaceCache.class,name_nscache));
|
||||
|
||||
} // end initialize
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface ComponentShutdown
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
m_ns_cache = null;
|
||||
m_ops.dispose();
|
||||
m_ops = null;
|
||||
m_id_to_type.clear();
|
||||
m_id_to_name.clear();
|
||||
m_pk_to_fact.clear();
|
||||
m_qnk_to_tf.clear();
|
||||
m_ns_to_tf.clear();
|
||||
|
||||
} // end shutdown
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface SideboxService
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public List getSideboxes(Request req, String context_namespace, String context_name, Object context_param)
|
||||
throws DynamoException
|
||||
{
|
||||
// Start by getting the current user object.
|
||||
SessionInfoProvider sip = (SessionInfoProvider)(req.queryService(SessionInfoProvider.class));
|
||||
SessionInfo si = sip.getSessionInfo();
|
||||
DynamoUser user = (DynamoUser)(si.getObject(SessionInfoParams.NAMESPACE,SessionInfoParams.ATTR_USER));
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Retrieving sidebox list for user: " + user.getName());
|
||||
|
||||
// Get the IDs of all the sideboxes.
|
||||
int[] ids = m_ops.getSideboxIDList(user.getUID(),m_ns_cache.namespaceNameToId(context_namespace),context_name,
|
||||
context_param);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Returned " + ids.length + " sideboxes");
|
||||
if (ids.length==0)
|
||||
return Collections.EMPTY_LIST;
|
||||
|
||||
// Create the return list.
|
||||
ArrayList rc = new ArrayList(ids.length);
|
||||
for (int i=0; i<ids.length; i++)
|
||||
{ // get the key to use for mapping
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Creating sidebox #" + ids[i]);
|
||||
Integer key = new Integer(ids[i]);
|
||||
SideboxFactory fact = null;
|
||||
|
||||
synchronized (this)
|
||||
{ // Look up the sidebox identity.
|
||||
PropertyKey name_key = null;
|
||||
|
||||
// look up the type in our map first
|
||||
name_key = (PropertyKey)(m_id_to_name.get(key));
|
||||
if (name_key==null)
|
||||
{ // go down to the database and get it
|
||||
name_key = m_ops.getSideboxIdentity(ids[i]);
|
||||
m_id_to_name.put(key,name_key);
|
||||
|
||||
} // end if
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Sidebox name: " + name_key);
|
||||
|
||||
// Now try and look up the factory.
|
||||
fact = (SideboxFactory)(m_pk_to_fact.get(name_key));
|
||||
if (fact==null)
|
||||
{ // need to go create the factory
|
||||
PropertyKey type_key = null;
|
||||
|
||||
// look up the type in our map first
|
||||
type_key = (PropertyKey)(m_id_to_type.get(key));
|
||||
if (type_key==null)
|
||||
{ // go down to the database and get it
|
||||
type_key = m_ops.getSideboxType(ids[i]);
|
||||
m_id_to_type.put(key,type_key);
|
||||
|
||||
} // end if
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Sidebox type: " + type_key);
|
||||
|
||||
// Convert the type key to a QualifiedNameKey and look for a SideboxTypeFactory to use.
|
||||
QualifiedNameKey type_qn = new QualifiedNameKey(m_ns_cache.namespaceIdToName(type_key.getNamespaceID()),
|
||||
type_key.getName());
|
||||
SideboxTypeFactory typefact = (SideboxTypeFactory)(m_qnk_to_tf.get(type_qn));
|
||||
if (typefact==null)
|
||||
typefact = (SideboxTypeFactory)(m_ns_to_tf.get(type_qn.getNamespace()));
|
||||
if (typefact==null)
|
||||
{ // no type factory found for this sidebox type - throw an error
|
||||
SideboxException se = new SideboxException(SideboxManager.class,"SideboxMessages","no.sbtype");
|
||||
se.setParameter(0,type_qn.getNamespace());
|
||||
se.setParameter(1,type_qn.getName());
|
||||
throw se;
|
||||
|
||||
} // end if
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Type factory is of class: " + typefact.getClass().getName());
|
||||
|
||||
// Now create the sidebox factory.
|
||||
fact = typefact.createFactory(type_qn.getNamespace(),type_qn.getName(),
|
||||
m_ns_cache.namespaceIdToName(name_key.getNamespaceID()),name_key.getName(),
|
||||
new InitProps(ids[i]));
|
||||
m_pk_to_fact.put(name_key,fact);
|
||||
|
||||
} // end if (no factory there)
|
||||
|
||||
} // end synchronized block
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Factory is of class: " + fact.getClass().getName());
|
||||
|
||||
// Use the factory to create the sidebox.
|
||||
Sidebox sbox = fact.createSidebox(req);
|
||||
if (sbox!=null)
|
||||
rc.add(sbox);
|
||||
|
||||
} // end for
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Final sidebox list has " + rc.size() + " element(s)");
|
||||
|
||||
if (rc.isEmpty())
|
||||
return Collections.EMPTY_LIST;
|
||||
rc.trimToSize();
|
||||
return Collections.unmodifiableList(rc);
|
||||
|
||||
} // end getSideboxes
|
||||
|
||||
} // end class SideboxManager
|
|
@ -0,0 +1,21 @@
|
|||
# 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
|
||||
context.param.ser=Unable to serialize context parameter of class {0}.
|
||||
no.sidebox=Unable to find definition for sidebox with ID #{0}.
|
||||
property.deserialize=The value of property "{0}" could not be deserialized.
|
||||
no.sbtype=Unable to find sidebox type factory for type namespace {0}, name {1}.
|
|
@ -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.sidebox;
|
||||
|
||||
import com.silverwrist.dynamo.db.OpsBase;
|
||||
import com.silverwrist.dynamo.except.*;
|
||||
import com.silverwrist.dynamo.iface.*;
|
||||
import com.silverwrist.dynamo.util.*;
|
||||
|
||||
abstract class SideboxOps extends OpsBase
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
protected SideboxOps(DBConnectionPool pool)
|
||||
{
|
||||
super(pool);
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Abstract operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
abstract int[] getSideboxIDList(int uid, int context_nsid, String context_name, Object context_param)
|
||||
throws DatabaseException;
|
||||
|
||||
abstract PropertyKey getSideboxType(int sbid) throws DatabaseException;
|
||||
|
||||
abstract PropertyKey getSideboxIdentity(int sbid) throws DatabaseException;
|
||||
|
||||
abstract Object getSideboxProperty(int sbid, PropertyKey key) throws DatabaseException;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static SideboxOps get(DBConnectionPool pool) throws ConfigException
|
||||
{
|
||||
return (SideboxOps)get(pool,SideboxOps.class.getClassLoader(),SideboxOps.class.getName() + "_","SideboxOps");
|
||||
|
||||
} // end get
|
||||
|
||||
} // end class SideboxOps
|
|
@ -0,0 +1,304 @@
|
|||
/*
|
||||
* 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.sidebox;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.apache.log4j.Logger;
|
||||
import com.silverwrist.util.*;
|
||||
import com.silverwrist.dynamo.except.*;
|
||||
import com.silverwrist.dynamo.iface.*;
|
||||
import com.silverwrist.dynamo.util.*;
|
||||
|
||||
public class SideboxOps_mysql extends SideboxOps
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private static final Logger logger = Logger.getLogger(SideboxOps_mysql.class);
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private PropertySerializer m_psz; // reference to property serializer
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public SideboxOps_mysql(DBConnectionPool pool)
|
||||
{
|
||||
super(pool);
|
||||
m_psz = (PropertySerializer)(pool.queryService(PropertySerializer.class));
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private final String serializeContextParam(Object param) throws DatabaseException
|
||||
{
|
||||
if (param==null)
|
||||
return null;
|
||||
String s = m_psz.serializeProperty(param);
|
||||
if (s==null)
|
||||
{ // serialization exception - throw it
|
||||
DatabaseException de = new DatabaseException(SideboxOps_mysql.class,"SideboxMessages","context.param.ser");
|
||||
de.setParameter(0,param.getClass().getName());
|
||||
throw de;
|
||||
|
||||
} // end if
|
||||
|
||||
return s;
|
||||
|
||||
} // end serializeContextParam
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Overrides from class OpsBase
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
m_psz = null;
|
||||
super.dispose();
|
||||
|
||||
} // end dispose
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Abstract implementations from class SideboxOps
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int[] getSideboxIDList(int uid, int context_nsid, String context_name, Object context_param) throws DatabaseException
|
||||
{
|
||||
String context_param_ser = serializeContextParam(context_param);
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
LinkedList tmp_list = new LinkedList();
|
||||
int total = 0;
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Getting sidebox list for UID #" + uid);
|
||||
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// create and execute the statement
|
||||
if (context_param_ser==null)
|
||||
stmt = conn.prepareStatement("SELECT sbid FROM sbox_deploy WHERE uid = ? AND ctx_nsid = ? AND ctx_name = ? "
|
||||
+ "AND param IS NULL ORDER BY seq;");
|
||||
else
|
||||
{ // use the version with the parameter
|
||||
stmt = conn.prepareStatement("SELECT sbid FROM sbox_deploy WHERE uid = ? AND ctx_nsid = ? AND ctx_name = ? "
|
||||
+ "AND param = ? ORDER BY seq;");
|
||||
stmt.setString(4,context_param_ser);
|
||||
|
||||
} // end else
|
||||
|
||||
stmt.setInt(1,uid);
|
||||
stmt.setInt(2,context_nsid);
|
||||
stmt.setString(3,context_name);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
// build the temporary return arrays
|
||||
int curptr = 0;
|
||||
int[] cur = new int[16];
|
||||
while (rs.next())
|
||||
{ // add elements to the array
|
||||
if (curptr==16)
|
||||
{ // shift array to list
|
||||
tmp_list.addLast(cur);
|
||||
cur = new int[16];
|
||||
curptr = 0;
|
||||
|
||||
} // end if
|
||||
|
||||
cur[curptr++] = rs.getInt(1);
|
||||
total++;
|
||||
|
||||
} // end while
|
||||
|
||||
tmp_list.addLast(cur); // add the "tail" to the array
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("found: " + total + " sidebox IDs");
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
// Build the return array.
|
||||
int[] rc = new int[total];
|
||||
int outptr = 0;
|
||||
while (total>0)
|
||||
{ // copy array segments into the full return array
|
||||
int[] piece = (int[])(tmp_list.removeFirst());
|
||||
int ncopy = Math.min(total,16);
|
||||
System.arraycopy(piece,0,rc,outptr,ncopy);
|
||||
outptr += ncopy;
|
||||
total -= ncopy;
|
||||
|
||||
} // end while
|
||||
|
||||
tmp_list.clear();
|
||||
return rc;
|
||||
|
||||
} // end getSideboxIDList
|
||||
|
||||
PropertyKey getSideboxType(int sbid) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// create and execute the statement
|
||||
stmt = conn.prepareStatement("SELECT type_nsid, type_name FROM sbox_master WHERE sbid = ?;");
|
||||
stmt.setInt(1,sbid);
|
||||
rs = stmt.executeQuery();
|
||||
if (rs.next())
|
||||
return new PropertyKey(rs.getInt(1),rs.getString(2));
|
||||
|
||||
// throw an exception if we didn't find it
|
||||
DatabaseException de = new DatabaseException(SideboxOps_mysql.class,"SideboxMessages","no.sidebox");
|
||||
de.setParameter(0,String.valueOf(sbid));
|
||||
throw de;
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end getSideboxType
|
||||
|
||||
PropertyKey getSideboxIdentity(int sbid) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// create and execute the statement
|
||||
stmt = conn.prepareStatement("SELECT sb_nsid, sb_name FROM sbox_master WHERE sbid = ?;");
|
||||
stmt.setInt(1,sbid);
|
||||
rs = stmt.executeQuery();
|
||||
if (rs.next())
|
||||
return new PropertyKey(rs.getInt(1),rs.getString(2));
|
||||
|
||||
// throw an exception if we didn't find it
|
||||
DatabaseException de = new DatabaseException(SideboxOps_mysql.class,"SideboxMessages","no.sidebox");
|
||||
de.setParameter(0,String.valueOf(sbid));
|
||||
throw de;
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end getSideboxIdentity
|
||||
|
||||
Object getSideboxProperty(int sbid, PropertyKey key) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String rc_str = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// look up the property
|
||||
stmt = conn.prepareStatement("SELECT prop_value FROM sbox_props WHERE sbid = ? AND nsid = ? AND prop_name = ?;");
|
||||
stmt.setInt(1,sbid);
|
||||
stmt.setInt(2,key.getNamespaceID());
|
||||
stmt.setString(3,key.getName());
|
||||
rs = stmt.executeQuery();
|
||||
if (!(rs.next()))
|
||||
return null; // property not found
|
||||
|
||||
rc_str = rs.getString(1);
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
// Deserialize the property value.
|
||||
Object rc = m_psz.deserializeProperty(rc_str);
|
||||
if (rc!=null)
|
||||
return rc;
|
||||
|
||||
// deserialization exception - throw it
|
||||
DatabaseException de = new DatabaseException(SideboxOps_mysql.class,"SideboxMessages","property.deserialize");
|
||||
de.setParameter(0,key.getName());
|
||||
throw de;
|
||||
|
||||
} // end getSideboxProperty
|
||||
|
||||
} // end class SideboxOps_mysql
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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.sidebox;
|
||||
|
||||
import java.util.List;
|
||||
import com.silverwrist.dynamo.except.DynamoException;
|
||||
import com.silverwrist.dynamo.iface.Request;
|
||||
|
||||
public interface SideboxService
|
||||
{
|
||||
public List getSideboxes(Request req, String context_namespace, String context_name, Object context_param)
|
||||
throws DynamoException;
|
||||
|
||||
} // end interface SideboxService
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* 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.sidebox.test;
|
||||
|
||||
import com.silverwrist.dynamo.except.*;
|
||||
import com.silverwrist.dynamo.iface.*;
|
||||
import com.silverwrist.venice.content.*;
|
||||
import com.silverwrist.venice.iface.*;
|
||||
|
||||
public class TestSideboxes implements SideboxTypeFactory
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal class for sidebox factory
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private static class TestFactory implements SideboxFactory
|
||||
{
|
||||
/*====================================================================
|
||||
* Attributes
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
private String m_title;
|
||||
private String m_body;
|
||||
|
||||
/*====================================================================
|
||||
* Constructor
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
TestFactory(String title, String body)
|
||||
{
|
||||
m_title = title;
|
||||
m_body = body;
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*====================================================================
|
||||
* Implementations from interface SideboxFactory
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
public Sidebox createSidebox(Request req)
|
||||
{
|
||||
return new StringSidebox(m_body,m_title);
|
||||
|
||||
} // end createSidebox
|
||||
|
||||
} // end class TestFactory
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static final String NAMESPACE = "http://www.silverwrist.com/NS/venice/2003/05/31/test.sideboxes";
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public TestSideboxes()
|
||||
{ // do nothing
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface SideboxTypeFactory
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public SideboxFactory createFactory(String type_namespace, String type_name, String box_namespace, String box_name,
|
||||
ObjectProvider properties) throws DynamoException
|
||||
{
|
||||
if (box_name.equals("test1"))
|
||||
return new TestFactory("Number One","The quick brown fox jumped over the lazy dog.");
|
||||
else if (box_name.equals("test2"))
|
||||
return new TestFactory("List Test","<ul><li>First</li><li>Second</li><li>Third</li></ul>");
|
||||
else
|
||||
throw new DynamoException("invalid sidebox");
|
||||
|
||||
} // end createFactory
|
||||
|
||||
} // end class TestSideboxes
|
|
@ -21,6 +21,8 @@ importPackage(Packages.com.silverwrist.dynamo.util);
|
|||
importClass(Packages.com.silverwrist.venice.VeniceNamespaces);
|
||||
importPackage(Packages.com.silverwrist.venice.content);
|
||||
importPackage(Packages.com.silverwrist.venice.frame);
|
||||
importPackage(Packages.com.silverwrist.venice.iface);
|
||||
importPackage(Packages.com.silverwrist.venice.sidebox);
|
||||
|
||||
req = bsf.lookupBean("request");
|
||||
req_help = bsf.lookupBean("request_help");
|
||||
|
@ -52,15 +54,8 @@ page_content.add(lipsum);
|
|||
// END TEMPORARY STUFF
|
||||
|
||||
// Create the sidebox list.
|
||||
// BEGIN TEMPORARY STUFF
|
||||
|
||||
sidebox_list = new ArrayList();
|
||||
tmp = new StringSidebox("The quick brown fox jumped over the lazy dog.","Number One");
|
||||
sidebox_list.add(tmp);
|
||||
tmp = new StringSidebox("<ul><li>First</li><li>Second</li><li>Third</li></ul>","List Test");
|
||||
sidebox_list.add(tmp);
|
||||
|
||||
// END TEMPORARY STUFF
|
||||
sideboxes = vcast.querySideboxService(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"venice-sidebox"));
|
||||
sidebox_list = sideboxes.getSideboxes(req,VeniceNamespaces.SIDEBOX_CONTEXT_NAMESPACE,"top",null);
|
||||
|
||||
// Create the master view and return it.
|
||||
rc = new SideboxView(page_content,sidebox_list);
|
||||
|
|
Loading…
Reference in New Issue
Block a user