Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Licensed to the Apache Software Foundation (ASF) under one or more
   *  contributor license agreements.  See the NOTICE file distributed with
   *  this work for additional information regarding copyright ownership.
   *  The ASF licenses this file to You 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.tomcat.util.http;
 
 
Handle (internationalized) HTTP messages.

Author(s):
James Duncan Davidson [duncan@eng.sun.com]
James Todd [gonzo@eng.sun.com]
Jason Hunter [jch@eng.sun.com]
Harish Prabandham
costin@eng.sun.com
 
 public class HttpMessages {
 	
     protected static Properties statusMessages = new Properties();
     
     static {
         try {
             InputStream is = HttpMessages.class.getClassLoader().getResourceAsStream("org/apache/tomcat/util/http/HttpMessages.properties");
             .load(is);
         } catch (Exception e) {
             ..errorLoadingMessages(e);
         }
     }
     
     static String st_200=null;
     static String st_302=null;
     static String st_400=null;
     static String st_404=null;
    
    
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.
 
     public static String getMessageint status ) {
 	// method from Response.
 	
 	// Does HTTP requires/allow international messages or
 	// are pre-defined? The user doesn't see them most of the time
 	switchstatus ) {
 	case 200:
 	    if==null ) =.getProperty"sc.200");
 	    return ;
 	case 302:
 	    if==null ) =.getProperty"sc.302");
 	    return ;
 	case 400:
 	    if==null ) =.getProperty"sc.400");
 	    return ;
 	case 404:
 	    if==null ) =.getProperty"sc.404");
 	    return ;
 	}
 	return .getProperty("sc."status);
     }

    
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.

Parameters:
message The message string to be filtered
 
     public static String filter(String message) {
 
 	if (message == null)
 	    return (null);
 
 	char content[] = new char[message.length()];
 	message.getChars(0, message.length(), content, 0);
 	StringBuilder result = new StringBuilder(content.length + 50);
 	for (int i = 0; i < content.lengthi++) {
 	    switch (content[i]) {
 	    case '<':
		result.append("&lt;");
		break;
	    case '>':
		result.append("&gt;");
		break;
	    case '&':
		result.append("&amp;");
		break;
	    case '"':
		result.append("&quot;");
		break;
	    default:
		result.append(content[i]);
	    }
	}
	return (result.toString());
    }
New to GrepCode? Check out our FAQ X