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.
This commit is contained in:
Eric J. Bowersox
2001-11-22 04:53:17 +00:00
parent 85518ca0d5
commit f5a5009932
29 changed files with 813 additions and 544 deletions

View File

@@ -20,12 +20,20 @@ package com.silverwrist.venice.servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.servlets.format.*;
public class CommunityFrontEnd extends VeniceServlet
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(CommunityFrontEnd.class);
/*--------------------------------------------------------------------------------
* Overrides from class HttpServlet
*--------------------------------------------------------------------------------
@@ -56,7 +64,9 @@ public class CommunityFrontEnd extends VeniceServlet
CommunityContext comm = user.getCommunityContext(alias);
// get the default servlet from the community context
String def_servlet = comm.getDefaultApplet();
String def_servlet = rdat.getDefaultServletAddress(comm);
if (logger.isDebugEnabled())
logger.debug("CommunityFrontEnd bouncing to: " + def_servlet);
if (def_servlet==null)
{ // return the default servlet
changeMenuTop(request);
@@ -65,7 +75,7 @@ public class CommunityFrontEnd extends VeniceServlet
} // end if
// and go there
throw new RedirectResult(def_servlet);
throw new RedirectResult(def_servlet,true);
} // end try
catch (DataException de)

View File

@@ -35,6 +35,7 @@ public class RedirectResult extends ExecuteResult
*/
private String target;
private boolean absolute;
/*--------------------------------------------------------------------------------
* Constructor
@@ -45,6 +46,15 @@ public class RedirectResult extends ExecuteResult
{
super();
this.target = target;
this.absolute = false;
} // end constructor
public RedirectResult(String target, boolean absolute)
{
super();
this.target = target;
this.absolute = absolute;
} // end constructor
@@ -55,6 +65,13 @@ public class RedirectResult extends ExecuteResult
public void execute(RenderData rdat) throws IOException
{
if (absolute)
{ // allow us to explicitly specify absolute redirection
rdat.redirectAbsolute(target);
return;
} // end if
for (int i=0; i<absolute_prefixes.length; i++)
if (target.startsWith(absolute_prefixes[i]))
{ // this is an absolute redirection...do it!

View File

@@ -579,6 +579,12 @@ public class RenderConfig implements ColorSelectors
} // end createCommunityMenu
String getDefaultServletAddress(RenderData rdat, CommunityContext comm)
{
return comm_menu_fact.getDefaultServletAddress(rdat,comm);
} // end getDefaultServletAddress
/*--------------------------------------------------------------------------------
* Static operations for use by VeniceServlet
*--------------------------------------------------------------------------------

View File

@@ -25,6 +25,7 @@ import javax.servlet.http.*;
import org.apache.log4j.*;
import com.silverwrist.util.IOUtil;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.core.CommunityContext;
import com.silverwrist.venice.core.IDUtils;
import com.silverwrist.venice.core.UserContext;
import com.silverwrist.venice.core.VeniceEngine;
@@ -334,6 +335,12 @@ public class RenderData implements ColorSelectors
} // end getPhotoNotAvailURL
public String getDefaultServletAddress(CommunityContext comm)
{
return rconf.getDefaultServletAddress(this,comm);
} // end getDefaultServletAddress
public String formatDateForDisplay(Date date)
{
if (display_date==null)

View File

@@ -23,6 +23,7 @@ import javax.servlet.*;
import javax.servlet.http.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.security.Role;
public class ViewCommunityMembers implements JSPRender, SearchMode
{
@@ -329,4 +330,12 @@ public class ViewCommunityMembers implements JSPRender, SearchMode
} // end getItem
public boolean isCommunityAdmin(UserFound uf)
{
SecurityInfo sinf = comm.getSecurityInfo();
Role r = sinf.getRole("Community.Host");
return r.isSatisfiedBy(uf.getLevel());
} // end isCommunityAdmin
} // end class ViewCommunityMembers

View File

@@ -20,6 +20,7 @@ package com.silverwrist.venice.servlets.format.menus;
import java.util.Map;
import org.w3c.dom.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.servlets.format.RenderData;
import com.silverwrist.venice.util.XMLLoader;
class CommunityLeftMenuEntry implements Comparable
@@ -114,4 +115,10 @@ class CommunityLeftMenuEntry implements Comparable
} // end resolveItem
final String getServletAddress(RenderData rdat, Map vars)
{
return item.getAddress(rdat,vars);
} // end getServletAddress
} // end class CommunityLeftMenuEntry

View File

@@ -21,6 +21,7 @@ import java.util.*;
import org.w3c.dom.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.servlets.format.RenderData;
public class CommunityLeftMenuFactory
{
@@ -30,6 +31,7 @@ public class CommunityLeftMenuFactory
*/
private List entries;
private Map map_symbol;
/*--------------------------------------------------------------------------------
* Constructor
@@ -42,6 +44,7 @@ public class CommunityLeftMenuFactory
{ // look for community services
NodeList nl = comm_sect.getChildNodes();
ArrayList tmp_entries = new ArrayList(nl.getLength());
HashMap tmp_map = new HashMap();
for (int i=0; i<nl.getLength(); i++)
{ // get each node and see if it's a service node
Node n = nl.item(i);
@@ -49,25 +52,35 @@ public class CommunityLeftMenuFactory
{ // create a template LeftMenuEntry and add it
CommunityLeftMenuEntry ent = new CommunityLeftMenuEntry((Element)n);
tmp_entries.add(ent);
tmp_map.put(ent.getSymbol(),ent);
} // end if
} // end for
if (tmp_entries.isEmpty())
{ // dummy it all out
entries = Collections.EMPTY_LIST;
map_symbol = Collections.EMPTY_MAP;
} // end if
else
{ // sort the list by sequence before we save it
if (tmp_entries.size()>1)
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

View File

@@ -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