All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.nemerosa.ontrack.model.support.LinkFreeTextAnnotatorContributor.kt Maven / Gradle / Ivy

There is a newer version: 4.4.5
Show newest version
package net.nemerosa.ontrack.model.support

import net.nemerosa.ontrack.model.structure.ProjectEntity
import org.springframework.stereotype.Component
import java.util.regex.Pattern

/**
 * Provides an annotator which transforms any HTTP link
 * into an actual link.
 */
@Component
class LinkFreeTextAnnotatorContributor : FreeTextAnnotatorContributor {

    private val pattern = Pattern.compile("((https?://|ftp://|www\\.)\\S+)")

    override fun getMessageAnnotators(entity: ProjectEntity): List =
            listOf(
                    RegexMessageAnnotator(
                            pattern
                    ) { link ->
                        MessageAnnotation.of("a")
                                .attr("href", link)
                                .attr("target", "_blank")
                                .text(link)
                    }
            )
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy