@Test public void uriInMiddleAfterInput() { String prefix = "prefix "; String uri = "http: String text = prefix + uri; parser.linkifyUri(text, prefix.length(), outputBuffer); assertLinkOnly(uri, outputBuffer); }
@Override public int linkifyUri(String text, int startPos, StringBuffer outputBuffer) { int currentPos = startPos; String shortScheme = text.substring(currentPos, Math.min(currentPos + 7, text.length())); String longScheme = text.substring(currentPos, Math.min(currentPos + 8, text.length())); if (longScheme.equalsIgnoreCase("https: currentPos += "https: } else if (shortScheme.equalsIgnoreCase("http: currentPos += "http: } else if (shortScheme.equalsIgnoreCase("rtsp: currentPos += "rtsp: } else { return startPos; } int matchedAuthorityEnd = tryMatchAuthority(text, currentPos); if (matchedAuthorityEnd == currentPos) { return startPos; } currentPos = matchedAuthorityEnd; if (currentPos < text.length() && text.charAt(currentPos) == '/') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, "/:@"); } if (currentPos < text.length() && text.charAt(currentPos) == '?') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } if (currentPos < text.length() && text.charAt(currentPos) == '#') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } String httpUri = text.substring(startPos, currentPos); outputBuffer.append("<a href=\"") .append(httpUri) .append("\">") .append(httpUri) .append("</a>"); return currentPos; }
HttpUriParser implements UriParser { @Override public int linkifyUri(String text, int startPos, StringBuffer outputBuffer) { int currentPos = startPos; String shortScheme = text.substring(currentPos, Math.min(currentPos + 7, text.length())); String longScheme = text.substring(currentPos, Math.min(currentPos + 8, text.length())); if (longScheme.equalsIgnoreCase("https: currentPos += "https: } else if (shortScheme.equalsIgnoreCase("http: currentPos += "http: } else if (shortScheme.equalsIgnoreCase("rtsp: currentPos += "rtsp: } else { return startPos; } int matchedAuthorityEnd = tryMatchAuthority(text, currentPos); if (matchedAuthorityEnd == currentPos) { return startPos; } currentPos = matchedAuthorityEnd; if (currentPos < text.length() && text.charAt(currentPos) == '/') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, "/:@"); } if (currentPos < text.length() && text.charAt(currentPos) == '?') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } if (currentPos < text.length() && text.charAt(currentPos) == '#') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } String httpUri = text.substring(startPos, currentPos); outputBuffer.append("<a href=\"") .append(httpUri) .append("\">") .append(httpUri) .append("</a>"); return currentPos; } }
HttpUriParser implements UriParser { @Override public int linkifyUri(String text, int startPos, StringBuffer outputBuffer) { int currentPos = startPos; String shortScheme = text.substring(currentPos, Math.min(currentPos + 7, text.length())); String longScheme = text.substring(currentPos, Math.min(currentPos + 8, text.length())); if (longScheme.equalsIgnoreCase("https: currentPos += "https: } else if (shortScheme.equalsIgnoreCase("http: currentPos += "http: } else if (shortScheme.equalsIgnoreCase("rtsp: currentPos += "rtsp: } else { return startPos; } int matchedAuthorityEnd = tryMatchAuthority(text, currentPos); if (matchedAuthorityEnd == currentPos) { return startPos; } currentPos = matchedAuthorityEnd; if (currentPos < text.length() && text.charAt(currentPos) == '/') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, "/:@"); } if (currentPos < text.length() && text.charAt(currentPos) == '?') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } if (currentPos < text.length() && text.charAt(currentPos) == '#') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } String httpUri = text.substring(startPos, currentPos); outputBuffer.append("<a href=\"") .append(httpUri) .append("\">") .append(httpUri) .append("</a>"); return currentPos; }  }
HttpUriParser implements UriParser { @Override public int linkifyUri(String text, int startPos, StringBuffer outputBuffer) { int currentPos = startPos; String shortScheme = text.substring(currentPos, Math.min(currentPos + 7, text.length())); String longScheme = text.substring(currentPos, Math.min(currentPos + 8, text.length())); if (longScheme.equalsIgnoreCase("https: currentPos += "https: } else if (shortScheme.equalsIgnoreCase("http: currentPos += "http: } else if (shortScheme.equalsIgnoreCase("rtsp: currentPos += "rtsp: } else { return startPos; } int matchedAuthorityEnd = tryMatchAuthority(text, currentPos); if (matchedAuthorityEnd == currentPos) { return startPos; } currentPos = matchedAuthorityEnd; if (currentPos < text.length() && text.charAt(currentPos) == '/') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, "/:@"); } if (currentPos < text.length() && text.charAt(currentPos) == '?') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } if (currentPos < text.length() && text.charAt(currentPos) == '#') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } String httpUri = text.substring(startPos, currentPos); outputBuffer.append("<a href=\"") .append(httpUri) .append("\">") .append(httpUri) .append("</a>"); return currentPos; }  @Override int linkifyUri(String text, int startPos, StringBuffer outputBuffer); }
HttpUriParser implements UriParser { @Override public int linkifyUri(String text, int startPos, StringBuffer outputBuffer) { int currentPos = startPos; String shortScheme = text.substring(currentPos, Math.min(currentPos + 7, text.length())); String longScheme = text.substring(currentPos, Math.min(currentPos + 8, text.length())); if (longScheme.equalsIgnoreCase("https: currentPos += "https: } else if (shortScheme.equalsIgnoreCase("http: currentPos += "http: } else if (shortScheme.equalsIgnoreCase("rtsp: currentPos += "rtsp: } else { return startPos; } int matchedAuthorityEnd = tryMatchAuthority(text, currentPos); if (matchedAuthorityEnd == currentPos) { return startPos; } currentPos = matchedAuthorityEnd; if (currentPos < text.length() && text.charAt(currentPos) == '/') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, "/:@"); } if (currentPos < text.length() && text.charAt(currentPos) == '?') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } if (currentPos < text.length() && text.charAt(currentPos) == '#') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } String httpUri = text.substring(startPos, currentPos); outputBuffer.append("<a href=\"") .append(httpUri) .append("\">") .append(httpUri) .append("</a>"); return currentPos; }  @Override int linkifyUri(String text, int startPos, StringBuffer outputBuffer);  }