Ticket #6532: imagery-xml-v2.patch
| File imagery-xml-v2.patch, 24.5 KB (added by , 15 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/layer/WMSLayer.java
695 695 oos.writeInt(imageSize); 696 696 oos.writeDouble(info.getPixelPerDegree()); 697 697 oos.writeObject(info.getName()); 698 oos.writeObject(info.get FullUrl());698 oos.writeObject(info.getExtendedUrl()); 699 699 oos.writeObject(images); 700 700 oos.close(); 701 701 } … … 734 734 imageSize = ois.readInt(); 735 735 info.setPixelPerDegree(ois.readDouble()); 736 736 doSetName((String)ois.readObject()); 737 info.set Url((String) ois.readObject());737 info.setExtendedUrl((String) ois.readObject()); 738 738 images = (GeorefImage[][])ois.readObject(); 739 739 ois.close(); 740 740 fis.close(); -
src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java
591 591 case 0: 592 592 return info.getName(); 593 593 case 1: 594 return info.get FullUrl();594 return info.getExtendedUrl(); 595 595 case 2: 596 596 return (info.getImageryType() == ImageryType.WMS || info.getImageryType() == ImageryType.HTML) ? 597 597 (info.getPixelPerDegree() == 0.0 ? "" : info.getPixelPerDegree()) : … … 609 609 info.setName((String) o); 610 610 break; 611 611 case 1: 612 info.set Url((String)o);612 info.setExtendedUrl((String)o); 613 613 break; 614 614 case 2: 615 615 info.setPixelPerDegree(0); … … 658 658 case 0: 659 659 return info.getName(); 660 660 case 1: 661 return info.get FullUrl();661 return info.getExtendedUrl(); 662 662 } 663 663 return null; 664 664 } -
src/org/openstreetmap/josm/io/imagery/ImageryReader.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.io.imagery; 3 4 import static org.openstreetmap.josm.tools.Utils.equal; 5 6 import java.io.IOException; 7 import java.io.InputStream; 8 import java.util.ArrayList; 9 import java.util.Arrays; 10 import java.util.List; 11 import java.util.Stack; 12 13 import javax.xml.parsers.ParserConfigurationException; 14 import javax.xml.parsers.SAXParserFactory; 15 16 import org.openstreetmap.josm.data.Bounds; 17 import org.openstreetmap.josm.data.imagery.ImageryInfo; 18 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 19 import org.openstreetmap.josm.io.UTFInputStreamReader; 20 import org.xml.sax.Attributes; 21 import org.xml.sax.InputSource; 22 import org.xml.sax.SAXException; 23 import org.xml.sax.helpers.DefaultHandler; 24 25 public class ImageryReader { 26 27 private InputSource inputSource; 28 29 private final static boolean debug = true; 30 31 private enum State { INIT, IMAGERY, ENTRY, ENTRY_ATTRIBUTE } 32 33 public ImageryReader(InputStream source) throws IOException { 34 this.inputSource = new InputSource(UTFInputStreamReader.create(source, "UTF-8")); 35 } 36 37 public List<ImageryInfo> parse() throws SAXException, IOException { 38 Parser parser = new Parser(); 39 try { 40 SAXParserFactory factory = SAXParserFactory.newInstance(); 41 factory.setNamespaceAware(true); 42 factory.newSAXParser().parse(inputSource, parser); 43 return parser.entries; 44 } catch (SAXException e) { 45 throw e; 46 } catch (ParserConfigurationException e) { 47 e.printStackTrace(); // broken SAXException chaining 48 throw new SAXException(e); 49 } 50 } 51 52 53 private class Parser extends DefaultHandler { 54 private StringBuffer accumulator = new StringBuffer(); 55 56 private Stack<State> states; 57 58 List<ImageryInfo> entries; 59 60 /** 61 * When entering an unknown element, don't try to recognize 62 * the inner content. Just keep track of the nesting depth and 63 * go on when the unknown element is finished. 64 */ 65 int unknownLevel; 66 /** 67 * Skip the current entry because it has mandatory attributes 68 * that this version of JOSM cannot process. 69 */ 70 boolean skipEntry; 71 72 ImageryInfo entry; 73 Bounds bounds; 74 75 @Override public void startDocument() { 76 accumulator = new StringBuffer(); 77 unknownLevel = 0; 78 skipEntry = false; 79 states = new Stack<State>(); 80 states.push(State.INIT); 81 entries = new ArrayList<ImageryInfo>(); 82 entry = null; 83 bounds = null; 84 } 85 86 @Override 87 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 88 if (debug) System.err.println("<"+qName+">"+(unknownLevel > 0 ? "["+unknownLevel+"]" : "")); 89 90 accumulator.setLength(0); 91 State newState = null; 92 known:{ 93 if (unknownLevel > 0) { 94 break known; 95 } else { 96 switch (states.peek()) { 97 case INIT: 98 if (qName.equals("imagery")) { 99 newState = State.IMAGERY; 100 } else { 101 break known; 102 } 103 break; 104 case IMAGERY: 105 if (qName.equals("entry")) { 106 entry = new ImageryInfo(); 107 skipEntry = false; 108 newState = State.ENTRY; 109 } else { 110 break known; 111 } 112 break; 113 case ENTRY: 114 if (Arrays.asList(new String[] { 115 "name", 116 "type", 117 "default", 118 "url", 119 "eula", 120 "min-zoom", 121 "max-zoom", 122 "attribution-text", 123 "attribution-url", 124 "logo-image", 125 "logo-url", 126 "terms-of-use-text", 127 "terms-of-use-url", 128 }).contains(qName)) { 129 newState = State.ENTRY_ATTRIBUTE; 130 } else if (qName.equals("bounds")) { 131 try { 132 bounds = new Bounds( 133 atts.getValue("min-lat") + "," + 134 atts.getValue("min-lon") + "," + 135 atts.getValue("max-lat") + "," + 136 atts.getValue("max-lon"), ","); 137 } catch (IllegalArgumentException e) { 138 break known; 139 } 140 newState = State.ENTRY_ATTRIBUTE; 141 } else { 142 break known; 143 } 144 break; 145 default: 146 break known; 147 } 148 } 149 if (newState == null) throw new AssertionError(); 150 states.push(newState); 151 return; 152 } 153 unknownLevel++; 154 if (equal(atts.getValue("mandatory"), "true")) { 155 skipEntry = true; 156 } 157 } 158 159 @Override 160 public void characters(char[] ch, int start, int length) { 161 accumulator.append(ch, start, length); 162 } 163 164 @Override 165 public void endElement(String namespaceURI, String qName, String rqName) { 166 if (debug) System.err.println("</"+qName+">"+(unknownLevel > 0 ? "["+unknownLevel+"]" : "")); 167 168 if (unknownLevel > 0) { 169 unknownLevel--; 170 } else { 171 switch (states.pop()) { 172 case INIT: 173 throw new RuntimeException(); 174 case IMAGERY: 175 break; 176 case ENTRY: 177 if (qName.equals("entry")) { 178 if (!skipEntry) { 179 entries.add(entry); 180 } 181 entry = null; 182 } 183 break; 184 case ENTRY_ATTRIBUTE: 185 if (qName.equals("name")) { 186 entry.setName(accumulator.toString()); 187 } else if (qName.equals("type")) { 188 boolean found = false; 189 for (ImageryType type : ImageryType.values()) { 190 if (equal(accumulator.toString(), type.getUrlString())) { 191 entry.setImageryType(type); 192 found = true; 193 break; 194 } 195 } 196 if (!found) { 197 skipEntry = true; 198 } 199 } else if (qName.equals("default")) { 200 if (accumulator.toString().equals("true")) { 201 entry.setDefaultEntry(true); 202 } else if (accumulator.toString().equals("false")) { 203 entry.setDefaultEntry(false); 204 } else { 205 skipEntry = true; 206 } 207 } else if (qName.equals("url")) { 208 entry.setUrl(accumulator.toString()); 209 } else if (qName.equals("eula")) { 210 entry.setEulaAcceptanceRequired(accumulator.toString()); 211 } else if (qName.equals("min-zoom") || qName.equals("max-zoom")) { 212 Integer val = null; 213 try { 214 val = Integer.parseInt(accumulator.toString()); 215 } catch(NumberFormatException e) { 216 val = null; 217 } 218 if (val == null) { 219 skipEntry = true; 220 } else { 221 if (qName.equals("min-zoom")) { 222 entry.setDefaultMinZoom(val); 223 } else { 224 entry.setDefaultMaxZoom(val); 225 entry.setMaxZoom(val); 226 } 227 } 228 } else if (qName.equals("bounds")) { 229 entry.setBounds(bounds); 230 bounds = null; 231 } else if (qName.equals("attribution-text")) { 232 entry.setAttributionText(accumulator.toString()); 233 } else if (qName.equals("attribution-url")) { 234 entry.setAttributionLinkURL(accumulator.toString()); 235 } else if (qName.equals("logo-image")) { 236 entry.setAttributionImage(accumulator.toString()); 237 } else if (qName.equals("logo-url")) { 238 // FIXME 239 } else if (qName.equals("terms-of-use-text")) { 240 // FIXME 241 } else if (qName.equals("terms-of-use-url")) { 242 entry.setTermsOfUseURL(accumulator.toString()); 243 } 244 break; 245 } 246 } 247 } 248 } 249 } -
src/org/openstreetmap/josm/io/imagery/OsmosnimkiOffsetServer.java
25 25 @Override 26 26 public boolean isLayerSupported(ImageryInfo info) { 27 27 try { 28 URL url = new URL(this.url + "action=CheckAvailability&id=" + URLEncoder.encode(info.get FullUrl(), "UTF-8"));28 URL url = new URL(this.url + "action=CheckAvailability&id=" + URLEncoder.encode(info.getExtendedUrl(), "UTF-8")); 29 29 System.out.println(tr("Querying offset availability: {0}", url)); 30 30 final BufferedReader rdr = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream(), "UTF-8")); 31 31 String response = rdr.readLine(); … … 41 41 public EastNorth getOffset(ImageryInfo info, EastNorth en) { 42 42 LatLon ll = Main.getProjection().eastNorth2latlon(en); 43 43 try { 44 URL url = new URL(this.url + "action=GetOffsetForPoint&lat=" + ll.lat() + "&lon=" + ll.lon() + "&id=" + URLEncoder.encode(info.get FullUrl(), "UTF-8"));44 URL url = new URL(this.url + "action=GetOffsetForPoint&lat=" + ll.lat() + "&lon=" + ll.lon() + "&id=" + URLEncoder.encode(info.getExtendedUrl(), "UTF-8")); 45 45 System.out.println(tr("Querying offset: {0}", url.toString())); 46 46 final BufferedReader rdr = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream(), "UTF-8")); 47 47 String s = rdr.readLine(); -
src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java
17 17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 19 19 import org.openstreetmap.josm.data.Bounds; 20 import org.openstreetmap.josm.io.imagery.ImageryReader; 20 21 import org.openstreetmap.josm.io.MirroredInputStream; 22 import org.openstreetmap.josm.tools.Utils; 23 import org.xml.sax.SAXException; 21 24 22 25 public class ImageryLayerInfo { 23 26 … … 26 29 static ArrayList<ImageryInfo> defaultLayers = new ArrayList<ImageryInfo>(); 27 30 28 31 private final static String[] DEFAULT_LAYER_SITES = { 29 " http://josm.openstreetmap.de/maps"32 "resource://data/imagery.xml" // TODO : create wiki site 30 33 }; 31 34 32 35 private ImageryLayerInfo() { … … 50 53 Collection<String> defaults = Main.pref.getCollection( 51 54 "imagery.layers.default", Collections.<String>emptySet()); 52 55 ArrayList<String> defaultsSave = new ArrayList<String>(); 53 for(String source : Main.pref.getCollection("imagery.layers.sites", Arrays.asList(DEFAULT_LAYER_SITES))) 54 { 56 for (String source : Main.pref.getCollection("imagery.layers.sites", Arrays.asList(DEFAULT_LAYER_SITES))) { 57 if (clearCache) { 58 MirroredInputStream.cleanup(source); 59 } 60 MirroredInputStream stream = null; 61 try { 62 stream = new MirroredInputStream(source, -1); 63 ImageryReader rd = new ImageryReader(stream); 64 Collection<ImageryInfo> result = rd.parse(); 65 defaultLayers.addAll(result); 66 } catch (IOException ex) { 67 Utils.close(stream); 68 ex.printStackTrace(); 69 continue; 70 } catch (SAXException sex) { 71 Utils.close(stream); 72 sex.printStackTrace(); 73 continue; 74 } 75 76 if (true) continue; 77 55 78 try 56 79 { 57 80 if (clearCache) { … … 114 137 if (!defaults.contains(url)) { 115 138 for (ImageryInfo i : layers) { 116 139 if ((i.getImageryType() == ImageryType.WMS && url.equals(i.getUrl())) 117 || url.equals(i.get FullUrl())) {140 || url.equals(i.getExtendedUrl())) { 118 141 force = false; 119 142 } 120 143 } -
src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
41 41 42 42 private String name; 43 43 private String url = null; 44 private boolean defaultEntry = false; 44 45 private String cookies = null; 45 46 private String eulaAcceptanceRequired= null; 46 47 private ImageryType imageryType = ImageryType.WMS; … … 54 55 private String attributionLinkURL; 55 56 private String termsOfUseURL; 56 57 58 public ImageryInfo() { 59 } 60 57 61 public ImageryInfo(String name) { 58 62 this.name=name; 59 63 } 60 64 61 65 public ImageryInfo(String name, String url) { 62 66 this.name=name; 63 set Url(url);67 setExtendedUrl(url); 64 68 } 65 69 66 70 public ImageryInfo(String name, String url, String eulaAcceptanceRequired) { 67 71 this.name=name; 68 set Url(url);72 setExtendedUrl(url); 69 73 this.eulaAcceptanceRequired = eulaAcceptanceRequired; 70 74 } 71 75 72 76 public ImageryInfo(String name, String url, String eulaAcceptanceRequired, String cookies) { 73 77 this.name=name; 74 set Url(url);78 setExtendedUrl(url); 75 79 this.cookies=cookies; 76 80 this.eulaAcceptanceRequired = eulaAcceptanceRequired; 77 81 } 78 82 79 83 public ImageryInfo(String name, String url, String cookies, double pixelPerDegree) { 80 84 this.name=name; 81 set Url(url);85 setExtendedUrl(url); 82 86 this.cookies=cookies; 83 87 this.pixelPerDegree=pixelPerDegree; 84 88 } … … 86 90 public ArrayList<String> getInfoArray() { 87 91 ArrayList<String> res = new ArrayList<String>(); 88 92 res.add(name); 89 res.add((url != null && !url.isEmpty()) ? get FullUrl() : null);93 res.add((url != null && !url.isEmpty()) ? getExtendedUrl() : null); 90 94 res.add(cookies); 91 95 if(imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) { 92 96 res.add(pixelPerDegree != 0.0 ? String.valueOf(pixelPerDegree) : null); … … 105 109 ArrayList<String> array = new ArrayList<String>(list); 106 110 this.name=array.get(0); 107 111 if(array.size() >= 2 && !array.get(1).isEmpty()) { 108 set Url(array.get(1));112 setExtendedUrl(array.get(1)); 109 113 } 110 114 if(array.size() >= 3 && !array.get(2).isEmpty()) { 111 115 this.cookies=array.get(2); … … 177 181 this.pixelPerDegree = ppd; 178 182 } 179 183 184 public void setDefaultMaxZoom(int defaultMaxZoom) { 185 this.defaultMaxZoom = defaultMaxZoom; 186 } 187 188 public void setDefaultMinZoom(int defaultMinZoom) { 189 this.defaultMinZoom = defaultMinZoom; 190 } 191 180 192 public void setMaxZoom(int maxZoom) { 181 193 this.maxZoom = maxZoom; 182 194 } … … 201 213 termsOfUseURL = text; 202 214 } 203 215 204 public void set Url(String url) {216 public void setExtendedUrl(String url) { 205 217 CheckParameterUtil.ensureParameterNotNull(url); 206 218 207 219 defaultMaxZoom = 0; … … 239 251 return this.url; 240 252 } 241 253 254 public void setUrl(String url) { 255 this.url = url; 256 } 257 258 public boolean isDefaultEntry() { 259 return defaultEntry; 260 } 261 262 public void setDefaultEntry(boolean defaultEntry) { 263 this.defaultEntry = defaultEntry; 264 } 265 242 266 public String getCookies() { 243 267 return this.cookies; 244 268 } … … 259 283 return eulaAcceptanceRequired; 260 284 } 261 285 262 public String getFullUrl() { 286 public void setEulaAcceptanceRequired(String eulaAcceptanceRequired) { 287 this.eulaAcceptanceRequired = eulaAcceptanceRequired; 288 } 289 290 public String getExtendedUrl() { 263 291 return imageryType.getUrlString() + (defaultMaxZoom != 0 264 292 ? "["+(defaultMinZoom != 0 ? defaultMinZoom+",":"")+defaultMaxZoom+"]" : "") + ":" + url; 265 293 } … … 315 343 return imageryType; 316 344 } 317 345 346 public void setImageryType(ImageryType imageryType) { 347 this.imageryType = imageryType; 348 } 349 318 350 public static boolean isUrlWithPatterns(String url) { 319 351 return url != null && url.contains("{") && url.contains("}"); 320 352 } -
data/imagery.xml
1 <?xml version="1.0"?> 2 <imagery> 3 <!--"true;OpenStreetMap (Mapnik);tms[18]:http://tile.openstreetmap.org/;;;osm;osm;osm"--> 4 <entry> 5 <name>Bing</name> 6 <type>bing</type> 7 <default>true</default> 8 </entry> 9 <entry> 10 <name>Landsat</name> 11 <type>wms</type> 12 <default>true</default> 13 <url><![CDATA[http://irs.gis-lab.info/?layers=landsat&]]></url> 14 </entry> 15 <entry> 16 <name>Yahoo Sat</name> 17 <type>html</type> 18 <url><![CDATA[http://josm.openstreetmap.de/wmsplugin/YahooDirect.html?]]></url> 19 </entry> 20 <entry> 21 <name>MapQuest Open Aerial</name> 22 <type>tms</type> 23 <default>true</default> 24 <url><![CDATA[http://oatile1.mqcdn.com/naip/{zoom}/{x}/{y}.png]]></url> 25 </entry> 26 <entry> 27 <!--"false;SPOTMaps (France);http://spotmaps.youmapps.org/cgi-bin/mapserv?map=/home/ortho/ortho.map&service=wms&version=1.1.1&srs=EPSG:4326&request=GetMap&layers=spotmaps4osm&format=image/jpeg&FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&Layers=demo&;http://www.youmapps.org/licenses/EULA-OSM-J-{lang}.html"--> 28 <name>SPOTMaps (France)</name> 29 <type>wms</type> 30 <url><![CDATA[http://spotmaps.youmapps.org/cgi-bin/mapserv?map=/home/ortho/ortho.map&service=wms&version=1.1.1&srs=EPSG:4326&request=GetMap&layers=spotmaps4osm&format=image/jpeg&FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&Layers=demo&]]></url> 31 <eula mandatory='true'><![CDATA[http://www.youmapps.org/licenses/EULA-OSM-J-{lang}.html]]></eula> 32 </entry> 33 <entry> 34 <!--"false;OpenPT Map;tms[5,16]:http://openptmap.de/tiles;;45.7,5.9,55.0,17.3;osm;osm;osm"--> 35 <name>OpenPT Map</name> 36 <type>tms</type> 37 <url><![CDATA[http://openptmap.de/tiles]]></url> 38 <min-zoom>5</min-zoom> 39 <max-zoom>16</max-zoom> 40 <bounds min-lat='45.7' min-lon='5.9' max-lat='55.0' max-lon='17.3'/> 41 <attribution-text mandatory='true'>© OpenStreetMap contributors, CC-BY-SA</attribution-text> 42 <attribution-url>http://openstreetmap.org/</attribution-url> 43 </entry> 44 <entry> 45 <!--"false;ÖPNV;tms[18]:http://tile.xn- -pnvkarte-m4a.de/tilegen;;;osm;osm;osm"--> 46 <name>ÖPNV</name> 47 <type>tms</type> 48 <url><![CDATA[http://tile.xn--pnvkarte-m4a.de/tilegen]]></url> 49 <max-zoom>18</max-zoom> 50 51 <attribution-text mandatory='true'>© OpenStreetMap contributors, CC-BY-SA</attribution-text> 52 <attribution-url>http://openstreetmap.org/</attribution-url> 53 <terms-of-use-text>Background terms of use</terms-of-use-text> 54 <terms-of-use-url>http://www.openstreetmap.org/copyright</terms-of-use-url> 55 <!-- just for test - we don't really want a logo in this case --> 56 <logo-image>http://wiki.openstreetmap.org/w/images/c/c8/Public-images-osm_logo.png</logo-image> 57 <logo-url>http://wiki.openstreetmap.org/</logo-url> 58 </entry> 59 </imagery>
