Java Code Examples for com.sun.tools.javac.util.StringUtils#indexOfIgnoreCase()

The following examples show how to use com.sun.tools.javac.util.StringUtils#indexOfIgnoreCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HtmlDocletWriter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Suppose a piece of documentation has a relative link.  When you copy
 * that documentation to another place such as the index or class-use page,
 * that relative link will no longer work.  We should redirect those links
 * so that they will work again.
 * <p>
 * Here is the algorithm used to fix the link:
 * <p>
 * {@literal <relative link> => docRoot + <relative path to file> + <relative link> }
 * <p>
 * For example, suppose com.sun.javadoc.RootDoc has this link:
 * {@literal <a href="package-summary.html">The package Page</a> }
 * <p>
 * If this link appeared in the index, we would redirect
 * the link like this:
 *
 * {@literal <a href="./com/sun/javadoc/package-summary.html">The package Page</a>}
 *
 * @param doc the Doc object whose documentation is being written.
 * @param text the text being written.
 *
 * @return the text, with all the relative links redirected to work.
 */
private String redirectRelativeLinks(Doc doc, String text) {
    if (doc == null || shouldNotRedirectRelativeLinks()) {
        return text;
    }

    DocPath redirectPathFromRoot;
    if (doc instanceof ClassDoc) {
        redirectPathFromRoot = DocPath.forPackage(((ClassDoc) doc).containingPackage());
    } else if (doc instanceof MemberDoc) {
        redirectPathFromRoot = DocPath.forPackage(((MemberDoc) doc).containingPackage());
    } else if (doc instanceof PackageDoc) {
        redirectPathFromRoot = DocPath.forPackage((PackageDoc) doc);
    } else {
        return text;
    }

    //Redirect all relative links.
    int end, begin = StringUtils.indexOfIgnoreCase(text, "<a");
    if(begin >= 0){
        StringBuilder textBuff = new StringBuilder(text);

        while(begin >=0){
            if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
                begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
                continue;
            }

            begin = textBuff.indexOf("=", begin) + 1;
            end = textBuff.indexOf(">", begin +1);
            if(begin == 0){
                //Link has no equal symbol.
                configuration.root.printWarning(
                    doc.position(),
                    configuration.getText("doclet.malformed_html_link_tag", text));
                break;
            }
            if (end == -1) {
                //Break without warning.  This <a> tag is not necessarily malformed.  The text
                //might be missing '>' character because the href has an inline tag.
                break;
            }
            if (textBuff.substring(begin, end).indexOf("\"") != -1){
                begin = textBuff.indexOf("\"", begin) + 1;
                end = textBuff.indexOf("\"", begin +1);
                if (begin == 0 || end == -1){
                    //Link is missing a quote.
                    break;
                }
            }
            String relativeLink = textBuff.substring(begin, end);
            String relativeLinkLowerCase = StringUtils.toLowerCase(relativeLink);
            if (!(relativeLinkLowerCase.startsWith("mailto:") ||
                    relativeLinkLowerCase.startsWith("http:") ||
                    relativeLinkLowerCase.startsWith("https:") ||
                    relativeLinkLowerCase.startsWith("file:"))) {
                relativeLink = "{@"+(new DocRootTaglet()).getName() + "}/"
                    + redirectPathFromRoot.resolve(relativeLink).getPath();
                textBuff.replace(begin, end, relativeLink);
            }
            begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
        }
        return textBuff.toString();
    }
    return text;
}
 
Example 2
Source File: HtmlDocletWriter.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Suppose a piece of documentation has a relative link.  When you copy
 * that documentation to another place such as the index or class-use page,
 * that relative link will no longer work.  We should redirect those links
 * so that they will work again.
 * <p>
 * Here is the algorithm used to fix the link:
 * <p>
 * {@literal <relative link> => docRoot + <relative path to file> + <relative link> }
 * <p>
 * For example, suppose com.sun.javadoc.RootDoc has this link:
 * {@literal <a href="package-summary.html">The package Page</a> }
 * <p>
 * If this link appeared in the index, we would redirect
 * the link like this:
 *
 * {@literal <a href="./com/sun/javadoc/package-summary.html">The package Page</a>}
 *
 * @param doc the Doc object whose documentation is being written.
 * @param text the text being written.
 *
 * @return the text, with all the relative links redirected to work.
 */
private String redirectRelativeLinks(Doc doc, String text) {
    if (doc == null || shouldNotRedirectRelativeLinks()) {
        return text;
    }

    DocPath redirectPathFromRoot;
    if (doc instanceof ClassDoc) {
        redirectPathFromRoot = DocPath.forPackage(((ClassDoc) doc).containingPackage());
    } else if (doc instanceof MemberDoc) {
        redirectPathFromRoot = DocPath.forPackage(((MemberDoc) doc).containingPackage());
    } else if (doc instanceof PackageDoc) {
        redirectPathFromRoot = DocPath.forPackage((PackageDoc) doc);
    } else {
        return text;
    }

    //Redirect all relative links.
    int end, begin = StringUtils.indexOfIgnoreCase(text, "<a");
    if(begin >= 0){
        StringBuilder textBuff = new StringBuilder(text);

        while(begin >=0){
            if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
                begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
                continue;
            }

            begin = textBuff.indexOf("=", begin) + 1;
            end = textBuff.indexOf(">", begin +1);
            if(begin == 0){
                //Link has no equal symbol.
                configuration.root.printWarning(
                    doc.position(),
                    configuration.getText("doclet.malformed_html_link_tag", text));
                break;
            }
            if (end == -1) {
                //Break without warning.  This <a> tag is not necessarily malformed.  The text
                //might be missing '>' character because the href has an inline tag.
                break;
            }
            if (textBuff.substring(begin, end).indexOf("\"") != -1){
                begin = textBuff.indexOf("\"", begin) + 1;
                end = textBuff.indexOf("\"", begin +1);
                if (begin == 0 || end == -1){
                    //Link is missing a quote.
                    break;
                }
            }
            String relativeLink = textBuff.substring(begin, end);
            String relativeLinkLowerCase = StringUtils.toLowerCase(relativeLink);
            if (!(relativeLinkLowerCase.startsWith("mailto:") ||
                    relativeLinkLowerCase.startsWith("http:") ||
                    relativeLinkLowerCase.startsWith("https:") ||
                    relativeLinkLowerCase.startsWith("file:"))) {
                relativeLink = "{@"+(new DocRootTaglet()).getName() + "}/"
                    + redirectPathFromRoot.resolve(relativeLink).getPath();
                textBuff.replace(begin, end, relativeLink);
            }
            begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
        }
        return textBuff.toString();
    }
    return text;
}
 
Example 3
Source File: HtmlDocletWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Suppose a piece of documentation has a relative link.  When you copy
 * that documentation to another place such as the index or class-use page,
 * that relative link will no longer work.  We should redirect those links
 * so that they will work again.
 * <p>
 * Here is the algorithm used to fix the link:
 * <p>
 * {@literal <relative link> => docRoot + <relative path to file> + <relative link> }
 * <p>
 * For example, suppose com.sun.javadoc.RootDoc has this link:
 * {@literal <a href="package-summary.html">The package Page</a> }
 * <p>
 * If this link appeared in the index, we would redirect
 * the link like this:
 *
 * {@literal <a href="./com/sun/javadoc/package-summary.html">The package Page</a>}
 *
 * @param doc the Doc object whose documentation is being written.
 * @param text the text being written.
 *
 * @return the text, with all the relative links redirected to work.
 */
private String redirectRelativeLinks(Doc doc, String text) {
    if (doc == null || shouldNotRedirectRelativeLinks()) {
        return text;
    }

    DocPath redirectPathFromRoot;
    if (doc instanceof ClassDoc) {
        redirectPathFromRoot = DocPath.forPackage(((ClassDoc) doc).containingPackage());
    } else if (doc instanceof MemberDoc) {
        redirectPathFromRoot = DocPath.forPackage(((MemberDoc) doc).containingPackage());
    } else if (doc instanceof PackageDoc) {
        redirectPathFromRoot = DocPath.forPackage((PackageDoc) doc);
    } else {
        return text;
    }

    //Redirect all relative links.
    int end, begin = StringUtils.indexOfIgnoreCase(text, "<a");
    if(begin >= 0){
        StringBuilder textBuff = new StringBuilder(text);

        while(begin >=0){
            if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
                begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
                continue;
            }

            begin = textBuff.indexOf("=", begin) + 1;
            end = textBuff.indexOf(">", begin +1);
            if(begin == 0){
                //Link has no equal symbol.
                configuration.root.printWarning(
                    doc.position(),
                    configuration.getText("doclet.malformed_html_link_tag", text));
                break;
            }
            if (end == -1) {
                //Break without warning.  This <a> tag is not necessarily malformed.  The text
                //might be missing '>' character because the href has an inline tag.
                break;
            }
            if (textBuff.substring(begin, end).indexOf("\"") != -1){
                begin = textBuff.indexOf("\"", begin) + 1;
                end = textBuff.indexOf("\"", begin +1);
                if (begin == 0 || end == -1){
                    //Link is missing a quote.
                    break;
                }
            }
            String relativeLink = textBuff.substring(begin, end);
            String relativeLinkLowerCase = StringUtils.toLowerCase(relativeLink);
            if (!(relativeLinkLowerCase.startsWith("mailto:") ||
                    relativeLinkLowerCase.startsWith("http:") ||
                    relativeLinkLowerCase.startsWith("https:") ||
                    relativeLinkLowerCase.startsWith("file:"))) {
                relativeLink = "{@"+(new DocRootTaglet()).getName() + "}/"
                    + redirectPathFromRoot.resolve(relativeLink).getPath();
                textBuff.replace(begin, end, relativeLink);
            }
            begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
        }
        return textBuff.toString();
    }
    return text;
}
 
Example 4
Source File: HtmlDocletWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Suppose a piece of documentation has a relative link.  When you copy
 * that documentation to another place such as the index or class-use page,
 * that relative link will no longer work.  We should redirect those links
 * so that they will work again.
 * <p>
 * Here is the algorithm used to fix the link:
 * <p>
 * {@literal <relative link> => docRoot + <relative path to file> + <relative link> }
 * <p>
 * For example, suppose com.sun.javadoc.RootDoc has this link:
 * {@literal <a href="package-summary.html">The package Page</a> }
 * <p>
 * If this link appeared in the index, we would redirect
 * the link like this:
 *
 * {@literal <a href="./com/sun/javadoc/package-summary.html">The package Page</a>}
 *
 * @param doc the Doc object whose documentation is being written.
 * @param text the text being written.
 *
 * @return the text, with all the relative links redirected to work.
 */
private String redirectRelativeLinks(Doc doc, String text) {
    if (doc == null || shouldNotRedirectRelativeLinks()) {
        return text;
    }

    DocPath redirectPathFromRoot;
    if (doc instanceof ClassDoc) {
        redirectPathFromRoot = DocPath.forPackage(((ClassDoc) doc).containingPackage());
    } else if (doc instanceof MemberDoc) {
        redirectPathFromRoot = DocPath.forPackage(((MemberDoc) doc).containingPackage());
    } else if (doc instanceof PackageDoc) {
        redirectPathFromRoot = DocPath.forPackage((PackageDoc) doc);
    } else {
        return text;
    }

    //Redirect all relative links.
    int end, begin = StringUtils.indexOfIgnoreCase(text, "<a");
    if(begin >= 0){
        StringBuilder textBuff = new StringBuilder(text);

        while(begin >=0){
            if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
                begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
                continue;
            }

            begin = textBuff.indexOf("=", begin) + 1;
            end = textBuff.indexOf(">", begin +1);
            if(begin == 0){
                //Link has no equal symbol.
                configuration.root.printWarning(
                    doc.position(),
                    configuration.getText("doclet.malformed_html_link_tag", text));
                break;
            }
            if (end == -1) {
                //Break without warning.  This <a> tag is not necessarily malformed.  The text
                //might be missing '>' character because the href has an inline tag.
                break;
            }
            if (textBuff.substring(begin, end).indexOf("\"") != -1){
                begin = textBuff.indexOf("\"", begin) + 1;
                end = textBuff.indexOf("\"", begin +1);
                if (begin == 0 || end == -1){
                    //Link is missing a quote.
                    break;
                }
            }
            String relativeLink = textBuff.substring(begin, end);
            String relativeLinkLowerCase = StringUtils.toLowerCase(relativeLink);
            if (!(relativeLinkLowerCase.startsWith("mailto:") ||
                    relativeLinkLowerCase.startsWith("http:") ||
                    relativeLinkLowerCase.startsWith("https:") ||
                    relativeLinkLowerCase.startsWith("file:"))) {
                relativeLink = "{@"+(new DocRootTaglet()).getName() + "}/"
                    + redirectPathFromRoot.resolve(relativeLink).getPath();
                textBuff.replace(begin, end, relativeLink);
            }
            begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
        }
        return textBuff.toString();
    }
    return text;
}
 
Example 5
Source File: HtmlDocletWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Suppose a piece of documentation has a relative link.  When you copy
 * that documentation to another place such as the index or class-use page,
 * that relative link will no longer work.  We should redirect those links
 * so that they will work again.
 * <p>
 * Here is the algorithm used to fix the link:
 * <p>
 * {@literal <relative link> => docRoot + <relative path to file> + <relative link> }
 * <p>
 * For example, suppose com.sun.javadoc.RootDoc has this link:
 * {@literal <a href="package-summary.html">The package Page</a> }
 * <p>
 * If this link appeared in the index, we would redirect
 * the link like this:
 *
 * {@literal <a href="./com/sun/javadoc/package-summary.html">The package Page</a>}
 *
 * @param doc the Doc object whose documentation is being written.
 * @param text the text being written.
 *
 * @return the text, with all the relative links redirected to work.
 */
private String redirectRelativeLinks(Doc doc, String text) {
    if (doc == null || shouldNotRedirectRelativeLinks()) {
        return text;
    }

    DocPath redirectPathFromRoot;
    if (doc instanceof ClassDoc) {
        redirectPathFromRoot = DocPath.forPackage(((ClassDoc) doc).containingPackage());
    } else if (doc instanceof MemberDoc) {
        redirectPathFromRoot = DocPath.forPackage(((MemberDoc) doc).containingPackage());
    } else if (doc instanceof PackageDoc) {
        redirectPathFromRoot = DocPath.forPackage((PackageDoc) doc);
    } else {
        return text;
    }

    //Redirect all relative links.
    int end, begin = StringUtils.indexOfIgnoreCase(text, "<a");
    if(begin >= 0){
        StringBuilder textBuff = new StringBuilder(text);

        while(begin >=0){
            if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
                begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
                continue;
            }

            begin = textBuff.indexOf("=", begin) + 1;
            end = textBuff.indexOf(">", begin +1);
            if(begin == 0){
                //Link has no equal symbol.
                configuration.root.printWarning(
                    doc.position(),
                    configuration.getText("doclet.malformed_html_link_tag", text));
                break;
            }
            if (end == -1) {
                //Break without warning.  This <a> tag is not necessarily malformed.  The text
                //might be missing '>' character because the href has an inline tag.
                break;
            }

            String quote = textBuff.substring(begin, end);
            quote = quote.contains("\"") ? "\"" :
                    quote.contains("\'") ? "\'" : null;
            if (quote != null) {
                begin = textBuff.indexOf(quote, begin) + 1;
                end = textBuff.indexOf(quote, begin +1);
                if (begin == 0 || end == -1){
                    //Link is missing a quote.
                    break;
                }
            }
            String relativeLink = textBuff.substring(begin, end);
            String relativeLinkLowerCase = StringUtils.toLowerCase(relativeLink);
            if (!(relativeLinkLowerCase.startsWith("mailto:") ||
                    relativeLinkLowerCase.startsWith("http:") ||
                    relativeLinkLowerCase.startsWith("https:") ||
                    relativeLinkLowerCase.startsWith("file:"))) {
                relativeLink = "{@"+(new DocRootTaglet()).getName() + "}/"
                    + redirectPathFromRoot.resolve(relativeLink).getPath();
                textBuff.replace(begin, end, relativeLink);
            }
            begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
        }
        return textBuff.toString();
    }
    return text;
}
 
Example 6
Source File: HtmlDocletWriter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Suppose a piece of documentation has a relative link.  When you copy
 * that documentation to another place such as the index or class-use page,
 * that relative link will no longer work.  We should redirect those links
 * so that they will work again.
 * <p>
 * Here is the algorithm used to fix the link:
 * <p>
 * {@literal <relative link> => docRoot + <relative path to file> + <relative link> }
 * <p>
 * For example, suppose com.sun.javadoc.RootDoc has this link:
 * {@literal <a href="package-summary.html">The package Page</a> }
 * <p>
 * If this link appeared in the index, we would redirect
 * the link like this:
 *
 * {@literal <a href="./com/sun/javadoc/package-summary.html">The package Page</a>}
 *
 * @param doc the Doc object whose documentation is being written.
 * @param text the text being written.
 *
 * @return the text, with all the relative links redirected to work.
 */
private String redirectRelativeLinks(Doc doc, String text) {
    if (doc == null || shouldNotRedirectRelativeLinks()) {
        return text;
    }

    DocPath redirectPathFromRoot;
    if (doc instanceof ClassDoc) {
        redirectPathFromRoot = DocPath.forPackage(((ClassDoc) doc).containingPackage());
    } else if (doc instanceof MemberDoc) {
        redirectPathFromRoot = DocPath.forPackage(((MemberDoc) doc).containingPackage());
    } else if (doc instanceof PackageDoc) {
        redirectPathFromRoot = DocPath.forPackage((PackageDoc) doc);
    } else {
        return text;
    }

    //Redirect all relative links.
    int end, begin = StringUtils.indexOfIgnoreCase(text, "<a");
    if(begin >= 0){
        StringBuilder textBuff = new StringBuilder(text);

        while(begin >=0){
            if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
                begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
                continue;
            }

            begin = textBuff.indexOf("=", begin) + 1;
            end = textBuff.indexOf(">", begin +1);
            if(begin == 0){
                //Link has no equal symbol.
                configuration.root.printWarning(
                    doc.position(),
                    configuration.getText("doclet.malformed_html_link_tag", text));
                break;
            }
            if (end == -1) {
                //Break without warning.  This <a> tag is not necessarily malformed.  The text
                //might be missing '>' character because the href has an inline tag.
                break;
            }
            if (textBuff.substring(begin, end).indexOf("\"") != -1){
                begin = textBuff.indexOf("\"", begin) + 1;
                end = textBuff.indexOf("\"", begin +1);
                if (begin == 0 || end == -1){
                    //Link is missing a quote.
                    break;
                }
            }
            String relativeLink = textBuff.substring(begin, end);
            String relativeLinkLowerCase = StringUtils.toLowerCase(relativeLink);
            if (!(relativeLinkLowerCase.startsWith("mailto:") ||
                    relativeLinkLowerCase.startsWith("http:") ||
                    relativeLinkLowerCase.startsWith("https:") ||
                    relativeLinkLowerCase.startsWith("file:"))) {
                relativeLink = "{@"+(new DocRootTaglet()).getName() + "}/"
                    + redirectPathFromRoot.resolve(relativeLink).getPath();
                textBuff.replace(begin, end, relativeLink);
            }
            begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
        }
        return textBuff.toString();
    }
    return text;
}