Changeset 36173 in osm for applications/editors/josm
- Timestamp:
- 2023-10-16T23:27:18+02:00 (15 months ago)
- Location:
- applications/editors/josm/plugins
- Files:
-
- 58 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/build-common.xml
r36168 r36173 133 133 <compilerarg value="-Xlint:deprecation"/> 134 134 <compilerarg value="-Xlint:unchecked"/> 135 <compilerarg value="-Xplugin:ErrorProne -Xep:StringSplitter:OFF -Xep:ReferenceEquality:OFF -Xep:InsecureCryptoUsage:OFF -Xep:FutureReturnValueIgnored:OFF -Xep:JdkObsolete:OFF -Xep:EqualsHashCode:OFF -Xep:JavaUtilDate:OFF -Xep:DoNotCallSuggester:OFF -Xep:BanSerializableRead:OFF -Xep:RestrictedApiChecker:OFF"/> 135 <compilerarg value="-Xplugin:ErrorProne -Xep:StringSplitter:OFF -Xep:ReferenceEquality:OFF -Xep:InsecureCryptoUsage:OFF -Xep:FutureReturnValueIgnored:OFF -Xep:JdkObsolete:OFF -Xep:EqualsHashCode:OFF -Xep:JavaUtilDate:OFF -Xep:DoNotCallSuggester:OFF -Xep:BanSerializableRead:OFF -Xep:RestrictedApiChecker:OFF" unless:set="isJava11"/> 136 <compilerarg value="-Xplugin:ErrorProne -Xep:StringSplitter:OFF -Xep:ReferenceEquality:OFF -Xep:InsecureCryptoUsage:OFF -Xep:FutureReturnValueIgnored:OFF -Xep:JdkObsolete:OFF -Xep:EqualsHashCode:OFF -Xep:JavaUtilDate:OFF -Xep:DoNotCallSuggester:OFF -Xep:BanSerializableRead:OFF" if:set="isJava11"/> 136 137 <compilerarg line="-Xmaxwarns 1000"/> 137 138 <classpath refid="plugin.classpath"/> … … 739 740 </target> 740 741 <target name="resolve-tools" depends="init-ivy" description="Resolves tools using Apache Ivy"> 742 <ivy:settings file="${josm.ivysettings}"/> 741 743 <ivy:resolve file="${core.tools.ivy}"/> 742 744 <ivy:cachepath file="${core.tools.ivy}" pathid="errorprone.classpath" conf="errorprone"/> -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/OdPlugin.java
r36072 r36173 104 104 loadModules(); 105 105 // Add menu in EDT 106 GuiHelper.runInEDT( () -> buildMenu());106 GuiHelper.runInEDT(this::buildMenu); 107 107 }).start(); 108 108 … … 117 117 } 118 118 119 private JMenu getModuleMenu(Module module) {119 private static JMenu getModuleMenu(Module module) { 120 120 String moduleName = module.getDisplayedName(); 121 121 if (moduleName == null || moduleName.isEmpty()) { … … 141 141 JMenu endMenu = null; 142 142 if (cat != null) { 143 if ((endMenu = catMenus.get(cat)) == null) { 144 catMenus.put(cat, endMenu = new JMenu(cat.getName())); 143 endMenu = catMenus.get(cat); 144 if (endMenu == null) { 145 endMenu = new JMenu(cat.getName()); 146 catMenus.put(cat, endMenu); 145 147 setMenuItemIcon(cat.getIcon(), endMenu); 146 148 moduleMenu.add(endMenu); … … 183 185 } 184 186 185 private void setMenuItemIcon(ImageIcon icon, JMenuItem menuItem) {187 private static void setMenuItemIcon(ImageIcon icon, JMenuItem menuItem) { 186 188 if (icon != null) { 187 189 if (icon.getIconHeight() != 16 || icon.getIconWidth() != 16) { … … 195 197 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 196 198 if (newFrame != null) { 197 newFrame.addToggleDialog(dialog = new OdDialog()); 199 dialog = new OdDialog(); 200 newFrame.addToggleDialog(dialog); 198 201 } else { 199 202 dialog = null; … … 206 209 } 207 210 208 private void loadModules() {211 private static void loadModules() { 209 212 MainFrame parent = MainApplication.getMainFrame(); 210 213 List<ModuleInformation> modulesToLoad = ModuleHandler.buildListOfModulesToLoad(parent); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/OdConstants.java
r36072 r36173 2 2 package org.openstreetmap.josm.plugins.opendata.core; 3 3 4 import java.nio.charset.StandardCharsets; 4 5 import java.util.ArrayList; 5 6 import java.util.Collection; … … 14 15 * Encodings 15 16 */ 16 public static final String UTF8 = "UTF-8";17 public static final String UTF8 = StandardCharsets.UTF_8.name(); 17 18 public static final String ISO8859_15 = "ISO-8859-15"; 18 19 public static final String CP850 = "Cp850"; … … 50 51 public static final String PREF_MODULES = "opendata.modules"; 51 52 public static final String PREF_MODULES_SITES = "opendata.modules.sites"; 52 public static final String OSM_SITE = "https:// svn.openstreetmap.org/applications/editors/josm/plugins/opendata/";53 public static final String OSM_SITE = "https://josm.openstreetmap.de/browser/osm/applications/editors/josm/plugins/opendata"; 53 54 public static final String[] DEFAULT_MODULE_SITES = {OSM_SITE + "modules.txt%<?modules=>"}; 54 55 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataAction.java
r36072 r36173 4 4 import java.awt.event.ActionEvent; 5 5 import java.net.URL; 6 import java.util.Locale; 6 7 7 8 import javax.swing.Action; … … 21 22 CheckParameterUtil.ensureParameterNotNull(url, "url"); 22 23 putValue(Action.NAME, name); 23 putValue("toolbar", ("opendata_download_"+module.getDisplayedName()+"_"+name).toLowerCase( ).replace(" ", "_"));24 putValue("toolbar", ("opendata_download_"+module.getDisplayedName()+"_"+name).toLowerCase(Locale.ROOT).replace(" ", "_")); 24 25 this.url = url; 25 26 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataTask.java
r36072 r36173 26 26 import org.openstreetmap.josm.plugins.opendata.core.modules.Module; 27 27 import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleHandler; 28 import org.openstreetmap.josm.tools.Logging; 28 29 29 30 public class DownloadDataTask extends DownloadOsmTask { … … 46 47 this.handler = null; 47 48 for (Module module : ModuleHandler.moduleList) { 48 for (AbstractDataSetHandler handler : module.getNewlyInstanciatedHandlers()) {49 if ( handler.acceptsUrl(url)) {50 this.handler = handler;49 for (AbstractDataSetHandler moduleHandler : module.getNewlyInstanciatedHandlers()) { 50 if (moduleHandler.acceptsUrl(url)) { 51 this.handler = moduleHandler; 51 52 return true; 52 53 } … … 113 114 return new AskLicenseAgreementDialog(license).showDialog().getValue() == 1; 114 115 } catch (IOException e) { 116 Logging.debug(e); 115 117 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("License URL not available: {0}", license.toString())); 116 118 return false; -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/OpenLinkAction.java
r36072 r36173 19 19 public class OpenLinkAction extends JosmAction { 20 20 21 private URL url;21 private final URL url; 22 22 23 23 public OpenLinkAction(URL url, String icon24Name, String title, String description) { … … 35 35 try { 36 36 Logging.error(e1.getLocalizedMessage()); 37 Logging.debug(e1); 37 38 int index = e1.getIndex(); 38 39 if (index > -1) { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/AbstractDataSetHandler.java
r36072 r36173 7 7 import java.util.ArrayList; 8 8 import java.util.Collection; 9 import java.util.Collections; 9 10 import java.util.List; 10 11 import java.util.regex.Pattern; … … 88 89 } 89 90 90 private boolean acceptsFilename(String filename, String[] expected, String ... extensions) {91 private static boolean acceptsFilename(String filename, String[] expected, String ... extensions) { 91 92 if (filename != null) { 92 93 for (String expectedName : expected) { … … 102 103 } 103 104 104 protected finalboolean acceptsCsvFilename(String filename, String... expected) {105 protected static boolean acceptsCsvFilename(String filename, String... expected) { 105 106 return acceptsFilename(filename, expected, OdConstants.CSV_EXT); 106 107 } 107 108 108 protected finalboolean acceptsXlsFilename(String filename, String... expected) {109 protected static boolean acceptsXlsFilename(String filename, String... expected) { 109 110 return acceptsFilename(filename, expected, OdConstants.XLS_EXT); 110 111 } 111 112 112 protected finalboolean acceptsOdsFilename(String filename, String... expected) {113 protected static boolean acceptsOdsFilename(String filename, String... expected) { 113 114 return acceptsFilename(filename, expected, OdConstants.ODS_EXT); 114 115 } 115 116 116 protected finalboolean acceptsShpFilename(String filename, String... expected) {117 protected static boolean acceptsShpFilename(String filename, String... expected) { 117 118 return acceptsFilename(filename, expected, OdConstants.SHP_EXT); 118 119 } 119 120 120 protected finalboolean acceptsMifFilename(String filename, String... expected) {121 protected static boolean acceptsMifFilename(String filename, String... expected) { 121 122 return acceptsFilename(filename, expected, OdConstants.MIF_EXT); 122 123 } 123 124 124 protected finalboolean acceptsMifTabFilename(String filename, String... expected) {125 protected static boolean acceptsMifTabFilename(String filename, String... expected) { 125 126 return acceptsFilename(filename, expected, OdConstants.MIF_EXT, OdConstants.TAB_EXT); 126 127 } 127 128 128 protected finalboolean acceptsShpMifFilename(String filename, String... expected) {129 protected static boolean acceptsShpMifFilename(String filename, String... expected) { 129 130 return acceptsFilename(filename, expected, OdConstants.SHP_EXT, OdConstants.MIF_EXT); 130 131 } 131 132 132 protected finalboolean acceptsKmlFilename(String filename, String... expected) {133 protected static boolean acceptsKmlFilename(String filename, String... expected) { 133 134 return acceptsFilename(filename, expected, OdConstants.KML_EXT); 134 135 } 135 136 136 protected finalboolean acceptsKmzFilename(String filename, String... expected) {137 protected static boolean acceptsKmzFilename(String filename, String... expected) { 137 138 return acceptsFilename(filename, expected, OdConstants.KMZ_EXT); 138 139 } 139 140 140 protected finalboolean acceptsKmzShpFilename(String filename, String... expected) {141 protected static boolean acceptsKmzShpFilename(String filename, String... expected) { 141 142 return acceptsFilename(filename, expected, OdConstants.KMZ_EXT, OdConstants.SHP_EXT); 142 143 } 143 144 144 protected finalboolean acceptsKmzTabFilename(String filename, String... expected) {145 protected static boolean acceptsKmzTabFilename(String filename, String... expected) { 145 146 return acceptsFilename(filename, expected, OdConstants.KMZ_EXT, OdConstants.TAB_EXT); 146 147 } 147 148 148 protected finalboolean acceptsZipFilename(String filename, String... expected) {149 protected static boolean acceptsZipFilename(String filename, String... expected) { 149 150 return acceptsFilename(filename, expected, OdConstants.ZIP_EXT); 150 151 } 151 152 152 protected finalboolean accepts7ZipFilename(String filename, String... expected) {153 protected static boolean accepts7ZipFilename(String filename, String... expected) { 153 154 return acceptsFilename(filename, expected, OdConstants.SEVENZIP_EXT); 154 155 } 155 156 156 protected finalboolean acceptsCsvKmzFilename(String filename, String... expected) {157 protected static boolean acceptsCsvKmzFilename(String filename, String... expected) { 157 158 return acceptsFilename(filename, expected, OdConstants.CSV_EXT, OdConstants.KMZ_EXT); 158 159 } 159 160 160 protected finalboolean acceptsCsvKmzTabFilename(String filename, String... expected) {161 protected static boolean acceptsCsvKmzTabFilename(String filename, String... expected) { 161 162 return acceptsFilename(filename, expected, OdConstants.CSV_EXT, OdConstants.KMZ_EXT, OdConstants.TAB_EXT); 162 163 } 163 164 164 protected finalboolean acceptsCsvXlsFilename(String filename, String... expected) {165 protected static boolean acceptsCsvXlsFilename(String filename, String... expected) { 165 166 return acceptsFilename(filename, expected, OdConstants.CSV_EXT, OdConstants.XLS_EXT); 166 167 } 167 168 168 protected finalboolean acceptsGpkgFilename(String filename, String... expected) {169 protected static boolean acceptsGpkgFilename(String filename, String... expected) { 169 170 return acceptsFilename(filename, expected, OdConstants.GEOPACKAGE_EXT); 170 171 } … … 238 239 239 240 public List<Pair<String, URL>> getDataURLs() { 240 return null;241 return Collections.emptyList(); 241 242 } 242 243 … … 315 316 } 316 317 317 protected finalvoid replace(IPrimitive p, String dataKey, String osmKey) {318 protected static void replace(IPrimitive p, String dataKey, String osmKey) { 318 319 addOrReplace(p, dataKey, osmKey, null, null, null, true); 319 320 } 320 321 321 protected finalvoid replace(IPrimitive p, String dataKey, String osmKey, ValueReplacer replacer) {322 protected static void replace(IPrimitive p, String dataKey, String osmKey, ValueReplacer replacer) { 322 323 addOrReplace(p, dataKey, osmKey, null, null, replacer, true); 323 324 } 324 325 325 protected finalvoid replace(IPrimitive p, String dataKey, String osmKey, String[] dataValues, String[] osmValues) {326 protected static void replace(IPrimitive p, String dataKey, String osmKey, String[] dataValues, String[] osmValues) { 326 327 addOrReplace(p, dataKey, osmKey, dataValues, osmValues, null, true); 327 328 } 328 329 329 protected finalvoid add(IPrimitive p, String dataKey, String osmKey, ValueReplacer replacer) {330 protected static void add(IPrimitive p, String dataKey, String osmKey, ValueReplacer replacer) { 330 331 addOrReplace(p, dataKey, osmKey, null, null, replacer, false); 331 332 } 332 333 333 protected finalvoid add(IPrimitive p, String dataKey, String osmKey, String[] dataValues, String[] osmValues) {334 protected static void add(IPrimitive p, String dataKey, String osmKey, String[] dataValues, String[] osmValues) { 334 335 addOrReplace(p, dataKey, osmKey, dataValues, osmValues, null, false); 335 336 } 336 337 337 private void addOrReplace(IPrimitive p, String dataKey, String osmKey, String[] dataValues, String[] osmValues,338 private static void addOrReplace(IPrimitive p, String dataKey, String osmKey, String[] dataValues, String[] osmValues, 338 339 ValueReplacer replacer, boolean replace) { 339 340 String value = p.get(dataKey); … … 358 359 } 359 360 360 private void doAddReplace(IPrimitive p, String dataKey, String osmKey, String osmValue, boolean replace) {361 private static void doAddReplace(IPrimitive p, String dataKey, String osmKey, String osmValue, boolean replace) { 361 362 if (replace) { 362 363 p.remove(dataKey); … … 436 437 437 438 public boolean acceptsUrl(String url) { 438 URL dataURL= getDataURL();439 if ( dataURL != null && url.equals(dataURL.toString())) {439 URL currentDataUrl = getDataURL(); 440 if (currentDataUrl != null && url.equals(currentDataUrl.toString())) { 440 441 return true; 441 442 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/DataSetUpdater.java
r36072 r36173 26 26 * Data set updater. 27 27 */ 28 public abstract classDataSetUpdater {28 public interface DataSetUpdater { 29 29 30 public static finalvoid updateDataSet(DataSet dataSet, AbstractDataSetHandler handler, File associatedFile) {30 static void updateDataSet(DataSet dataSet, AbstractDataSetHandler handler, File associatedFile) { 31 31 if (dataSet != null) { 32 32 if (handler != null) { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/at/AustrianGmlHandler.java
r36072 r36173 18 18 if (crsName != null && crsName.startsWith("AUT")) { 19 19 // CHECKSTYLE.OFF: LineLength 20 if ( crsName.equalsIgnoreCase("AUT-GK28")) { // Gauß-Krüger, Meridianstreifen M2820 if ("AUT-GK28".equalsIgnoreCase(crsName)) { // Gauß-Krüger, Meridianstreifen M28 21 21 return CRS.decode("EPSG:31281"); 22 22 23 } else if ( crsName.equalsIgnoreCase("AUT-GK31")) { // Gauß-Krüger, Meridianstreifen M3123 } else if ("AUT-GK31".equalsIgnoreCase(crsName)) { // Gauß-Krüger, Meridianstreifen M31 24 24 return CRS.decode("EPSG:31282"); 25 25 26 } else if ( crsName.equalsIgnoreCase("AUT-GK34")) { // Gauß-Krüger, Meridianstreifen M3426 } else if ("AUT-GK34".equalsIgnoreCase(crsName)) { // Gauß-Krüger, Meridianstreifen M34 27 27 return CRS.decode("EPSG:31283"); 28 28 29 } else if ( crsName.equalsIgnoreCase("AUT-GK28-5")) { // Gauß-Krüger, Meridianstreifen M28, ohne 5 Mio. im Hochwert29 } else if ("AUT-GK28-5".equalsIgnoreCase(crsName)) { // Gauß-Krüger, Meridianstreifen M28, ohne 5 Mio. im Hochwert 30 30 return CRS.decode("EPSG:31251"); 31 31 32 } else if ( crsName.equalsIgnoreCase("AUT-GK31-5")) { // Gauß-Krüger, Meridianstreifen M31, ohne 5 Mio. im Hochwert32 } else if ("AUT-GK31-5".equalsIgnoreCase(crsName)) { // Gauß-Krüger, Meridianstreifen M31, ohne 5 Mio. im Hochwert 33 33 return CRS.decode("EPSG:31252"); 34 34 35 } else if ( crsName.equalsIgnoreCase("AUT-GK34-5")) { // Gauß-Krüger, Meridianstreifen M34, ohne 5 Mio. im Hochwert35 } else if ("AUT-GK34-5".equalsIgnoreCase(crsName)) { // Gauß-Krüger, Meridianstreifen M34, ohne 5 Mio. im Hochwert 36 36 return CRS.decode("EPSG:31253"); 37 37 38 } else if ( crsName.equalsIgnoreCase("AUT-BM28")) { // Bundesmeldenetz, Meridianstreifen M2838 } else if ("AUT-BM28".equalsIgnoreCase(crsName)) { // Bundesmeldenetz, Meridianstreifen M28 39 39 return CRS.decode("EPSG:31288"); 40 40 41 } else if ( crsName.equalsIgnoreCase("AUT-BM31")) { // Bundesmeldenetz, Meridianstreifen M3141 } else if ("AUT-BM31".equalsIgnoreCase(crsName)) { // Bundesmeldenetz, Meridianstreifen M31 42 42 return CRS.decode("EPSG:31289"); 43 43 44 } else if ( crsName.equalsIgnoreCase("AUT-BM34")) { // Bundesmeldenetz, Meridianstreifen M3444 } else if ("AUT-BM34".equalsIgnoreCase(crsName)) { // Bundesmeldenetz, Meridianstreifen M34 45 45 return CRS.decode("EPSG:31290"); 46 46 47 } else if ( crsName.equalsIgnoreCase("AUT-LM")) { // Lambertsche Kegelprojektion (geogr. Breite des Koo.Ursprungs = 47°30')47 } else if ("AUT-LM".equalsIgnoreCase(crsName)) { // Lambertsche Kegelprojektion (geogr. Breite des Koo.Ursprungs = 47°30') 48 48 return CRS.decode("EPSG:31287"); 49 49 50 } else if ( crsName.equalsIgnoreCase("AUT-LL-BESSEL")) { // Geographische Koordinaten auf dem Bessel-Ellipsoid, Längenzählung nach Greenwich50 } else if ("AUT-LL-BESSEL".equalsIgnoreCase(crsName)) { // Geographische Koordinaten auf dem Bessel-Ellipsoid, Längenzählung nach Greenwich 51 51 // See http://josebatiz.com/granvision/Almap/Install/Data1/_B5694C166D6A4B5390B1E547C6A1FAF6 52 52 // FIXME -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/be/BelgianDataSetHandler.java
r36092 r36173 87 87 public URL getNationalPortalURL() { 88 88 try { 89 String nationalPortalPath = "";89 String nationalPortalPath; 90 90 String lang = Config.getPref().get("language"); 91 91 if (lang == null || lang.isEmpty()) { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/AskLicenseAgreementDialog.java
r36072 r36173 14 14 super(license, MainApplication.getMainFrame(), tr("License Agreement"), new String[] {tr("Accept"), "", tr("Refuse")}); 15 15 16 setToolTipTexts(new String[] { 17 tr("I understand and accept these terms and conditions"), 16 setToolTipTexts(tr("I understand and accept these terms and conditions"), 18 17 tr("View the full text of this license"), 19 tr("I refuse these terms and conditions. Cancel download.") });18 tr("I refuse these terms and conditions. Cancel download.")); 20 19 } 21 20 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/ChooserLauncher.java
r36072 r36173 11 11 public final class ChooserLauncher implements Runnable { 12 12 13 private Projection proj = null;13 private Projection proj; 14 14 private final ProgressMonitor progressMonitor; 15 15 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/ModuleListPanel.java
r36072 r36173 7 7 import java.awt.GridBagLayout; 8 8 import java.awt.Insets; 9 import java.awt.event.ActionEvent;10 import java.awt.event.ActionListener;11 9 import java.util.List; 12 10 … … 14 12 import javax.swing.JLabel; 15 13 import javax.swing.SwingConstants; 16 import javax.swing.event.HyperlinkEvent;17 14 import javax.swing.event.HyperlinkEvent.EventType; 18 import javax.swing.event.HyperlinkListener;19 15 20 16 import org.openstreetmap.josm.gui.widgets.HtmlPanel; … … 28 24 */ 29 25 public class ModuleListPanel extends VerticallyScrollablePanel { 30 private ModulePreferencesModel model;26 private final ModulePreferencesModel model; 31 27 32 28 public ModuleListPanel() { … … 42 38 protected String formatModuleRemoteVersion(ModuleInformation pi) { 43 39 StringBuilder sb = new StringBuilder(); 44 if (pi.version == null || pi.version.trim(). equals("")) {40 if (pi.version == null || pi.version.trim().isEmpty()) { 45 41 sb.append(tr("unknown")); 46 42 } else { … … 52 48 protected String formatModuleLocalVersion(ModuleInformation pi) { 53 49 if (pi == null) return tr("unknown"); 54 if (pi.localversion == null || pi.localversion.trim(). equals(""))50 if (pi.localversion == null || pi.localversion.trim().isEmpty()) 55 51 return tr("unknown"); 56 52 return pi.localversion; … … 106 102 cbModule.setSelected(selected); 107 103 cbModule.setToolTipText(formatCheckboxTooltipText(pi)); 108 cbModule.addActionListener(new ActionListener() { 109 @Override 110 public void actionPerformed(ActionEvent e) { 111 model.setModuleSelected(pi.getName(), cbModule.isSelected()); 112 } 113 }); 104 cbModule.addActionListener(e -> model.setModuleSelected(pi.getName(), cbModule.isSelected())); 114 105 JLabel lblModule = new JLabel( 115 106 tr("{0}: Version {1} (local: {2})", pi.getName(), remoteversion, localversion), … … 130 121 HtmlPanel description = new HtmlPanel(); 131 122 description.setText(pi.getDescriptionAsHtml()); 132 description.getEditorPane().addHyperlinkListener(new HyperlinkListener() { 133 @Override 134 public void hyperlinkUpdate(HyperlinkEvent e) { 135 if (e.getEventType() == EventType.ACTIVATED) { 136 OpenBrowser.displayUrl(e.getURL().toString()); 137 } 123 description.getEditorPane().addHyperlinkListener(e -> { 124 if (e.getEventType() == EventType.ACTIVATED) { 125 OpenBrowser.displayUrl(e.getURL().toString()); 138 126 } 139 127 }); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/ModulePreference.java
r36072 r36173 159 159 @Override 160 160 public void addGui(final PreferenceTabbedPane gui) { 161 GridBagConstraints gc = new GridBagConstraints();162 gc.weightx = 1.0;163 gc.weighty = 1.0;164 gc.anchor = GridBagConstraints.NORTHWEST;165 gc.fill = GridBagConstraints.BOTH;166 161 OdPreferenceSetting settings = gui.getSetting(OdPreferenceSetting.class); 167 162 settings.tabPane.addTab(tr("Modules"), buildModuleListPanel()); … … 209 204 */ 210 205 public List<ModuleInformation> getModulesScheduledForUpdateOrDownload() { 211 return model != null ? model.getModulesScheduledForUpdateOrDownload() : null;206 return model.getModulesScheduledForUpdateOrDownload(); 212 207 } 213 208 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/ModulePreferencesModel.java
r36072 r36173 6 6 import java.util.Collection; 7 7 import java.util.Collections; 8 import java.util.Comparator;9 8 import java.util.HashMap; 10 9 import java.util.HashSet; 11 10 import java.util.LinkedList; 12 11 import java.util.List; 12 import java.util.Locale; 13 13 import java.util.Set; 14 14 … … 19 19 import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleInformation; 20 20 import org.openstreetmap.josm.spi.preferences.Config; 21 import org.openstreetmap.josm.tools.Logging; 21 22 22 23 public class ModulePreferencesModel extends ChangeNotifier { … … 24 25 private final ArrayList<ModuleInformation> displayedModules = new ArrayList<>(); 25 26 private final HashMap<ModuleInformation, Boolean> selectedModulesMap = new HashMap<>(); 26 private Set<String> pendingDownloads = new HashSet<>();27 private final Set<String> pendingDownloads = new HashSet<>(); 27 28 private String filterExpression; 28 29 private final Set<String> currentActiveModules; … … 62 63 Set<String> activeModules = new HashSet<>(getModules(Collections.emptyList())); 63 64 for (ModuleInformation pi: availableModules) { 64 if (selectedModulesMap.get(pi) == null) { 65 if (activeModules.contains(pi.name)) { 66 selectedModulesMap.put(pi, true); 67 } 65 if (selectedModulesMap.get(pi) == null && activeModules.contains(pi.name)) { 66 selectedModulesMap.put(pi, true); 68 67 } 69 68 } … … 95 94 Set<String> activeModules = new HashSet<>(getModules(Collections.emptyList())); 96 95 for (ModuleInformation pi: availableModules) { 97 if (selectedModulesMap.get(pi) == null) { 98 if (activeModules.contains(pi.name)) { 99 selectedModulesMap.put(pi, true); 100 } 96 if (selectedModulesMap.get(pi) == null && activeModules.contains(pi.name)) { 97 selectedModulesMap.put(pi, true); 101 98 } 102 99 } … … 115 112 continue; 116 113 } 117 if ( selectedModulesMap.get(pi)) {114 if (Boolean.TRUE.equals(selectedModulesMap.get(pi))) { 118 115 ret.add(pi); 119 116 } … … 125 122 * Replies the list of selected module information objects 126 123 * 127 * @return the list of selected module information objects124 * @return the set of selected module information objects 128 125 */ 129 126 public Set<String> getSelectedModuleNames() { … … 139 136 */ 140 137 protected void sort() { 141 Collections.sort( 142 availableModules, 143 new Comparator<ModuleInformation>() { 144 @Override 145 public int compare(ModuleInformation o1, ModuleInformation o2) { 146 String n1 = o1.getName() == null ? "" : o1.getName().toLowerCase(); 147 String n2 = o2.getName() == null ? "" : o2.getName().toLowerCase(); 148 return n1.compareTo(n2); 149 } 150 } 151 ); 152 } 153 154 /** 155 * Replies the list of module informations to display 156 * 157 * @return the list of module informations to display 138 availableModules.sort((o1, o2) -> { 139 String n1 = o1.getName() == null ? "" : o1.getName().toLowerCase(Locale.ROOT); 140 String n2 = o2.getName() == null ? "" : o2.getName().toLowerCase(Locale.ROOT); 141 return n1.compareTo(n2); 142 }); 143 } 144 145 /** 146 * Replies the list of module information to display 147 * 148 * @return the list of module information to display 158 149 */ 159 150 public List<ModuleInformation> getDisplayedModules() { … … 225 216 } 226 217 227 /* *218 /* 228 219 * Initializes the model from preferences 229 220 */ … … 257 248 } 258 249 259 /* *250 /* 260 251 * Replies the set of modules which have been added by the user to 261 252 * the set of activated modules. … … 275 266 }*/ 276 267 277 /* *268 /* 278 269 * Replies the set of modules which have been removed by the user from 279 270 * the set of activated modules. … … 294 285 }*/ 295 286 296 /* *287 /* 297 288 * Replies the set of module names which have been added by the user to 298 289 * the set of activated modules. … … 350 341 oldinfo.localversion = newinfo.version; 351 342 } catch (ModuleException e) { 352 e.printStackTrace();343 Logging.debug(e); 353 344 } 354 345 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/OdPreferenceSetting.java
r36072 r36173 58 58 * @return the collection of module site URLs from where module lists can be downloaded 59 59 */ 60 public static finalCollection<String> getModuleSites() {60 public static Collection<String> getModuleSites() { 61 61 return Config.getPref().getList(OdConstants.PREF_MODULES_SITES, Arrays.asList(OdConstants.DEFAULT_MODULE_SITES)); 62 62 } … … 153 153 // 154 154 final Runnable continuation = () -> { 155 boolean requiresRestart = false; 156 if (task != null && !task.isCanceled()) { 157 if (!task.getDownloadedModules().isEmpty()) { 158 requiresRestart = true; 159 } 160 } 155 boolean requiresRestart = task != null && !task.isCanceled() && !task.getDownloadedModules().isEmpty(); 161 156 162 157 // build the messages. We only display one message, including the status … … 200 195 } 201 196 202 return task == null ? result : false;197 return task == null && result; 203 198 } 204 199 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/ProjectionChooser.java
r36072 r36173 7 7 import java.awt.Dimension; 8 8 import java.awt.GridBagLayout; 9 import java.awt.event.ActionEvent;10 9 import java.awt.event.ActionListener; 11 10 … … 44 43 */ 45 44 private JPanel projSubPrefPanel; 46 private JPanel projSubPrefPanelWrapper = new JPanel(new GridBagLayout());45 private final JPanel projSubPrefPanelWrapper = new JPanel(new GridBagLayout()); 47 46 48 47 private JLabel projectionCodeLabel; 49 48 private Component projectionCodeGlue; 50 private JLabel projectionCode = new JLabel();49 private final JLabel projectionCode = new JLabel(); 51 50 private JLabel projectionNameLabel; 52 51 private Component projectionNameGlue; 53 private JLabel projectionName = new JLabel();54 private JLabel bounds = new JLabel();52 private final JLabel projectionName = new JLabel(); 53 private final JLabel bounds = new JLabel(); 55 54 56 55 /** … … 77 76 78 77 public void addGui() { 78 projectionCodeLabel = new JLabel(tr("Projection code")); 79 projectionCodeGlue = GBC.glue(5, 0); 80 projectionNameLabel = new JLabel(tr("Projection name")); 81 projectionNameGlue = GBC.glue(5, 0); 79 82 projPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); 80 83 projPanel.setLayout(new GridBagLayout()); … … 82 85 projPanel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL)); 83 86 projPanel.add(projectionCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0, 5, 5, 5)); 84 projPanel.add(projectionCodeLabel = new JLabel(tr("Projection code")), GBC.std().insets(25, 5, 0, 5));85 projPanel.add(projectionCodeGlue = GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));87 projPanel.add(projectionCodeLabel, GBC.std().insets(25, 5, 0, 5)); 88 projPanel.add(projectionCodeGlue, GBC.std().fill(GBC.HORIZONTAL)); 86 89 projPanel.add(projectionCode, GBC.eop().fill(GBC.HORIZONTAL).insets(0, 5, 5, 5)); 87 projPanel.add(projectionNameLabel = new JLabel(tr("Projection name")), GBC.std().insets(25, 5, 0, 5));88 projPanel.add(projectionNameGlue = GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));90 projPanel.add(projectionNameLabel, GBC.std().insets(25, 5, 0, 5)); 91 projPanel.add(projectionNameGlue, GBC.std().fill(GBC.HORIZONTAL)); 89 92 projPanel.add(projectionName, GBC.eop().fill(GBC.HORIZONTAL).insets(0, 5, 5, 5)); 90 93 projPanel.add(new JLabel(tr("Bounds")), GBC.std().insets(25, 5, 0, 5)); … … 94 97 95 98 selectedProjectionChanged((ProjectionChoice) projectionCombo.getSelectedItem()); 96 projectionCombo.addActionListener(new ActionListener() { 97 @Override 98 public void actionPerformed(ActionEvent e) { 99 ProjectionChoice pc = (ProjectionChoice) projectionCombo.getSelectedItem(); 100 selectedProjectionChanged(pc); 101 } 99 projectionCombo.addActionListener(e -> { 100 ProjectionChoice pc = (ProjectionChoice) projectionCombo.getSelectedItem(); 101 selectedProjectionChanged(pc); 102 102 }); 103 103 setContent(projPanel); … … 110 110 return; 111 111 112 final ActionListener listener = new ActionListener() { 113 @Override 114 public void actionPerformed(ActionEvent e) { 115 updateMeta(pc); 116 } 117 }; 112 final ActionListener listener = e -> updateMeta(pc); 118 113 119 114 // Replace old panel with new one -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/LambertCC9ZonesProjectionPatterns.java
r36072 r36173 14 14 static { 15 15 for (int i = 0; i < lambertCC9Zones.length; i++) { 16 lambertCC9Zones[i] = Projections.getProjectionByCode("EPSG:" +Integer.toString(3942+i));16 lambertCC9Zones[i] = Projections.getProjectionByCode("EPSG:" + (3942 + i)); 17 17 } 18 18 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/NeptuneReader.java
r36072 r36173 86 86 private final Map<String, OsmPrimitive> tridentObjects = new HashMap<>(); 87 87 88 public static finalboolean acceptsXmlNeptuneFile(File file) {88 public static boolean acceptsXmlNeptuneFile(File file) { 89 89 return acceptsXmlNeptuneFile(file, null); 90 90 } 91 91 92 public static finalboolean acceptsXmlNeptuneFile(File file, URL schemaURL) {92 public static boolean acceptsXmlNeptuneFile(File file, URL schemaURL) { 93 93 94 94 if (schemaURL == null) { … … 105 105 Logging.info(xmlFile.getSystemId() + " is valid"); 106 106 return true; 107 } catch (SAXException e) {107 } catch (SAXException | IOException e) { 108 108 Logging.error(xmlFile.getSystemId() + " is NOT valid"); 109 109 Logging.error("Reason: " + e.getLocalizedMessage()); 110 } catch (IOException e) { 111 Logging.error(xmlFile.getSystemId() + " is NOT valid"); 112 Logging.error("Reason: " + e.getLocalizedMessage()); 110 Logging.debug(e); 113 111 } 114 112 } catch (IOException e) { … … 123 121 } 124 122 125 protected static final<T> T unmarshal(Class<T> docClass, InputStream inputStream) throws JAXBException {123 protected static <T> T unmarshal(Class<T> docClass, InputStream inputStream) throws JAXBException { 126 124 String packageName = docClass.getPackage().getName(); 127 125 JAXBContext jc = JAXBContext.newInstance(packageName, NeptuneReader.class.getClassLoader()); … … 215 213 } 216 214 217 protected final<T extends TridentObjectType> T findTridentObject(List<T> list, String id) {215 protected static <T extends TridentObjectType> T findTridentObject(List<T> list, String id) { 218 216 for (T object : list) { 219 217 if (object.getObjectId().equals(id)) { … … 343 341 Logging.warn("Cannot find StopPoint: "+grandchildId); 344 342 } else { 345 if (grandchild.getLongLatType() .equals(LongLatTypeType.WGS_84)) {343 if (grandchild.getLongLatType() == LongLatTypeType.WGS_84) { 346 344 Node platform = createPlatform(grandchild); 347 345 stopArea.addMember(new RelationMember(OSM_PLATFORM, platform)); … … 358 356 if (areaCentroid == null) { 359 357 Logging.warn("Cannot find AreaCentroid: "+centroidId); 360 } else if ( !areaCentroid.getLongLatType().equals(LongLatTypeType.WGS_84)) {358 } else if (areaCentroid.getLongLatType() != LongLatTypeType.WGS_84) { 361 359 Logging.warn("Unsupported long/lat type: "+areaCentroid.getLongLatType()); 362 360 } else { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/NetworkReader.java
r36072 r36173 5 5 6 6 import java.io.File; 7 import java.io.IOException; 7 8 import java.io.InputStream; 8 9 import java.util.HashMap; 10 import java.util.Locale; 9 11 import java.util.Map; 10 12 import java.util.regex.Matcher; 11 13 import java.util.regex.Pattern; 14 15 import javax.xml.stream.XMLStreamException; 12 16 13 17 import org.openstreetmap.josm.data.osm.DataSet; … … 16 20 import org.openstreetmap.josm.io.Compression; 17 21 import org.openstreetmap.josm.io.GeoJSONReader; 22 import org.openstreetmap.josm.io.IllegalDataException; 18 23 import org.openstreetmap.josm.io.OsmServerReader; 19 24 import org.openstreetmap.josm.io.OsmTransferException; … … 121 126 } 122 127 123 private Class<? extends AbstractReader> findReaderByExtension(String filename) {124 filename = filename.replace("\"", "").toLowerCase( );125 for ( String ext : FILE_AND_ARCHIVE_READERS.keySet()) {126 if (filename.endsWith("."+e xt)) {127 return FILE_AND_ARCHIVE_READERS.get(ext);128 private static Class<? extends AbstractReader> findReaderByExtension(String filename) { 129 filename = filename.replace("\"", "").toLowerCase(Locale.ROOT); 130 for (Map.Entry<String, Class<? extends AbstractReader>> entry : FILE_AND_ARCHIVE_READERS.entrySet()) { 131 if (filename.endsWith("."+entry.getKey())) { 132 return entry.getValue(); 128 133 } 129 134 } … … 142 147 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 143 148 InputStream in = null; 144 ProgressMonitor instance = null;149 ProgressMonitor instance; 145 150 try { 146 151 in = getInputStreamRaw(url, progressMonitor); … … 176 181 return GeoJSONReader.parseDataSet(in, instance); 177 182 } else if (readerClass.equals(MifReader.class)) { 178 return MifReader.parseDataSet(in, null, handler , instance);183 return MifReader.parseDataSet(in, null, handler); 179 184 } else if (readerClass.equals(ShpReader.class)) { 180 185 return ShpReader.parseDataSet(in, null, handler, instance); … … 192 197 throw new IllegalArgumentException("Unsupported reader class: "+readerClass.getName()); 193 198 } 194 } catch (OsmTransferException e) { 195 throw e; 196 } catch (Exception e) { 199 } catch (IOException | XMLStreamException | IllegalDataException e) { 197 200 if (cancel) 198 201 return null; … … 205 208 in.close(); 206 209 } 207 } catch ( Exception e) {210 } catch (IOException e) { 208 211 Logging.trace(e); 209 212 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/OverpassApi.java
r36072 r36173 43 43 } 44 44 45 public static finalStringBuilder union(CharSequence... queries) {45 public static StringBuilder union(CharSequence... queries) { 46 46 StringBuilder result = new StringBuilder("<union>\n"); 47 47 for (CharSequence query : queries) { … … 54 54 } 55 55 56 public static finalStringBuilder query(String bbox, OaQueryType type, CharSequence... conditions) {56 public static StringBuilder query(String bbox, OaQueryType type, CharSequence... conditions) { 57 57 StringBuilder result = new StringBuilder("<query type=\"").append(type).append("\" >\n"); 58 58 if (bbox != null) { … … 68 68 } 69 69 70 public static finalString recurse(OaRecurseType type, String into) {70 public static String recurse(OaRecurseType type, String into) { 71 71 return "<recurse type=\""+type+"\" into=\""+into+"\"/>\n"; 72 72 } 73 73 74 public static finalString recurse(OaRecurseType... types) {75 String result = "";74 public static String recurse(OaRecurseType... types) { 75 StringBuilder result = new StringBuilder(); 76 76 for (OaRecurseType type : types) { 77 result += "<recurse type=\""+type+"\"/>\n";77 result.append("<recurse type=\"").append(type).append("\"/>\n"); 78 78 } 79 return result ;79 return result.toString(); 80 80 } 81 81 82 public static finalString print() {82 public static String print() { 83 83 return "<print mode=\"meta\"/>"; 84 84 } 85 85 86 public static finalString hasKey(String key) {86 public static String hasKey(String key) { 87 87 return hasKey(key, null); 88 88 } 89 89 90 public static finalString hasKey(String key, String value) {90 public static String hasKey(String key, String value) { 91 91 return "<has-kv k=\""+key+"\" "+(value != null && !value.isEmpty() ? "v=\""+value+"\"" : "")+" />"; 92 92 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/ProjectionPatterns.java
r36072 r36173 52 52 } 53 53 54 public static finalPattern getCoordinatePattern(String coor, String proj) {54 public static Pattern getCoordinatePattern(String coor, String proj) { 55 55 if (proj != null && !proj.isEmpty()) { 56 56 return Pattern.compile("(?:.*(?:"+coor+").*(?:"+proj+").*)|(?:.*("+proj+").*(?:"+coor+").*)", Pattern.CASE_INSENSITIVE); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ArchiveReader.java
r36072 r36173 12 12 import java.util.HashMap; 13 13 import java.util.List; 14 import java.util.Locale; 14 15 import java.util.Map; 15 16 … … 154 155 instance = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 155 156 } 156 final String lowerCaseName = f.getName().toLowerCase( );157 final String lowerCaseName = f.getName().toLowerCase(Locale.ROOT); 157 158 if (lowerCaseName.endsWith(OdConstants.CSV_EXT)) { 158 159 from = CsvReader.parseDataSet(in, handler, instance); … … 168 169 from = ShpReader.parseDataSet(in, f, handler, instance); 169 170 } else if (lowerCaseName.endsWith(OdConstants.MIF_EXT)) { 170 from = MifReader.parseDataSet(in, f, handler , instance);171 from = MifReader.parseDataSet(in, f, handler); 171 172 } else if (lowerCaseName.endsWith(OdConstants.TAB_EXT)) { 172 173 from = TabReader.parseDataSet(in, f, handler, instance); … … 190 191 // Test file name to see if it may contain useful data 191 192 for (String ext : NetworkReader.FILE_READERS.keySet()) { 192 if (entryName.toLowerCase( ).endsWith("."+ext)) {193 if (entryName.toLowerCase(Locale.ROOT).endsWith("."+ext)) { 193 194 candidates.add(file); 194 195 break; -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/DefaultArchiveHandler.java
r36072 r36173 6 6 public class DefaultArchiveHandler implements ArchiveHandler { 7 7 8 private boolean skipXsdValidation = false;8 private boolean skipXsdValidation; 9 9 10 10 @Override -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ZipReader.java
r36072 r36173 27 27 private final ZipInputStream zis; 28 28 29 private ZipEntry entry;30 31 29 public ZipReader(InputStream in, AbstractDataSetHandler handler, boolean promptUser) { 32 30 super(handler, handler != null ? handler.getArchiveHandler() : null, promptUser); … … 46 44 @Override 47 45 protected void extractArchive(final File temp, final List<File> candidates) throws IOException, FileNotFoundException { 46 ZipEntry entry; 48 47 while ((entry = zis.getNextEntry()) != null) { 49 48 Logging.debug("Extracting {0}", entry.getName()); … … 63 62 try (FileOutputStream fos = new FileOutputStream(file)) { 64 63 byte[] buffer = new byte[8192]; 65 int count = 0;64 int count; 66 65 while ((count = zis.read(buffer, 0, buffer.length)) > 0) { 67 66 fos.write(buffer, 0, count); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/AbstractMapInfoReader.java
r36072 r36173 12 12 import java.util.ArrayList; 13 13 import java.util.List; 14 import java.util.Locale; 14 15 15 16 import org.openstreetmap.josm.data.osm.DataSet; … … 51 52 protected final File getDataFile(File headerFile, String extension) { 52 53 String filename = headerFile.getName().substring(0, headerFile.getName().lastIndexOf('.')); 53 File dataFile = new File(headerFile.getParent() + File.separator + filename + extension.toUpperCase( ));54 File dataFile = new File(headerFile.getParent() + File.separator + filename + extension.toUpperCase(Locale.ROOT)); 54 55 if (!dataFile.exists()) { 55 dataFile = new File(headerFile.getParent() + File.separator + filename + extension.toLowerCase( ));56 dataFile = new File(headerFile.getParent() + File.separator + filename + extension.toLowerCase(Locale.ROOT)); 56 57 } 57 58 return dataFile; -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/DefaultGeographicHandler.java
r36072 r36173 10 10 11 11 private boolean useNodeMap = true; 12 private boolean checkNodeProximity = false;13 private boolean preferMultipolygonToSimpleWay = false;12 private boolean checkNodeProximity; 13 private boolean preferMultipolygonToSimpleWay; 14 14 15 15 @Override -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeographicReader.java
r36122 r36173 18 18 import java.util.TreeMap; 19 19 20 import jakarta.json.JsonArray;21 import jakarta.json.JsonObject;22 import jakarta.json.JsonReader;23 import jakarta.json.spi.JsonProvider;24 20 import javax.swing.JOptionPane; 25 21 … … 69 65 import org.openstreetmap.josm.tools.Utils; 70 66 67 import jakarta.json.JsonArray; 68 import jakarta.json.JsonObject; 69 import jakarta.json.JsonReader; 70 import jakarta.json.spi.JsonProvider; 71 71 72 /** 72 73 * Superclass of geographic format readers (currently GML, GPKG, and SHP). … … 181 182 Way tempWay = new Way(); 182 183 if (ls != null) { 183 final List<Node> nodes = new ArrayList<>(ls.getNumPoints());184 final List<Node> lsNodes = new ArrayList<>(ls.getNumPoints()); 184 185 // Build list of nodes 185 186 for (int i = 0; i < ls.getNumPoints(); i++) { 186 187 try { 187 nodes.add(createOrGetNode(ls.getPointN(i)));188 lsNodes.add(createOrGetNode(ls.getPointN(i))); 188 189 } catch (TransformException | IllegalArgumentException e) { 189 190 Logging.error("Exception for " + ls + ": " + e.getClass().getName() + ": " + e.getMessage()); 190 191 } 191 192 } 192 tempWay.setNodes( nodes);193 tempWay.setNodes(lsNodes); 193 194 // Find possible duplicated ways 194 195 if (tempWay.getNodesCount() > 0) { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeotoolsConverter.java
r36076 r36173 276 276 277 277 private static void readNonGeometricAttributes(Feature feature, OsmPrimitive primitive) { 278 try { 279 Collection<Property> properties = feature.getProperties(); 280 Map<String, String> tagMap = new LinkedHashMap<>(properties.size()); 281 for (Property prop : properties) { 282 if (!(prop instanceof GeometryAttribute)) { 283 Name name = prop.getName(); 284 Object value = prop.getValue(); 285 if (name != null && value != null) { 286 String sName = name.toString(); 287 String sValue = value.toString(); 288 if (value instanceof Date) { 289 sValue = new SimpleDateFormat("yyyy-MM-dd").format(value); 290 } 291 if (!sName.isEmpty() && !sValue.isEmpty()) { 292 tagMap.put(sName, sValue); 293 //primitive.put(sName, sValue); 294 } 295 } 296 } 297 } 298 primitive.putAll(tagMap); 299 } catch (Exception e) { 300 Logging.error(e); 301 } 278 Collection<Property> properties = feature.getProperties(); 279 Map<String, String> tagMap = new LinkedHashMap<>(properties.size()); 280 for (Property prop : properties) { 281 if (!(prop instanceof GeometryAttribute)) { 282 Name name = prop.getName(); 283 Object value = prop.getValue(); 284 if (name != null && value != null) { 285 String sName = name.toString(); 286 String sValue = value.toString(); 287 if (value instanceof Date) { 288 sValue = new SimpleDateFormat("yyyy-MM-dd").format(value); 289 } 290 if (!sName.isEmpty() && !sValue.isEmpty()) { 291 tagMap.put(sName, sValue); 292 //primitive.put(sName, sValue); 293 } 294 } 295 } 296 } 297 primitive.putAll(tagMap); 302 298 } 303 299 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeotoolsHandler.java
r36025 r36173 51 51 if (getCrsFor(sourceCRS.getName().getCode()) != null) { 52 52 return CRS.findMathTransform(getCrsFor(sourceCRS.getName().getCode()), targetCRS, lenient); 53 } else if (sourceCRS instanceof AbstractDerivedCRS && sourceCRS.getName().getCode().equalsIgnoreCase("Lambert_Conformal_Conic")) {53 } else if (sourceCRS instanceof AbstractDerivedCRS && "Lambert_Conformal_Conic".equalsIgnoreCase(sourceCRS.getName().getCode())) { 54 54 List<MathTransform> result = new ArrayList<>(); 55 55 AbstractDerivedCRS crs = (AbstractDerivedCRS) sourceCRS; … … 93 93 } catch (FactoryException e) { 94 94 Logging.error(e.getMessage()); 95 Logging.debug(e); 95 96 } 96 97 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GmlImporter.java
r36072 r36173 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.IOException; 6 7 import java.io.InputStream; 8 9 import javax.xml.stream.XMLStreamException; 7 10 8 11 import org.openstreetmap.josm.actions.ExtensionFileFilter; … … 27 30 try { 28 31 return GmlReader.parseDataSet(in, handler, instance); 29 } catch ( Exception e) {32 } catch (IOException | XMLStreamException e) { 30 33 throw new IllegalDataException(e); 31 34 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GmlReader.java
r36072 r36173 18 18 import org.opengis.geometry.MismatchedDimensionException; 19 19 import org.opengis.referencing.FactoryException; 20 import org.opengis.referencing.NoSuchAuthorityCodeException;21 20 import org.opengis.referencing.crs.CoordinateReferenceSystem; 22 21 import org.opengis.referencing.operation.MathTransform; … … 55 54 private final GmlHandler gmlHandler; 56 55 57 private XMLStreamReader parser;56 private final XMLStreamReader parser; 58 57 59 58 private int dim; … … 84 83 try { 85 84 return new GmlReader(parser, handler != null ? handler.getGmlHandler() : null).parseDoc(instance); 86 } catch (Exception e) { 85 } catch (XMLStreamException | GeoCrsException | FactoryException | GeoMathTransformException | 86 TransformException e) { 87 87 throw new IOException(e); 88 88 } … … 110 110 } 111 111 112 private void findCRS(String srs) throws NoSuchAuthorityCodeException,FactoryException {112 private void findCRS(String srs) throws FactoryException { 113 113 Logging.info("Finding CRS for "+srs); 114 114 if (gmlHandler != null) { … … 150 150 UserCancelException, GeoMathTransformException, MismatchedDimensionException, TransformException { 151 151 Way way = null; 152 Node node = null;152 Node node; 153 153 Map<String, StringBuilder> tags = new HashMap<>(); 154 154 OsmPrimitive prim = null; … … 195 195 } 196 196 } else if (event == XMLStreamConstants.CHARACTERS && key != null) { 197 StringBuilder sb = tags.get(key); 198 if (sb == null) { 199 sb = new StringBuilder(); 200 tags.put(key, sb); 201 } 197 StringBuilder sb = tags.computeIfAbsent(key, k -> new StringBuilder()); 202 198 sb.append(parser.getTextCharacters(), parser.getTextStart(), parser.getTextLength()); 203 199 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/KmlKmzImporter.java
r36072 r36173 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.IOException; 6 7 import java.io.InputStream; 8 import java.util.Locale; 9 10 import javax.xml.stream.XMLStreamException; 7 11 8 12 import org.openstreetmap.josm.actions.ExtensionFileFilter; … … 30 34 throws IllegalDataException { 31 35 try { 32 if (file != null && file.getName().toLowerCase( ).endsWith(OdConstants.KML_EXT)) {36 if (file != null && file.getName().toLowerCase(Locale.ROOT).endsWith(OdConstants.KML_EXT)) { 33 37 return KmlReader.parseDataSet(in, instance); 34 38 } else { 35 39 return KmzReader.parseDataSet(in, instance); 36 40 } 37 } catch ( Exception e) {41 } catch (IOException | XMLStreamException e) { 38 42 throw new IllegalDataException(e); 39 43 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/KmlReader.java
r36072 r36173 54 54 // CHECKSTYLE.ON: SingleSpaceSeparator 55 55 56 public static Pattern COLOR_PATTERN = Pattern.compile("\\p{XDigit}{8}");57 58 private XMLStreamReader parser;59 private Map<LatLon, Node> nodes = new HashMap<>();56 public static final Pattern COLOR_PATTERN = Pattern.compile("\\p{XDigit}{8}"); 57 58 private final XMLStreamReader parser; 59 private final Map<LatLon, Node> nodes = new HashMap<>(); 60 60 61 61 public KmlReader(XMLStreamReader parser) { … … 65 65 public static DataSet parseDataSet(InputStream in, ProgressMonitor instance) 66 66 throws IOException, XMLStreamException, FactoryConfigurationError { 67 InputStreamReader ir = UTFInputStreamReader.create(in); 68 XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(ir); 69 return new KmlReader(parser).parseDoc(); 67 try (InputStreamReader ir = UTFInputStreamReader.create(in)) { 68 XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(ir); 69 return new KmlReader(parser).parseDoc(); 70 } 70 71 } 71 72 … … 80 81 while (parser.hasNext()) { 81 82 int event = parser.next(); 82 if (event == XMLStreamConstants.START_ELEMENT) { 83 if (parser.getLocalName().equals(KML_PLACEMARK)) { 84 parsePlaceMark(ds); 85 } 83 if (event == XMLStreamConstants.START_ELEMENT && parser.getLocalName().equals(KML_PLACEMARK)) { 84 parsePlaceMark(ds); 86 85 } 87 86 } … … 129 128 } 130 129 } else if (parser.getLocalName().equals(KML_POLYGON)) { 131 ds.addPrimitive(relation = new Relation()); 130 relation = new Relation(); 131 ds.addPrimitive(relation); 132 132 relation.put("type", "multipolygon"); 133 133 list.add(relation); … … 138 138 } else if (parser.getLocalName().equals(KML_LINEAR_RING)) { 139 139 if (relation != null) { 140 ds.addPrimitive(way = new Way()); 140 way = new Way(); 141 ds.addPrimitive(way); 141 142 wayNodes = new ArrayList<>(); 142 143 relation.addMember(new RelationMember(role, way)); … … 147 148 list.add(way); 148 149 } else if (parser.getLocalName().equals(KML_COORDINATES)) { 149 String[] tab = parser.getElementText().trim().split("\\s" );150 for ( int i = 0; i < tab.length; i++) {151 node = parseNode(ds, wayNodes, node, tab[i].split(","));150 String[] tab = parser.getElementText().trim().split("\\s", Pattern.UNICODE_CHARACTER_CLASS); 151 for (String s : tab) { 152 node = parseNode(ds, wayNodes, node, s.split(",")); 152 153 } 153 154 } else if (parser.getLocalName().equals(KML_EXT_COORD)) { 154 node = parseNode(ds, wayNodes, node, parser.getElementText().trim().split("\\s" ));155 node = parseNode(ds, wayNodes, node, parser.getElementText().trim().split("\\s", Pattern.UNICODE_CHARACTER_CLASS)); 155 156 if (node != null && when > 0) { 156 157 node.setRawTimestamp((int) when); … … 158 159 } else if (parser.getLocalName().equals(KML_WHEN)) { 159 160 when = DateUtils.tsFromString(parser.getElementText().trim()); 160 } else if (parser.getLocalName().equals(KML_EXT_LANG)) { 161 if (KML_NAME.equals(previousName)) { 162 tags.put(KML_NAME, parser.getElementText()); 163 } 161 } else if (parser.getLocalName().equals(KML_EXT_LANG) && KML_NAME.equals(previousName)) { 162 tags.put(KML_NAME, parser.getElementText()); 164 163 } 165 164 previousName = parser.getLocalName(); … … 179 178 } 180 179 for (OsmPrimitive p : list) { 181 for (String key : tags.keySet()) { 182 p.put(key, tags.get(key)); 183 } 180 p.putAll(tags); 184 181 } 185 182 } … … 187 184 private Node parseNode(DataSet ds, List<Node> wayNodes, Node node, String[] values) { 188 185 if (values.length >= 2) { 189 LatLon ll = new LatLon(Double.valueOf(values[1]), Double.valueOf(values[0])).getRoundedToOsmPrecision(); 190 node = nodes.get(ll); 191 if (node == null) { 192 ds.addPrimitive(node = new Node(ll)); 193 nodes.put(ll, node); 194 if (values.length > 2 && !values[2].equals("0")) { 195 node.put("ele", values[2]); 186 LatLon ll = new LatLon(Double.parseDouble(values[1]), Double.parseDouble(values[0])).getRoundedToOsmPrecision(); 187 node = nodes.computeIfAbsent(ll, latLon -> { 188 Node tNode = new Node(latLon); 189 ds.addPrimitive(tNode); 190 if (values.length > 2 && !"0".equals(values[2])) { 191 tNode.put("ele", values[2]); 196 192 } 197 } 193 return tNode; 194 }); 198 195 if (wayNodes != null) { 199 196 wayNodes.add(node); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/KmzReader.java
r36072 r36173 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 import java.util.Locale; 8 9 import java.util.zip.ZipEntry; 9 10 import java.util.zip.ZipInputStream; … … 15 16 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 16 17 import org.openstreetmap.josm.io.AbstractReader; 17 import org.openstreetmap.josm.io.IllegalDataException;18 18 import org.openstreetmap.josm.tools.Logging; 19 19 20 public class KmzReader extends AbstractReader { 20 /** 21 * Read kmz files 22 */ 23 public final class KmzReader extends AbstractReader { 21 24 22 private ZipInputStream zis;25 private final ZipInputStream zis; 23 26 24 public KmzReader(ZipInputStream zis) { 27 /** 28 * Create a new {@link KmzReader} 29 * @param zis The stream to read 30 */ 31 KmzReader(ZipInputStream zis) { 25 32 this.zis = zis; 26 33 } 27 34 35 /** 36 * Parse a dataset from a stream 37 * @param in The stream to read 38 * @param instance The progress monitor to update 39 * @return The dataset 40 * @throws IOException If there was an issue reading the stream 41 * @throws XMLStreamException If there was an issue with the XML 42 * @throws FactoryConfigurationError If there was an issue with creating the xml factory 43 */ 28 44 public static DataSet parseDataSet(InputStream in, ProgressMonitor instance) 29 45 throws IOException, XMLStreamException, FactoryConfigurationError { … … 33 49 @Override 34 50 protected DataSet doParseDataSet(InputStream source, 35 ProgressMonitor progressMonitor) throws IllegalDataException{51 ProgressMonitor progressMonitor) { 36 52 return null; 37 53 } … … 45 61 return null; 46 62 } 47 } while (!entry.getName().toLowerCase( ).endsWith(".kml"));63 } while (!entry.getName().toLowerCase(Locale.ROOT).endsWith(".kml")); 48 64 long size = entry.getSize(); 49 65 byte[] buffer; … … 51 67 buffer = new byte[(int) size]; 52 68 int off = 0; 53 int count = 0;69 int count; 54 70 while ((count = zis.read(buffer, off, (int) size)) > 0) { 55 71 off += count; -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/MifReader.java
r36092 r36173 16 16 import java.nio.charset.Charset; 17 17 import java.util.Arrays; 18 import java.util.Locale; 18 19 19 20 import org.openstreetmap.josm.data.coor.EastNorth; … … 29 30 import org.openstreetmap.josm.data.projection.Projections; 30 31 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 31 import org.openstreetmap.josm.gui.progress.ProgressMonitor;32 32 import org.openstreetmap.josm.plugins.opendata.core.OdConstants; 33 33 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; … … 60 60 private File file; 61 61 private InputStream stream; 62 private Charset charset;63 62 private BufferedReader midReader; 64 63 … … 71 70 private Relation region; 72 71 private Way polygon; 73 private Node node;74 72 private Way polyline; 75 73 76 74 // CoordSys clause 77 75 private String units; 78 private Double originLon;79 private Double originLat;80 private Double stdP1;81 private Double stdP2;82 private Double scaleFactor;83 private Double falseEasting;84 private Double falseNorthing;85 private Double minx;86 private Double miny;87 private Double maxx;88 private Double maxy;76 private double originLon = Double.NaN; 77 private double originLat = Double.NaN; 78 private double stdP1 = Double.NaN; 79 private double stdP2 = Double.NaN; 80 private double scaleFactor = Double.NaN; 81 private double falseEasting = Double.NaN; 82 private double falseNorthing = Double.NaN; 83 private double minx = Double.NaN; 84 private double miny = Double.NaN; 85 private double maxx = Double.NaN; 86 private double maxy = Double.NaN; 89 87 90 88 // Region clause … … 100 98 101 99 public static DataSet parseDataSet(InputStream in, File file, 102 AbstractDataSetHandler handler , ProgressMonitor instance) throws IOException {103 return new MifReader(handler).parse(in, file, instance,Charset.forName(OdConstants.ISO8859_15));100 AbstractDataSetHandler handler) throws IOException { 101 return new MifReader(handler).parse(in, file, Charset.forName(OdConstants.ISO8859_15)); 104 102 } 105 103 … … 108 106 } 109 107 110 private void parseUnique( String[] words) {108 private void parseUnique() { 111 109 // TODO 112 110 Logging.warn("TODO Unique: "+line); 113 111 } 114 112 115 private void parseIndex( String[] words) {113 private void parseIndex() { 116 114 // TODO 117 115 Logging.warn("TODO Index: "+line); … … 282 280 if (equals(originLat, 42.0+i) && equals(stdP1, 41.25+i) && equals(stdP2, 42.75+i) 283 281 && equals(falseNorthing, (i+1)*1000000.0 + 200000.0)) { 284 josmProj = Projections.getProjectionByCode("EPSG:"+ Integer.toString(3942 + i)); // LambertCC9Zones282 josmProj = Projections.getProjectionByCode("EPSG:"+ (3942 + i)); // LambertCC9Zones 285 283 } 286 284 } … … 293 291 294 292 // TODO: handle cases with Affine declaration 295 int index = parseAffineUnits( words);293 int index = parseAffineUnits(); 296 294 297 295 // handle cases with Bounds declaration … … 307 305 private void parseCoordSysSyntax2(String[] words) { 308 306 // handle cases with Affine declaration 309 int index = parseAffineUnits( words);307 int index = parseAffineUnits(); 310 308 311 309 units = words[index+1]; … … 314 312 } 315 313 316 private int parseAffineUnits( String[] words) {314 private int parseAffineUnits() { 317 315 // TODO: handle affine units 318 return 2 +0;316 return 2; 319 317 } 320 318 … … 322 320 if (index < words.length && "Bounds".equals(words[index])) { 323 321 // Useless parenthesis... "(minx, miny) (maxx, maxy)" 324 minx = Double. valueOf(words[index+1].substring(1));325 miny = Double. valueOf(words[index+2].substring(0, words[index+2].length()-1));326 maxx = Double. valueOf(words[index+3].substring(1));327 maxy = Double. valueOf(words[index+4].substring(0, words[index+4].length()-1));322 minx = Double.parseDouble(words[index+1].substring(1)); 323 miny = Double.parseDouble(words[index+2].substring(0, words[index+2].length()-1)); 324 maxx = Double.parseDouble(words[index+3].substring(1)); 325 maxy = Double.parseDouble(words[index+4].substring(0, words[index+4].length()-1)); 328 326 if (Logging.isTraceEnabled()) { 329 327 Logging.trace(Arrays.toString(words) + " -> "+minx+","+miny+","+maxx+","+maxy); … … 336 334 words[i] = words[i].replace(",", ""); 337 335 } 338 switch (words[1].toLowerCase( )) {336 switch (words[1].toLowerCase(Locale.ROOT)) { 339 337 case "earth": 340 338 parseCoordSysSyntax1(words); … … 369 367 } 370 368 371 private void parseTransform( String[] words) {369 private void parseTransform() { 372 370 // TODO 373 371 Logging.warn("TODO Transform: "+line); … … 380 378 } 381 379 382 private void parseData( String[] words) {380 private void parseData() { 383 381 if (dataSet == null) { 384 382 dataSet = new DataSet(); … … 439 437 } 440 438 441 private void parseArc( String[] words) {439 private void parseArc() { 442 440 // TODO 443 441 Logging.warn("TODO Arc: "+line); 444 442 } 445 443 446 private void parseText( String[] words) {444 private void parseText() { 447 445 // TODO 448 446 Logging.warn("TODO Text: "+line); 449 447 } 450 448 451 private void parseRect( String[] words) {449 private void parseRect() { 452 450 // TODO 453 451 Logging.warn("TODO Rect: "+line); 454 452 } 455 453 456 private void parseRoundRect( String[] words) {454 private void parseRoundRect() { 457 455 // TODO 458 456 Logging.warn("TODO RoundRect: "+line); 459 457 } 460 458 461 private void parseEllipse( String[] words) {459 private void parseEllipse() { 462 460 // TODO 463 461 Logging.warn("TODO Ellipse: "+line); … … 466 464 private void initializeReaders(InputStream in, File f, Charset cs, int bufSize) throws IOException { 467 465 stream = in; 468 charset = cs;469 466 file = f; 470 467 Reader isr; 471 468 // Did you know ? new InputStreamReader(in, charset) has a non-configurable buffer of 8kb :( 472 469 if (bufSize < 8192) { 473 isr = new InputStreamReaderUnbuffered(in, c harset);470 isr = new InputStreamReaderUnbuffered(in, cs); 474 471 } else { 475 isr = new InputStreamReader(in, c harset);472 isr = new InputStreamReader(in, cs); 476 473 } 477 474 headerReader = new BufferedReader(isr, bufSize); … … 479 476 midReader.close(); 480 477 } 481 midReader = getDataReader(file, ".mid", c harset);482 } 483 484 private DataSet parse(InputStream in, File file, ProgressMonitor instance,Charset cs) throws IOException {478 midReader = getDataReader(file, ".mid", cs); 479 } 480 481 private DataSet parse(InputStream in, File file, Charset cs) throws IOException { 485 482 try { 486 483 try { … … 501 498 @Override 502 499 protected void parseHeaderLine(String[] words) throws IOException { 503 if ( words[0].equalsIgnoreCase("Version")) {500 if ("Version".equalsIgnoreCase(words[0])) { 504 501 parseVersion(words); 505 } else if ( words[0].equalsIgnoreCase("Charset")) {502 } else if ("Charset".equalsIgnoreCase(words[0])) { 506 503 // Reinitialize readers with an efficient buffer value now we know for sure the good charset 507 504 initializeReaders(stream, file, parseCharset(words), 8192); 508 } else if ( words[0].equalsIgnoreCase("Delimiter")) {505 } else if ("Delimiter".equalsIgnoreCase(words[0])) { 509 506 parseDelimiter(words); 510 } else if ( words[0].equalsIgnoreCase("Unique")) {511 parseUnique( words);512 } else if ( words[0].equalsIgnoreCase("Index")) {513 parseIndex( words);514 } else if ( words[0].equalsIgnoreCase("CoordSys")) {507 } else if ("Unique".equalsIgnoreCase(words[0])) { 508 parseUnique(); 509 } else if ("Index".equalsIgnoreCase(words[0])) { 510 parseIndex(); 511 } else if ("CoordSys".equalsIgnoreCase(words[0])) { 515 512 parseCoordSys(words); 516 } else if ( words[0].equalsIgnoreCase("Transform")) {517 parseTransform( words);518 } else if ( words[0].equalsIgnoreCase("Columns")) {513 } else if ("Transform".equalsIgnoreCase(words[0])) { 514 parseTransform(); 515 } else if ("Columns".equalsIgnoreCase(words[0])) { 519 516 parseColumns(words); 520 } else if ( words[0].equalsIgnoreCase("Data")) {521 parseData( words);517 } else if ("Data".equalsIgnoreCase(words[0])) { 518 parseData(); 522 519 } else if (dataSet != null) { 523 520 if (state == State.START_POLYGON) { … … 538 535 } else if (state == State.READING_POINTS && numpts > 0) { 539 536 if (josmProj != null) { 540 node = createNode(words[0], words[1]);537 Node node = createNode(words[0], words[1]); 541 538 if (polygon != null) { 542 539 polygon.addNode(node); … … 547 544 if (--numpts == 0) { 548 545 if (numpolygons > -1) { 549 if ( !polygon.isClosed()) {546 if (polygon != null && !polygon.isClosed()) { 550 547 polygon.addNode(polygon.firstNode()); 551 548 } … … 565 562 } 566 563 } 567 } else if ( words[0].equalsIgnoreCase("Point")) {564 } else if ("Point".equalsIgnoreCase(words[0])) { 568 565 parsePoint(words); 569 } else if ( words[0].equalsIgnoreCase("Line")) {566 } else if ("Line".equalsIgnoreCase(words[0])) { 570 567 parseLine(words); 571 } else if ( words[0].equalsIgnoreCase("PLine")) {568 } else if ("PLine".equalsIgnoreCase(words[0])) { 572 569 parsePLine(words); 573 } else if ( words[0].equalsIgnoreCase("Region")) {570 } else if ("Region".equalsIgnoreCase(words[0])) { 574 571 parseRegion(words); 575 } else if (words[0].equalsIgnoreCase("Arc")) { 576 parseArc(words); 577 } else if (words[0].equalsIgnoreCase("Text")) { 578 parseText(words); 579 } else if (words[0].equalsIgnoreCase("Rect")) { 580 parseRect(words); 581 } else if (words[0].equalsIgnoreCase("RoundRect")) { 582 parseRoundRect(words); 583 } else if (words[0].equalsIgnoreCase("Ellipse")) { 584 parseEllipse(words); 585 } else if (words[0].equalsIgnoreCase("Pen")) { 586 // Do nothing 587 } else if (words[0].equalsIgnoreCase("Brush")) { 588 // Do nothing 589 } else if (words[0].equalsIgnoreCase("Center")) { 590 // Do nothing 591 } else if (words[0].equalsIgnoreCase("Symbol")) { 592 // Do nothing 593 } else if (words[0].equalsIgnoreCase("Font")) { 594 // Do nothing 595 } else if (!words[0].isEmpty()) { 572 } else if ("Arc".equalsIgnoreCase(words[0])) { 573 parseArc(); 574 } else if ("Text".equalsIgnoreCase(words[0])) { 575 parseText(); 576 } else if ("Rect".equalsIgnoreCase(words[0])) { 577 parseRect(); 578 } else if ("RoundRect".equalsIgnoreCase(words[0])) { 579 parseRoundRect(); 580 } else if ("Ellipse".equalsIgnoreCase(words[0])) { 581 parseEllipse(); 582 } else if (!"Pen".equalsIgnoreCase(words[0]) 583 && !"Brush".equalsIgnoreCase(words[0]) 584 && !"Center".equalsIgnoreCase(words[0]) 585 && !"Symbol".equalsIgnoreCase(words[0]) 586 && !"Font".equalsIgnoreCase(words[0]) 587 && !words[0].isEmpty()) { 588 // Pen, Brush, Center, Symbol, and Font we currently ignore 596 589 Logging.warn("Line "+lineNum+". Unknown clause in data section: "+line); 597 590 } … … 628 621 629 622 private Node createNode(String x, String y) { 630 Node n ode = new Node(josmProj.eastNorth2latlon(new EastNorth(Double.parseDouble(x), Double.parseDouble(y))));631 dataSet.addPrimitive(n ode);632 return n ode;623 Node newNode = new Node(josmProj.eastNorth2latlon(new EastNorth(Double.parseDouble(x), Double.parseDouble(y)))); 624 dataSet.addPrimitive(newNode); 625 return newNode; 633 626 } 634 627 … … 639 632 * @return {@code true} if {@code a} and {@code b} are equals 640 633 */ 641 public static boolean equals( Double a, Double b) {634 public static boolean equals(double a, double b) { 642 635 if (a == b) return true; 643 636 // If the difference is less than epsilon, treat as equal. -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/MifTabImporter.java
r36072 r36173 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 import java.util.Locale; 8 9 9 10 import org.openstreetmap.josm.actions.ExtensionFileFilter; … … 31 32 throws IllegalDataException { 32 33 try { 33 if (file != null && file.getName().toLowerCase( ).endsWith(OdConstants.MIF_EXT)) {34 return MifReader.parseDataSet(in, file, handler , instance);34 if (file != null && file.getName().toLowerCase(Locale.ROOT).endsWith(OdConstants.MIF_EXT)) { 35 return MifReader.parseDataSet(in, file, handler); 35 36 } else { 36 37 return TabReader.parseDataSet(in, file, handler, instance); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java
r36072 r36173 25 25 import org.locationtech.jts.geom.Point; 26 26 import org.opengis.geometry.MismatchedDimensionException; 27 import org.opengis.referencing.FactoryException; 27 28 import org.opengis.referencing.operation.TransformException; 28 29 import org.openstreetmap.josm.data.osm.DataSet; … … 112 113 Logging.error(e); 113 114 throw e; 114 } catch ( Exception e) {115 } catch (FactoryException | GeoMathTransformException | TransformException | GeoCrsException e) { 115 116 Logging.error(e); 116 117 throw new IOException(e); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/TabFiles.java
r36092 r36173 5 5 6 6 import java.io.File; 7 import java.io.FilenameFilter;8 7 import java.lang.reflect.Field; 9 8 import java.net.MalformedURLException; 10 9 import java.net.URL; 11 import java.util.HashMap; 10 import java.util.EnumMap; 11 import java.util.Locale; 12 12 import java.util.Map; 13 13 import java.util.Map.Entry; … … 57 57 } 58 58 59 private String baseName(Object obj) {59 private static String baseName(Object obj) { 60 60 if (obj instanceof URL) { 61 61 return toBase(((URL) obj).toExternalForm()); … … 64 64 } 65 65 66 private String toBase(String path) {67 return path.substring(0, path.toLowerCase( ).lastIndexOf(".tab"));66 private static String toBase(String path) { 67 return path.substring(0, path.toLowerCase(Locale.ROOT).lastIndexOf(".tab")); 68 68 } 69 69 … … 86 86 String extensionWithPeriod = type.extensionWithPeriod; 87 87 if (upperCase) { 88 extensionWithPeriod = extensionWithPeriod.toUpperCase( );88 extensionWithPeriod = extensionWithPeriod.toUpperCase(Locale.ROOT); 89 89 } else { 90 extensionWithPeriod = extensionWithPeriod.toLowerCase( );90 extensionWithPeriod = extensionWithPeriod.toLowerCase(Locale.ROOT); 91 91 } 92 92 … … 97 97 } catch (MalformedURLException e) { 98 98 // shouldn't happen because the starting url was constructable 99 throw new RuntimeException(e);99 throw new JosmRuntimeException(e); 100 100 } 101 101 urls.put(type, newURL); … … 108 108 if (isLocal()) { 109 109 Set<Entry<ShpFileType, URL>> entries = urls.entrySet(); 110 Map<ShpFileType, URL> toUpdate = new HashMap<>();110 Map<ShpFileType, URL> toUpdate = new EnumMap<>(ShpFileType.class); 111 111 for (Entry<ShpFileType, URL> entry : entries) { 112 112 if (!exists(entry.getKey())) { … … 121 121 } 122 122 123 private URL findExistingFile(URL value) {123 private static URL findExistingFile(URL value) { 124 124 final File file = URLs.urlToFile(value); 125 125 File directory = file.getParentFile(); 126 126 if (directory != null && directory.exists()) { 127 File[] files = directory.listFiles(( FilenameFilter) (dir, name) -> file.getName().equalsIgnoreCase(name));128 if (files .length > 0) {127 File[] files = directory.listFiles((dir, name) -> file.getName().equalsIgnoreCase(name)); 128 if (files != null && files.length > 0) { 129 129 try { 130 130 return files[0].toURI().toURL(); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/TabReader.java
r36072 r36173 84 84 } catch (IOException e) { 85 85 Logging.error(e.getMessage()); 86 Logging.debug(e); 86 87 } 87 88 return ds; … … 90 91 @Override 91 92 protected void parseHeaderLine(String[] words) throws IOException { 92 if ( words[0].equalsIgnoreCase("!table")) {93 if ("!table".equalsIgnoreCase(words[0])) { 93 94 // Do nothing 94 } else if ( words[0].equalsIgnoreCase("!version")) {95 } else if ("!version".equalsIgnoreCase(words[0])) { 95 96 parseVersion(words); 96 } else if ( words[0].equalsIgnoreCase("!charset")) {97 } else if ("!charset".equalsIgnoreCase(words[0])) { 97 98 parseCharset(words); 98 99 } else if (numcolumns > 0) { 99 100 parseField(words); 100 } else if ( words[0].equalsIgnoreCase("Definition")) {101 } else if ("Definition".equalsIgnoreCase(words[0])) { 101 102 // Do nothing 102 } else if ( words[0].equalsIgnoreCase("Type")) {103 } else if ("Type".equalsIgnoreCase(words[0])) { 103 104 parseType(words); 104 } else if ( words[0].equalsIgnoreCase("Fields")) {105 } else if ("Fields".equalsIgnoreCase(words[0])) { 105 106 parseColumns(words); 106 107 } else if (!line.isEmpty()) { … … 115 116 116 117 private void parseType(String[] words) throws IllegalCharsetNameException, UnsupportedCharsetException { 117 if ( words[1].equalsIgnoreCase("NATIVE") && words[2].equalsIgnoreCase("Charset")) {118 if ("NATIVE".equalsIgnoreCase(words[1]) && "Charset".equalsIgnoreCase(words[2])) { 118 119 datCharset = parseCharset(words, 3); 119 120 } else { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/CsvReader.java
r36072 r36173 7 7 import java.io.InputStreamReader; 8 8 import java.nio.charset.Charset; 9 import java.nio.charset.StandardCharsets; 9 10 10 11 import org.openstreetmap.josm.data.osm.DataSet; 11 12 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 12 13 import org.openstreetmap.josm.io.IllegalDataException; 13 import org.openstreetmap.josm.plugins.opendata.core.OdConstants;14 14 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 15 15 import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils; … … 30 30 public CsvReader(CsvHandler handler, String defaultSep) { 31 31 super(handler); 32 this.charset = handler != null && handler.getCharset() != null ? handler.getCharset() : Charset.forName(OdConstants.UTF8);32 this.charset = handler != null && handler.getCharset() != null ? handler.getCharset() : StandardCharsets.UTF_8; 33 33 this.sep = handler != null && handler.getSeparator() != null ? handler.getSeparator() : defaultSep; 34 34 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/DefaultCsvHandler.java
r36072 r36173 6 6 public class DefaultCsvHandler extends DefaultSpreadSheetHandler implements CsvHandler { 7 7 8 private Charset charset = null;9 private String separator = null;8 private Charset charset; 9 private String separator; 10 10 11 11 @Override -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/DefaultSpreadSheetHandler.java
r36072 r36173 14 14 private int sheetNumber = -1; 15 15 private int lineNumber = -1; 16 private boolean handlesProjection = false;16 private boolean handlesProjection; 17 17 18 18 private int xCol = -1; -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/OdsDocument.java
r36072 r36173 25 25 } 26 26 27 private InputSource getEntryInputSource(ZipInputStream zis) throws IOException {27 private static InputSource getEntryInputSource(ZipInputStream zis) throws IOException { 28 28 int n; 29 29 final byte[] buffer = new byte[4096]; … … 46 46 47 47 while (!contentParsed && (entry = zis.getNextEntry()) != null) { 48 if ( entry.getName().equals("content.xml")) {48 if ("content.xml".equals(entry.getName())) { 49 49 rdr.setContentHandler(contentHandler); 50 50 Logging.info("Parsing content.xml"); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/SpreadSheetReader.java
r36072 r36173 36 36 private static final NumberFormat formatUK = NumberFormat.getInstance(Locale.UK); 37 37 38 private static final String COOR = "( \\-?\\d+(?:[\\.,]\\d+)?)";38 private static final String COOR = "(-?\\d+(?:[.,]\\d+)?)"; 39 39 // Lat/lon pattern with optional altitude and precision 40 40 private static final Pattern LATLON_PATTERN = Pattern.compile( … … 43 43 protected final SpreadSheetHandler handler; 44 44 45 p ublicSpreadSheetReader(SpreadSheetHandler handler) {45 protected SpreadSheetReader(SpreadSheetHandler handler) { 46 46 this.handler = handler; 47 47 } … … 68 68 69 69 public static class CoordinateColumns { 70 public Projection proj = null;70 public Projection proj; 71 71 public int xCol = -1; 72 72 public int yCol = -1; … … 81 81 } 82 82 83 private CoordinateColumns addCoorColIfNeeded(List<CoordinateColumns> columns, CoordinateColumns col) {83 private static CoordinateColumns addCoorColIfNeeded(List<CoordinateColumns> columns, CoordinateColumns col) { 84 84 if (col == null || col.isOk()) { 85 columns.add(col = new CoordinateColumns()); 85 col = new CoordinateColumns(); 86 columns.add(col); 86 87 } 87 88 return col; … … 101 102 for (int i = 0; i < header.length; i++) { 102 103 for (ProjectionPatterns pp : OdConstants.PROJECTIONS) { 103 List<CoordinateColumns> columns = projColumns.get(pp); 104 if (columns == null) { 105 projColumns.put(pp, columns = new ArrayList<>()); 106 } 104 List<CoordinateColumns> columns = projColumns.computeIfAbsent(pp, k -> new ArrayList<>()); 107 105 CoordinateColumns col = columns.isEmpty() ? null : columns.get(columns.size()-1); 108 106 if (pp.getXYPattern().matcher(header[i]).matches()) { … … 123 121 final List<CoordinateColumns> columns = new ArrayList<>(); 124 122 125 for ( ProjectionPatterns pp : projColumns.keySet()) {126 for (CoordinateColumns col : projColumns.get(pp)) {123 for (Map.Entry<ProjectionPatterns, List<SpreadSheetReader.CoordinateColumns>> entry : projColumns.entrySet()) { 124 for (CoordinateColumns col : entry.getValue()) { 127 125 if (col.isOk()) { 128 126 columns.add(col); 129 127 if (col.proj == null) { 130 col.proj = pp.getProjection(header[col.xCol], header[col.yCol]);128 col.proj = entry.getKey().getProjection(header[col.xCol], header[col.yCol]); 131 129 } 132 130 } … … 166 164 } 167 165 168 String message = "";166 StringBuilder message = new StringBuilder(); 169 167 for (CoordinateColumns c : columns) { 170 if ( !message.isEmpty()) {171 message += "; ";172 } 173 message += c.proj + "("+header[c.xCol]+", "+header[c.yCol]+")";168 if (message.length() != 0) { 169 message.append("; "); 170 } 171 message.append(c.proj).append('(').append(header[c.xCol]).append(", ").append(header[c.yCol]).append(')'); 174 172 } 175 173 … … 229 227 } 230 228 } 231 if (!coordinate) { 232 if (!fields[i].isEmpty()) { 233 for (Node n : nodes.values()) { 234 n.put(header[i], fields[i]); 235 } 229 if (!coordinate && !fields[i].isEmpty()) { 230 for (Node n : nodes.values()) { 231 n.put(header[i], fields[i]); 236 232 } 237 233 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/XlsReader.java
r36072 r36173 22 22 public class XlsReader extends SpreadSheetReader { 23 23 24 private Workbook wb;25 24 private Sheet sheet; 26 25 private int rowIndex; … … 39 38 Logging.info("Parsing XLS file"); 40 39 try { 41 wb = new HSSFWorkbook(new POIFSFileSystem(in));40 Workbook wb = new HSSFWorkbook(new POIFSFileSystem(in)); 42 41 sheet = wb.getSheetAt(getSheetNumber()); 43 42 rowIndex = 0; -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/layers/OdDataLayer.java
r36072 r36173 6 6 import java.io.File; 7 7 import java.util.ArrayList; 8 import java.util.Arrays; 8 9 import java.util.Collection; 9 10 import java.util.List; … … 120 121 @Override 121 122 public Action[] getMenuEntries() { 122 List<Action> result = new ArrayList<>(); 123 for (Action entry : super.getMenuEntries()) { 124 result.add(entry); 125 } 123 List<Action> result = new ArrayList<>(Arrays.asList(super.getMenuEntries())); 126 124 if (this.handler != null) { 127 125 if (this.handler.getWikiURL() != null || this.handler.getLocalPortalURL() != null || this.handler.getNationalPortalURL() != null) { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/licenses/License.java
r36092 r36173 5 5 import java.net.URL; 6 6 import java.util.HashMap; 7 import java.util.Iterator;8 7 import java.util.Map; 9 8 … … 25 24 // Find URL for current language 26 25 String lang = OdUtils.getJosmLanguage(); 27 for ( String l : map.keySet()) {28 if (lang.startsWith( l)) {29 return map.get(l);26 for (Map.Entry<String, URL> entry : map.entrySet()) { 27 if (lang.startsWith(entry.getKey())) { 28 return entry.getValue(); 30 29 } 31 30 } … … 36 35 } 37 36 // If not found, return first non-null url 38 if (map.keySet().size() > 0) { 39 for (Iterator<String> it = map.keySet().iterator(); it.hasNext();) { 40 url = map.get(it.next()); 41 if (url != null) { 42 return url; 43 } 37 if (!map.keySet().isEmpty()) { 38 for (URL entryUrl : map.values()) { 39 return entryUrl; 44 40 } 45 41 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/AbstractModule.java
r36072 r36173 7 7 import java.io.InputStream; 8 8 import java.util.ArrayList; 9 import java.util.Collection;10 9 import java.util.List; 10 import java.util.Objects; 11 11 12 12 import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry; … … 18 18 import org.openstreetmap.josm.tools.Logging; 19 19 20 /** 21 * A common {@link Module} base implementation 22 */ 20 23 public abstract class AbstractModule implements Module { 21 24 22 25 protected final List<Class<? extends AbstractDataSetHandler>> handlers = new ArrayList<>(); 23 26 24 private final List<AbstractDataSetHandler> instan ciatedHandlers = new ArrayList<>();27 private final List<AbstractDataSetHandler> instantiatedHandlers = new ArrayList<>(); 25 28 26 29 protected final ModuleInformation info; 27 30 28 p ublicAbstractModule(ModuleInformation info) {31 protected AbstractModule(ModuleInformation info) { 29 32 this.info = info; 30 33 } … … 48 51 public SourceProvider getMapPaintStyleSourceProvider() { 49 52 final List<SourceEntry> sources = new ArrayList<>(); 50 for (AbstractDataSetHandler handler : getInstan ciatedHandlers()) {53 for (AbstractDataSetHandler handler : getInstantiatedHandlers()) { 51 54 ExtendedSourceEntry src; 52 55 if (handler != null && (src = handler.getMapPaintStyle()) != null) { … … 56 59 + src.url.replace(OdConstants.PROTO_RSRC, "").replace('/', File.separatorChar); 57 60 58 int n = 0;61 int n; 59 62 byte[] buffer = new byte[4096]; 60 63 try (InputStream in = getClass().getResourceAsStream( 61 64 src.url.substring(OdConstants.PROTO_RSRC.length()-1)); 62 65 FileOutputStream out = new FileOutputStream(path)) { 66 Objects.requireNonNull(in); 63 67 String dir = path.substring(0, path.lastIndexOf(File.separatorChar)); 64 68 if (new File(dir).mkdirs() && Logging.isDebugEnabled()) { … … 72 76 sources.add(src); 73 77 } catch (IOException e) { 74 Logging.error(e .getMessage());78 Logging.error(e); 75 79 } 76 80 } 77 81 } 78 return sources.isEmpty() ? null : new SourceProvider() { 79 @Override 80 public Collection<SourceEntry> getSources() { 81 return sources; 82 } 83 }; 82 return sources.isEmpty() ? null : () -> sources; 84 83 } 85 84 … … 87 86 public SourceProvider getPresetSourceProvider() { 88 87 final List<SourceEntry> sources = new ArrayList<>(); 89 for (AbstractDataSetHandler handler : getInstan ciatedHandlers()) {88 for (AbstractDataSetHandler handler : getInstantiatedHandlers()) { 90 89 if (handler != null && handler.getTaggingPreset() != null) { 91 90 sources.add(handler.getTaggingPreset()); 92 91 } 93 92 } 94 return sources.isEmpty() ? null : new SourceProvider() { 95 @Override 96 public Collection<SourceEntry> getSources() { 97 return sources; 98 } 99 }; 93 return sources.isEmpty() ? null : () -> sources; 100 94 } 101 95 … … 115 109 } 116 110 117 private List<AbstractDataSetHandler> getInstan ciatedHandlers() {118 if (instan ciatedHandlers.isEmpty()) {119 instan ciatedHandlers.addAll(getNewlyInstanciatedHandlers());111 private List<AbstractDataSetHandler> getInstantiatedHandlers() { 112 if (instantiatedHandlers.isEmpty()) { 113 instantiatedHandlers.addAll(getNewlyInstanciatedHandlers()); 120 114 } 121 return instan ciatedHandlers;115 return instantiatedHandlers; 122 116 } 123 117 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ModuleDownloadTask.java
r36072 r36173 37 37 private final Collection<ModuleInformation> failed = new LinkedList<>(); 38 38 private final Collection<ModuleInformation> downloaded = new LinkedList<>(); 39 //private Exception lastException;40 39 private boolean canceled; 41 40 private HttpURLConnection downloadConnection; … … 134 133 @Override protected void realRun() throws SAXException, IOException { 135 134 File moduleDir = OdPlugin.getInstance().getModulesDirectory(); 136 if (!moduleDir.exists()) { 137 if (!moduleDir.mkdirs()) { 138 //lastException = new ModuleDownloadException(tr("Failed to create module directory ''{0}''", moduleDir.toString())); 139 failed.addAll(toUpdate); 140 return; 141 } 135 if (!moduleDir.exists() && !moduleDir.mkdirs()) { 136 failed.addAll(toUpdate); 137 return; 142 138 } 143 139 getProgressMonitor().setTicksCount(toUpdate.size()); … … 150 146 download(d, moduleFile); 151 147 } catch (ModuleDownloadException e) { 152 e.printStackTrace();148 Logging.error(e); 153 149 failed.add(d); 154 150 continue; -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ModuleHandler.java
r36072 r36173 11 11 import java.awt.Insets; 12 12 import java.io.File; 13 import java.io.FilenameFilter;14 13 import java.net.URL; 15 14 import java.net.URLClassLoader; … … 23 22 import java.util.LinkedList; 24 23 import java.util.List; 24 import java.util.Locale; 25 25 import java.util.Map; 26 26 import java.util.Set; … … 76 76 sources.add(ModuleHandler.class.getClassLoader()); 77 77 } catch (SecurityException ex) { 78 Logging.trace(ex); 78 79 sources.add(ImageProvider.class.getClassLoader()); 79 80 } … … 103 104 long tim = System.currentTimeMillis(); 104 105 long last = Config.getPref().getLong("opendata.modulemanager.lastupdate", 0); 105 IntegermaxTime = Config.getPref().getInt("opendata.modulemanager.time-based-update.interval", 60);106 int maxTime = Config.getPref().getInt("opendata.modulemanager.time-based-update.interval", 60); 106 107 long d = (tim - last) / (24 * 60 * 60 * 1000L); 107 108 if ((last <= 0) || (maxTime <= 0)) { … … 138 139 // 139 140 String policy = Config.getPref().get(togglePreferenceKey, "ask"); 140 policy = policy.trim().toLowerCase( );141 if ( policy.equals("never")) {141 policy = policy.trim().toLowerCase(Locale.ROOT); 142 if ("never".equals(policy)) { 142 143 if ("opendata.modulemanager.time-based-update.policy".equals(togglePreferenceKey)) { 143 144 Logging.info(tr("Skipping module update after elapsed update interval. Automatic update at startup is disabled.")); … … 146 147 } 147 148 148 if ( policy.equals("always")) {149 if ("always".equals(policy)) { 149 150 if ("opendata.modulemanager.time-based-update.policy".equals(togglePreferenceKey)) { 150 151 Logging.info(tr("Running module update after elapsed update interval. Automatic update at startup is disabled.")); … … 153 154 } 154 155 155 if (! policy.equals("ask")) {156 if (!"ask".equals(policy)) { 156 157 Logging.warn(tr("Unexpected value ''{0}'' for preference ''{1}''. Assuming value ''ask''.", policy, togglePreferenceKey)); 157 158 } … … 252 253 msg = null; 253 254 } catch (ModuleException e) { 254 e.printStackTrace();255 Logging.debug(e); 255 256 if (e.getCause() instanceof ClassNotFoundException) { 256 257 msg = tr("<html>Could not load module {0} because the module<br>main class ''{1}'' was not found.<br>" 257 258 + "Delete from preferences?</html>", module.name, module.className); 258 259 } 259 } catch (Exception e) {260 Logging.error(e);261 260 } 262 261 if (msg != null && confirmDisableModule(parent, msg, module.name)) { … … 307 306 * 308 307 * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null. 309 * @return the listof locally available module information308 * @return the map of locally available module information 310 309 * 311 310 */ … … 320 319 try { 321 320 future.get(); 322 } catch (ExecutionException | InterruptedExceptione) {321 } catch (ExecutionException e) { 323 322 Logging.error(e); 324 return null; 323 return Collections.emptyMap(); 324 } catch (InterruptedException e) { 325 Logging.error(e); 326 Thread.currentThread().interrupt(); 327 return Collections.emptyMap(); 325 328 } 326 329 HashMap<String, ModuleInformation> ret = new HashMap<>(); … … 363 366 * 364 367 * @param parent parent component 365 * @return the set of modules to load (as set of module names)368 * @return the list of modules to load (as set of module names) 366 369 */ 367 370 public static List<ModuleInformation> buildListOfModulesToLoad(Component parent) { 368 Set<String> modules = new HashSet<>(); 369 modules.addAll(Config.getPref().getList(OdConstants.PREF_MODULES, new LinkedList<String>())); 371 Set<String> modules = new HashSet<>(Config.getPref().getList(OdConstants.PREF_MODULES, new LinkedList<>())); 370 372 if (System.getProperty("josm."+OdConstants.PREF_MODULES) != null) { 371 373 modules.addAll(Arrays.asList(System.getProperty("josm."+OdConstants.PREF_MODULES).split(","))); … … 387 389 388 390 private static void alertFailedModuleUpdate(Component parent, Collection<ModuleInformation> modules) { 389 StringBu ffer sb = new StringBuffer();391 StringBuilder sb = new StringBuilder(150); 390 392 sb.append("<html>"); 391 393 sb.append(trn( … … 447 449 } catch (ExecutionException e) { 448 450 Logging.warn(tr("Warning: failed to download module information list")); 449 e.printStackTrace();451 Logging.debug(e); 450 452 // don't abort in case of error, continue with downloading modules below 451 453 } catch (InterruptedException e) { 452 454 Logging.warn(tr("Warning: failed to download module information list")); 453 e.printStackTrace(); 455 Logging.debug(e); 456 Thread.currentThread().interrupt(); 457 return Collections.emptyList(); 454 458 // don't abort in case of error, continue with downloading modules below 455 459 } … … 477 481 future.get(); 478 482 } catch (ExecutionException e) { 479 e.printStackTrace();483 Logging.debug(e); 480 484 alertFailedModuleUpdate(parent, modulesToUpdate); 481 485 return modules; 482 486 } catch (InterruptedException e) { 483 e.printStackTrace();487 Logging.debug(e); 484 488 alertFailedModuleUpdate(parent, modulesToUpdate); 489 Thread.currentThread().interrupt(); 485 490 return modules; 486 491 } … … 540 545 * Installs downloaded modules. Moves files with the suffix ".jar.new" to the corresponding 541 546 * ".jar" files. 542 * 543 * If {@code do warn} is true, this methodsemits warning messages on the console if a downloaded544 * but not yet installed module .jar can't be be installed. If {@code dowarn} is false, the545 * installation of the respective module is sil lently skipped.546 * 547 * @param do warn if true, warning messages are displayed; false otherwise548 */ 549 public static void installDownloadedModules(boolean do warn) {547 * <p> 548 * If {@code doWarn} is true, this method emits warning messages on the console if a downloaded 549 * but not yet installed module .jar can't be installed. If {@code doWarn} is false, the 550 * installation of the respective module is silently skipped. 551 * 552 * @param doWarn if true, warning messages are displayed; false otherwise 553 */ 554 public static void installDownloadedModules(boolean doWarn) { 550 555 File moduleDir = OdPlugin.getInstance().getModulesDirectory(); 551 556 if (!moduleDir.exists() || !moduleDir.isDirectory() || !moduleDir.canWrite()) 552 557 return; 553 558 554 final File[] files = moduleDir.listFiles(new FilenameFilter() { 555 @Override 556 public boolean accept(File dir, String name) { 557 return name.endsWith(".jar.new"); 558 } }); 559 560 for (File updatedModule : files) { 561 final String filePath = updatedModule.getPath(); 562 File module = new File(filePath.substring(0, filePath.length() - 4)); 563 String moduleName = updatedModule.getName().substring(0, updatedModule.getName().length() - 8); 564 // CHECKSTYLE.OFF: LineLength 565 if (module.exists()) { 566 if (!module.delete() && dowarn) { 559 final File[] files = moduleDir.listFiles((dir, name) -> name.endsWith(".jar.new")); 560 561 if (files != null) { 562 for (File updatedModule : files) { 563 final String filePath = updatedModule.getPath(); 564 File module = new File(filePath.substring(0, filePath.length() - 4)); 565 String moduleName = updatedModule.getName().substring(0, updatedModule.getName().length() - 8); 566 if (module.exists() && !module.delete() && doWarn) { 567 567 Logging.warn(tr("Warning: failed to delete outdated module ''{0}''.", module.toString())); 568 Logging.warn(tr("Warning: failed to install already downloaded module ''{0}''. Skipping installation. JOSM is still going to load the old module version.", moduleName)); 568 Logging.warn(tr("Warning: failed to install already downloaded module ''{0}''. Skipping installation." + 569 "JOSM is still going to load the old module version.", moduleName)); 569 570 continue; 570 571 } 571 }572 if (!updatedModule.renameTo(module) && dowarn) {573 Logging.warn(tr("Warning: failed to install module ''{0}'' from temporary download file ''{1}''. Renaming failed.",module.toString(), updatedModule.toString()));574 Logging.warn(tr("Warning: failed to install already downloaded module ''{0}''. Skipping installation. JOSM is still going to load the old module version.", moduleName));575 }576 // CHECKSTYLE.ON: LineLength577 }578 return;572 if (!updatedModule.renameTo(module) && doWarn) { 573 Logging.warn(tr("Warning: failed to install module ''{0}'' from temporary download file ''{1}''. Renaming failed.", 574 module.toString(), updatedModule.toString())); 575 Logging.warn(tr("Warning: failed to install already downloaded module ''{0}''. Skipping installation." + 576 "JOSM is still going to load the old module version.", moduleName)); 577 } 578 } 579 } 579 580 } 580 581 581 582 private static class UpdateModulesMessagePanel extends JPanel { 582 583 private JMultilineLabel lblMessage; 583 private JCheckBox cbDo ntShowAgain;584 private JCheckBox cbDoNotShowAgain; 584 585 585 586 protected void build() { … … 591 592 gc.weighty = 1.0; 592 593 gc.insets = new Insets(5, 5, 5, 5); 593 add(lblMessage = new JMultilineLabel(""), gc); 594 lblMessage = new JMultilineLabel(""); 595 add(lblMessage, gc); 594 596 lblMessage.setFont(lblMessage.getFont().deriveFont(Font.PLAIN)); 595 597 … … 597 599 gc.fill = GridBagConstraints.HORIZONTAL; 598 600 gc.weighty = 0.0; 599 add(cbDontShowAgain = new JCheckBox( 600 tr("Do not ask again and remember my decision (go to Preferences->Modules to change it later)")), gc); 601 cbDontShowAgain.setFont(cbDontShowAgain.getFont().deriveFont(Font.PLAIN)); 601 cbDoNotShowAgain = new JCheckBox( 602 tr("Do not ask again and remember my decision (go to Preferences->Modules to change it later)")); 603 add(cbDoNotShowAgain, gc); 604 cbDoNotShowAgain.setFont(cbDoNotShowAgain.getFont().deriveFont(Font.PLAIN)); 602 605 } 603 606 … … 612 615 public void initDontShowAgain(String preferencesKey) { 613 616 String policy = Config.getPref().get(preferencesKey, "ask"); 614 policy = policy.trim().toLowerCase( );615 cbDo ntShowAgain.setSelected(!policy.equals("ask"));617 policy = policy.trim().toLowerCase(Locale.ROOT); 618 cbDoNotShowAgain.setSelected(!"ask".equals(policy)); 616 619 } 617 620 618 621 public boolean isRememberDecision() { 619 return cbDo ntShowAgain.isSelected();622 return cbDoNotShowAgain.isSelected(); 620 623 } 621 624 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ModuleInformation.java
r36072 r36173 10 10 import java.io.IOException; 11 11 import java.io.InputStream; 12 import java.lang.reflect.InvocationTargetException; 12 13 import java.net.MalformedURLException; 13 14 import java.net.URL; … … 16 17 import java.util.LinkedList; 17 18 import java.util.List; 19 import java.util.Locale; 18 20 import java.util.Map; 19 21 import java.util.TreeMap; … … 38 40 */ 39 41 public class ModuleInformation { 40 public File file = null;41 public String name = null;42 public String className = null;43 public String link = null;44 public String description = null;45 public String author = null;46 public String version = null;47 public String localversion = null;48 public String downloadlink = null;42 public File file; 43 public String name; 44 public String className; 45 public String link; 46 public String description; 47 public String author; 48 public String version; 49 public String localversion; 50 public String downloadlink; 49 51 public String iconPath; 50 52 public ImageIcon icon; … … 52 54 public final Map<String, String> attr = new TreeMap<>(); 53 55 54 /* *56 /* 55 57 * Creates a module information object by reading the module information from 56 58 * the manifest in the module jar. … … 78 80 try ( 79 81 FileInputStream fis = new FileInputStream(file); 80 JarInputStream jar = new JarInputStream(fis) ;82 JarInputStream jar = new JarInputStream(fis) 81 83 ) { 82 84 Manifest manifest = jar.getManifest(); … … 139 141 } 140 142 141 @SuppressWarnings("unused")142 143 private void scanManifest(Manifest manifest) { 143 144 String lang = LanguageInfo.getLanguageCodeManifest(); 144 Attributes attr= manifest.getMainAttributes();145 className = attr.getValue("Module-Class");146 String s = attr.getValue(lang+"Module-Link");145 Attributes manifestMainAttributes = manifest.getMainAttributes(); 146 className = manifestMainAttributes.getValue("Module-Class"); 147 String s = manifestMainAttributes.getValue(lang+"Module-Link"); 147 148 if (s == null) { 148 s = attr.getValue("Module-Link");149 s = manifestMainAttributes.getValue("Module-Link"); 149 150 } 150 151 if (s != null) { … … 157 158 } 158 159 link = s; 159 s = attr.getValue(lang+"Module-Description");160 s = manifestMainAttributes.getValue(lang+"Module-Description"); 160 161 if (s == null) { 161 s = attr.getValue("Module-Description");162 s = manifestMainAttributes.getValue("Module-Description"); 162 163 if (s != null) { 163 164 s = tr(s); … … 165 166 } 166 167 description = s; 167 version = attr.getValue("Module-Version");168 author = attr.getValue("Author");169 iconPath = attr.getValue("Module-Icon");168 version = manifestMainAttributes.getValue("Module-Version"); 169 author = manifestMainAttributes.getValue("Author"); 170 iconPath = manifestMainAttributes.getValue("Module-Icon"); 170 171 if (iconPath != null && file != null) { 171 172 // extract icon from the module jar file … … 180 181 } 181 182 182 String classPath = attr.getValue(Attributes.Name.CLASS_PATH);183 String classPath = manifestMainAttributes.getValue(Attributes.Name.CLASS_PATH); 183 184 if (classPath != null) { 184 185 for (String entry : classPath.split(" ")) { … … 193 194 } 194 195 } 195 for (Object o : attr.keySet()) {196 this.attr.put(o.toString(), attr.getValue(o.toString()));196 for (Object o : manifestMainAttributes.keySet()) { 197 this.attr.put(o.toString(), manifestMainAttributes.getValue(o.toString())); 197 198 } 198 199 } … … 205 206 */ 206 207 public String getDescriptionAsHtml() { 207 StringBuilder sb = new StringBuilder( );208 StringBuilder sb = new StringBuilder(32); 208 209 sb.append("<html><body>"); 209 210 sb.append(description == null ? tr("no description available") : description); … … 212 213 } 213 214 if (downloadlink != null && !downloadlink.startsWith(OdConstants.OSM_SITE+"dist/")) { 214 sb.append("<p> </p><p>" +tr("<b>Module provided by an external source:</b> {0}", downloadlink)+"</p>");215 sb.append("<p> </p><p>").append(tr("<b>Module provided by an external source:</b> {0}", downloadlink)).append("</p>"); 215 216 } 216 217 sb.append("</body></html>"); … … 228 229 try { 229 230 return klass.getConstructor(ModuleInformation.class).newInstance(this); 230 } catch ( Exception t) {231 } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException t) { 231 232 throw new ModuleException(name, t); 232 233 } … … 246 247 try { 247 248 return (Class<? extends Module>) Class.forName(className, true, classLoader); 248 } catch ( Exception t) {249 } catch (ClassNotFoundException t) { 249 250 throw new ModuleException(name, t); 250 251 } … … 282 283 if (this.version == null && referenceVersion != null) 283 284 return true; 284 if (this.version != null && !this.version.equals(referenceVersion)) 285 return true; 286 return false; 287 } 288 289 /** 290 * Replies true if this this module should be updated/downloaded because either 285 return this.version != null && !this.version.equals(referenceVersion); 286 } 287 288 /** 289 * Replies true if this module should be updated/downloaded because either 291 290 * it is not available locally (its local version is null) or its local version is 292 291 * older than the available version on the server. … … 303 302 if (filter == null) return true; 304 303 if (value == null) return false; 305 return value.toLowerCase( ).contains(filter.toLowerCase());304 return value.toLowerCase(Locale.ROOT).contains(filter.toLowerCase(Locale.ROOT)); 306 305 } 307 306 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ModuleListParser.java
r36072 r36173 9 9 import java.io.InputStream; 10 10 import java.io.InputStreamReader; 11 import java. io.UnsupportedEncodingException;11 import java.nio.charset.StandardCharsets; 12 12 import java.util.LinkedList; 13 13 import java.util.List; … … 15 15 /** 16 16 * A parser for the module list provided by an opendata Module Download Site. 17 * 17 * <p> 18 18 * See <a href="https://svn.openstreetmap.org/applications/editors/josm/plugins/opendata/modules.txt">OSM SVN</a> 19 19 * for a sample of the document. The format is a custom format, kind of mix of CSV and RFC822 style … … 35 35 try { 36 36 return new ModuleInformation( 37 new ByteArrayInputStream(manifest.getBytes( "utf-8")),37 new ByteArrayInputStream(manifest.getBytes(StandardCharsets.UTF_8)), 38 38 name.substring(0, name.length() - 4), 39 39 url 40 40 ); 41 } catch (UnsupportedEncodingException e) {42 throw new ModuleListParseException(tr("Failed to create module information from manifest for module ''{0}''", name), e);43 41 } catch (ModuleException e) { 44 42 throw new ModuleListParseException(tr("Failed to create module information from manifest for module ''{0}''", name), e); … … 48 46 /** 49 47 * Parses a module information document and replies a list of module information objects. 50 * 48 * <p> 51 49 * See <a href="https://svn.openstreetmap.org/applications/editors/josm/plugins/opendata/modules.txt">OSM SVN</a> 52 50 * for a sample of the document. The format is a custom format, kind of mix of CSV and RFC822 style … … 59 57 public List<ModuleInformation> parse(InputStream in) throws ModuleListParseException { 60 58 List<ModuleInformation> ret = new LinkedList<>(); 61 BufferedReader r = null;59 BufferedReader r; 62 60 try { 63 r = new BufferedReader(new InputStreamReader(in, "utf-8"));61 r = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); 64 62 String name = null; 65 63 String url = null; … … 78 76 line = line.substring(1); 79 77 if (line.length() > 70) { 80 manifest.append(line .substring(0, 70)).append("\n");78 manifest.append(line, 0, 70).append("\n"); 81 79 line = " " + line.substring(70); 82 80 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ReadLocalModuleInformationTask.java
r36072 r36173 6 6 import java.io.File; 7 7 import java.io.FileInputStream; 8 import java.io.FilenameFilter;9 8 import java.io.IOException; 10 9 import java.util.ArrayList; … … 25 24 * This is an asynchronous task for reading module information from the files 26 25 * in the local module repositories. 27 * 26 * <p> 28 27 * It scans the files in the local modules repository (see {@link OdPlugin#getModulesDirectory()} 29 28 * and extracts module information from three kind of files: … … 36 35 */ 37 36 public class ReadLocalModuleInformationTask extends PleaseWaitRunnable { 38 private Map<String, ModuleInformation> availableModules;37 private final Map<String, ModuleInformation> availableModules; 39 38 private boolean canceled; 40 39 … … 78 77 protected void scanSiteCacheFiles(ProgressMonitor monitor, File modulesDirectory) { 79 78 File[] siteCacheFiles = modulesDirectory.listFiles( 80 new FilenameFilter() { 81 @Override 82 public boolean accept(File dir, String name) { 83 return name.matches("^([0-9]+-)?site.*\\.txt$"); 84 } 85 } 86 ); 79 (dir, name) -> name.matches("^([0-9]+-)?site.*\\.txt$") 80 ); 87 81 if (siteCacheFiles == null || siteCacheFiles.length == 0) 88 82 return; … … 96 90 } catch (ModuleListParseException e) { 97 91 Logging.warn(tr("Warning: Failed to scan file ''{0}'' for module information. Skipping.", fname)); 98 e.printStackTrace();92 Logging.debug(e); 99 93 } 100 94 monitor.worked(1); … … 104 98 protected void scanIconCacheFiles(ProgressMonitor monitor, File modulesDirectory) { 105 99 File[] siteCacheFiles = modulesDirectory.listFiles( 106 new FilenameFilter() { 107 @Override 108 public boolean accept(File dir, String name) { 109 return name.matches("^([0-9]+-)?site.*modules-icons\\.zip$"); 110 } 111 } 112 ); 100 (dir, name) -> name.matches("^([0-9]+-)?site.*modules-icons\\.zip$") 101 ); 113 102 if (siteCacheFiles == null || siteCacheFiles.length == 0) 114 103 return; … … 133 122 protected void scanModuleFiles(ProgressMonitor monitor, File modulesDirectory) { 134 123 File[] moduleFiles = modulesDirectory.listFiles( 135 new FilenameFilter() { 136 @Override 137 public boolean accept(File dir, String name) { 138 return name.endsWith(".jar") || name.endsWith(".jar.new"); 139 } 140 } 141 ); 124 (dir, name) -> name.endsWith(".jar") || name.endsWith(".jar.new") 125 ); 142 126 if (moduleFiles == null || moduleFiles.length == 0) 143 127 return; … … 157 141 } catch (ModuleException e) { 158 142 Logging.warn(tr("Warning: Failed to scan file ''{0}'' for module information. Skipping.", fname)); 159 e.printStackTrace();143 Logging.debug(e); 160 144 } 161 145 monitor.worked(1); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/ReadRemoteModuleInformationTask.java
r36072 r36173 7 7 import java.io.ByteArrayInputStream; 8 8 import java.io.File; 9 import java.io.FileOutputStream;10 import java.io.FilenameFilter;11 9 import java.io.IOException; 12 10 import java.io.InputStream; … … 15 13 import java.io.OutputStreamWriter; 16 14 import java.io.PrintWriter; 17 import java.io.UnsupportedEncodingException;18 15 import java.net.HttpURLConnection; 19 16 import java.net.MalformedURLException; 20 17 import java.net.URL; 18 import java.nio.charset.StandardCharsets; 19 import java.nio.file.Files; 21 20 import java.util.Arrays; 22 21 import java.util.Collection; … … 157 156 connection.setRequestProperty("Accept-Charset", "utf-8"); 158 157 } 159 try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"))) {158 try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) { 160 159 String line; 161 160 while ((line = in.readLine()) != null) { … … 164 163 return sb.toString(); 165 164 } 166 } catch (MalformedURLException e) {167 if (canceled) return null;168 e.printStackTrace();169 return null;170 165 } catch (IOException e) { 171 166 if (canceled) return null; 172 e.printStackTrace();167 Logging.debug(e); 173 168 return null; 174 169 } finally { … … 205 200 try ( 206 201 InputStream in = connection.getInputStream(); 207 OutputStream out = new FileOutputStream(destFile)202 OutputStream out = Files.newOutputStream(destFile.toPath()) 208 203 ) { 209 204 byte[] buffer = new byte[8192]; … … 212 207 } 213 208 } 214 } catch (MalformedURLException e) {215 if (canceled) return;216 e.printStackTrace();217 return;218 209 } catch (IOException e) { 219 210 if (canceled) return; 220 e.printStackTrace();211 Logging.debug(e); 221 212 return; 222 213 } finally { … … 249 240 try { 250 241 File moduleDir = OdPlugin.getInstance().getModulesDirectory(); 251 if (!moduleDir.exists()) { 252 if (!moduleDir.mkdirs()) { 253 Logging.warn(tr("Warning: failed to create module directory ''{0}''. Cannot cache module list from module site ''{1}''.", 254 moduleDir.toString(), site)); 255 } 242 if (!moduleDir.exists() && !moduleDir.mkdirs()) { 243 Logging.warn(tr("Warning: failed to create module directory ''{0}''. Cannot cache module list from module site ''{1}''.", 244 moduleDir.toString(), site)); 256 245 } 257 246 File cacheFile = createSiteCacheFile(moduleDir, site, CacheType.PLUGIN_LIST); 258 247 getProgressMonitor().subTask(tr("Writing module list to local cache ''{0}''", cacheFile.toString())); 259 try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(cacheFile), "utf-8"))) { 248 try (OutputStream fileOutputStream = Files.newOutputStream(cacheFile.toPath()); 249 PrintWriter writer = new PrintWriter(new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8))) { 260 250 writer.write(list); 261 251 } … … 275 265 try { 276 266 getProgressMonitor().subTask(tr("Parsing module list from site ''{0}''", site)); 277 InputStream in = new ByteArrayInputStream(doc.getBytes( "UTF-8"));267 InputStream in = new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8)); 278 268 availableModules.addAll(new ModuleListParser().parse(in)); 279 } catch (UnsupportedEncodingException e) {280 Logging.error(tr("Failed to parse module list document from site ''{0}''. Skipping site. Exception was: {1}", site, e.toString()));281 e.printStackTrace();282 269 } catch (ModuleListParseException e) { 283 270 Logging.error(tr("Failed to parse module list document from site ''{0}''. Skipping site. Exception was: {1}", site, e.toString())); 284 e.printStackTrace();271 Logging.debug(e); 285 272 } 286 273 } … … 296 283 for (String location : ModuleInformation.getModuleLocations()) { 297 284 File[] f = new File(location).listFiles( 298 new FilenameFilter() { 299 @Override 300 public boolean accept(File dir, String name) { 301 return name.matches("^([0-9]+-)?site.*\\.txt$") || 302 name.matches("^([0-9]+-)?site.*-icons\\.zip$"); 303 } 304 } 305 ); 285 (dir, name) -> name.matches("^([0-9]+-)?site.*\\.txt$") || 286 name.matches("^([0-9]+-)?site.*-icons\\.zip$") 287 ); 306 288 if (f != null && f.length > 0) { 307 289 siteCacheFiles.addAll(Arrays.asList(f)); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/util/NamesFrUtils.java
r36072 r36173 5 5 import java.io.IOException; 6 6 import java.io.InputStreamReader; 7 import java.nio.charset.StandardCharsets; 7 8 import java.util.Arrays; 8 9 import java.util.HashMap; 9 10 import java.util.List; 11 import java.util.Locale; 10 12 import java.util.Map; 11 13 … … 21 23 public abstract class NamesFrUtils { 22 24 23 private static Map<String, String> dictionary = initDictionary();24 25 public static finalString checkDictionary(String value) {26 String result = "";25 private static final Map<String, String> dictionary = initDictionary(); 26 27 public static String checkDictionary(String value) { 28 StringBuilder result = new StringBuilder(); 27 29 for (String word : value.split(" ")) { 28 if ( !result.isEmpty()) {29 result += " ";30 if (result.length() != 0) { 31 result.append(' '); 30 32 } 31 result += dictionary.containsKey(word) ? dictionary.get(word) : word;32 } 33 return result ;33 result.append(dictionary.getOrDefault(word, word)); 34 } 35 return result.toString(); 34 36 } 35 37 … … 37 39 Map<String, String> result = new HashMap<>(); 38 40 try (BufferedReader reader = new BufferedReader(new InputStreamReader( 39 SimpleDataSetHandler.class.getResourceAsStream(OdConstants.DICTIONARY_FR), OdConstants.UTF8))) {41 SimpleDataSetHandler.class.getResourceAsStream(OdConstants.DICTIONARY_FR), StandardCharsets.UTF_8))) { 40 42 String line = reader.readLine(); // Skip first line 41 43 Logging.trace(line); … … 50 52 } 51 53 52 public static finalString getStreetLabel(String label) {54 public static String getStreetLabel(String label) { 53 55 if (label == null) { 54 return label;56 return null; 55 57 } else if (label.startsWith("All")) { 56 58 return "Allée"; 57 } else if ( label.equals("Autoroute")) {59 } else if ("Autoroute".equals(label)) { 58 60 return label; 59 61 } else if (label.startsWith("Anc")) { … … 63 65 } else if (label.startsWith("Barr")) { 64 66 return "Barrière"; 65 } else if ( label.equals("Bd") || label.equals("Boulevard")) {67 } else if ("Bd".equals(label) || "Boulevard".equals(label)) { 66 68 return "Boulevard"; 67 69 } else if (label.startsWith("Bret")) { 68 70 return "Bretelle"; 69 } else if ( label.equals("Bre")) {71 } else if ("Bre".equals(label)) { 70 72 return "Bré"; 71 } else if ( label.equals("Caminot")) {72 return label; 73 } else if ( label.equals("Carrefour")) {74 return label; 75 } else if ( label.equals("Carré")) {73 } else if ("Caminot".equals(label)) { 74 return label; 75 } else if ("Carrefour".equals(label)) { 76 return label; 77 } else if ("Carré".equals(label)) { 76 78 return label; 77 79 } else if (label.startsWith("Chemine")) { … … 81 83 } else if (label.startsWith("Cit")) { 82 84 return "Cité"; 83 } else if ( label.equals("Clos")) {84 return label; 85 } else if ( label.equals("Cote") || label.equals("Côte")) {85 } else if ("Clos".equals(label)) { 86 return label; 87 } else if ("Cote".equals(label) || "Côte".equals(label)) { 86 88 return "Côte"; 87 } else if ( label.equals("Cours")) {89 } else if ("Cours".equals(label)) { 88 90 return label; 89 91 } else if (label.startsWith("Dep") || label.startsWith("Dép")) { … … 91 93 } else if (label.startsWith("Dom")) { 92 94 return "Domaine"; 93 } else if ( label.equals("Dsc") || label.startsWith("Desc")) {95 } else if ("Dsc".equals(label) || label.startsWith("Desc")) { 94 96 return "Descente"; 95 } else if ( label.equals("Esp") || label.startsWith("Espl")) {97 } else if ("Esp".equals(label) || label.startsWith("Espl")) { 96 98 return "Esplanade"; 97 99 } else if (label.startsWith("Espa")) { 98 100 return "Espace"; 99 } else if ( label.equals("Giratoire")) {100 return label; 101 } else if ( label.equals("Grande-rue")) {102 return label; 103 } else if ( label.equals("Hameau")) {104 return label; 105 } else if (label.startsWith("Imp") || label.equals("Ipasse")) {101 } else if ("Giratoire".equals(label)) { 102 return label; 103 } else if ("Grande-rue".equals(label)) { 104 return label; 105 } else if ("Hameau".equals(label)) { 106 return label; 107 } else if (label.startsWith("Imp") || "Ipasse".equals(label)) { 106 108 return "Impasse"; 107 109 } else if (label.startsWith("Itin")) { 108 110 return "Itinéraire"; 109 } else if ( label.equals("Jardin")) {110 return label; 111 } else if (label.startsWith("L'") || label.equals("La") || label.equals("Le") || label.equals("Les") ||112 label.equals("Saint")) { // Lieux-dits111 } else if ("Jardin".equals(label)) { 112 return label; 113 } else if (label.startsWith("L'") || "La".equals(label) || "Le".equals(label) || "Les".equals(label) || 114 "Saint".equals(label)) { // Lieux-dits 113 115 return label; 114 116 } else if (label.startsWith("Lot")) { 115 117 return "Lotissement"; 116 } else if ( label.equals("Mail")) {117 return label; 118 } else if ( label.equals("Mas")) {118 } else if ("Mail".equals(label)) { 119 return label; 120 } else if ("Mas".equals(label)) { 119 121 return label; 120 122 } else if (label.startsWith("Nat")) { 121 123 return "Nationale"; 122 } else if ( label.equals("Parc")) {123 return label; 124 } else if ( label.equals("Passerelle")) {124 } else if ("Parc".equals(label)) { 125 return label; 126 } else if ("Passerelle".equals(label)) { 125 127 return label; 126 128 } else if (label.startsWith("Pas")) { 127 129 return "Passage"; 128 } else if ( label.equals("Pch") || label.startsWith("Petit-chem")) {130 } else if ("Pch".equals(label) || label.startsWith("Petit-chem")) { 129 131 return "Petit-chemin"; 130 } else if ( label.equals("Petit") || label.equals("Petite")) {131 return label; 132 } else if ( label.equals("Petite-allée")) {133 return label; 134 } else if ( label.equals("Petite-rue")) {135 return label; 136 } else if ( label.equals("Plan")) {132 } else if ("Petit".equals(label) || "Petite".equals(label)) { 133 return label; 134 } else if ("Petite-allée".equals(label)) { 135 return label; 136 } else if ("Petite-rue".equals(label)) { 137 return label; 138 } else if ("Plan".equals(label)) { 137 139 return label; 138 140 } else if (label.startsWith("Pl")) { 139 141 return "Place"; 140 } else if ( label.equals("Pont")) {141 return label; 142 } else if ( label.equals("Port")) {143 return label; 144 } else if ( label.equals("Porte")) {142 } else if ("Pont".equals(label)) { 143 return label; 144 } else if ("Port".equals(label)) { 145 return label; 146 } else if ("Porte".equals(label)) { 145 147 return label; 146 148 } else if (label.startsWith("Prom")) { 147 149 return "Promenade"; 148 } else if ( label.equals("Prv") || label.startsWith("Parv")) {150 } else if ("Prv".equals(label) || label.startsWith("Parv")) { 149 151 return "Parvis"; 150 152 } else if (label.startsWith("Qu")) { 151 153 return "Quai"; 152 } else if ( label.equals("Rampe")) {154 } else if ("Rampe".equals(label)) { 153 155 return label; 154 156 } else if (label.startsWith("Res") || label.startsWith("Rés")) { 155 157 return "Résidence"; 156 } else if ( label.equals("Rocade")) {157 return label; 158 } else if ( label.equals("Rpt") || label.startsWith("Ron")) {158 } else if ("Rocade".equals(label)) { 159 return label; 160 } else if ("Rpt".equals(label) || label.startsWith("Ron")) { 159 161 return "Rond-Point"; 160 } else if ( label.equals("Rte") || label.equals("Route")) {162 } else if ("Rte".equals(label) || "Route".equals(label)) { 161 163 return "Route"; 162 } else if ( label.equals("Rue") || label.equals("Rued")) {164 } else if ("Rue".equals(label) || "Rued".equals(label)) { 163 165 return "Rue"; 164 } else if ( label.equals("Sentier")) {166 } else if ("Sentier".equals(label)) { 165 167 return label; 166 168 } else if (label.startsWith("Sq")) { 167 169 return "Square"; 168 } else if ( label.equals("Théâtre")) {170 } else if ("Théâtre".equals(label)) { 169 171 return "Théâtre"; 170 172 } else if (label.startsWith("Tra")) { 171 173 return "Traverse"; 172 } else if ( label.equals("Vieux")) {173 return label; 174 } else if ( label.equals("Voie")) {175 return label; 176 } else if ( label.equals("Zone")) {174 } else if ("Vieux".equals(label)) { 175 return label; 176 } else if ("Voie".equals(label)) { 177 return label; 178 } else if ("Zone".equals(label)) { 177 179 return label; 178 180 } else { … … 182 184 } 183 185 184 public static finalString checkStreetName(OsmPrimitive p, String key) {186 public static String checkStreetName(OsmPrimitive p, String key) { 185 187 String value = null; 186 188 if (p != null) { … … 189 191 value = WordUtils.capitalizeFully(value); 190 192 // Cas particuliers 191 if ( value.equals("Boulingrin")) { // square Boulingrin, mal formé193 if ("Boulingrin".equals(value)) { // square Boulingrin, mal formé 192 194 value = "Sq Boulingrin"; 193 195 } else if (value.matches("A[0-9]+")) { // Autoroutes sans le mot "Autoroute" 194 196 value = "Autoroute "+value; 195 } else if ( value.equals("All A61")) { // A61 qualifiée d'Allée ?197 } else if ("All A61".equals(value)) { // A61 qualifiée d'Allée ? 196 198 value = "Autoroute A61"; 197 199 } else if (value.startsWith("Che Vieux Che")) { // "Che" redondant … … 210 212 String[] words = value.split(" "); 211 213 if (words.length > 0) { 212 value = "";214 final StringBuilder stringBuilder = new StringBuilder(); 213 215 List<String> list = Arrays.asList(words); 214 216 words[0] = getStreetLabel(words[0]); 215 if ( words[0].equals("Ancien") && words.length > 1 && words[1].equals("Che")) {217 if ("Ancien".equals(words[0]) && words.length > 1 && "Che".equals(words[1])) { 216 218 words[1] = "Chemin"; 217 219 } 218 220 for (int i = 0; i < words.length; i++) { 219 221 if (i > 0) { 220 value += " ";222 stringBuilder.append(' '); 221 223 // Prénoms/Noms propres abrégés 222 if ( words[i].equals("A") && list.contains("Bernard")) {224 if ("A".equals(words[i]) && list.contains("Bernard")) { 223 225 words[i] = "Arnaud"; 224 } else if ( words[i].equals("A") && list.contains("Passerieu")) {226 } else if ("A".equals(words[i]) && list.contains("Passerieu")) { 225 227 words[i] = "Ariste"; 226 } else if ( words[i].equals("A") && list.contains("Bougainville")) {228 } else if ("A".equals(words[i]) && list.contains("Bougainville")) { 227 229 words[i] = "Antoine"; 228 } else if ( words[i].equals("Ch") && list.contains("Leconte")) {230 } else if ("Ch".equals(words[i]) && list.contains("Leconte")) { 229 231 words[i] = "Charles"; 230 } else if ( words[i].equals("Frs") && list.contains("Dugua")) {232 } else if ("Frs".equals(words[i]) && list.contains("Dugua")) { 231 233 words[i] = "François"; 232 } else if ( words[i].equals("G") && list.contains("Latecoere")) {234 } else if ("G".equals(words[i]) && list.contains("Latecoere")) { 233 235 words[i] = "Georges"; 234 } else if ( words[i].equals("H") && list.contains("Lautrec")) {236 } else if ("H".equals(words[i]) && list.contains("Lautrec")) { 235 237 words[i] = "Henri"; 236 } else if ( words[i].equals("J") && list.contains("Dieulafoy")) {238 } else if ("J".equals(words[i]) && list.contains("Dieulafoy")) { 237 239 words[i] = "Jane"; 238 } else if ( words[i].equals("J") && (list.contains("Champollion") || list.contains("Stanislas"))) {240 } else if ("J".equals(words[i]) && (list.contains("Champollion") || list.contains("Stanislas"))) { 239 241 words[i] = "Jean"; 240 } else if ( words[i].equals("L") && list.contains("Zamenhof")) {242 } else if ("L".equals(words[i]) && list.contains("Zamenhof")) { 241 243 words[i] = "Ludwik"; 242 } else if ( words[i].equals("L") && list.contains("Sacha")) {244 } else if ("L".equals(words[i]) && list.contains("Sacha")) { 243 245 words[i] = "Lucien"; 244 246 if (!list.contains("Et")) { 245 247 words[i] += " et"; 246 248 } 247 } else if ( words[i].equals("L") && (list.contains("Vauquelin") || list.contains("Bougainville"))) {249 } else if ("L".equals(words[i]) && (list.contains("Vauquelin") || list.contains("Bougainville"))) { 248 250 words[i] = "Louis"; 249 } else if ( words[i].equals("M") && list.contains("Dieulafoy")) {251 } else if ("M".equals(words[i]) && list.contains("Dieulafoy")) { 250 252 words[i] = "Marcel"; 251 } else if ( words[i].equals("M") && list.contains("Arifat")) {253 } else if ("M".equals(words[i]) && list.contains("Arifat")) { 252 254 words[i] = "Marie"; 253 } else if ( words[i].equals("N") && list.contains("Djamena")) {255 } else if ("N".equals(words[i]) && list.contains("Djamena")) { 254 256 words[i] = "N'"; 255 } else if ( words[i].equals("Oo")) {257 } else if ("Oo".equals(words[i])) { 256 258 words[i] = "Oô"; 257 } else if ( words[i].equals("Ph") && list.contains("Ravary")) {259 } else if ("Ph".equals(words[i]) && list.contains("Ravary")) { 258 260 words[i] = "Philippe"; 259 } else if ( words[i].equals("R") && list.contains("Folliot")) {261 } else if ("R".equals(words[i]) && list.contains("Folliot")) { 260 262 words[i] = "Raphaël"; 261 } else if ( words[i].equals("W") && list.contains("Booth")) {263 } else if ("W".equals(words[i]) && list.contains("Booth")) { 262 264 words[i] = "William"; 263 265 // Mots de liaison non couverts par le dictionnaire 264 } else if ( words[i].equals("A")) {266 } else if ("A".equals(words[i])) { 265 267 words[i] = "à"; 266 } else if ( words[i].equals("D") || words[i].equals("L")) {267 words[i] = words[i].toLowerCase( )+"'";268 } else if ( words[i].equals("La") || words[i].equals("Le")) {269 words[i] = words[i].toLowerCase( );268 } else if ("D".equals(words[i]) || "L".equals(words[i])) { 269 words[i] = words[i].toLowerCase(Locale.FRENCH)+"'"; 270 } else if ("La".equals(words[i]) || "Le".equals(words[i])) { 271 words[i] = words[i].toLowerCase(Locale.FRENCH); 270 272 } 271 273 } 272 value += words[i];274 stringBuilder.append(words[i]); 273 275 } 276 value = stringBuilder.toString(); 274 277 } 275 278 // Ponctuation -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/util/OdUtils.java
r36072 r36173 3 3 4 4 import java.io.File; 5 import java.io.FilenameFilter;6 5 import java.io.IOException; 7 6 import java.nio.file.Files; … … 24 23 private static final String TEMP_DIR_PREFIX = "josm_opendata_temp_"; 25 24 26 public static finalboolean isMultipolygon(OsmPrimitive p) {27 return p instanceof Relation && ((Relation) p).isMultipolygon();25 public static boolean isMultipolygon(OsmPrimitive p) { 26 return p instanceof Relation && p.isMultipolygon(); 28 27 } 29 28 30 public static finalString[] stripQuotesAndExtraChars(String[] split, String sep) {29 public static String[] stripQuotesAndExtraChars(String[] split, String sep) { 31 30 List<String> result = new ArrayList<>(); 32 31 boolean append = false; … … 37 36 append = false; 38 37 } 39 result.set(index, result.get(index)+sep+split[i].replace All("\"", ""));38 result.set(index, result.get(index)+sep+split[i].replace("\"", "")); 40 39 } else if (split[i].startsWith("\"")) { 41 40 if (!(split[i].endsWith("\"") && StringUtils.countMatches(split[i], "\"") % 2 == 0)) { 42 41 append = true; 43 42 } 44 result.add(split[i].replace All("\"", ""));43 result.add(split[i].replace("\"", "")); 45 44 } else { 46 45 result.add(split[i]); … … 54 53 } 55 54 56 public static finalImageIcon getImageIcon(String iconName) {55 public static ImageIcon getImageIcon(String iconName) { 57 56 return getImageIcon(iconName, false); 58 57 } 59 58 60 public static finalImageIcon getImageIcon(String iconName, boolean optional) {59 public static ImageIcon getImageIcon(String iconName, boolean optional) { 61 60 return getImageProvider(iconName, optional).get(); 62 61 } 63 62 64 public static finalImageProvider getImageProvider(String iconName) {63 public static ImageProvider getImageProvider(String iconName) { 65 64 return getImageProvider(iconName, false); 66 65 } 67 66 68 public static finalImageProvider getImageProvider(String iconName, boolean optional) {67 public static ImageProvider getImageProvider(String iconName, boolean optional) { 69 68 return new ImageProvider(iconName).setOptional(optional); 70 69 } 71 70 72 public static finalString getJosmLanguage() {71 public static String getJosmLanguage() { 73 72 String lang = Config.getPref().get("language"); 74 73 if (lang == null || lang.isEmpty()) { … … 78 77 } 79 78 80 public static finaldouble convertMinuteSecond(double minute, double second) {79 public static double convertMinuteSecond(double minute, double second) { 81 80 return (minute/60.0) + (second/3600.0); 82 81 } 83 82 84 public static finaldouble convertDegreeMinuteSecond(double degree, double minute, double second) {83 public static double convertDegreeMinuteSecond(double degree, double minute, double second) { 85 84 return degree + convertMinuteSecond(minute, second); 86 85 } 87 86 88 public static finalFile createTempDir() throws IOException {87 public static File createTempDir() throws IOException { 89 88 return Files.createTempDirectory(TEMP_DIR_PREFIX).toFile(); 90 89 } 91 90 92 public static finalvoid deleteDir(File dir) {91 public static void deleteDir(File dir) { 93 92 for (File file : dir.listFiles()) { 94 93 if (!file.delete()) { … … 101 100 } 102 101 103 public static finalvoid deletePreviousTempDirs() {102 public static void deletePreviousTempDirs() { 104 103 File tmpDir = new File(System.getProperty("java.io.tmpdir")); 105 104 if (tmpDir.exists() && tmpDir.isDirectory()) { 106 for (File dir : tmpDir.listFiles(new FilenameFilter() { 107 @Override 108 public boolean accept(File dir, String name) { 109 return name.startsWith(TEMP_DIR_PREFIX); 110 } 111 })) { 105 for (File dir : tmpDir.listFiles((dir, name) -> name.startsWith(TEMP_DIR_PREFIX))) { 112 106 deleteDir(dir); 113 107 } -
applications/editors/josm/plugins/opendata/test/unit/org/openstreetmap/josm/plugins/opendata/core/io/geographic/MifReaderTest.java
r36072 r36173 47 47 File file = new File(TestUtils.getRegressionDataFile(9592, "bg.mif")); 48 48 try (InputStream is = new FileInputStream(file)) { 49 NonRegFunctionalTests.testGeneric("#9592", MifReader.parseDataSet(is, file, newHandler("EPSG:32635") , null));49 NonRegFunctionalTests.testGeneric("#9592", MifReader.parseDataSet(is, file, newHandler("EPSG:32635"))); 50 50 } 51 51 }
Note:
See TracChangeset
for help on using the changeset viewer.