From f5a5009932559301323ed4267e29798216523c1d Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Thu, 22 Nov 2001 04:53:17 +0000 Subject: [PATCH] completed the transition away from features and toward "services" - the old database-based configuration has been replaced with the new XML-based one. This paves the way for further modularization of the code. --- etc/services-config.xml | 2 +- setup/database.sql | 49 +--- .../venice/core/CommunityContext.java | 13 +- ...ommunityFeature.java => ServiceGroup.java} | 14 +- .../silverwrist/venice/core/ServiceToken.java | 110 ++++++++ .../silverwrist/venice/core/VeniceEngine.java | 6 +- .../venice/core/impl/CommunityCoreData.java | 211 ++++++++------- .../core/impl/CommunityUserContextImpl.java | 125 ++++----- .../core/impl/ServiceControlManager.java | 214 ++++++++++++++-- .../venice/core/impl/StaticCommService.java | 59 +++-- .../venice/core/impl/VeniceEngineImpl.java | 240 +----------------- .../venice/core/internals/CommunityData.java | 17 +- .../venice/core/internals/EngineBackend.java | 14 - .../venice/core/internals/EnvCommunity.java | 6 + .../venice/core/internals/EnvConference.java | 7 + .../venice/core/internals/EnvEngine.java | 12 +- .../venice/core/internals/EnvUser.java | 46 +++- .../venice/servlets/CommunityFrontEnd.java | 14 +- .../venice/servlets/RedirectResult.java | 17 ++ .../venice/servlets/format/RenderConfig.java | 6 + .../venice/servlets/format/RenderData.java | 7 + .../servlets/format/ViewCommunityMembers.java | 9 + .../format/menus/CommunityLeftMenuEntry.java | 7 + .../menus/CommunityLeftMenuFactory.java | 48 +++- .../servlets/format/menus/LinkItem.java | 19 ++ .../silverwrist/venice/svc/CommService.java | 12 +- src/com/silverwrist/venice/svc/Service.java | 32 +++ .../venice/svc/ServiceControl.java | 38 +++ web/format/view_member.jsp | 3 +- 29 files changed, 813 insertions(+), 544 deletions(-) rename src/com/silverwrist/venice/core/{CommunityFeature.java => ServiceGroup.java} (77%) create mode 100644 src/com/silverwrist/venice/core/ServiceToken.java create mode 100644 src/com/silverwrist/venice/svc/Service.java create mode 100644 src/com/silverwrist/venice/svc/ServiceControl.java diff --git a/etc/services-config.xml b/etc/services-config.xml index d64b7f8..8d5b834 100644 --- a/etc/services-config.xml +++ b/etc/services-config.xml @@ -53,7 +53,7 @@ - + Members diff --git a/setup/database.sql b/setup/database.sql index 6f9c306..a84bae8 100644 --- a/setup/database.sql +++ b/setup/database.sql @@ -198,22 +198,6 @@ CREATE TABLE refcategory ( UNIQUE INDEX display (parent, name) ); -# A reference to feature codes and what they mean. -CREATE TABLE refsigftr ( - ftr_code SMALLINT NOT NULL PRIMARY KEY, - is_default TINYINT DEFAULT 0, - is_locked TINYINT DEFAULT 0, - is_hidden TINYINT DEFAULT 0, - require_read TINYINT DEFAULT 1, - sequence SMALLINT NOT NULL, - min_level SMALLINT UNSIGNED DEFAULT 0, - symbol CHAR(4) NOT NULL, - name VARCHAR(64) NOT NULL, - applet VARCHAR(64) NOT NULL, - UNIQUE INDEX name_x (name), - UNIQUE index sequence_x (sequence) -); - # The table mapping SIGs and their associated features. CREATE TABLE sigftrs ( sigid INT NOT NULL, @@ -472,18 +456,18 @@ INSERT INTO refaudit (type, descr) VALUES (111, 'Admin Change User Account'), (112, 'Admin Set Account Security'), (113, 'Admin Lock/Unlock Account'), - (201, 'Create New SIG'), - (202, 'Set SIG Membership'), - (203, 'Set SIG Contact Info'), - (204, 'Set SIG Feature Set'), - (205, 'Set SIG Name'), - (206, 'Set SIG Alias'), - (207, 'Set SIG Category'), - (208, 'Set SIG Hiding Information'), - (209, 'Set SIG Members-Only Flag'), - (210, 'Set SIG Join Key'), - (211, 'Set SIG Security Levels'), - (212, 'Delete SIG'), + (201, 'Create New Community'), + (202, 'Set Community Membership'), + (203, 'Set Community Contact Info'), + (204, 'Set Community Services'), + (205, 'Set Community Name'), + (206, 'Set Community Alias'), + (207, 'Set Community Category'), + (208, 'Set Community Hiding Information'), + (209, 'Set Community Members-Only Flag'), + (210, 'Set Community Join Key'), + (211, 'Set Community Security Levels'), + (212, 'Delete Community'), (301, 'Create New Conference'), (302, 'Set Conference Security Levels'), (303, 'Set Conference Name'), @@ -874,15 +858,6 @@ INSERT INTO refcategory (catid, parent, symlink, name) VALUES # Make sure the special "System" category is hidden. UPDATE refcategory SET hide_dir = 1, hide_search = 1 WHERE catid = 15; -# Populate the Features reference table. -INSERT INTO refsigftr (ftr_code, is_default, is_locked, is_hidden, require_read, sequence, min_level, - symbol, name, applet) VALUES - (0, 1, 1, 1, 0, 4900, 0, 'PROF', 'Profile', 'sigprofile'), - (1, 1, 1, 1, 0, 5000, 57000, 'ADMN', 'Administration', 'sigadmin'), - (2, 0, 1, 1, 0, 10000, 63000, 'SYSA', 'System Administration', 'sysadmin'), - (3, 1, 0, 0, 1, 500, 0, 'CONF', 'Conferences', 'confops'), - (4, 1, 1, 0, 1, 4800, 0, 'MEMB', 'Members', 'members'); - # Create the initial advertisements (quotes). INSERT INTO adverts (imagepath) VALUES ('images/ads/Brown.gif'), diff --git a/src/com/silverwrist/venice/core/CommunityContext.java b/src/com/silverwrist/venice/core/CommunityContext.java index 09bc585..2e5daec 100644 --- a/src/com/silverwrist/venice/core/CommunityContext.java +++ b/src/com/silverwrist/venice/core/CommunityContext.java @@ -20,6 +20,7 @@ package com.silverwrist.venice.core; import java.util.BitSet; import java.util.Date; import java.util.List; +import java.util.Set; import com.silverwrist.venice.except.AccessError; import com.silverwrist.venice.except.DataException; import com.silverwrist.venice.except.EmailException; @@ -68,13 +69,11 @@ public interface CommunityContext extends SearchMode public abstract void putContactInfo(ContactInfo ci) throws DataException, AccessError; - public abstract BitSet getFeatures(); + public abstract Set getServices(); - public abstract void setFeatures(BitSet feature_set, BitSet mask) throws DataException, AccessError; + public abstract Set getConfiguredServices(); - public abstract List getCommunityFeaturesList(); - - public abstract String getDefaultApplet(); + public abstract void setServiceEnable(ServiceToken token, boolean enable) throws AccessError, DataException; public abstract void setName(String name) throws DataException, AccessError; @@ -98,9 +97,9 @@ public interface CommunityContext extends SearchMode public abstract void setMembersOnly(boolean flag) throws DataException, AccessError; - public abstract short getInitialFeatureIndex(); + public abstract ServiceToken getDefaultService(); - public abstract void setInitialFeatureIndex(short ndx) throws DataException, AccessError; + public abstract void setDefaultService(ServiceToken token) throws AccessError, DataException; public abstract String getJoinKey() throws DataException, AccessError; diff --git a/src/com/silverwrist/venice/core/CommunityFeature.java b/src/com/silverwrist/venice/core/ServiceGroup.java similarity index 77% rename from src/com/silverwrist/venice/core/CommunityFeature.java rename to src/com/silverwrist/venice/core/ServiceGroup.java index 392a8f7..d10ba04 100644 --- a/src/com/silverwrist/venice/core/CommunityFeature.java +++ b/src/com/silverwrist/venice/core/ServiceGroup.java @@ -17,16 +17,14 @@ */ package com.silverwrist.venice.core; -public interface CommunityFeature +public interface ServiceGroup { - public abstract int getFeatureCode(); + public static final int SVCGRP_GLOBAL = 0; - public abstract String getSymbol(); + public static final int SVCGRP_COMMUNITY = 1; - public abstract String getName(); + public static final int SVCGRP_USER = 2; - public abstract String getApplet(); + public static final int NUM_SVCGRPS = 3; - public abstract int getSequence(); - -} // end interface CommunityFeature +} // end interface ServiceGroup diff --git a/src/com/silverwrist/venice/core/ServiceToken.java b/src/com/silverwrist/venice/core/ServiceToken.java new file mode 100644 index 0000000..d386f8a --- /dev/null +++ b/src/com/silverwrist/venice/core/ServiceToken.java @@ -0,0 +1,110 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.core; + +public class ServiceToken implements Comparable, ServiceGroup +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private int group; + private String symbol; + private int index; + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + protected ServiceToken(int group, String symbol, int index) + { + this.group = group; + this.symbol = symbol; + this.index = index; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Overrides from class Object + *-------------------------------------------------------------------------------- + */ + + public boolean equals(Object o) + { + if ((o==null) || !(o instanceof ServiceToken)) + return false; + ServiceToken other = (ServiceToken)o; + return ((this.group==other.group) && (this.symbol.equals(other.symbol))); + + } // end equals + + public int hashCode() + { + return (group << 24) ^ symbol.hashCode(); + + } // end hashCode + + public String toString() + { + return symbol; + + } // end toString + + /*-------------------------------------------------------------------------------- + * Implementations from interface Comparable + *-------------------------------------------------------------------------------- + */ + + public int compareTo(Object o) + { + if (o==null) + throw new NullPointerException("compareTo null object!"); + ServiceToken other = (ServiceToken)o; // may throw ClassCastException + int rc = this.group - other.group; + if (rc!=0) + return rc; + return this.symbol.compareTo(other.symbol); + + } // end compareTo + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public final int getGroup() + { + return group; + + } // end getGroup + + public final String getSymbol() + { + return symbol; + + } // end getSymbol + + public final int getIndex() + { + return index; + + } // end getIndex + +} // end class ServiceToken diff --git a/src/com/silverwrist/venice/core/VeniceEngine.java b/src/com/silverwrist/venice/core/VeniceEngine.java index b5d8e82..341026b 100644 --- a/src/com/silverwrist/venice/core/VeniceEngine.java +++ b/src/com/silverwrist/venice/core/VeniceEngine.java @@ -27,16 +27,12 @@ import com.silverwrist.venice.except.DataException; import com.silverwrist.venice.except.EmailException; import com.silverwrist.venice.htmlcheck.HTMLChecker; -public interface VeniceEngine extends SearchMode +public interface VeniceEngine extends SearchMode, ServiceGroup { public abstract void initialize(Document config, String app_root) throws ConfigException, DataException; public abstract void shutdown() throws ConfigException; - public abstract int getNumFeatures(); - - public abstract BitSet getAllFeaturesMask(); - public abstract UserContext createUserContext(String remote_addr) throws DataException; public abstract String getEmailAddressForUser(String username) throws DataException, AccessError; diff --git a/src/com/silverwrist/venice/core/impl/CommunityCoreData.java b/src/com/silverwrist/venice/core/impl/CommunityCoreData.java index 423cc3e..9ee39a0 100644 --- a/src/com/silverwrist/venice/core/impl/CommunityCoreData.java +++ b/src/com/silverwrist/venice/core/impl/CommunityCoreData.java @@ -28,6 +28,7 @@ import com.silverwrist.venice.core.*; import com.silverwrist.venice.core.internals.*; import com.silverwrist.venice.except.*; import com.silverwrist.venice.security.AuditRecord; +import com.silverwrist.venice.svc.*; class CommunityCoreData implements CommunityData, CommunityDataBackend { @@ -94,17 +95,17 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend private boolean hidden_search; // hidden from keyword searches? private boolean members_only; // only members allowed in this community? private boolean is_admin; // is this the administrative community? - private short initial_feature; // the "initial" feature to display for this community private String name; // the name of this community private String language; // the default language code private String synopsis; // the synopsis of the community private String rules; // the community "rules" private String alias; // the community alias value private boolean public_comm; // is this a public community? - private BitSet features; // set of available features private ObjectCache conf_objcache = new ObjectCache(new ConferenceCommunityContextImplCreator()); private boolean deleted = false; // has this community been deleted? private OptionSet flags; // property flags + private HashSet services; // services for this community + private ServiceToken initial_service; // the initial service /*-------------------------------------------------------------------------------- * Constructor @@ -152,13 +153,18 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end while - // get the community feature set + // get the set of community services + services = new HashSet(); sql.setLength(0); sql.append("SELECT ftr_code FROM sigftrs WHERE sigid = ").append(cid).append(';'); rs = stmt.executeQuery(sql.toString()); - features = new BitSet(); while (rs.next()) - features.set(rs.getInt("ftr_code")); + { // get the service tokens and return them + ServiceToken token = env.getSCM().getTokenForIndex(ServiceControl.SVCGRP_COMMUNITY,rs.getInt(1)); + if (token!=null) + services.add(token); + + } // end while } // end try catch (SQLException e) @@ -178,7 +184,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend protected CommunityCoreData(EnvEngine env, int cid, java.util.Date creation, String name, String alias, int host_uid, String language, String synopsis, String rules, String joinkey, boolean hide_dir, boolean hide_search, - BitSet features) + int[] levels, Set services) { if (logger.isDebugEnabled()) logger.debug("new CommunityCoreData for BRAND NEW COMMUNITY " + cid); @@ -188,11 +194,11 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend this.created = creation; this.last_access = creation; this.last_update = creation; - this.read_level = new_env.getDefaultRole("Community.Read").getLevel(); - this.write_level = new_env.getDefaultRole("Community.Write").getLevel(); - this.create_level = new_env.getDefaultRole("Community.Create").getLevel(); - this.delete_level = new_env.getDefaultRole("Community.Delete").getLevel(); - this.join_level = new_env.getDefaultRole("Community.Join").getLevel(); + this.read_level = levels[0]; + this.write_level = levels[1]; + this.create_level = levels[2]; + this.delete_level = levels[3]; + this.join_level = levels[4]; this.contactid = -1; this.host_uid = host_uid; this.category_id = 0; @@ -200,15 +206,15 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend this.hidden_search = hide_search; this.members_only = true; this.is_admin = false; - this.initial_feature = 0; this.name = name; this.language = language; this.synopsis = synopsis; this.rules = rules; this.alias = alias; this.public_comm = StringUtil.isStringEmpty(joinkey); - this.features = (BitSet)(features.clone()); this.flags = new OptionSet(); + this.services = new HashSet(services); + this.initial_service = env.getSCM().getTokenForIndex(ServiceControl.SVCGRP_COMMUNITY,0); if (env.getEngine().getParamBoolean(EngineBackend.BP_POSTPICTURES)) flags.set(BP_POSTPICTURES); @@ -237,7 +243,6 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend hidden_search = rs.getBoolean("hide_search"); members_only = rs.getBoolean("membersonly"); is_admin = rs.getBoolean("is_admin"); - initial_feature = rs.getShort("init_ftr"); name = rs.getString("signame"); language = rs.getString("language"); synopsis = rs.getString("synopsis"); @@ -251,6 +256,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend else // Admin is NEVER a public community! public_comm = false; alias = rs.getString("alias"); + initial_service = env.getSCM().getTokenForIndex(ServiceControl.SVCGRP_COMMUNITY,rs.getShort("init_ftr")); if (logger.isDebugEnabled()) logger.debug("Loaded data for community \"" + name + "\" (ID " + cid + ", alias '" + alias @@ -578,17 +584,53 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end putContactInfo - public BitSet getFeatureSet() + public Set getServices() { - return (BitSet)(features.clone()); + return Collections.unmodifiableSet((Set)(services.clone())); - } // end getFeatureSet + } // end getServices - public synchronized void putFeatureSet(EnvCommunity outer, BitSet set) throws DataException + public Set getServices(EnvCommunity outer) + { + HashSet tmp = new HashSet(); + Iterator it = services.iterator(); + while (it.hasNext()) + { // get the service associated with the token + ServiceToken token = (ServiceToken)(it.next()); + CommService svc = (CommService)(env.getSCM().getServiceForToken(token)); + + // Check the permission first. + String perm = svc.getPermission(); + if (perm!=null) + { // test the permission against the outer environment + if (!(outer.testPermission(perm))) + continue; // permission failed - just go on to the next one + + } // end if + + if (outer.satisfy(svc.getRole())) + tmp.add(token); + + } // end getServices + + if (tmp.isEmpty()) + return Collections.EMPTY_SET; + else + return Collections.unmodifiableSet(tmp); + + } // end getServices + + public synchronized void setServiceEnable(EnvCommunity outer, ServiceToken token, boolean enable) + throws DataException { if (deleted) throw new DataException("This community has been deleted."); + if (enable && services.contains(token)) + return; + if (!enable && !(services.contains(token))) + return; + Connection conn = null; // database connection AuditRecord ar = null; // audit record @@ -599,35 +641,26 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend stmt.executeUpdate("LOCK TABLES sigftrs WRITE;"); try - { // first, delete all the old entries - StringBuffer sql = new StringBuffer("DELETE FROM sigftrs WHERE sigid = "); - sql.append(cid).append(';'); - stmt.executeUpdate(sql.toString()); - - // now, add all the new entries - sql.setLength(0); - for (int i=0; i0) - { // add the features to the database - sql.append(';'); - stmt.executeUpdate(sql.toString()); + { // execute the right statement + StringBuffer sql; + if (enable) + { // create an INSERT statement + sql = new StringBuffer("INSERT INTO sigftrs (sigid, ftr_code) VALUES ("); + sql.append(cid).append(", ").append(token.getIndex()).append(");"); } // end if + else + { // create a DELETE statement + sql = new StringBuffer("DELETE FROM sigftrs WHERE sigid = "); + sql.append(cid).append(" AND ftr_code = ").append(token.getIndex()).append(';'); - features = set; + } // end else + + stmt.executeUpdate(sql.toString()); + if (enable) + services.add(token); + else + services.remove(token); } // end try finally @@ -665,21 +698,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end finally - } // end putFeatureSet - - public List getCommunityFeaturesList(int level) - { - return env.getEngine().getCommunityFeatureSet(features,level,canReadCommunitySubObjects(level)); - - } // end getCommunityFeaturesList - - public String getDefaultApplet() - { - StringBuffer buf = new StringBuffer(env.getEngine().getAppletForFeature(initial_feature)); - buf.append("?sig=").append(cid); - return buf.toString(); - - } // end getDefaultApplet + } // end setServiceEnable public synchronized void setName(EnvCommunity outer, String name) throws DataException { @@ -1076,13 +1095,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end setMembersOnly - public short getInitialFeatureIndex() + public ServiceToken getDefaultService() { - return initial_feature; + return initial_service; - } // end getInitialFeatureIndex + } // end getDefaultService - public synchronized void setInitialFeatureIndex(short ndx) throws DataException + public synchronized void setDefaultService(ServiceToken token) throws DataException { if (deleted) throw new DataException("This community has been deleted."); @@ -1094,11 +1113,11 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend conn = env.getConnection(); Statement stmt = conn.createStatement(); StringBuffer sql = new StringBuffer("UPDATE sigs SET init_ftr = "); - sql.append(ndx).append(", lastupdate = '"); + sql.append(token.getIndex()).append(", lastupdate = '"); java.util.Date now = new java.util.Date(); sql.append(SQLUtil.encodeDate(now)).append("' WHERE sigid = ").append(cid).append(';'); stmt.executeUpdate(sql.toString()); - initial_feature = ndx; + initial_service = token; last_update = now; } // end try @@ -1114,7 +1133,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end finally - } // end setInitialFeatureIndex + } // end setDefaultService public String getJoinKey() throws DataException { @@ -1435,17 +1454,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end getMemberCount - public boolean isFeaturePresent(String symbol) + public boolean hasService(ServiceToken token) { if (deleted) return false; - int ndx = env.getEngine().getFeatureIndexBySymbol(symbol); - if (ndx>=0) - return features.get(ndx); - else - return false; + return services.contains(token); - } // end isFeaturePresent + } // end hasService public synchronized ConferenceCommunityContext getConferenceDataObject(int confid) throws DataException { @@ -1954,12 +1969,11 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend boolean hide_search) throws DataException, AccessError { Connection conn = null; // database connection - BitSet def_features = env.getEngine().getDefaultFeaturesMask(); int new_cid; // ID of the new community java.util.Date creation; // creation date! AuditRecord ar = null; // the audit record CommunityCoreData comm; // the new community that gets returned - + try { // get a database connection and create the appropriate SELECT statement conn = env.getConnection(); @@ -1981,14 +1995,15 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend + "rules, joinkey, alias) VALUES ('"); creation = new java.util.Date(); String creation_str = SQLUtil.encodeDate(creation); - int level_read = env.getCommunityDefaultRole("Community.Read").getLevel(); - int level_write = env.getCommunityDefaultRole("Community.Write").getLevel(); - int level_create = env.getCommunityDefaultRole("Community.Create").getLevel(); - int level_delete = env.getCommunityDefaultRole("Community.Delete").getLevel(); - int level_join = env.getCommunityDefaultRole("Community.Join").getLevel(); + int[] levels = new int[5]; + levels[0] = env.getCommunityDefaultRole("Community.Read").getLevel(); + levels[1] = env.getCommunityDefaultRole("Community.Write").getLevel(); + levels[2] = env.getCommunityDefaultRole("Community.Create").getLevel(); + levels[3] = env.getCommunityDefaultRole("Community.Delete").getLevel(); + levels[4] = env.getCommunityDefaultRole("Community.Join").getLevel(); sql.append(creation).append("', '").append(creation).append("', '").append(creation).append("', "); - sql.append(level_read).append(", ").append(level_write).append(", ").append(level_create).append(", "); - sql.append(level_delete).append(", ").append(level_join).append(", ").append(host_uid).append(", "); + sql.append(levels[0]).append(", ").append(levels[1]).append(", ").append(levels[2]).append(", "); + sql.append(levels[3]).append(", ").append(levels[4]).append(", ").append(host_uid).append(", "); sql.append(hide_dir ? '1' : '0').append(", ").append(hide_search ? '1' : '0').append(", "); sql.append(SQLUtil.encodeStringArg(name)).append(", ").append(SQLUtil.encodeStringArg(language)); sql.append(", ").append(SQLUtil.encodeStringArg(synopsis)).append(", "); @@ -2011,22 +2026,22 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend } // end else - if (def_features.length()>0) - { // need to build the community's defined feature set + // Assign the new community the default services for new communities. + Set default_service = env.getSCM().getDefaultServices(ServiceControl.SVCGRP_COMMUNITY); + if (default_service.size()>0) + { // build the communty's defined service set sql.setLength(0); - for (int i=0; i0) - comm_symbol_to_service = Collections.unmodifiableMap(tmp_symbol_to_service); + symbol_to_service[SVCGRP_COMMUNITY] = Collections.unmodifiableMap(tmp_symbol_to_service); else - comm_symbol_to_service = Collections.EMPTY_MAP; + symbol_to_service[SVCGRP_COMMUNITY] = Collections.EMPTY_MAP; if (tmp_index_to_service.size()>0) - comm_index_to_service = Collections.unmodifiableMap(tmp_index_to_service); + index_to_service[SVCGRP_COMMUNITY] = Collections.unmodifiableMap(tmp_index_to_service); else - comm_index_to_service = Collections.EMPTY_MAP; + index_to_service[SVCGRP_COMMUNITY] = Collections.EMPTY_MAP; } // end if else { // no community services - undo this - comm_symbol_to_service = Collections.EMPTY_MAP; - comm_index_to_service = Collections.EMPTY_MAP; + symbol_to_service[SVCGRP_COMMUNITY] = Collections.EMPTY_MAP; + index_to_service[SVCGRP_COMMUNITY] = Collections.EMPTY_MAP; } // end else + symbol_to_service[SVCGRP_USER] = Collections.EMPTY_MAP; + index_to_service[SVCGRP_USER] = Collections.EMPTY_MAP; + + for (i=0; i=NUM_SVCGRPS)) + throw new IndexOutOfBoundsException("group index not valid"); + synchronized (this) + { // extract the reference + Set rc = null; + if (list_all_cache[group]!=null) + rc = (Set)(list_all_cache[group].get()); + if (rc==null) + { // need to regenerate the set + rc = listServices(group,new ServicePredicate(){ + public final boolean test(Service svc) { return true; } + }); + + // cache the result + list_all_cache[group] = new SoftReference(rc); + + } // end if + + return rc; + + } // end synchronized block + + } // end getAllServices + + public Set getDefaultServices(int group) + { + if ((group<0) || (group>=NUM_SVCGRPS)) + throw new IndexOutOfBoundsException("group index not valid"); + synchronized (this) + { // extract the reference + Set rc = null; + if (list_default_cache[group]!=null) + rc = (Set)(list_default_cache[group].get()); + if (rc==null) + { // need to regenerate the set + rc = listServices(group,new ServicePredicate(){ + public final boolean test(Service svc) { return svc.isDefault(); } + }); + + // cache the result + list_default_cache[group] = new SoftReference(rc); + + } // end if + + return rc; + + } // end synchronized block + + } // end getDefaultServices + + public Service getServiceForSymbol(int group, String sym) + { + if ((group<0) || (group>=NUM_SVCGRPS)) + throw new IndexOutOfBoundsException("group index not valid"); + return (Service)(symbol_to_service[group].get(sym)); + + } // end getServiceForSymbol + + public Service getServiceForToken(ServiceToken token) + { + return this.getServiceForSymbol(token.getGroup(),token.getSymbol()); + + } // end getServiceForToken + + public ServiceToken getTokenForIndex(int group, int ndx) + { + if ((group<0) || (group>=NUM_SVCGRPS)) + throw new IndexOutOfBoundsException("group index not valid"); + Service svc = (Service)(index_to_service[group].get(new Integer(ndx))); + return ((svc==null) ? null : svc.getToken()); + + } // end getTokenForIndex + + public ServiceToken getTokenForSymbol(int group, String sym) + { + Service svc = this.getServiceForSymbol(group,sym); + return ((svc==null) ? null : svc.getToken()); + + } // end getTokenForSymbol + /*-------------------------------------------------------------------------------- * External operations *-------------------------------------------------------------------------------- */ - public final void shutdown() + public final synchronized void shutdown() { - Iterator it = comm_symbol_to_service.values().iterator(); - while (it.hasNext()) - { // shut down each service in turn - CommService svc = (CommService)(it.next()); - svc.shutdown(); + for (int i=0; imax_value) - max_value = ndx; - - } // end while - - // store the real feature table as an array - features = new VeniceFeatureDef[++max_value]; - System.arraycopy(tmp_array,0,features,0,max_value); - if (logger.isDebugEnabled()) - logger.debug(max_value + " features loaded from database"); // load the global defaults loadDefaults(stmt); @@ -823,9 +707,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend } // end finally - for (i=0; i=features.length)) - { // the index is out of bounds! - logger.error("getAppletForFeature(" + code + ") => out of range"); - throw new IndexOutOfBoundsException("invalid feature code"); - - } // end if - - String rc = features[code].getApplet(); - if (logger.isDebugEnabled()) - logger.debug("getAppletForFeature(" + code + ") => \"" + rc + "\""); - return rc; - - } // end getAppletForFeature - - public boolean isValidInitialFeatureIndex(short ndx) - { - if ((ndx<0) || (ndx>=features.length)) - return false; - return features[ndx].isVisible(); - - } // end isValidInitialFeatureIndex - - public BitSet getDefaultFeaturesMask() - { - checkInitialized(); - BitSet rc = new BitSet(); - for (int i=0; i1) Collections.sort(tmp_entries); tmp_entries.trimToSize(); entries = Collections.unmodifiableList(tmp_entries); + map_symbol = Collections.unmodifiableMap(tmp_map); } // end else } // end if - else // no communty services - initialize to null + else + { // no communty services - initialize to null entries = Collections.EMPTY_LIST; + map_symbol = Collections.EMPTY_MAP; + + } // end else } // end constructor @@ -78,19 +91,15 @@ public class CommunityLeftMenuFactory public CommunityLeftMenu createMenu(CommunityContext comm) { - // N.B. This implementation will change once the engine uses the SCM to return the defined - // community services. - List items; if (entries.size()>0) - { // Get the community features list and stash the indexes in a set. + { // Get the community services and stash the symbols in a set. HashSet defined = new HashSet(); - List ftr_list = comm.getCommunityFeaturesList(); - Iterator it = ftr_list.iterator(); + Iterator it = comm.getServices().iterator(); while (it.hasNext()) - { // add each index to the set - CommunityFeature ftr = (CommunityFeature)(it.next()); - defined.add(new Integer(ftr.getFeatureCode())); + { // add each symbol to the set + ServiceToken token = (ServiceToken)(it.next()); + defined.add(token.getSymbol()); } // end while @@ -104,7 +113,7 @@ public class CommunityLeftMenuFactory while (it.hasNext()) { // get this entry and see if there's a match in the set CommunityLeftMenuEntry ntry = (CommunityLeftMenuEntry)(it.next()); - if (defined.contains(new Integer(ntry.getIndex()))) + if (defined.contains(ntry.getSymbol())) tmp_items.add(ntry.resolveItem(vars)); } // end while @@ -127,4 +136,21 @@ public class CommunityLeftMenuFactory } // end createMenu + public String getDefaultServletAddress(RenderData rdat, CommunityContext comm) + { + ServiceToken token = comm.getDefaultService(); + if (token==null) + return null; + CommunityLeftMenuEntry ent = (CommunityLeftMenuEntry)(map_symbol.get(token.getSymbol())); + if (ent==null) + return null; + + // Create the map used to replace the variables in the servlet address. + HashMap vars = new HashMap(); + vars.put("cid",String.valueOf(comm.getCommunityID())); + + return ent.getServletAddress(rdat,vars); + + } // end getDefaultServletAddress + } // end class CommunityLeftMenuFactory diff --git a/src/com/silverwrist/venice/servlets/format/menus/LinkItem.java b/src/com/silverwrist/venice/servlets/format/menus/LinkItem.java index fa0e7e0..acdee30 100644 --- a/src/com/silverwrist/venice/servlets/format/menus/LinkItem.java +++ b/src/com/silverwrist/venice/servlets/format/menus/LinkItem.java @@ -145,4 +145,23 @@ class LinkItem implements ComponentRender, ColorSelectors } // end renderHere + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + final String getAddress(RenderData rdat, Map vars) + { + String s = StringUtil.replaceAllVariables(href,vars); + if (type.equals(ABSOLUTE)) + return s; + else if (type.equals(SERVLET)) + return rdat.getEncodedServletPath(s); + else if (type.equals(FRAME)) + return rdat.getEncodedServletPath("frame/" + s); + else + return null; + + } // end getAddress + } // end class LinkItem diff --git a/src/com/silverwrist/venice/svc/CommService.java b/src/com/silverwrist/venice/svc/CommService.java index ba7f085..bd757b0 100644 --- a/src/com/silverwrist/venice/svc/CommService.java +++ b/src/com/silverwrist/venice/svc/CommService.java @@ -18,18 +18,18 @@ package com.silverwrist.venice.svc; import org.w3c.dom.Element; +import com.silverwrist.venice.core.ServiceToken; import com.silverwrist.venice.except.ConfigException; +import com.silverwrist.venice.security.Role; import com.silverwrist.venice.security.SecurityMonitor; -public interface CommService +public interface CommService extends Service { - public abstract void initialize(Element root, SecurityMonitor sm, CommServiceSite site) + public abstract void initialize(ServiceToken token, Element root, SecurityMonitor sm, CommServiceSite site) throws ConfigException; - public abstract void shutdown(); + public abstract String getPermission(); - public abstract String getSymbol(); - - public abstract int getIndex(); + public abstract Role getRole(); } // end interface CommService diff --git a/src/com/silverwrist/venice/svc/Service.java b/src/com/silverwrist/venice/svc/Service.java new file mode 100644 index 0000000..6acdd4c --- /dev/null +++ b/src/com/silverwrist/venice/svc/Service.java @@ -0,0 +1,32 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.svc; + +import com.silverwrist.venice.core.ServiceToken; + +public interface Service +{ + public abstract void shutdown(); + + public abstract ServiceToken getToken(); + + public abstract boolean isDefault(); + + public abstract boolean isLocked(); + +} // end interface Service diff --git a/src/com/silverwrist/venice/svc/ServiceControl.java b/src/com/silverwrist/venice/svc/ServiceControl.java new file mode 100644 index 0000000..429647c --- /dev/null +++ b/src/com/silverwrist/venice/svc/ServiceControl.java @@ -0,0 +1,38 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.svc; + +import java.util.Set; +import com.silverwrist.venice.core.ServiceGroup; +import com.silverwrist.venice.core.ServiceToken; + +public interface ServiceControl extends ServiceGroup +{ + public abstract Set getAllServices(int group); + + public abstract Set getDefaultServices(int group); + + public abstract Service getServiceForSymbol(int group, String sym); + + public abstract Service getServiceForToken(ServiceToken token); + + public abstract ServiceToken getTokenForIndex(int group, int ndx); + + public abstract ServiceToken getTokenForSymbol(int group, String sym); + +} // end interface ServiceControl diff --git a/web/format/view_member.jsp b/web/format/view_member.jsp index 000b340..3dd5289 100644 --- a/web/format/view_member.jsp +++ b/web/format/view_member.jsp @@ -18,7 +18,6 @@ <%@ page import = "java.util.*" %> <%@ page import = "com.silverwrist.util.StringUtil" %> <%@ page import = "com.silverwrist.venice.core.*" %> -<%@ page import = "com.silverwrist.venice.security.Capability" %> <%@ page import = "com.silverwrist.venice.servlets.Variables" %> <%@ page import = "com.silverwrist.venice.servlets.format.*" %> <% @@ -129,7 +128,7 @@ <%= StringUtil.encodeHTML(uf.getGivenName()) %> <%= StringUtil.encodeHTML(uf.getFamilyName()) %>, from <%= StringUtil.encodeHTML(uf.getLocality()) %>, <%= StringUtil.encodeHTML(uf.getRegion()) %> <%= uf.getCountry() %> - <% if (Capability.isCommunityAdmin(uf.getLevel())) { %> + <% if (data.isCommunityAdmin(uf)) { %> " ALT="Host!" HSPACE=2 VSPACE=0 BORDER=0 WIDTH=40 HEIGHT=20 ALIGN=BOTTOM> <% } // end if %>