Changeset 16836 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2020-08-03T20:39:45+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Tag2Link.java
r16835 r16836 9 9 import java.net.MalformedURLException; 10 10 import java.net.URL; 11 import java.util.Arrays; 11 12 import java.util.Collections; 13 import java.util.List; 12 14 import java.util.Map; 13 15 import java.util.function.UnaryOperator; … … 15 17 import java.util.regex.Pattern; 16 18 import java.util.stream.Collectors; 17 import java.util.stream.Stream;18 19 19 20 import javax.json.Json; … … 23 24 24 25 import org.openstreetmap.josm.data.osm.OsmUtils; 26 import org.openstreetmap.josm.data.preferences.CachingProperty; 25 27 import org.openstreetmap.josm.data.preferences.ListProperty; 26 28 import org.openstreetmap.josm.io.CachedFile; … … 59 61 Collections.singletonList("resource://META-INF/resources/webjars/tag2link/2020.8.3/index.json")); 60 62 63 static final CachingProperty<List<String>> PREF_SEARCH_ENGINES = new ListProperty("tag2link.search", 64 Arrays.asList("https://duckduckgo.com/?q=$1", "https://www.google.com/search?q=$1")).cached(); 65 61 66 private Tag2Link() { 62 67 // private constructor for utility class … … 139 144 // Search 140 145 if (key.matches("^(.+[:_])?name([:_]" + languagePattern + ")?$")) { 141 linkConsumer.acceptLink(tr("Search on DuckDuckGo"), "https://duckduckgo.com/?q=" + value); 146 PREF_SEARCH_ENGINES.get().forEach(url -> 147 linkConsumer.acceptLink(tr("Search on {0}", getHost(url, url)), url.replace("$1", Utils.encodeUrl(value)))); 142 148 } 143 149 … … 192 198 193 199 private static String getLinkName(String url, String fallback) { 200 return tr("Open {0}", getHost(url, fallback)); 201 } 202 203 private static String getHost(String url, String fallback) { 194 204 try { 195 return tr("Open {0}", new URL(url).getHost());205 return new URL(url).getHost().replaceFirst("^www\\.", ""); 196 206 } catch (MalformedURLException e) { 197 return tr("Open {0}", fallback);207 return fallback; 198 208 } 199 209 }
Note:
See TracChangeset
for help on using the changeset viewer.