https://github.com/michael-simons/java-autolinker
An extendable autolinking library
https://github.com/michael-simons/java-autolinker
autolink java
Last synced: over 1 year ago
JSON representation
An extendable autolinking library
- Host: GitHub
- URL: https://github.com/michael-simons/java-autolinker
- Owner: michael-simons
- Created: 2010-12-28T20:07:38.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2018-06-16T11:24:07.000Z (about 8 years ago)
- Last Synced: 2025-03-18T05:52:21.341Z (over 1 year ago)
- Topics: autolink, java
- Language: Java
- Homepage:
- Size: 147 KB
- Stars: 3
- Watchers: 2
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.textile
Awesome Lists containing this project
README
h1. An extendable autolinking library
!https://travis-ci.org/michael-simons/java-autolinker.svg?branch=master!:https://travis-ci.org/michael-simons/java-autolinker !https://maven-badges.herokuapp.com/maven-central/eu.michael-simons/java-autolinker/badge.svg(Maven Central)!:https://maven-badges.herokuapp.com/maven-central/eu.michael-simons/java-autolinker
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":http://jsoup.org/ 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.
The project is a ready to use configured maven project and has nearly 100% test coverage.
*Important*
Since version 0.1.1 this project is Java 8 *only*.
Since version 0.2.1 this project is Java 10+ *only*. In addition, it uses Spring Boots dependency management.
Since version 0.3.1 I have changed the API of _AutoLinkService_ and removed _Optional<>_ as input parameter as suggested by various people (Joshua Bloch, Simon Harrer and others).
h2. Usage
h3. 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
h3. 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.