*** empty log message ***

This commit is contained in:
Eric J. Bowersox
2001-01-31 20:55:37 +00:00
parent cb2d194940
commit 946f3fb493
205 changed files with 297131 additions and 0 deletions
@@ -0,0 +1,46 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
public class AccessError extends com.silverwrist.venice.VeniceException
{
public AccessError()
{
super();
} // end constructor
public AccessError(String msg)
{
super(msg);
} // end constructor
public AccessError(Exception e)
{
super(e);
} // end constructor
public AccessError(String msg, Exception e)
{
super(msg,e);
} // end constructor
} // end class AccessError
@@ -0,0 +1,23 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
public interface AdminOperations
{
// TODO: fill this in
} // end interface AdminOperations
@@ -0,0 +1,50 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
import java.util.List;
public interface CategoryDescriptor
{
public abstract int getCategoryID();
public abstract int getNumLevels();
public abstract int getIDAtLevel(int level);
public abstract String getTitleAtLevel(int level);
public abstract List getSubCategories() throws DataException;
public abstract CategoryDescriptor getSuperCategory(int levels);
public abstract CategoryDescriptor getParentCategory();
public abstract int getLinkedCategoryID();
public abstract boolean isSymbolicLink();
public abstract CategoryDescriptor getLinkedCategory() throws DataException;
public abstract boolean equals(Object obj);
public abstract int hashCode();
public abstract String toString();
} // end interface CategoryDescriptor
@@ -0,0 +1,112 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
import java.util.Date;
import java.util.List;
public interface ConferenceContext
{
public static final int GET_ALL = 0;
public static final int DISPLAY_NEW = 1;
public static final int DISPLAY_ACTIVE = 2;
public static final int DISPLAY_ALL = 3;
public static final int DISPLAY_HIDDEN = 4;
public static final int DISPLAY_ARCHIVED = 5;
public static final int SORT_TOPICID = 0;
public static final int SORT_NUMBER = 1;
public static final int SORT_NAME = 2;
public static final int SORT_UNREAD = 3;
public static final int SORT_TOTAL = 4;
public static final int SORT_DATE = 5;
public abstract int getConfID();
public abstract String getName();
public abstract String getDescription();
public abstract Date getCreationDate();
public abstract Date getLastUpdateDate();
public abstract List getAliases() throws DataException;
public abstract List getHosts() throws DataException;
public abstract boolean canReadConference();
public abstract boolean canPostToConference();
public abstract boolean canCreateTopic();
public abstract boolean canChangeConference();
public abstract int getReadLevel() throws DataException, AccessError;
public abstract int getPostLevel() throws DataException, AccessError;
public abstract int getCreateLevel() throws DataException, AccessError;
public abstract int getHideLevel() throws DataException, AccessError;
public abstract int getNukeLevel() throws DataException, AccessError;
public abstract int getChangeLevel() throws DataException, AccessError;
public abstract int getDeleteLevel() throws DataException, AccessError;
public abstract void setSecurityLevels(int read, int post, int create, int hide, int nuke,
int change, int delete) throws DataException, AccessError;
public abstract void setName(String val) throws DataException, AccessError;
public abstract void setDescription(String val) throws DataException, AccessError;
public abstract void addAlias(String alias) throws DataException, AccessError;
public abstract void removeAlias(String alias) throws DataException, AccessError;
public abstract void addMember(int uid, boolean as_host) throws DataException, AccessError;
public abstract void removeMember(int uid) throws DataException, AccessError;
public abstract int getSIGGrantedLevel() throws DataException, AccessError;
public abstract void setSIGGrantedLevel(int new_level) throws DataException, AccessError;
public abstract short getSequence() throws DataException, AccessError;
public abstract void setSequence(short seq) throws DataException, AccessError;
public abstract boolean getHideList() throws DataException, AccessError;
public abstract void setHideList(boolean flag) throws DataException, AccessError;
public abstract String getDefaultPseud();
public abstract void setDefaultPseud(String val) throws DataException;
public abstract boolean anyUnread();
public abstract List getTopicList(int get_option, int sort_option) throws DataException, AccessError;
public abstract TopicContext getTopic(short number) throws DataException, AccessError;
} // end interface ConferenceContext
@@ -0,0 +1,93 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
import org.w3c.dom.*;
import com.silverwrist.venice.VeniceException;
public class ConfigException extends VeniceException
{
// Attributes
private Node faulty_sect = null; // section of the configuration at fault
public ConfigException()
{
super();
} // end constructor
public ConfigException(String msg)
{
super(msg);
} // end constructor
public ConfigException(Exception e)
{
super(e);
} // end constructor
public ConfigException(String msg, Exception e)
{
super(msg,e);
} // end constructor
public ConfigException(Node faulty_sect)
{
super("Error in <" + faulty_sect.getNodeName() + "/> section of configuration!");
this.faulty_sect = faulty_sect;
} // end constructor
public ConfigException(String msg, Node faulty_sect)
{
super(msg);
this.faulty_sect = faulty_sect;
} // end constructor
public ConfigException(Exception e, Node faulty_sect)
{
super("Error in <" + faulty_sect.getNodeName() + "/> section of configuration - " + e.getMessage(),e);
this.faulty_sect = faulty_sect;
} // end constructor
public ConfigException(String msg, Exception e, Node faulty_sect)
{
super(msg,e);
this.faulty_sect = faulty_sect;
} // end constructor
protected void finalize() throws Throwable
{
faulty_sect = null;
super.finalize();
} // end finalize
public Node getFaultySect()
{
return faulty_sect;
} // end getFaultySect
} // end class ConfigException
@@ -0,0 +1,123 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
import java.util.Date;
import java.sql.Connection;
public interface ContactInfo
{
public abstract int getContactID();
public abstract String getGivenName();
public abstract void setGivenName(String name);
public abstract String getFamilyName();
public abstract void setFamilyName(String name);
public abstract char getMiddleInitial();
public abstract void setMiddleInitial(char in);
public abstract String getNamePrefix();
public abstract void setNamePrefix(String p);
public abstract String getNameSuffix();
public abstract void setNameSuffix(String s);
public abstract String getCompany();
public abstract void setCompany(String c);
public abstract String getAddressLine1();
public abstract void setAddressLine1(String addr);
public abstract String getAddressLine2();
public abstract void setAddressLine2(String addr);
public abstract String getLocality();
public abstract void setLocality(String city);
public abstract String getRegion();
public abstract void setRegion(String state);
public abstract String getPostalCode();
public abstract void setPostalCode(String zip);
public abstract String getCountry();
public abstract void setCountry(String c);
public abstract String getPhone();
public abstract void setPhone(String num);
public abstract String getFax();
public abstract void setFax(String num);
public abstract String getMobile();
public abstract void setMobile(String num);
public abstract String getEmail();
public abstract void setEmail(String addr);
public abstract String getPhotoURL();
public abstract void setPhotoURL(String addr);
public abstract String getURL();
public abstract void setURL(String addr);
public abstract boolean getPrivateAddress();
public abstract void setPrivateAddress(boolean flag);
public abstract boolean getPrivatePhone();
public abstract void setPrivatePhone(boolean flag);
public abstract boolean getPrivateFax();
public abstract void setPrivateFax(boolean flag);
public abstract boolean getPrivateEmail();
public abstract void setPrivateEmail(boolean flag);
public abstract int getOwnerUID();
public abstract int getOwnerSIGID();
public abstract Date getLastUpdate();
public abstract boolean getModified();
} // end interface ContactInfo
@@ -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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
public interface Country
{
public abstract String getCode();
public abstract String getName();
} // end interface Country
@@ -0,0 +1,46 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
public class DataException extends com.silverwrist.venice.VeniceException
{
public DataException()
{
super();
} // end constructor
public DataException(String msg)
{
super(msg);
} // end constructor
public DataException(Exception e)
{
super(e);
} // end constructor
public DataException(String msg, Exception e)
{
super(msg,e);
} // end constructor
} // end class DataException
@@ -0,0 +1,46 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
public class EmailException extends com.silverwrist.venice.VeniceException
{
public EmailException()
{
super();
} // end constructor
public EmailException(String msg)
{
super(msg);
} // end constructor
public EmailException(Exception e)
{
super(e);
} // end constructor
public EmailException(String msg, Exception e)
{
super(msg,e);
} // end constructor
} // end class EmailException
@@ -0,0 +1,36 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
public interface FrontPageViewConfig
{
public abstract int getNumRows();
public abstract int getNumColumns();
public abstract String getPartID(int row, int column);
public abstract void setPartID(int row, int column, String partid);
public abstract String getParameter(int row, int column);
public abstract void setParameter(int row, int column, String param);
public abstract boolean getModified();
} // end interface FrontPageViewConfig
@@ -0,0 +1,75 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.AddressException;
public class IDUtils
{
/**
* The list of valid characters in Venice identifiers other than alphanumerics.
*/
private static final String EXTRA_VALID = "-_~*'$";
public static boolean isValidVeniceID(String id)
{
if ((id==null) || (id.length()==0))
return false; // null values and null strings are NEVER valid
for (int i=0; i<id.length(); i++)
{ // test each character in turn
char c = id.charAt(i);
if ((c>='A') && (c<='Z'))
continue; // upper-case letters are OK
if ((c>='a') && (c<='z'))
continue; // lower-case letters are OK
if ((c>='0') && (c<='9'))
continue; // digits are OK
if (EXTRA_VALID.indexOf(c)<0)
return false;
} // end for
return true; // all tests passed - ship it!
} // end isValidVeniceID
public static boolean isValidEmailAddress(String addr)
{
try
{ // take advantage of the JavaMail address parser
InternetAddress tmp = new InternetAddress(addr);
} // end try
catch (AddressException e)
{ // if we get an AddressException, it's not valid, is it?
return false;
} // end catch
return true; // if get here, it's valid
} // end isValidEmailAddress
public static boolean isValidConfirmationNumber(int num)
{
return ((num>=1000000) && (num<=9999999));
} // end isValidConfirmationNumber
} // end class IDUtils
@@ -0,0 +1,64 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
public class InternalStateError extends RuntimeException
{
// Attributes
private Exception e = null; // internal "root cause" exception
public InternalStateError()
{
super();
} // end constructor
public InternalStateError(String msg)
{
super(msg);
} // end constructor
public InternalStateError(Exception e)
{
super(e.getMessage());
this.e = e;
} // end constructor
public InternalStateError(String msg, Exception e)
{
super(msg);
this.e = e;
} // end constructor
protected void finalize() throws Throwable
{
e = null;
super.finalize();
} // end finalize
public Exception getException()
{
return e;
} // end getException
} // end class InternalStateError
@@ -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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
public interface Language
{
public abstract String getCode();
public abstract String getName();
} // end interface Language
@@ -0,0 +1,147 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
import java.util.BitSet;
import java.util.Date;
import java.util.List;
public interface SIGContext
{
public static final int HIDE_NONE = 0;
public static final int HIDE_DIRECTORY = 1;
public static final int HIDE_BOTH = 2;
public abstract int getSIGID();
public abstract String getName();
public abstract String getAlias();
public abstract boolean isMember();
public abstract boolean isAdmin();
public abstract boolean isPublicSIG();
public abstract int getCategoryID();
public abstract CategoryDescriptor getCategory() throws DataException;
public abstract String getSynopsis();
public abstract int getHostUID();
public abstract UserProfile getHostProfile() throws DataException;
public abstract String getLanguageCode();
public abstract String getLanguageFullName();
public abstract String getRules();
public abstract Date getCreationDate();
public abstract Date getLastAccessDate();
public abstract Date getLastUpdateDate();
public abstract ContactInfo getContactInfo() throws DataException;
public abstract void putContactInfo(ContactInfo ci) throws DataException, AccessError;
public abstract BitSet getFeatures();
public abstract void setFeatures(BitSet feature_set, BitSet mask) throws DataException, AccessError;
public abstract List getSIGFeaturesList();
public abstract String getDefaultApplet();
public abstract void setName(String name) throws DataException, AccessError;
public abstract void setAlias(String alias) throws DataException, AccessError;
public abstract void setCategoryID(int catid) throws DataException, AccessError;
public abstract void setCategory(CategoryDescriptor cat) throws DataException, AccessError;
public abstract void setSynopsis(String synopsis) throws DataException, AccessError;
public abstract void setLanguage(String language) throws DataException, AccessError;
public abstract void setRules(String rules) throws DataException, AccessError;
public abstract int getHideMode();
public abstract void setHideMode(int mode) throws DataException, AccessError;
public abstract boolean getMembersOnly();
public abstract void setMembersOnly(boolean flag) throws DataException, AccessError;
public abstract short getInitialFeatureIndex();
public abstract void setInitialFeatureIndex(short ndx) throws DataException, AccessError;
public abstract String getJoinKey() throws DataException, AccessError;
public abstract void setJoinKey(String key) throws DataException, AccessError;
public abstract int getReadLevel() throws DataException, AccessError;
public abstract int getWriteLevel() throws DataException, AccessError;
public abstract int getCreateLevel() throws DataException, AccessError;
public abstract int getDeleteLevel() throws DataException, AccessError;
public abstract int getJoinLevel() throws DataException, AccessError;
public abstract void setSecurityLevels(int read, int write, int create, int delete, int join)
throws DataException, AccessError;
public abstract boolean canAdministerSIG();
public abstract boolean canModifyProfile();
public abstract boolean isAdminSIG();
public abstract void join(String joinkey) throws DataException, AccessError;
public abstract void unjoin() throws DataException, AccessError;
public abstract int getMemberCount() throws DataException;
public abstract boolean canUnjoin();
public abstract boolean canJoin();
public abstract List getConferences() throws DataException, AccessError;
public abstract ConferenceContext getConferenceContext(int confid) throws DataException, AccessError;
public abstract ConferenceContext getConferenceContext(String alias) throws DataException, AccessError;
public abstract ConferenceContext createConference(String name, String alias, String description,
boolean pvt, boolean hide_list)
throws DataException, AccessError;
public abstract boolean canCreateConference();
} // end interface SIGContext
@@ -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 <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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
public interface SIGFeature
{
public abstract int getFeatureCode();
public abstract String getSymbol();
public abstract String getName();
public abstract String getApplet();
public abstract int getSequence();
} // end interface SIGFeature
@@ -0,0 +1,40 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
public interface SearchMode
{
public static final int FIELD_SIG_NAME = 0;
public static final int FIELD_SIG_SYNOPSIS = 1;
public static final int FIELD_USER_NAME = 2;
public static final int FIELD_USER_DESCRIPTION = 3;
public static final int FIELD_USER_GIVEN_NAME = 4;
public static final int FIELD_USER_FAMILY_NAME = 5;
public static final int SEARCH_PREFIX = 0;
public static final int SEARCH_SUBSTRING = 1;
public static final int SEARCH_REGEXP = 2;
} // end interface SearchMode
@@ -0,0 +1,216 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
import java.io.*;
import javax.xml.parsers.*;
import org.apache.log4j.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import com.silverwrist.util.DOMElementHelper;
public class Startup
{
/*--------------------------------------------------------------------------------
* Static data values
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(Startup.class.getName());
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
private Startup()
{ // this class cannot be created
} // end constructor
/*--------------------------------------------------------------------------------
* Internal functions
*--------------------------------------------------------------------------------
*/
private static Document loadConfiguration(String configname) throws ConfigException
{
try
{ // create a simple DOM parser by using the Java XML parsing API
DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
fac.setNamespaceAware(false);
fac.setValidating(false);
DocumentBuilder parser = fac.newDocumentBuilder();
// access the config file and parse it into our config data tree
File configfile = new File(configname);
Document rc = parser.parse(configfile);
if (logger.isDebugEnabled())
logger.debug("configuration loaded successfully");
return rc;
} // end try
catch (FactoryConfigurationError e1)
{ // if the document builder factory could not be created
logger.fatal("Parser factory configuration error: " + e1.getMessage(),e1);
throw new ConfigException("XML parser factory could not be created - " + e1.getMessage());
} // end catch
catch (ParserConfigurationException e2)
{ // if the XML parser itself could not be created
logger.fatal("Parser configuration error: " + e2.getMessage(),e2);
throw new ConfigException("XML parser could not be created - " + e2.getMessage(),e2);
} // end catch
catch (SAXException e3)
{ // if the XML parser choked on our document
if (e3 instanceof SAXParseException)
{ // we have a detailed message - make a proper exception
SAXParseException e3a = (SAXParseException)e3;
logger.fatal("Config file error [" + configname + ":" + e3a.getLineNumber() + ","
+ e3a.getColumnNumber() + "]: " + e3a.getMessage(),e3a);
throw new ConfigException("Configuration file error: " + e3a.getMessage() + " at line "
+ e3a.getLineNumber() + ", column " + e3a.getColumnNumber(),e3a);
} // end if
else
{ // generic exception - just send up a simple error message
logger.fatal("Config file error [" + configname + "]: " + e3.getMessage(),e3);
throw new ConfigException("Configuration file error - " + e3.getMessage(),e3);
} // end else
} // end catch
catch (IOException e4)
{ // error reading the config file itself off the disk
logger.fatal("IO error reading config: " + e4.getMessage(),e4);
throw new ConfigException("unable to read config file \"" + configname + "\" - " + e4.getMessage(),e4);
} // end catch
} // end loadConfiguration
private static String getEngineClassName(Document config) throws ConfigException
{
// Make sure the configuration is valid...
Element root = config.getDocumentElement();
if (!(root.getTagName().equals("venice-config")))
{ // not the correct root tag name
logger.fatal("config document is not a <venice-config/> document (root tag: <"
+ root.getTagName() + "/>)");
throw new ConfigException("document is not a <venice-config/> document",root);
} // end if
// Get the <engine/> section.
DOMElementHelper root_h = new DOMElementHelper(root);
Element engine_sect = root_h.getSubElement("engine");
if (engine_sect==null)
{ // no <engine/> section - bail out now!
logger.fatal("config document has no <engine/> section");
throw new ConfigException("no <engine/> section found in config file",root);
} // end if
// Get the classname out of that section.
DOMElementHelper engine_sect_h = new DOMElementHelper(engine_sect);
String rc = engine_sect_h.getSubElementText("classname");
if (rc==null)
{ // no <classname/> specified - bail out now!
logger.fatal("config document <engine/> section has no <classname/>");
throw new ConfigException("no <classname/> found in <engine/> section",engine_sect);
} // end if
return rc;
} // end getEngineClassName
/*--------------------------------------------------------------------------------
* External static methods (global functions)
*--------------------------------------------------------------------------------
*/
public static VeniceEngine createEngine(String configname) throws ConfigException, DataException
{
// load the configuration data
Document config = loadConfiguration(configname);
// find the classname of the engine
String cname = getEngineClassName(config);
if (logger.isDebugEnabled())
logger.debug("Venice engine classname: " + cname);
try
{ // attempt to load the engine class
Class engine_class = Class.forName(cname);
// now create a new Venice engine (cast to the external interface)
VeniceEngine engine = (VeniceEngine)(engine_class.newInstance());
if (logger.isDebugEnabled())
logger.debug("VeniceEngine created successfully");
// initialize the engine
engine.initialize(config);
// and return it
return engine;
} // end try
catch (ClassNotFoundException e1)
{ // the class was not found
logger.fatal("Venice engine class \"" + cname + "\" not found",e1);
throw new ConfigException("Invalid engine classname: " + cname);
} // end catch
catch (IllegalAccessException e2)
{ // could not access constructor or something
logger.fatal("Can't access \"" + cname + "\" constructor: " + e2.getMessage(),e2);
throw new ConfigException("Unable to create classname: " + cname);
} // end catch
catch (InstantiationException e3)
{ // could not create the instance
logger.fatal("Can't create instance of \"" + cname + "\": " + e3.getMessage(),e3);
throw new ConfigException("Unable to create classname: " + cname);
} // end catch
catch (ExceptionInInitializerError e4)
{ // some exception while initializing class
logger.fatal("Exception while initializing \"" + cname + "\": " + e4.getMessage(),e4);
throw new ConfigException("Unable to create classname: " + cname);
} // end catch
catch (SecurityException e5)
{ // security violation somewhere
logger.fatal("Security violation on \"" + cname + "\": " + e5.getMessage(),e5);
throw new ConfigException("Unable to create classname: " + cname);
} // end catch
catch (ClassCastException e6)
{ // engine could not be cast to VeniceEngine interface type
logger.fatal("\"" + cname + "\" is not of type VeniceEngine",e6);
throw new ConfigException("Invalid engine classname: " + cname);
} // end catch
} // end createEngine
} // end class Startup
@@ -0,0 +1,67 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
import java.util.Date;
import java.util.List;
public interface TopicContext
{
public abstract void refresh() throws DataException;
public abstract int getTopicID();
public abstract short getTopicNumber();
public abstract String getName();
public abstract int getUnreadMessages();
public abstract int getTotalMessages();
public abstract Date getLastUpdateDate();
public abstract int getCreatorUID();
public abstract boolean isFrozen();
public abstract boolean isArchived();
public abstract Date getCreatedDate();
public abstract boolean isHidden();
public abstract boolean isDeleted();
public abstract boolean canFreeze();
public abstract boolean canArchive();
public abstract void setFrozen(boolean flag) throws DataException, AccessError;
public abstract void setArchived(boolean flag) throws DataException, AccessError;
public abstract void setHidden(boolean flag) throws DataException;
public abstract int getFirstUnreadMessage();
public abstract void setUnreadMessages(int count) throws DataException;
public abstract void fixSeen() throws DataException;
} // end interface TopicContext
@@ -0,0 +1,92 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
import java.util.List;
public interface UserContext extends SearchMode
{
public abstract int getUID();
public abstract String getUserName();
public abstract int getContactID();
public abstract String getDescription();
public abstract boolean isLoggedIn();
public abstract boolean isEmailVerified();
public abstract void authenticate(String username, String password)
throws AccessError, DataException;
public abstract void confirmEmail(int conf_num) throws AccessError, DataException;
public abstract void resendEmailConfirmation() throws DataException, EmailException;
public abstract ContactInfo getContactInfo() throws DataException;
public abstract boolean putContactInfo(ContactInfo ci) throws DataException, EmailException;
public abstract UserProfile getProfile(String xusername) throws DataException;
public abstract UserProfile getProfile(int xuid) throws DataException;
public abstract void setPassword(String password, String reminder) throws DataException;
public abstract void setDescription(String new_descr) throws DataException;
public abstract FrontPageViewConfig getFrontPageViewConfig(int max_cols) throws DataException;
public abstract void putFrontPageViewConfig(FrontPageViewConfig cfg) throws DataException;
public abstract List getMemberSIGs() throws DataException;
public abstract SIGContext getSIGContext(int sigid) throws DataException;
public abstract SIGContext getSIGContext(String alias) throws DataException;
public abstract List getRootCategoryList() throws DataException;
public abstract CategoryDescriptor getCategoryDescriptor(int catid) throws DataException;
public abstract List searchForSIGs(int field, int mode, String term, int offset, int count)
throws DataException;
public abstract int getSearchSIGCount(int field, int mode, String term) throws DataException;
public abstract List getSIGsInCategory(int catid, int offset, int count) throws DataException;
public abstract List getSIGsInCategory(CategoryDescriptor cat, int offset, int count) throws DataException;
public abstract int getNumSIGsInCategory(int catid) throws DataException;
public abstract int getNumSIGsInCategory(CategoryDescriptor cat) throws DataException;
public abstract List searchForCategories(int mode, String term, int offset, int count) throws DataException;
public abstract int getSearchCategoryCount(int mode, String term) throws DataException;
public abstract SIGContext createSIG(String name, String alias, String language, String synopsis,
String rules, String joinkey, int hide_mode)
throws DataException, AccessError;
public abstract boolean canCreateSIG();
} // end interface UserContext
@@ -0,0 +1,40 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
public interface UserFound
{
public abstract int getUID();
public abstract String getName();
public abstract String getDescription();
public abstract String getGivenName();
public abstract String getFamilyName();
public abstract String getLocality();
public abstract String getRegion();
public abstract String getCountry();
public abstract int getLevel();
} // end interface UserFound
@@ -0,0 +1,74 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
import java.util.Date;
public interface UserProfile
{
public abstract int getUID();
public abstract String getUserName();
public abstract String getGivenName();
public abstract String getFamilyName();
public abstract char getMiddleInitial();
public abstract String getNamePrefix();
public abstract String getNameSuffix();
public abstract String getCompany();
public abstract String getAddressLine1();
public abstract String getAddressLine2();
public abstract String getLocality();
public abstract String getRegion();
public abstract String getPostalCode();
public abstract String getCountry();
public abstract String getFullCountry();
public abstract String getPhone();
public abstract String getFax();
public abstract String getMobile();
public abstract String getEmail();
public abstract String getPhotoURL();
public abstract String getURL();
public abstract Date getCreateDate();
public abstract Date getLastLoginDate();
public abstract Date getLastUpdate();
public abstract String getDescription();
} // end interface UserProfile
@@ -0,0 +1,68 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core;
import java.util.BitSet;
import java.util.List;
import org.w3c.dom.Document;
import com.silverwrist.venice.htmlcheck.HTMLChecker;
public interface VeniceEngine extends SearchMode
{
public abstract void initialize(Document config) throws ConfigException, DataException;
public abstract int getNumFeatures();
public abstract BitSet getAllFeaturesMask();
public abstract List getCountryList() throws DataException;
public abstract List getLanguageList() throws DataException;
public abstract String getNameOfCountry(String code);
public abstract UserContext createUserContext(String remote_addr) throws DataException;
public abstract String getEmailAddressForUser(String username) throws DataException, AccessError;
public abstract void sendPasswordReminder(String username)
throws DataException, AccessError, EmailException;
public abstract UserContext createNewAccount(String remote_addr, String username, String password,
String reminder) throws DataException, AccessError;
public abstract boolean aliasExists(String alias, int exist_sigid);
public abstract boolean isValidCategoryID(int catid);
public abstract List searchForUsers(int field, int mode, String term, int offset, int count)
throws DataException;
public abstract int getSearchUserCount(int field, int mode, String term) throws DataException;
public abstract int getStdNumSearchResults();
public abstract boolean isEmailAddressBanned(String email);
public abstract boolean confAliasExists(String alias);
public abstract HTMLChecker getPreviewChecker();
public abstract HTMLChecker getEscapingChecker();
} // end interface VeniceEngine
@@ -0,0 +1,577 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.sql.*;
import java.util.*;
import org.apache.log4j.*;
import com.silverwrist.venice.db.*;
import com.silverwrist.venice.core.*;
class CategoryDescriptorImpl implements CategoryDescriptor, Cloneable
{
/*--------------------------------------------------------------------------------
* Internal class for saving category segments
*--------------------------------------------------------------------------------
*/
static class CatSegment
{
private int id;
private String name;
CatSegment(int id, String name)
{
this.id = id;
this.name = name;
} // end constructor
public int getID()
{
return id;
} // end getID
public String getName()
{
return name;
} // end getName
} // end class CatSegment
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(CategoryDescriptorImpl.class.getName());
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private DataPool datapool; // used for doing database lookups
private Vector cats; // the actual category segments
private int symlink = -1; // if our category is actually a symlink
private boolean do_hide = true; // do we hide subcategories marked hide_dir?
/*--------------------------------------------------------------------------------
* Constructors
*--------------------------------------------------------------------------------
*/
CategoryDescriptorImpl(DataPool datapool, int catid, boolean do_hide) throws DataException
{
this.datapool = datapool;
cats = new Vector();
this.do_hide = do_hide;
if (catid<0)
return; // this is a "top" category
Connection conn = null;
try
{ // get a connection and a prepared statement
conn = datapool.getConnection();
doFillFromTop(conn,catid);
} // end try
catch (SQLException e)
{ // remap to DataException
throw new DataException("Unable to load category descriptor: " + e.getMessage(),e);
} // end catch
finally
{ // make sure and release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end constructor
protected CategoryDescriptorImpl(DataPool datapool, Connection conn, int catid, boolean do_hide)
throws SQLException, DataException
{
this.datapool = datapool;
cats = new Vector();
this.do_hide = do_hide;
if (catid<0)
return; // this is a "top" category
doFillFromTop(conn,catid);
} // end constructor
protected CategoryDescriptorImpl(DataPool datapool, int id, int symlink, String name, boolean do_hide)
{
this.datapool = datapool;
this.cats = new Vector();
this.symlink = symlink;
this.do_hide = do_hide;
this.cats.add(new CatSegment(id,name));
this.cats.trimToSize();
} // end constructor
protected CategoryDescriptorImpl(CategoryDescriptorImpl other, int copy_levels)
{
this.datapool = other.datapool;
this.cats = new Vector();
this.symlink = ((copy_levels==other.cats.size()) ? other.symlink : -1);
this.do_hide = other.do_hide;
if (copy_levels>0)
{ // copy the references to the objects directly
for (int i=0; i<copy_levels; i++)
this.cats.add(other.cats.get(i));
this.cats.trimToSize();
} // end if
} // end constructor
protected CategoryDescriptorImpl(CategoryDescriptorImpl other, int id, int symlink, String name)
{
this.datapool = other.datapool;
this.cats = new Vector();
this.symlink = symlink;
this.do_hide = other.do_hide;
// copy the references to the objects directly
for (int i=0; i<other.cats.size(); i++)
this.cats.add(other.cats.get(i));
this.cats.add(new CatSegment(id,name));
this.cats.trimToSize();
} // end constructor
/*--------------------------------------------------------------------------------
* finalize() function
*--------------------------------------------------------------------------------
*/
protected void finalize()
{
datapool = null;
cats = null;
} // end finalize
/*--------------------------------------------------------------------------------
* Internal functions
*--------------------------------------------------------------------------------
*/
private void doFillFromTop(Connection conn, int catid) throws SQLException, DataException
{
PreparedStatement stmt = conn.prepareStatement("SELECT parent, symlink, name "
+ "FROM refcategory WHERE catid = ?;");
int curr_catid = catid;
while (curr_catid!=-1)
{ // get the category reference for this level
stmt.setInt(1,curr_catid);
ResultSet rs = stmt.executeQuery();
if (!(rs.next())) // unable to read database
throw new DataException("category #" + String.valueOf(catid) + " could not be resolved");
// Save off the symbolic link value, if this category is a symlink.
int symlink_field = rs.getInt("symlink");
if (symlink_field!=-1)
{ // handle saving our symlink value - can only occur at END of path
if (cats.size()>0)
throw new InternalStateError("invalid symlink in category table (" + String.valueOf(curr_catid)
+ " => " + String.valueOf(symlink_field) + ")");
symlink = symlink_field;
} // end if
cats.add(0,new CatSegment(curr_catid,rs.getString("name")));
curr_catid = rs.getInt("parent");
} // end while
cats.trimToSize(); // shrink vector down to size
} // end doFillFromTop
/*--------------------------------------------------------------------------------
* Implementations from interface CategoryDescriptor
*--------------------------------------------------------------------------------
*/
public int getCategoryID()
{
if (cats.size()>0)
return ((CatSegment)(cats.lastElement())).getID();
else
return -1;
} // end getCategoryID
public int getNumLevels()
{
return cats.size();
} // end getNumLevels
public int getIDAtLevel(int level)
{
return ((CatSegment)(cats.get(level))).getID();
} // end getIDAtLevel
public String getTitleAtLevel(int level)
{
return ((CatSegment)(cats.get(level))).getName();
} // end getTitleAtLevel
public List getSubCategories() throws DataException
{
if (symlink!=-1)
{ // "snap" the symlink before getting subcategories
CategoryDescriptorImpl real_obj = new CategoryDescriptorImpl(datapool,symlink,do_hide);
return real_obj.getSubCategories();
} // end if
Connection conn = null;
Vector rc = new Vector();
try
{ // get a connection and create a statement
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT catid, symlink, name FROM refcategory WHERE parent = ");
sql.append(getCategoryID());
if (do_hide)
sql.append(" AND hide_dir = 0");
sql.append(';');
// run the database query
ResultSet rs = stmt.executeQuery(sql.toString());
while (rs.next())
{ // turn data values into CategoryDescriptor objects
CategoryDescriptor ncd = new CategoryDescriptorImpl(this,rs.getInt("catid"),rs.getInt("symlink"),
rs.getString("name"));
rc.add(ncd);
} // end while
} // end try
catch (SQLException e)
{ // remap to DataException
throw new DataException("Unable to load subcategories: " + e.getMessage(),e);
} // end catch
finally
{ // make sure and release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
// wrap the vector in a ReadOnlyVector object
return new ReadOnlyVector(rc);
} // end getSubCategories
public CategoryDescriptor getSuperCategory(int levels)
{
if ((levels<0) || (levels>(cats.size()-1)))
throw new IndexOutOfBoundsException("invalid supercategory level value");
return new CategoryDescriptorImpl(this,levels);
} // end getSuperCategory
public CategoryDescriptor getParentCategory()
{
return getSuperCategory(cats.size()-1);
} // end getParentCategory
public int getLinkedCategoryID()
{
if (symlink!=-1)
return symlink;
else
return getCategoryID();
} // end getLinkedCategoryID
public boolean isSymbolicLink()
{
return (symlink!=-1);
} // end isSymbolicLink
public CategoryDescriptor getLinkedCategory() throws DataException
{
if (symlink!=-1)
return new CategoryDescriptorImpl(datapool,symlink,do_hide);
else
return this;
} // end getLinkedCategory
public boolean equals(Object obj)
{
if (obj==null)
return false;
if (obj instanceof CategoryDescriptor)
{ // this is something we can compare to directly
CategoryDescriptor other = (CategoryDescriptor)obj;
return (other.getLinkedCategoryID()==getLinkedCategoryID());
} // end if
// compare string values
return obj.toString().equals(toString());
} // end equals
public int hashCode()
{
if (symlink!=-1)
return symlink;
else
return getCategoryID();
} // end hashCode
public String toString()
{
StringBuffer buf = new StringBuffer();
Iterator it = cats.iterator();
while (it.hasNext())
{ // concatenate all the parts together
CatSegment seg = (CatSegment)(it.next());
if (buf.length()>0)
buf.append(": ");
buf.append(seg.getName());
} // end while
return buf.toString();
} // end toString
public Object clone()
{
return new CategoryDescriptorImpl(this,cats.size());
} // end clone
/*--------------------------------------------------------------------------------
* Static operations for use within implementation package
*--------------------------------------------------------------------------------
*/
static List getTopLevelCategoryList(DataPool datapool, boolean do_hide) throws DataException
{
Connection conn = null;
Vector rc = new Vector();
try
{ // get a connection and create a statement
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT catid, symlink, name FROM refcategory WHERE parent = -1");
if (do_hide)
sql.append(" AND hide_dir = 0");
sql.append(';');
// run the database query
ResultSet rs = stmt.executeQuery(sql.toString());
while (rs.next())
{ // turn data values into CategoryDescriptor objects
CategoryDescriptor ncd = new CategoryDescriptorImpl(datapool,rs.getInt("catid"),rs.getInt("symlink"),
rs.getString("name"),do_hide);
rc.add(ncd);
} // end while
} // end try
catch (SQLException e)
{ // remap to DataException
throw new DataException("Unable to load subcategories: " + e.getMessage(),e);
} // end catch
finally
{ // make sure and release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
// wrap the vector in a ReadOnlyVector object
return new ReadOnlyVector(rc);
} // end getTopLevelCategoryList
static List searchForCategories(DataPool datapool, boolean do_hide, boolean search_all, int mode,
String term, int offset, int count) throws DataException
{
if (logger.isDebugEnabled())
logger.debug("Category search: mode = " + String.valueOf(mode) + ", term '" + term + "', offset = "
+ String.valueOf(offset) + ", count = " + String.valueOf(count));
Vector rc = new Vector();
Connection conn = null; // pooled database connection
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT catid FROM refcategory WHERE name ");
switch (mode)
{ // compose SQL in different ways depending on the search term
case SearchMode.SEARCH_PREFIX:
sql.append("LIKE '").append(SQLUtil.encodeStringWildcards(term)).append("%'");
break;
case SearchMode.SEARCH_SUBSTRING:
sql.append("LIKE '%").append(SQLUtil.encodeStringWildcards(term)).append("%'");
break;
case SearchMode.SEARCH_REGEXP:
sql.append("REGEXP '").append(SQLUtil.encodeString(term)).append('\'');
break;
default:
throw new DataException("invalid search mode specified");
} // end switch
if (do_hide)
sql.append(" AND hide_dir = 0");
if (!search_all)
sql.append(" AND hide_search = 0");
sql.append(" ORDER BY parent, name LIMIT ").append(offset).append(", ").append(count+1).append(';');
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
// launch the search!
ResultSet rs = stmt.executeQuery(sql.toString());
int[] rc_raw = new int[count+1];
int n = 0;
while (rs.next()) // just read off the matching CATIDs for now
rc_raw[n++] = rs.getInt("catid");
for (int i=0; i<n; i++)
{ // convert all the simple category IDs into full-blown CategoryDescriptor objects
CategoryDescriptor tmp = new CategoryDescriptorImpl(datapool,conn,rc_raw[i],do_hide);
rc.add(tmp);
} // end for
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error reading SIG entries: " + e.getMessage(),e);
throw new DataException("unable to retrieve user SIG information: " + e.getMessage(),e);
} // end catch
finally
{ // make sure we release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
return new ReadOnlyVector(rc);
} // end searchForCategories
static int getSearchCategoryCount(DataPool datapool, boolean do_hide, boolean search_all, int mode,
String term) throws DataException
{
if (logger.isDebugEnabled())
logger.debug("Category search: mode = " + String.valueOf(mode) + ", term '" + term + "'");
Connection conn = null; // pooled database connection
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT COUNT(*) AS total FROM refcategory WHERE name ");
switch (mode)
{ // compose SQL in different ways depending on the search term
case SearchMode.SEARCH_PREFIX:
sql.append("LIKE '").append(SQLUtil.encodeStringWildcards(term)).append("%'");
break;
case SearchMode.SEARCH_SUBSTRING:
sql.append("LIKE '%").append(SQLUtil.encodeStringWildcards(term)).append("%'");
break;
case SearchMode.SEARCH_REGEXP:
sql.append("REGEXP '").append(SQLUtil.encodeString(term)).append('\'');
break;
default:
throw new DataException("invalid search mode specified");
} // end switch
if (do_hide)
sql.append(" AND hide_dir = 0");
if (!search_all)
sql.append(" AND hide_search = 0");
sql.append(';');
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
// launch the search!
ResultSet rs = stmt.executeQuery(sql.toString());
if (!(rs.next()))
throw new InternalStateError("getSearchCategoryCount search failure (MUST have 1 row!)");
return rs.getInt("total");
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error reading SIG entries: " + e.getMessage(),e);
throw new DataException("unable to retrieve user SIG information: " + e.getMessage(),e);
} // end catch
finally
{ // make sure we release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end getSearchCategoryCount
} // end class CategoryDescriptorImpl
@@ -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 <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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.sql.*;
public interface ConferenceBackend extends SIGBackend
{
public abstract int realConfID();
public abstract boolean userCanHide();
public abstract void touchRead(Connection conn) throws SQLException;
public abstract String realConfAlias();
} // end interface ConferenceBackend
@@ -0,0 +1,958 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.sql.*;
import java.util.*;
import org.apache.log4j.*;
import com.silverwrist.venice.db.*;
import com.silverwrist.venice.security.AuditRecord;
import com.silverwrist.venice.security.DefaultLevels;
import com.silverwrist.venice.core.*;
class ConferenceCoreData implements ConferenceData
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(ConferenceCoreData.class.getName());
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private int refcount = 1; // object reference count
private EngineBackend engine; // pointer to engine back end
private DataPool datapool; // pointer to data pool
private int confid; // ID of this conference
private java.util.Date create_date; // creation date of this conference
private java.util.Date last_update; // last update date of conference
private int read_level; // access level required to read conference contents
private int post_level; // access level required to post messages
private int create_level; // access level required to create new topics
private int hide_level; // access level required to hide posts/archive topics
private int nuke_level; // access level required to delete topics/scribble/nuke posts
private int change_level; // access level required to modify conference profile
private int delete_level; // access level required to delete conference
private int top_topic; // the highest topic number in the conference
private String name; // the name of the conference
private String description; // the conference's description
private String cached_alias = null; // the cached alias (for getAnAlias)
/*--------------------------------------------------------------------------------
* Constructors
*--------------------------------------------------------------------------------
*/
ConferenceCoreData(EngineBackend engine, DataPool datapool, int confid) throws DataException
{
if (logger.isDebugEnabled())
logger.debug("new ConferenceCoreData for conference " + String.valueOf(confid));
this.engine = engine;
this.datapool = datapool;
this.confid = confid;
Connection conn = null;
try
{ // get a database connection from this object
conn = datapool.getConnection();
// get the conference basic data from the database
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT * FROM confs WHERE confid = ");
sql.append(confid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString());
if (!(rs.next()))
throw new DataException("Conference #" + String.valueOf(confid) + " does not exist in the database.");
loadData(rs); // load the conference data
} // end try
catch (SQLException e)
{ // translate into a nicer DataException
logger.error("DB error reading conference data: " + e.getMessage(),e);
throw new DataException("unable to load conference data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end constructor
protected ConferenceCoreData(EngineBackend engine, DataPool datapool, int confid, java.util.Date created,
boolean pvt, String name, String descr)
{
if (logger.isDebugEnabled())
logger.debug("new ConferenceCoreData for NEW conference " + String.valueOf(confid));
this.engine = engine;
this.datapool = datapool;
this.confid = confid;
this.create_date = created;
this.last_update = null;
this.read_level = DefaultLevels.newConferenceRead(pvt);
this.post_level = DefaultLevels.newConferencePost(pvt);
this.create_level = DefaultLevels.newConferenceCreate(pvt);
this.hide_level = DefaultLevels.newConferenceHide();
this.nuke_level = DefaultLevels.newConferenceNuke();
this.change_level = DefaultLevels.newConferenceChange();
this.delete_level = DefaultLevels.newConferenceDelete();
this.top_topic = 0;
this.name = name;
this.description = descr;
} // end constructor
/*--------------------------------------------------------------------------------
* Internal functions
*--------------------------------------------------------------------------------
*/
private synchronized void loadData(ResultSet rs) throws SQLException
{
// "confid" field is skipped
create_date = SQLUtil.getFullDateTime(rs,"createdate");
last_update = SQLUtil.getFullDateTime(rs,"lastupdate");
read_level = rs.getInt("read_lvl");
post_level = rs.getInt("post_lvl");
create_level = rs.getInt("create_lvl");
hide_level = rs.getInt("hide_lvl");
nuke_level = rs.getInt("nuke_lvl");
change_level = rs.getInt("change_lvl");
delete_level = rs.getInt("delete_lvl");
top_topic = rs.getInt("top_topic");
name = rs.getString("name");
description = rs.getString("descr");
// "icon_url" and "color" fields are skipped
} // end loadData
private synchronized void touchUpdate(Connection conn) throws SQLException
{
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE confs SET lastupdate = '");
java.util.Date now = new java.util.Date();
sql.append(SQLUtil.encodeDate(now)).append("' WHERE confid = ").append(confid).append(';');
stmt.executeUpdate(sql.toString());
last_update = now;
} // end touchUpdate
/*--------------------------------------------------------------------------------
* Implementations from interface ReferencedData
*--------------------------------------------------------------------------------
*/
public int rd_addRef()
{
return ++refcount;
} // end rd_addRef()
public int rd_release()
{
return --refcount;
} // end rd_release
public boolean rd_unreferenced()
{
return (refcount<=0);
} // end rd_unreferenced
/*--------------------------------------------------------------------------------
* Implementations from interface ConferenceData
*--------------------------------------------------------------------------------
*/
public int getID()
{
return confid;
} // end getID
public String getName()
{
return name;
} // end getName
public String getDescription()
{
return description;
} // end getDescription
public java.util.Date getCreationDate()
{
return create_date;
} // end getCreationDate
public java.util.Date getLastUpdateDate()
{
return last_update;
} // end getLastUpdate
public List getAliases() throws DataException
{
Connection conn = null;
Vector rc = new Vector();
try
{ // get a database connection from this object
conn = datapool.getConnection();
// get a list of all aliases
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT alias FROM confalias WHERE confid = ");
sql.append(confid).append(" ORDER BY alias;");
// execute the query
ResultSet rs = stmt.executeQuery(sql.toString());
while (rs.next())
rc.add(rs.getString(1));
} // end try
catch (SQLException e)
{ // translate into a nicer DataException
logger.error("DB error reading conference data: " + e.getMessage(),e);
throw new DataException("unable to load conference data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
return new ReadOnlyVector(rc);
} // end getAlias
public List getHosts() throws DataException
{
Connection conn = null;
Vector rc = new Vector();
try
{ // get a database connection from this object
conn = datapool.getConnection();
// get a list of all hosts (with user info)
Statement stmt = conn.createStatement();
StringBuffer sql =
new StringBuffer("SELECT u.uid, u.username, u.description, c.given_name, c.family_name, "
+ "c.locality, c.region, c.country FROM users u, contacts c, confmember m "
+ "WHERE u.contactid = c.contactid AND u.uid = m.uid AND m.confid = ");
sql.append(confid).append(" AND m.granted_lvl >= ").append(DefaultLevels.hostPrivsConference());
sql.append(" ORDER BY u.username;");
// execute the query
ResultSet rs = stmt.executeQuery(sql.toString());
while (rs.next())
{ // create the UserFound
UserFound uf = new UserFoundImpl(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),
rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8));
rc.add(uf);
} // end while
} // end try
catch (SQLException e)
{ // translate into a nicer DataException
logger.error("DB error reading conference hosts: " + e.getMessage(),e);
throw new DataException("unable to load conference hosts: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
return new ReadOnlyVector(rc);
} // end getHosts
public boolean canReadConference(int level)
{
return (level>=read_level);
} // end canReadConference
public boolean canPostToConference(int level)
{
return (level>=post_level);
} // end canReadConference
public boolean canCreateTopic(int level)
{
return (level>=create_level);
} // end canCreateTopic
public boolean canChangeConference(int level)
{
return (level>=change_level);
} // end canChangeConference
public int getReadLevel()
{
return read_level;
} // end getReadLevel
public int getPostLevel()
{
return post_level;
} // end getPostLevel
public int getCreateLevel()
{
return create_level;
} // end getCreateLevel
public int getHideLevel()
{
return hide_level;
} // end getHideLevel
public int getNukeLevel()
{
return nuke_level;
} // end getNukeLevel
public int getChangeLevel()
{
return change_level;
} // end getChangeLevel
public int getDeleteLevel()
{
return delete_level;
} // end getDeleteLevel
public synchronized void setSecurityLevels(SIGBackend sig, int read, int post, int create, int hide,
int nuke, int change, int delete) throws DataException
{
Connection conn = null; // database connection
AuditRecord ar = null; // audit record
try
{ // get a database connection
conn = datapool.getConnection();
// create the SQL statement
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE confs SET read_lvl = ");
sql.append(read).append(", post_lvl = ").append(post).append(", create_lvl = ").append(create);
sql.append(", hide_lvl = ").append(hide).append(", nuke_lvl = ").append(nuke).append(", change_lvl = ");
sql.append(change).append(", delete_lvl = ").append(delete).append(", lastupdate = '");
java.util.Date now = new java.util.Date();
sql.append(SQLUtil.encodeDate(now)).append("' WHERE confid = ").append(confid).append(';');
// execute the update
stmt.executeUpdate(sql.toString());
// save copies of the data in our local variables
read_level = read;
post_level = post;
create_level = create;
hide_level = hide;
nuke_level = nuke;
change_level = change;
delete_level = delete;
last_update = now;
// create an audit record reflecting the change
ar = new AuditRecord(AuditRecord.CONF_SECURITY,sig.realUID(),sig.userRemoteAddress(),sig.realSIGID(),
"conf=" + String.valueOf(confid));
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error storing conference data: " + e.getMessage(),e);
throw new DataException("unable to save conference data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setSecurityLevels
public synchronized void setName(SIGBackend sig, String val) throws DataException
{
Connection conn = null; // database connection
AuditRecord ar = null; // audit record
try
{ // get a database connection
conn = datapool.getConnection();
// create the SQL statement
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE confs SET name = '");
sql.append(SQLUtil.encodeString(val)).append("', lastupdate = '");
java.util.Date now = new java.util.Date();
sql.append(SQLUtil.encodeDate(now)).append("' WHERE confid = ").append(confid).append(';');
// execute the update
stmt.executeUpdate(sql.toString());
// save copies of the data in our local variables
name = val;
last_update = now;
// create an audit record reflecting the change
ar = new AuditRecord(AuditRecord.CONF_SECURITY,sig.realUID(),sig.userRemoteAddress(),sig.realSIGID(),
"conf=" + String.valueOf(confid));
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error storing conference data: " + e.getMessage(),e);
throw new DataException("unable to save conference data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setName
public synchronized void setDescription(String val) throws DataException
{
Connection conn = null; // database connection
try
{ // get a database connection
conn = datapool.getConnection();
// create the SQL statement
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE confs SET descr = '");
sql.append(SQLUtil.encodeString(val)).append("', lastupdate = '");
java.util.Date now = new java.util.Date();
sql.append(SQLUtil.encodeDate(now)).append("' WHERE confid = ").append(confid).append(';');
// execute the update
stmt.executeUpdate(sql.toString());
// save copies of the data in our local variables
description = val;
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error storing conference data: " + e.getMessage(),e);
throw new DataException("unable to save conference data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setDescription
public synchronized void addAlias(SIGBackend sig, String alias) throws DataException
{
Connection conn = null; // database connection
AuditRecord ar = null; // audit record
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES confalias WRITE;");
try
{ // first check to see if the alias already exists
StringBuffer sql = new StringBuffer("SELECT confid FROM confalias WHERE alias = '");
String alias_encode = SQLUtil.encodeString(alias);
sql.append(alias_encode).append("';");
ResultSet rs = stmt.executeQuery(sql.toString());
if (rs.next())
{ // already exists...but is it in this conference or a different one?
if (confid==rs.getInt(1))
return; // this conference - this is a no-op
throw new DataException("The alias \"" + alias + "\" is already in use by a different conference.");
} // end if
// now add it!
sql.setLength(0);
sql.append("INSERT INTO confalias (confid, alias) VALUES (").append(confid).append(", '");
sql.append(alias_encode).append("');");
stmt.executeUpdate(sql.toString());
} // end try
finally
{ // make sure we unlock the tables before we go
Statement ulk_stmt = conn.createStatement();
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally
// set the database's update date and generate a new audit record
touchUpdate(conn);
ar = new AuditRecord(AuditRecord.CONF_ALIAS,sig.realUID(),sig.userRemoteAddress(),sig.realSIGID(),
"conf=" + String.valueOf(confid),"add=" + alias);
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error storing conference alias: " + e.getMessage(),e);
throw new DataException("unable to save conference alias: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end addAlias
public synchronized void removeAlias(SIGBackend sig, String alias) throws DataException
{
Connection conn = null; // database connection
AuditRecord ar = null; // audit record
try
{ // get a database connection
conn = datapool.getConnection();
boolean did_it = false;
Statement stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES confalias WRITE;");
try
{ // first check to see how many aliases there are
StringBuffer sql = new StringBuffer("SELECT COUNT(*) FROM confalias WHERE confid = ");
sql.append(confid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString());
if (!(rs.next()))
throw new InternalStateError("removeAlias query screwup - must be at least ONE row!");
int alias_count = rs.getInt(1);
if (alias_count<=0)
throw new InternalStateError("removeAlias database failure - detected less than one alias!");
if (alias_count==1)
{ // OK, there's only one alias - make sure it ain't the one we're trying to remove!
sql.setLength(0);
sql.append("SELECT alias FROM confalias WHERE confid = ").append(confid).append(" AND alias = '");
sql.append(SQLUtil.encodeString(alias)).append("';");
rs = stmt.executeQuery(sql.toString());
if (rs.next()) // it is - that would be bad, throw an error!
throw new DataException("The conference must have at least one alias.");
return; // but if it isn't, we're not going to succeed in removing it anyway
} // end if
// OK, go delete the row (or not, if this alias is not in the table)
sql.setLength(0);
sql.append("DELETE FROM confalias WHERE confid = ").append(confid).append("AND alias = '");
sql.append(SQLUtil.encodeString(alias)).append("';");
did_it = (stmt.executeUpdate(sql.toString())>0);
} // end try
finally
{ // make sure we unlock the tables before we go
Statement ulk_stmt = conn.createStatement();
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally
if (did_it)
{ // set the database's update date and generate a new audit record
touchUpdate(conn);
if (cached_alias.equals(alias))
cached_alias = null; // also release the cached alias and force a re-get
ar = new AuditRecord(AuditRecord.CONF_ALIAS,sig.realUID(),sig.userRemoteAddress(),sig.realSIGID(),
"conf=" + String.valueOf(confid),"remove=" + alias);
} // end if
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error storing conference alias: " + e.getMessage(),e);
throw new DataException("unable to save conference alias: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end removeAlias
public synchronized void setMembership(SIGBackend sig, int uid, int grant_level) throws DataException
{
Connection conn = null; // database connection
AuditRecord ar = null; // audit record
try
{ // get a database connection
conn = datapool.getConnection();
boolean did_it = false;
Statement stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES confmember WRITE;");
try
{ // how we go about this depends on whether we're adding or removing
StringBuffer sql = new StringBuffer();
if (grant_level>=0)
{ // see whether the user is in the table yet...
sql.append("SELECT granted_lvl FROM confmember WHERE confid = ").append(confid);
sql.append(" AND uid = ").append(uid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString());
sql.setLength(0);
if (rs.next())
{ // just poke the new level value in
sql.append("UPDATE confmember SET granted_lvl = ").append(grant_level).append(" WHERE confid = ");
sql.append(confid).append(" AND uid = ").append(uid).append(';');
} // end if
else
{ // need to insert a new row...
sql.append("INSERT INTO confmember (confid, uid, granted_lvl) VALUES (").append(confid);
sql.append(", ").append(uid).append(", ").append(grant_level).append(");");
} // end else
stmt.executeUpdate(sql.toString());
did_it = true;
} // end if
else
{ // just try to delete this row from the table (if possible)
sql.append("DELETE FROM confmember WHERE confid = ").append(confid).append(" AND uid = ");
sql.append(uid).append(';');
did_it = (stmt.executeUpdate(sql.toString())>0);
} // end else
} // end try
finally
{ // make sure we unlock the tables before we go
Statement ulk_stmt = conn.createStatement();
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally
if (did_it)
{ // set the database's update date and generate a new audit record
touchUpdate(conn);
ar = new AuditRecord(AuditRecord.CONF_MEMBERSHIP,sig.realUID(),sig.userRemoteAddress(),sig.realSIGID(),
"conf=" + String.valueOf(confid),"uid=" + String.valueOf(uid),
"level=" + String.valueOf(grant_level));
} // end if
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error storing conference data: " + e.getMessage(),e);
throw new DataException("unable to save conference data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setMembership
public boolean canHideTopics(int level)
{
return (level>=hide_level);
} // end canHideTopics
public synchronized String getAnAlias() throws DataException
{
if (cached_alias!=null)
return cached_alias;
Connection conn = null;
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
// create the SQL statement and execute it
StringBuffer sql = new StringBuffer("SELECT alias FROM confalias WHERE confid = ");
sql.append(confid).append(" LIMIT 1;");
ResultSet rs = stmt.executeQuery(sql.toString());
if (!(rs.next()))
throw new DataException("unable to find alias for conference");
cached_alias = rs.getString(1);
return cached_alias;
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error retrieving conference data: " + e.getMessage(),e);
throw new DataException("unable to get conference data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end getAnAlias
/*--------------------------------------------------------------------------------
* External static operations (usable only from within package)
*--------------------------------------------------------------------------------
*/
static ReturnConfSeq createConference(EngineBackend engine, SIGBackend sig, DataPool datapool, String name,
String alias, String description, boolean pvt, boolean hide_list,
int host_uid) throws DataException
{
Connection conn = null; // database connection
AuditRecord ar = null; // audit record
int new_confid; // new conference ID
short new_sequence; // new sequence number
java.util.Date created; // date/time conference created
if (logger.isDebugEnabled())
logger.debug("createConference entry");
try
{ // start by locking all the tables we need
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES confs WRITE, sigtoconf WRITE, confalias WRITE, confmember WRITE;");
try
{ // first check on the alias availability
StringBuffer sql = new StringBuffer("SELECT confid FROM confalias WHERE alias = '");
String alias_encode = SQLUtil.encodeString(alias);
sql.append(alias_encode).append("';");
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
ResultSet rs = stmt.executeQuery(sql.toString());
if (rs.next()) // already used - this is bogus!
throw new DataException("The alias \"" + alias + "\" is already in use by a different conference.");
// compute our new sequence number
sql.setLength(0);
sql.append("SELECT MAX(sequence) FROM sigtoconf WHERE sigid = ").append(sig.realSIGID()).append(';');
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
rs = stmt.executeQuery(sql.toString());
if (!(rs.next()))
throw new InternalStateError("bogus query in createConference - must return at least 1 row!");
new_sequence = (short)(rs.getShort(1) + 100);
// insert the record into the conferences table!
sql.setLength(0);
sql.append("INSERT INTO confs (createdate, read_lvl, post_lvl, create_lvl, hide_lvl, nuke_lvl, "
+ "change_lvl, delete_lvl, top_topic, name, descr) VALUES ('");
created = new java.util.Date();
sql.append(SQLUtil.encodeDate(created)).append("', ").append(DefaultLevels.newConferenceRead(pvt));
sql.append(", ").append(DefaultLevels.newConferencePost(pvt)).append(", ");
sql.append(DefaultLevels.newConferenceCreate(pvt)).append(", ");
sql.append(DefaultLevels.newConferenceHide()).append(", ").append(DefaultLevels.newConferenceNuke());
sql.append(", ").append(DefaultLevels.newConferenceChange()).append(", ");
sql.append(DefaultLevels.newConferenceDelete()).append(", 0, '").append(SQLUtil.encodeString(name));
sql.append("', '").append(SQLUtil.encodeString(description)).append("');");
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
stmt.executeUpdate(sql.toString());
// Get the new conference ID.
rs = stmt.executeQuery("SELECT LAST_INSERT_ID();");
if (!(rs.next()))
throw new InternalStateError("bogus query in createConference - must get new confid!");
new_confid = rs.getInt(1);
// Make the insert into the confalias table to give the conference an alias.
sql.setLength(0);
sql.append("INSERT INTO confalias (confid, alias) VALUES (").append(new_confid).append(", '");
sql.append(alias_encode).append("');");
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
stmt.executeUpdate(sql.toString());
// Link the SIG to the conference by adding a row to sigtoconf.
sql.setLength(0);
sql.append("INSERT INTO sigtoconf (sigid, confid, sequence, hide_list) VALUES (");
sql.append(sig.realSIGID()).append(", ").append(new_confid).append(", ").append(new_sequence);
sql.append(", ").append(hide_list ? '1' : '0').append(");");
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
stmt.executeUpdate(sql.toString());
// Make the specified UID the host of this new conference.
sql.setLength(0);
sql.append("INSERT INTO confmember (confid, uid, granted_lvl) VALUES (").append(new_confid);
sql.append(", ").append(host_uid).append(", ").append(DefaultLevels.hostConference()).append(");");
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
stmt.executeUpdate(sql.toString());
} // end try
finally
{ // unlock the tables before we go
Statement ulk_stmt = conn.createStatement();
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally
// create an audit record indicating we were successful
ar = new AuditRecord(AuditRecord.CREATE_CONF,sig.realUID(),sig.userRemoteAddress(),sig.realSIGID(),
"confid=" + String.valueOf(new_confid),"name=" + name,"alias=" + alias);
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error creating SIG: " + e.getMessage(),e);
throw new DataException("unable to create SIG: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
// Create a new ConferenceCoreData object representing this conference and register it with the
// engine's conference data object cache.
ConferenceCoreData conf = new ConferenceCoreData(engine,datapool,new_confid,created,pvt,name,description);
engine.registerNewConference(conf);
return new ReturnConfSeq(conf,new_sequence);
} // end createConference
} // end class ConferenceCoreData
@@ -0,0 +1,79 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.util.Date;
import java.util.List;
import com.silverwrist.venice.core.DataException;
public interface ConferenceData extends ReferencedData
{
public abstract int getID();
public abstract String getName();
public abstract String getDescription();
public abstract Date getCreationDate();
public abstract Date getLastUpdateDate();
public abstract List getAliases() throws DataException;
public abstract List getHosts() throws DataException;
public abstract boolean canReadConference(int level);
public abstract boolean canPostToConference(int level);
public abstract boolean canCreateTopic(int level);
public abstract boolean canChangeConference(int level);
public abstract int getReadLevel();
public abstract int getPostLevel();
public abstract int getCreateLevel();
public abstract int getHideLevel();
public abstract int getNukeLevel();
public abstract int getChangeLevel();
public abstract int getDeleteLevel();
public abstract void setSecurityLevels(SIGBackend sig, int read, int post, int create, int hide,
int nuke, int change, int delete) throws DataException;
public abstract void setName(SIGBackend sig, String val) throws DataException;
public abstract void setDescription(String val) throws DataException;
public abstract void addAlias(SIGBackend sig, String alias) throws DataException;
public abstract void removeAlias(SIGBackend sig, String alias) throws DataException;
public abstract void setMembership(SIGBackend sig, int uid, int grant_level) throws DataException;
public abstract boolean canHideTopics(int level);
public abstract String getAnAlias() throws DataException;
} // end interface ConferenceData
@@ -0,0 +1,91 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.util.Date;
import java.util.List;
import com.silverwrist.venice.core.DataException;
public interface ConferenceSIGContext extends ReferencedData
{
public abstract int getConfID();
public abstract String getName();
public abstract String getDescription();
public abstract Date getCreationDate();
public abstract Date getLastUpdateDate();
public abstract int getSIGGrantedLevel();
public abstract List getAliases() throws DataException;
public abstract List getHosts() throws DataException;
public abstract boolean canReadConference(int level);
public abstract boolean canPostToConference(int level);
public abstract boolean canCreateTopic(int level);
public abstract boolean canChangeConference(int level);
public abstract int getReadLevel() throws DataException;
public abstract int getPostLevel() throws DataException;
public abstract int getCreateLevel() throws DataException;
public abstract int getHideLevel() throws DataException;
public abstract int getNukeLevel() throws DataException;
public abstract int getChangeLevel() throws DataException;
public abstract int getDeleteLevel() throws DataException;
public abstract void setSecurityLevels(SIGBackend sig, int read, int post, int create, int hide,
int nuke, int change, int delete) throws DataException;
public abstract void setName(SIGBackend sig, String val) throws DataException;
public abstract void setDescription(String val) throws DataException;
public abstract void addAlias(SIGBackend sig, String alias) throws DataException;
public abstract void removeAlias(SIGBackend sig, String alias) throws DataException;
public abstract void setMembership(SIGBackend sig, int uid, int grant_level) throws DataException;
public abstract void setSIGGrantedLevel(SIGBackend sig, int new_level) throws DataException;
public abstract short getSequence();
public abstract void setSequence(short seq) throws DataException;
public abstract boolean getHideList();
public abstract void setHideList(SIGBackend sig, boolean flag) throws DataException;
public abstract boolean canHideTopics(int level);
public abstract String getAnAlias() throws DataException;
} // end interface ConferenceSIGContext
@@ -0,0 +1,614 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.sql.*;
import java.util.*;
import org.apache.log4j.*;
import com.silverwrist.venice.db.*;
import com.silverwrist.venice.security.AuditRecord;
import com.silverwrist.venice.core.*;
class ConferenceSIGContextImpl implements ConferenceSIGContext
{
/*--------------------------------------------------------------------------------
* Inner class used to cache locally-important data
*--------------------------------------------------------------------------------
*/
static class ConfCache
{
String name;
String description;
java.util.Date created;
public ConfCache(String name, String description, java.util.Date created)
{
this.name = name;
this.description = description;
this.created = created;
} // end constructor
public String getName()
{
return name;
} // end getName
public String getDescription()
{
return description;
} // end getDescription
public java.util.Date getCreated()
{
return created;
} // end getCreated
} // end class ConfCache
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(ConferenceSIGContextImpl.class.getName());
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private int refcount = 1; // reference count (within the SIGData)
private EngineBackend engine; // engine object reference
private SIGDataBackend sig; // SIG object reference
private DataPool datapool; // data pool object
private int confid; // ID of this conference
private int level; // level granted in conference to members of the SIG
private short sequence; // sequence number this conference appears in list
private boolean hide_list; // hide the conference in the list?
private ConfCache cache; // cache of locally-important information
private ConferenceData confdata = null; // the inner conference data object
/*--------------------------------------------------------------------------------
* Constructors
*--------------------------------------------------------------------------------
*/
ConferenceSIGContextImpl(EngineBackend engine, SIGDataBackend sig, DataPool datapool, int confid)
throws DataException
{
if (logger.isDebugEnabled())
logger.debug("new ConferenceSIGContextImpl(#" + String.valueOf(confid) + ") for SIG # "
+ String.valueOf(sig.realSIGID()));
this.engine = engine;
this.sig = sig;
this.datapool = datapool;
this.confid = confid;
Connection conn = null; // pooled database connection
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
// Build a monster query! This is like the query for retrieving the ConferenceUserContextImpl
// data, except without the left outer join to the user conference membership table.
StringBuffer sql =
new StringBuffer("SELECT c.createdate, c.name, c.descr, s.granted_lvl, s.sequence, s.hide_list "
+ "FROM sigtoconf s, confs c WHERE s.confid = c.confid AND s.sigid = ");
sql.append(sig.realSIGID()).append(" AND c.confid = ").append(confid).append(';');
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
// Run that monster query!
ResultSet rs = stmt.executeQuery(sql.toString());
if (!(rs.next()))
throw new DataException("conference ID#" + String.valueOf(confid) + " not found in SIG#"
+ String.valueOf(sig.realSIGID()));
// fill in the "cache" and "level" indicators
this.cache = new ConfCache(rs.getString(2),rs.getString(3),SQLUtil.getFullDateTime(rs,1));
this.level = rs.getInt(4);
this.sequence = rs.getShort(5);
this.hide_list = rs.getBoolean(6);
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error reading conference entry: " + e.getMessage(),e);
throw new DataException("unable to retrieve conference information: " + e.getMessage(),e);
} // end catch
finally
{ // make sure we release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end constructor
ConferenceSIGContextImpl(EngineBackend engine, SIGDataBackend sig, DataPool datapool,
short sequence, boolean hide_list, ConferenceData cdata)
{
if (logger.isDebugEnabled())
logger.debug("new ConferenceSIGContextImpl(NEW#" + String.valueOf(confid) + ") for SIG # "
+ String.valueOf(sig.realSIGID()));
this.engine = engine;
this.sig = sig;
this.datapool = datapool;
this.confid = cdata.getID();
this.level = 0;
this.sequence = sequence;
this.hide_list = hide_list;
this.cache = null;
cdata.rd_addRef();
this.confdata = cdata;
} // end constructor
/*--------------------------------------------------------------------------------
* Internal functions
*--------------------------------------------------------------------------------
*/
private synchronized ConferenceData getConferenceData() throws DataException
{
if (confdata==null)
{ // attempt to load the ConferenceSIGContext
confdata = engine.getConferenceDataObject(confid);
// clear cache when we get the real confdata
cache = null;
} // end if
return confdata;
} // end getConferenceData
private synchronized ConferenceData getConferenceDataNE()
{
if (confdata==null)
{ // we need to load the ConferenceSIGContext...
try
{ // attempt to load the ConferenceSIGContext
confdata = engine.getConferenceDataObject(confid);
} // end try
catch (DataException e)
{ // there was a data failure loading the conference
logger.error("** Got DataException in getConferenceDataNE: " + e.getMessage(),e);
return null;
} // end catch
// clear cache when we get the real confdata
cache = null;
} // end if
return confdata;
} // end getConferenceDataNE
/*--------------------------------------------------------------------------------
* Implementations from interface ReferencedData
*--------------------------------------------------------------------------------
*/
public int rd_addRef()
{
return ++refcount;
} // end rd_addRef
public int rd_release()
{
return --refcount;
} // end rd_release
public boolean rd_unreferenced()
{
return (refcount<=0);
} // end rd_unreferences
/*--------------------------------------------------------------------------------
* Implementations from interface ConferenceSIGContext
*--------------------------------------------------------------------------------
*/
public int getConfID()
{
return confid;
} // end getConfID
public String getName()
{
if (cache!=null)
return cache.getName();
ConferenceData c = getConferenceDataNE();
if (c!=null)
return c.getName();
else
return null;
} // end getName
public String getDescription()
{
if (cache!=null)
return cache.getDescription();
ConferenceData c = getConferenceDataNE();
if (c!=null)
return c.getDescription();
else
return null;
} // end getDescription
public java.util.Date getCreationDate()
{
if (cache!=null)
return cache.getCreated();
ConferenceData c = getConferenceDataNE();
if (c!=null)
return c.getCreationDate();
else
return null;
} // end getCreationDate
public java.util.Date getLastUpdateDate()
{
ConferenceData c = getConferenceDataNE();
if (c!=null)
return c.getLastUpdateDate();
else
return null;
} // end getLastUpdateDate
public int getSIGGrantedLevel()
{
return level;
} // end getSIGGrantedLevel
public List getAliases() throws DataException
{
return getConferenceData().getAliases();
} // end getAliases
public List getHosts() throws DataException
{
return getConferenceData().getHosts();
} // end getHosts
public boolean canReadConference(int level)
{
ConferenceData c = getConferenceDataNE();
if (c==null)
return false;
if (level<this.level)
return c.canReadConference(this.level);
else
return c.canReadConference(level);
} // end canReadConference
public boolean canPostToConference(int level)
{
ConferenceData c = getConferenceDataNE();
if (c==null)
return false;
if (level<this.level)
return c.canPostToConference(this.level);
else
return c.canPostToConference(level);
} // end canPostToConference
public boolean canCreateTopic(int level)
{
ConferenceData c = getConferenceDataNE();
if (c==null)
return false;
if (level<this.level)
return c.canCreateTopic(this.level);
else
return c.canCreateTopic(level);
} // end canCreateTopic
public boolean canChangeConference(int level)
{
ConferenceData c = getConferenceDataNE();
if (c==null)
return false;
if (level<this.level)
return c.canChangeConference(this.level);
else
return c.canChangeConference(level);
} // end canChangeConference
public int getReadLevel() throws DataException
{
return getConferenceData().getReadLevel();
} // end getReadLevel
public int getPostLevel() throws DataException
{
return getConferenceData().getPostLevel();
} // end getPostLevel
public int getCreateLevel() throws DataException
{
return getConferenceData().getCreateLevel();
} // end getCreateLevel
public int getHideLevel() throws DataException
{
return getConferenceData().getHideLevel();
} // end getHideLevel
public int getNukeLevel() throws DataException
{
return getConferenceData().getNukeLevel();
} // end getNukeLevel
public int getChangeLevel() throws DataException
{
return getConferenceData().getChangeLevel();
} // end getChangeLevel
public int getDeleteLevel() throws DataException
{
return getConferenceData().getDeleteLevel();
} // end getDeleteLevel
public synchronized void setSecurityLevels(SIGBackend sig, int read, int post, int create, int hide,
int nuke, int change, int delete) throws DataException
{
getConferenceData().setSecurityLevels(sig,read,post,create,hide,nuke,change,delete);
} // end setSecurityLevels
public synchronized void setName(SIGBackend sig, String val) throws DataException
{
getConferenceData().setName(sig,val);
} // end setName
public synchronized void setDescription(String val) throws DataException
{
getConferenceData().setDescription(val);
} // end setDescription
public synchronized void addAlias(SIGBackend sig, String alias) throws DataException
{
getConferenceData().addAlias(sig,alias);
} // end addAlias
public synchronized void removeAlias(SIGBackend sig, String alias) throws DataException
{
getConferenceData().removeAlias(sig,alias);
} // end removeAlias
public synchronized void setMembership(SIGBackend sig, int uid, int grant_level) throws DataException
{
getConferenceData().setMembership(sig,uid,grant_level);
} // end setMembership
public synchronized void setSIGGrantedLevel(SIGBackend sig, int new_level) throws DataException
{
Connection conn = null; // database connection
AuditRecord ar = null; // audit record
try
{ // get a database connection
conn = datapool.getConnection();
// create the SQL statement
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET granted_lvl = ");
sql.append(new_level).append(" WHERE sigid = ").append(this.sig.realSIGID()).append(" AND confid = ");
sql.append(confid).append(';');
// execute the update
stmt.executeUpdate(sql.toString());
// save copies of the data in our local variables
level = new_level;
// create an audit record reflecting the change
ar = new AuditRecord(AuditRecord.CONF_SECURITY,sig.realUID(),sig.userRemoteAddress(),sig.realSIGID(),
"conf=" + String.valueOf(confid));
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error storing conference data: " + e.getMessage(),e);
throw new DataException("unable to save conference data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setSIGGrantedLevel
public short getSequence()
{
return sequence;
} // end getSequence
public synchronized void setSequence(short seq) throws DataException
{
Connection conn = null; // database connection
try
{ // get a database connection
conn = datapool.getConnection();
// create the SQL statement
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET sequence = ");
sql.append(seq).append(" WHERE sigid = ").append(this.sig.realSIGID()).append(" AND confid = ");
sql.append(confid).append(';');
// execute the update
stmt.executeUpdate(sql.toString());
// save copies of the data in our local variables
sequence = seq;
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error storing conference data: " + e.getMessage(),e);
throw new DataException("unable to save conference data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setSequence
public boolean getHideList()
{
return hide_list;
} // end getHideList
public void setHideList(SIGBackend sig, boolean flag) throws DataException
{
Connection conn = null; // database connection
AuditRecord ar = null; // audit record
try
{ // get a database connection
conn = datapool.getConnection();
// create the SQL statement
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE sigtoconf SET hide_list = ");
sql.append(hide_list ? '1' : '0').append(" WHERE sigid = ").append(this.sig.realSIGID());
sql.append(" AND confid = ").append(confid).append(';');
// execute the update
stmt.executeUpdate(sql.toString());
// save copies of the data in our local variables
hide_list = flag;
// create an audit record reflecting the change
ar = new AuditRecord(AuditRecord.CONF_SECURITY,sig.realUID(),sig.userRemoteAddress(),sig.realSIGID(),
"conf=" + String.valueOf(confid));
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error storing conference data: " + e.getMessage(),e);
throw new DataException("unable to save conference data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setHideList
public boolean canHideTopics(int level)
{
ConferenceData c = getConferenceDataNE();
if (c==null)
return false;
if (level<this.level)
return c.canHideTopics(this.level);
else
return c.canHideTopics(level);
} // end canHideTopics
public String getAnAlias() throws DataException
{
return getConferenceData().getAnAlias();
} // end getAnAlias
} // end class ConferenceSIGContextImpl
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,694 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.sql.*;
import java.util.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.db.*;
class ContactInfoImpl implements ContactInfo, Stashable
{
// Attributes
private int contactid; // ID of this contact record (-1 = new)
private String given_name; // given name ("first name")
private String family_name; // family name ("last name")
private char middle_initial; // middle initial (natch)
private String prefix; // prefix (Mr., Ms., Prof., Dr., etc.)
private String suffix; // suffix (Jr., III, etc.)
private String company; // company name
private String addr1; // address line 1
private String addr2; // address line 2
private String locality; // locality ("city")
private String region; // region ("state")
private String postal_code; // postal code ("ZIP code")
private String country; // 2-character ISO 3166 country code
private String phone; // voice phone number
private String fax; // facsimile (fax) number
private String mobile; // mobile phone (cellphone) number
private String email; // email address
private String photo_url; // URL of user photo
private String url; // URL of user's homepage
private boolean private_addr; // are addr1 and addr2 hidden?
private boolean private_phone; // are phone and mobile hidden?
private boolean private_fax; // is fax hidden?
private boolean private_email; // is email hidden?
private int owner_uid; // UID that owns this contact record
private int owner_sigid; // SIGID this contact record is in (-1 for none)
private java.util.Date last_update; // date of last update
private boolean is_modified = false; // have we modified this ContactInfo?
/**
* Constructs a new blank <CODE>ContactInfoImpl</CODE> object.
*
* @param owner_uid UID that owns this object.
*/
ContactInfoImpl(int owner_uid)
{
makeEmpty(owner_uid,-1);
} // end constructor
/**
* Constructs a new blank <CODE>ContactInfoImpl</CODE> object.
*
* @param owner_uid UID that owns this object.
* @param owner_sigid SIGID that owns this object.
*/
ContactInfoImpl(int owner_uid, int owner_sigid)
{
makeEmpty(owner_uid,owner_sigid);
} // end constructor
/**
* Loads a <CODE>ContactInfoImpl</CODE> object out of the database.
*
* @param dp Database connection pool to get a Venice database connection from.
* @param contactid ID of the contact to load.
* @exception DataException The contact could not be loaded for some reason.
*/
ContactInfoImpl(DataPool dp, int contactid) throws DataException
{
Connection conn = null;
try
{ // get a connection and call loadData
conn = dp.getConnection();
loadData(conn,contactid);
} // end try
catch (SQLException e)
{ // turn SQLExceptions at this level into DataExceptions
throw new DataException("Unable to look up contact info: " + e.getMessage(),e);
} // end catch
finally
{ // make sure we release the connection before we go
if (conn!=null)
dp.releaseConnection(conn);
} // end finally
} // end constructor
private void makeEmpty(int owner_uid, int owner_sigid)
{
this.contactid = -1;
this.given_name = null;
this.family_name = null;
this.middle_initial = ' ';
this.prefix = null;
this.suffix = null;
this.company = null;
this.addr1 = null;
this.addr2 = null;
this.locality = null;
this.region = null;
this.postal_code = null;
this.country = null;
this.phone = null;
this.fax = null;
this.mobile = null;
this.email = null;
this.photo_url = null;
this.url = null;
this.private_addr = false;
this.private_phone = false;
this.private_fax = false;
this.private_email = false;
this.owner_uid = owner_uid;
this.owner_sigid = owner_sigid;
this.last_update = null;
} // end makeEmpty
private void loadData(Connection conn, int contactid) throws DataException
{
try
{ // do a simple SELECT in contacts to look this up
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT * FROM contacts WHERE contactid = ");
sql.append(contactid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString());
if (rs.next())
{ // do a mad orgy of saving off field values
this.contactid = rs.getInt("contactid");
given_name = rs.getString("given_name");
family_name = rs.getString("family_name");
String blort = rs.getString("middle_init");
if ((blort!=null) && (blort.length()>0))
middle_initial = blort.charAt(0);
else
middle_initial = ' ';
prefix = rs.getString("prefix");
suffix = rs.getString("suffix");
company = rs.getString("company");
addr1 = rs.getString("addr1");
addr2 = rs.getString("addr2");
locality = rs.getString("locality");
region = rs.getString("region");
postal_code = rs.getString("pcode");
country = rs.getString("country");
phone = rs.getString("phone");
fax = rs.getString("fax");
mobile = rs.getString("mobile");
email = rs.getString("email");
private_addr = rs.getBoolean("pvt_addr");
private_phone = rs.getBoolean("pvt_phone");
private_fax = rs.getBoolean("pvt_fax");
private_email = rs.getBoolean("pvt_email");
owner_uid = rs.getInt("owner_uid");
owner_sigid = rs.getInt("owner_sigid");
photo_url = rs.getString("photo_url");
url = rs.getString("url");
last_update = SQLUtil.getFullDateTime(rs,"lastupdate");
} // end if
else // contact was not found
throw new DataException("Contact was not found.");
} // end try
catch (SQLException e)
{ // map all SQLExceptions into DataExceptions
throw new DataException("Unable to look up contact info: " + e.getMessage(),e);
} // end catch
} // end loadData
public int getContactID()
{
return contactid;
} // end getContactID
public String getGivenName()
{
return given_name;
} // end getGivenName
public void setGivenName(String name)
{
if ((name!=null) && (name.length()>64))
given_name = name.substring(0,64);
else
given_name = name;
is_modified = true;
} // end setGivenName
public String getFamilyName()
{
return family_name;
} // end getFamilyName
public void setFamilyName(String name)
{
if ((name!=null) && (name.length()>64))
family_name = name.substring(0,64);
else
family_name = name;
is_modified = true;
} // end setFamilyName
public char getMiddleInitial()
{
return middle_initial;
} // end getMiddleInitial
public void setMiddleInitial(char in)
{
middle_initial = in;
is_modified = true;
} // end setMiddleInitial
public String getNamePrefix()
{
return prefix;
} // end getNamePrefix
public void setNamePrefix(String p)
{
if ((p!=null) && (p.length()>8))
prefix = p.substring(0,8);
else
prefix = p;
is_modified = true;
} // end setNamePrefix
public String getNameSuffix()
{
return suffix;
} // end getNameSuffix
public void setNameSuffix(String s)
{
if ((s!=null) && (s.length()>16))
suffix = s.substring(0,16);
else
suffix = s;
is_modified = true;
} // end setNameSuffix
public String getCompany()
{
return company;
} // end getCompany
public void setCompany(String c)
{
if ((c!=null) && (c.length()>255))
company = c.substring(0,255);
else
company = c;
is_modified = true;
} // end setCompany
public String getAddressLine1()
{
return addr1;
} // end getAddressLine1
public void setAddressLine1(String addr)
{
if ((addr!=null) && (addr.length()>255))
addr1 = addr.substring(0,255);
else
addr1 = addr;
is_modified = true;
} // end setAddressLine1
public String getAddressLine2()
{
return addr2;
} // end getAddressLine2
public void setAddressLine2(String addr)
{
if ((addr!=null) && (addr.length()>255))
addr2 = addr.substring(0,255);
else
addr2 = addr;
is_modified = true;
} // end setAddressLine2
public String getLocality()
{
return locality;
} // end getLocality
public void setLocality(String city)
{
if ((city!=null) && (city.length()>64))
locality = city.substring(0,64);
else
locality = city;
is_modified = true;
} // end setLocality
public String getRegion()
{
return region;
} // end getRegion
public void setRegion(String state)
{
if ((state!=null) && (state.length()>64))
region = state.substring(0,64);
else
region = state;
is_modified = true;
} // end setRegion
public String getPostalCode()
{
return postal_code;
} // end getPostalCode
public void setPostalCode(String zip)
{
if ((zip!=null) && (zip.length()>16))
postal_code = zip.substring(0,16);
else
postal_code = zip;
is_modified = true;
} // end setPostalCode
public String getCountry()
{
return country;
} // end getCountry
public void setCountry(String c)
{
if ((c!=null) && (c.length()>2))
country = c.substring(0,2);
else
country = c;
is_modified = true;
} // end setCountry
public String getPhone()
{
return phone;
} // end getPhone
public void setPhone(String num)
{
if ((num!=null) && (num.length()>32))
phone = num.substring(0,32);
else
phone = num;
is_modified = true;
} // end setPhone
public String getFax()
{
return fax;
} // end getFax
public void setFax(String num)
{
if ((num!=null) && (num.length()>32))
fax = num.substring(0,32);
else
fax = num;
is_modified = true;
} // end setFax
public String getMobile()
{
return mobile;
} // end getMobile
public void setMobile(String num)
{
if ((num!=null) && (num.length()>32))
mobile = num.substring(0,32);
else
mobile = num;
is_modified = true;
} // end setMobile
public String getEmail()
{
return email;
} // end getEmail
public void setEmail(String addr)
{
if ((addr!=null) && (addr.length()>255))
email = addr.substring(0,255);
else
email = addr;
is_modified = true;
} // end setEmail
public String getPhotoURL()
{
return photo_url;
} // end getPhotoURL
public void setPhotoURL(String addr)
{
if ((addr!=null) && (addr.length()>255))
photo_url = addr.substring(0,255);
else
photo_url = addr;
is_modified = true;
} // end setPhotoURL
public String getURL()
{
return url;
} // end getURL
public void setURL(String addr)
{
if ((addr!=null) && (addr.length()>255))
url = addr.substring(0,255);
else
url = addr;
is_modified = true;
} // end setURL
public boolean getPrivateAddress()
{
return private_addr;
} // end getPrivateAddress
public void setPrivateAddress(boolean flag)
{
private_addr = flag;
is_modified = true;
} // end setPrivateAddress
public boolean getPrivatePhone()
{
return private_phone;
} // end getPrivatePhone
public void setPrivatePhone(boolean flag)
{
private_phone = flag;
is_modified = true;
} // end setPrivatePhone
public boolean getPrivateFax()
{
return private_fax;
} // end getPrivateFax
public void setPrivateFax(boolean flag)
{
private_fax = flag;
is_modified = true;
} // end setPrivateFax
public boolean getPrivateEmail()
{
return private_email;
} // end getPrivateEmail
public void setPrivateEmail(boolean flag)
{
private_email = flag;
is_modified = true;
} // end setPrivateEmail
public int getOwnerUID()
{
return owner_uid;
} // end getOwnerUID
public int getOwnerSIGID()
{
return owner_sigid;
} // end getOwnerSIGID
public java.util.Date getLastUpdate()
{
return last_update;
} // end getLastUpdate
public boolean getModified()
{
return is_modified;
} // end getModified
public int getStashableUID()
{
return getOwnerUID();
} // end getStashableUID
public void stash(Connection conn) throws DataException, SQLException
{
java.util.Date update = null;
Statement stmt = conn.createStatement();
StringBuffer buf;
if (contactid>=0)
{ // this involves updating an existing record
buf = new StringBuffer("UPDATE contacts SET given_name = ");
buf.append(SQLUtil.encodeStringArg(given_name)).append(", family_name = ");
buf.append(SQLUtil.encodeStringArg(family_name)).append(", middle_init = ");
if (middle_initial==' ')
buf.append("NULL");
else
buf.append('\'').append(middle_initial).append('\'');
buf.append(", prefix = ").append(SQLUtil.encodeStringArg(prefix));
buf.append(", suffix = ").append(SQLUtil.encodeStringArg(suffix));
buf.append(", company = ").append(SQLUtil.encodeStringArg(company));
buf.append(", addr1 = ").append(SQLUtil.encodeStringArg(addr1));
buf.append(", addr2 = ").append(SQLUtil.encodeStringArg(addr2));
buf.append(", locality = ").append(SQLUtil.encodeStringArg(locality));
buf.append(", region = ").append(SQLUtil.encodeStringArg(region));
buf.append(", pcode = ").append(SQLUtil.encodeStringArg(postal_code));
buf.append(", country = ").append(SQLUtil.encodeStringArg(country));
buf.append(", phone = ").append(SQLUtil.encodeStringArg(phone));
buf.append(", fax = ").append(SQLUtil.encodeStringArg(fax));
buf.append(", mobile = ").append(SQLUtil.encodeStringArg(mobile));
buf.append(", email = ").append(SQLUtil.encodeStringArg(email));
buf.append(", pvt_addr = ").append(private_addr ? '1' : '0');
buf.append(", pvt_phone = ").append(private_phone ? '1' : '0');
buf.append(", pvt_fax = ").append(private_fax ? '1' : '0');
buf.append(", pvt_email = ").append(private_email ? '1' : '0');
buf.append(", photo_url = ").append(SQLUtil.encodeStringArg(photo_url));
buf.append(", url = ").append(SQLUtil.encodeStringArg(url)).append(", lastupdate = '");
update = new java.util.Date();
buf.append(SQLUtil.encodeDate(update)).append("' WHERE contactid = ").append(contactid).append(';');
stmt.executeUpdate(buf.toString());
} // end if
else
{ // this involves creating a new record
if (owner_sigid>=0)
stmt.executeUpdate("LOCK TABLES contacts WRITE, sigs WRITE;");
else
stmt.executeUpdate("LOCK TABLES contacts WRITE, users WRITE;");
try
{ // insert contact record data
buf = new StringBuffer("INSERT INTO contacts (given_name, family_name, middle_init, prefix, "
+ "suffix, company, addr1, addr2, locality, region, pcode, country, "
+ "phone, fax, mobile, email, pvt_addr, pvt_phone, pvt_fax, pvt_email, "
+ "owner_uid, owner_sigid, photo_url, url, lastupdate) VALUES (");
buf.append(SQLUtil.encodeStringArg(given_name)).append(", ");
buf.append(SQLUtil.encodeStringArg(family_name)).append(", ");
if (middle_initial==' ')
buf.append("NULL, ");
else
buf.append('\'').append(middle_initial).append("', ");
buf.append(SQLUtil.encodeStringArg(prefix)).append(", ");
buf.append(SQLUtil.encodeStringArg(suffix)).append(", ");
buf.append(SQLUtil.encodeStringArg(company)).append(", ");
buf.append(SQLUtil.encodeStringArg(addr1)).append(", ");
buf.append(SQLUtil.encodeStringArg(addr2)).append(", ");
buf.append(SQLUtil.encodeStringArg(locality)).append(", ");
buf.append(SQLUtil.encodeStringArg(region)).append(", ");
buf.append(SQLUtil.encodeStringArg(postal_code)).append(", ");
buf.append(SQLUtil.encodeStringArg(country)).append(", ");
buf.append(SQLUtil.encodeStringArg(phone)).append(", ");
buf.append(SQLUtil.encodeStringArg(fax)).append(", ");
buf.append(SQLUtil.encodeStringArg(mobile)).append(", ");
buf.append(SQLUtil.encodeStringArg(email)).append(", ");
buf.append(private_addr ? '1' : '0').append(", ");
buf.append(private_phone ? '1' : '0').append(", ");
buf.append(private_fax ? '1' : '0').append(", ");
buf.append(private_email ? '1' : '0').append(", ");
buf.append(owner_uid).append(", ").append(owner_sigid).append(", ");
buf.append(SQLUtil.encodeStringArg(photo_url)).append(", ");
buf.append(SQLUtil.encodeStringArg(url)).append(", '");
update = new java.util.Date();
buf.append(SQLUtil.encodeDate(update)).append("');");
stmt.executeUpdate(buf.toString());
// now read back the contact ID we just added
int new_contactid;
ResultSet rs = stmt.executeQuery("SELECT LAST_INSERT_ID() AS blort;");
if (rs.next())
new_contactid = rs.getInt("blort");
else
throw new DataException("unable to read back new contact ID");
// and patch the database table so we know what our contact ID is
buf.setLength(0);
if (owner_sigid>=0)
{ // update the SIGS table
buf.append("UPDATE sigs SET contactid = ").append(new_contactid).append(" WHERE sigid = ");
buf.append(owner_sigid).append(';');
} // end if
else
{ // update the USERS table
buf.append("UPDATE users SET contactid = ").append(new_contactid).append(" WHERE uid = ");
buf.append(owner_uid).append(';');
} // end else
stmt.executeUpdate(buf.toString());
contactid = new_contactid; // save link
} // end try
finally
{ // make sure the tables get unlocked
Statement ulk_stmt = conn.createStatement();
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally
} // end else
last_update = update; // save last update date
is_modified = false;
} // end stash
} // end class ContactInfoImpl
@@ -0,0 +1,69 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.util.BitSet;
import java.util.List;
import com.silverwrist.venice.security.AuditRecord;
import com.silverwrist.venice.htmlcheck.HTMLChecker;
import com.silverwrist.venice.core.DataException;
public interface EngineBackend
{
public static final int HTMLC_POST_BODY = 0;
public static final int HTMLC_POST_PSEUD = 1;
public static final int HTMLC_PREVIEW_BODY = 2;
public static final int HTMLC_ESCAPE_BODY_PSEUD = 3;
public abstract SimpleEmailer createEmailer();
public abstract String getStockMessage(String key);
public abstract int getNewConfirmationNumber();
public abstract String getCountryNameForCode(String code);
public abstract String getLanguageNameForCode(String code);
public abstract SIGData getSIGDataObject(int sigid) throws DataException;
public abstract BitSet getLockedFeaturesMask();
public abstract List getSIGFeatureSet(BitSet enabled_features, int level, boolean read_privs);
public abstract String getAppletForFeature(int code);
public abstract boolean isValidInitialFeatureIndex(short ndx);
public abstract BitSet getDefaultFeaturesMask();
public abstract void registerNewSIG(SIGData sig);
public abstract int getFeatureIndexBySymbol(String symbol);
public abstract boolean canAccessFeature(String symbol, int level, boolean has_read);
public abstract ConferenceData getConferenceDataObject(int confid) throws DataException;
public abstract void saveAuditRecord(AuditRecord ar);
public abstract void registerNewConference(ConferenceData conf);
public abstract HTMLChecker createCheckerObject(int type);
} // end interface EngineBackend
@@ -0,0 +1,273 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.sql.*;
import java.util.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.db.*;
class FrontPageViewConfigImpl implements FrontPageViewConfig, Stashable
{
private int my_uid;
private int num_cols;
private Vector v_parts = new Vector();
private Vector v_params = new Vector();
private boolean is_modified = false;
FrontPageViewConfigImpl(Connection conn, int uid, int max_cols) throws DataException, SQLException
{
my_uid = uid;
num_cols = max_cols;
StringBuffer sql = new StringBuffer("SELECT row, col, partid, param FROM topconfig WHERE uid = ");
sql.append(uid).append(';');
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql.toString());
while (rs.next())
{ // make sure the column is in range first
int col = rs.getInt("col");
if ((col>=0) && (col<num_cols))
{ // get the row and find out how far down we have to go in the vector
int row = rs.getInt("row");
if (row>=0)
{ // now look for the right arrays to store into
String[] a_part = null;
String[] a_param = null;
if (row>=v_parts.size())
{ // need to extend the vector contents
while (row>=v_parts.size())
{ // append new arrays onto the config
a_part = new String[num_cols];
a_param = new String[num_cols];
for (int i=0; i<num_cols; i++)
{ // nuke the new arrays
a_part[i] = null;
a_param[i] = null;
} // end for
v_parts.addElement(a_part);
v_params.addElement(a_param);
} // end while
} // end if
else
{ // just fetch the existing arrays
a_part = (String[])(v_parts.elementAt(row));
a_param = (String[])(v_params.elementAt(row));
} // end else
// and now save off the recordset data
a_part[col] = rs.getString("partid");
a_param[col] = rs.getString("param");
} // end if
} // end if
} // end while
} // end constructor
public int getNumRows()
{
return v_parts.size();
} // end getNumRows
public int getNumColumns()
{
return num_cols;
} // end getNumCols
public String getPartID(int row, int column)
{
if ((row<0) || (row>=v_parts.size()))
throw new IndexOutOfBoundsException("invalid row specified to FrontPageViewConfig.getPartID");
if ((column<0) || (column>=num_cols))
throw new IndexOutOfBoundsException("invalid column specified to FrontPageViewConfig.getPartID");
String[] array = (String[])(v_parts.elementAt(row));
return array[column];
} // end getPartID
public void setPartID(int row, int column, String partid)
{
if (row<0)
throw new IndexOutOfBoundsException("invalid row specified to FrontPageViewConfig.setPartID");
if ((column<0) || (column>=num_cols))
throw new IndexOutOfBoundsException("invalid column specified to FrontPageViewConfig.setPartID");
String[] a_part = null;
String[] a_param = null;
if (row>=v_parts.size())
{ // need to extend the vector contents
while (row>=v_parts.size())
{ // append new arrays onto the config
a_part = new String[num_cols];
a_param = new String[num_cols];
for (int i=0; i<num_cols; i++)
{ // nuke the new arrays
a_part[i] = null;
a_param[i] = null;
} // end for
v_parts.addElement(a_part);
v_params.addElement(a_param);
} // end while
} // end if
else // just fetch the existing array
a_part = (String[])(v_parts.elementAt(row));
a_part[column] = partid;
is_modified = true;
} // end setPartID
public String getParameter(int row, int column)
{
if ((row<0) || (row>=v_params.size()))
throw new IndexOutOfBoundsException("invalid row specified to FrontPageViewConfig.getParameter");
if ((column<0) || (column>=num_cols))
throw new IndexOutOfBoundsException("invalid column specified to FrontPageViewConfig.getParameter");
String[] array = (String[])(v_params.elementAt(row));
return array[column];
} // end getParameter
public void setParameter(int row, int column, String param)
{
if (row<0)
throw new IndexOutOfBoundsException("invalid row specified to FrontPageViewConfig.setParameter");
if ((column<0) || (column>=num_cols))
throw new IndexOutOfBoundsException("invalid column specified to FrontPageViewConfig.setParameter");
String[] a_part = null;
String[] a_param = null;
if (row>=v_parts.size())
{ // need to extend the vector contents
while (row>=v_parts.size())
{ // append new arrays onto the config
a_part = new String[num_cols];
a_param = new String[num_cols];
for (int i=0; i<num_cols; i++)
{ // nuke the new arrays
a_part[i] = null;
a_param[i] = null;
} // end for
v_parts.addElement(a_part);
v_params.addElement(a_param);
} // end while
} // end if
else // just fetch the existing array
a_param = (String[])(v_params.elementAt(row));
a_param[column] = param;
is_modified = true;
} // end setParameter
public boolean getModified()
{
return is_modified;
} // end getModified
public int getStashableUID()
{
return my_uid;
} // end getStashableUID
public void stash(Connection conn) throws SQLException
{
StringBuffer buf = new StringBuffer();
for (int row=0; row<v_parts.size(); row++)
{ // retrieve the row arrays first
String[] a_part = (String[])(v_parts.elementAt(row));
String[] a_param = (String[])(v_params.elementAt(row));
for (int col=0; col<num_cols; col++)
{ // add to the list as long as the part isn't NULL
if (a_part[col]!=null)
{ // append this set of values to the INSERT we're going to make later
if (buf.length()==0)
buf.append("INSERT INTO topconfig (uid, row, col, partid, param) VALUES ");
else
buf.append(", ");
buf.append('(').append(my_uid).append(", ").append(row).append(", ").append(col).append(", ");
buf.append(SQLUtil.encodeStringArg(a_part[col])).append(", ");
buf.append(SQLUtil.encodeStringArg(a_param[col])).append(')');
} // end if
} // end for (each column)
} // end for (each row)
String insert_cmd = null;
if (buf.length()>0)
{ // we've got the insert command
buf.append(';');
insert_cmd = buf.toString();
buf.setLength(0);
} // end if
// now create the DELETE command
buf.append("DELETE FROM topconfig WHERE uid = ").append(my_uid).append(';');
// we need to lock the topconfig table while we do this
Statement stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES topconfig WRITE;");
try
{ // delete all existing records
stmt.executeUpdate(buf.toString());
// now insert the new records
if (insert_cmd!=null)
stmt.executeUpdate(insert_cmd);
} // end try
finally
{ // make sure to unlock the tables when we're done
Statement ulk_stmt = conn.createStatement();
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally
} // end stash
} // end class FrontPageViewConfigImpl
@@ -0,0 +1,73 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.util.*;
class ReadOnlyVector extends AbstractList
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private Vector my_vec; // local vector
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
ReadOnlyVector(Vector vec)
{
my_vec = vec;
my_vec.trimToSize();
} // end constructor
/*--------------------------------------------------------------------------------
* finalize() method
*--------------------------------------------------------------------------------
*/
protected void finalize() throws Throwable
{
my_vec = null;
super.finalize();
} // end finalize
/*--------------------------------------------------------------------------------
* Implementations from superclass AbstractList
*--------------------------------------------------------------------------------
*/
public Object get(int index)
{
return my_vec.elementAt(index);
} // end get
public int size()
{
return my_vec.size();
} // end size
} // end class ReadOnlyVector
@@ -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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
public interface ReferencedData
{
public abstract int rd_addRef();
public abstract int rd_release();
public abstract boolean rd_unreferenced();
} // end interface ReferencedData
@@ -0,0 +1,59 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
class ReturnConfSeq
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private ConferenceData conf;
private short sequence;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
ReturnConfSeq(ConferenceData conf, short sequence)
{
this.conf = conf;
this.sequence = sequence;
} // end constructor
/*--------------------------------------------------------------------------------
* External operations (usable only inside package)
*--------------------------------------------------------------------------------
*/
ConferenceData getConference()
{
return conf;
} // end getConference
short getSequence()
{
return sequence;
} // end getSequence
} // end class ReturnConfSeq
@@ -0,0 +1,36 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import com.silverwrist.venice.core.DataException;
public interface SIGBackend extends UserBackend
{
public abstract int realSIGID();
public abstract boolean userHideHiddenConferences();
public abstract int realSIGLevel();
public abstract ConferenceSIGContext getConferenceDataObject(int confid) throws DataException;
public abstract boolean userCanCreateSubobjects();
public abstract String realSIGAlias();
} // end interface SIGBackend
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,139 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.util.BitSet;
import java.util.Date;
import java.util.List;
import com.silverwrist.venice.core.AccessError;
import com.silverwrist.venice.core.ContactInfo;
import com.silverwrist.venice.core.DataException;
public interface SIGData extends ReferencedData
{
public abstract int getID();
public abstract String getName();
public abstract String getAlias();
public abstract boolean isPublicSIG();
public abstract int getCategoryID();
public abstract String getSynopsis();
public abstract int getHostUID();
public abstract String getLanguage();
public abstract String getRules();
public abstract int getContactID();
public abstract Date getCreationDate();
public abstract Date getLastAccessDate();
public abstract Date getLastUpdateDate();
public abstract void testMembership(int level, boolean is_member) throws AccessError;
public abstract boolean checkMembership(int level, boolean is_member);
public abstract boolean canReadSIGSubObjects(int level);
public abstract boolean canModifySIGProfile(int level);
public abstract boolean canCreateSIGSubObjects(int level);
public abstract boolean canDeleteSIG(int level);
public abstract boolean canJoinSIG(int uid, int level);
public abstract void putContactInfo(UserBackend user, ContactInfo ci) throws DataException;
public abstract BitSet getFeatureSet();
public abstract void putFeatureSet(UserBackend user, BitSet set) throws DataException;
public abstract List getSIGFeaturesList(int level);
public abstract String getDefaultApplet();
public abstract void setName(UserBackend user, String name) throws DataException;
public abstract void setAlias(UserBackend user, String alias) throws DataException;
public abstract void setCategoryID(UserBackend user, int catid) throws DataException;
public abstract void setSynopsis(String synopsis) throws DataException;
public abstract void setLanguage(String language) throws DataException;
public abstract void setRules(String rules) throws DataException;
public abstract void touch() throws DataException;
public abstract boolean getHideDirectory();
public abstract boolean getHideSearch();
public abstract void setHideFlags(UserBackend user, boolean directory, boolean search) throws DataException;
public abstract boolean getMembersOnly();
public abstract void setMembersOnly(UserBackend user, boolean flag) throws DataException;
public abstract short getInitialFeatureIndex();
public abstract void setInitialFeatureIndex(short ndx) throws DataException;
public abstract String getJoinKey() throws DataException;
public abstract void setJoinKey(UserBackend user, String key) throws DataException;
public abstract int getReadLevel();
public abstract int getWriteLevel();
public abstract int getCreateLevel();
public abstract int getDeleteLevel();
public abstract int getJoinLevel();
public abstract void setSecurityLevels(UserBackend user, int read, int write, int create, int delete,
int join) throws DataException;
public abstract boolean isAdminSIG();
public abstract void setMembership(UserBackend user, int uid, int grant_level, boolean locked,
boolean hidden) throws DataException;
public abstract int getMemberCount(boolean include_hidden) throws DataException;
public abstract boolean isFeaturePresent(String symbol);
public abstract ConferenceSIGContext getConferenceDataObject(int confid) throws DataException;
public abstract ConferenceSIGContext createConference(SIGBackend sig, String name, String alias,
String description, boolean pvt, boolean hide_list)
throws DataException;
} // end interface SIGData
@@ -0,0 +1,24 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
public interface SIGDataBackend
{
public abstract int realSIGID();
} // end interface SIGDataBackend
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,129 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import com.silverwrist.venice.core.EmailException;
import com.silverwrist.venice.core.InternalStateError;
class SimpleEmailer
{
private Session session; // the email session
private MimeMessage msg; // the message being composed
public SimpleEmailer(Properties props, javax.mail.Session session)
{
this.session = session;
msg = new MimeMessage(session);
try
{ // set the X-Mailer header
msg.setHeader("X-Mailer",(String)(props.get("com.silverwrist.venice.email.mailer")));
} // end try
catch (Exception e)
{ // do nothing - we don't really care about this too much
} // end catch
try
{ // set the From address on the message
msg.setFrom(InternetAddress.getLocalAddress(session));
} // end try
catch (MessagingException me)
{ // this should be impossible
throw new InternalStateError("condition should not apply to message here",me);
} // end catch
} // end constructor
public void setTo(String to) throws EmailException
{
try
{ // create an Internet address and set the recipient to it
InternetAddress[] address = { new InternetAddress(to) };
msg.setRecipients(Message.RecipientType.TO,address);
} // end try
catch (AddressException e1)
{ // the address was somehow invalid
throw new EmailException("invalid email recipient address",e1);
} // end catch
catch (MessagingException e2)
{ // msg.setRecipients should NOT be throwing a MessageException here!
throw new InternalStateError("condition should not apply to message here",e2);
} // end catch
} // end setTo
public void setSubject(String subject)
{
try
{ // set the mail message subject
msg.setSubject(subject);
} // end try
catch (MessagingException e2)
{ // msg.setSubject should NOT be throwing a MessageException here!
throw new InternalStateError("condition should not apply to message here",e2);
} // end catch
} // end setSubject
public void setText(String text)
{
try
{ // set the mail message subject
msg.setText(text);
} // end try
catch (MessagingException e2)
{ // msg.setText should NOT be throwing a MessageException here!
throw new InternalStateError("condition should not apply to message here",e2);
} // end catch
} // end setText
public void send() throws EmailException
{
try
{ // attempt to send the transport message
Transport.send(msg);
} // end try
catch (SendFailedException e1)
{ // convert this exception into an EmailException
throw new EmailException("send of the email message failed: " + e1.getMessage(),e1);
} // end catch
catch (MessagingException e2)
{ // msg.setText should NOT be throwing a MessageException here!
throw new InternalStateError("condition should not apply to message here",e2);
} // end catch
} // end send
} // end class SimpleEmailer
@@ -0,0 +1,30 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.sql.Connection;
import java.sql.SQLException;
import com.silverwrist.venice.core.DataException;
public interface Stashable
{
public abstract int getStashableUID();
public abstract void stash(Connection conn) throws DataException, SQLException;
} // end interface Stashable
@@ -0,0 +1,785 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.sql.*;
import java.util.*;
import org.apache.log4j.*;
import com.silverwrist.venice.db.*;
import com.silverwrist.venice.security.AuditRecord;
import com.silverwrist.venice.core.*;
class TopicUserContextImpl implements TopicContext
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(TopicUserContextImpl.class.getName());
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private EngineBackend engine;
private ConferenceBackend conf;
private DataPool datapool;
private int topicid;
private short topicnum;
private int creator_uid;
private int top_message;
private boolean frozen;
private boolean archived;
private java.util.Date created;
private java.util.Date lastupdate;
private String name;
private boolean hidden;
private int unread;
private boolean deleted = false;
/*--------------------------------------------------------------------------------
* Constructors
*--------------------------------------------------------------------------------
*/
protected TopicUserContextImpl(EngineBackend engine, ConferenceBackend conf, DataPool datapool, int topicid,
short topicnum, int creator_uid, int top_message, boolean frozen,
boolean archived, java.util.Date created, java.util.Date lastupdate,
String name, boolean hidden, int unread)
{
this.engine = engine;
this.conf = conf;
this.datapool = datapool;
this.topicid = topicid;
this.topicnum = topicnum;
this.creator_uid = creator_uid;
this.top_message = top_message;
this.frozen = frozen;
this.archived = archived;
this.created = created;
this.lastupdate = lastupdate;
this.name = name;
this.hidden = hidden;
this.unread = unread;
} // end TopicUserContextImpl
/*--------------------------------------------------------------------------------
* Internal functions
*--------------------------------------------------------------------------------
*/
private static ResultSet queryByTopic(Statement stmt, int topicid, int uid) throws SQLException
{
StringBuffer sql =
new StringBuffer("SELECT t.topicid, t.num, t.creator_uid, t.top_message, t.frozen, t.archived, "
+ "t.createdate, t.lastupdate, t.name, IFNULL(s.hidden,0) AS hidden, "
+ "(t.top_message - IFNULL(s.last_message,-1)) AS unread FROM topics t "
+ "LEFT JOIN topicsettings s ON t.topicid = s.topicid AND s.uid = ");
sql.append(uid).append(" WHERE t.topicid = ").append(topicid).append(';');
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
return stmt.executeQuery(sql.toString());
} // end queryByTopic
private void makeDeleted()
{
top_message = -1;
frozen = false;
archived = false;
created = null;
lastupdate = null;
name = null;
hidden = false;
unread = -1;
deleted = true;
} // end if
/*--------------------------------------------------------------------------------
* Implementatuions from interface TopicContext
*--------------------------------------------------------------------------------
*/
public void refresh() throws DataException
{
if (logger.isDebugEnabled())
logger.debug("refreshing topic ID " + String.valueOf(topicid));
Connection conn = null; // pooled database connection
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
// perform a requery of the database
ResultSet rs = queryByTopic(stmt,topicid,conf.realUID());
if (rs.next())
{ // update the fields that are capable of changing
top_message = rs.getInt(4);
frozen = rs.getBoolean(5);
archived = rs.getBoolean(6);
lastupdate = SQLUtil.getFullDateTime(rs,8);
hidden = rs.getBoolean(10);
unread = rs.getInt(11);
} // end if
else // this topic must have been deleted - fsck it
makeDeleted();
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error reading topic data: " + e.getMessage(),e);
throw new DataException("unable to retrieve topic information: " + e.getMessage(),e);
} // end catch
finally
{ // make sure we release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end refresh
public int getTopicID()
{
return topicid;
} // end getTopicID
public short getTopicNumber()
{
return topicnum;
} // end getTopicNumber
public String getName()
{
return name;
} // end getName
public int getUnreadMessages()
{
return unread;
} // end getUnreadMessages
public int getTotalMessages()
{
return top_message + 1;
} // end getTotalMessages
public java.util.Date getLastUpdateDate()
{
return lastupdate;
} // end getLastUpdateDate
public int getCreatorUID()
{
return creator_uid;
} // end getCreatorUID
public boolean isFrozen()
{
return frozen;
} // end isFrozen
public boolean isArchived()
{
return archived;
} // end isArchived
public java.util.Date getCreatedDate()
{
return created;
} // end getCreatedDate
public boolean isHidden()
{
return hidden;
} // end isHidden
public boolean isDeleted()
{
return deleted;
} // end isDeleted
public boolean canFreeze()
{
return conf.userCanHide();
} // end canFreeze
public boolean canArchive()
{
return conf.userCanHide();
} // end canArchive
public void setFrozen(boolean flag) throws DataException, AccessError
{
if ((frozen==flag) || deleted)
return; // no-op
if (!(conf.userCanHide()))
{ // you can't freeze the topic!
logger.error("user cannot change frozen status of topic");
throw new AccessError("You are not permitted to freeze or unfreeze this topic.");
} // end if
Connection conn = null; // pooled database connection
AuditRecord ar = null; // audit record indicating success
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
// create the SQL statement to freeze or unfreeze the topic
StringBuffer sql = new StringBuffer("UPDATE topics SET frozen = ");
sql.append(flag ? '1' : '0').append(" WHERE topicid = ").append(topicid).append(';');
if (stmt.executeUpdate(sql.toString())>0)
{ // success! save the flag and generate an audit record
frozen = flag;
ar = new AuditRecord(AuditRecord.TOPIC_FREEZE,conf.realUID(),conf.userRemoteAddress(),
conf.realSIGID(),"conf=" + String.valueOf(conf.realConfID()) + ",topic="
+ String.valueOf(topicid),flag ? "freeze" : "unfreeze");
} // end if
else // somebody else must have deleted this topic
makeDeleted();
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error setting topic data: " + e.getMessage(),e);
throw new DataException("unable to set topic frozen status: " + e.getMessage(),e);
} // end catch
finally
{ // make sure we release the connection before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setFrozen
public void setArchived(boolean flag) throws DataException, AccessError
{
if ((archived==flag) || deleted)
return; // no-op
if (!(conf.userCanHide()))
{ // you can't archive the topic!
logger.error("user cannot change archived status of topic");
throw new AccessError("You are not permitted to archive or unarchive this topic.");
} // end if
Connection conn = null; // pooled database connection
AuditRecord ar = null; // audit record indicating success
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
// create the SQL statement to freeze or unfreeze the topic
StringBuffer sql = new StringBuffer("UPDATE topics SET archived = ");
sql.append(flag ? '1' : '0').append(" WHERE topicid = ").append(topicid).append(';');
if (stmt.executeUpdate(sql.toString())>0)
{ // success! save the flag and generate an audit record
archived = flag;
ar = new AuditRecord(AuditRecord.TOPIC_ARCHIVE,conf.realUID(),conf.userRemoteAddress(),
conf.realSIGID(),"conf=" + String.valueOf(conf.realConfID()) + ",topic="
+ String.valueOf(topicid),flag ? "archive" : "unarchive");
} // end if
else // somebody else must have deleted this topic
makeDeleted();
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error setting topic data: " + e.getMessage(),e);
throw new DataException("unable to set topic archived status: " + e.getMessage(),e);
} // end catch
finally
{ // make sure we release the connection before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setArchived
public void setHidden(boolean flag) throws DataException
{
if ((hidden==flag) || deleted)
return; // no-op
Connection conn = null; // pooled database connection
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES topicsettings WRITE, topics READ;");
try
{ // start by trying to see if we can update topicsettings directly
StringBuffer sql = new StringBuffer("UPDATE topicsettings SET hidden = ");
sql.append(flag ? '1' : '0').append(" WHERE topicid = ").append(topicid).append(" AND uid = ");
sql.append(conf.realUID()).append(';');
if (stmt.executeUpdate(sql.toString())>0)
{ // that was all we needed - just save the flag and exit
hidden = flag;
return;
} // end if
// OK, check: Is the topic still there?!?
sql.setLength(0);
sql.append("SELECT topicid from topics WHERE topicid = ").append(topicid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString());
if (!(rs.next()))
{ // the topic's been deleted - bail out
makeDeleted();
return;
} // end if
// OK, just insert a new row into topicsettings, why dontcha...
sql.setLength(0);
sql.append("INSERT INTO topicsettings (topicid, uid, hidden) VALUES (").append(topicid).append(", ");
sql.append(conf.realUID()).append(", ").append(flag ? '1' : '0').append(");");
stmt.executeUpdate(sql.toString());
hidden = flag; // successful completion
} // end try
finally
{ // unlock the tables before we go
Statement ulk_stmt = conn.createStatement();
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error setting topic data: " + e.getMessage(),e);
throw new DataException("unable to set topic hidden status: " + e.getMessage(),e);
} // end catch
finally
{ // make sure we release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setHidden
public int getFirstUnreadMessage()
{
if (unread==0)
return -1;
else
return top_message - (unread - 1);
} // end getFirstUnreadMessage
public void setUnreadMessages(int count) throws DataException
{
if (count>(top_message+1)) // constrain count to [0, top_message+1]
count = top_message + 1;
else if (count<0)
count = 0;
if ((count==unread) || deleted)
return; // no-op
int last_msg = top_message - count;
Connection conn = null; // pooled database connection
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate("LOCK TABLES confsettings WRITE, topicsettings WRITE, topics READ;");
try
{ // start by trying to see if we can update topicsettings directly
StringBuffer sql = new StringBuffer("UPDATE topicsettings SET last_message = ");
sql.append(last_msg).append(" WHERE topicid = ").append(topicid).append(" AND uid = ");
sql.append(conf.realUID()).append(';');
if (stmt.executeUpdate(sql.toString())>0)
{ // that was all we needed - just save the flag and exit
conf.touchRead(conn);
unread = count;
return;
} // end if
// OK, check: Is the topic still there?!?
sql.setLength(0);
sql.append("SELECT topicid from topics WHERE topicid = ").append(topicid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString());
if (!(rs.next()))
{ // the topic's been deleted - bail out
makeDeleted();
return;
} // end if
// OK, just insert a new row into topicsettings, why dontcha...
sql.setLength(0);
sql.append("INSERT INTO topicsettings (topicid, uid, last_message) VALUES (").append(topicid);
sql.append(", ").append(conf.realUID()).append(", ").append(last_msg).append(");");
stmt.executeUpdate(sql.toString());
conf.touchRead(conn);
unread = count; // successful completion
} // end try
finally
{ // unlock the tables before we go
Statement ulk_stmt = conn.createStatement();
ulk_stmt.executeUpdate("UNLOCK TABLES;");
} // end finally
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error setting topic data: " + e.getMessage(),e);
throw new DataException("unable to set topic hidden status: " + e.getMessage(),e);
} // end catch
finally
{ // make sure we release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setUnreadMessages
public void fixSeen() throws DataException
{
setUnreadMessages(0);
} // end fixSeen
/*--------------------------------------------------------------------------------
* External operations usable only from within the package
*--------------------------------------------------------------------------------
*/
static List getTopicList(EngineBackend engine, ConferenceBackend conf, DataPool datapool, int get_option,
int sort_option) throws DataException
{
if (logger.isDebugEnabled())
logger.debug("getTopicList for conf # " + String.valueOf(conf.realConfID()) + ", user #"
+ String.valueOf(conf.realUID()));
Vector rc = new Vector(); // return from this function
Connection conn = null; // pooled database connection
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
// Figure out what the "where" clause of the SQL statement will be. This is in addition to a
// WHERE t.confid = (confid) that is always present. (Some of these WHERE specifiers refer to
// computed fields of the SELECT.)
String where_clause;
switch (get_option)
{
case ConferenceContext.GET_ALL:
where_clause = null; // no filtering options
break;
case ConferenceContext.DISPLAY_NEW:
where_clause = "hidden = 0 AND unread > 0"; // only non-hidden topics w/unread messages
break;
case ConferenceContext.DISPLAY_ACTIVE:
where_clause = "t.archived = 0 AND hidden = 0"; // only non-hidden, non-archived topics
break;
case ConferenceContext.DISPLAY_ALL:
where_clause = "t.archived = 0 AND hidden = 0"; // only non-hidden, non-archived topics
break;
case ConferenceContext.DISPLAY_HIDDEN:
where_clause = "hidden = 1"; // only hidden topics
break;
case ConferenceContext.DISPLAY_ARCHIVED:
where_clause = "t.archived = 1 AND hidden = 0"; // only non-hidden, archived topics
break;
default:
logger.error("ACK! get_option (" + String.valueOf(get_option) + ") is bogus!");
throw new DataException("Invalid retrieval option specified.");
} // end switch
// Figure out what the "order by" clause of the SQL statement will be. In the case of
// DISPLAY_NEW mode, this will be in addition to an ordering clause that puts all topics
// with unread messages first.
boolean reverse = false;
int real_sort_option = sort_option;
if (sort_option<0)
{ // did we specify a "reverse" option?
reverse = true;
real_sort_option = -sort_option;
} // end if
String order_by_clause;
switch (real_sort_option)
{
case ConferenceContext.SORT_TOPICID:
// no reverse possible here
order_by_clause = "t.topicid ASC";
break;
case ConferenceContext.SORT_NUMBER:
if (reverse)
order_by_clause = "t.num DESC";
else
order_by_clause = "t.num ASC";
break;
case ConferenceContext.SORT_NAME:
if (reverse)
order_by_clause = "t.name DESC, t.num DESC";
else
order_by_clause = "t.name ASC, t.num ASC";
break;
case ConferenceContext.SORT_UNREAD:
if (reverse)
order_by_clause = "unread ASC, t.num DESC";
else
order_by_clause = "unread DESC, t.num ASC";
break;
case ConferenceContext.SORT_TOTAL:
if (reverse)
order_by_clause = "t.top_message ASC, t.num DESC";
else
order_by_clause = "t.top_message DESC, t.num ASC";
break;
case ConferenceContext.SORT_DATE:
if (reverse)
order_by_clause = "t.lastupdate ASC, t.num DESC";
else
order_by_clause = "t.lastupdate DESC, t.num ASC";
break;
default:
logger.error("ACK! sort_option (" + String.valueOf(sort_option) + ") is bogus!");
throw new DataException("Invalid sort option specified.");
} // end switch
// Build the huge SQL statement to feed to the database.
StringBuffer sql =
new StringBuffer("SELECT t.topicid, t.num, t.creator_uid, t.top_message, t.frozen, t.archived, "
+ "t.createdate, t.lastupdate, t.name, IFNULL(s.hidden,0) AS hidden, "
+ "(t.top_message - IFNULL(s.last_message,-1)) AS unread");
if (get_option==ConferenceContext.DISPLAY_ACTIVE)
sql.append(", SIGN(t.top_message - IFNULL(s.last_message,-1)) AS newflag");
sql.append(" FROM topics t LEFT JOIN topicsettings s ON t.topicid = s.topicid AND s.uid = ");
sql.append(conf.realUID()).append(" WHERE t.confid = ").append(conf.realConfID());
if (where_clause!=null)
sql.append(" AND ").append(where_clause);
sql.append(" ORDER BY ");
if (get_option==ConferenceContext.DISPLAY_ACTIVE)
sql.append("newflag DESC, ");
sql.append(order_by_clause).append(';');
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
// Now pass this query off to the database!
ResultSet rs = stmt.executeQuery(sql.toString());
while (rs.next())
{ // create the returned objects and add them to the vector
TopicContext top =
new TopicUserContextImpl(engine,conf,datapool,rs.getInt(1),rs.getShort(2),rs.getInt(3),
rs.getInt(4),rs.getBoolean(5),rs.getBoolean(6),
SQLUtil.getFullDateTime(rs,7),SQLUtil.getFullDateTime(rs,8),
rs.getString(9),rs.getBoolean(10),rs.getInt(11));
rc.add(top);
} // end while
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error reading topic entries: " + e.getMessage(),e);
throw new DataException("unable to retrieve topic information: " + e.getMessage(),e);
} // end catch
finally
{ // make sure we release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
return new ReadOnlyVector(rc);
} // end getTopicList
static TopicContext getTopicByID(EngineBackend engine, ConferenceBackend conf, DataPool datapool,
int topicid) throws DataException
{
if (logger.isDebugEnabled())
logger.debug("getTopicByID for topic # " + String.valueOf(topicid) + ", user #"
+ String.valueOf(conf.realUID()));
Connection conn = null; // pooled database connection
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
// Query the dtabase by topic ID.
ResultSet rs = queryByTopic(stmt,topicid,conf.realUID());
if (rs.next()) // found it!
return new TopicUserContextImpl(engine,conf,datapool,topicid,rs.getShort(2),rs.getInt(3),
rs.getInt(4),rs.getBoolean(5),rs.getBoolean(6),
SQLUtil.getFullDateTime(rs,7),SQLUtil.getFullDateTime(rs,8),
rs.getString(9),rs.getBoolean(10),rs.getInt(11));
// else fall out and return null
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error reading topic entries: " + e.getMessage(),e);
throw new DataException("unable to retrieve topic information: " + e.getMessage(),e);
} // end catch
finally
{ // make sure we release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
return null; // default return
} // end getTopicByID
static TopicContext getTopicByNumber(EngineBackend engine, ConferenceBackend conf, DataPool datapool,
short topicnum) throws DataException
{
if (logger.isDebugEnabled())
logger.debug("getTopicByNumber for topic # " + String.valueOf(topicnum) + ", conf # "
+ String.valueOf(conf.realConfID()) + ", user #" + String.valueOf(conf.realUID()));
Connection conn = null; // pooled database connection
try
{ // get a database connection
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
// Build the database query.
StringBuffer sql =
new StringBuffer("SELECT t.topicid, t.num, t.creator_uid, t.top_message, t.frozen, t.archived, "
+ "t.createdate, t.lastupdate, t.name, IFNULL(s.hidden,0) AS hidden, "
+ "(t.top_message - IFNULL(s.last_message,-1)) AS unread FROM topics t "
+ "LEFT JOIN topicsettings s ON t.topicid = s.topicid AND s.uid = ");
sql.append(conf.realUID()).append(" WHERE t.confid = ").append(conf.realConfID());
sql.append(" AND t.num = ").append(topicnum).append(';');
if (logger.isDebugEnabled())
logger.debug("SQL: " + sql.toString());
// Now pass this query off to the database!
ResultSet rs = stmt.executeQuery(sql.toString());
if (rs.next()) // found it!
return new TopicUserContextImpl(engine,conf,datapool,rs.getInt(1),topicnum,rs.getInt(3),
rs.getInt(4),rs.getBoolean(5),rs.getBoolean(6),
SQLUtil.getFullDateTime(rs,7),SQLUtil.getFullDateTime(rs,8),
rs.getString(9),rs.getBoolean(10),rs.getInt(11));
// else fall out and return null
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error reading topic entries: " + e.getMessage(),e);
throw new DataException("unable to retrieve topic information: " + e.getMessage(),e);
} // end catch
finally
{ // make sure we release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
return null; // default return
} // end getTopicByNumber
} // end class TopicUserContextImpl
@@ -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 <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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import com.silverwrist.venice.core.DataException;
public interface UserBackend
{
public abstract int realUID();
public abstract int realBaseLevel();
public abstract String userRemoteAddress();
public abstract String userDefaultPseud() throws DataException;
} // end interface UserBackend
@@ -0,0 +1,988 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.util.*;
import java.sql.*;
import org.apache.log4j.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.db.*;
import com.silverwrist.venice.security.PasswordHash;
import com.silverwrist.venice.security.Capability;
import com.silverwrist.venice.security.DefaultLevels;
import com.silverwrist.venice.security.AuditRecord;
class UserContextImpl implements UserContext, UserBackend
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(UserContextImpl.class.getName());
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private EngineBackend engine; // the back end of the engine
private DataPool datapool; // the data pool used by this object
private String remote_addr; // remote address identifier
private int uid = -1; // the user ID we're using
private int contactid; // ID of our contact information
private int level; // base security level for this user
private int confirm_num; // email confirmation number for this user
private boolean is_anon = false; // is this the anonymous user?
private boolean email_verified = false; // has email address been verified?
private String username; // the user name we're using
private java.util.Date created; // when was this user created? (GMT)
private java.util.Date last_access; // when did we last log in? (GMT)
private String description; // personal description
private String my_email = null; // my email address (cached)
private String my_pseud = null; // my pseud (cached)
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
UserContextImpl(EngineBackend engine, DataPool datapool)
{
this.engine = engine;
this.datapool = datapool;
} // end constructor
/*--------------------------------------------------------------------------------
* finalize() method
*--------------------------------------------------------------------------------
*/
protected void finalize()
{
engine = null;
datapool = null;
username = null;
created = null;
last_access = null;
} // end finalize
/*--------------------------------------------------------------------------------
* Internal functions
*--------------------------------------------------------------------------------
*/
private void loadUserData(ResultSet rs) throws SQLException
{
uid = rs.getInt("uid");
username = rs.getString("username");
// skip field "passhash"
contactid = rs.getInt("contactid");
is_anon = rs.getBoolean("is_anon");
email_verified = rs.getBoolean("verify_email");
// skip fields "lockout", "access_tries"
confirm_num = rs.getInt("email_confnum");
level = rs.getInt("base_lvl");
created = SQLUtil.getFullDateTime(rs,"created");
last_access = SQLUtil.getFullDateTime(rs,"lastaccess");
// skip field "passreminder"
description = rs.getString("description");
if (logger.isDebugEnabled())
{ // spit it all out to debug info
logger.debug("Loaded: UID " + String.valueOf(uid) + ", username \"" + username + "\", contactid "
+ String.valueOf(contactid));
logger.debug("...is_anon " + String.valueOf(is_anon) + ", email_verified "
+ String.valueOf(email_verified));
logger.debug("... level " + String.valueOf(level));
} // end if
} // end loadUserData
private void sendEmailConfirmation() throws DataException, EmailException
{
if (logger.isDebugEnabled())
logger.debug("sendEmailConfirmation(): sending to \"" + my_email + "\"");
// Create the message to be sent.
String message = engine.getStockMessage("email-confirm");
if (message==null)
{ // no message defined? oy!
logger.error("internal error condition: email-confirm stock message not defined");
throw new DataException("INTERNAL: email-confirm message not defined");
} // end if
message = StringUtil.replaceAllInstances(message,"$USERNAME",username);
message = StringUtil.replaceAllInstances(message,"$CONFNUM",String.valueOf(confirm_num));
// Create the emailer and send the message.
SimpleEmailer emailer = engine.createEmailer();
emailer.setTo(my_email);
emailer.setSubject("Venice Email Confirmation");
emailer.setText(message);
emailer.send();
if (logger.isDebugEnabled())
logger.debug("...email sent!");
} // end sendEmailConfirmation
/*--------------------------------------------------------------------------------
* Implementations from interface UserContext
*--------------------------------------------------------------------------------
*/
public int getUID()
{
return uid;
} // end getUID
public String getUserName()
{
return username;
} // end getUserName
public int getContactID()
{
return contactid;
} // end getContactID
public String getDescription()
{
return description;
} // end getDescription
public boolean isLoggedIn()
{
if (logger.isDebugEnabled())
logger.debug("isLoggedIn(): uid = " + String.valueOf(uid) + ", is_anon = " + String.valueOf(is_anon));
return ((uid!=-1) && !is_anon);
} // end is_logged_in
public boolean isEmailVerified()
{
return email_verified;
} // end isEmailVerified
public void authenticate(String username, String password) throws AccessError, DataException
{
if (isLoggedIn())
{ // already authenticated, can't authenticate again
logger.error("UserContext already authenticated (with uid " + String.valueOf(uid) + ")");
throw new InternalStateError("context already authenticated");
} // end if
if (logger.isDebugEnabled())
logger.debug("authenticate(): authenticating user \"" + username + "\"...");
Connection conn = null;
AuditRecord ar = null;
try
{ // look for a user name matching this user record
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE username = '"
+ SQLUtil.encodeString(username) + "';");
if (!(rs.next()))
{ // user not found
logger.error("...user not found");
ar = new AuditRecord(AuditRecord.LOGIN_FAIL,0,remote_addr,"Bad username: " + username);
throw new AccessError("The user account you have specified does not exist. Please try again.");
} // end if
int the_uid = rs.getInt("uid");
if (rs.getBoolean("is_anon"))
{ // can't log in as Anonymous Honyak
logger.error("...user is the Anonymous Honyak, can't explicitly login");
ar = new AuditRecord(AuditRecord.LOGIN_FAIL,the_uid,remote_addr,"Anonymous user");
throw new AccessError("This account cannot be explicitly logged into. Please try again.");
} // end if
if (rs.getBoolean("lockout"))
{ // account locked out
logger.error("...user is locked out by the Admin");
ar = new AuditRecord(AuditRecord.LOGIN_FAIL,the_uid,remote_addr,"Account locked out");
throw new AccessError("This account has been administratively locked out. Please contact "
+ "the system administrator for assistance.");
} // end if
// hash the password and compare it to the stored password hash
PasswordHash phash = new PasswordHash(password);
if (!(phash.equals(rs.getString("passhash"))))
{ // they specified an incorrect password
// TODO: advance an "invalid" counter and lock the account out if more than X tries
logger.warn("...invalid password");
ar = new AuditRecord(AuditRecord.LOGIN_FAIL,the_uid,remote_addr,"Bad password");
throw new AccessError("The password you have specified is incorrect. Please try again.");
} // end if
if (logger.isDebugEnabled())
logger.debug("...authenticated");
// we're authenticated - load the user data into the context
loadUserData(rs);
// update the "last access" time in the database
java.util.Date mydate = new java.util.Date();
stmt.executeUpdate("UPDATE users SET lastaccess = '" + SQLUtil.encodeDate(mydate)
+ "' WHERE uid = " + uid + ";");
// update the "last access" time in this object
last_access = mydate;
// an audit record indicating we logged in OK
ar = new AuditRecord(AuditRecord.LOGIN_OK,the_uid,remote_addr);
if (logger.isDebugEnabled())
logger.debug("...context loaded, we're ready :-)");
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error reading user data: " + e.getMessage(),e);
throw new DataException("unable to access user data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end if
} // end authenticate
public void confirmEmail(int conf_num) throws AccessError, DataException
{
if (logger.isDebugEnabled())
logger.debug("confirmEmail(): confirming for UID " + String.valueOf(uid));
if ((email_verified) || Capability.exemptFromEmailVerification(level))
{ // already confirmed
if (logger.isDebugEnabled())
logger.debug("...user has either already confirmed or is exempt");
return;
} // end if
AuditRecord ar = null;
if (conf_num!=confirm_num)
{ // the confirmation number is wrong
logger.warn("...confirmation number incorrect");
ar = new AuditRecord(AuditRecord.VERIFY_FAIL,uid,remote_addr,"Invalid confirmation number");
engine.saveAuditRecord(ar);
throw new AccessError("Confirmation number is incorrect. Please try again.");
} // end if
Connection conn = null;
try
{ // get a connection and set the user's status to reflect the verification
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = 1, base_lvl = ");
sql.append(DefaultLevels.afterEmailVerification()).append(" WHERE uid = ").append(uid).append(';');
stmt.executeUpdate(sql.toString());
email_verified = true;
level = DefaultLevels.afterEmailVerification();
// record an audit message indicating that we verified OK
ar = new AuditRecord(AuditRecord.VERIFY_OK,uid,remote_addr);
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error updating user data: " + e.getMessage(),e);
throw new DataException("unable to update user data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end if
} // end confirmEmail
public void resendEmailConfirmation() throws DataException, EmailException
{
if (logger.isDebugEnabled())
logger.debug("resendEmailConfirmation(): resending for UID " + String.valueOf(uid));
if ((email_verified) || Capability.exemptFromEmailVerification(level))
{ // already confirmed, no need to resend
if (logger.isDebugEnabled())
logger.debug("...user has either already confirmed or is exempt");
return;
} // end if
if (my_email==null)
getContactInfo(); // forces my_email to be updated
Connection conn = null;
AuditRecord ar = null;
try
{ // need to change the user's email confirmation number first
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
// generate new confirmation number
int new_confirm_num = engine.getNewConfirmationNumber();
// create an SQL statement to reset the user account information, and execute it
StringBuffer sql = new StringBuffer("UPDATE users SET email_confnum = ");
sql.append(new_confirm_num).append(" WHERE uid = ").append(uid).append(';');
stmt.executeUpdate(sql.toString());
confirm_num = new_confirm_num; // save changed value
// now send the email confirmation!
sendEmailConfirmation();
// log that a resend was performed...
ar = new AuditRecord(AuditRecord.RESEND_CONFIRM,uid,remote_addr);
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error updating user data: " + e.getMessage(),e);
throw new DataException("unable to update user data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end if
} // end resendEmailConfirmation
public ContactInfo getContactInfo() throws DataException
{
ContactInfoImpl rc;
if (contactid>=0)
rc = new ContactInfoImpl(datapool,contactid);
else
rc = new ContactInfoImpl(uid);
if (my_email==null)
my_email = rc.getEmail();
if (my_pseud==null)
my_pseud = rc.getGivenName() + " " + rc.getFamilyName();
return rc;
} // end getContactInfo
public boolean putContactInfo(ContactInfo ci) throws DataException, EmailException
{
boolean email_changed = false;
if ((ci.getOwnerUID()!=uid) || (ci.getOwnerSIGID()>=0))
{ // the contact information is not owned correctly
logger.error("ContactInfo ownership wrong (it's " + String.valueOf(ci.getOwnerUID()) + ", "
+ String.valueOf(ci.getOwnerSIGID()) + "), should be (" + String.valueOf(uid) + ", -1)");
throw new DataException("invalid contact information record");
} // end if
if (is_anon)
{ // we can't change Anonymous Honyak this way!
logger.error("cannot modify anonymous user contact info");
throw new DataException("unmodifiable contact information");
} // end if
Connection conn = null; // database connection
AuditRecord ar = null; // audit record
try
{ // get a database connection
conn = datapool.getConnection();
Stashable obj = (Stashable)ci;
// save the contact information
obj.stash(conn);
if (contactid<0)
{ // contact being established for the first time
contactid = ci.getContactID();
if (logger.isDebugEnabled())
logger.debug("...established initial contact (" + String.valueOf(contactid) + ") for user");
my_email = ci.getEmail();
sendEmailConfirmation();
email_changed = true;
} // end if
my_pseud = ci.getGivenName() + " " + ci.getFamilyName(); // update this field
if (my_email==null) // filling in, this is not necessarily the first time
my_email = ci.getEmail();
else if (!(my_email.equals(ci.getEmail())) && !Capability.exemptFromEmailVerification(level))
{ // email address change - need to reconfirm - but choose a new confirmation
// number and save it in the database first; also turn off the verify flag
// and set the base level to GLOBAL_UNVERIFIED
// NOTE: Administrators are exempt from this requirement!
if (logger.isDebugEnabled())
logger.debug("email address changed, need to reconfirm");
// generate new confirmation number
int new_confirm_num = engine.getNewConfirmationNumber();
// create an SQL statement to reset the user account information, and execute it
StringBuffer sql = new StringBuffer("UPDATE users SET verify_email = 0, email_confnum = ");
sql.append(new_confirm_num).append(", base_lvl = ").append(DefaultLevels.afterEmailAddressChange());
sql.append(" WHERE uid = ").append(uid).append(';');
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql.toString());
// save off changed data
email_verified = false;
confirm_num = new_confirm_num;
level = DefaultLevels.afterEmailAddressChange();
// now send the email confirmation!
sendEmailConfirmation();
email_changed = true;
} // end else if
ar = new AuditRecord(AuditRecord.USER_CONTACT_INFO,uid,remote_addr,
"contactid=" + String.valueOf(contactid));
} // end try
catch (ClassCastException cce)
{ // we need to be able to coerce the ContactInfo to a Stashable
logger.error("ContactInfo needs to be a Stashable for this to work");
throw new DataException("improper contact information record");
} // end catch
catch (SQLException e)
{ // database error - this is a DataException
logger.error("DB error updating contact info: " + e.getMessage(),e);
throw new DataException("unable to access user contact data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end if
return email_changed;
} // end putContactInfo
public UserProfile getProfile(String xusername) throws DataException
{
if (logger.isDebugEnabled())
logger.debug("getProfile(\"" + xusername + "\")...");
Connection conn = null;
try
{ // retrieve a connection from the data pool
conn = datapool.getConnection();
UserProfileImpl prof = new UserProfileImpl(engine,conn,xusername,
Capability.canSeeHiddenContactFields(level));
if (logger.isDebugEnabled())
logger.debug("...found it!");
return prof;
} // end catch
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error looking up profile information: " + e.getMessage(),e);
throw new DataException("Unable to look up user info: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end getProfile
public UserProfile getProfile(int xuid) throws DataException
{
if (logger.isDebugEnabled())
logger.debug("getProfile(#" + String.valueOf(xuid) + ")...");
Connection conn = null;
try
{ // retrieve a connection from the data pool
conn = datapool.getConnection();
UserProfileImpl prof = new UserProfileImpl(engine,conn,xuid,Capability.canSeeHiddenContactFields(level));
if (logger.isDebugEnabled())
logger.debug("...found it!");
return prof;
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error looking up profile information: " + e.getMessage(),e);
throw new DataException("Unable to look up user info: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end getProfile
public void setPassword(String password, String reminder) throws DataException
{
if (is_anon)
{ // trying to change Anonymous Honyak's (nonexistent) password?
logger.error("cannot change password of anonymous account");
throw new DataException("The anonymous account cannot change its password.");
} // end if
Connection conn = null;
AuditRecord ar = null;
try
{ // retrieve a connection from the data pool
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
PasswordHash phash = new PasswordHash(password);
StringBuffer sql = new StringBuffer("UPDATE users SET passhash = '");
sql.append(phash.toString()).append("', passreminder = '").append(SQLUtil.encodeString(reminder));
sql.append("' WHERE uid = ").append(uid).append(';');
stmt.executeUpdate(sql.toString());
// record an audit record for this user
ar = new AuditRecord(AuditRecord.PASSWORD_CHANGE,uid,remote_addr);
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error changing password: " + e.getMessage(),e);
throw new DataException("Unable to set user password: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
try
{ // save off the audit record before we go, though
if ((ar!=null) && (conn!=null))
ar.store(conn);
} // end try
catch (SQLException e)
{ // we couldn't store the audit record!
logger.error("DB error saving audit record: " + e.getMessage(),e);
} // end catch
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setPassword
public void setDescription(String new_descr) throws DataException
{
if (is_anon)
{ // trying to change Anonymous Honyak's (nonexistent) description?
logger.error("cannot change description of anonymous account");
throw new DataException("The anonymous account cannot change its description.");
} // end if
Connection conn = null;
try
{ // retrieve a connection from the data pool
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("UPDATE users SET description = '");
sql.append(SQLUtil.encodeString(new_descr)).append("' WHERE uid = ").append(uid).append(';');
stmt.executeUpdate(sql.toString());
description = new_descr; // change stored information
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error changing description: " + e.getMessage(),e);
throw new DataException("Unable to set user description: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end setDescription
public FrontPageViewConfig getFrontPageViewConfig(int max_cols) throws DataException
{
Connection conn = null;
try
{ // retrieve a connection from the data pool
conn = datapool.getConnection();
// create new object
return new FrontPageViewConfigImpl(conn,uid,max_cols);
} // end try
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error getting front page view config: " + e.getMessage(),e);
throw new DataException("unable to retrieve front page view config: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end getFrontPageViewConfig
public void putFrontPageViewConfig(FrontPageViewConfig cfg) throws DataException
{
Connection conn = null;
try
{ // coerce the value to a Stashable first
Stashable obj = (Stashable)cfg;
if (obj.getStashableUID()!=uid)
{ // wrong UID for configuration - this is bogus
logger.error("invalid ownership of FrontPageViewConfig (was "
+ String.valueOf(obj.getStashableUID()) + ", should be " + String.valueOf(uid) + ")");
throw new DataException("invalid front page view config record");
} // end if
// retrieve a connection from the data pool
conn = datapool.getConnection();
// stash the object
obj.stash(conn);
} // end try
catch (ClassCastException cce)
{ // we need to be able to coerce the FrontPageViewConfig to a Stashable
logger.error("FrontPageViewConfig was not a Stashable");
throw new DataException("improper front page view config record");
} // end catch
catch (SQLException e)
{ // turn SQLException into data exception
logger.error("DB error saving front page view config: " + e.getMessage(),e);
throw new DataException("unable to save front page view config: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end putFrontPageViewConfig
public List getMemberSIGs() throws DataException
{
return SIGUserContextImpl.getMemberSIGEntries(engine,this,datapool);
} // end getMemberSIGs
public SIGContext getSIGContext(int sigid) throws DataException
{
return SIGUserContextImpl.getSIGContext(engine,this,datapool,sigid);
} // end getSIGContext
public SIGContext getSIGContext(String alias) throws DataException
{
return SIGUserContextImpl.getSIGContext(engine,this,datapool,alias);
} // end getSIGContext
public List getRootCategoryList() throws DataException
{
return CategoryDescriptorImpl.getTopLevelCategoryList(datapool,Capability.hideHiddenCategories(level));
} // end getRootCategoryList
public CategoryDescriptor getCategoryDescriptor(int catid) throws DataException
{
return new CategoryDescriptorImpl(datapool,catid,Capability.hideHiddenCategories(level));
} // end getCategoryDescriptor
public List searchForSIGs(int field, int mode, String term, int offset, int count) throws DataException
{
return SIGUserContextImpl.searchForSIGs(engine,this,datapool,field,mode,term,offset,count);
} // end searchForSIGs
public int getSearchSIGCount(int field, int mode, String term) throws DataException
{
return SIGUserContextImpl.getSearchSIGCount(this,datapool,field,mode,term);
} // end getSearchSIGCount
public List getSIGsInCategory(int catid, int offset, int count) throws DataException
{
return SIGUserContextImpl.getSIGsInCategory(engine,this,datapool,catid,offset,count);
} // end getSIGsInCategory
public List getSIGsInCategory(CategoryDescriptor cat, int offset, int count) throws DataException
{
return SIGUserContextImpl.getSIGsInCategory(engine,this,datapool,cat.getLinkedCategoryID(),offset,count);
} // end getSIGsInCategory
public int getNumSIGsInCategory(int catid) throws DataException
{
return SIGUserContextImpl.getNumSIGsInCategory(this,datapool,catid);
} // end getNumSIGsInCategory
public int getNumSIGsInCategory(CategoryDescriptor cat) throws DataException
{
return SIGUserContextImpl.getNumSIGsInCategory(this,datapool,cat.getLinkedCategoryID());
} // end getNumSIGsInCategory
public List searchForCategories(int mode, String term, int offset, int count) throws DataException
{
return CategoryDescriptorImpl.searchForCategories(datapool,Capability.hideHiddenCategories(level),
Capability.showHiddenSearchCategories(level),mode,
term,offset,count);
} // end searchForCategories
public int getSearchCategoryCount(int mode, String term) throws DataException
{
return CategoryDescriptorImpl.getSearchCategoryCount(datapool,Capability.hideHiddenCategories(level),
Capability.showHiddenSearchCategories(level),
mode,term);
} // end getSearchCategoryCount
public SIGContext createSIG(String name, String alias, String language, String synopsis, String rules,
String joinkey, int hide_mode) throws DataException, AccessError
{
if (!(Capability.canCreateSIG(level)))
throw new AccessError("You are not authorized to create new SIGs.");
// Convert the "hide mode" value int othe two hide flags.
boolean hide_dir = (hide_mode!=SIGContext.HIDE_NONE);
boolean hide_search = (hide_mode==SIGContext.HIDE_BOTH);
// Create the new SIG's database entries and internal data.
SIGData new_sig = SIGCoreData.createSIG(engine,this,datapool,name,alias,uid,language,synopsis,rules,
joinkey,hide_dir,hide_search);
// Create the SIG context we return to the user.
SIGContext rc = new SIGUserContextImpl(engine,this,datapool,new_sig);
new_sig.rd_release(); // release the extra reference we have on SIGData
// And that's it! You expected lightning bolts maybe? :-)
return rc;
} // end createSIG
public boolean canCreateSIG()
{
return Capability.canCreateSIG(level);
} // end canCreateSIG
/*--------------------------------------------------------------------------------
* Implementations from interface UserBackend
*--------------------------------------------------------------------------------
*/
public int realUID()
{
return uid;
} // end realUID
public int realBaseLevel()
{
return level;
} // end realBaseLevel
public String userRemoteAddress()
{
return remote_addr;
} // end userRemoteAddress
public String userDefaultPseud() throws DataException
{
if (my_pseud==null)
getContactInfo();
return my_pseud;
} // end userDefaultPseud
/*--------------------------------------------------------------------------------
* Operations private to implementation package
*--------------------------------------------------------------------------------
*/
void loadAnonymous(String remote_addr) throws DataException
{
Connection conn = null;
if (logger.isDebugEnabled())
logger.debug("loadAnonymous() on UserContext: addr " + remote_addr);
try
{ // retrieve a connection from the data pool
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE is_anon = 1;");
if (!(rs.next()))
{ // could not find the anonymous user - this is an internal error
logger.error("WTF? anonymous user not found?!?");
throw new DataException("INTERNAL ERROR - cannot find anonymous user");
} // end if
loadUserData(rs); // load the data for Anonymous Honyak
this.remote_addr = remote_addr;
} // end try
catch (SQLException e)
{ // database error - this is a DataException
logger.error("error loading anonymous user data: " + e.getMessage(),e);
throw new DataException("unable to access user data: " + e.getMessage(),e);
} // end catch
finally
{ // make sure the connection is released before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
} // end loadAnonymous
void loadNewUser(String remote_addr, int uid, int level, String username, int confirm_num,
java.util.Date created, java.util.Date last_access)
{
if (logger.isDebugEnabled())
logger.debug("loadNewUser() on UserContext: addr " + remote_addr + ", uid " + String.valueOf(uid)
+ ", level " + String.valueOf(level) + ", username \"" + username + "\"");
this.remote_addr = remote_addr;
this.uid = uid;
this.contactid = -1;
this.level = level;
this.username = username;
this.confirm_num = confirm_num;
this.created = created;
this.last_access = last_access;
} // end loadNewUser
} // end class UserContextImpl
@@ -0,0 +1,132 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import com.silverwrist.venice.core.*;
class UserFoundImpl implements UserFound
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private int uid;
private String name;
private String description;
private String given_name;
private String family_name;
private String locality;
private String region;
private String country;
private int level = -1;
/*--------------------------------------------------------------------------------
* Constructors
*--------------------------------------------------------------------------------
*/
UserFoundImpl(int uid, String name, String description, String given_name, String family_name,
String locality, String region, String country)
{
this.uid = uid;
this.name = name;
this.description = description;
this.given_name = given_name;
this.family_name = family_name;
this.locality = locality;
this.region = region;
this.country = country;
} // end constructor
UserFoundImpl(int uid, String name, String description, String given_name, String family_name,
String locality, String region, String country, int level)
{
this.uid = uid;
this.name = name;
this.description = description;
this.given_name = given_name;
this.family_name = family_name;
this.locality = locality;
this.region = region;
this.country = country;
this.level = level;
} // end constructor
/*--------------------------------------------------------------------------------
* Implementations from interface UserFound
*--------------------------------------------------------------------------------
*/
public int getUID()
{
return uid;
} // end getUID
public String getName()
{
return name;
} // end getName
public String getDescription()
{
return description;
} // end getDescription
public String getGivenName()
{
return given_name;
} // end getGivenName
public String getFamilyName()
{
return family_name;
} // end getFamilyName
public String getLocality()
{
return locality;
} // end getLocality
public String getRegion()
{
return region;
} // end getRegion
public String getCountry()
{
return country;
} // end getCountry
public int getLevel()
{
return level;
} // end getLevel
} // end class UserFoundImpl
@@ -0,0 +1,347 @@
/*
* 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 Community 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) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.core.impl;
import java.sql.*;
import java.util.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.db.*;
class UserProfileImpl implements UserProfile
{
private EngineBackend engine; // the engine back end
private int uid; // user ID
private String username; // user name
private String given_name; // given name ("first name")
private String family_name; // family name ("last name")
private char middle_initial; // middle initial (natch)
private String prefix; // prefix (Mr., Ms., Prof., Dr., etc.)
private String suffix; // suffix (Jr., III, etc.)
private String company; // company name
private String addr1; // address line 1
private String addr2; // address line 2
private String locality; // locality ("city")
private String region; // region ("state")
private String postal_code; // postal code ("ZIP code")
private String country; // 2-character ISO 3166 country code
private String phone; // voice phone number
private String fax; // facsimile (fax) number
private String mobile; // mobile phone (cellphone) number
private String email; // email address
private String photo_url; // URL of user photo
private String url; // URL of user's homepage
private String descr; // user's self-description
private java.util.Date created; // date created
private java.util.Date last_login; // date of last login
private java.util.Date last_update; // date of last update
private String real_email; // real email address
UserProfileImpl(EngineBackend engine, Connection conn, String username, boolean override)
throws DataException, SQLException
{
this.engine = engine;
// first retrieve from the users table
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT uid, username, contactid, created, lastaccess, description "
+ "FROM users WHERE username = '");
sql.append(SQLUtil.encodeString(username)).append("';");
ResultSet rs = stmt.executeQuery(sql.toString());
if (!(rs.next()))
throw new DataException("User '" + username + "' not found.");
// load the "elementary" fields
this.uid = rs.getInt("uid");
this.username = rs.getString("username");
int contact_id = rs.getInt("contactid");
created = SQLUtil.getFullDateTime(rs,"created");
last_login = SQLUtil.getFullDateTime(rs,"lastaccess");
descr = rs.getString("description");
loadContact(conn,contact_id,override);
} // end constructor
UserProfileImpl(EngineBackend engine, Connection conn, int uid, boolean override)
throws DataException, SQLException
{
this.engine = engine;
// first retrieve from the users table
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT uid, username, contactid, created, lastaccess, description "
+ "FROM users WHERE uid = ");
sql.append(uid).append(';');
ResultSet rs = stmt.executeQuery(sql.toString());
if (!(rs.next()))
throw new DataException("User #" + String.valueOf(uid) + " not found.");
// load the "elementary" fields
this.uid = rs.getInt("uid");
this.username = rs.getString("username");
int contact_id = rs.getInt("contactid");
created = SQLUtil.getFullDateTime(rs,"created");
last_login = SQLUtil.getFullDateTime(rs,"lastaccess");
descr = rs.getString("description");
loadContact(conn,contact_id,override);
} // end constructor
private void loadContact(Connection conn, int contact_id, boolean override) throws SQLException
{
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT * FROM contacts WHERE contactid = ");
sql.append(contact_id).append(';');
ResultSet rs = stmt.executeQuery(sql.toString());
if (rs.next())
{ // load all the record data
given_name = rs.getString("given_name");
family_name = rs.getString("family_name");
String blort = rs.getString("middle_init");
if ((blort==null) || (blort.length()<1))
middle_initial = ' ';
else
middle_initial = blort.charAt(0);
prefix = rs.getString("prefix");
suffix = rs.getString("suffix");
company = rs.getString("company");
if (!override && rs.getBoolean("pvt_addr"))
{ // enforce address privacy
addr1 = null;
addr2 = null;
} // end if
else
{ // load the address strings
addr1 = rs.getString("addr1");
addr2 = rs.getString("addr2");
} // end else
locality = rs.getString("locality");
region = rs.getString("region");
postal_code = rs.getString("pcode");
country = rs.getString("country");
if (!override && rs.getBoolean("pvt_phone"))
{ // enforce phone privacy
phone = null;
mobile = null;
} // end if
else
{ // load the phone strings
phone = rs.getString("phone");
mobile = rs.getString("mobile");
} // end else
if (!override && rs.getBoolean("pvt_fax"))
fax = null;
else
fax = rs.getString("fax");
real_email = rs.getString("email");
if (!override && rs.getBoolean("pvt_email"))
email = null;
else
email = real_email;
photo_url = rs.getString("photo_url");
url = rs.getString("url");
last_update = SQLUtil.getFullDateTime(rs,"lastupdate");
} // end if
else
{ // no contact ID - just default all the data
given_name = null;
family_name = null;
middle_initial = ' ';
prefix = null;
suffix = null;
company = null;
addr1 = null;
addr2 = null;
locality = null;
region = null;
postal_code = null;
country = null;
phone = null;
fax = null;
mobile = null;
email = null;
photo_url = null;
url = null;
last_update = null;
real_email = null;
} // end else
} // end loadContact
public int getUID()
{
return uid;
} // end getUID
public String getUserName()
{
return username;
} // end getUserName
public String getGivenName()
{
return given_name;
} // end getGivenName
public String getFamilyName()
{
return family_name;
} // end getFamilyName
public char getMiddleInitial()
{
return middle_initial;
} // end getMiddleInitial
public String getNamePrefix()
{
return prefix;
} // end getNamePrefix
public String getNameSuffix()
{
return suffix;
} // end getNameSuffix
public String getCompany()
{
return company;
} // end getCompany
public String getAddressLine1()
{
return addr1;
} // end getAddressLine1
public String getAddressLine2()
{
return addr2;
} // end getAddressLine2
public String getLocality()
{
return locality;
} // end getLocality
public String getRegion()
{
return region;
} // end getRegion
public String getPostalCode()
{
return postal_code;
} // end getPostalCode
public String getCountry()
{
return country;
} // end getCountry
public String getFullCountry()
{
return engine.getCountryNameForCode(country);
} // end getFullCountry
public String getPhone()
{
return phone;
} // end getPhone
public String getFax()
{
return fax;
} // end getFax
public String getMobile()
{
return mobile;
} // end getMobile
public String getEmail()
{
return email;
} // end getEmail
public String getPhotoURL()
{
return photo_url;
} // end getPhotoURL
public String getURL()
{
return url;
} // end getURL
public java.util.Date getCreateDate()
{
return created;
} // end getCreateDate
public java.util.Date getLastLoginDate()
{
return last_login;
} // end getLastLoginDate
public java.util.Date getLastUpdate()
{
return last_update;
} // end getLastUpdate
public String getDescription()
{
return descr;
} // end getDescription
} // end class UserProfileImpl
File diff suppressed because it is too large Load Diff