,
+ * 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.Random;
+import com.silverwrist.util.cachemap.*;
+import com.silverwrist.venice.core.*;
+import com.silverwrist.venice.db.*;
+
+class AdvertisementImpl implements Advertisement
+{
+ /*--------------------------------------------------------------------------------
+ * Static data members
+ *--------------------------------------------------------------------------------
+ */
+
+ private static Random rng = new Random(System.currentTimeMillis());
+ private static CacheMap ad_cache = new CacheMap(500);
+
+ /*--------------------------------------------------------------------------------
+ * Attributes
+ *--------------------------------------------------------------------------------
+ */
+
+ private DataPool datapool;
+ private int adid;
+ private String imagepath;
+ private short style;
+ private String caption;
+ private String linkurl;
+
+ /*--------------------------------------------------------------------------------
+ * Constructor
+ *--------------------------------------------------------------------------------
+ */
+
+ protected AdvertisementImpl(DataPool datapool, ResultSet rs) throws SQLException
+ {
+ this.datapool = datapool;
+ this.adid = rs.getInt("adid");
+ this.imagepath = rs.getString("imagepath");
+ this.style = rs.getShort("pathstyle");
+ this.caption = rs.getString("caption");
+ this.linkurl = rs.getString("linkurl");
+
+ } // end constructor
+
+ /*--------------------------------------------------------------------------------
+ * Internal functions
+ *--------------------------------------------------------------------------------
+ */
+
+ private static Advertisement getTheAd(DataPool datapool, Statement stmt, int ad_id) throws SQLException
+ {
+ Integer my_ad_id = new Integer(ad_id);
+ Advertisement rc = (Advertisement)(ad_cache.get(my_ad_id));
+ if (rc!=null)
+ return rc;
+
+ ResultSet rs = stmt.executeQuery("SELECT * From adverts WHERE adid = " + ad_id + ";");
+ if (!(rs.next()))
+ return null;
+ rc = new AdvertisementImpl(datapool,rs);
+ ad_cache.put(my_ad_id,rc);
+ return rc;
+
+ } // end getTheAd
+
+ /*--------------------------------------------------------------------------------
+ * Implementations from interface Advertisement
+ *--------------------------------------------------------------------------------
+ */
+
+ public int getAdID()
+ {
+ return adid;
+
+ } // end getAdID
+
+ public String getImagePath()
+ {
+ return imagepath;
+
+ } // end getImagePath
+
+ public short getImagePathStyle()
+ {
+ return style;
+
+ } // end getImagePathStyle
+
+ public String getCaption()
+ {
+ return caption;
+
+ } // end getCaption
+
+ public String getLinkURL()
+ {
+ return linkurl;
+
+ } // end getLinkURL
+
+ public void hit(String remote_addr)
+ { // this does nothing right now
+ } // end hit
+
+ /*--------------------------------------------------------------------------------
+ * Static functions for use within package
+ *--------------------------------------------------------------------------------
+ */
+
+ static Advertisement getAdByID(DataPool datapool, int id)
+ {
+ Connection conn = null;
+
+ try
+ { // get a database connection and call the internal function
+ conn = datapool.getConnection();
+ Statement stmt = conn.createStatement();
+ return getTheAd(datapool,stmt,id);
+
+ } // end try
+ catch (SQLException e)
+ { // database error - no ad
+ return null;
+
+ } // end catch
+ finally
+ { // make sure the connection is released before we go
+ if (conn!=null)
+ datapool.releaseConnection(conn);
+
+ } // end finally
+
+ } // end getAdByID
+
+ static Advertisement getRandomAd(DataPool datapool)
+ {
+ Connection conn = null;
+
+ try
+ { // get a database connection and call the internal function
+ conn = datapool.getConnection();
+ Statement stmt = conn.createStatement();
+ ResultSet rs = stmt.executeQuery("SELECT MAX(adid) FROM adverts;");
+ if (!(rs.next()))
+ throw new InternalStateError("getRandomAd() must be able to find MAX(adid)!");
+ int maximum = rs.getInt(1);
+
+ for (int i=0; i<100; i++)
+ { // select an ad ID
+ int ad_id = rng.nextInt(maximum) + 1;
+ Advertisement rc = getTheAd(datapool,stmt,ad_id);
+ if (rc!=null)
+ return rc;
+
+ } // end for
+
+ // else just dump out and return null
+
+ } // end try
+ catch (SQLException e)
+ { // database error - no ad
+ return null;
+
+ } // end catch
+ finally
+ { // make sure the connection is released before we go
+ if (conn!=null)
+ datapool.releaseConnection(conn);
+
+ } // end finally
+
+ return null; // no ad
+
+ } // end getRandomAd
+
+} // end class AdvertisementImpl
diff --git a/src/com/silverwrist/venice/core/impl/UserContextImpl.java b/src/com/silverwrist/venice/core/impl/UserContextImpl.java
index 6da5cc3..076d8ab 100644
--- a/src/com/silverwrist/venice/core/impl/UserContextImpl.java
+++ b/src/com/silverwrist/venice/core/impl/UserContextImpl.java
@@ -1345,6 +1345,13 @@ class UserContextImpl implements UserContext, UserBackend
} // end authenticateWithToken
+ public Advertisement selectAd()
+ {
+ // just get a random ad for now
+ return AdvertisementImpl.getRandomAd(datapool);
+
+ } // end selectAd
+
/*--------------------------------------------------------------------------------
* Implementations from interface UserBackend
*--------------------------------------------------------------------------------
diff --git a/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java b/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java
index c1cf4cc..262794c 100644
--- a/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java
+++ b/src/com/silverwrist/venice/core/impl/VeniceEngineImpl.java
@@ -1567,6 +1567,19 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
} // end getNumAuditRecordsPerPage
+ public Advertisement getAdByID(int id)
+ {
+ return AdvertisementImpl.getAdByID(datapool,id);
+
+ } // end getAdByID
+
+ public Advertisement selectAd()
+ {
+ // just get a random ad for now
+ return AdvertisementImpl.getRandomAd(datapool);
+
+ } // end selectAd
+
/*--------------------------------------------------------------------------------
* Implementations from interface EngineBackend
*--------------------------------------------------------------------------------
diff --git a/src/com/silverwrist/venice/servlets/VeniceServlet.java b/src/com/silverwrist/venice/servlets/VeniceServlet.java
index b15089a..7775ed4 100644
--- a/src/com/silverwrist/venice/servlets/VeniceServlet.java
+++ b/src/com/silverwrist/venice/servlets/VeniceServlet.java
@@ -608,7 +608,7 @@ public abstract class VeniceServlet extends HttpServlet
Variables.flushCookies(request,response);
if (content!=null)
{ // display the content!
- BaseJSPData base = new BaseJSPData(getMyLocation(request,engine,user,rdat),content);
+ BaseJSPData base = new BaseJSPData(engine,user,getMyLocation(request,engine,user,rdat),content);
base.transfer(ctxt,rdat);
} // end if
@@ -663,7 +663,7 @@ public abstract class VeniceServlet extends HttpServlet
catch (ServletMultipartException e)
{ // this is an error message we need to generate and just bail out on
logger.error("ServletMultipartException caught in doVenicePost!",e);
- BaseJSPData base = new BaseJSPData(getMyLocation(request,engine,user,rdat),
+ BaseJSPData base = new BaseJSPData(engine,user,getMyLocation(request,engine,user,rdat),
new ErrorBox(null,"Internal Error: " + e.getMessage(),null));
base.transfer(ctxt,rdat);
return;
@@ -712,7 +712,7 @@ public abstract class VeniceServlet extends HttpServlet
Variables.flushCookies(request,response);
if (content!=null)
{ // display the content!
- BaseJSPData base = new BaseJSPData(getMyLocation(request,engine,user,rdat),content);
+ BaseJSPData base = new BaseJSPData(engine,user,getMyLocation(request,engine,user,rdat),content);
base.transfer(ctxt,rdat);
} // end if
diff --git a/src/com/silverwrist/venice/servlets/format/BaseJSPData.java b/src/com/silverwrist/venice/servlets/format/BaseJSPData.java
index 8889fe7..60ad74f 100644
--- a/src/com/silverwrist/venice/servlets/format/BaseJSPData.java
+++ b/src/com/silverwrist/venice/servlets/format/BaseJSPData.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
+import com.silverwrist.venice.core.*;
import com.silverwrist.venice.servlets.Variables;
import com.silverwrist.venice.servlets.format.menus.LeftMenu;
@@ -40,6 +41,8 @@ public class BaseJSPData
*--------------------------------------------------------------------------------
*/
+ private VeniceEngine engine; // the Venice engine
+ private UserContext user; // user context
private String location; // location string to use for this page
private VeniceContent content; // the actual content
private boolean login_links = true; // show login links up top?
@@ -49,8 +52,10 @@ public class BaseJSPData
*--------------------------------------------------------------------------------
*/
- public BaseJSPData(String location, VeniceContent content)
+ public BaseJSPData(VeniceEngine engine, UserContext user, String location, VeniceContent content)
{
+ this.engine = engine;
+ this.user = user;
this.location = location;
this.content = content;
@@ -116,6 +121,47 @@ public class BaseJSPData
} // end transfer
+ public void renderBannerAd(Writer out, RenderData rdat) throws IOException
+ {
+ Advertisement advert;
+ if (user.isLoggedIn())
+ advert = user.selectAd();
+ else
+ advert = engine.selectAd();
+ if (advert==null)
+ { // no advert found - bail out now!
+ out.write(" ");
+ return;
+
+ } // end if
+
+ String full_image_path;
+ if (advert.getImagePathStyle()==Advertisement.CONTEXT_RELATIVE)
+ { // return the full image path
+ full_image_path = rdat.getContextRelativePath(advert.getImagePath());
+
+ } // end if
+ else
+ { // can't render the ad - just punt
+ out.write(" ");
+ return;
+
+ } // end else
+
+ // Write the banner ad.
+ String url = advert.getLinkURL();
+ String capt = advert.getCaption();
+ if (url!=null)
+ out.write("");
+ out.write("");
+ if (url!=null)
+ out.write("");
+
+ } // end renderBannerAd
+
public void renderMenu(HttpSession session, Writer out, RenderData rdat) throws IOException
{
ComponentRender menu = Variables.getMenu(session);
diff --git a/src/com/silverwrist/venice/servlets/format/RenderData.java b/src/com/silverwrist/venice/servlets/format/RenderData.java
index 80f467b..63bd1fd 100644
--- a/src/com/silverwrist/venice/servlets/format/RenderData.java
+++ b/src/com/silverwrist/venice/servlets/format/RenderData.java
@@ -190,6 +190,15 @@ public class RenderData
} // end getStaticIncludePath
+ public String getContextRelativePath(String name)
+ {
+ StringBuffer buf = new StringBuffer(request.getContextPath());
+ if (name.charAt(0)!='/')
+ buf.append('/');
+ return buf.append(name).toString();
+
+ } // end getContextRelativePath
+
public String getStdFontTag(String color, int size)
{
return rconf.getStdFontTag(color,size);
diff --git a/web/format/base.jsp b/web/format/base.jsp
index a9acac7..c747c5e 100644
--- a/web/format/base.jsp
+++ b/web/format/base.jsp
@@ -55,10 +55,7 @@
<% if (rdat.useHTMLComments()) { %><% } %>
- <%-- BEGIN TEMP - Banner Ad code --%>
-
- <%-- END TEMP - Banner Ad Code --%>
+ <% basedat.renderBannerAd(out,rdat); %>
|
diff --git a/web/images/ads/Brown.gif b/web/images/ads/Brown.gif
new file mode 100644
index 0000000..68f0996
Binary files /dev/null and b/web/images/ads/Brown.gif differ
diff --git a/web/images/ads/Caine.gif b/web/images/ads/Caine.gif
new file mode 100644
index 0000000..112832d
Binary files /dev/null and b/web/images/ads/Caine.gif differ
diff --git a/web/images/ads/Frost.gif b/web/images/ads/Frost.gif
new file mode 100644
index 0000000..13fe7f6
Binary files /dev/null and b/web/images/ads/Frost.gif differ
diff --git a/web/images/ads/Keller.gif b/web/images/ads/Keller.gif
new file mode 100644
index 0000000..99ee82d
Binary files /dev/null and b/web/images/ads/Keller.gif differ
diff --git a/web/images/ads/Letterman.gif b/web/images/ads/Letterman.gif
new file mode 100644
index 0000000..11af0dc
Binary files /dev/null and b/web/images/ads/Letterman.gif differ
diff --git a/web/images/ads/Pooh.gif b/web/images/ads/Pooh.gif
new file mode 100644
index 0000000..3b433fa
Binary files /dev/null and b/web/images/ads/Pooh.gif differ
diff --git a/web/images/ads/Shakespeare.gif b/web/images/ads/Shakespeare.gif
new file mode 100644
index 0000000..a03139e
Binary files /dev/null and b/web/images/ads/Shakespeare.gif differ
diff --git a/web/images/ads/Thomas.gif b/web/images/ads/Thomas.gif
new file mode 100644
index 0000000..496be40
Binary files /dev/null and b/web/images/ads/Thomas.gif differ
diff --git a/web/images/ads/WolinskiTeamwork.gif b/web/images/ads/WolinskiTeamwork.gif
new file mode 100644
index 0000000..9cddd4f
Binary files /dev/null and b/web/images/ads/WolinskiTeamwork.gif differ
diff --git a/web/images/ads/Wonder.gif b/web/images/ads/Wonder.gif
new file mode 100644
index 0000000..7669e49
Binary files /dev/null and b/web/images/ads/Wonder.gif differ
diff --git a/web/images/ads/bonaparte.gif b/web/images/ads/bonaparte.gif
new file mode 100644
index 0000000..bdd5cd0
Binary files /dev/null and b/web/images/ads/bonaparte.gif differ
diff --git a/web/images/ads/buscaglia.gif b/web/images/ads/buscaglia.gif
new file mode 100644
index 0000000..8cf616c
Binary files /dev/null and b/web/images/ads/buscaglia.gif differ
diff --git a/web/images/ads/dana.gif b/web/images/ads/dana.gif
new file mode 100644
index 0000000..dccb6d8
Binary files /dev/null and b/web/images/ads/dana.gif differ
diff --git a/web/images/ads/deadpoets.gif b/web/images/ads/deadpoets.gif
new file mode 100644
index 0000000..1840274
Binary files /dev/null and b/web/images/ads/deadpoets.gif differ
diff --git a/web/images/ads/ford.gif b/web/images/ads/ford.gif
new file mode 100644
index 0000000..4f3fd33
Binary files /dev/null and b/web/images/ads/ford.gif differ
diff --git a/web/images/ads/karen.gif b/web/images/ads/karen.gif
new file mode 100644
index 0000000..f7d8482
Binary files /dev/null and b/web/images/ads/karen.gif differ
diff --git a/web/images/ads/lynett.gif b/web/images/ads/lynett.gif
new file mode 100644
index 0000000..cd57a4c
Binary files /dev/null and b/web/images/ads/lynett.gif differ
diff --git a/web/images/ads/mcauliffe.gif b/web/images/ads/mcauliffe.gif
new file mode 100644
index 0000000..69a256a
Binary files /dev/null and b/web/images/ads/mcauliffe.gif differ
diff --git a/web/images/ads/midler.gif b/web/images/ads/midler.gif
new file mode 100644
index 0000000..f21824a
Binary files /dev/null and b/web/images/ads/midler.gif differ
diff --git a/web/images/ads/sophocles.gif b/web/images/ads/sophocles.gif
new file mode 100644
index 0000000..8b0ff4a
Binary files /dev/null and b/web/images/ads/sophocles.gif differ
diff --git a/web/images/ads/talbert.gif b/web/images/ads/talbert.gif
new file mode 100644
index 0000000..7927862
Binary files /dev/null and b/web/images/ads/talbert.gif differ
diff --git a/web/images/ads/torvalds.gif b/web/images/ads/torvalds.gif
new file mode 100644
index 0000000..d63a5c9
Binary files /dev/null and b/web/images/ads/torvalds.gif differ
diff --git a/web/images/ads/wonka.gif b/web/images/ads/wonka.gif
new file mode 100644
index 0000000..823bc04
Binary files /dev/null and b/web/images/ads/wonka.gif differ
diff --git a/web/images/ads/worf.gif b/web/images/ads/worf.gif
new file mode 100644
index 0000000..e7e7cb3
Binary files /dev/null and b/web/images/ads/worf.gif differ