Skip to content

Instantly share code, notes, and snippets.

@jyeary
Created July 21, 2017 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jyeary/38edc1be1d9c0a7c5fb3afc5748859df to your computer and use it in GitHub Desktop.
Save jyeary/38edc1be1d9c0a7c5fb3afc5748859df to your computer and use it in GitHub Desktop.
An example of how to use the autolink-java framework.
package com.bluelotussoftware.autolink;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.EnumSet;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.nibor.autolink.LinkExtractor;
import org.nibor.autolink.LinkSpan;
import org.nibor.autolink.LinkType;
/**
*
* @author John Yeary <jyeary@bluelotussoftware.com>
* @version 1.0.0
*/
public class ExtractorExample {
public static void main(String[] args) throws FileNotFoundException, IOException {
List<String> lines = IOUtils.readLines(new FileReader("target/classes/links2.html"));
LinkExtractor linkExtractor = LinkExtractor.builder()
.linkTypes(EnumSet.of(LinkType.URL, LinkType.WWW, LinkType.EMAIL))
.build();
lines.forEach((String line) -> {
Iterable<LinkSpan> links = linkExtractor.extractLinks(line);
for (LinkSpan link : links) {
System.out.println(MessageFormat.format("{0} : {1}", link.getType(), line.substring(link.getBeginIndex(), link.getEndIndex())));
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment