merged in a round of changes from the stable branch
This commit is contained in:
parent
dc28dfeb3e
commit
39944e49cd
|
@ -271,6 +271,27 @@ public final class DOMElementHelper
|
|||
|
||||
} // end getAttributeInt
|
||||
|
||||
public final Boolean getAttributeBoolean(String name)
|
||||
{
|
||||
String tmp = elt.getAttribute(name);
|
||||
if (StringUtil.isBooleanTrue(tmp))
|
||||
return Boolean.TRUE;
|
||||
else if (StringUtil.isBooleanFalse(tmp))
|
||||
return Boolean.FALSE;
|
||||
else
|
||||
return null;
|
||||
|
||||
} // end getAttributeBoolean
|
||||
|
||||
public final Boolean getAttributeBoolean(String name, boolean default_val)
|
||||
{
|
||||
if (this.hasAttribute(name))
|
||||
return this.getAttributeBoolean(name);
|
||||
else
|
||||
return (default_val ? Boolean.TRUE : Boolean.FALSE);
|
||||
|
||||
} // end getAttributeBoolean
|
||||
|
||||
} // end DOMElementHelper
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*
|
||||
* 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
* Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
@ -36,12 +36,17 @@ public interface AdminOperations
|
|||
|
||||
public abstract AdminUserContext getUserContext(String username) throws DataException;
|
||||
|
||||
public abstract CommunityContext getCommunityContext(int cid) throws DataException;
|
||||
|
||||
public abstract CommunityContext getCommunityContext(String alias) throws DataException;
|
||||
|
||||
public abstract GlobalProperties getProperties();
|
||||
|
||||
public abstract void setProperties(GlobalProperties props) throws DataException;
|
||||
|
||||
public abstract AdminUserContext createNewAccount(String username, String password, String reminder,
|
||||
boolean verify_email, boolean lockout, Role base_role,
|
||||
String description) throws DataException, AccessError;
|
||||
String description, boolean auto_join)
|
||||
throws DataException, AccessError;
|
||||
|
||||
} // end interface AdminOperations
|
||||
|
|
|
@ -140,6 +140,18 @@ class AdminOperationsImpl implements AdminOperations
|
|||
|
||||
} // end getUserContext
|
||||
|
||||
public CommunityContext getCommunityContext(int cid) throws DataException
|
||||
{
|
||||
return CommunityUserContextImpl.getCommunityContext(env,cid,true);
|
||||
|
||||
} // end getCommunityContext
|
||||
|
||||
public CommunityContext getCommunityContext(String alias) throws DataException
|
||||
{
|
||||
return CommunityUserContextImpl.getCommunityContext(env,alias,true);
|
||||
|
||||
} // end getCommunityContext
|
||||
|
||||
public GlobalProperties getProperties()
|
||||
{
|
||||
return env.getEngine().getProperties();
|
||||
|
@ -154,7 +166,8 @@ class AdminOperationsImpl implements AdminOperations
|
|||
|
||||
public AdminUserContext createNewAccount(String username, String password, String reminder,
|
||||
boolean verify_email, boolean lockout, Role base_role,
|
||||
String description) throws DataException, AccessError
|
||||
String description, boolean auto_join)
|
||||
throws DataException, AccessError
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("createNewAccount(\"" + username + "\",<password>,<reminder>)...");
|
||||
|
@ -166,12 +179,15 @@ class AdminOperationsImpl implements AdminOperations
|
|||
ReturnNewUser rnu = UserContextImpl.createAccount(env,env.getRemoteAddress(),username,password,reminder,
|
||||
verify_email,lockout,0,base_role,description);
|
||||
|
||||
// Need to create a normal user context here for just a minute to autojoin the communities.
|
||||
if (auto_join)
|
||||
{ // Need to create a normal user context here for just a minute to autojoin the communities.
|
||||
UserContextImpl rc = new UserContextImpl(env.getGlobalSite(),env);
|
||||
rc.loadNewUser("0.0.0.0",rnu.getUserID(),base_role.getLevel(),username,0,rnu.getCreationDate(),
|
||||
rnu.getCreationDate());
|
||||
rc.autoJoinCommunities();
|
||||
|
||||
} // end if
|
||||
|
||||
// Now reload the user context and return it.
|
||||
return AdminUserContextImpl.getAdminUserContext(env,rnu.getUserID());
|
||||
|
||||
|
|
|
@ -231,19 +231,23 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
|||
|
||||
} // end testConferenceAccess
|
||||
|
||||
private static final CommunityUserContextImpl getCommunityPrivate(EnvUser env, Connection conn, int cid)
|
||||
private static final CommunityUserContextImpl getCommunityPrivate(EnvUser env, Connection conn, int cid,
|
||||
boolean allow_null)
|
||||
throws DataException
|
||||
{
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
try
|
||||
{ // create the query to find the community in the table
|
||||
stmt = conn.createStatement();
|
||||
StringBuffer sql = new StringBuffer("SELECT signame, alias FROM sigs WHERE sigid = ");
|
||||
sql.append(cid).append(';');
|
||||
ResultSet rs = stmt.executeQuery(sql.toString());
|
||||
rs = stmt.executeQuery(sql.toString());
|
||||
if (!(rs.next()))
|
||||
{ // the community entry was not found
|
||||
if (allow_null)
|
||||
return null;
|
||||
logger.error("Community " + String.valueOf(cid) + " not found in database");
|
||||
throw new DataException("Community #" + String.valueOf(cid) + " was not found in the database.");
|
||||
|
||||
|
@ -251,7 +255,6 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
|||
|
||||
// initialize the object and check membership info
|
||||
CommunityUserContextImpl sc = new CommunityUserContextImpl(env,cid,rs.getString(1),rs.getString(2));
|
||||
SQLUtil.shutdown(rs);
|
||||
sc.checkMembership(conn);
|
||||
return sc;
|
||||
|
||||
|
@ -264,6 +267,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
|||
} // end catch
|
||||
finally
|
||||
{ // shut down statement to conserve resources
|
||||
SQLUtil.shutdown(rs);
|
||||
SQLUtil.shutdown(stmt);
|
||||
|
||||
} // end finally
|
||||
|
@ -1674,7 +1678,8 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
|||
|
||||
} // end getMemberCommunityEntries
|
||||
|
||||
static final CommunityContext getCommunityContext(EnvUser env, int cid) throws DataException
|
||||
static final CommunityContext getCommunityContext(EnvUser env, int cid, boolean allow_null)
|
||||
throws DataException
|
||||
{
|
||||
Connection conn = null; // pooled database connection
|
||||
|
||||
|
@ -1683,7 +1688,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
|||
conn = env.getConnection();
|
||||
|
||||
// return the community we want
|
||||
return getCommunityPrivate(env,conn,cid);
|
||||
return getCommunityPrivate(env,conn,cid,allow_null);
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
|
@ -1700,10 +1705,12 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
|||
|
||||
} // end getCommunityContext
|
||||
|
||||
static final CommunityContext getCommunityContext(EnvUser env, String alias) throws DataException
|
||||
static final CommunityContext getCommunityContext(EnvUser env, String alias, boolean allow_null)
|
||||
throws DataException
|
||||
{
|
||||
Connection conn = null; // pooled database connection
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
try
|
||||
{ // get a database connection
|
||||
|
@ -1713,9 +1720,11 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
|||
stmt = conn.createStatement();
|
||||
StringBuffer sql = new StringBuffer("SELECT sigid, signame FROM sigs WHERE alias = '");
|
||||
sql.append(SQLUtil.encodeString(alias)).append("';");
|
||||
ResultSet rs = stmt.executeQuery(sql.toString());
|
||||
rs = stmt.executeQuery(sql.toString());
|
||||
if (!(rs.next()))
|
||||
{ // no community entry found...
|
||||
if (allow_null)
|
||||
return null;
|
||||
logger.error("Community '" + alias + "' not found in the database");
|
||||
throw new DataException("The community '" + alias + "' was not found in the database.");
|
||||
|
||||
|
@ -1723,7 +1732,6 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
|||
|
||||
// initialize the object and check membership info
|
||||
CommunityUserContextImpl c = new CommunityUserContextImpl(env,rs.getInt(1),rs.getString(2),alias);
|
||||
SQLUtil.shutdown(rs);
|
||||
c.checkMembership(conn);
|
||||
return c;
|
||||
|
||||
|
@ -1736,6 +1744,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
|||
} // end catch
|
||||
finally
|
||||
{ // make sure we release the connection before we go
|
||||
SQLUtil.shutdown(rs);
|
||||
SQLUtil.shutdown(stmt);
|
||||
SQLUtil.shutdown(conn);
|
||||
|
||||
|
@ -1745,7 +1754,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
|||
|
||||
static final CommunityBackend getCommunityBackend(EnvUser env, Connection conn, int cid) throws DataException
|
||||
{
|
||||
return getCommunityPrivate(env,conn,cid);
|
||||
return getCommunityPrivate(env,conn,cid,false);
|
||||
|
||||
} // end getCommunityBackend
|
||||
|
||||
|
|
|
@ -895,13 +895,13 @@ class UserContextImpl implements UserContext, ServiceProvider, PropertyProvider
|
|||
|
||||
public CommunityContext getCommunityContext(int cid) throws DataException
|
||||
{
|
||||
return CommunityUserContextImpl.getCommunityContext(env,cid);
|
||||
return CommunityUserContextImpl.getCommunityContext(env,cid,false);
|
||||
|
||||
} // end getCommunityContext
|
||||
|
||||
public CommunityContext getCommunityContext(String alias) throws DataException
|
||||
{
|
||||
return CommunityUserContextImpl.getCommunityContext(env,alias);
|
||||
return CommunityUserContextImpl.getCommunityContext(env,alias,false);
|
||||
|
||||
} // end getCommunityContext
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ public class ImportHelper
|
|||
|
||||
SecurityInfo sinf = adm.getSecurityInfo();
|
||||
Role default_role = sinf.getDefaultRole("Global.NewUser");
|
||||
HashMap community_cache = new HashMap();
|
||||
ArrayList scroll = new ArrayList();
|
||||
NodeList nl = root.getChildNodes();
|
||||
for (int i=0; i<nl.getLength(); i++)
|
||||
|
@ -91,8 +92,9 @@ public class ImportHelper
|
|||
String zonehint = null;
|
||||
Role r = default_role;
|
||||
boolean confirm = false, locked = false, hideaddr = false, hidephone = false, hidefax = false;
|
||||
boolean hideemail = false;
|
||||
boolean hideemail = false, autojoin = true;
|
||||
VCard vcard = null;
|
||||
ArrayList join_list = null;
|
||||
|
||||
// BUILD PHASE - Build the data to be used for this user.
|
||||
try
|
||||
|
@ -125,12 +127,13 @@ public class ImportHelper
|
|||
|
||||
} // end if
|
||||
|
||||
confirm = hopts.hasAttribute("confirmed");
|
||||
locked = hopts.hasAttribute("locked");
|
||||
hideaddr = hopts.hasAttribute("hideaddr");
|
||||
hidephone = hopts.hasAttribute("hidephone");
|
||||
hidefax = hopts.hasAttribute("hidefax");
|
||||
hideemail = hopts.hasAttribute("hideemail");
|
||||
confirm = loader.loadGetAttributeBoolean(opts,"confirmed",confirm);
|
||||
locked = loader.loadGetAttributeBoolean(opts,"locked",locked);
|
||||
hideaddr = loader.loadGetAttributeBoolean(opts,"hideaddr",hideaddr);
|
||||
hidephone = loader.loadGetAttributeBoolean(opts,"hidephone",hidephone);
|
||||
hidefax = loader.loadGetAttributeBoolean(opts,"hidefax",hidefax);
|
||||
hideemail = loader.loadGetAttributeBoolean(opts,"hideemail",hideemail);
|
||||
autojoin = loader.loadGetAttributeBoolean(opts,"autojoin",autojoin);
|
||||
if (hopts.hasAttribute("zonehint"))
|
||||
zonehint = opts.getAttribute("zonehint").trim();
|
||||
|
||||
|
@ -142,6 +145,75 @@ public class ImportHelper
|
|||
throw new ValidationException("no <vCard/> element found");
|
||||
vcard = new VCard(opts);
|
||||
|
||||
// Now process all the child nodes which may have multiple instances.
|
||||
NodeList nl2 = n.getChildNodes();
|
||||
for (int j=0; j<nl2.getLength(); j++)
|
||||
{ // get each node in turn, only handle it if it's an element
|
||||
Node cn = nl2.item(j);
|
||||
if (cn.getNodeType()!=Node.ELEMENT_NODE)
|
||||
continue; // not an element, we don't care
|
||||
|
||||
if (cn.getNodeName().equals("join"))
|
||||
{ // "join" node - causes the user to join a specified community
|
||||
h = new DOMElementHelper((Element)cn);
|
||||
String alias = h.getElementText();
|
||||
if (StringUtil.isStringEmpty(alias))
|
||||
continue; // ignore this value - it doesn't make sense
|
||||
|
||||
// Translate the alias into a community context.
|
||||
CommunityContext comm = (CommunityContext)(community_cache.get(alias));
|
||||
if (comm==null)
|
||||
{ // call down to the AdminOperations object to get a community context
|
||||
try
|
||||
{ // attempt to get the community context
|
||||
try
|
||||
{ // the "alias" may specify a numeric community ID - try that first
|
||||
comm = adm.getCommunityContext(Integer.parseInt(alias));
|
||||
|
||||
} // end try
|
||||
catch (NumberFormatException nfe)
|
||||
{ // well, it wasn't a numeric value, so fahgeddaboudit
|
||||
comm = null;
|
||||
|
||||
} // end catch
|
||||
|
||||
if (comm==null) // OK, try to get it by alias name
|
||||
comm = adm.getCommunityContext(alias);
|
||||
|
||||
} // end try
|
||||
catch (DataException de)
|
||||
{ // this should only happen in the case of database failures
|
||||
throw new ValidationException("database failure resolving alias \"" + alias + "\"");
|
||||
|
||||
} // end catch
|
||||
|
||||
if (comm!=null) // cache it for next time
|
||||
community_cache.put(alias,comm);
|
||||
|
||||
} // end if (we needed to look up community in database)
|
||||
|
||||
if (comm==null)
|
||||
continue; // ignore this - the community is specified wrong
|
||||
|
||||
// Figure out the role we want to join as.
|
||||
SecurityInfo csinf = comm.getSecurityInfo();
|
||||
Role my_role = null;
|
||||
String str_role = h.getElement().getAttribute("role");
|
||||
if (!(StringUtil.isStringEmpty(str_role)))
|
||||
my_role = csinf.getRole(str_role);
|
||||
if (my_role==null)
|
||||
my_role = csinf.getDefaultRole("Community.NewUser");
|
||||
|
||||
// Save off join information in a list.
|
||||
if (join_list==null)
|
||||
join_list = new ArrayList();
|
||||
join_list.add(comm);
|
||||
join_list.add(my_role);
|
||||
|
||||
} // end if ("join" element spotted)
|
||||
|
||||
} // end for
|
||||
|
||||
} // end try
|
||||
catch (ValidationException e)
|
||||
{ // record the error and continue
|
||||
|
@ -157,7 +229,8 @@ public class ImportHelper
|
|||
// EXECUTE PHASE - make this user go!
|
||||
try
|
||||
{ // create the user context
|
||||
AdminUserContext uc = adm.createNewAccount(username,password,reminder,confirm,locked,r,description);
|
||||
AdminUserContext uc = adm.createNewAccount(username,password,reminder,confirm,locked,r,
|
||||
description,autojoin);
|
||||
|
||||
// set up the contact info
|
||||
ContactInfo ci = uc.getContactInfo();
|
||||
|
@ -195,6 +268,20 @@ public class ImportHelper
|
|||
|
||||
} // end if
|
||||
|
||||
if (join_list!=null)
|
||||
{ // set up the community membership
|
||||
for (int j=0; j<join_list.size(); j+=2)
|
||||
{ // get the community and role, and set the membership status
|
||||
CommunityContext comm = (CommunityContext)(join_list.get(j));
|
||||
Role my_role = (Role)(join_list.get(j+1));
|
||||
comm.setMembership(uc.getUID(),my_role.getLevel());
|
||||
|
||||
} // end for
|
||||
|
||||
join_list.clear(); // dump the excess junk
|
||||
|
||||
} // end if
|
||||
|
||||
} // end try
|
||||
catch (AccessError ae)
|
||||
{ // caught an access error creating user
|
||||
|
@ -221,9 +308,9 @@ public class ImportHelper
|
|||
String tmp = "[id " + StringUtil.encodeHTML(id) + "] user \"" + username + "\" created successfully.";
|
||||
scroll.add(tmp);
|
||||
|
||||
} // end if
|
||||
} // end if ("venice-user" element found)
|
||||
|
||||
} // end for
|
||||
} // end for (each element in the node list)
|
||||
|
||||
// Gather the scroll items together to form the message.
|
||||
message = StringUtil.join(scroll,"<BR>\n");
|
||||
|
|
|
@ -382,6 +382,22 @@ public class XMLLoader
|
|||
|
||||
} // end configGetAttributeBoolean
|
||||
|
||||
public final boolean loadGetAttributeBoolean(Element elt, String attr_name, boolean default_val)
|
||||
throws ValidationException
|
||||
{
|
||||
String tmp = elt.getAttribute(attr_name);
|
||||
if (StringUtil.isStringEmpty(tmp))
|
||||
return default_val;
|
||||
if (StringUtil.isBooleanTrue(tmp))
|
||||
return true;
|
||||
if (StringUtil.isBooleanFalse(tmp))
|
||||
return false;
|
||||
logger.error(attr_name + "= attribute in <" + elt.getTagName() + "/> element is not a valid boolean");
|
||||
throw new ValidationException(attr_name + "= attribute in <" + elt.getTagName()
|
||||
+ "/> element is not a valid boolean");
|
||||
|
||||
} // end loadGetAttributeBoolean
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static operations
|
||||
*--------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue
Block a user