Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

An extendable autolinking library

Notifications You must be signed in to change notification settings

upwork/java-autolinker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 

Repository files navigation

An extendable autolinking library

Under the impression that it is nearly impossible to write a robust autolinker without parsing the input text to a dom tree, i’ve written an autolinker that uses Jsoup to build trees and proccess them in a way that new types of links can easily be added.

The core service of this project is the AutoLinkService which uses several AutoLinkers to add links to arbitrary text. 3 autolinkers (URLs, E-Mail adresses and Twitter Handles) are build in.

Since version 0.1.1 this project is Java 8 only.

The project is a ready to use configured maven project and has nearly 100% test coverage.

Usage

Standalone


public static void main(String... args) {
	// Instantiate AutoLinkService using all available autolinkers
	final AutoLinkService autoLinkService = new AutoLinkService(Arrays.asList(
		new EmailAddressAutoLinker(true, true),
		new TwitterUserAutoLinker(),
		new UrlAutoLinker(30)
	));
	// Autolink stuff
	System.out.println(autoLinkService.addLinks("Maybe there's a link http://michael-simons.eu to @rotnroll666", Optional.empty()));
}

or have a look at the test code.

The AutoLinkService can be easily registered as a

As a Spring bean


@Bean
public AutoLinkService autoLinkService(
  @Value("${dailyfratze.emailAddressAutoLinker.hexEncodeEmailAddress:true}") boolean hexEncodeEmailAddress,
  @Value("${dailyfratze.emailAddressAutoLinker.obfuscateEmailAddress:true}") boolean obfuscateEmailAddress,
  @Value("${dailyfratze.urlAutoLinker.maxLabelLength:30}") int maxLabelLength	    
) {
  return new AutoLinkService(Arrays.asList(
  		new EmailAddressAutoLinker(hexEncodeEmailAddress, obfuscateEmailAddress),
  		new TwitterUserAutoLinker(),
  		new UrlAutoLinker(maxLabelLength)		
  ));
}

I assume you know what you’re doing with Spring, so i don’t explain that further.

Enjoy and if you find that library usefull, drop me a line or star it. Thanks.

About

An extendable autolinking library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%