Changeset 11975 in josm for trunk/scripts
- Timestamp:
- 2017-04-22T18:55:26+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/SyncEditorLayerIndex.groovy
r11968 r11975 197 197 myprintln "*** Loaded ${eliEntries.size()} entries (ELI). ***" 198 198 } 199 String cdata(def s) { 200 if(s =~ /[<>&]/) 199 String cdata(def s, boolean escape = false) { 200 if(escape) { 201 return s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">") 202 } else if(s =~ /[<>&]/) 201 203 return "<![CDATA[$s]]>" 202 204 return s … … 204 206 205 207 String maininfo(def entry, String offset) { 206 String res = offset + "<type>${getType(entry)}</type>\n" 208 String t = getType(entry) 209 String res = offset + "<type>$t</type>\n" 207 210 res += offset + "<url>${cdata(getUrl(entry))}</url>\n" 208 if( getType(entry)== "tms") {211 if(t == "tms") { 209 212 if(getMinZoom(entry) != null) 210 213 res += offset + "<min-zoom>${getMinZoom(entry)}</min-zoom>\n" 211 214 if(getMaxZoom(entry) != null) 212 215 res += offset + "<max-zoom>${getMaxZoom(entry)}</max-zoom>\n" 216 } else if (t == "wms") { 217 def p = getProjections(entry) 218 if (p) { 219 res += offset + "<projections>\n" 220 for (def c : p) 221 res += offset + " <code>$c</code>\n" 222 res += offset + "</projections>\n" 223 } 213 224 } 214 225 return res … … 223 234 def best = "eli-best".equals(getQuality(e)) 224 235 stream.write " <entry"+(best ? " eli-best=\"true\"" : "" )+">\n" 225 stream.write " <name>${ getName(e)}</name>\n"236 stream.write " <name>${cdata(getName(e), true)}</name>\n" 226 237 stream.write " <id>${getId(e)}</id>\n" 227 238 def t … … 230 241 if((t = getCountryCode(e))) 231 242 stream.write " <country-code>$t</country-code>\n" 243 stream.write maininfo(e, " ") 244 if((t = getAttributionText(e))) 245 stream.write " <attribution-text mandatory=\"true\">${cdata(t, true)}</attribution-text>\n" 246 if((t = getAttributionUrl(e))) 247 stream.write " <attribution-url>${cdata(t)}</attribution-url>\n" 248 if((t = getTermsOfUseText(e))) 249 stream.write " <terms-of-use-text>${cdata(t, true)}</terms-of-use-text>\n" 250 if((t = getTermsOfUseUrl(e))) 251 stream.write " <terms-of-use-url>${cdata(t)}</terms-of-use-url>\n" 252 if((t = getPermissionReferenceUrl(e))) 253 stream.write " <permission-ref>${cdata(t)}</permission-ref>\n" 254 if((getValidGeoreference(e))) 255 stream.write " <valid-georeference>true</valid-georeference>\n" 232 256 if((t = getIcon(e))) 233 257 stream.write " <icon>${cdata(t)}</icon>\n" 234 stream.write maininfo(e, " ") 258 for (def d : getDescriptions(e)) { 259 stream.write " <description lang=\"${d.getKey()}\">${d.getValue()}</description>\n" 260 } 235 261 for (def m : getMirrors(e)) { 236 262 stream.write " <mirror>\n"+maininfo(m, " ")+" </mirror>\n" … … 616 642 return [] 617 643 } 644 static List<Object> getProjections(Object e) { 645 def r 646 if (e instanceof ImageryInfo) { 647 r = e.getServerProjections() 648 } else { 649 r = e.get("properties").get("available_projections") 650 } 651 return r ? r : [] 652 } 618 653 static List<Shape> getShapes(Object e) { 619 654 if (e instanceof ImageryInfo) { … … 680 715 return e.get("properties").getString("icon", null) 681 716 } 717 static String getAttributionText(Object e) { 718 if (e instanceof ImageryInfo) return e.getAttributionText(0, null, null) 719 try {return e.get("properties").get("attribution").getString("text", null)} catch (NullPointerException ex) {return null} 720 } 721 static String getAttributionUrl(Object e) { 722 if (e instanceof ImageryInfo) return e.getAttributionLinkURL() 723 try {return e.get("properties").get("attribution").getString("url", null)} catch (NullPointerException ex) {return null} 724 } 725 static String getTermsOfUseText(Object e) { 726 if (e instanceof ImageryInfo) return e.getTermsOfUseText() 727 return null 728 } 729 static String getTermsOfUseUrl(Object e) { 730 if (e instanceof ImageryInfo) return e.getTermsOfUseURL() 731 return null 732 } 733 static String getPermissionReferenceUrl(Object e) { 734 if (e instanceof ImageryInfo) return e.getPermissionReferenceURL() 735 return e.get("properties").getString("license_url", null) 736 } 737 static Map<String,String> getDescriptions(Object e) { 738 Map<String,String> res = new HashMap<String, String>() 739 if (e instanceof ImageryInfo) { 740 String a = e.getDescription() 741 if (a) res.put("en", a) 742 } else { 743 String a = e.get("properties").getString("description", null) 744 if (a) res.put("en", a) 745 } 746 return res 747 } 748 static Boolean getValidGeoreference(Object e) { 749 if (e instanceof ImageryInfo) return e.isGeoreferenceValid() 750 return false 751 } 682 752 String getDescription(Object o) { 683 753 def url = getUrl(o)
Note:
See TracChangeset
for help on using the changeset viewer.