/*
 * Created on 2004-3-14
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package workflow.script.interpretor;
import java.io.IOException;
import java.io.PrintWriter;
/**
 * @author zosatapo
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class ScriptWriter
{ 
	// The sink writer:
	PrintWriter writer;
  
	// script line numbers start from 1
	private int javaLine = 1;
  
	public ScriptWriter(PrintWriter writer)
	{
		this.writer = writer;
	}
	public void close() throws IOException
	{
		writer.close();
	}
	// -------------------- Access informations --------------------
	public int getJavaLine()
	{
		return javaLine;
	}
	// -------------------- Formatting --------------------
	/**
	 * Prints the given string followed by '\n'
	 */
	public void println(String s)
	{
		javaLine++;
		writer.println(s);
	}
	
	/**
	 * Prints a '\n'
	 */
	public void println()
	{
		javaLine++;
		writer.println("");
	}
  
	/**
	 * Prints the given char.
	 *
	 * Use println() to print a '\n'.
	 */
	public void print(char c)
	{
		writer.print(c);
	}
	/**
	 * Prints the given int.
	 */
	public void print(int i)
	{
		writer.print(i);
	}
	/**
	 * Prints the given string.
	 *
	 * The string must not contain any '\n', otherwise the line count will be
	 * off.
	 */
	public void print(String s)
	{
		writer.print(s);
	}
	
	/**
	 * Prints the given string.
	 *
	 * If the string spans multiple lines, the line count will be adjusted
	 * accordingly.
	 */
	public void printMultiLn(String s)
	{
		int index = 0;
		// look for hidden newlines inside strings
		while ((index = s.indexOf('\n', index)) > -1)
		{
			javaLine++;
			index++;
		}
		writer.print(s);
	}
}
