/* * Copyright (c) 2009 The Jackson Laboratory * * This software was developed by Gary Churchill's Lab at The Jackson * Laboratory (see http://research.jax.org/faculty/churchill). * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software. If not, see <http://www.gnu.org/licenses/>. */ package org.jax.r.project; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.net.InetAddress; import java.util.Date; import java.util.logging.Logger; import org.jax.r.jaxbgenerated.RHistoryItemType; import org.jax.util.ConfigurationUtilities; /** * Class for exporting a bunch of R commands to a script * @author <A HREF="mailto:keith.sheppard@jax.org">Keith Sheppard</A> */ public class RCommandExporter { /** * our logger */ private static final Logger LOG = Logger.getLogger( RCommandExporter.class.getName()); /** * Export the given command history to the given output stream * @param project * the project to export * @param outputStream * the output stream to export the history to * @throws IOException * if we fail to write the command history */ public void exportCommandHistoryToStream( RProject project, OutputStream outputStream) throws IOException { PrintStream ps = new PrintStream(outputStream); ConfigurationUtilities configurationUtilities = new ConfigurationUtilities(); ps.println( "# Generated by: " + configurationUtilities.getApplicationName() + " " + configurationUtilities.getApplicationVersion()); ps.println( "# Project name: " + project.getName()); ps.println( "# Creation Time: " + new Date().toString()); ps.println( "# Host Name: " + InetAddress.getLocalHost().getHostName()); for(RHistoryItemType currRHistoryItem: project.getRHistory()) { switch(currRHistoryItem.getItemType()) { case COMMAND: { ps.println(currRHistoryItem.getContent()); } break; case COMMENT: { ps.print(currRHistoryItem.getContent()); } break; case R_OUTPUT: { // don't care } break; default: { LOG.warning( "ignoring unknown R history type:" + currRHistoryItem); } break; } } ps.close(); } }