/* * [Revised.java] * * Summary: Handles a Revised macro. * * 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. * 1.9 2009-04-29 allow dates in either order. Allow either to be incomplete. */ package com.mindprod.htmlmacros.macro; import com.mindprod.common18.BigDate; import com.mindprod.fastcat.FastCat; import static java.lang.System.*; /** * Handles a Revised macro. *

* macro Revised verifiedDate revisedDate [why] -- * or * macro Revised revisedDate verifiedDate [why] -- * or * macro Revised verified/revisedDate *

* the verified date is the more recent date of the pair. * macro Revised 2005-07-08 2001-02 {to fix bugs} -- * * @author Roedy Green, Canadian Mind Products * @version 1.8 2009-02-06 include go package in ZIP bundle. * Java 1.2 --
generates: As of 2005-07-08 it was revised in 2001-02 for Java 1.2.
-- macro Revised * 2005-07-08 * 2001-02 --
generates: On 2005-07-08 I determined it was last revised was in 2001-02. * @since 2009 */ public final class Revised extends Macro { /** * how to use the macro */ private static final String USAGE = "\nRevised macro needs verifiedDate [revisedDate] [why]"; /** * guts to Generate revised * * @param verifiedDate in form yyyy-mm-dd date that this information about the revision * @param revisedDate in form yyyy-mm-dd, or yyyy-mm or yyyy date that this information was last revised * @param why reason for the revision, or phrase summarising the revision, * e.g. "for jdk 1.2" or " upgrading * to CSS 2" * * @return expanded href both to online and local. */ private static String expand( String verifiedDate, String revisedDate, String why ) { final FastCat sb = new FastCat( 8 ); if ( revisedDate.length() > 0 ) { // we do not use class="date" because we want date unobtrusive. sb.append( "Last revised: ", revisedDate ); // this is reverse to canonical order of parms. sb.append( " Verified: ", verifiedDate, "" ); if ( why.length() > 0 ) { sb.append( ' ' ); sb.append( why ); } sb.append( "" ); } else { sb.append( "Last revised/verified: ", verifiedDate, "" ); } return sb.toString(); } /** * Expands: Handles a Revised macro * * @param parms first is asof date, second revised date, third optional for what/why clause. * @param quiet true if want output suppressed. * @param verbose @return expanded macro HTML */ public String expandMacro( String[] parms, final boolean quiet, final boolean verbose ) { if ( !quiet ) { out.print( "R" ); } if ( !( 1 <= parms.length && parms.length <= 3 ) ) { throw new IllegalArgumentException( USAGE ); } String verifiedDate = parms[ 0 ]; final BigDate tidyVerifiedDate = BigDate.parseYYYYmmdd( verifiedDate ); if ( tidyVerifiedDate.compareTo( Global.TODAY ) > 0 ) { throw new IllegalArgumentException( "Revised macro verifiedDate : [" + verifiedDate + "] must not be in future." ); } String revisedDate = ""; String why = ""; if ( parms.length > 1 ) { revisedDate = parms[ 1 ]; final BigDate tidyRevisedDate = BigDate.parseYYYYmmdd( revisedDate ); if ( tidyRevisedDate.compareTo( Global.TODAY ) > 0 ) { throw new IllegalArgumentException( "Revised macro revisedDate: [" + revisedDate + "] must not be in the future." ); } if ( tidyVerifiedDate.compareTo( tidyRevisedDate ) < 0 ) { // dates are in reverse to canonical order. Swap them. String swap = verifiedDate; verifiedDate = revisedDate; revisedDate = swap; } else if ( tidyVerifiedDate.compareTo( tidyRevisedDate ) == 0 ) { // if dates are equal, we don't need both. Keep the longer representation. // discard the second revised date, display only the verified date as the revised date. if ( revisedDate.length() > verifiedDate.length() ) { verifiedDate = revisedDate; } revisedDate = ""; } if ( parms.length > 2 ) { why = parms[ 2 ]; } } return expand( verifiedDate, revisedDate, why ); } }