[jdom-interest] Important proposal: Element/Document changes - bug

Michael Hinchey hincheymg at yahoo.com
Fri Jul 28 01:36:02 PDT 2000


I have the latest CVS code.  This is the only problem
from the changes that I found by running my code.

Element#getTextTrim() should check for null text
first.  Otherwise StringTokenizer throws an NPE.  I
also added the same length==0 check as you have in
getText().

BTW, I'm +1 on this method normalizing internal
whitespace.

public String getTextTrim() {
    if (getText() == null) {
      return null;
    }

    // Use "cached" trimmed text if available
    if (trimmedContent == null) {

        StringBuffer textContent = new StringBuffer();

        StringTokenizer tokenizer = new
StringTokenizer(getText());
        while (tokenizer.hasMoreTokens()) {
            String str = tokenizer.nextToken();
            textContent.append(str);
            if (tokenizer.hasMoreTokens()) {
                textContent.append(" ");  // separator
            }
        }

        trimmedContent = textContent.toString();
    }

    if (trimmedContent.length() == 0) {
        return null;
    }
    else {
        return trimmedContent;
    }
}

-Mike



__________________________________________________
Do You Yahoo!?
Kick off your party with Yahoo! Invites.
http://invites.yahoo.com/



More information about the jdom-interest mailing list