/* * [DVD.java] * * Summary: implements HTML DVD macro to sell a DVD. * * Copyright: (c) 2007-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.1 2007-03-25 add flags, B&N link, refactor */ package com.mindprod.stores; import com.mindprod.common18.EIO; import com.mindprod.common18.ST; import com.mindprod.fastcat.FastCat; import com.mindprod.htmlmacros.macro.Born; import com.mindprod.htmlmacros.macro.CountryFlag; import com.mindprod.htmlmacros.macro.GoogleCannedSearch; import com.mindprod.htmlmacros.macro.Macro; import com.mindprod.htmlmacros.support.BuildImage; import com.mindprod.htmlmacros.support.ImageAlignment; import com.mindprod.htmlmacros.support.Tools; import com.mindprod.hunkio.HunkIO; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.regex.Pattern; import static com.mindprod.htmlmacros.macro.Global.configuration; import static com.mindprod.stores.DStore.*; import static com.mindprod.stores.StockStatus.INSTOCK; import static java.lang.System.*; /** * implements HTML DVD macro to sell a DVD. *
* Expands HTML DVD macro. * Covers images names after asin. * file named after upc * * Formats data in a table. Sell DVDs at electronic and other sources if UPC is known. * * @author Roedy Green, Canadian Mind Products * @version 1.1 2007-03-25 add flags, B&N link, refactor * @see DStore * @since 2007 */ @SuppressWarnings( { "ConstantConditions" } ) public class DVD extends Macro { // declarations /** * Google search modifier to ensure find only other DVD stores */ private static final String JUST_OTHER_DVDSTORES = "-amazon -site:barnesandnoble.com -site:powells.com"; /** * this item goes on the left side. */ private static final boolean ON_LEFT = false; /** * this item goes on the right side. */ private static final boolean ON_RIGHT = true; /** * how to use the macro */ private static final String USAGE = "\nDVD macro needs asin=, upc=, [isbn=,] title= author= " + "[birth=] [death=] [type=] [notes=]"; /** * list of image formats we support for DVD cover to display in HTML. */ private static final String[] SUPPORTED_EXTENSIONS = { ".png", ".jpg", ".gif" }; // /declarations // methods /** * split isbns at comma, gets rid of spaces around comma */ private static final Pattern SPLIT_ON_COMMA = Pattern.compile( "\\s*,\\s*" ); /** * true if one or more stores was grayed out for beingout of stock or not carried */ private boolean greyed = false; /** * find best isbn to display for this store, ideally instock * * @param dvdStore DVD store * @param preferredProducts list of isbns etc in preferred order * * @return bet fit isbn, null if no fit. will be NOTCARRIED, OUTOFSTOCK or INSTOCK. */ private static BestResult best( DStore dvdStore, String[] preferredProducts ) { String bestProduct = null; StockStatus bestStockStatus = StockStatus.UNKNOWN; for ( String product : preferredProducts ) { final StockStatus stockStatus = dvdStore.getProductStatus( product, true ); if ( stockStatus.compareTo( bestStockStatus ) > 0 ) { bestStockStatus = stockStatus; bestProduct = product; // if we find an isbn in stock, no point in continuing to search. if ( bestStockStatus == StockStatus.INSTOCK ) { break; } } } // end for // we might have fallen out the loop without finding anything if ( bestStockStatus.compareTo( StockStatus.NOTCARRIED ) < 0 ) { return new BestResult( dvdStore, null, bestStockStatus ); } else { return new BestResult( dvdStore, bestProduct, bestStockStatus ); } }// /method /** * Build a link to a DVD at dummy vendor. May be needed later. * * @param onRight true if inserting on right side of table. * * @return HTML for a filler, dummy vendor. */ @SuppressWarnings( { "SameParameterValue" } ) private static String buildDummy( boolean onRight ) { return onRight ? "