You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Patrick J. McNerthney" <pa...@mcnerthney.com> on 2000/07/18 01:28:11 UTC

Jasper code generation problem (bug?)

When I create a custom tag with a name that contains a dash, such as
"Foo-Bar", Jasper uses this name in the generation of the variable name
used to hold the instance of this tag.  Since the dash is not a valid
java variable character, this code does not compile under javac.  Other
JSP compilers, such as WebLogic do handle tag names with dashes fine.

The JavaServer Pages Specification, Version 1.1 states in section 5.3.5
that the name element's PCDATA is comprised of NMTOKEN (name token),
which according to the XML specification includes the dash.

Is this a problem with Jasper or does the JSP specification in fact
preclude the use of dashes in the name element PCDATA?

Thanks,
Pat McNerthney
Icicle Software, Inc.

Re: Jasper code generation problem (bug?)

Posted by "Patrick J. McNerthney" <pa...@mcnerthney.com>.
> This does turn out to be a bug in Tomcat.  I'm not sure it can get
> addressed
> in a 3.2 timeframe, but will definitely be addressed in a subsequent
> version.


The following changes to TagGeneratorBase.java fixes the issue (I also
attached the .java file).  I can understand if this still doesn't make
it into 3.2 if you have QA issues.

Thanks,
Patrick J. McNerthney
Icicle Software, Inc.


<code>

    protected String getTagVarName(String prefix, String shortTagName) {
        // Fix: Can probably remove the synchronization now when no vars
or method is static
        synchronized (tagVarNumbers) {
            prefix = javaizeName(prefix);
            shortTagName = javaizeName(shortTagName);
            String tag = prefix+":"+shortTagName;
            String varName = prefix+"_"+shortTagName+"_";
            if (tagVarNumbers.get(tag) != null) {
                Integer i = (Integer) tagVarNumbers.get(tag);
                varName = varName + i.intValue();
                tagVarNumbers.put(tag, new Integer(i.intValue()+1));
                return varName;
            } else {
                tagVarNumbers.put(tag, new Integer(1));
                return varName+"0";
            }
        }
    }

    private String javaizeName(String name) {
        int length = name.length();
        for (int i = 0; i < length; ++i) {
            if (!Character.isJavaIdentifierPart(name.charAt(i))) {
                char[] chars = name.toCharArray();
                chars[i] = '_';
                for (++i; i < length; ++i) {
                    if (!Character.isJavaIdentifierPart(chars[i])) {
                        chars[i] = '_';
                    }
                }
                return new String(chars);
            }
        }
        return name;
    }

</code>

Re: Jasper code generation problem (bug?)

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"Patrick J. McNerthney" wrote:

> Did I submit this question to the right place?

This does turn out to be a bug in Tomcat.  I'm not sure it can get
addressed
in a 3.2 timeframe, but will definitely be addressed in a subsequent
version.

Craig McClanahan


>
> "Patrick J. McNerthney" wrote:
> >
> > When I create a custom tag with a name that contains a dash, such as
> > "Foo-Bar", Jasper uses this name in the generation of the variable name
> > used to hold the instance of this tag.  Since the dash is not a valid
> > java variable character, this code does not compile under javac.  Other
> > JSP compilers, such as WebLogic do handle tag names with dashes fine.
> >
> > The JavaServer Pages Specification, Version 1.1 states in section 5.3.5
> > that the name element's PCDATA is comprised of NMTOKEN (name token),
> > which according to the XML specification includes the dash.
> >
> > Is this a problem with Jasper or does the JSP specification in fact
> > preclude the use of dashes in the name element PCDATA?
> >
> > Thanks,
> > Pat McNerthney
> > Icicle Software, Inc.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org

Re: Jasper code generation problem (bug?)

Posted by "Patrick J. McNerthney" <pa...@mcnerthney.com>.
Did I submit this question to the right place?

"Patrick J. McNerthney" wrote:
> 
> When I create a custom tag with a name that contains a dash, such as
> "Foo-Bar", Jasper uses this name in the generation of the variable name
> used to hold the instance of this tag.  Since the dash is not a valid
> java variable character, this code does not compile under javac.  Other
> JSP compilers, such as WebLogic do handle tag names with dashes fine.
> 
> The JavaServer Pages Specification, Version 1.1 states in section 5.3.5
> that the name element's PCDATA is comprised of NMTOKEN (name token),
> which according to the XML specification includes the dash.
> 
> Is this a problem with Jasper or does the JSP specification in fact
> preclude the use of dashes in the name element PCDATA?
> 
> Thanks,
> Pat McNerthney
> Icicle Software, Inc.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org