Created
July 21, 2017 22:08
-
-
Save jyeary/38edc1be1d9c0a7c5fb3afc5748859df to your computer and use it in GitHub Desktop.
An example of how to use the autolink-java framework.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]> | |
* @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