CVS: TapestryBook/examples-library/src/java/bannerads/library/components BannerAd.java,NONE,1.1
Howard Lewis Ship <[email protected]> Sun, 13 Jul 2003 15:42:17 -0700
| Newsgroups | gmane.comp.java.tapestry.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/tapestry/TapestryBook/examples-library/src/java/bannerads/library/components
In directory sc8-pr-cvs1:/tmp/cvs-serv3466/examples-library/src/java/bannerads/library/components
Added Files:
BannerAd.java
Log Message:
Move the examples and bannerads libraries into a new examples-library subproject.
--- NEW FILE: BannerAd.java ---
package bannerads.library.components;
import org.apache.tapestry.AbstractComponent;
import org.apache.tapestry.IEngine;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.engine.ILink;
import bannerads.library.*;
import bannerads.library.IBanner;
import bannerads.library.IBannerSource;
/**
* Renders a <a> tag around a <img> tag; this consistitues a
* banner impression.
*/
public class BannerAd extends AbstractComponent
{
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{
if (cycle.isRewinding())
return;
IBanner banner = getRandomBanner(cycle);
IEngineService service = cycle.getEngine().getService(BannerService.SERVICE_NAME);
ILink link = service.getLink(cycle, this, new Object[] { banner.getId()});
writer.begin("a");
writer.attribute("href", link.getURL());
renderInformalParameters(writer, cycle);
writer.beginEmpty("img");
writer.attribute("src", banner.getImageURL());
writer.attribute("width", banner.getWidth());
writer.attribute("height", banner.getHeight());
writer.attribute("alt", banner.getTitle());
writer.attribute("border", 0);
writer.end(); // <a>
}
private IBanner getRandomBanner(IRequestCycle cycle)
{
IEngine engine = cycle.getEngine();
IBannerSource source =
(IBannerSource) engine.getSpecification().getExtension(
IBannerSource.BANNER_SOURCE_EXTENSION_NAME,
IBannerSource.class);
source.initialize(cycle);
IBanner result = source.getRandomBanner();
source.recordImpression(result.getId());
return result;
}
}
-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1