/* * [MailTo.java] * * Summary: Generate a reference to a masker-generated email address. * * 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. * <!-- macro Mailto piotr "Piotr Kobzda" --> is shorthand for <!-- macro Image mailto/piotr * png "email Piotr * Kobzda" both --> * Optional third parm: * both : show both name and email address * name : show name, link to email address image * email : (default) just show email address. */ package com.mindprod.htmlmacros.macro; import com.mindprod.htmlmacros.support.BuildImage; import com.mindprod.htmlmacros.support.ImageAlignment; import com.mindprod.htmlmacros.support.Tools; import static java.lang.System.*; /** * Generate a reference to a masker-generated email address. * * @author Roedy Green, Canadian Mind Products * @version 1.8 2009-02-06 include go package in ZIP bundle. * <!-- macro Mailto piotr "Piotr Kobzda" --> is shorthand for <!-- macro Image mailto/piotr.png * "email Piotr * Kobzda" absmiddle --> * Optional third parm: * both : show both name and email address * name : show name, link to email address image * email : (default) just show email address. * @since 2009 */ public final class MailTo extends Macro { /** how to use the macro */ /** * how to use the macro */ private static final String USAGE = "\nMailTo macro needs mungedEmailImage(name of masker file without .png) " + "personName [email/name/both]"; /** * Expand the Mailto macro, specialised version of Image macro * * @param parms first is image file in mindprod/image second is text for alt * @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( "M" ); } if ( !( 2 <= parms.length && parms.length <= 3 ) ) { throw new IllegalArgumentException( USAGE ); } final String mungedEmailImageName = parms[ 0 ]; final String name = parms[ 1 ]; final String show = ( parms.length > 2 ) ? parms[ 2 ] : "email"; // tack space on each end in case client left it out. Two spaces // will collapse to one. if ( mungedEmailImageName.startsWith( "mailto/" ) ) { throw new IllegalArgumentException( "MailTo macro mungedEmailImageName [" + mungedEmailImageName + "] should not start with \"mailto/\"." ); } if ( mungedEmailImageName.endsWith( ".png" ) ) { throw new IllegalArgumentException( "MailTo macro mungedEmailImageName [" + mungedEmailImageName + "] should not end with \".png\"." ); } if ( mungedEmailImageName.indexOf( '@' ) >= 0 ) { throw new IllegalArgumentException( "MailTo macro mungedEmailImageName [" + mungedEmailImageName + "] should not contain an @." ); } if ( show.equalsIgnoreCase( "email" ) || show.equalsIgnoreCase( "mailto" ) ) { // Padding around it handled by mailto CSS style, fine tuning of vertical position // handled by style too. return BuildImage.buildImgTag( "mailto/" + mungedEmailImageName + ".png", "email " + name, ImageAlignment.none, "mailto", fileBeingDistributed ); } else if ( show.equalsIgnoreCase( "name" ) ) { return Tools.completeLink( "image/mailto" + mungedEmailImageName + ".png", name, "mailto", fileBeingDistributed ); } else if ( show.equalsIgnoreCase( "both" ) ) { return name + BuildImage.buildImgTag( "mailto/" + mungedEmailImageName + ".png", "email " + name, ImageAlignment.none, "mailto", fileBeingDistributed ); } else { throw new IllegalArgumentException( USAGE ); } } }