Author: keith Date: Thu Feb 12 06:41:06 2009 New Revision: 30738 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=30738
Log: Fix for Author: jonathan Date: Mon Oct 13 15:47:00 2008 New Revision: 22382 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=22382 Log: Improved removal of tags after the display limit has been reached. Modified: branches/mashup/java/1.5/java/modules/core/src/org/wso2/mashup/webapp/utils/QueryParamUtils.java Modified: branches/mashup/java/1.5/java/modules/core/src/org/wso2/mashup/webapp/utils/QueryParamUtils.java URL: http://wso2.org/svn/browse/wso2/branches/mashup/java/1.5/java/modules/core/src/org/wso2/mashup/webapp/utils/QueryParamUtils.java?rev=30738&r1=30737&r2=30738&view=diff ============================================================================== --- branches/mashup/java/1.5/java/modules/core/src/org/wso2/mashup/webapp/utils/QueryParamUtils.java (original) +++ branches/mashup/java/1.5/java/modules/core/src/org/wso2/mashup/webapp/utils/QueryParamUtils.java Thu Feb 12 06:41:06 2009 @@ -150,24 +150,49 @@ entities e.g. < are counted as 4 charactets instead of one. */ public static String trimVisibleChars(String markup, int length) { - String trimmedMarkup = ""; - int charactersDisplayed = 0; - boolean parsingTag = false; - boolean completingWord = true; + String trimmedMarkup = ""; // The result string + int charactersDisplayed = 0; // How many visible characters have been displayed so far + boolean underDisplayLimit = true; // State variable - are we under the visible display limit or not (length + word completion) + boolean parsingTag = false; // State variable - are we parsing inside a tag? + boolean closeTag = false; // State variable - are we parsing inside a close tag? + int tagDepth = 0; // How many ancestors we have so far + int tagDepthLimit = 0; // How many ancestors are displayable. Anything deeper than this will be suppressed + // when the display limit has been reached. // Walk through the string a character at a time. for (int i=0; i<markup.length(); i++) { char c = markup.charAt(i); if (parsingTag) { - // preserve all markup (anything between < and >) - trimmedMarkup += c; + // preserve markup (anything between < and >) when we're under the visible length limit, + // or we're closing off existing markup. i.e. don't go any deeper. + if (underDisplayLimit || (!underDisplayLimit && tagDepth <=tagDepthLimit)) { + trimmedMarkup += c; + } + // we're at the end of a tag if (c == '>') { + // if we've just completed a close tag (indicated by closeTag), or we're at the end of a minimized tag, comment, or pi + // indicate that the depth has decreased. And even as you pop out remember never to go any deeper. + if (closeTag || markup.charAt(i - 1) == '/' || markup.charAt(i - 1) == '-' || markup.charAt(i - 1) == '?') { + tagDepth--; + if (tagDepth < tagDepthLimit) { + tagDepthLimit--; + } + } + // update state parsingTag = false; } } else { if (c == '<') { // entering a tag. Anything from now till > will be passed through. - trimmedMarkup += c; + if (markup.charAt(i + 1) == '/') { + closeTag = true; + } else { + tagDepth++; + } + + if (underDisplayLimit || (!underDisplayLimit && tagDepth <= tagDepthLimit)) { + trimmedMarkup += c; + } parsingTag = true; } else { if (c == ' ' && i > 0 && markup.charAt(i-1) == ' ') { @@ -179,7 +204,7 @@ charactersDisplayed++; } else { // now we're past the trimming mark, but we still might want to show a few characters. - if (completingWord) { + if (underDisplayLimit) { // if we're in the middle of a word, keep a few more characters. if (('0' <= c && c <= '9') || ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')) { trimmedMarkup += c; @@ -187,7 +212,8 @@ } else { // now we just completed the word, no other visible characters will be displayed. // add an ellipsis to indicate that trimming occurred. - completingWord = false; + underDisplayLimit = false; + tagDepthLimit = tagDepth; trimmedMarkup += "…"; charactersDisplayed++; } _______________________________________________ Mashup-dev mailing list [email protected] https://wso2.org/cgi-bin/mailman/listinfo/mashup-dev
