implemented the ability to upload community logos, similar to how we did user

photos
This commit is contained in:
Eric J. Bowersox 2001-11-07 22:32:12 +00:00
parent dde12bdf2e
commit bc859178f2
8 changed files with 419 additions and 0 deletions

View File

@ -238,6 +238,14 @@
<servlet-class>com.silverwrist.venice.servlets.PasswordRecovery</servlet-class>
</servlet>
<servlet>
<servlet-name>communitylogo</servlet-name>
<description>
Changes the logo for a community (uploads a new one).
</description>
<servlet-class>com.silverwrist.venice.servlets.CommunityLogo</servlet-class>
</servlet>
<!-- the following are test servlets, they should go away -->
<servlet>
@ -361,6 +369,11 @@
<url-pattern>/passrecovery/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>communitylogo</servlet-name>
<url-pattern>/commlogo</url-pattern>
</servlet-mapping>
<!-- the following are test servlets, they should go away -->
<servlet-mapping>
<servlet-name>testformdata</servlet-name>

View File

@ -89,4 +89,6 @@ public interface VeniceEngine extends SearchMode
public abstract Dimension getUserPhotoSize();
public abstract Dimension getCommunityLogoSize();
} // end interface VeniceEngine

View File

@ -479,6 +479,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
private static final int AUTH_STRING_LEN = 32;
private static final Dimension DEFAULT_DIM_USERPHOTO = new Dimension(100,100);
private static final Dimension DEFAULT_DIM_COMMUNITYLOGO = new Dimension(110,65);
/*--------------------------------------------------------------------------------
* Attributes
@ -1817,6 +1818,12 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end getUserPhotoSize
public Dimension getCommunityLogoSize()
{
return DEFAULT_DIM_COMMUNITYLOGO;
} // end getCommunityLogoSize
/*--------------------------------------------------------------------------------
* Implementations from interface EngineBackend
*--------------------------------------------------------------------------------

View File

@ -0,0 +1,168 @@
/*
* 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@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.servlets;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.util.ServletMultipartHandler;
import com.silverwrist.util.ServletMultipartException;
import com.silverwrist.util.image.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.servlets.format.*;
public class CommunityLogo extends VeniceServlet
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(CommunityLogo.class);
/*--------------------------------------------------------------------------------
* Overrides from class HttpServlet
*--------------------------------------------------------------------------------
*/
public String getServletInfo()
{
String rc = "CommunityLogo servlet - changes the community logo for a community\n"
+ "Part of the Venice Web Communities System\n";
return rc;
} // end getServletInfo
/*--------------------------------------------------------------------------------
* Overrides from class VeniceServlet
*--------------------------------------------------------------------------------
*/
protected VeniceContent doVeniceGet(HttpServletRequest request, VeniceEngine engine,
UserContext user, RenderData rdat)
throws ServletException, IOException, VeniceServletResult
{
// Get the community.
CommunityContext comm = getCommunityParameter(request,user,true,null);
changeMenuCommunity(request,comm);
if (!(comm.canModifyProfile()))
return new ErrorBox("Community Error","You are not permitted to modify this community's profile.",null);
try
{ // create the display
return new CommunityLogoData(engine,comm,rdat);
} // end try
catch (DataException de)
{ // error getting at the data stream from the attachment
return new ErrorBox("Database Error","Database error generating display: " + de.getMessage(),
"sigadmin?cmd=P&sig=" + comm.getCommunityID());
} // end catch
} // end doVeniceGet
protected VeniceContent doVenicePost(HttpServletRequest request, ServletMultipartHandler mphandler,
VeniceEngine engine, UserContext user, RenderData rdat)
throws ServletException, IOException, VeniceServletResult
{
// Get the community.
CommunityContext comm = getCommunityParameter(mphandler,user,true,null);
changeMenuCommunity(request,comm);
String target = "sigadmin?cmd=P&sig=" + comm.getCommunityID();
if (!(comm.canModifyProfile()))
return new ErrorBox("Community Error","You are not permitted to modify this community's profile.",
target);
if (isImageButtonClicked(mphandler,"cancel"))
throw new RedirectResult(target);
if (isImageButtonClicked(mphandler,"upload"))
{ // uploading the image here!
// also check on file parameter status
if (!(mphandler.isFileParam("thepic")))
{ // bogus file parameter
logger.error("Internal Error: 'thepic' should be a file param");
return new ErrorBox(null,"Internal Error: 'thepic' should be a file param",target);
} // end if
if (!(mphandler.getContentType("thepic").startsWith("image/")))
{ // must be an image type we uploaded!
logger.error("Error: 'thepic' not an image type");
return new ErrorBox(null,"You did not upload an image file. Try again.",
"commlogo?sig=" + comm.getCommunityID());
} // end if
try
{ // get the real picture (normalized to 110x65 size)
ImageLengthPair real_pic = ImageNormalizer.normalizeImage(mphandler.getFileContentStream("thepic"),
engine.getCommunityLogoSize(),"jpeg");
// set the community logo data!
ContactInfo ci = comm.getContactInfo();
ci.setPhotoData(request.getContextPath() + "/imagedata/","image/jpeg",real_pic.getLength(),
real_pic.getData());
comm.putContactInfo(ci);
// Jump back to the profile form.
clearMenu(request); // allow the menu to be redisplayed
throw new RedirectResult(target);
} // end try
catch (ServletMultipartException smpe)
{ // the servlet multipart parser screwed up
logger.error("Servlet multipart error:",smpe);
return new ErrorBox(null,"Internal Error: " + smpe.getMessage(),target);
} // end catch
catch (ImageNormalizerException ine)
{ // the image was not valid
logger.error("Image normalizer error:",ine);
return new ErrorBox(null,ine.getMessage(),"commlogo?sig=" + comm.getCommunityID());
} // end catch
catch (DataException de)
{ // error in the database!
logger.error("DataException:",de);
return new ErrorBox("Database Error","Database error storing community logo: " + de.getMessage(),
target);
} // end catch
catch (AccessError ae)
{ // email exception (WTF?)
logger.error("Access error:",ae);
return new ErrorBox(null,"Access error: " + ae.getMessage(),target);
} // end catch
} // end if
else
{ // the button must be wrong!
logger.error("no known button click on CommunityLogo.doPost");
return new ErrorBox("Internal Error","Unknown command button pressed",target);
} // end else
} // end doVenicePost
} // end class CommunityLogo

View File

@ -0,0 +1,126 @@
/*
* 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@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.servlets.format;
import java.awt.Dimension;
import javax.servlet.*;
import javax.servlet.http.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.core.*;
public class CommunityLogoData implements JSPRender
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
// Attribute name for request attribute
protected static final String ATTR_NAME = "com.silverwrist.venice.content.CommunityLogoData";
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private int cid;
private Dimension logo_dims;
private String logo_url;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public CommunityLogoData(VeniceEngine engine, CommunityContext comm, RenderData rdat)
throws DataException
{
cid = comm.getCommunityID();
logo_dims = engine.getCommunityLogoSize();
logo_url = comm.getContactInfo().getPhotoURL();
if (StringUtil.isStringEmpty(logo_url))
logo_url = rdat.getFullImagePath("sig_other.jpg");
} // end constructor
/*--------------------------------------------------------------------------------
* External static functions
*--------------------------------------------------------------------------------
*/
public static CommunityLogoData retrieve(ServletRequest request)
{
return (CommunityLogoData)(request.getAttribute(ATTR_NAME));
} // end retrieve
/*--------------------------------------------------------------------------------
* Implementations from interface VeniceContent
*--------------------------------------------------------------------------------
*/
public String getPageTitle(RenderData rdat)
{
return "Set Community Logo";
} // end getPageTitle
public String getPageQID()
{
return null;
} // end getPageQID
/*--------------------------------------------------------------------------------
* Implementations from interface JSPRender
*--------------------------------------------------------------------------------
*/
public void store(ServletRequest request)
{
request.setAttribute(ATTR_NAME,this);
} // end store
public String getTargetJSPName()
{
return "comm_logo.jsp";
} // end getTargetJSPName
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public int getCommunityID()
{
return cid;
} // end getCommunityID
public String getLogoTag(RenderData rdat)
{
StringBuffer buf = new StringBuffer("<IMG SRC=\"");
buf.append(logo_url).append("\" ALT=\"\" ALIGN=LEFT WIDTH=").append(logo_dims.width).append(" HEIGHT=");
buf.append(logo_dims.height).append(" HSPACE=6 VSPACE=0 BORDER=0>");
return buf.toString();
} // end getLogoTag
} // end class CommunityLogoData

View File

@ -17,6 +17,7 @@
*/
package com.silverwrist.venice.servlets.format;
import java.io.*;
import java.util.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.ValidationException;
@ -25,11 +26,66 @@ import com.silverwrist.venice.core.*;
public class EditCommunityProfileDialog extends ContentDialog
{
/*--------------------------------------------------------------------------------
* The logo URL control class.
*--------------------------------------------------------------------------------
*/
static class CDCommunityLogoControl extends CDBaseFormField
{
private String linkURL;
public CDCommunityLogoControl(String name, String caption, String linkURL)
{
super(name,caption,"(click to change)",false);
this.linkURL = linkURL;
} // end constructor
protected CDCommunityLogoControl(CDCommunityLogoControl other)
{
super(other);
this.linkURL = other.linkURL;
} // end constructor
protected void renderActualField(Writer out, RenderData rdat) throws IOException
{
if (isEnabled())
out.write("<A HREF=\"" + rdat.getEncodedServletPath(linkURL) + "\">");
String photo = getValue();
if (StringUtil.isStringEmpty(photo))
photo = rdat.getFullImagePath("sig_other.jpg");
out.write("<IMG SRC=\"" + photo + "\" ALT=\"\" BORDER=0 WIDTH=110 HEIGHT=65></A>");
if (isEnabled())
out.write("</A>");
} // end renderActualField
protected void validateContents(String value) throws ValidationException
{ // this is a do-nothing value
} // end validateContents
public CDFormField duplicate()
{
return new CDCommunityLogoControl(this);
} // end clone
public void setLinkURL(String s)
{
linkURL = s;
} // end setLinkURL
} // end class CDCommunityLogoControl
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private CDCommunityLogoControl logo_control;
private VeniceEngine engine;
private int cid;
@ -63,6 +119,8 @@ public class EditCommunityProfileDialog extends ContentDialog
addFormField(new CDTextFormField("rules","Rules",null,false,32,255));
addFormField(new CDLanguageListFormField("language","Primary language",null,true,language_list));
addFormField(new CDTextFormField("url","Home page",null,false,32,255));
logo_control = new CDCommunityLogoControl("logo","Community logo","commlogo");
addFormField(logo_control);
addFormField(new CDFormCategoryHeader("Location"));
addFormField(new CDTextFormField("company","Company",null,false,32,255));
addFormField(new CDTextFormField("addr1","Address",null,false,32,255));
@ -96,6 +154,7 @@ public class EditCommunityProfileDialog extends ContentDialog
protected EditCommunityProfileDialog(EditCommunityProfileDialog other)
{
super(other);
logo_control = (CDCommunityLogoControl)modifyField("logo");
} // end constructor
@ -165,6 +224,8 @@ public class EditCommunityProfileDialog extends ContentDialog
setFieldValue("rules",comm.getRules());
setFieldValue("language",comm.getLanguageCode());
setFieldValue("url",ci.getURL());
setFieldValue("logo",ci.getPhotoURL());
logo_control.setLinkURL("commlogo?sig=" + comm.getCommunityID());
setFieldValue("company",ci.getCompany());
setFieldValue("addr1",ci.getAddressLine1());
setFieldValue("addr2",ci.getAddressLine2());

View File

@ -39,6 +39,7 @@ public class EditProfileDialog extends ContentDialog
public CDUserPhotoControl(String name, String caption, String linkURL)
{
super(name,caption,"(click to change)",false);
this.linkURL = linkURL;
} // end constructor

41
web/format/comm_logo.jsp Normal file
View File

@ -0,0 +1,41 @@
<%--
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@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):
--%>
<%@ page import = "java.util.*" %>
<%@ page import = "com.silverwrist.util.StringUtil" %>
<%@ page import = "com.silverwrist.venice.core.*" %>
<%@ page import = "com.silverwrist.venice.servlets.Variables" %>
<%@ page import = "com.silverwrist.venice.servlets.format.*" %>
<%
CommunityLogoData data = CommunityLogoData.retrieve(request);
Variables.failIfNull(data);
RenderData rdat = RenderConfig.createRenderData(application,request,response);
%>
<% rdat.writeContentHeader(out,"Change Community Logo",null); %>
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="<%= rdat.getEncodedServletPath("commlogo") %>">
<DIV CLASS="content"><%= rdat.getStdFontTag(ColorSelectors.CONTENT_FOREGROUND,2) %>
<INPUT TYPE="HIDDEN" NAME="sig" VALUE="<%= data.getCommunityID() %>">
<%= data.getLogoTag(rdat) %>
New community logo:<BR>
<INPUT TYPE="FILE" NAME="thepic"><P>
<INPUT TYPE=IMAGE SRC="<%= rdat.getFullImagePath("bn_upload.gif") %>" NAME="upload" ALT="Upload"
WIDTH=80 HEIGHT=24 BORDER=0>&nbsp;
<INPUT TYPE=IMAGE SRC="<%= rdat.getFullImagePath("bn_cancel.gif") %>" NAME="cancel" ALT="Cancel"
WIDTH=80 HEIGHT=24 BORDER=0><BR CLEAR=LEFT>
</FONT></DIV>
</FORM>