/*
* [Reunion.java]
*
* Summary: Expands HTML Reunion macro, formats data in a table.
*
* 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.
*/
package com.mindprod.htmlmacros.macro;
import com.mindprod.common18.Misc;
import com.mindprod.common18.ST;
import com.mindprod.fastcat.FastCat;
import com.mindprod.htmlmacros.support.BuildImage;
import com.mindprod.htmlmacros.support.ImageAlignment;
import com.mindprod.htmlmacros.support.Tools;
import static com.mindprod.htmlmacros.macro.Global.configuration;
import static java.lang.System.*;
/**
* Expands HTML Reunion macro, formats data in a table.
*
*
* @author Roedy Green, Canadian Mind Products
* @version 1.8 2009-02-06 include go package in ZIP bundle.
* @noinspection WeakerAccess
* @since 2009
*/
public final class Reunion extends Macro
{
/**
* suffix for a tag
*/
private static final String TAG_TAIL = configuration.getTagTail();
/**
* how to use the macro
*/
private static final String USAGE = "\nReunion macro needs oldFirst oldLast newFirst newLast significantOther "
+ "birthdate photo coming excuse homePhone workPhone emailHint emailMungImage" +
" website address "
+ "city prov postal country bringing";
/**
* calculate attendance text. Also used by LL macro.
*
* @param comingCode Y M U L D Z
*
* @return text to describe attendance
*/
static String calcComingText( char comingCode )
{
switch ( comingCode )
{
case '+':
return "ATTENDED";
case '-':
return "-";
case 'Y':
return "ATTENDING";
case 'N':
return "not coming";
case 'M':
return "might be coming";
case 'U':
return "not contacted yet";
case 'L':
return "left a message";
case 'D':
return "deceased";
case 'Z':
return "no show";
default:
throw new IllegalArgumentException( "Reunion macro invalid comingCode "
+ comingCode + " should be + - Y N M U L D Z" );
}
}
/**
* Generate macro expansion for Reunion macro.
*
* @param parms parsed params for the macro. parms typically look like this: -- macro Reunion
* Munroe Green
Roedy Green
1948-02-04
"roedy.jpg" Y "happy to come"
* "(250) 361-9093"(home) "(250) 361-9093"(work)
"roedyg at mindprod.com" (email
* munged) roedy(emailimg) mindprod.com(website)
"#101 - 2536 Wark Street"
* Victoria BC "V8T 4G8" Canada
"assorted soft ciders".
* @param quiet true if want output suppressed.
* @param verbose @return expanded text in the form of a table entry.
*/
@SuppressWarnings( { "UnusedAssignment" } )
public final String expandMacro( String[] parms, final boolean quiet, final boolean verbose )
{
if ( !quiet )
{
out.print( "R" );
}
if ( parms.length != 20 )
{
throw new IllegalArgumentException( USAGE );
}
int i = 0;
final String oldFirst = parms[ i++ ];
final String oldLast = parms[ i++ ];
final String newFirst = parms[ i++ ];
final String newLast = parms[ i++ ];
String sigOther = parms[ i++ ];
if ( sigOther.length() == 0
|| sigOther.equalsIgnoreCase( "so" )
|| sigOther.equalsIgnoreCase( "sigOther" )
|| sigOther.equalsIgnoreCase( "significantOther" ) )
{
sigOther = "";
}
String birthDate = parms[ i++ ];
if ( birthDate.length() == 0
|| birthDate.equalsIgnoreCase( "birthDate" ) )
{
birthDate = " ";
}
String photo = parms[ i++ ];
if ( photo.length() == 0 || photo.equals( "photo" ) || photo.equals(
"image" ) )
{
photo = " ";
}
else
{
// " + BuildImage.buildImgTag(
"mailto/" + emailHandle + ".png",
"email " + newFirst + " " + newLast,
ImageAlignment.none,
"mailto",
fileBeingProcessed );
}
String website = parms[ i++ ];
if ( website.length() == 0 || website.equals( "website" ) )
{
website = " ";
}
else
{
website = ST.chopLeadingString( website, "http://" );
final String cssClass = Global.assignCSSClasses.assignCSSClass( "http://" + website, fileBeingProcessed );
final FastCat sb = new FastCat( 7 );
sb.append( "" );
sb.append( website );
sb.append( "" );
website = sb.toString();
}
String address = parms[ i++ ];
if ( address.length() == 0 || address.equals( "address" ) )
{
address = " ";
}
String city = parms[ i++ ];
if ( city.length() == 0 || city.equals( "city" ) )
{
city = " ";
}
String stateProv = parms[ i++ ];
if ( stateProv.length() == 0 || stateProv.equals( "prov" ) )
{
stateProv = " ";
}
String postal = parms[ i++ ];
if ( postal.length() == 0 || postal.equals( "postal" ) )
{
postal = " ";
}
else
{
postal = Tools.nonBreaking( postal.toUpperCase() );
}
String country = parms[ i++ ];
if ( country.length() == 0 || country.equals( "country" ) )
{
country = " ";
}
String bringing = parms[ i++ ];
if ( bringing.length() == 0 || bringing.equals( "bringing" ) || bringing
.equals( "bring" ) )
{
bringing = " ";
}
final String stateProvClass = country.equals( "Canada" ) ? "prov" : "state";
final String postalClass = country.equals( "USA" ) ? "zip" : "postal";
final String phoneClass = country.equals( "Canada" ) || country.equals( "USA" ) ? "naphone" : "intphone";
// generate the macro expansion now we have all the information needed
final String br = configuration.getBr();
final FastCat sb = new FastCat( 59 );
sb.append( "" );
sb.append( oldFirst );
sb.append( "" );
sb.append( br );
sb.append( "" );
sb.append( oldLast );
sb.append( " | \n" );
sb.append( newFirst );
sb.append( " " );
sb.append( newLast );
sb.append( " | \n" );
sb.append( homePhone );
sb.append( " | \n" );
sb.append( workPhone );
sb.append( " | \n" );
sb.append( comingText );
sb.append( " |
" );
sb.append( photo );
sb.append( " | \n" );
sb.append( sigOther );
sb.append( " | \n" );
sb.append( email );
sb.append( " | \n" );
sb.append( website );
sb.append( " | \n" );
sb.append( excuse );
sb.append( " | \n" );
sb.append( bringing );
sb.append( " |
\n" );
sb.append( address );
sb.append( " | \n" );
sb.append( birthDate );
sb.append( " |
\n" );
sb.append( city );
sb.append( " | \n" );
sb.append( stateProv );
sb.append( " | \n" );
sb.append( postal );
sb.append( " | \n" );
sb.append( country );
sb.append( " |
\n" );
sb.append( configuration.getHr() );
sb.append( " |
" );
return sb.toString();
}
} // end Reunion