Changeset 30568 in osm for applications/editors/josm/plugins/opendata/src
- Timestamp:
- 2014-08-06T19:33:57+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/NeptuneReader.java
r30532 r30568 39 39 import neptune.TridentObjectType; 40 40 41 import org.openstreetmap.josm.Main; 41 42 import org.openstreetmap.josm.data.coor.LatLon; 42 43 import org.openstreetmap.josm.data.osm.DataSet; … … 103 104 Validator validator = schema.newValidator(); 104 105 validator.validate(xmlFile); 105 System.out.println(xmlFile.getSystemId() + " is valid");106 Main.info(xmlFile.getSystemId() + " is valid"); 106 107 return true; 107 108 } catch (SAXException e) { 108 System.out.println(xmlFile.getSystemId() + " is NOT valid");109 System.out.println("Reason: " + e.getLocalizedMessage());109 Main.error(xmlFile.getSystemId() + " is NOT valid"); 110 Main.error("Reason: " + e.getLocalizedMessage()); 110 111 } catch (IOException e) { 111 System.out.println(xmlFile.getSystemId() + " is NOT valid");112 System.out.println("Reason: " + e.getLocalizedMessage());112 Main.error(xmlFile.getSystemId() + " is NOT valid"); 113 Main.error("Reason: " + e.getLocalizedMessage()); 113 114 } finally { 114 115 try { … … 119 120 } 120 121 } catch (FileNotFoundException e) { 121 System.err.println(e.getMessage());122 Main.error(e.getMessage()); 122 123 } 123 124 … … 317 318 } else { 318 319 // TODO 319 System.out.println("TODO: handle StopPoint "+childId);320 Main.info("TODO: handle StopPoint "+childId); 320 321 } 321 322 322 323 } else { 323 System.err.println("Unsupported child: "+childId);324 Main.warn("Unsupported child: "+childId); 324 325 } 325 326 } 326 327 } else if (sa.getStopAreaExtension().getAreaType().equals(ChouetteAreaType.BOARDING_POSITION)) { 327 // System.out.println("skipping StopArea with type "+sa.getStopAreaExtension().getAreaType()+": "+sa.getObjectId());328 //Main.info("skipping StopArea with type "+sa.getStopAreaExtension().getAreaType()+": "+sa.getObjectId()); 328 329 } else { 329 System.err.println("Unsupported StopArea type: "+sa.getStopAreaExtension().getAreaType());330 Main.warn("Unsupported StopArea type: "+sa.getStopAreaExtension().getAreaType()); 330 331 } 331 332 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/OsmDownloader.java
r30563 r30568 15 15 try { 16 16 String oapiServer = Main.pref.get(OdConstants.PREF_OAPI, OdConstants.DEFAULT_OAPI); 17 System.out.println(oapiReq);17 Main.info(oapiReq); 18 18 String oapiReqEnc = URLEncoder.encode(oapiReq, OdConstants.UTF8); 19 19 Main.main.menu.openLocation.openUrl(false, oapiServer+"data="+oapiReqEnc); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ArchiveReader.java
r30563 r30568 7 7 import java.io.IOException; 8 8 import java.util.ArrayList; 9 import java.util.Collection; 10 import java.util.Collections; 11 import java.util.HashMap; 9 12 import java.util.List; 13 import java.util.Map; 10 14 11 15 import javax.xml.bind.JAXBException; … … 56 60 57 61 protected abstract String getTaskMessage(); 58 59 public DataSet parseDoc(final ProgressMonitor progressMonitor) throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 60 61 final File temp = OdUtils.createTempDir(); 62 63 protected Collection<File> getDocsToParse(final File temp, final ProgressMonitor progressMonitor) throws FileNotFoundException, IOException { 62 64 final List<File> candidates = new ArrayList<>(); 63 65 66 if (progressMonitor != null) { 67 progressMonitor.beginTask(getTaskMessage()); 68 } 69 extractArchive(temp, candidates); 70 71 if (promptUser && candidates.size() > 1) { 72 DialogPrompter<CandidateChooser> prompt = new DialogPrompter<CandidateChooser>() { 73 @Override 74 protected CandidateChooser buildDialog() { 75 return new CandidateChooser(progressMonitor.getWindowParent(), candidates); 76 } 77 }; 78 if (prompt.promptInEdt().getValue() == 1) { 79 return Collections.singleton(prompt.getDialog().getSelectedFile()); 80 } 81 } else if (!candidates.isEmpty()) { 82 return candidates; 83 } 84 return Collections.emptyList(); 85 } 86 87 public Map<File, DataSet> parseDocs(final ProgressMonitor progressMonitor) throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 88 Map<File, DataSet> result = new HashMap<>(); 89 File temp = OdUtils.createTempDir(); 64 90 try { 91 file = null; 92 for (File f : getDocsToParse(temp, progressMonitor)) { 93 DataSet from = getDataForFile(f, progressMonitor); 94 if (from != null) { 95 result.put(f, from); 96 } 97 } 98 } finally { 99 OdUtils.deleteDir(temp); 65 100 if (progressMonitor != null) { 66 progressMonitor. beginTask(getTaskMessage());101 progressMonitor.finishTask(); 67 102 } 68 extractArchive(temp, candidates); 69 70 file = null; 71 72 if (promptUser && candidates.size() > 1) { 73 DialogPrompter<CandidateChooser> prompt = new DialogPrompter<CandidateChooser>() { 74 @Override 75 protected CandidateChooser buildDialog() { 76 return new CandidateChooser(progressMonitor.getWindowParent(), candidates); 77 } 78 }; 79 if (prompt.promptInEdt().getValue() == 1) { 80 file = prompt.getDialog().getSelectedFile(); 81 } 82 } else if (!candidates.isEmpty()) { 83 file = candidates.get(0); 103 } 104 return result; 105 } 106 107 public DataSet parseDoc(final ProgressMonitor progressMonitor) throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 108 File temp = OdUtils.createTempDir(); 109 110 try { 111 file = null; 112 Collection<File> files = getDocsToParse(temp, progressMonitor); 113 if (!files.isEmpty()) { 114 file = files.iterator().next(); 84 115 } 85 116 86 DataSet from = getDataForFile(progressMonitor); 117 DataSet from = getDataForFile(file, progressMonitor); 87 118 if (from != null) { 88 119 ds = from; … … 100 131 } 101 132 102 protected DataSet getDataForFile(final ProgressMonitor progressMonitor) 133 protected DataSet getDataForFile(File f, final ProgressMonitor progressMonitor) 103 134 throws FileNotFoundException, IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 104 if (f ile== null) {135 if (f == null) { 105 136 return null; 106 } else if (!f ile.exists()) {107 Main.warn("File does not exist: "+f ile.getPath());137 } else if (!f.exists()) { 138 Main.warn("File does not exist: "+f.getPath()); 108 139 return null; 109 140 } else { 141 Main.info("Parsing file "+f.getName()); 110 142 DataSet from = null; 111 FileInputStream in = new FileInputStream(f ile);143 FileInputStream in = new FileInputStream(f); 112 144 ProgressMonitor instance = null; 113 145 if (progressMonitor != null) { 114 146 instance = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 115 147 } 116 if (f ile.getName().toLowerCase().endsWith(OdConstants.CSV_EXT)) {148 if (f.getName().toLowerCase().endsWith(OdConstants.CSV_EXT)) { 117 149 from = CsvReader.parseDataSet(in, handler, instance); 118 } else if (f ile.getName().toLowerCase().endsWith(OdConstants.KML_EXT)) {150 } else if (f.getName().toLowerCase().endsWith(OdConstants.KML_EXT)) { 119 151 from = KmlReader.parseDataSet(in, instance); 120 } else if (f ile.getName().toLowerCase().endsWith(OdConstants.KMZ_EXT)) {152 } else if (f.getName().toLowerCase().endsWith(OdConstants.KMZ_EXT)) { 121 153 from = KmzReader.parseDataSet(in, instance); 122 } else if (f ile.getName().toLowerCase().endsWith(OdConstants.XLS_EXT)) {154 } else if (f.getName().toLowerCase().endsWith(OdConstants.XLS_EXT)) { 123 155 from = XlsReader.parseDataSet(in, handler, instance); 124 } else if (f ile.getName().toLowerCase().endsWith(OdConstants.ODS_EXT)) {156 } else if (f.getName().toLowerCase().endsWith(OdConstants.ODS_EXT)) { 125 157 from = OdsReader.parseDataSet(in, handler, instance); 126 } else if (f ile.getName().toLowerCase().endsWith(OdConstants.SHP_EXT)) {127 from = ShpReader.parseDataSet(in, f ile, handler, instance);128 } else if (f ile.getName().toLowerCase().endsWith(OdConstants.MIF_EXT)) {129 from = MifReader.parseDataSet(in, f ile, handler, instance);130 } else if (f ile.getName().toLowerCase().endsWith(OdConstants.TAB_EXT)) {131 from = TabReader.parseDataSet(in, f ile, handler, instance);132 } else if (f ile.getName().toLowerCase().endsWith(OdConstants.GML_EXT)) {158 } else if (f.getName().toLowerCase().endsWith(OdConstants.SHP_EXT)) { 159 from = ShpReader.parseDataSet(in, f, handler, instance); 160 } else if (f.getName().toLowerCase().endsWith(OdConstants.MIF_EXT)) { 161 from = MifReader.parseDataSet(in, f, handler, instance); 162 } else if (f.getName().toLowerCase().endsWith(OdConstants.TAB_EXT)) { 163 from = TabReader.parseDataSet(in, f, handler, instance); 164 } else if (f.getName().toLowerCase().endsWith(OdConstants.GML_EXT)) { 133 165 from = GmlReader.parseDataSet(in, handler, instance); 134 } else if (f ile.getName().toLowerCase().endsWith(OdConstants.XML_EXT)) {135 if (OdPlugin.getInstance().xmlImporter.acceptFile(f ile)) {166 } else if (f.getName().toLowerCase().endsWith(OdConstants.XML_EXT)) { 167 if (OdPlugin.getInstance().xmlImporter.acceptFile(f)) { 136 168 from = NeptuneReader.parseDataSet(in, handler, instance); 137 169 } else { 138 System.err.println("Unsupported XML file: "+f ile.getName());170 System.err.println("Unsupported XML file: "+f.getName()); 139 171 } 140 172 141 173 } else { 142 System.err.println("Unsupported file extension: "+f ile.getName());174 System.err.println("Unsupported file extension: "+f.getName()); 143 175 } 144 176 return from; … … 151 183 if (entryName.toLowerCase().endsWith("."+ext)) { 152 184 candidates.add(file); 153 System.out.println(entryName);154 185 break; 155 186 } … … 159 190 || OdPlugin.getInstance().xmlImporter.acceptFile(file))) { 160 191 candidates.add(file); 161 System.out.println(entryName);162 192 } 163 193 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/SevenZipReader.java
r30436 r30568 11 11 import java.io.OutputStream; 12 12 import java.util.List; 13 import java.util.Map; 13 14 14 15 import javax.xml.bind.JAXBException; … … 57 58 } 58 59 59 @Override protected String getTaskMessage() { 60 public static Map<File, DataSet> parseDataSets(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance, boolean promptUser) 61 throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 62 return new SevenZipReader(in, handler, promptUser).parseDocs(instance); 63 } 64 65 @Override 66 protected String getTaskMessage() { 60 67 return tr("Reading 7Zip file..."); 61 68 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ZipReader.java
r30340 r30568 10 10 import java.io.InputStream; 11 11 import java.util.List; 12 import java.util.Map; 12 13 import java.util.zip.ZipEntry; 13 14 import java.util.zip.ZipInputStream; … … 36 37 return new ZipReader(in, handler, promptUser).parseDoc(instance); 37 38 } 39 40 public static Map<File, DataSet> parseDataSets(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance, boolean promptUser) 41 throws IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 42 return new ZipReader(in, handler, promptUser).parseDocs(instance); 43 } 38 44 39 45 protected void extractArchive(final File temp, final List<File> candidates) throws IOException, FileNotFoundException { … … 75 81 } 76 82 77 @Override protected String getTaskMessage() { 83 @Override 84 protected String getTaskMessage() { 78 85 return tr("Reading Zip file..."); 79 86 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/DefaultShpHandler.java
r30563 r30568 51 51 boolean res = Math.abs(a - b) <= Main.pref.getDouble(OdConstants.PREF_CRS_COMPARISON_TOLERANCE, OdConstants.DEFAULT_CRS_COMPARISON_TOLERANCE); 52 52 if (Main.pref.getBoolean(OdConstants.PREF_CRS_COMPARISON_DEBUG, false)) { 53 System.out.println("Comparing "+a+" and "+b+" -> "+res);53 Main.debug("Comparing "+a+" and "+b+" -> "+res); 54 54 } 55 55 return res; -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeographicReader.java
r30563 r30568 5 5 6 6 import java.awt.Component; 7 import java.awt.GraphicsEnvironment; 7 8 import java.awt.Image; 8 9 import java.util.ArrayList; 10 import java.util.Arrays; 9 11 import java.util.HashMap; 10 12 import java.util.List; … … 200 202 201 203 private static final void compareDebug(CoordinateReferenceSystem crs1, CoordinateReferenceSystem crs2) { 202 System.out.println("-- COMPARING "+crs1.getName()+" WITH "+crs2.getName()+" --");204 Main.debug("-- COMPARING "+crs1.getName()+" WITH "+crs2.getName()+" --"); 203 205 compareDebug("class", crs1.getClass(), crs2.getClass()); 204 206 CoordinateSystem cs1 = crs1.getCoordinateSystem(); … … 229 231 } 230 232 } 231 System.out.println("-- COMPARING FINISHED --");233 Main.debug("-- COMPARING FINISHED --"); 232 234 } 233 235 … … 245 247 246 248 private static final boolean compareDebug(String text, boolean result, Object o1, Object o2) { 247 System.out.println(text + ": " + result + "("+o1+", "+o2+")");249 Main.debug(text + ": " + result + "("+o1+", "+o2+")"); 248 250 return result; 249 251 } … … 253 255 transform = CRS.findMathTransform(crs, wgs84); 254 256 } catch (OperationNotFoundException e) { 255 System.out.println(crs.getName()+": "+e.getMessage()); // Bursa wolf parameters required.257 Main.info(crs.getName()+": "+e.getMessage()); // Bursa wolf parameters required. 256 258 257 259 if (findSimiliarCrs) { … … 267 269 Main.pref.getDouble(OdConstants.PREF_CRS_COMPARISON_TOLERANCE, OdConstants.DEFAULT_CRS_COMPARISON_TOLERANCE)); 268 270 if (((AbstractCRS)candidate).equals((AbstractIdentifiedObject)crs, false)) { 269 System.out.println("Found a potential CRS: "+candidate.getName());271 Main.info("Found a potential CRS: "+candidate.getName()); 270 272 candidates.add(candidate); 271 273 } else if (Main.pref.getBoolean(OdConstants.PREF_CRS_COMPARISON_DEBUG, false)) { … … 281 283 282 284 if (candidates.size() > 1) { 283 System.err.println("Found several potential CRS.");//TODO: ask user which one to use 285 Main.warn("Found several potential CRS: "+Arrays.toString(candidates.toArray())); 286 // TODO: ask user which one to use 284 287 } 285 288 … … 300 303 transform = handler.findMathTransform(crs, wgs84, false); 301 304 } catch (OperationNotFoundException ex) { 302 System.out.println(crs.getName()+": "+ex.getMessage()); // Bursa wolf parameters required.305 Main.warn(crs.getName()+": "+ex.getMessage()); // Bursa wolf parameters required. 303 306 } 304 307 } else { … … 310 313 } 311 314 } catch (OperationNotFoundException ex) { 312 System.out.println(crs.getName()+": "+ex.getMessage()); // Bursa wolf parameters required.315 Main.warn(crs.getName()+": "+ex.getMessage()); // Bursa wolf parameters required. 313 316 } 314 317 } 315 318 } 316 319 if (transform == null) { 317 // ask user before trying lenient method 318 if (warnLenientMethod(parent, crs)) { 320 // ask user before trying lenient method, unless in headless mode (unit tests) 321 if (!GraphicsEnvironment.isHeadless() && warnLenientMethod(parent, crs)) { 319 322 // User canceled 320 323 throw new UserCancelException(); 321 324 } 322 System.out.println("Searching for a lenient math transform.");325 Main.info("Searching for a lenient math transform."); 323 326 transform = CRS.findMathTransform(crs, wgs84, true); 324 327 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GmlReader.java
r30563 r30568 107 107 108 108 private void findCRS(String srs) throws NoSuchAuthorityCodeException, FactoryException { 109 System.out.println("Finding CRS for "+srs);109 Main.info("Finding CRS for "+srs); 110 110 if (gmlHandler != null) { 111 111 crs = gmlHandler.getCrsFor(srs); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java
r30567 r30568 158 158 } else { 159 159 // Debug unknown geometry 160 System.out.println("\ttype: "+geometry.getType());161 System.out.println("\tbounds: "+geometry.getBounds());162 System.out.println("\tdescriptor: "+desc);163 System.out.println("\tname: "+geometry.getName());164 System.out.println("\tvalue: "+geometry.getValue());165 System.out.println("\tid: "+geometry.getIdentifier());166 System.out.println("-------------------------------------------------------------");160 Main.debug("\ttype: "+geometry.getType()); 161 Main.debug("\tbounds: "+geometry.getBounds()); 162 Main.debug("\tdescriptor: "+desc); 163 Main.debug("\tname: "+geometry.getName()); 164 Main.debug("\tvalue: "+geometry.getValue()); 165 Main.debug("\tid: "+geometry.getIdentifier()); 166 Main.debug("-------------------------------------------------------------"); 167 167 } 168 168 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/CsvReader.java
r30563 r30568 8 8 import java.nio.charset.Charset; 9 9 10 import org.openstreetmap.josm.Main; 10 11 import org.openstreetmap.josm.data.osm.DataSet; 11 12 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 43 44 if (csvHandler == null || csvHandler.getSeparator() == null || ";".equals(csvHandler.getSeparator())) { 44 45 // If default sep has been used, try comma 45 System.out.println(e.getMessage());46 Main.warn(e.getMessage()); 46 47 csvReader.sep = ","; 47 48 return csvReader.doParse(csvReader.splitLine(), instance); … … 54 55 @Override 55 56 protected void initResources(InputStream in, ProgressMonitor progressMonitor) throws IOException { 56 System.out.println("Parsing CSV file using charset "+charset+" and separator '"+sep+"'");57 Main.info("Parsing CSV file using charset "+charset+" and separator '"+sep+"'"); 57 58 58 59 reader = new BufferedReader(new InputStreamReader(in, charset)); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/OdsDocument.java
r30563 r30568 11 11 import org.jopendocument.io.SaxContentUnmarshaller; 12 12 import org.jopendocument.model.OpenDocument; 13 import org.openstreetmap.josm.Main; 13 14 import org.xml.sax.InputSource; 14 15 import org.xml.sax.XMLReader; … … 44 45 if (entry.getName().equals("content.xml")) { 45 46 rdr.setContentHandler(contentHandler); 46 System.out.println("Parsing content.xml");47 Main.info("Parsing content.xml"); 47 48 rdr.parse(getEntryInputSource(zis)); 48 49 contentParsed = true; -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/OdsReader.java
r30532 r30568 13 13 import org.jopendocument.model.table.TableTableRow; 14 14 import org.jopendocument.model.text.TextP; 15 import org.openstreetmap.josm.Main; 15 16 import org.openstreetmap.josm.data.osm.DataSet; 16 17 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 38 39 protected void initResources(InputStream in, ProgressMonitor progressMonitor) throws IOException { 39 40 try { 40 System.out.println("Parsing ODS file");41 Main.info("Parsing ODS file"); 41 42 doc = new OdsDocument(in); 42 43 List<OfficeSpreadsheet> spreadsheets = doc.getBody().getOfficeSpreadsheets(); … … 62 63 63 64 if (rowIndex % 5000 == 0) { 64 System.out.println("Lines read: "+rowIndex);65 Main.info("Lines read: "+rowIndex); 65 66 } 66 67 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/SpreadSheetReader.java
r30563 r30568 100 100 101 101 public DataSet doParse(String[] header, ProgressMonitor progressMonitor) throws IOException { 102 System.out.println("Header: "+Arrays.toString(header));102 Main.info("Header: "+Arrays.toString(header)); 103 103 104 104 Map<ProjectionPatterns, List<CoordinateColumns>> projColumns = new HashMap<>(); … … 175 175 } 176 176 177 System.out.println("Loading data using projections "+message);177 Main.info("Loading data using projections "+message); 178 178 179 179 final DataSet ds = new DataSet(); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/XlsReader.java
r30532 r30568 14 14 import org.apache.poi.ss.usermodel.Sheet; 15 15 import org.apache.poi.ss.usermodel.Workbook; 16 import org.openstreetmap.josm.Main; 16 17 import org.openstreetmap.josm.data.osm.DataSet; 17 18 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 35 36 @Override 36 37 protected void initResources(InputStream in, ProgressMonitor progressMonitor) throws IOException { 37 System.out.println("Parsing XLS file");38 Main.info("Parsing XLS file"); 38 39 try { 39 40 wb = new HSSFWorkbook(new POIFSFileSystem(in));
Note:
See TracChangeset
for help on using the changeset viewer.