FileDocCategorySizeDatePackage
Writer.javaAPI DocExample3083Tue Dec 08 01:21:00 GMT 1998oisoft.togetherx.scripts.Rose98Export

Writer.java

//---------------------------------------------------------
// Copyright (c) 1998  Object International Software GmbH
//
// Author: Eugene Belyaev
//---------------------------------------------------------

package oisoft.togetherx.scripts.Rose98Export;

import java.io.*;

/** @author  Eugene Belyaev
 *  @version 2.1.0
 */
public class Writer {
	private PrintWriter stream = null;
	private int indent = 0;

	public Writer( String path )
	{
		try {
			Reporter.Info( "filename: " + path );
		  	stream = new PrintWriter( new FileOutputStream( path ) );
			stream.flush();
			stream.print( "# @Rose98Export.Writer, version 06/18/98\n" );
			stream.print( "# Copyright (c) 1998 by Object International Software\n" );
			stream.print( "# Model generated on " + new java.util.Date() + "\n" );
		}
		catch ( java.io.IOException e )	{
			System.err.println( "Couldn't create PrintWriter for " + path );
		}
	}

	public void out( String outstring )
	{
		if( stream != null ) stream.print( internalTab() + outstring + "\n" );
	}

	public void close()
	{
		if( stream != null ) stream.close();
	}

	public void advance()
	{
		indent++;
	}

	public void retreat()
	{
		indent--;
	}

	public void newline()
	{
		out("");
	}

	public void println( String s )
	{
		stream.print( s + "\n" );
	}

	/**
	 *  !!! needs correction
	 */
	public String makeLongString( String s )
	{
		String res = "\n|";
		if( s != null )	{
			for( int i = 0; i < s.length(); i++ ) {
				if( s.charAt(i) == '\n' ) res += "\n|";
				else res += s.charAt(i);
			}
		}
		return res;
	}

	public String makeString()
	{
		return makeString(null);
	}

	public String makeString( String s )
	{
		if( s != null )	return "\"" + s + "\"";
		return "\"\"";
	}

	public void closeObject()
	{
		out(")");
	}

	public boolean isString( String s )
	{
		if ( s!=null && s.indexOf('\"')>=0 )
			return true;
		//if( s.startsWith("\"") && s.endsWith("\"") ) return true;
		return false;
	}

	public String tab()
	{
		return "\t";
	}

	private String internalTab()
	{
		String s = "";
		for( int i = 0; i < indent; i++ ) {
			s += "\t";
		}
		return s;
	}

	/**
	 * Replaces the '.' with '::' in s
	 * @param s String to convert
	 */
	public String makeRose98StyleQualifiedName( String s )
	{
		String result = "";

		for( int i = 0; i < s.length(); i++ ) {
			if( s.charAt(i) == '.' ) result += "::";
			else result += s.charAt(i);
		}
		return result;
	}

	public String makeBooleanString( boolean b ) {
		if(b) return "TRUE";
		return "FALSE";
	}

	public String makeStateString( String s )
	{
		String result = "";

		for( int i = 0; i < s.length(); i++ ) {
			if( s.charAt(i) == '.' ) result += ":";
			else result += s.charAt(i);
		}
		return result;
	}

	public String replaceQuotationMarks( String s )
	{
		String result = "";

		for( int i = 0; i < s.length(); i++ ) {
			if( s.charAt(i) == '\"' ) result += "'";
			else result += s.charAt(i);
		}
		return result;
	}
}