alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/PluginGenerator.java,v 1.13 2004/02/23 06:22:36 billbarker Exp $
 * $Revision: 1.13 $
 * $Date: 2004/02/23 06:22:36 $
 *
 *
 *  Copyright 1999-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.jasper.compiler;

import java.util.Hashtable;
import java.util.Enumeration;

import org.apache.jasper.JasperException;
import org.apache.jasper.Constants;
import org.apache.jasper.JspCompilationContext;

/**
 * Generator for 
 *
 * @author Rajiv Mordani [mode@eng.sun.com]
 */
public class PluginGenerator 
    extends GeneratorBase
    implements ServiceMethodPhase 
{
    Hashtable attrs;
    Hashtable param;
    String fallback;

    String ieClassId;
    Mark start;
    
    
    public PluginGenerator(Mark start, Hashtable attrs, Hashtable param,
			   String fallback) {
    	this.attrs = attrs;
	this.param = param;
	this.fallback = fallback;
	this.start = start;
    }

    public void init(JspCompilationContext ctxt) throws JasperException {
        ieClassId = ctxt.getOptions().getIeClassId();
    }
    
    public void generate(ServletWriter writer, Class phase) 
    				throws JasperException
    {

	String type = getAttribute ("type");
	String code = getAttribute ("code");
	String codebase = getAttribute ("codebase");
	String archive = getAttribute ("archive");
	String jreversion = getAttribute ("jreversion");
	String name = getAttribute ("name");
	String nspluginurl = getAttribute ("nspluginurl");
	String iepluginurl = getAttribute ("iepluginurl");

	if (type == null)
	    throw new CompileException (start, Constants.getString (
	    				"jsp.error.plugin.notype"));
	if (code == null)
	    throw new CompileException (start, Constants.getString (
	    				"jsp.error.plugin.nocode"));

	writer.popIndent ();
	writer.println ("/*Code generated for plugin*/");
	writer.println("{");	// Work around multi-plugin-tag bug
	writer.indent ();
	writer.print ("out.println (\"\");");
	// Done to avoid spaces being generated between the closing angular
	// bracket of the tag.
	writer.println ();
	writer.indent ();
	writer.print ("out.println (\"\");");
	writer.println ();

	if (codebase != null) {
	    writer.indent ();
	    writer.print ("out.println (\"\");");
	    writer.println ();
	}

	if (archive != null) {
	    writer.indent ();
	    writer.print ("out.println (\"\");");
	    writer.println ();
	}

	writer.indent ();
	writer.print ("out.println (\"\");");
	writer.println ();

	// Evaluate params and if expression get the appropriate code for
	// the expression

	Enumeration e = null;
	String value [] = null;
	String key = null;

	writer.indent ();
	writer.print ("String _jspxString = null;");
	writer.println ();

	if (param != null) {
	    e = param.keys ();
	    while (e.hasMoreElements ()) {
	        key = (String) e.nextElement ();
	        value = (String[]) param.get (key);
		writer.indent ();
	 	//Check to see if the param is an expression, if so
		//evaluate that and put the value.
		String temp = null;
		if (JspUtil.isExpression (value[0])) {
		    temp = JspUtil.getExpr (value[0]);
		    //value[0] = JspUtil.getExpr(value[0]);
		    writer.print ("_jspxString =" + temp + ";");
		} else {
		    writer.print ("_jspxString = \"" + value[0] + "\";");
		}
		writer.println ();
	        writer.indent ();
	        writer.print ("out.println (\"\");");
	        writer.println ();
	    }
	}

	writer.indent ();
	writer.print ("String [][] _jspxNSString = null;"); 
	writer.println ();
	writer.indent ();
	writer.print ("int i = 0;");
	writer.println ();
	if (param != null) {
	    e = param.keys ();
	    writer.indent ();
	    writer.indent ();
	    writer.print ("_jspxNSString = new String [");
	    Integer temp = new Integer (param.size ());
	    writer.print (temp.toString ());
	    writer.print ("][2];");
	    writer.println ();
	    writer.indent ();
	    key = null;
	    value = null;
	    while (e.hasMoreElements ()) {
	        key = (String) e.nextElement ();
	        value = (String[]) param.get (key);
	        writer.print ("_jspxNSString [i][0] = \"");
		if (key.equalsIgnoreCase ("object"))
		    key = "java_object";
		else if (key.equalsIgnoreCase ("type"))
		    key = "java_type";
		writer.print (key);
		writer.print ("\";");
		writer.println ();
		writer.indent ();

	        //value = (String[]) param.get (key);
		if (JspUtil.isExpression (value[0])) {
		    value[0] = JspUtil.getExpr(value[0]);
		    writer.print ("_jspxNSString[i][1] =" + value[0] + ";");
		} else {
		    writer.print ("_jspxNSString[i][1] = \"" + value[0] + 
		    			"\";");
		}
		writer.println ();
		writer.indent ();
		writer.print ("i++;");
		writer.println ();
	    }
	}
	
	writer.println ("out.println (\"\");");
	writer.indent ();
	writer.print ("out.print (\"\");");
	writer.println ("out.println (\"\");");
	writer.println ("out.println (\"</COMMENT>\");");

	if (fallback != null) {
	    fallback = writer.quoteString (fallback);
	    writer.indent ();
	    writer.print ("out.println (");
	    writer.print (fallback);
	    writer.print (");");
	    writer.println ();
	}
	writer.println ("out.println (\"\");");
	writer.println ("out.println (\"\");");
	writer.pushIndent ();
	writer.println("}");	// Work around multi-plugin-tag bug
    }

    public void generateCommon (ServletWriter writer) {
	String align = getAttribute ("align");
	String width = getAttribute ("width");
	String height = getAttribute ("height");
	String hspace = getAttribute ("hspace");
	String vspace = getAttribute ("vspace");

	if (width != null) {
	    writer.print (" width=\\\"");
	    writer.print (width);
	    writer.print ("\\\" ");
	}

	if (height != null) {
	    writer.print (" height=\\\"");
	    writer.print (height);
	    writer.print ("\\\" ");
	}

	if (hspace != null) {
	    writer.print (" hspace=\\\"");
	    writer.print (hspace);
	    writer.print ("\\\" ");
	}

	if (vspace != null) {
	    writer.print (" vspace=\\\"");
	    writer.print (vspace);
	    writer.print ("\\\" ");
	}

	if (align != null) {
	    writer.print (" align=\\\"");
	    writer.print (align);
	    writer.print ("\\\" ");
	}

    }

    public String getAttribute(String name) {
	return (attrs != null) ? (String) attrs.get(name) : null;
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.