/* * [RSS.java] * * Summary: Generate an RSS feed item, both inline HTML and export XML item to file. * * Copyright: (c) 2008-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 2008-07-31 */ package com.mindprod.htmlmacros.macro; import com.mindprod.common18.BigDate; import com.mindprod.fastcat.FastCat; import com.mindprod.htmlmacros.support.RSSBatchLog; import com.mindprod.htmlmacros.support.RSSFeedLog; import com.mindprod.htmlmacros.support.RSSSortableItem; import static com.mindprod.htmlmacros.macro.Global.configuration; import static java.lang.System.*; /** * Generate an RSS feed item, both inline HTML and export XML item to file. *

* combined binary feed rss/temp/rss.bin * for later processing into separate RSS2 feeds. * rss/prelude/xxx.xml must exist to define the prelude header for each feed. * where xxx in the name of the feed. * Result is rss/xxx.xml generated RSS2 feed where xxx is the feed name. * The title and description for each time may contain HTML entities and HTML tags. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2008-07-31 * @see com.mindprod.htmlmacros.macro.RSSBegin * @see com.mindprod.htmlmacros.macro.RSSEnd * @since 2008-07-31 */ @SuppressWarnings( { "UnusedDeclaration", "WeakerAccess" } ) public final class RSS extends Macro { /** * Today as a BigDate ordinal */ private static final int now = Global.TODAY.getOrdinal(); /** * how to use the RSS macro */ /** * how to use the macro */ private static final String USAGE = "\nRSS macro needs [feedName] [YYYY-MM-DD] [uPath] [title] " + "[description]"; /** * Generate RSS feed, both as HTML item and as RSS-2 item in XML. *

* * feedName is the name of the feed. e.g. jgloss. It corresponds to the file * of generated RSS items: E:\mindprod\include\rssjgloss.xml. * That file will need a prelude and postlude before posting. * Called twice, once to save data to log, and later to expandNoRef log entry. * * @param parms five parms as strings * @param quiet true if want output suppressed. * @param verbose @return expanded macro text */ public String expandMacro( String[] parms, final boolean quiet, final boolean verbose ) { if ( !quiet ) { out.print( "R" ); } if ( parms.length != 5 ) { throw new IllegalArgumentException( USAGE ); } try { final String feedName = parms[ 0 ]; final String dateString = parms[ 1 ]; final int year = Integer.parseInt( dateString.substring( 0, 4 ) ); final int month = Integer.parseInt( dateString.substring( 5, 7 ) ); final int day = Integer.parseInt( dateString.substring( 8, 10 ) ); final BigDate publishDate = new BigDate( year, month, day ); final int ordinal = publishDate.getOrdinal(); final String link = parms[ 2 ]; final String title = parms[ 3 ]; final String description = parms[ 4 ]; RSSSortableItem item = new RSSSortableItem( feedName, ordinal, link, title, description ); // Usually we will log this both the the feed and to an HTML batch for later rendering. if ( ordinal < now - Math.max( configuration.getRSSKeepDays(), configuration.getRSSDisplayDays() ) ) { err.println( "Warning: expired RSS item ignored " + fileBeingProcessed.toString() + " : " + title + "\n" ); } if ( ordinal >= now - configuration.getRSSKeepDays() ) { RSSFeedLog.logFeedItem( item ); } if ( ordinal >= now - configuration.getRSSDisplayDays() ) { if ( RSSBatchLog.inBatch ) { // we are inside RSSBegin .. RSSEnd, accumulate on disk to expandNoRef later. RSSBatchLog.logBatchItem( item ); // leave marker to help find where one RSS ends and the next starts. // Marker must be carefully constructed so Compactor does not meddle with it by removing space or \n final FastCat sb = new FastCat( 7 ); sb.append( "" ); return sb.toString(); } else { // expandNoRef inline now , we are not inside a RSSBegin .. RSSEnd return item.asHTML( fileBeingProcessed ); } } else { final FastCat sb = new FastCat( 5 ); sb.append( "" ); return sb.toString(); } } catch ( StringIndexOutOfBoundsException e ) { throw new IllegalArgumentException( USAGE ); } catch ( NumberFormatException e ) { throw new IllegalArgumentException( USAGE ); } } }