/* * [Insert.java] * * Summary: Implements Insert macro. * * Copyright: (c) 2012-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.0 2012-02-12 initial version */ package com.mindprod.htmlmacros.macro; import com.mindprod.htmlmacros.Replacer; import com.mindprod.htmlmacros.support.Tools; import com.mindprod.hunkio.HunkIO; import com.mindprod.isbn.ISBNValidate; import java.io.File; import java.io.IOException; import static java.lang.System.*; /** * Implements Insert macro. *

* Like include, but includes only some of the text in the referenced file. * It picks out only the first macro invocation of the named type * * @author Roedy Green, Canadian Mind Products * @version 1.0 2012-02-12 initial version * @since 2012-02-12 */ public final class Insert extends Macro { /** * how to use the macro */ private static final String USAGE = "\nInsert macro needs partno, [title] [price] [published=yyyy-mm-dd]"; /** * guts of Insert expansion, also used by JGlossHead to insert caveat files. * Must set up files first. * * @param product product number e.g. 13-digit ISBN 12-digit DVD upc or 10-char ASIN * @param dir where the file to insert is, webroot relative. * @param quiet true if should display status * @param verbose true if want progress log. * * @return inserted HTML. */ String insertFile( final String product, final String dir, final String pickMacro, final boolean quiet, final boolean verbose ) { File fileToInsert = Tools.toFileFromUPath( dir + "/" + product + ".html" ); // we do not process title, price or published try { // we are not worrying about \r \n here. It will be handled later in Replacer. final String textToInsert = HunkIO.readEntireFile( fileToInsert ); final String marker = "", start + marker.length() ); if ( end < 0 ) { throw new IllegalArgumentException( "missing --> in " + fileToInsert ); } end += " -->".length(); //