1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Thu Dec 19 11:38:45 2013 -0500 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Thu May 29 10:48:00 2014 +0200 1.3 @@ -28,6 +28,8 @@ 1.4 import java.io.*; 1.5 import java.text.SimpleDateFormat; 1.6 import java.util.*; 1.7 +import java.util.regex.Matcher; 1.8 +import java.util.regex.Pattern; 1.9 1.10 import com.sun.javadoc.*; 1.11 import com.sun.tools.doclets.formats.html.markup.*; 1.12 @@ -139,42 +141,37 @@ 1.13 if (index < 0) { 1.14 return htmlstr; 1.15 } 1.16 - String lowerHtml = StringUtils.toLowerCase(htmlstr); 1.17 - final String docroot = "{@docroot}"; 1.18 - // Return index of first occurrence of {@docroot} 1.19 - // Note: {@docRoot} is not case sensitive when passed in w/command line option 1.20 - index = lowerHtml.indexOf(docroot, index); 1.21 - if (index < 0) { 1.22 + Matcher docrootMatcher = docrootPattern.matcher(htmlstr); 1.23 + if (!docrootMatcher.find()) { 1.24 return htmlstr; 1.25 } 1.26 StringBuilder buf = new StringBuilder(); 1.27 - int previndex = 0; 1.28 - while (true) { 1.29 - // Search for lowercase version of {@docRoot} 1.30 - index = lowerHtml.indexOf(docroot, previndex); 1.31 - // If next {@docRoot} tag not found, append rest of htmlstr and exit loop 1.32 - if (index < 0) { 1.33 - buf.append(htmlstr.substring(previndex)); 1.34 - break; 1.35 - } 1.36 - // If next {@docroot} tag found, append htmlstr up to start of tag 1.37 - buf.append(htmlstr.substring(previndex, index)); 1.38 - previndex = index + docroot.length(); 1.39 - if (configuration.docrootparent.length() > 0 && htmlstr.startsWith("/..", previndex)) { 1.40 + int prevEnd = 0; 1.41 + do { 1.42 + int match = docrootMatcher.start(); 1.43 + // append htmlstr up to start of next {@docroot} 1.44 + buf.append(htmlstr.substring(prevEnd, match)); 1.45 + prevEnd = docrootMatcher.end(); 1.46 + if (configuration.docrootparent.length() > 0 && htmlstr.startsWith("/..", prevEnd)) { 1.47 // Insert the absolute link if {@docRoot} is followed by "/..". 1.48 buf.append(configuration.docrootparent); 1.49 - previndex += 3; 1.50 + prevEnd += 3; 1.51 } else { 1.52 // Insert relative path where {@docRoot} was located 1.53 buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath()); 1.54 } 1.55 // Append slash if next character is not a slash 1.56 - if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') { 1.57 + if (prevEnd < htmlstr.length() && htmlstr.charAt(prevEnd) != '/') { 1.58 buf.append('/'); 1.59 } 1.60 - } 1.61 + } while (docrootMatcher.find()); 1.62 + buf.append(htmlstr.substring(prevEnd)); 1.63 return buf.toString(); 1.64 } 1.65 + //where: 1.66 + // Note: {@docRoot} is not case sensitive when passed in w/command line option: 1.67 + private static final Pattern docrootPattern = 1.68 + Pattern.compile(Pattern.quote("{@docroot}"), Pattern.CASE_INSENSITIVE); 1.69 1.70 /** 1.71 * Get the script to show or hide the All classes link. 1.72 @@ -1690,13 +1687,13 @@ 1.73 } 1.74 1.75 //Redirect all relative links. 1.76 - int end, begin = StringUtils.toLowerCase(text).indexOf("<a"); 1.77 + int end, begin = StringUtils.indexOfIgnoreCase(text, "<a"); 1.78 if(begin >= 0){ 1.79 StringBuilder textBuff = new StringBuilder(text); 1.80 1.81 while(begin >=0){ 1.82 if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) { 1.83 - begin = StringUtils.toLowerCase(textBuff.toString()).indexOf("<a", begin + 1); 1.84 + begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1); 1.85 continue; 1.86 } 1.87 1.88 @@ -1732,7 +1729,7 @@ 1.89 + redirectPathFromRoot.resolve(relativeLink).getPath(); 1.90 textBuff.replace(begin, end, relativeLink); 1.91 } 1.92 - begin = StringUtils.toLowerCase(textBuff.toString()).indexOf("<a", begin + 1); 1.93 + begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1); 1.94 } 1.95 return textBuff.toString(); 1.96 }