001 /*
002 * Created by IntelliJ IDEA.
003 * User: d@hd.org
004 * Date: 22-Jul-02
005 * Time: 18:13:44
006
007 Copyright (c) 1996-2011, Damon Hart-Davis
008 All rights reserved.
009
010 Redistribution and use in source and binary forms, with or without
011 modification, are permitted provided that the following conditions are
012 met:
013
014 * Redistributions of source code must retain the above copyright
015 notice, this list of conditions and the following disclaimer.
016
017 * Redistributions in binary form must reproduce the above copyright
018 notice, this list of conditions and the following disclaimer in the
019 documentation and/or other materials provided with the
020 distribution.
021
022 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
023 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
024 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
025 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
026 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
027 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
028 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
029 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
030 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
031 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
032 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
033
034 */
035 package org.hd.d.pg2k.webSvr.ads;
036
037 import java.util.Random;
038
039 import org.hd.d.pg2k.webSvr.util.WebConsts;
040
041 import ORG.hd.d.IsDebug;
042
043 /**This implements the AdBrite bean.
044 */
045 public final class AdBriteBean implements AdBeanInterface
046 {
047 /**Parameter value to select vertical (tower) format (default). */
048 public static final String AD_FORMAT_AB_VERTICAL = "ABVertical";
049
050 /**Parameter value to select horizontal (banner) format. */
051 public static final String AD_FORMAT_AB_HORIZONTAL = "ABHorizontal";
052
053 /**Requested ad format or null; volatile to allow lock-less thread-safe access. */
054 private volatile String selectedFormat;
055
056 /**Can be used to set general parameters for the bean, or can be null.
057 */
058 public AdBeanInterface setParams(final String rawParams)
059 {
060 selectedFormat = rawParams;
061 return(this);
062 }
063
064 /**Can make an HTML body-text insert in the given context.
065 * Always true for AdBrite.
066 */
067 public boolean canMakeHTMLBodyInsert(final Context ctxt)
068 {
069 return(true);
070 }
071
072 /**Make HTML body text in the given context, or null if none can be made.
073 * @param ctxt not used
074 * @param source not used
075 */
076 public String getHTMLBodyInsert(final Context ctxt,
077 final Random source)
078 {
079 if(!canMakeHTMLBodyInsert(ctxt)) { return(""); } // Definitely cannot.
080
081 final int capacity = 599;
082 final StringBuilder sb = new StringBuilder(capacity);
083 if(AD_FORMAT_AB_HORIZONTAL.equals(selectedFormat))
084 {
085 // Horizontal banner requested...
086 // Variable number of ads shown.
087 sb.append("<!-- Begin: AdBrite -->").append(WebConsts.WEB_LINE_END);
088 sb.append("<style type=\"text/css\">").append(WebConsts.WEB_LINE_END);
089 sb.append(".adHeadline {font: bold 10pt Arial; text-decoration: underline; color: blue; background-color: white;}").append(WebConsts.WEB_LINE_END);
090 sb.append(".adText {font: normal 10pt Arial; text-decoration: none; color: black; background-color: white;}").append(WebConsts.WEB_LINE_END);
091 sb.append("</style>").append(WebConsts.WEB_LINE_END);
092 sb.append("<script type=\"text/javascript\" src=\"http://3.adbrite.com/mb/text_group.php?sid=44471&col=").append(source.nextBoolean() ? 2 : 4).append("&br=1\"></script>").append(WebConsts.WEB_LINE_END);
093 sb.append("<p />").append(WebConsts.WEB_LINE_END);
094 sb.append("<div><a class=\"adHeadline\" target=\"_top\" href=\"http://www.adbrite.com/mb/commerce/purchase_form.php?opid=44471&afsid=1\">Your Ad Here</a></div>").append(WebConsts.WEB_LINE_END);
095 sb.append("<!-- End: AdBrite -->").append(WebConsts.WEB_LINE_END);
096 }
097 else
098 {
099 // Vertical tower (default)...
100 sb.append("<!-- Begin: AdBrite -->").append(WebConsts.WEB_LINE_END);
101 sb.append("<style type=\"text/css\">").append(WebConsts.WEB_LINE_END);
102 sb.append(".adHeadline {font: bold 10pt Arial; text-decoration: underline; color: blue; background-color: white;}").append(WebConsts.WEB_LINE_END);
103 sb.append(".adText {font: normal 10pt Arial; text-decoration: none; color: black; background-color: white;}").append(WebConsts.WEB_LINE_END);
104 sb.append("</style>").append(WebConsts.WEB_LINE_END);
105 sb.append("<script type=\"text/javascript\" src=\"http://3.adbrite.com/mb/text_group.php?sid=44471&br=1\"></script>").append(WebConsts.WEB_LINE_END);
106 sb.append("<p />").append(WebConsts.WEB_LINE_END);
107 sb.append("<div><a class=\"adHeadline\" target=\"_top\" href=\"http://www.adbrite.com/mb/commerce/purchase_form.php?opid=44471&afsid=1\">Your Ad Here</a></div>").append(WebConsts.WEB_LINE_END);
108 sb.append("<!-- End: AdBrite -->").append(WebConsts.WEB_LINE_END);
109 }
110
111 // We can see if the initial capacity guess needs adjusting...
112 if(IsDebug.isDebug && (sb.length() > capacity))
113 { System.err.println("WARNING: AB BEAN OUTPUT LEN = " + sb.length() + " vs initial capacity guess " + capacity); }
114
115 return(sb.toString());
116 }
117 }