dgraham 2003/11/28 14:55:36 Modified: src/share/org/apache/struts/taglib/html JavascriptValidatorTag.java Log: Removed getNextVar() and replaceChar() methods and use a simpler javascript identifier naming scheme. All variables with be named a0, a1, etc. to prevent using reserved words as variable names. PR# 24516 Revision Changes Path 1.40 +9 -58 jakarta-struts/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java Index: JavascriptValidatorTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- JavascriptValidatorTag.java 28 Sep 2003 17:02:51 -0000 1.39 +++ JavascriptValidatorTag.java 28 Nov 2003 22:55:36 -0000 1.40 @@ -7,7 +7,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999-2003 The Apache Software Foundation. All rights + * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -423,7 +423,7 @@ for (Iterator i = actions.iterator(); i.hasNext();) { ValidatorAction va = (ValidatorAction) i.next(); - String jscriptVar = null; + int jscriptVar = 0; String functionName = null; if (va.getJsFunctionName() != null @@ -450,11 +450,10 @@ message = (message != null) ? message : ""; - jscriptVar = this.getNextVar(jscriptVar); - + // prefix variable with 'a' to make it a legal identifier results.append( - " this." - + jscriptVar + " this.a" + + jscriptVar++ + " = new Array(\"" + field.getKey() + "\", \"" @@ -724,54 +723,6 @@ sb.append("</script>\n\n"); return sb.toString(); - } - - /** - * The value <code>null</code> will be returned at the end of the sequence. - * ex: "zz" will return <code>null</code> - */ - private String getNextVar(String input) { - if (input == null) { - return "aa"; - } - - input = input.toLowerCase(); - - for (int i = input.length(); i > 0; i--) { - int pos = i - 1; - - char c = input.charAt(pos); - c++; - - if (c <= 'z') { - if (i == 0) { - return c + input.substring(pos, input.length()); - } else if (i == input.length()) { - return input.substring(0, pos) + c; - } else { - return input.substring(0, pos) + c + input.substring(pos, input.length() - 1); - } - } else { - input = replaceChar(input, pos, 'a'); - } - - } - - return null; - - } - - /** - * Replaces a single character in a <code>String</code> - */ - private String replaceChar(String input, int pos, char c) { - if (pos == 0) { - return c + input.substring(pos, input.length()); - } else if (pos == input.length()) { - return input.substring(0, pos) + c; - } else { - return input.substring(0, pos) + c + input.substring(pos, input.length() - 1); - } } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]