FileDocCategorySizeDatePackage
HttpMessages.javaAPI DocGlassfish v2 API4554Fri May 04 22:33:14 BST 2007org.apache.tomcat.util.http

HttpMessages

public class HttpMessages extends Object
Handle (internationalized) HTTP messages.
author
James Duncan Davidson [duncan@eng.sun.com]
author
James Todd [gonzo@eng.sun.com]
author
Jason Hunter [jch@eng.sun.com]
author
Harish Prabandham
author
costin@eng.sun.com

Fields Summary
protected static final org.apache.tomcat.util.res.StringManager
sm
static String
st_200
static String
st_302
static String
st_400
static String
st_404
Constructors Summary
Methods Summary
public static java.lang.Stringfilter(java.lang.String message)
Filter the specified message string for characters that are sensitive in HTML. This avoids potential attacks caused by including JavaScript codes in the request URL that is often reported in error messages.

param
message The message string to be filtered


	if (message == null)
	    return (null);

	char content[] = new char[message.length()];
	message.getChars(0, message.length(), content, 0);
	StringBuffer result = new StringBuffer(content.length + 50);
	for (int i = 0; i < content.length; i++) {
	    switch (content[i]) {
	    case '<":
		result.append("<");
		break;
	    case '>":
		result.append(">");
		break;
	    case '&":
		result.append("&");
		break;
	    case '"":
		result.append(""");
		break;
	    default:
		result.append(content[i]);
	    }
	}
	return (result.toString());
    
public static java.lang.StringgetMessage(int status)
Get the status string associated with a status code. No I18N - return the messages defined in the HTTP spec. ( the user isn't supposed to see them, this is the last thing to translate) Common messages are cached.

    
                                                    
           
	// method from Response.
	
	// Does HTTP requires/allow international messages or
	// are pre-defined? The user doesn't see them most of the time
	switch( status ) {
	case 200:
	    if( st_200==null ) st_200=sm.getString( "sc.200");
	    return st_200;
	case 302:
	    if( st_302==null ) st_302=sm.getString( "sc.302");
	    return st_302;
	case 400:
	    if( st_400==null ) st_400=sm.getString( "sc.400");
	    return st_400;
	case 404:
	    if( st_404==null ) st_404=sm.getString( "sc.404");
	    return st_404;
	}
	return sm.getString("sc."+ status);