java-autolinker

An extendable autolinking library

License

License

Categories

Categories

Java Languages Auto Application Layer Libs Code Generators
GroupId

GroupId

eu.michael-simons
ArtifactId

ArtifactId

java-autolinker
Last Version

Last Version

0.3.1
Release Date

Release Date

Type

Type

jar
Description

Description

java-autolinker
An extendable autolinking library
Project URL

Project URL

http://info.michael-simons.eu/2011/11/28/java-stuff/
Project Organization

Project Organization

michael-simons.eu
Source Code Management

Source Code Management

https://github.com/michael-simons/java-autolinker

Download java-autolinker

How to add to project

<!-- https://jarcasting.com/artifacts/eu.michael-simons/java-autolinker/ -->
<dependency>
    <groupId>eu.michael-simons</groupId>
    <artifactId>java-autolinker</artifactId>
    <version>0.3.1</version>
</dependency>
// https://jarcasting.com/artifacts/eu.michael-simons/java-autolinker/
implementation 'eu.michael-simons:java-autolinker:0.3.1'
// https://jarcasting.com/artifacts/eu.michael-simons/java-autolinker/
implementation ("eu.michael-simons:java-autolinker:0.3.1")
'eu.michael-simons:java-autolinker:jar:0.3.1'
<dependency org="eu.michael-simons" name="java-autolinker" rev="0.3.1">
  <artifact name="java-autolinker" type="jar" />
</dependency>
@Grapes(
@Grab(group='eu.michael-simons', module='java-autolinker', version='0.3.1')
)
libraryDependencies += "eu.michael-simons" % "java-autolinker" % "0.3.1"
[eu.michael-simons/java-autolinker "0.3.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.jsoup : jsoup jar 1.11.3
org.yaml : snakeyaml jar

test (1)

Group / Artifact Type Version
junit : junit jar

Project Modules

There are no modules declared in this project.

An extendable autolinking library

Maven Central

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.

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).

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.

Versions

Version
0.3.1
0.2.1
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1