JSP Tag RunTime Problem
jfraser Nov 11, 2003 4:59 PMI have a tag that will not work on windows XP at runtime. I am using jboss-3.2.2. Please don't ask me about the calling JSP, the tld, or the web.xml file. I have been all through that. Besides If they were not right how could it compile? What is wrong with my code. Help me anybody.
package org.apache.jsp;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.util.*;
/**
*
* @version 1.0, 05/02/00
* @author Joe Fraser
* Copyright:
* Copyright (c) 2000 Marketing.Comm. All Rights Reserved.
* File Name:
* ReportServlet.java
* Purpose:
* This Servlet is an example that gets a connection from a SQL Server pool, and
* then queries a table which is written to output as html. The Servlet reads initalization parameters from
* the file servlet.properties. The connection pool reads the file db.properties.
* Output:
* The output is an html page.
* Note:
* This servlet was tested with servletrunner using the -s and -d options.
* History:
* 1.0, 05/02/00 - Joe Fraser
*
*/
public class AppletPluginTag
extends BodyTagSupport
{
private PageContext jspPageContext;
private String name;
private String width;
private String height;
private String code;
private String codeBase;
private String archive;
private String [] searchList = {"\"CODE\"", "\"CODEBASE\"", "\"ARCHIVE\""};
public AppletPluginTag()
{
init();
}
protected void init()
{
name = null;
width = null;
height = null;
code = null;
codeBase = null;
archive = null;
jspPageContext = null;
}
public void setPageContext(PageContext aPageContext)
{
jspPageContext = aPageContext;
return;
}
// this next three set methods are automatically called during
// the tag processing because they are attributes of the tag
public void setName(String aName)
{
name = aName;
}
public void setWidth(String aWidth)
{
width = aWidth;
}
public void setHeight(String aHeight)
{
height = aHeight;
}
public String getName()
{
return(name);
}
public String getWidth()
{
return(width);
}
public String getHeight()
{
return(height);
}
protected void finishTopOfObjectTag(StringBuffer outBuffer)
{
outBuffer.append(width);
outBuffer.append(" HEIGHT = ");
outBuffer.append(height);
outBuffer.append(" NAME = \"");
outBuffer.append(name);
outBuffer.append("\"\n\t"); // end line one
outBuffer.append("codebase=\"http://java.sun.com/products/plugin/autodl/jinstall-1_4_0-win.cab#Version=1,4,0,0\">");
outBuffer.append("\n"); // end line two
}
protected void finishRestOfObjectTag(StringBuffer outBuffer)
{
outBuffer.append("\n"); // end line
outBuffer.append("<PARAM NAME=\"scriptable\" VALUE=\"true\">");
outBuffer.append("\n"); // end line
outBuffer.append("");
outBuffer.append("\n"); // end line
outBuffer.append ("<EMBED type=\"application/x-java-applet;jpi-version=1.4\" CODE = ");
outBuffer.append(code);
outBuffer.append(" CODEBASE = ");
outBuffer.append(codeBase);
outBuffer.append(" ARCHIVE = ");
outBuffer.append(archive);
outBuffer.append(" NAME = \"");
outBuffer.append(name);
outBuffer.append("\"\n"); // end line
outBuffer.append("WIDTH = ");
outBuffer.append(width);
outBuffer.append(" HEIGHT = ");
outBuffer.append(height);
outBuffer.append(" scriptable=true");
outBuffer.append("\n"); // end line
outBuffer.append("pluginspage=\"http://java.sun.com/products/plugin/index.html#download\">");
outBuffer.append("\n");
outBuffer.append("");
outBuffer.append("\n");
outBuffer.append("NO JDK 1.4 support for Applet!!");
outBuffer.append("\n");
outBuffer.append("");
outBuffer.append("\n");
outBuffer.append("");
outBuffer.append("\n");
outBuffer.append("");
outBuffer.append("\n");
outBuffer.append("");
outBuffer.append("\n");
}
public int doStartTag()
throws JspException
{
// pageContext is a given object set before this method
StringBuffer outBuf;
outBuf = new StringBuffer("<OBJECT classid=\"clsid:CAFEEFAC-0014-0000-0000-ABCDEFFEDCBA\" WIDTH = ");
finishTopOfObjectTag(outBuf);
try {
JspWriter writer = jspPageContext.getOut();
writer.print(outBuf.toString());
// writer.print("out doStartTag()");
}
catch (IOException e)
{
throw new JspException(e.getMessage() + ": error in doStartTag()");
}
return(EVAL_BODY_BUFFERED);
}
public int doAfterBody() // After the body is already written
throws JspException
{
String tag = null;
ArrayList bodyTagList = new ArrayList();
// bodyContent is a given object
String bodyText = bodyContent.getString();
// start parsing the text
StringTokenizer bodyTokens = new StringTokenizer(bodyText, "\n");
while(bodyTokens.hasMoreTokens())
{
bodyTagList.add(bodyTokens.nextToken());
}
// now that I have an array of PARAM Tags find the CODE, CODEBASE, and ARCHIVE
for (int i = 0; i < bodyTagList.size(); i++)
{
tag = (String)bodyTagList.get(i);
if (tag.trim().length() > 0)
{
// find NAME=
int beforeNameIndex = tag.indexOf("NAME=", 0);
int beforeValueIndex = tag.indexOf("VALUE=", beforeNameIndex + 5);
String nameIs = tag.substring(beforeNameIndex + 5, beforeValueIndex);
// find VALUE
int beforeTagEnd = tag.indexOf(">", beforeValueIndex + 6);
String valueIs = tag.substring(beforeValueIndex + 6, beforeTagEnd);
boolean found = false;
int subscript = -1;
for (int j = 0; j < searchList.length; j++)
{
if (nameIs.equalsIgnoreCase(searchList))
{
found = true;
subscript = j;
break;
}
}
if (found)
{
if (subscript == 0)
code = new String(valueIs);
else if (subscript == 1)
codeBase = new String(valueIs);
else if (subscript == 2)
archive = new String(valueIs);
}
}
}
return (SKIP_BODY); // single iteration return
}
public int doEndTag()
throws JspException
{
// pageContext is a given object
StringBuffer outBuf = null;
JspWriter writer = jspPageContext.getOut();
outBuf = new StringBuffer("<PARAM NAME=\"TYPE\" VALUE=\"application/x-java-applet;jpi-version=1.4\">");
finishRestOfObjectTag(outBuf);
try {
writer.print(outBuf.toString());
}
catch (IOException e)
{
throw new JspException(e.getMessage() + ": error in doEndTag()");
}
return(EVAL_PAGE);
}
public void release()
{
super.release();
init();
}
}