/* * [PSA.java] * * Summary: generates public service ads for the Footer. This is not a macro. It is a helper for Foot. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.8 2009-02-06 include go package in ZIP bundle. * Foot decides if do nonmil or PSA ad, and PSA decides which ad. */ package com.mindprod.htmlmacros.support; import com.mindprod.common18.BigDate; import com.mindprod.htmlmacros.macro.Global; import java.io.File; import static com.mindprod.htmlmacros.macro.Global.configuration; /** * generates public service ads for the Footer. This is not a macro. It is a helper for Foot. *

* Key methods are adForPSA and footerQuoteOfTheDay. * PSA class decides if we do non-mil, quote or PSA ad. * * @author Roedy Green, Canadian Mind Products * @version 1.8 2009-02-06 include go package in ZIP bundle. * @see com.mindprod.htmlmacros.macro.Quotation * @see com.mindprod.htmlmacros.support.PSAType * @since 2009 */ public class PSA { /** * turn on special remembrance day weighting. * treat remembrance day specially for to days prior * Change the weights. * * @see PSA * @see QuoteAggregate */ static final boolean NEAR_REMEMBRANCE_DAY = new BigDate( Global.THIS_CALENDAR_YEAR, 11, 11 ).isCelebrating( 5, 0 ); /** * turn on special Christmas weighting. * treat Christmas day specially for to days prior * Change the weights. * * @see PSA * @see QuoteAggregate */ static final boolean NEAR_CHRISTMAS = new BigDate( Global.THIS_CALENDAR_YEAR, 12, 25 ).isCelebrating( 10, 3 ); /** * weight assigned to dummy psa to represent a footer quotation, relative to weights for PSAs * Relative to about 34 total for PSAs */ static final int FOOTER_QUOTE_WEIGHT = ( NEAR_REMEMBRANCE_DAY || NEAR_CHRISTMAS ) ? 400 : 40; /** * weight assigned to non-mil-only dummy psa, relative to other PSAs. Relative to about 34 total for PSAs */ static final int NONMIL_WEIGHT = ( NEAR_REMEMBRANCE_DAY || NEAR_CHRISTMAS ) ? 1 : 5; /** * M A S T E R M E T H O D * get html for non-mil, random quote, Greenpeace ad, SpreadTheNet public service ad etc. * * @param aggregate which quote aggregate to use if generate quote rather than PSA. * @param fileBeingDistributed where the psa ad will be inserted * @param footerFile web page where iframe ad will go * * @return html to display banner and link * @see QuoteAggregate#getRandomQuotationForFile(long, java.io.File) * @see QuoteFlock.calcWeight */ public static String psaOrQuoteOrNonMil( final QuoteAggregate aggregate, final File fileBeingDistributed, final File footerFile ) { // selected PSA does not depend on directory. // are we in the Quotation pool directory final boolean suppressQuotation = Tools.dirWithSlashes( fileBeingDistributed ).equals( "quote" ); // W E I G H T S to control which ads/quotations play most frequently. One slot for each PSA advertiser. final int[] weights = PSAType.getAllWeights(); final boolean nonMil = configuration.isRestrictedToNonMil( fileBeingDistributed ); /* override usual weights for PSAType.NONMIL and PSAType.FOOTER_QUOTE */ weights[ PSAType.NONMIL.ordinal() ] = nonMil ? NONMIL_WEIGHT : 0; weights[ PSAType.FOOTER_QUOTE.ordinal() ] = suppressQuotation ? 0 : FOOTER_QUOTE_WEIGHT; final int hash = Randomiser.getHashForFilename( configuration.getFooterRotateIntervalInMillis( fileBeingDistributed ), fileBeingDistributed ); final int choice = Randomiser.getWeightedSelectorIndexForHash( hash, weights ); return PSAType.values()[ choice ].ad( fileBeingDistributed, footerFile, aggregate, -1 ); } }