refactored image handler code for sideboxes into a separate class; added option

for titles of sideboxes to be images
This commit is contained in:
Eric J. Bowersox 2001-11-05 03:55:27 +00:00
parent e201ecb34b
commit e1d22e1082
5 changed files with 309 additions and 264 deletions

View File

@ -46,10 +46,18 @@ public class ConferenceBox implements SideBoxFactory
public String getPageTitle(RenderData rdat)
{
if (uc.isLoggedIn())
return title;
if (title_image!=null)
{ // return an image rendering
ImageHandler ih = (uc.isLoggedIn() ? title_image : anon_title_image);
return ih.getRendering(rdat);
} // end if
else
return anon_title;
{ // return a title string
String rc = (uc.isLoggedIn() ? title : anon_title);
return StringUtil.encodeHTML(rc);
} // end else
} // end getPageTitle
@ -72,8 +80,8 @@ public class ConferenceBox implements SideBoxFactory
ConferenceHotlistEntry hle = (ConferenceHotlistEntry)(it.next());
ConferenceContext conf = hle.getConference();
String href = "confdisp?sig=" + conf.getEnclosingSIG().getSIGID() + "&conf=" + conf.getConfID();
out.write("<TR VALIGN=MIDDLE>\n<TD ALIGN=CENTER WIDTH=" + bullet_width + ">");
renderBullet(out,rdat);
out.write("<TR VALIGN=MIDDLE>\n<TD ALIGN=CENTER WIDTH=" + bullet.getWidth() + ">");
bullet.renderHere(out,rdat);
out.write("</TD>\n<TD ALIGN=LEFT CLASS=\"sidebox\">\n" + norm_font
+ "<B><A CLASS=\"sidebox\" HREF=\"" + rdat.getEncodedServletPath(href) + "\">" + hilite
+ StringUtil.encodeHTML(conf.getName()) + "</FONT></A></B> ("
@ -81,7 +89,7 @@ public class ConferenceBox implements SideBoxFactory
if (conf.anyUnread())
{ // write out the new-messages tag and its enclosing link
out.write("&nbsp;<A HREF=\"" + rdat.getEncodedServletPath(href + "&rnm=1") + "\">");
renderNewMessageTag(out,rdat);
newmsg.renderHere(out,rdat);
out.write("</A>\n");
} // end if
@ -113,19 +121,14 @@ public class ConferenceBox implements SideBoxFactory
*--------------------------------------------------------------------------------
*/
private ImageHandler title_image; // title image for sidebox for logged-in users
private ImageHandler anon_title_image; // title image for sidebox for not-logged-in users
private String title; // title of sidebox for logged-in users
private String anon_title; // title of sidebox for not-logged-in users
private String null_message; // message if they have no hotlist conferences
private String manage_link; // "Manage" link text
private String bullet_url; // URL to bullet image
private boolean bullet_fixup; // does bullet image need to be run through getFullImagePath?
private int bullet_width; // width of bullet image
private int bullet_height; // height of bullet image
private String newmsg_url; // URL to new messages tag image
private boolean newmsg_fixup; // does new messages image need to be run through getFullImagePath?
private String newmsg_alt; // ALT text to use for new message tag image
private int newmsg_width; // width of new message tag image
private int newmsg_height; // height of new message tag image
private ImageHandler bullet; // bullet image
private ImageHandler newmsg; // new message image
/*--------------------------------------------------------------------------------
* Constructor
@ -136,47 +139,6 @@ public class ConferenceBox implements SideBoxFactory
{ // do nothing
} // end constructor
/*--------------------------------------------------------------------------------
* Internal operations
*--------------------------------------------------------------------------------
*/
private void renderBullet(Writer out, RenderData rdat) throws IOException
{
synchronized (this)
{ // this may be called by more than one class, so protect this part
if (bullet_fixup)
{ // fix up the bullet URL
bullet_url = rdat.getFullImagePath(bullet_url);
bullet_fixup = false;
} // end if
} // end synchronized block
out.write("<IMG SRC=\"" + bullet_url + "\" ALT=\"*\" WIDTH=" + bullet_width + " HEIGHT=" + bullet_height
+ " BORDER=0>");
} // end renderBullet
private void renderNewMessageTag(Writer out, RenderData rdat) throws IOException
{
synchronized (this)
{ // this may be called by more than one class, so protect this part
if (newmsg_fixup)
{ // fix up the host tag URL
newmsg_url = rdat.getFullImagePath(newmsg_url);
newmsg_fixup = false;
} // end if
} // end synchronized block
out.write("<IMG SRC=\"" + newmsg_url + "\" ALT=\"" + newmsg_alt + "\" WIDTH=" + newmsg_width + " HEIGHT="
+ newmsg_height + " BORDER=0>");
} // end renderNewMessageTag
/*--------------------------------------------------------------------------------
* Implementations from interface SideBoxFactory
*--------------------------------------------------------------------------------
@ -185,6 +147,18 @@ public class ConferenceBox implements SideBoxFactory
public void setConfiguration(Element cfg) throws ConfigException
{
DOMElementHelper cfg_h = new DOMElementHelper(cfg);
title_image = new ImageHandler(cfg_h.getSubElement("title-image"));
if (title_image.isDefined())
{ // we're using image titles...
title = anon_title = null;
anon_title_image = new ImageHandler(cfg_h.getSubElement("anon-title-image"));
if (!(anon_title_image.isDefined()))
anon_title_image = title_image;
} // end if
else
{ // standard textual title
title_image = anon_title_image = null;
title = cfg_h.getSubElementText("title");
if (title==null)
throw new ConfigException("no <title/> specified for conference list sidebox",cfg);
@ -195,6 +169,8 @@ public class ConferenceBox implements SideBoxFactory
else
anon_title += ":";
} // end else
null_message = cfg_h.getSubElementText("null-msg");
if (null_message==null)
null_message = "You are not a member of any SIGs.";
@ -203,72 +179,12 @@ public class ConferenceBox implements SideBoxFactory
if (manage_link==null)
manage_link = "Manage";
Element x = cfg_h.getSubElement("bullet");
if (x!=null)
{ // get the parameters for the bullet image
DOMElementHelper x_h = new DOMElementHelper(x);
bullet_url = x_h.getElementText();
if (StringUtil.isStringEmpty(bullet_url))
{ // default the bullet URL and fixup parameter
bullet_url = "purple-ball.gif";
bullet_fixup = true;
} // end if
else // get the "fixup" parameter
bullet_fixup = x_h.hasAttribute("fixup");
Integer xi = x_h.getAttributeInt("width");
bullet_width = (xi!=null) ? xi.intValue() : 14;
xi = x_h.getAttributeInt("height");
bullet_height = (xi!=null) ? xi.intValue() : 14;
} // end if
else
{ // just default all the bullet parameters
bullet_url = "purple-ball.gif";
bullet_fixup = true;
bullet_width = 14;
bullet_height = 14;
} // end else
x = cfg_h.getSubElement("new-image");
if (x!=null)
{ // get the parameters for the host tag image
DOMElementHelper x_h = new DOMElementHelper(x);
newmsg_url = x_h.getElementText();
if (StringUtil.isStringEmpty(newmsg_url))
{ // default the host tag image URL and fixup parameter
newmsg_url = "tag_new.gif";
newmsg_fixup = true;
} // end if
else // get the "fixup" parameter
newmsg_fixup = x_h.hasAttribute("fixup");
newmsg_alt = x.getAttribute("alt");
if (StringUtil.isStringEmpty(newmsg_alt))
newmsg_alt = "New!";
Integer xi = x_h.getAttributeInt("width");
newmsg_width = (xi!=null) ? xi.intValue() : 40;
xi = x_h.getAttributeInt("height");
newmsg_height = (xi!=null) ? xi.intValue() : 20;
} // end if
else
{ // just default all the host tag parameters
newmsg_url = "tag_new.gif";
newmsg_fixup = true;
newmsg_alt = "New!";
newmsg_width = 40;
newmsg_height = 20;
} // end else
bullet = new ImageHandler(cfg_h.getSubElement("bullet"),"purple-ball.gif","*",14,14);
newmsg = new ImageHandler(cfg_h.getSubElement("new-image"),"tag_new.gif","New!",40,20);
} // end setConfiguration
public VeniceContent create(VeniceEngine engine, UserContext uc) throws AccessError, DataException
public VeniceContent create(VeniceEngine engine, UserContext uc) throws DataException
{
return new ConferenceBoxImpl(uc);

View File

@ -0,0 +1,186 @@
/*
* 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.sideboxes;
import java.io.*;
import org.w3c.dom.*;
import com.silverwrist.util.DOMElementHelper;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.servlets.format.*;
public class ImageHandler implements ComponentRender
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private String url; // URL of the image
private boolean fixup; // does the image need to be fixed up?
private String alt; // ALT text for the image
private int width; // width of the image
private int height; // height of the image
/*--------------------------------------------------------------------------------
* Constructors
*--------------------------------------------------------------------------------
*/
public ImageHandler(Element tag, String def_url, String def_alt, int def_width, int def_height)
{
if (tag!=null)
{ // extract the details from the tag
DOMElementHelper h = new DOMElementHelper(tag);
url = h.getElementText();
if (StringUtil.isStringEmpty(url))
{ // default the URL and fixup parameter
url = def_url;
fixup = true;
} // end if
else // get the "fixup" parameter
fixup = h.hasAttribute("fixup");
alt = tag.getAttribute("alt");
if (StringUtil.isStringEmpty(alt))
alt = def_alt;
Integer tmp = h.getAttributeInt("width");
width = (tmp!=null) ? tmp.intValue() : def_width;
tmp = h.getAttributeInt("height");
height = (tmp!=null) ? tmp.intValue() : def_height;
} // end if
else
{ // just fill in all the defaults
url = def_url;
fixup = true;
alt = def_alt;
width = def_width;
height = def_height;
} // end else
} // end constructor
public ImageHandler(Element tag)
{
boolean defined = (tag!=null);
DOMElementHelper h = null;
if (defined)
{ // check the URL and see if it's defined
h = new DOMElementHelper(tag);
url = h.getElementText();
defined = !(StringUtil.isStringEmpty(url));
} // end if
Integer tmp = null;
if (defined)
{ // get the ALT text if it's there
alt = tag.getAttribute("alt");
if (StringUtil.isStringEmpty(alt))
alt = "";
// get the width
tmp = h.getAttributeInt("width");
defined = (tmp!=null);
} // end if
if (defined)
{ // stash the width, get the height
width = tmp.intValue();
tmp = h.getAttributeInt("height");
defined = (tmp!=null);
} // end if
if (defined)
height = tmp.intValue();
else
{ // not defined - clear it out
url = null;
fixup = false;
alt = null;
width = -1;
height = -1;
} // end else
} // end constructor
/*--------------------------------------------------------------------------------
* Implementations from interface ComponentRender
*--------------------------------------------------------------------------------
*/
public void renderHere(Writer out, RenderData rdat) throws IOException
{
if (url!=null)
out.write(getRendering(rdat));
} // end renderHere
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public boolean isDefined()
{
return (url!=null);
} // end if
public int getWidth()
{
return width;
} // end getWidth
public int getHeight()
{
return height;
} // end getHeight
public String getRendering(RenderData rdat)
{
if (url==null)
return "";
synchronized (this)
{ // this may be called by more than one class, so protect this part
if (fixup)
{ // fix up the host tag URL
url = rdat.getFullImagePath(url);
fixup = false;
} // end if
} // end synchronized block
StringBuffer buf = new StringBuffer("<IMG SRC=\"");
buf.append(url).append("\" ALT=\"").append(alt).append("\" WIDTH=").append(width).append(" HEIGHT=");
buf.append(height).append(" BORDER=0>");
return buf.toString();
} // end getRendering
} // end class ImageHandler

View File

@ -74,7 +74,7 @@ public class JSPSideBox implements JSPRender
public String getPageTitle(RenderData rdat)
{
return factory.getTitle(uc.isLoggedIn());
return factory.getTitle(uc.isLoggedIn(),rdat);
} // end getPageTitle

View File

@ -32,6 +32,8 @@ public class JSPSideBoxFactory implements SideBoxFactory
*--------------------------------------------------------------------------------
*/
private ImageHandler title_image; // title image for sidebox for logged-in users
private ImageHandler anon_title_image; // title image for sidebox for not-logged-in users
private String title; // title of sidebox for logged-in users
private String anon_title; // title of sidebox for not-logged-in users
private String format_jsp; // name of formatting JSP file
@ -51,9 +53,20 @@ public class JSPSideBoxFactory implements SideBoxFactory
*--------------------------------------------------------------------------------
*/
String getTitle(boolean logged_in)
String getTitle(boolean logged_in, RenderData rdat)
{
return (logged_in ? title : anon_title);
if (title_image!=null)
{ // return an image rendering
ImageHandler ih = (logged_in ? title_image : anon_title_image);
return ih.getRendering(rdat);
} // end if
else
{ // return a title string
String rc = (logged_in ? title : anon_title);
return StringUtil.encodeHTML(rc);
} // end else
} // end getTitle
@ -83,6 +96,18 @@ public class JSPSideBoxFactory implements SideBoxFactory
public void setConfiguration(Element cfg) throws ConfigException
{
DOMElementHelper cfg_h = new DOMElementHelper(cfg);
title_image = new ImageHandler(cfg_h.getSubElement("title-image"));
if (title_image.isDefined())
{ // we're using image titles...
title = anon_title = null;
anon_title_image = new ImageHandler(cfg_h.getSubElement("anon-title-image"));
if (!(anon_title_image.isDefined()))
anon_title_image = title_image;
} // end if
else
{ // standard textual title
title_image = anon_title_image = null;
title = cfg_h.getSubElementText("title");
if (title==null)
throw new ConfigException("no <title/> specified for sidebox",cfg);
@ -93,6 +118,8 @@ public class JSPSideBoxFactory implements SideBoxFactory
else
anon_title += ":";
} // end else
format_jsp = cfg_h.getSubElementText("format-jsp");
if (format_jsp==null)
throw new ConfigException("no <format-jsp/> specified for sidebox",cfg);

View File

@ -46,10 +46,18 @@ public class SIGBox implements SideBoxFactory
public String getPageTitle(RenderData rdat)
{
if (uc.isLoggedIn())
return title;
if (title_image!=null)
{ // return an image rendering
ImageHandler ih = (uc.isLoggedIn() ? title_image : anon_title_image);
return ih.getRendering(rdat);
} // end if
else
return anon_title;
{ // return a title string
String rc = (uc.isLoggedIn() ? title : anon_title);
return StringUtil.encodeHTML(rc);
} // end else
} // end getPageTitle
@ -69,15 +77,15 @@ public class SIGBox implements SideBoxFactory
while (it.hasNext())
{ // write each SIG out in turn
SIGContext sig = (SIGContext)(it.next());
out.write("<TR VALIGN=MIDDLE>\n<TD ALIGN=CENTER WIDTH=" + bullet_width + ">");
renderBullet(out,rdat);
out.write("<TR VALIGN=MIDDLE>\n<TD ALIGN=CENTER WIDTH=" + bullet.getWidth() + ">");
bullet.renderHere(out,rdat);
out.write("</TD>\n<TD ALIGN=LEFT CLASS=\"sidebox\">\n<A CLASS=\"sidebox\" HREF=\""
+ rdat.getEncodedServletPath("sig/" + sig.getAlias()) + "\">" + link_font + "<B>"
+ StringUtil.encodeHTML(sig.getName()) + "</B></FONT></A>\n");
if (sig.isAdmin())
{ // write the host tag at the end
out.write("&nbsp;");
renderHostTag(out,rdat);
host.renderHere(out,rdat);
} // end if
@ -113,20 +121,15 @@ public class SIGBox implements SideBoxFactory
*--------------------------------------------------------------------------------
*/
private ImageHandler title_image; // title image for sidebox for logged-in users
private ImageHandler anon_title_image; // title image for sidebox for not-logged-in users
private String title; // title of sidebox for logged-in users
private String anon_title; // title of sidebox for not-logged-in users
private String null_message; // message if they're not a member of any SIGs
private String manage_link; // "Manage" link text
private String create_new_link; // "Create New" link text
private String bullet_url; // URL to bullet image
private boolean bullet_fixup; // does bullet image need to be run through getFullImagePath?
private int bullet_width; // width of bullet image
private int bullet_height; // height of bullet image
private String host_url; // URL to host tag image
private boolean host_fixup; // does host tag image need to be run through getFullImagePath?
private String host_alt; // ALT text to use for host tag image
private int host_width; // width of host tag image
private int host_height; // height of host tag image
private ImageHandler bullet; // bullet image
private ImageHandler host; // host image
/*--------------------------------------------------------------------------------
* Constructor
@ -137,47 +140,6 @@ public class SIGBox implements SideBoxFactory
{ // do nothing
} // end constructor
/*--------------------------------------------------------------------------------
* Internal operations
*--------------------------------------------------------------------------------
*/
private void renderBullet(Writer out, RenderData rdat) throws IOException
{
synchronized (this)
{ // this may be called by more than one class, so protect this part
if (bullet_fixup)
{ // fix up the bullet URL
bullet_url = rdat.getFullImagePath(bullet_url);
bullet_fixup = false;
} // end if
} // end synchronized block
out.write("<IMG SRC=\"" + bullet_url + "\" ALT=\"*\" WIDTH=" + bullet_width + " HEIGHT=" + bullet_height
+ " BORDER=0>");
} // end renderBullet
private void renderHostTag(Writer out, RenderData rdat) throws IOException
{
synchronized (this)
{ // this may be called by more than one class, so protect this part
if (host_fixup)
{ // fix up the host tag URL
host_url = rdat.getFullImagePath(host_url);
host_fixup = false;
} // end if
} // end synchronized block
out.write("<IMG SRC=\"" + host_url + "\" ALT=\"" + host_alt + "\" WIDTH=" + host_width + " HEIGHT="
+ host_height + " BORDER=0>");
} // end renderBullet
/*--------------------------------------------------------------------------------
* Implementations from interface SideBoxFactory
*--------------------------------------------------------------------------------
@ -186,6 +148,18 @@ public class SIGBox implements SideBoxFactory
public void setConfiguration(Element cfg) throws ConfigException
{
DOMElementHelper cfg_h = new DOMElementHelper(cfg);
title_image = new ImageHandler(cfg_h.getSubElement("title-image"));
if (title_image.isDefined())
{ // we're using image titles...
title = anon_title = null;
anon_title_image = new ImageHandler(cfg_h.getSubElement("anon-title-image"));
if (!(anon_title_image.isDefined()))
anon_title_image = title_image;
} // end if
else
{ // standard textual title
title_image = anon_title_image = null;
title = cfg_h.getSubElementText("title");
if (title==null)
throw new ConfigException("no <title/> specified for SIG list sidebox",cfg);
@ -196,6 +170,8 @@ public class SIGBox implements SideBoxFactory
else
anon_title += ":";
} // end else
null_message = cfg_h.getSubElementText("null-msg");
if (null_message==null)
null_message = "You are not a member of any SIGs.";
@ -208,68 +184,8 @@ public class SIGBox implements SideBoxFactory
if (create_new_link==null)
create_new_link = "Create New";
Element x = cfg_h.getSubElement("bullet");
if (x!=null)
{ // get the parameters for the bullet image
DOMElementHelper x_h = new DOMElementHelper(x);
bullet_url = x_h.getElementText();
if (StringUtil.isStringEmpty(bullet_url))
{ // default the bullet URL and fixup parameter
bullet_url = "purple-ball.gif";
bullet_fixup = true;
} // end if
else // get the "fixup" parameter
bullet_fixup = x_h.hasAttribute("fixup");
Integer xi = x_h.getAttributeInt("width");
bullet_width = (xi!=null) ? xi.intValue() : 14;
xi = x_h.getAttributeInt("height");
bullet_height = (xi!=null) ? xi.intValue() : 14;
} // end if
else
{ // just default all the bullet parameters
bullet_url = "purple-ball.gif";
bullet_fixup = true;
bullet_width = 14;
bullet_height = 14;
} // end else
x = cfg_h.getSubElement("host-image");
if (x!=null)
{ // get the parameters for the host tag image
DOMElementHelper x_h = new DOMElementHelper(x);
host_url = x_h.getElementText();
if (StringUtil.isStringEmpty(host_url))
{ // default the host tag image URL and fixup parameter
host_url = "tag_host.gif";
host_fixup = true;
} // end if
else // get the "fixup" parameter
host_fixup = x_h.hasAttribute("fixup");
host_alt = x.getAttribute("alt");
if (StringUtil.isStringEmpty(host_alt))
host_alt = "Host!";
Integer xi = x_h.getAttributeInt("width");
host_width = (xi!=null) ? xi.intValue() : 40;
xi = x_h.getAttributeInt("height");
host_height = (xi!=null) ? xi.intValue() : 20;
} // end if
else
{ // just default all the host tag parameters
host_url = "tag_host.gif";
host_fixup = true;
host_alt = "Host!";
host_width = 40;
host_height = 20;
} // end else
bullet = new ImageHandler(cfg_h.getSubElement("bullet"),"purple-ball.gif","*",14,14);
host = new ImageHandler(cfg_h.getSubElement("host-image"),"tag_host.gif","Host!",40,20);
} // end setConfiguration