package componentlibrary; import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; import java.util.TreeMap; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.Velocity; import org.apache.velocity.exception.MethodInvocationException; import org.apache.velocity.exception.ParseErrorException; import org.apache.velocity.exception.ResourceNotFoundException; public class HTMLComponentDocumentation { private static final String TEMPLATE_FILE="template/components.vm"; // private static final String HTML_FILE="template/components.html"; private static final String HTML_FILE="C:/Users/mkoenig/Desktop/CellML/models/MetabolicLibraryCellML/components.html"; /* Render the template with the given components */ private static void render(TreeMap cMap) throws IOException{ System.out.println("*** START TEMPLATE RENDERING ***"); Velocity.init(); // Generate the Context for the Template // put the components in the context VelocityContext context = new VelocityContext(); //context.put( "name", new String("Velocity") ); context.put( "cSet", cMap.values()); // Generate the Template Template template = null; try { template = Velocity.getTemplate(TEMPLATE_FILE); } catch( ResourceNotFoundException rnfe ) { // couldn't find the template System.out.println("Template not found."); } catch( ParseErrorException pee ) { // syntax error: problem parsing the template System.out.println("Template not parsable."); } catch( MethodInvocationException mie ) { // something invoked in the template // threw an exception System.out.println("Template method invocation error."); } catch( Exception e ) {} // Render the Template FileWriter fw = new FileWriter(HTML_FILE); StringWriter sw = new StringWriter(); template.merge( context, sw ); fw.write(sw.toString()); fw.close(); System.out.println("HTML --> " + HTML_FILE); System.out.println("*** END TEMPLATE RENDERING ***"); } public static void main(final String[] args) throws Exception{ TreeMap cMap = RComponentImporter.readComponentsFromCSV(); TreeMap rccMap = RCellMLComponent.generateRCellMLComponents(cMap); HTMLComponentDocumentation.render(rccMap); } }