<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.io.*;
import java.util.*;

/**
 * A missive in an instant messaging system
 *
 * Unlike a normal Chirp, an ExpandedChirp does not
 * contain abbreviations -- they are all expanded
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class ExpandedChirp extends Chirp
{
    private Properties      abbreviations;


    /**
     * Explicit Value Constructor
     *
     * @param typed   What was typed by the user
     */
    public ExpandedChirp(String typed)
    {
	super(typed);
	InputStream      is;

	abbreviations = new Properties();
	try
        {
	    is = new FileInputStream("abbreviations.txt");
	    abbreviations.load(is);
	}
        catch (IOException ioe)
        {
	    // There was a problem opening the file
	    // containing the abbreviations
	}
    }

    /**
     * Get the text of this Chirp with all of the
     * abbreviations expanded
     *
     * This method overrides the version in the parent
     *
     * @return   The text
     */
    public String getText()
    {
	String       tempText;

	// Use getText() in the parent
	tempText  = replaceAbbreviations(super.getText());

	return tempText;
    }

    /**
     * Replace the abbreviations in a message
     *
     * @param msg   The original message
     */
    private String replaceAbbreviations(String msg)
    {
	String              replaced, token, word;
	StringTokenizer     tokenizer;

	replaced = "";
	
	tokenizer = new StringTokenizer(msg, getDelimiters(), true);
	while (tokenizer.hasMoreTokens())
        {
	    token = tokenizer.nextToken();
	    word  = abbreviations.getProperty(token);

	    if (word == null) replaced += token;
	    else              replaced += word;
	}

	return replaced;
    }
}
</pre></body></html>