Index: /applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java
===================================================================
--- /applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java	(revision 26909)
+++ /applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java	(revision 26910)
@@ -6,6 +6,18 @@
 
 public class TemplatedTMSTileSource extends TMSTileSource {
-    Random rand = null;
-    String[] randomParts = null;
+    
+    private Random rand = null;
+    private String[] randomParts = null;
+    
+    public static final String PATTERN_ZOOM    = "\\{zoom\\}";
+    public static final String PATTERN_X       = "\\{x\\}";
+    public static final String PATTERN_Y       = "\\{y\\}";
+    public static final String PATTERN_Y_YAHOO = "\\{!y\\}";
+    public static final String PATTERN_SWITCH  = "\\{switch:[^}]+\\}";
+    
+    public static final String[] ALL_PATTERNS = {
+        PATTERN_ZOOM, PATTERN_X, PATTERN_Y, PATTERN_Y_YAHOO, PATTERN_SWITCH
+    };
+    
     public TemplatedTMSTileSource(String name, String url, int maxZoom) {
         super(name, url, maxZoom);
@@ -14,6 +26,6 @@
     public TemplatedTMSTileSource(String name, String url, int minZoom, int maxZoom) {
         super(name, url, minZoom, maxZoom);
-        Matcher m = Pattern.compile(".*\\{switch:([^}]+)\\}.*").matcher(url);
-        if(m.matches()) {
+        Matcher m = Pattern.compile(".*"+PATTERN_SWITCH+".*").matcher(url);
+        if (m.matches()) {
             rand = new Random();
             randomParts = m.group(1).split(",");
@@ -24,11 +36,10 @@
     public String getTileUrl(int zoom, int tilex, int tiley) {
         String r = this.baseUrl
-        .replaceAll("\\{zoom\\}", Integer.toString(zoom))
-        .replaceAll("\\{x\\}", Integer.toString(tilex))
-        .replaceAll("\\{y\\}", Integer.toString(tiley))
-        .replaceAll("\\{!y\\}", Integer.toString((int)Math.pow(2, zoom)-1-tiley));
-        if(rand != null) {
-            r = r.replaceAll("\\{switch:[^}]+\\}",
-            randomParts[rand.nextInt(randomParts.length)]);
+            .replaceAll(PATTERN_ZOOM, Integer.toString(zoom))
+            .replaceAll(PATTERN_X, Integer.toString(tilex))
+            .replaceAll(PATTERN_Y, Integer.toString(tiley))
+            .replaceAll(PATTERN_Y_YAHOO, Integer.toString((int)Math.pow(2, zoom)-1-tiley));
+        if (rand != null) {
+            r = r.replaceAll(PATTERN_SWITCH, randomParts[rand.nextInt(randomParts.length)]);
         }
         return r;
