package com.mindprod.htmlmacros;
import java.io.IOException;
/**
* Expands HTML boilerplate refresher macros
* that simply include from another file e.g.
* <!-- macro Include dogs.txt -->
* <!-- generated by macro Include -->
* <img src="images/animals/dog.jpg" height="410" width="511" alt="dog">
* <!-- /generated by macro Include -->
* It is not this classes's duty to create the generated and /generated
* comment tags, just the material between them.
*/
public class Include implements Macro
{
/**
* Generate macro expansion for Include macro
*
* @param parms parsed params for the macro,
* usually alternating field name and value,
* in this case just "filename".
* @return expanded text
*/
public String expand ( String[] parms )
{
if ( parms.length != 1 )
{
throw new IllegalArgumentException ( "macrosyntaxerror:try<!--macroIncludefile.txt-->" );
}
String fromFile = parms[0];
try
{
return HunkIO.readEntireFile ( fromFile ) ;
}
catch ( IOException e )
{
return "error:unabletofindfile" + fromFile + "toinclude.";
}
}
}