langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
changeset 22005 4270ada5dcd1
parent 21494 eb34dbccfb60
child 22153 f9f06fcca59d
equal deleted inserted replaced
22004:203318f0799d 22005:4270ada5dcd1
   146             return htmlstr;
   146             return htmlstr;
   147         }
   147         }
   148         StringBuilder buf = new StringBuilder();
   148         StringBuilder buf = new StringBuilder();
   149         int previndex = 0;
   149         int previndex = 0;
   150         while (true) {
   150         while (true) {
   151             if (configuration.docrootparent.length() > 0) {
   151             final String docroot = "{@docroot}";
   152                 final String docroot_parent = "{@docroot}/..";
   152             // Search for lowercase version of {@docRoot}
   153                 // Search for lowercase version of {@docRoot}/..
   153             index = lowerHtml.indexOf(docroot, previndex);
   154                 index = lowerHtml.indexOf(docroot_parent, previndex);
   154             // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
   155                 // If next {@docRoot}/.. pattern not found, append rest of htmlstr and exit loop
   155             if (index < 0) {
   156                 if (index < 0) {
   156                 buf.append(htmlstr.substring(previndex));
   157                     buf.append(htmlstr.substring(previndex));
   157                 break;
   158                     break;
   158             }
   159                 }
   159             // If next {@docroot} tag found, append htmlstr up to start of tag
   160                 // If next {@docroot}/.. pattern found, append htmlstr up to start of tag
   160             buf.append(htmlstr.substring(previndex, index));
   161                 buf.append(htmlstr.substring(previndex, index));
   161             previndex = index + docroot.length();
   162                 previndex = index + docroot_parent.length();
   162             if (configuration.docrootparent.length() > 0 && htmlstr.startsWith("/..", previndex)) {
   163                 // Insert docrootparent absolute path where {@docRoot}/.. was located
   163                 // Insert the absolute link if {@docRoot} is followed by "/..".
   164 
       
   165                 buf.append(configuration.docrootparent);
   164                 buf.append(configuration.docrootparent);
   166                 // Append slash if next character is not a slash
   165                 previndex += 3;
   167                 if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
       
   168                     buf.append('/');
       
   169                 }
       
   170             } else {
   166             } else {
   171                 final String docroot = "{@docroot}";
       
   172                 // Search for lowercase version of {@docRoot}
       
   173                 index = lowerHtml.indexOf(docroot, previndex);
       
   174                 // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
       
   175                 if (index < 0) {
       
   176                     buf.append(htmlstr.substring(previndex));
       
   177                     break;
       
   178                 }
       
   179                 // If next {@docroot} tag found, append htmlstr up to start of tag
       
   180                 buf.append(htmlstr.substring(previndex, index));
       
   181                 previndex = index + docroot.length();
       
   182                 // Insert relative path where {@docRoot} was located
   167                 // Insert relative path where {@docRoot} was located
   183                 buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath());
   168                 buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath());
   184                 // Append slash if next character is not a slash
   169             }
   185                 if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
   170             // Append slash if next character is not a slash
   186                     buf.append('/');
   171             if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
   187                 }
   172                 buf.append('/');
   188             }
   173             }
   189         }
   174         }
   190         return buf.toString();
   175         return buf.toString();
   191     }
   176     }
   192 
   177 
  1602             String tagName = tagelem.name();
  1587             String tagName = tagelem.name();
  1603             if (tagelem instanceof SeeTag) {
  1588             if (tagelem instanceof SeeTag) {
  1604                 result.addContent(seeTagToContent((SeeTag) tagelem));
  1589                 result.addContent(seeTagToContent((SeeTag) tagelem));
  1605             } else if (! tagName.equals("Text")) {
  1590             } else if (! tagName.equals("Text")) {
  1606                 boolean wasEmpty = result.isEmpty();
  1591                 boolean wasEmpty = result.isEmpty();
  1607                 Content output = TagletWriter.getInlineTagOuput(
  1592                 Content output;
  1608                     configuration.tagletManager, holderTag,
  1593                 if (configuration.docrootparent.length() > 0
  1609                     tagelem, getTagletWriterInstance(isFirstSentence));
  1594                         && tagelem.name().equals("@docRoot")
       
  1595                         && ((tags[i + 1]).text()).startsWith("/..")) {
       
  1596                     // If Xdocrootparent switch ON, set the flag to remove the /.. occurrence after
       
  1597                     // {@docRoot} tag in the very next Text tag.
       
  1598                     textTagChange = true;
       
  1599                     // Replace the occurrence of {@docRoot}/.. with the absolute link.
       
  1600                     output = new StringContent(configuration.docrootparent);
       
  1601                 } else {
       
  1602                     output = TagletWriter.getInlineTagOuput(
       
  1603                             configuration.tagletManager, holderTag,
       
  1604                             tagelem, getTagletWriterInstance(isFirstSentence));
       
  1605                 }
  1610                 if (output != null)
  1606                 if (output != null)
  1611                     result.addContent(output);
  1607                     result.addContent(output);
  1612                 if (wasEmpty && isFirstSentence && tagelem.name().equals("@inheritDoc") && !result.isEmpty()) {
  1608                 if (wasEmpty && isFirstSentence && tagelem.name().equals("@inheritDoc") && !result.isEmpty()) {
  1613                     break;
  1609                     break;
  1614                 } else if (configuration.docrootparent.length() > 0 &&
       
  1615                         tagelem.name().equals("@docRoot") &&
       
  1616                         ((tags[i + 1]).text()).startsWith("/..")) {
       
  1617                     //If Xdocrootparent switch ON, set the flag to remove the /.. occurance after
       
  1618                     //{@docRoot} tag in the very next Text tag.
       
  1619                     textTagChange = true;
       
  1620                     continue;
       
  1621                 } else {
  1610                 } else {
  1622                     continue;
  1611                     continue;
  1623                 }
  1612                 }
  1624             } else {
  1613             } else {
  1625                 String text = tagelem.text();
  1614                 String text = tagelem.text();
  1626                 //If Xdocrootparent switch ON, remove the /.. occurance after {@docRoot} tag.
  1615                 //If Xdocrootparent switch ON, remove the /.. occurrence after {@docRoot} tag.
  1627                 if (textTagChange) {
  1616                 if (textTagChange) {
  1628                     text = text.replaceFirst("/..", "");
  1617                     text = text.replaceFirst("/..", "");
  1629                     textTagChange = false;
  1618                     textTagChange = false;
  1630                 }
  1619                 }
  1631                 //This is just a regular text tag.  The text may contain html links (<a>)
  1620                 //This is just a regular text tag.  The text may contain html links (<a>)