added UI for exporting all the members from a community, and tweaked the

implementation of XML generation and importing
This commit is contained in:
Eric J. Bowersox 2004-06-13 21:34:51 +00:00
parent 7061d88b22
commit 2966ab703a
13 changed files with 166 additions and 73 deletions

View File

@ -0,0 +1,55 @@
// The contents of this file are subject to the Mozilla Public License Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
// WARRANTY OF ANY KIND, either express or implied. See the License for the specific
// language governing rights and limitations under the License.
//
// The Original Code is the Venice Web Communities System.
//
// The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
// Copyright (C) 2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
//
// Contributor(s):
importPackage(java.util);
importPackage(Packages.com.silverwrist.venice.core);
importPackage(Packages.com.silverwrist.venice.except);
importPackage(Packages.com.silverwrist.venice.ui);
importPackage(Packages.com.silverwrist.venice.ui.helpers);
// get the request object and the community
rinput = bsf.lookupBean("request");
comm = rinput.getCommunity(true,"top.js.vs");
if (!(rinput.user.hasAdminAccess()))
{ // no admin access - we can't do this
vlib.output(new ErrorBox("Access Error","You do not have permission to export a community's members",null));
vlib.done();
} // end if
rc = null;
try
{ // get the community member list
mbr_list = comm.getMemberList();
// perform the export and get the results
rc = new UserExportHelper(rinput.user.adminInterface,mbr_list);
} // end try
catch (e)
{ // an error of some sort
etype = vlib.exceptionType(e) + "";
if (etype.match("DataException"))
rc = new ErrorBox("Database Error",e.message,"community/" + comm.alias);
else if (etype.match("IOException"))
rc = new ErrorBox("I/O Error",e.message,"community/" + comm.alias);
else
rc = e;
} // end catch
vlib.output(rc);

View File

@ -21,8 +21,7 @@ import java.io.*;
import java.sql.*;
import java.util.*;
import org.apache.log4j.*;
import com.silverwrist.util.International;
import com.silverwrist.util.OptionSet;
import com.silverwrist.util.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.core.internals.*;
import com.silverwrist.venice.db.*;
@ -685,11 +684,16 @@ class AdminUserContextImpl implements AdminUserContext
} // end finally
xml.write("<venice-user id=\"" + uid + "\">\n");
xml.write("<username>" + username + "</username>\n");
xml.write("<password prehashed=\"true\">" + hash + "</password>\n");
xml.write("<password-reminder>" + reminder + "</password-reminder>\n");
xml.write("<description>" + description + "</description>\n");
xml.write("<venice-user id=\"" + uid + "\">\n<username>" + username
+ "</username>\n<password prehashed=\"true\">" + hash + "</password>\n");
if (StringUtil.isStringEmpty(reminder))
xml.write("<password-reminder/>\n");
else
xml.write("<password-reminder>" + reminder + "</password-reminder>\n");
if (StringUtil.isStringEmpty(description))
xml.write("<description/>\n");
else
xml.write("<description>" + description + "</description>\n");
xml.write("<options confirmed=\"");
xml.write(email_verified ? "true" : "false");
xml.write("\" locked=\"");

View File

@ -729,7 +729,7 @@ class ContactInfoImpl implements ContactInfo, Stashable
if (vc.getOrganizationName()!=null)
company = vc.getOrganizationName();
if (vc.getURL()!=null)
url = vc.getURL();
url = vc.getURL();
// Look for an address.
Boolean hide = null;
@ -1112,7 +1112,7 @@ class ContactInfoImpl implements ContactInfo, Stashable
BuildVCard bvc = new BuildVCard();
bvc.setFamilyName(family_name);
bvc.setGivenName(given_name);
bvc.setMiddleName(new String(new char[] { middle_initial }));
bvc.setMiddleName(new String(new char[] { middle_initial }).trim());
bvc.setPrefix(prefix);
bvc.setSuffix(suffix);
bvc.setOrganizationName(company);
@ -1120,12 +1120,14 @@ class ContactInfoImpl implements ContactInfo, Stashable
// add the address to the VCard
BuildVCardAddress baddr = new BuildVCardAddress();
baddr.setHomeAddress(true);
baddr.setWorkAddress(true);
if (private_addr)
baddr.setHomeAddress(true);
else
baddr.setWorkAddress(true);
baddr.setPreferred(true);
if (addr1!=null)
if (!StringUtil.isStringEmpty(addr1))
{ // save off address
if (addr2!=null)
if (!StringUtil.isStringEmpty(addr2))
{ // set extension, then street
baddr.setExtension(addr1);
baddr.setStreet(addr2);
@ -1144,10 +1146,12 @@ class ContactInfoImpl implements ContactInfo, Stashable
// Add phone number.
BuildVCardPhone bphone = new BuildVCardPhone();
if (phone!=null)
if (!StringUtil.isStringEmpty(phone))
{ // set attributes and number
bphone.setHomePhone(true);
bphone.setWorkPhone(true);
if (private_phone)
bphone.setHomePhone(true);
else
bphone.setWorkPhone(true);
bphone.setVoicePhone(true);
bphone.setNumber(phone);
bvc.addPhone(bphone.create());
@ -1156,10 +1160,12 @@ class ContactInfoImpl implements ContactInfo, Stashable
} // end if
// Add fax number.
if (fax!=null)
if (!StringUtil.isStringEmpty(fax))
{ // set attributes and number
bphone.setHomePhone(true);
bphone.setWorkPhone(true);
if (private_fax)
bphone.setHomePhone(true);
else
bphone.setWorkPhone(true);
bphone.setFax(true);
bphone.setNumber(fax);
bvc.addPhone(bphone.create());
@ -1168,7 +1174,7 @@ class ContactInfoImpl implements ContactInfo, Stashable
} // end if
// Add mobile number.
if (mobile!=null)
if (!StringUtil.isStringEmpty(mobile))
{ // set attributes and number
bphone.setCellPhone(true);
bphone.setPCSPhone(true);
@ -1178,11 +1184,13 @@ class ContactInfoImpl implements ContactInfo, Stashable
} // end if
// Add E-mail address.
if (email!=null)
if (!StringUtil.isStringEmpty(email))
{ // set attributes and address
BuildVCardEmail bemail = new BuildVCardEmail();
bemail.setHomeEmail(true);
bemail.setWorkEmail(true);
if (private_email)
bemail.setHomeEmail(true);
else
bemail.setWorkEmail(true);
bemail.setInternetEmail(true);
bemail.setPreferred(true);
bemail.setAddress(email);

View File

@ -440,7 +440,7 @@ class UserProfileImpl implements UserProfile
BuildVCard bvc = new BuildVCard();
bvc.setFamilyName(family_name);
bvc.setGivenName(given_name);
bvc.setMiddleName(new String(new char[] { middle_initial }));
bvc.setMiddleName(new String(new char[] { middle_initial }).trim());
bvc.setPrefix(prefix);
bvc.setSuffix(suffix);
bvc.setNickname(username);
@ -450,12 +450,11 @@ class UserProfileImpl implements UserProfile
// add the address to the VCard
BuildVCardAddress baddr = new BuildVCardAddress();
baddr.setHomeAddress(true);
baddr.setWorkAddress(true);
baddr.setPreferred(true);
if (addr1!=null)
if (!StringUtil.isStringEmpty(addr1))
{ // save off address
if (addr2!=null)
if (!StringUtil.isStringEmpty(addr2))
{ // set extension, then street
baddr.setExtension(addr1);
baddr.setStreet(addr2);
@ -474,9 +473,8 @@ class UserProfileImpl implements UserProfile
// Add phone number.
BuildVCardPhone bphone = new BuildVCardPhone();
if (phone!=null)
if (!StringUtil.isStringEmpty(phone))
{ // set attributes and number
bphone.setHomePhone(true);
bphone.setWorkPhone(true);
bphone.setVoicePhone(true);
bphone.setNumber(phone);
@ -486,9 +484,8 @@ class UserProfileImpl implements UserProfile
} // end if
// Add fax number.
if (fax!=null)
if (!StringUtil.isStringEmpty(fax))
{ // set attributes and number
bphone.setHomePhone(true);
bphone.setWorkPhone(true);
bphone.setFax(true);
bphone.setNumber(fax);
@ -498,7 +495,7 @@ class UserProfileImpl implements UserProfile
} // end if
// Add mobile number.
if (mobile!=null)
if (!StringUtil.isStringEmpty(mobile))
{ // set attributes and number
bphone.setCellPhone(true);
bphone.setPCSPhone(true);
@ -508,10 +505,9 @@ class UserProfileImpl implements UserProfile
} // end if
// Add E-mail address.
if (email!=null)
if (!StringUtil.isStringEmpty(email))
{ // set attributes and address
BuildVCardEmail bemail = new BuildVCardEmail();
bemail.setHomeEmail(true);
bemail.setWorkEmail(true);
bemail.setInternetEmail(true);
bemail.setPreferred(true);

View File

@ -245,11 +245,13 @@ public class ImportHelper
// set up the contact info
ContactInfo ci = uc.getContactInfo();
ci.importVCard(vcard);
// N.B.: Since the vCard importer uses its own heuristics as to how to set the "hidden"
// flags, we need to reset them to the values from the <options/> element afterwards.
ci.setPrivateAddress(hideaddr);
ci.setPrivatePhone(hidephone);
ci.setPrivateFax(hidefax);
ci.setPrivateEmail(hideemail);
ci.importVCard(vcard);
uc.putContactInfo(ci);
// set up the locale

View File

@ -56,6 +56,8 @@ public class UserExportHelper implements ContentExecute
tmp.add(adm.getUserContext(((UserContext)o).getUID()));
else if (o instanceof UserProfile)
tmp.add(adm.getUserContext(((UserProfile)o).getUID()));
else if (o instanceof UserFound)
tmp.add(adm.getUserContext(((UserFound)o).getUID()));
else if (o instanceof Number)
tmp.add(adm.getUserContext(((Number)o).intValue()));
else
@ -95,7 +97,7 @@ public class UserExportHelper implements ContentExecute
public void execute(RequestExec req) throws IOException
{
req.sendBinary("text/xml","export-data.xml",m_length,m_stm);
req.sendBinary("text/xml","exported-users.xml",m_length,m_stm);
} // end execute

View File

@ -9,9 +9,9 @@
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
* Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
@ -230,6 +230,14 @@ public class MembersView implements ContentJSP
} // end isCommunityAdmin
public boolean canExportMembers()
{
if (rinput==null)
return false;
return rinput.getUser().hasAdminAccess();
} // end canExportMembers
/*--------------------------------------------------------------------------------
* External static operations
*--------------------------------------------------------------------------------

View File

@ -18,6 +18,7 @@
package com.silverwrist.venice.util;
import java.util.*;
import com.silverwrist.util.*;
public class BuildVCard
{
@ -61,28 +62,28 @@ public class BuildVCard
private final String realFormattedName()
{
if (formatted_name!=null)
if (!StringUtil.isStringEmpty(formatted_name))
return formatted_name;
StringBuffer buf = new StringBuffer();
if (prefix!=null)
if (!StringUtil.isStringEmpty(prefix))
buf.append(prefix).append(' ');
if (given_name!=null)
if (!StringUtil.isStringEmpty(given_name))
buf.append(given_name);
if ((middle_name!=null) || (family_name!=null))
if (!StringUtil.isStringEmpty(middle_name) || !StringUtil.isStringEmpty(family_name))
buf.append(' ');
if (middle_name!=null)
if (!StringUtil.isStringEmpty(middle_name))
{ // figure out the middle name
buf.append(middle_name);
if (middle_name.length()==1)
buf.append('.');
if (family_name!=null)
if (!StringUtil.isStringEmpty(family_name))
buf.append(' ');
} // end if
if (family_name!=null)
if (!StringUtil.isStringEmpty(family_name))
buf.append(family_name);
if (suffix!=null)
if (!StringUtil.isStringEmpty(suffix))
buf.append(' ').append(suffix);
String s = buf.toString();
if (s.length()==0)
@ -209,6 +210,13 @@ public class BuildVCard
public final void setTimeZone(TimeZone tz)
{
int ofs = tz.getRawOffset();
if (ofs==0)
{ // we're dead-bang on Zulu time - recognize that fact
timezone = "Z";
return;
} // end if
StringBuffer buf = new StringBuffer();
if (ofs<0)
{ // negative offset

View File

@ -588,26 +588,28 @@ public class VCard
public final void exportXML(Writer xml_writer) throws IOException
{
xml_writer.write("<vCard xmlns=\"vcard-temp\">\n<VERSION>2.0</VERSION>\n");
if (formatted_name!=null)
if (!StringUtil.isStringEmpty(formatted_name))
xml_writer.write("<FN>" + formatted_name + "</FN>\n");
if ((family_name!=null) || (given_name!=null) || (middle_name!=null) || (prefix!=null) || (suffix!=null))
if ( !StringUtil.isStringEmpty(family_name) || !StringUtil.isStringEmpty(given_name)
|| !StringUtil.isStringEmpty(middle_name) || !StringUtil.isStringEmpty(prefix)
|| !StringUtil.isStringEmpty(suffix))
{ // write out the "N" block
xml_writer.write("<N>");
if (family_name!=null)
if (!StringUtil.isStringEmpty(family_name))
xml_writer.write("<FAMILY>" + family_name + "</FAMILY>");
if (given_name!=null)
if (!StringUtil.isStringEmpty(given_name))
xml_writer.write("<GIVEN>" + given_name + "</GIVEN>");
if (middle_name!=null)
if (!StringUtil.isStringEmpty(middle_name))
xml_writer.write("<MIDDLE>" + middle_name + "</MIDDLE>");
if (prefix!=null)
if (!StringUtil.isStringEmpty(prefix))
xml_writer.write("<PREFIX>" + prefix + "</PREFIX>");
if (suffix!=null)
if (!StringUtil.isStringEmpty(suffix))
xml_writer.write("<SUFFIX>" + suffix + "</SUFFIX>");
xml_writer.write("</N>\n");
} // end if
if (nickname!=null)
if (!StringUtil.isStringEmpty(nickname))
xml_writer.write("<NICKNAME>" + nickname + "</NICKNAME>\n");
Iterator it;
@ -632,21 +634,21 @@ public class VCard
} // end for
if (mailer!=null)
if (!StringUtil.isStringEmpty(mailer))
xml_writer.write("<MAILER>" + mailer + "</MAILER>\n");
if (timezone!=null)
if (!StringUtil.isStringEmpty(timezone))
xml_writer.write("<TZ>" + timezone + "</TZ>\n");
if (title!=null)
if (!StringUtil.isStringEmpty(title))
xml_writer.write("<TITLE>" + title + "</TITLE>\n");
if (role!=null)
if (!StringUtil.isStringEmpty(role))
xml_writer.write("<ROLE>" + role + "</ROLE>\n");
if (orgname!=null)
if (!StringUtil.isStringEmpty(orgname))
xml_writer.write("<ORG><ORGNAME>" + orgname + "</ORGNAME></ORG>\n");
if (note!=null)
if (!StringUtil.isStringEmpty(note))
xml_writer.write("<NOTE>" + note + "</NOTE>\n");
if (sort_string!=null)
if (!StringUtil.isStringEmpty(sort_string))
xml_writer.write("<SORTSTR>" + sort_string + "</SORTSTR>\n");
if (url!=null)
if (!StringUtil.isStringEmpty(url))
xml_writer.write("<URL>" + url + "</URL>\n");
xml_writer.write("</vCard>\n");

View File

@ -126,19 +126,19 @@ public class VCardAddress
if (preferred)
xml_writer.write("<PREF/>");
xml_writer.write("\n");
if (pobox!=null)
if (!StringUtil.isStringEmpty(pobox))
xml_writer.write("<POBOX>" + pobox + "</POBOX>\n");
if (ext_address!=null)
if (!StringUtil.isStringEmpty(ext_address))
xml_writer.write("<EXTADR>" + ext_address + "</EXTADR>\n");
if (street!=null)
if (!StringUtil.isStringEmpty(street))
xml_writer.write("<STREET>" + street + "</STREET>\n");
if (locality!=null)
if (!StringUtil.isStringEmpty(locality))
xml_writer.write("<LOCALITY>" + locality + "</LOCALITY>\n");
if (region!=null)
if (!StringUtil.isStringEmpty(region))
xml_writer.write("<REGION>" + region + "</REGION>\n");
if (postal_code!=null)
if (!StringUtil.isStringEmpty(postal_code))
xml_writer.write("<PCODE>" + postal_code + "</PCODE>\n");
if (country!=null)
if (!StringUtil.isStringEmpty(country))
xml_writer.write("<CTRY>" + country + "</CTRY>\n");
xml_writer.write("</ADR>\n");

View File

@ -98,7 +98,7 @@ public class VCardEmail
xml_writer.write("<X400/>");
if (preferred)
xml_writer.write("<PREF/>");
if (address!=null)
if (!StringUtil.isStringEmpty(address))
xml_writer.write("<USERID>" + address + "</USERID>");
xml_writer.write("</EMAIL>\n");

View File

@ -137,7 +137,7 @@ public class VCardPhone
xml_writer.write("<PCS/>");
if (preferred)
xml_writer.write("<PREF/>");
if (number!=null)
if (!StringUtil.isStringEmpty(number))
xml_writer.write("<NUMBER>" + number + "</NUMBER>");
xml_writer.write("</TEL>\n");

View File

@ -9,9 +9,9 @@
The Original Code is the Venice Web Communities System.
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
Contributor(s):
--%>
@ -28,6 +28,14 @@
<util:header title="Members of Community:">
<util:subtitle><util:escape><comm:name/></util:escape></util:subtitle>
</util:header>
<% if (view.canExportMembers()) { %>
<util:font color="content.fg" size="content">[
<util:xlink>
<util:href type="servlet">comm/member_export.js.vs?cc=<comm:ID/></util:href>
<util:text>Export Member List</util:text>
</util:xlink>
]</util:font><p>
<% } // end if %>
<util:font color="content.fg" size="subhead"><B>Find members of community "<comm:name/>":</B></util:font><P>
<util:form action="comm/members.js.vs" type="servlet"><DIV CLASS="content">
<INPUT TYPE="HIDDEN" NAME="cc" VALUE="<comm:ID/>">