From bc859178f21dc76aae99701696bcf5d9d0c096f9 Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Wed, 7 Nov 2001 22:32:12 +0000 Subject: [PATCH] implemented the ability to upload community logos, similar to how we did user photos --- etc/web.xml | 13 ++ .../silverwrist/venice/core/VeniceEngine.java | 2 + .../venice/core/impl/VeniceEngineImpl.java | 7 + .../venice/servlets/CommunityLogo.java | 168 ++++++++++++++++++ .../servlets/format/CommunityLogoData.java | 126 +++++++++++++ .../format/EditCommunityProfileDialog.java | 61 +++++++ .../servlets/format/EditProfileDialog.java | 1 + web/format/comm_logo.jsp | 41 +++++ 8 files changed, 419 insertions(+) create mode 100644 src/com/silverwrist/venice/servlets/CommunityLogo.java create mode 100644 src/com/silverwrist/venice/servlets/format/CommunityLogoData.java create mode 100644 web/format/comm_logo.jsp diff --git a/etc/web.xml b/etc/web.xml index d8dd44a..81e1226 100644 --- a/etc/web.xml +++ b/etc/web.xml @@ -238,6 +238,14 @@ com.silverwrist.venice.servlets.PasswordRecovery + + communitylogo + + Changes the logo for a community (uploads a new one). + + com.silverwrist.venice.servlets.CommunityLogo + + @@ -361,6 +369,11 @@ /passrecovery/* + + communitylogo + /commlogo + + testformdata diff --git a/src/com/silverwrist/venice/core/VeniceEngine.java b/src/com/silverwrist/venice/core/VeniceEngine.java index e390be0..3a79e2a 100644 --- a/src/com/silverwrist/venice/core/VeniceEngine.java +++ b/src/com/silverwrist/venice/core/VeniceEngine.java @@ -89,4 +89,6 @@ public interface VeniceEngine extends SearchMode public abstract Dimension getUserPhotoSize(); + public abstract Dimension getCommunityLogoSize(); + } // end interface VeniceEngine diff --git a/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java b/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java index e2910cb..1eafdf2 100644 --- a/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java +++ b/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java @@ -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 *-------------------------------------------------------------------------------- diff --git a/src/com/silverwrist/venice/servlets/CommunityLogo.java b/src/com/silverwrist/venice/servlets/CommunityLogo.java new file mode 100644 index 0000000..b6c071c --- /dev/null +++ b/src/com/silverwrist/venice/servlets/CommunityLogo.java @@ -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 . + * + * 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 , + * 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 diff --git a/src/com/silverwrist/venice/servlets/format/CommunityLogoData.java b/src/com/silverwrist/venice/servlets/format/CommunityLogoData.java new file mode 100644 index 0000000..35a02fb --- /dev/null +++ b/src/com/silverwrist/venice/servlets/format/CommunityLogoData.java @@ -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 . + * + * 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 , + * 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("\"\""); + return buf.toString(); + + } // end getLogoTag + +} // end class CommunityLogoData diff --git a/src/com/silverwrist/venice/servlets/format/EditCommunityProfileDialog.java b/src/com/silverwrist/venice/servlets/format/EditCommunityProfileDialog.java index 9f10e80..dbb35de 100644 --- a/src/com/silverwrist/venice/servlets/format/EditCommunityProfileDialog.java +++ b/src/com/silverwrist/venice/servlets/format/EditCommunityProfileDialog.java @@ -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(""); + String photo = getValue(); + if (StringUtil.isStringEmpty(photo)) + photo = rdat.getFullImagePath("sig_other.jpg"); + out.write("\"\""); + if (isEnabled()) + out.write(""); + + } // 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()); diff --git a/src/com/silverwrist/venice/servlets/format/EditProfileDialog.java b/src/com/silverwrist/venice/servlets/format/EditProfileDialog.java index a3d4c19..60d2563 100644 --- a/src/com/silverwrist/venice/servlets/format/EditProfileDialog.java +++ b/src/com/silverwrist/venice/servlets/format/EditProfileDialog.java @@ -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 diff --git a/web/format/comm_logo.jsp b/web/format/comm_logo.jsp new file mode 100644 index 0000000..a5e73fc --- /dev/null +++ b/web/format/comm_logo.jsp @@ -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 . + + 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 , + 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); %> + +
"> +
<%= rdat.getStdFontTag(ColorSelectors.CONTENT_FOREGROUND,2) %> + + <%= data.getLogoTag(rdat) %> + New community logo:
+

+ " NAME="upload" ALT="Upload" + WIDTH=80 HEIGHT=24 BORDER=0>  + " NAME="cancel" ALT="Cancel" + WIDTH=80 HEIGHT=24 BORDER=0>
+

+