Package org.openstreetmap.josm.tools
Class Tag2Link
- java.lang.Object
-
- org.openstreetmap.josm.tools.Tag2Link
-
public final class Tag2Link extends java.lang.Object
Extracts web links from OSM tags.The following rules are used:
- internal rules for basic tags
- rules from Wikidata based on OSM tag or key (P1282); formatter URL (P1630); third-party formatter URL (P3303)
- rules from OSM Sophox based on permanent key ID (P16); formatter URL (P8)
- Since:
- 15673
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Tag2Link.LinkConsumer
Represents an operation that accepts a link.
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
languagePattern
private static java.util.regex.Pattern
PATTERN_DOLLAR_ONE
(package private) static CachingProperty<java.util.List<java.lang.String>>
PREF_SEARCH_ENGINES
(package private) static ListProperty
PREF_SOURCE
(package private) static java.util.Map<java.lang.String,java.util.function.UnaryOperator<java.lang.String>>
valueFormatter
(package private) static MultiMap<java.lang.String,java.lang.String>
wikidataRules
Maps OSM keys to formatter URLs from Wikidata and OSM Sophox where"$1"
has to be replaced by a value.
-
Constructor Summary
Constructors Modifier Constructor Description private
Tag2Link()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
getHost(java.lang.String url, java.lang.String fallback)
private static java.lang.String
getLinkName(java.lang.String url, java.lang.String fallback)
static void
getLinksForTag(java.lang.String key, java.lang.String value, Tag2Link.LinkConsumer linkConsumer)
Generates the links for the tag given bykey
andvalue
, and sends 0, 1 or more links to thelinkConsumer
.private static java.lang.String
getWikimediaCommonsUrl(java.lang.String i)
static void
initialize()
Initializes the tag2link rulesprivate static void
initializeFromResources(CachedFile resource)
Initializes the tag2link rules from the resources.
-
-
-
Field Detail
-
wikidataRules
static final MultiMap<java.lang.String,java.lang.String> wikidataRules
Maps OSM keys to formatter URLs from Wikidata and OSM Sophox where"$1"
has to be replaced by a value.
-
valueFormatter
static final java.util.Map<java.lang.String,java.util.function.UnaryOperator<java.lang.String>> valueFormatter
-
languagePattern
static final java.lang.String languagePattern
-
PREF_SOURCE
static final ListProperty PREF_SOURCE
-
PREF_SEARCH_ENGINES
static final CachingProperty<java.util.List<java.lang.String>> PREF_SEARCH_ENGINES
-
PATTERN_DOLLAR_ONE
private static final java.util.regex.Pattern PATTERN_DOLLAR_ONE
-
-
Constructor Detail
-
Tag2Link
private Tag2Link()
-
-
Method Detail
-
initialize
public static void initialize()
Initializes the tag2link rules
-
initializeFromResources
private static void initializeFromResources(CachedFile resource) throws java.io.IOException
Initializes the tag2link rules from the resources.- Parameters:
resource
- the source- Throws:
java.io.IOException
- in case of I/O error
-
getLinksForTag
public static void getLinksForTag(java.lang.String key, java.lang.String value, Tag2Link.LinkConsumer linkConsumer)
Generates the links for the tag given bykey
andvalue
, and sends 0, 1 or more links to thelinkConsumer
.- Parameters:
key
- the tag keyvalue
- the tag valuelinkConsumer
- the receiver of the generated links
-
getWikimediaCommonsUrl
private static java.lang.String getWikimediaCommonsUrl(java.lang.String i)
-
getLinkName
private static java.lang.String getLinkName(java.lang.String url, java.lang.String fallback)
-
getHost
private static java.lang.String getHost(java.lang.String url, java.lang.String fallback)
-
-