FileDocCategorySizeDatePackage
PermittedTaglibsTLV.javaAPI DocGlassfish v2 API7123Sat May 05 19:17:14 BST 2007javax.servlet.jsp.jstl.tlv

PermittedTaglibsTLV

public class PermittedTaglibsTLV extends javax.servlet.jsp.tagext.TagLibraryValidator

A TagLibraryValidator class to allow a TLD to restrict what taglibs (in addition to itself) may be imported on a page where it's used.

This TLV supports the following initialization parameter:

  • permittedTaglibs: A whitespace-separated list of URIs corresponding to tag libraries permitted to be imported on the page in addition to the tag library that references PermittedTaglibsTLV (which is allowed implicitly).
author
Shawn Bayern

Fields Summary
private final String
PERMITTED_TAGLIBS_PARAM
private final String
JSP_ROOT_URI
private final String
JSP_ROOT_NAME
private final String
JSP_ROOT_QN
private Set
permittedTaglibs
private boolean
failed
private String
uri
Constructors Summary
public PermittedTaglibsTLV()

				// our taglib's URI

    //*********************************************************************
    // Constructor and lifecycle management

      
	super();
	init();
    
Methods Summary
private voidinit()

	permittedTaglibs = null;
        failed = false;
    
private java.util.SetreadConfiguration()
Returns Set of permitted taglibs, based on configuration data.


	// initialize the Set
	Set s = new HashSet();

	// get the space-separated list of taglibs
	String uris = (String) getInitParameters().get(PERMITTED_TAGLIBS_PARAM);

        // separate the list into individual uris and store them
        StringTokenizer st = new StringTokenizer(uris);
        while (st.hasMoreTokens())
	    s.add(st.nextToken());

	// return the new Set
	return s;

    
public voidrelease()

	super.release();
	init();
    
public synchronized javax.servlet.jsp.tagext.ValidationMessage[]validate(java.lang.String prefix, java.lang.String uri, javax.servlet.jsp.tagext.PageData page)

	try {

	    // initialize
	    this.uri = uri;
	    permittedTaglibs = readConfiguration();

	    // get a handler
	    DefaultHandler h = new PermittedTaglibsHandler();

	    // parse the page
	    SAXParserFactory f = SAXParserFactory.newInstance();
	    f.setValidating(true);
	    SAXParser p = f.newSAXParser();
	    p.parse(page.getInputStream(), h);

	    if (failed)
		return vmFromString(
		    "taglib " + prefix + " (" + uri + ") allows only the "
		    + "following taglibs to be imported: " + permittedTaglibs);
	    else
		return null;

	} catch (SAXException ex) {
	    return vmFromString(ex.toString());
	} catch (ParserConfigurationException ex) {
	    return vmFromString(ex.toString());
	} catch (IOException ex) {
	    return vmFromString(ex.toString());
	}
    
private javax.servlet.jsp.tagext.ValidationMessage[]vmFromString(java.lang.String message)

	return new ValidationMessage[] {
	    new ValidationMessage(null, message)
	};