com.darwinsys.html
Class SimpleTagValidator

java.lang.Object
  extended by com.darwinsys.html.SimpleTagValidator

public class SimpleTagValidator
extends java.lang.Object

Check a String to ensure that it contains either no HTML tags, or only the HTML tags listed in OKTAGS (or the corresponding end-tags). It is not intended as a full-function HTML validator! Nor is any claim advanced that this is a complete solution to preventing Cross-Site Scripting. It is just, well, a SIMPLE Tag Validator.

Version:
$Id: SimpleTagValidator.java,v 1.5 2006/04/06 22:32:57 ian Exp $

Constructor Summary
SimpleTagValidator()
          Construct a Validator using the default OK list
SimpleTagValidator(java.lang.String[] okTagList)
          Construct a Validator using a non-default OK list
 
Method Summary
 java.lang.String getFailedTag()
          Return the last tag that failed.
 java.lang.String getTagsAsString(boolean useCommas)
          Return the list of valid tags as a single string.
 boolean validate(java.lang.String s)
          Validate a String that may contain HTML to ensure it contains only the tags listed in the OK list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleTagValidator

public SimpleTagValidator()
Construct a Validator using the default OK list


SimpleTagValidator

public SimpleTagValidator(java.lang.String[] okTagList)
Construct a Validator using a non-default OK list

Method Detail

validate

public boolean validate(java.lang.String s)
Validate a String that may contain HTML to ensure it contains only the tags listed in the OK list.

Parameters:
s - The HTML String to validate.
Returns:
true iff s does not contain any non-OK strings.

getFailedTag

public java.lang.String getFailedTag()
Return the last tag that failed. Usage example: System.out.printf("Invalid tag %s\n", val.getFailedTag());

Returns:
The name of the tag that caused validate() to fail.

getTagsAsString

public java.lang.String getTagsAsString(boolean useCommas)
Return the list of valid tags as a single string. Usage example: System.out.printf("Valid tags are %01s\n", val.tagsAsString());

Parameters:
useCommas - True to include commas ("a, b, c"); false just space ("a b c").


Copyright © 1996-2004 Ian F. Darwin. See license.html for usage license.