Changeset 11975 in josm


Ignore:
Timestamp:
2017-04-22T18:55:26+02:00 (7 years ago)
Author:
stoecker
Message:

see #14655 - implement nearly all features in ELI sync XML output

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/SyncEditorLayerIndex.groovy

    r11968 r11975  
    197197        myprintln "*** Loaded ${eliEntries.size()} entries (ELI). ***"
    198198    }
    199     String cdata(def s) {
    200         if(s =~ /[<>&]/)
     199    String cdata(def s, boolean escape = false) {
     200        if(escape) {
     201            return s.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;")
     202        } else if(s =~ /[<>&]/)
    201203            return "<![CDATA[$s]]>"
    202204       return s
     
    204206
    205207    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"
    207210        res += offset + "<url>${cdata(getUrl(entry))}</url>\n"
    208         if(getType(entry) == "tms") {
     211        if(t == "tms") {
    209212            if(getMinZoom(entry) != null)
    210213                res += offset + "<min-zoom>${getMinZoom(entry)}</min-zoom>\n"
    211214            if(getMaxZoom(entry) != null)
    212215                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            }
    213224        }
    214225        return res
     
    223234            def best = "eli-best".equals(getQuality(e))
    224235            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"
    226237            stream.write "        <id>${getId(e)}</id>\n"
    227238            def t
     
    230241            if((t = getCountryCode(e)))
    231242                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"
    232256            if((t = getIcon(e)))
    233257                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            }
    235261            for (def m : getMirrors(e)) {
    236262                    stream.write "        <mirror>\n"+maininfo(m, "            ")+"        </mirror>\n"
     
    616642        return []
    617643    }
     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    }
    618653    static List<Shape> getShapes(Object e) {
    619654        if (e instanceof ImageryInfo) {
     
    680715        return e.get("properties").getString("icon", null)
    681716    }
     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    }
    682752    String getDescription(Object o) {
    683753        def url = getUrl(o)
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r11889 r11975  
    175175    /** Text of a text attribution displayed when using the imagery */
    176176    private String attributionText;
    177     /** Link behing the text attribution displayed when using the imagery */
     177    /** Link to a reference stating the permission for OSM usage */
     178    private String permissionReferenceURL;
     179    /** Link behind the text attribution displayed when using the imagery */
    178180    private String attributionLinkURL;
    179181    /** Image of a graphical attribution displayed when using the imagery */
     
    222224        @pref String attribution_text;
    223225        @pref String attribution_url;
     226        @pref String permission_reference_url;
    224227        @pref String logo_image;
    225228        @pref String logo_url;
     
    265268            attribution_text = i.attributionText;
    266269            attribution_url = i.attributionLinkURL;
     270            permission_reference_url = i.permissionReferenceURL;
    267271            date = i.date;
    268272            bestMarked = i.bestMarked;
     
    429433        attributionText = e.attribution_text;
    430434        attributionLinkURL = e.attribution_url;
     435        permissionReferenceURL = e.permission_reference_url;
    431436        attributionImage = e.logo_image;
    432437        attributionImageURL = e.logo_url;
     
    470475        this.attributionText = i.attributionText;
    471476        this.attributionLinkURL = i.attributionLinkURL;
     477        this.permissionReferenceURL = i.permissionReferenceURL;
    472478        this.attributionImage = i.attributionImage;
    473479        this.attributionImageURL = i.attributionImageURL;
     
    520526                Objects.equals(this.attributionText, other.attributionText) &&
    521527                Objects.equals(this.attributionLinkURL, other.attributionLinkURL) &&
     528                Objects.equals(this.permissionReferenceURL, other.permissionReferenceURL) &&
    522529                Objects.equals(this.attributionImageURL, other.attributionImageURL) &&
    523530                Objects.equals(this.attributionImage, other.attributionImage) &&
     
    633640    }
    634641
     642    /**
     643     * Return the permission reference URL.
     644     * @param url The url.
     645     * @see #setPermissionReferenceURL()
     646     * @since 11975
     647     */
     648    public String getPermissionReferenceURL() {
     649        return permissionReferenceURL;
     650    }
     651
    635652    @Override
    636653    public Image getAttributionImage() {
     
    691708    public void setAttributionLinkURL(String url) {
    692709        attributionLinkURL = url;
     710    }
     711
     712    /**
     713     * Sets the permission reference URL.
     714     * @param url The url.
     715     * @see #getPermissionReferenceURL()
     716     * @since 11975
     717     */
     718    public void setPermissionReferenceURL(String url) {
     719        permissionReferenceURL = url;
    693720    }
    694721
  • trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java

    r11913 r11975  
    197197                        "terms-of-use-text",
    198198                        "terms-of-use-url",
     199                        "permission-ref",
    199200                        "country-code",
    200201                        "icon",
     
    437438                    entry.setTermsOfUseText(accumulator.toString());
    438439                    break;
     440                case "permission-ref":
     441                    entry.setPermissionReferenceURL(accumulator.toString());
     442                    break;
    439443                case "terms-of-use-url":
    440444                    entry.setTermsOfUseURL(accumulator.toString());
Note: See TracChangeset for help on using the changeset viewer.