tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pier...@locus.apache.org
Subject cvs commit: jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler JspUtil.java
Date Wed, 27 Sep 2000 17:14:19 GMT
pierred     00/09/27 10:14:19

  Modified:    jasper/src/share/org/apache/jasper/compiler JspUtil.java
  Log:
  new method: escapeXml()
  
  Revision  Changes    Path
  1.2       +28 -4     jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspUtil.java
  
  Index: JspUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspUtil.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JspUtil.java	2000/08/12 00:52:08	1.1
  +++ JspUtil.java	2000/09/27 17:14:19	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspUtil.java,v
1.1 2000/08/12 00:52:08 pierred Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/12 00:52:08 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspUtil.java,v
1.2 2000/09/27 17:14:19 pierred Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/09/27 17:14:19 $
    *
    * ====================================================================
    * 
  @@ -264,7 +264,31 @@
   	return escString;
       }
       
  -
  +    /**
  +     *  Escape the 5 entities defined by XML.
  +     */
  +    public static String escapeXml(String s) {
  +        if (s == null) return null;
  +        StringBuffer sb = new StringBuffer();
  +        for(int i=0; i<s.length(); i++) {
  +            char c = s.charAt(i);
  +            if (c == '<') {
  +                sb.append("&lt;");
  +            } else if (c == '>') {
  +                sb.append("&gt;");
  +            } else if (c == '\'') {
  +                sb.append("&apos;");
  +            } else if (c == '&') {
  +                sb.append("&amp;");
  +            } else if (c == '"') {
  +                sb.append("&quote;");
  +            } else {
  +                sb.append(c);
  +            }
  +        }
  +        return sb.toString();
  +    }
  +    
       public static class ValidAttribute {
      	String name;
   	boolean mandatory;
  
  
  

Mime
View raw message