/*=============================================================*/ /* gtPage.java */ /*=============================================================*/ /** *
 *
 *   P1.java -- An HTML stripper and object serialization
 *               program for CS4812, fall 1998
 *
 *             This program is designed to teach basics of
 *               Java file IO, streams, networking, and
 *               simple console-based programming
 *
 *   Revisions:  0.1 Sept. 12, 1988
 *               Created class P1.java
 *
 *               0.2 Sept. 13, 1998
 *               Added toString(), overrode java.Object 
 *               equals() method
 *   
 *               0.3 Sept. 28, 1998
 *               Added Javadoc comments
 *               Tweaked error-checking
 *
 *  
* * @author David Dagon * @version Version 0.3, Sept. 28, 1998 * */ public class gtPage implements java.io.Serializable { /*=============================================================*/ /* Instance Variables */ /*=============================================================*/ private static String strDEFAULT_TEXT="No text loaded"; private static String strWARNING = strDEFAULT_TEXT; public static boolean DEBUG = false; private String[] line = null; private int iColumns = -1; private String strHTML = null; private String strText = null; /*=============================================================*/ /* Constructors */ /*=============================================================*/ /** *
    *
    *  Default constructor
    *
    *  Precondition: An instance of gtPage has been declared,
    *    and the default constructor is called.
    *
    *  Postcondition:  An instance of gtPage is created, by
    *    chaining constructors
    *
    *  @see gtPage(String, boolean)
    *
    *  
*/ public gtPage() { this(strDEFAULT_TEXT, true); }//default constructor /*=============================================================*/ /** *
   *
   *  Constructor 
   *
   *  Precondition: An instance of gtPage has been declared,
   *    and this constructor is called.
   *
   *  Postcondition: The call is chained, setting the DEBUG
   *    flag to false
   *
   * @param String strHTML -- the String holding the HTML
   *    wrapped by this class.
   *
   * @see gtPage(String, boolean)
   * 
   *
   * 
*/ public gtPage(String strHTML) { this (strHTML, false); }//constructor /*=============================================================*/ /** *
   *
   *  Constructor
   * 
   *  Precondition: An instance of gtPage has been declared,
   *    and this constructor is called.
   *
   *  Postcondition: The instance of this class is created,
   *    and the debug flag is set.
   *
   * @param String strHTML -- the String holding the HTML
   *    wrapped by this class.
   *
   * @param boolean DEBUG -- a debugging flag.
   *
   * @see setHTML() -- called to set the instance value of
   *    the String strHTML.
   *
   * @see setDEBUG() -- called to set the instance value of
   *    the boolean DEBUG.
   *
   * 
*/ public gtPage (String strHTML, boolean DEBUG) { setHTML(strHTML); setDEBUG(DEBUG); if (DEBUG) System.out.println ("Completed gtPage constructor\n" + "\tHTML = " + strHTML + "\n"); }// constructor /*=============================================================*/ /* Accessors */ /*=============================================================*/ /** *
   *
   *  getHTML() -- return the String wrapped by this class
   *
   *  Precondition: The instance variable strHTML has been
   *    set
   *
   *  Postcondition: The String strHTML is returned.
   *
   *  @return String strHTML -- the String containing the HTML
   *
   *  
*/ public String getHTML() { return strHTML; }//getHTML /*=============================================================*/ /** *
   *
   *  getText() -- return the text String wrapped by this class
   *
   *  Precondition: The instance variable strText has been
   *    set
   *
   *  Postcondition: The String strText is returned.
   *
   *  @return String strHTML -- the String containing the text
   *
   * 
* */ public String getText() { return strText; }//getText /*=============================================================*/ /** *
   *
   *  getLineCount() -- return the number of formatted lines
   *   
   *  Precondition: The text has been formatted, and the parsed
   *     lines have been saved into the String array, line.
   *
   *  Postcondition: The number of lines is returned, or -1
   *     if the String array is null.
   *
   *  @return int -- the number of lines
   *
   *  
*/ public int getLineCount() { return ((line==null)?-1:line.length); }//getLineCount /*=============================================================*/ /** *
   *
   *  getLineCount() -- return the number of columns
   *   
   *  Precondition: The number of columns has been set
   *
   *  Postcondition: The number of lines is returned
   *
   *  @return int iColumns -- the number of columns
   *
   *  
*/ public int getColumns() { if (DEBUG) System.out.println ( (iColumns==-1) ? "WARNING: Columns == -1" : "Accessing columns (" + iColumns + ")."); return iColumns; }//getColumns /*=============================================================*/ /** *
   *
   *  getLine() -- return an individual line
   *
   *  Precondition: The String[] line object has been created and
   *     set, and an individual line is needed.
   *
   *  Postcondition: An individual line is returned.
   *
   *  @param int i -- the line number to be returned.
   *
   *  @return String -- the String from the line array,
   *     at the specified index.
   *
   * 
*/ public String getLine(int i) { if (DEBUG) System.out.println ((line==null) ? "WARNING: " + strWARNING : "Accessing line[" + i + "]: " + line[i]); return ( (line==null) ? strWARNING:line[i]); }//getLine /*=============================================================*/ /** *
   *   
   *   equals -- test the equality of two instance of gtPage
   *
   *   Precondition: A non-null object is passed in
   *
   *   Postcondition: The object is compared to this instance
   *
   *   @param Object o -- the object to be compared against
   *     this instance of gtPage
   *
   *   @return boolean -- whether or not the Object is the same
   *     as this object
   *
   *  
* */ public boolean equals(Object o) { if (o instanceof gtPage && o!=null) { if ( ((gtPage)o).getHTML().equals(getHTML()) && ((gtPage)o).getText().equals(getText())) return true; } return false; }//equals /*=============================================================*/ /** *
   *   
   *  toString() -- return a String representation of the parsed
   *    and formatted text
   *
   *  Precondition: The String[] line object has been created
   *
   *  Postcondition: A String composite of the entire array,
   *     with information about the column count, is
   *     created and returned
   *
   *  @return String -- all of the lines, plus column information
   *
   * 
*/ public String toString() { String ret="gtPage; Columns = " + iColumns; if (line!=null) for (int i=0; i * * setColumns() -- set the number of columns represented by this * instance * * Precondition: An instance of this class has been created, * and a new column number has been specified * * Postcondition: The column count is set * * @param iColumns -- the number of columns * * */ public void setColumns(int iColumns) { this.iColumns = iColumns; }//setColumns /*=============================================================*/ /** *
   *
   *  setHTML() -- set the HTML wrapped by this program
   *
   *  Precondition:  An instance of this class has been created,
   *     and new HTML need to be saved
   *
   *  Postcondition:  The strHTML variable is set
   *
   *  @param strHTML -- the String containing the entire HTML document
   *
   * 
*/ public void setHTML(String strHTML) { this.strHTML = strHTML; }//setHTML /*=============================================================*/ /** *
   *
   *  setLines() -- set the String[] line array.
   *
   *  Precondition:  An instance of this class has been created,
   *     and the parsed text is formatted for columns
   *
   *  Postcondition:  The line variable is set
   *
   *  @param line -- the String[] array of individual lines
   *
   * 
*/ public void setLines(String[] line) { this.line = line; }//setLines /*=============================================================*/ /** *
   *
   *  setText() -- set the parsed text
   *
   *  Precondition:  An instance of this class has been created,
   *     and the HTML has been parsed into plain text
   *
   *  Postcondition:  The text
   *
   *  @param strText -- the String containing the parsed text.
   *
   * 
*/ public void setText(String strText) { this.strText = strText; }//setText /*=============================================================*/ /** *
   *
   *  setDEBUG -- set the DEBUG flag
   *
   *  Precondition: An instance of gtPage has been created,
   *    and a debug flag is specified
   *
   *  Postcondition: The debug flag is set
   *
   *  @param DEBUG -- the boolean debug flag
   *
   * 
*/ public void setDEBUG(boolean DEBUG) { this.DEBUG = DEBUG; }//setDEBUG /*=============================================================*/ }// class gtPage