/* * [InlineFooter.java] * * Summary: Generate the inline footer that inserts into the footer. * * Copyright: (c) 2014-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.0 2014-05-07 initial version */ package com.mindprod.htmlmacros.support; import com.mindprod.common18.EIO; import com.mindprod.common18.ST; import com.mindprod.compactor.Compactor; import com.mindprod.fastcat.FastCat; import com.mindprod.htmlmacros.macro.Head; import com.mindprod.htmlmacros.macro.Include; import com.mindprod.hunkio.HunkIO; import java.io.File; import java.io.IOException; import static com.mindprod.htmlmacros.macro.Global.configuration; import static java.lang.System.*; /** * Generate the inline footer that inserts into the footer. *

* This is not a macro. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2014-05-07 initial version * @see com.mindprod.htmlmacros.macro.Foot * @since 2014-05-07 */ public final class InlineFooter { // declarations /** * true means extre debug output */ private static final boolean DEBUGGING = false; // /declarations // methods /** * get the name of the corresponding footer file * * @param fileBeingDistributed name of corresponding HTML file * * @return file pointing to inline footer to include as in iframe. */ public static File getFooterFile( File fileBeingDistributed ) { return new File( Tools.getParent( fileBeingDistributed ), "foot/" + EIO.getCoreName( fileBeingDistributed ) + ".htm" ); } // /method /** * Build/update the separate appendage footer file that varies daily to handle varying PSA ads. * Might display as: * 1. PSA * 2. quotatation * 3. non-mil * There are no google ads. * * @param fileBeingDistributed file being distributed, not the footer file itself, where this file willbe inserted */ public static void updateInlineFooterFile( final File fileBeingDistributed ) { // lives in /foot/xxx.htm // generated prior to page for which it is for. final File footerFile = new File( Tools.getParent( fileBeingDistributed ), "foot/" + EIO.getCoreName( fileBeingDistributed ) + ".htm" ); if ( DEBUGGING ) { out.println( "processing footer: " + footerFile.getAbsolutePath() ); } // if footer was generated recently, we can avoid generating it, even if what is there is // slightly out of date because we have added new quotes or PSAs. // updateThisFooterNow may giva random result. if ( !configuration.shouldWeUpdateThisFooterNow( fileBeingDistributed ) && footerFile.exists() ) { // avoid recompute of footer if it has not yet expired. final long lastModified = footerFile.lastModified(); // UTC final long now = System.currentTimeMillis(); final long ageAllowed = configuration.getFooterRotateIntervalInMillis( fileBeingDistributed ); if ( lastModified + ageAllowed > now ) { return; } } if ( DEBUGGING ) { out.println( " considered for update: " + footerFile ); } // we regenerate. We avoid writing if same as prev, also untouch avoids redistributing identical aux footers. // e.g. E:/mindprod/jgloss/foot/pad.html Head headDelegate = new Head(); headDelegate.setFileBeingProcessedAndFileBeingDistributed( footerFile, footerFile ); final FastCat sb = new FastCat( 19 ); sb.append( configuration.getDoctypeForIframe( fileBeingDistributed ) ); sb.append( "\n" ); sb.append( "\n" ); sb.append( "Appendix footer for " ); sb.append( Tools.uPathName( fileBeingDistributed ) ); sb.append( "\n\n" ); // ensure none of the foot files are spidered sb.append( "\n" ); { final String screen = configuration.getStylesheetForUsual(); final String handheld = ST.chopTrailingString( screen, ".css" ) + "h.css"; sb.append( headDelegate.buildStylesheetLink( screen, "screen" ) ); sb.append( headDelegate.buildStylesheetLink( handheld, "handheld" ) ); } { final String screen = configuration.getStylesheetForJDisplay(); final String handheld = ST.chopTrailingString( screen, ".css" ) + "h.css"; sb.append( headDelegate.buildStylesheetLink( screen, "screen" ) ); sb.append( headDelegate.buildStylesheetLink( handheld, "handheld" ) ); } sb.append( "\n\n" ); sb.append( "" ); // depending the random wheel, could get quote, psa or "non-mil" // get quote aggregate category based on dir, might be overridden later by value on Foot macro. final QuoteAggregate aggregate = configuration.getQuoteAggregateForFooter( footerFile ); final String psaOrQuote = PSA.psaOrQuoteOrNonMil( aggregate, fileBeingDistributed, footerFile ); if ( psaOrQuote.contains( "