/* * [Art.java] * * Summary: Generate an affiliate reference to an art.com poster. * * 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.entities.DeEntifyStrings; import com.mindprod.fastcat.FastCat; import static com.mindprod.htmlmacros.macro.Global.configuration; import static java.lang.System.*; /** * Generate an affiliate reference to an art.com poster. * * @author Roedy Green, Canadian Mind Products * @version 1.8 2009-02-06 include go package in ZIP bundle. * @since 2009 */ public final class Art extends Macro { /** * art.com's vendor id */ private static final int ARTCOMID = 918185;// constant vendor id, art.com's id. /** * suffix for a tag */ private static final String TAG_TAIL = configuration.getTagTail(); /** * how to use the macro */ private static final String USAGE = "\nArt macro needs title productid width height"; /** * guts to Generate Art reference, displays image with title below with VIEW button. * * @param title description of print. * @param p productId of the print., no trailing A * @param width width of the print image. * @param height height of the print image. * * @return expand html for the link to art.com */ private static String expand( String title, int p, int width, int height ) { int pRounded = ( p / 1000 ) * 1000; final FastCat sb = new FastCat( 45 ); sb.append( "\n" ); sb.append( "\n" ); sb.append( "\n" ); sb.append( "
" ); sb.append( DeEntifyStrings.stripHTMLTags( title ) ); sb.append( " art print
" + "" ); sb.append( "\"View" ); sb.append( "
" ); sb.append( title );// leave decorative HTML especially
sb.append( "
\n" ); sb.append( "\n" ); return sb.toString(); } /** * generate Art.com reference given product id and size of image. Typical use: <-- macro Art "dolphins" * 10068764 74 114 --> title productid width-of-image height-of-image * * @param parms first is title second is product id third is width fourth is height * @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( "P" ); } if ( parms.length != 4 ) { throw new IllegalArgumentException( USAGE ); } final String title; final int productId; final int width; final int height; try { title = parms[ 0 ].trim(); productId = Integer.parseInt( parms[ 1 ].trim() ); width = Integer.parseInt( parms[ 2 ].trim() ); height = Integer.parseInt( parms[ 3 ].trim() ); } catch ( NumberFormatException e ) { throw new IllegalArgumentException( "Art needs numeric productid width height" ); } return expand( title, productId, width, height ); } }