/*****************************************
* Hlib.java
* From http://home.att.net/~gobruen
*
* 	Called by the HTMLGen.java
*	takes the JText input from the main program
*	and generates HTML content and returns it
*	to the main where is it made into a file
*
******************************************/


public class Hlib
{
	public static String makePage(String title, String meta, 
		String bgcolor, String textcolor, String textfont,
		String genLink, String genLinkN, String img,
		String paragArr[]){


/********************************************************
*	Tag Library 
*		each String tag is decribe in the
*		comment next to it
*
********************************************************/
	String fileContent;			//The end product file
	String HHTMLtagOp ="<HTML>";		//start the html page
	String HheadTit1 = "<HEAD><TITLE>";	//head and title open tags
	String HheadTit2 = "</TITLE></HEAD>";	//close head and open
	String HbodytagOp = "<BODY BGCOLOR=";	//open body tag
	String HbodyTextC = " TEXT=";		//body text color
	String Hclosetag = ">";			//generic tag close
	String Hopentag = "<";			//generic tag open
	String HmetaOp = "<META NAME=";		//meta tag open
	String HfontOp = "<FONT FACE=";		//font tag open
	String HfontCl = "</FONT>";		//font tag open
	String HbodytagCl = "</BODY>";		//close body tag
	String HHTMLtagCl = "</HTML>";		//end html file
	String HAHREFOp = "<A HREF=\"";		//link open tag
	String HAHREFCL = "\">";		//close tag with double quote
	String HAHREFCtag = "</A>";		//close link
	String HBR = "<BR>";			//line break
	String H2o = "<H2>";			//page heading
	String H2c = "</H2>";			//close page heading

/*************************
*
* Secton creates content
*
*************************/

	if(bgcolor.equals("")){
		bgcolor="WHITE";
	}

	if(textcolor.equals("")){
		textcolor="BLACK";
	}



	fileContent = HHTMLtagOp + HheadTit1 + title+ HheadTit2 + 
		HbodytagOp + bgcolor + 
		HbodyTextC + textcolor + Hclosetag +
		HmetaOp + meta + Hclosetag +
		HfontOp + textfont + Hclosetag +
		H2o + title + H2c +
		retImage(img) +
		getAllParags(paragArr) + HBR +
		makeAlink(genLink, genLinkN) + HfontCl + 
		HbodytagCl + HHTMLtagCl;


	return fileContent;
	}//end makePage()


	

	public static String retImage(String img){
		String HimgOp = "<IMG SRC=";		//image tag open
		String HimgCl = "</IMG>";		//image tag close
		String Hclosetag = ">";			//generic tag close

		if(!img.equals("")){
		img = HimgOp + "images/" + img + Hclosetag + HimgCl;
		}

		return img;
	}

/*****************************
*
* Breaks up the paragraphs
* and puts them in <P> tags
*
******************************/



	public static String getAllParags(String paragArr[]){
		String pContent = "";
		String Po = "<P>";
		String Pc = "</P>";

		/*
		*	Go through paragraph array and make
		*	individual sections for paragraphs
		*	that were entered
		*/
	
		for(int i =0; i < paragArr.length; i++){
			if(paragArr[i]!=null){
			pContent = pContent + Po + paragArr[i] + Pc + "\n";
			}
		}
		return pContent;
	}//end getAllParags

/***************************************************
*
* Generates links
*	Combine the tags, link and link
*	name into one string and return it
***************************************************/


	public static String makeAlink(String aLink, String aName){	
		return "<A HREF=\""+aLink+"\">"+aName+"</A>";
	}//end makeAlink


}//end Hlib.java
