src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java

changeset 997
dbc4ced9d171
parent 995
62bc3775d5bb
child 1326
30c36e23f154
     1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Mon May 02 12:05:41 2011 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Mon May 02 10:10:31 2011 -0700
     1.3 @@ -159,22 +159,42 @@
     1.4          StringBuilder buf = new StringBuilder();
     1.5          int previndex = 0;
     1.6          while (true) {
     1.7 -            // Search for lowercase version of {@docRoot}
     1.8 -            index = lowerHtml.indexOf("{@docroot}", previndex);
     1.9 -            // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
    1.10 -            if (index < 0) {
    1.11 -                buf.append(htmlstr.substring(previndex));
    1.12 -                break;
    1.13 -            }
    1.14 -            // If next {@docroot} tag found, append htmlstr up to start of tag
    1.15 -            buf.append(htmlstr.substring(previndex, index));
    1.16 -            previndex = index + 10;  // length for {@docroot} string
    1.17 -            // Insert relative path where {@docRoot} was located
    1.18 -            buf.append(relativepathNoSlash);
    1.19 -            // Append slash if next character is not a slash
    1.20 -            if (relativepathNoSlash.length() > 0 && previndex < htmlstr.length()
    1.21 -                    && htmlstr.charAt(previndex) != '/') {
    1.22 -                buf.append(DirectoryManager.URL_FILE_SEPARATOR);
    1.23 +            if (configuration.docrootparent.length() > 0) {
    1.24 +                // Search for lowercase version of {@docRoot}/..
    1.25 +                index = lowerHtml.indexOf("{@docroot}/..", previndex);
    1.26 +                // If next {@docRoot}/.. pattern not found, append rest of htmlstr and exit loop
    1.27 +                if (index < 0) {
    1.28 +                    buf.append(htmlstr.substring(previndex));
    1.29 +                    break;
    1.30 +                }
    1.31 +                // If next {@docroot}/.. pattern found, append htmlstr up to start of tag
    1.32 +                buf.append(htmlstr.substring(previndex, index));
    1.33 +                previndex = index + 13;  // length for {@docroot}/.. string
    1.34 +                // Insert docrootparent absolute path where {@docRoot}/.. was located
    1.35 +
    1.36 +                buf.append(configuration.docrootparent);
    1.37 +                // Append slash if next character is not a slash
    1.38 +                if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
    1.39 +                    buf.append(DirectoryManager.URL_FILE_SEPARATOR);
    1.40 +                }
    1.41 +            } else {
    1.42 +                // Search for lowercase version of {@docRoot}
    1.43 +                index = lowerHtml.indexOf("{@docroot}", previndex);
    1.44 +                // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
    1.45 +                if (index < 0) {
    1.46 +                    buf.append(htmlstr.substring(previndex));
    1.47 +                    break;
    1.48 +                }
    1.49 +                // If next {@docroot} tag found, append htmlstr up to start of tag
    1.50 +                buf.append(htmlstr.substring(previndex, index));
    1.51 +                previndex = index + 10;  // length for {@docroot} string
    1.52 +                // Insert relative path where {@docRoot} was located
    1.53 +                buf.append(relativepathNoSlash);
    1.54 +                // Append slash if next character is not a slash
    1.55 +                if (relativepathNoSlash.length() > 0 && previndex < htmlstr.length() &&
    1.56 +                        htmlstr.charAt(previndex) != '/') {
    1.57 +                    buf.append(DirectoryManager.URL_FILE_SEPARATOR);
    1.58 +                }
    1.59              }
    1.60          }
    1.61          return buf.toString();
    1.62 @@ -2318,6 +2338,7 @@
    1.63      public String commentTagsToString(Tag holderTag, Doc doc, Tag[] tags,
    1.64              boolean isFirstSentence) {
    1.65          StringBuilder result = new StringBuilder();
    1.66 +        boolean textTagChange = false;
    1.67          // Array of all possible inline tags for this javadoc run
    1.68          configuration.tagletManager.checkTags(doc, tags, true);
    1.69          for (int i = 0; i < tags.length; i++) {
    1.70 @@ -2333,13 +2354,26 @@
    1.71                  result.append(output == null ? "" : output.toString());
    1.72                  if (originalLength == 0 && isFirstSentence && tagelem.name().equals("@inheritDoc") && result.length() > 0) {
    1.73                      break;
    1.74 +                } else if (configuration.docrootparent.length() > 0 &&
    1.75 +                        tagelem.name().equals("@docRoot") &&
    1.76 +                        ((tags[i + 1]).text()).startsWith("/..")) {
    1.77 +                    //If Xdocrootparent switch ON, set the flag to remove the /.. occurance after
    1.78 +                    //{@docRoot} tag in the very next Text tag.
    1.79 +                    textTagChange = true;
    1.80 +                    continue;
    1.81                  } else {
    1.82 -                        continue;
    1.83 +                    continue;
    1.84                  }
    1.85              } else {
    1.86 +                String text = tagelem.text();
    1.87 +                //If Xdocrootparent switch ON, remove the /.. occurance after {@docRoot} tag.
    1.88 +                if (textTagChange) {
    1.89 +                    text = text.replaceFirst("/..", "");
    1.90 +                    textTagChange = false;
    1.91 +                }
    1.92                  //This is just a regular text tag.  The text may contain html links (<a>)
    1.93                  //or inline tag {@docRoot}, which will be handled as special cases.
    1.94 -                String text = redirectRelativeLinks(tagelem.holder(), tagelem.text());
    1.95 +                text = redirectRelativeLinks(tagelem.holder(), text);
    1.96  
    1.97                  // Replace @docRoot only if not represented by an instance of DocRootTaglet,
    1.98                  // that is, only if it was not present in a source file doc comment.

mercurial