Changeset 4430 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-09-16T22:47:09+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r4423 r4430 2 2 package org.openstreetmap.josm.data.imagery; 3 3 4 import java.util.Arrays; 4 5 import java.util.ArrayList; 5 6 import java.util.Collection; … … 138 139 } 139 140 res.add(shapesString.isEmpty() ? null : shapesString); 141 if(serverProjections != null && serverProjections.size() != 0) { 142 String val = ""; 143 for(String p : serverProjections) { 144 if(!val.isEmpty()) 145 val += ","; 146 val += p; 147 } 148 res.add(val); 149 } 140 150 return res; 141 151 } … … 184 194 Main.warn(e.toString()); 185 195 } 196 } 197 if(array.size() >= 11 && !array.get(10).isEmpty()) { 198 serverProjections = Arrays.asList(array.get(10).split(",")); 186 199 } 187 200 } … … 202 215 this.attributionText = i.attributionText; 203 216 this.termsOfUseURL = i.termsOfUseURL; 217 this.serverProjections = i.serverProjections; 204 218 } 205 219 -
trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
r4240 r4430 38 38 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 39 39 import org.openstreetmap.josm.data.ProjectionBounds; 40 import org.openstreetmap.josm.data.projection.Mercator; 40 41 import org.openstreetmap.josm.data.projection.Projection; 41 42 import org.openstreetmap.josm.data.coor.EastNorth; … … 930 931 @Override 931 932 public boolean isProjectionSupported(Projection proj) { 932 return serverProjections == null || serverProjections.contains(proj.toCode().toUpperCase()); 933 return serverProjections == null || serverProjections.contains(proj.toCode().toUpperCase()) 934 || (proj instanceof Mercator && serverProjections.contains("EPSG:4326")); 933 935 } 934 936 -
trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java
r4423 r4430 41 41 ENTRY_ATTRIBUTE, // note we are inside an entry attribute to collect the character data 42 42 SUPPORTED_PROJECTIONS, 43 PR,43 SRS, 44 44 BOUNDS, 45 45 SHAPE, … … 52 52 53 53 public List<ImageryInfo> parse() throws SAXException, IOException { 54 if (isXml(source)) { 55 Parser parser = new Parser(); 56 try { 57 SAXParserFactory factory = SAXParserFactory.newInstance(); 58 factory.setNamespaceAware(true); 59 InputStream in = new MirroredInputStream(source); 60 InputSource is = new InputSource(UTFInputStreamReader.create(in, "UTF-8")); 61 factory.newSAXParser().parse(is, parser); 62 return parser.entries; 63 } catch (SAXException e) { 64 throw e; 65 } catch (ParserConfigurationException e) { 66 e.printStackTrace(); // broken SAXException chaining 67 throw new SAXException(e); 68 } 69 } else { 70 return readCSV(source); 71 } 72 } 73 74 /** 75 * Probe the file to see if it is xml or the traditional csv format. 76 * 77 * If the first non-whitespace character is a '<', decide for 78 * xml, otherwise csv. 79 */ 80 private boolean isXml(String source) { 81 MirroredInputStream in = null; 54 Parser parser = new Parser(); 82 55 try { 83 in = new MirroredInputStream(source); 84 InputStreamReader reader = UTFInputStreamReader.create(in, null); 85 WHILE: while (true) { 86 int c = reader.read(); 87 switch (c) { 88 case -1: 89 break WHILE; 90 case ' ': 91 case '\t': 92 case '\n': 93 case '\r': 94 continue; 95 case '<': 96 return true; 97 default: 98 return false; 99 } 100 } 101 } catch (IOException ex) { 102 ex.printStackTrace(); 103 } finally { 104 Utils.close(in); 105 } 106 Main.warn(tr("Warning: Could not detect type of imagery source ''{0}''. Using default (xml).", source)); 107 return true; 108 } 109 110 private List<ImageryInfo> readCSV(String source) { 111 List<ImageryInfo> entries = new ArrayList<ImageryInfo>(); 112 MirroredInputStream s = null; 113 try { 114 s = new MirroredInputStream(source); 115 try { 116 InputStreamReader r; 117 try 118 { 119 r = new InputStreamReader(s, "UTF-8"); 120 } 121 catch (UnsupportedEncodingException e) 122 { 123 r = new InputStreamReader(s); 124 } 125 BufferedReader reader = new BufferedReader(r); 126 String line; 127 while((line = reader.readLine()) != null) 128 { 129 String val[] = line.split(";"); 130 if(!line.startsWith("#") && val.length >= 3) { 131 boolean defaultEntry = "true".equals(val[0]); 132 String name = tr(val[1]); 133 String url = val[2]; 134 String eulaAcceptanceRequired = null; 135 136 if (val.length >= 4 && !val[3].isEmpty()) { 137 // 4th parameter optional for license agreement (EULA) 138 eulaAcceptanceRequired = val[3]; 139 } 140 141 ImageryInfo info = new ImageryInfo(name, url, eulaAcceptanceRequired); 142 143 info.setDefaultEntry(defaultEntry); 144 145 if (val.length >= 5 && !val[4].isEmpty()) { 146 // 5th parameter optional for bounds 147 try { 148 info.setBounds(new ImageryBounds(val[4], ",")); 149 } catch (IllegalArgumentException e) { 150 Main.warn(e.toString()); 151 } 152 } 153 if (val.length >= 6 && !val[5].isEmpty()) { 154 info.setAttributionText(val[5]); 155 } 156 if (val.length >= 7 && !val[6].isEmpty()) { 157 info.setAttributionLinkURL(val[6]); 158 } 159 if (val.length >= 8 && !val[7].isEmpty()) { 160 info.setTermsOfUseURL(val[7]); 161 } 162 if (val.length >= 9 && !val[8].isEmpty()) { 163 info.setAttributionImage(val[8]); 164 } 165 166 entries.add(info); 167 } 168 } 169 } finally { 170 Utils.close(s); 171 } 172 return entries; 173 } catch (IOException ex) { 174 ex.printStackTrace(); 175 } finally { 176 Utils.close(s); 177 } 178 return entries; 56 SAXParserFactory factory = SAXParserFactory.newInstance(); 57 factory.setNamespaceAware(true); 58 InputStream in = new MirroredInputStream(source); 59 InputSource is = new InputSource(UTFInputStreamReader.create(in, "UTF-8")); 60 factory.newSAXParser().parse(is, parser); 61 return parser.entries; 62 } catch (SAXException e) { 63 throw e; 64 } catch (ParserConfigurationException e) { 65 e.printStackTrace(); // broken SAXException chaining 66 throw new SAXException(e); 67 } 179 68 } 180 69 … … 275 164 break; 276 165 case SUPPORTED_PROJECTIONS: 277 if (qName.equals(" pr")) {278 newState = State. PR;166 if (qName.equals("srs")) { 167 newState = State.SRS; 279 168 } 280 169 break; … … 383 272 shape = null; 384 273 break; 385 case PR:274 case SRS: 386 275 supported_srs.add(accumulator.toString()); 387 276 break; -
trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java
r4253 r4430 96 96 String srs = ""; 97 97 boolean useepsg = false; 98 // FIXME: Non-Pattern format should be dropped in future 98 99 try 99 100 { … … 103 104 if(m.group(1).equals("EPSG:4326") && Main.getProjection() instanceof Mercator) 104 105 useepsg = true; 105 } else if( Main.getProjection() instanceof Mercator) {106 } else if((Main.getProjection() instanceof Mercator) && !serverProjections.contains(myProj)) { 106 107 useepsg = true; 107 108 srs ="&srs=EPSG:4326"; … … 156 157 { 157 158 ArrayList<String> serverProjections = new ArrayList<String>(); 159 boolean hasepsg = false; 160 161 // FIXME: Non-Pattern format should be dropped in future 158 162 try 159 163 { … … 161 165 if(m.matches()) 162 166 { 163 boolean hasepsg = false;164 167 for(String p : m.group(1).split(",")) 165 168 { … … 168 171 hasepsg = true; 169 172 } 170 if(hasepsg && !serverProjections.contains(new Mercator().toCode()))171 serverProjections.add(new Mercator().toCode());172 173 } 173 174 else … … 178 179 serverProjections.add(m.group(1)); 179 180 if(m.group(1).equals("EPSG:4326")) 180 serverProjections.add(new Mercator().toCode());181 hasepsg = true; 181 182 } 182 183 /* TODO: here should be an "else" code checking server capabilities */ … … 191 192 { 192 193 String myProj = Main.getProjection().toCode().toUpperCase(); 193 if(!serverProjections.contains(myProj)) 194 if(!serverProjections.contains(myProj) && 195 !(Main.getProjection() instanceof Mercator && serverProjections.contains("EPSG:4326"))) 194 196 { 195 197 JOptionPane.showMessageDialog(Main.parent,
Note:
See TracChangeset
for help on using the changeset viewer.