26 package com.sun.tools.doclets.formats.html; |
26 package com.sun.tools.doclets.formats.html; |
27 |
27 |
28 import java.io.*; |
28 import java.io.*; |
29 import java.text.SimpleDateFormat; |
29 import java.text.SimpleDateFormat; |
30 import java.util.*; |
30 import java.util.*; |
|
31 import java.util.regex.Matcher; |
|
32 import java.util.regex.Pattern; |
31 |
33 |
32 import com.sun.javadoc.*; |
34 import com.sun.javadoc.*; |
33 import com.sun.tools.doclets.formats.html.markup.*; |
35 import com.sun.tools.doclets.formats.html.markup.*; |
34 import com.sun.tools.doclets.internal.toolkit.*; |
36 import com.sun.tools.doclets.internal.toolkit.*; |
35 import com.sun.tools.doclets.internal.toolkit.taglets.*; |
37 import com.sun.tools.doclets.internal.toolkit.taglets.*; |
137 // Return if no inline tags exist |
139 // Return if no inline tags exist |
138 int index = htmlstr.indexOf("{@"); |
140 int index = htmlstr.indexOf("{@"); |
139 if (index < 0) { |
141 if (index < 0) { |
140 return htmlstr; |
142 return htmlstr; |
141 } |
143 } |
142 String lowerHtml = StringUtils.toLowerCase(htmlstr); |
144 Matcher docrootMatcher = docrootPattern.matcher(htmlstr); |
143 final String docroot = "{@docroot}"; |
145 if (!docrootMatcher.find()) { |
144 // Return index of first occurrence of {@docroot} |
|
145 // Note: {@docRoot} is not case sensitive when passed in w/command line option |
|
146 index = lowerHtml.indexOf(docroot, index); |
|
147 if (index < 0) { |
|
148 return htmlstr; |
146 return htmlstr; |
149 } |
147 } |
150 StringBuilder buf = new StringBuilder(); |
148 StringBuilder buf = new StringBuilder(); |
151 int previndex = 0; |
149 int prevEnd = 0; |
152 while (true) { |
150 do { |
153 // Search for lowercase version of {@docRoot} |
151 int match = docrootMatcher.start(); |
154 index = lowerHtml.indexOf(docroot, previndex); |
152 // append htmlstr up to start of next {@docroot} |
155 // If next {@docRoot} tag not found, append rest of htmlstr and exit loop |
153 buf.append(htmlstr.substring(prevEnd, match)); |
156 if (index < 0) { |
154 prevEnd = docrootMatcher.end(); |
157 buf.append(htmlstr.substring(previndex)); |
155 if (configuration.docrootparent.length() > 0 && htmlstr.startsWith("/..", prevEnd)) { |
158 break; |
|
159 } |
|
160 // If next {@docroot} tag found, append htmlstr up to start of tag |
|
161 buf.append(htmlstr.substring(previndex, index)); |
|
162 previndex = index + docroot.length(); |
|
163 if (configuration.docrootparent.length() > 0 && htmlstr.startsWith("/..", previndex)) { |
|
164 // Insert the absolute link if {@docRoot} is followed by "/..". |
156 // Insert the absolute link if {@docRoot} is followed by "/..". |
165 buf.append(configuration.docrootparent); |
157 buf.append(configuration.docrootparent); |
166 previndex += 3; |
158 prevEnd += 3; |
167 } else { |
159 } else { |
168 // Insert relative path where {@docRoot} was located |
160 // Insert relative path where {@docRoot} was located |
169 buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath()); |
161 buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath()); |
170 } |
162 } |
171 // Append slash if next character is not a slash |
163 // Append slash if next character is not a slash |
172 if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') { |
164 if (prevEnd < htmlstr.length() && htmlstr.charAt(prevEnd) != '/') { |
173 buf.append('/'); |
165 buf.append('/'); |
174 } |
166 } |
175 } |
167 } while (docrootMatcher.find()); |
|
168 buf.append(htmlstr.substring(prevEnd)); |
176 return buf.toString(); |
169 return buf.toString(); |
177 } |
170 } |
|
171 //where: |
|
172 // Note: {@docRoot} is not case sensitive when passed in w/command line option: |
|
173 private static final Pattern docrootPattern = |
|
174 Pattern.compile(Pattern.quote("{@docroot}"), Pattern.CASE_INSENSITIVE); |
178 |
175 |
179 /** |
176 /** |
180 * Get the script to show or hide the All classes link. |
177 * Get the script to show or hide the All classes link. |
181 * |
178 * |
182 * @param id id of the element to show or hide |
179 * @param id id of the element to show or hide |
1688 } else { |
1685 } else { |
1689 return text; |
1686 return text; |
1690 } |
1687 } |
1691 |
1688 |
1692 //Redirect all relative links. |
1689 //Redirect all relative links. |
1693 int end, begin = StringUtils.toLowerCase(text).indexOf("<a"); |
1690 int end, begin = StringUtils.indexOfIgnoreCase(text, "<a"); |
1694 if(begin >= 0){ |
1691 if(begin >= 0){ |
1695 StringBuilder textBuff = new StringBuilder(text); |
1692 StringBuilder textBuff = new StringBuilder(text); |
1696 |
1693 |
1697 while(begin >=0){ |
1694 while(begin >=0){ |
1698 if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) { |
1695 if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) { |
1699 begin = StringUtils.toLowerCase(textBuff.toString()).indexOf("<a", begin + 1); |
1696 begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1); |
1700 continue; |
1697 continue; |
1701 } |
1698 } |
1702 |
1699 |
1703 begin = textBuff.indexOf("=", begin) + 1; |
1700 begin = textBuff.indexOf("=", begin) + 1; |
1704 end = textBuff.indexOf(">", begin +1); |
1701 end = textBuff.indexOf(">", begin +1); |
1730 relativeLinkLowerCase.startsWith("file:"))) { |
1727 relativeLinkLowerCase.startsWith("file:"))) { |
1731 relativeLink = "{@"+(new DocRootTaglet()).getName() + "}/" |
1728 relativeLink = "{@"+(new DocRootTaglet()).getName() + "}/" |
1732 + redirectPathFromRoot.resolve(relativeLink).getPath(); |
1729 + redirectPathFromRoot.resolve(relativeLink).getPath(); |
1733 textBuff.replace(begin, end, relativeLink); |
1730 textBuff.replace(begin, end, relativeLink); |
1734 } |
1731 } |
1735 begin = StringUtils.toLowerCase(textBuff.toString()).indexOf("<a", begin + 1); |
1732 begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1); |
1736 } |
1733 } |
1737 return textBuff.toString(); |
1734 return textBuff.toString(); |
1738 } |
1735 } |
1739 return text; |
1736 return text; |
1740 } |
1737 } |