From 76082512d97cf1c353aac1962d20c6322960fccb Mon Sep 17 00:00:00 2001
From: Sebastian Schulz
Date: Mon, 13 Dec 2021 16:11:10 +0100
Subject: [PATCH] Use 'toURI()' before calling 'toURL()'
---
.../udig/context/internal/URLWizardPage.java | 239 +++++++------
.../udig/project/ui/internal/MapFactory.java | 164 +++++----
.../ui/internal/actions/AddLayerFiles.java | 37 +-
.../project/ui/internal/actions/DropMap.java | 13 +-
.../ui/internal/actions/SLDDropAction.java | 57 +--
.../udig/tool/edit/DifferenceOp.java | 337 ++++++++++--------
.../raster/RasterTutorialHandler.java | 78 ++--
.../udig/tutorials/shpexport/ShpExportOp.java | 127 ++++---
8 files changed, 549 insertions(+), 503 deletions(-)
diff --git a/plugins/org.locationtech.udig.context/src/org/locationtech/udig/context/internal/URLWizardPage.java b/plugins/org.locationtech.udig.context/src/org/locationtech/udig/context/internal/URLWizardPage.java
index d2b0ef2b21..1384ca66e0 100644
--- a/plugins/org.locationtech.udig.context/src/org/locationtech/udig/context/internal/URLWizardPage.java
+++ b/plugins/org.locationtech.udig.context/src/org/locationtech/udig/context/internal/URLWizardPage.java
@@ -1,4 +1,5 @@
-/* uDig - User Friendly Desktop Internet GIS client
+/**
+ * uDig - User Friendly Desktop Internet GIS client
* http://udig.refractions.net
* (C) 2004, Refractions Research Inc.
*
@@ -33,236 +34,238 @@
/**
* The most basic, simple annoying URL prompt you can imagine.
*
- * This import page is similar the eclipse example and was
- * last seen as the ShapefileImportPage in UDIG 0.7. Yes I am
- * that lazy - lazy smart.
+ * This import page is similar the eclipse example and was last seen as the ShapefileImportPage in
+ * UDIG 0.7. Yes I am that lazy - lazy smart.
*
*
- * This time around I am going to try and keep things
- * reusable, so we can use this for Context Documents, SLD
- * files whatever. Also will let us improve the "look" as
- * needed.
+ * This time around I am going to try and keep things reusable, so we can use this for Context
+ * Documents, SLD files whatever. Also will let us improve the "look" as needed.
*
+ *
* The following user-interface elements are used:
*
- *
text - will need to be a URL to proceed.
- * (Valid file syntax will also do...)
- *
browse - button used to bring up a file browser
+ *
text - will need to be a URL to proceed. (Valid file syntax will also do...)
+ *
browse - button used to bring up a file browser
*
*
*
- * In the future - I would really like to hook this into the
- * generic DnD system Jesse is working on for UDIG 1.1.x. In
- * such a use the end of this process would be the URL being
- * "dropped" onto the current selection.
+ * In the future - I would really like to hook this into the generic DnD system Jesse is working on
+ * for UDIG 1.1.x. In such a use the end of this process would be the URL being "dropped" onto the
+ * current selection.
*
- *
+ *
* @author Jody Garnett
* @since 1.0.5
*/
public class URLWizardPage extends WizardPage implements KeyListener {
-
+
protected URL url = null;
+
private Text text;
- private String promptMessage = Messages.URLWizardPage_prompt_initial;
-
+
+ private String promptMessage = Messages.URLWizardPage_prompt_initial;
+
/**
- * Force subclasses to actually cough up the stuff needed for
- * a pretty user interface.
+ * Force subclasses to actually cough up the stuff needed for a pretty user interface.
*
- * As per usual eclipse practice, both the constructor (duh) and
- * init have been called.
+ * As per usual eclipse practice, both the constructor (duh) and init have been called.
*
*/
- public void createControl( Composite parent ) {
- Composite composite = new Composite(parent,SWT.NULL);
+ @Override
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
composite.setLayout(new GridLayout(3, false));
-
- // add url
- Label label = new Label( composite, SWT.NONE );
- label.setText(Messages.URLWizardPage_label_url_text );
- label.setLayoutData( new GridData(SWT.END, SWT.DEFAULT, false, false ) );
- text = new Text( composite, SWT.BORDER );
- text.setLayoutData( new GridData(GridData.FILL_HORIZONTAL) );
- text.setText( "" ); //$NON-NLS-1$
- text.addKeyListener( this );
-
+ // add URL
+ Label label = new Label(composite, SWT.NONE);
+ label.setText(Messages.URLWizardPage_label_url_text);
+ label.setLayoutData(new GridData(SWT.END, SWT.DEFAULT, false, false));
+
+ text = new Text(composite, SWT.BORDER);
+ text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ text.setText(""); //$NON-NLS-1$
+ text.addKeyListener(this);
+
Button button = new Button(composite, SWT.PUSH);
button.setLayoutData(new GridData());
- button.setText(Messages.URLWizardPage_button_browse_text);
- button.addSelectionListener(new SelectionAdapter(){
- public void widgetSelected( SelectionEvent e ) {
+ button.setText(Messages.URLWizardPage_button_browse_text);
+ button.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
Display display = Display.getCurrent();
- if (display == null) { // not on the ui thread?
+ if (display == null) { // not on the UI thread?
display = Display.getDefault();
}
-
+
FileDialog dialog = new FileDialog(display.getActiveShell(), SWT.OPEN);
- //dialog.setFilterExtensions(new String[]{"*.shp"});
- dialog.setText( Messages.URLWizardPage_dialog_text ); // hope for open ?
-
+ dialog.setText(Messages.URLWizardPage_dialog_text); // hope for open ?
+
String open = dialog.open();
- if(open == null){
+ if (open == null) {
// canceled - no change
- }
- else {
- text.setText( open );
- setPageComplete(isPageComplete());
+ } else {
+ text.setText(open);
+ setPageComplete(isPageComplete());
}
}
- });
+ });
setControl(text);
-
-// eclipse ui guidelines say we must start with prompt (not error)
- setMessage( null );
- setPageComplete(true);
+
+ // Eclipse UI guidelines say we must start with prompt (not error)
+ setMessage(null);
+ setPageComplete(true);
}
-
+
/**
- * We cannot assume how far we got in the consturction process.
- * So we have to carefully tear the roof down over our heads and
- * sweep away our footprints.
+ * We cannot assume how far we got in the construction process. So we have to carefully tear the
+ * roof down over our heads and sweep away our footprints.
*/
@Override
public void dispose() {
- if( text != null ){
- text.removeKeyListener( this );
+ if (text != null) {
+ text.removeKeyListener(this);
text.dispose();
text = null;
}
super.dispose();
}
-
- public void keyReleased( KeyEvent e ) {
- if(isPageComplete()){
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if (isPageComplete()) {
setPageComplete(true);
}
}
- public void keyPressed( KeyEvent e ) {
+
+ @Override
+ public void keyPressed(KeyEvent e) {
setPageComplete(false);
}
+
/**
* Default implementation will return true for a valid URL.
*
* Valid URL is based on text containing:
*
- *
URL that parses without exception
- *
Text that can be treated as a File (and thus a URL)
- *
URLs w/ the File protocol the file must exist!
+ *
URL that parses without exception
+ *
Text that can be treated as a File (and thus a URL)
+ *
URLs w/ the File protocol the file must exist!
*
- * Subclasses may override to perform extra sanity checks on
- * the URL (for things like extention, magic, etc...)
+ * Subclasses may override to perform extra sanity checks on the URL (for things like extention,
+ * magic, etc...)
*
- *
+ *
* @see org.eclipse.jface.wizard.IWizardPage#isPageComplete()
* @return true if we have a useful URL
*/
+ @Override
public boolean isPageComplete() {
url = null;
-
+
String txt = text.getText();
- Exception errorMessage = null;
-
- if( txt == null || txt.length() == 0 ){
+ Exception errorMessage = null;
+
+ if (txt == null || txt.length() == 0) {
// not available
- }
- else {
+ } else {
try {
- url = new URL( txt );
- }
- catch( MalformedURLException erp ){
+ url = new URL(txt);
+ } catch (MalformedURLException erp) {
errorMessage = erp;
}
- if( errorMessage != null ){ // try file
+ if (errorMessage != null) { // try file
try {
- File file = new File( txt );
- url = file.toURL();
+ File file = new File(txt);
+ url = file.toURI().toURL();
errorMessage = null;
} catch (MalformedURLException notFile) {
}
}
}
- if( url == null ){
- if( errorMessage != null ){
- setErrorMessage( errorMessage.getLocalizedMessage() );
+ if (url == null) {
+ if (errorMessage != null) {
+ setErrorMessage(errorMessage.getLocalizedMessage());
+ } else {
+ setMessage(""); //$NON-NLS-1$
}
- else {
- setMessage( "" ); //$NON-NLS-1$
- }
- }
- setMessage( Messages.URLWizardPage_prompt_import );
+ }
+ setMessage(Messages.URLWizardPage_prompt_import);
return true;
}
+
/**
- * Called as a quick sanity check on the provided url.
+ * Called as a quick sanity check on the provided URL.
*
- * Note this method is called before checking if the url
- * is a file. You can assume that urlCheck is true if fileCheck
- * is called.
+ * Note this method is called before checking if the URL is a file. You can assume that urlCheck
+ * is true if fileCheck is called.
*
*
- * The default implementation just check that the url is non
- * null. Please override to check for things like
- * the correct extention ...
+ * The default implementation just check that the URL is non null. Please override
+ * to check for things like the correct extention ...
*
- *
+ *
* @param url
- * @return true if url is okay
+ * @return true if URL is okay
*/
- protected boolean urlCheck( URL url ){
+ protected boolean urlCheck(URL url) {
return url != null;
}
-
+
/**
* Used for a quick file check - don't open it!
*
- * Default implementation checks that the file exists, override
- * to check file extention or permissions or something.
+ * Default implementation checks that the file exists, override to check file extention or
+ * permissions or something.
*
*
- * This method is being called on every key press so don't
- * waste your user's time. Save that till they hit Next, that
- * way you get a progress monitor...
+ * This method is being called on every key press so don't waste your user's time. Save that
+ * till they hit Next, that way you get a progress monitor...
*
*
- * Method can call setErrorMessage to report reasonable user
- * level explainations back to the user, default implementation
- * will complain if the file does not exist.
+ * Method can call setErrorMessage to report reasonable user level explanations back to the
+ * user, default implementation will complain if the file does not exist.
*
+ *
* @param file
* @return true if file passes a quick sanity check
*/
- protected boolean fileCheck( File file ){
- if( file.exists() ){
+ protected boolean fileCheck(File file) {
+ if (file.exists()) {
return true;
- }
- //file = file.getAbsoluteFile();
- while( file.getParent() != null && !file.exists() ){
+ }
+ // file = file.getAbsoluteFile();
+ while (file.getParent() != null && !file.exists()) {
file = file.getParentFile();
}
- setErrorMessage( MessageFormat.format(Messages.URLWizardPage_prompt_error_fileNotExist, file.getName()));
-
+ setErrorMessage(MessageFormat.format(Messages.URLWizardPage_prompt_error_fileNotExist,
+ file.getName()));
+
return false;
}
}
diff --git a/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/internal/MapFactory.java b/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/internal/MapFactory.java
index a7a37428ca..51b7f2b5ad 100644
--- a/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/internal/MapFactory.java
+++ b/plugins/org.locationtech.udig.project.ui/src/org/locationtech/udig/project/ui/internal/MapFactory.java
@@ -1,7 +1,7 @@
-/*
- * uDig - User Friendly Desktop Internet GIS client
- * http://udig.refractions.net
- * (C) 2004, Refractions Research Inc.
+/**
+ * uDig - User Friendly Desktop Internet GIS client
+ * http://udig.refractions.net
+ * (C) 2004, Refractions Research Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -61,6 +61,7 @@
*
* @deprecated use {@link ApplicationGIS}
*/
+@Deprecated
public class MapFactory {
/**
@@ -76,9 +77,9 @@ private MapFactory() {
}
/**
- * For each URL in resources, load the services at that location and access
- * their layers. Then add the layers to the current map, or a new one if it doesn't exist. The
- * new map will be created in the current project.
+ * For each URL in resources, load the services at that location and access their
+ * layers. Then add the layers to the current map, or a new one if it doesn't exist. The new map
+ * will be created in the current project.
*
* This is equivalent to calling processURLs(resources, null).
*
@@ -86,13 +87,14 @@ private MapFactory() {
* @param resources a List of URLs pointing to services (WMS, Shapefile, etc)
* @deprecated use {@link ApplicationGIS#createAndOpenMap(List)}
*/
- public void processURLs( List resources ) {
+ @Deprecated
+ public void processURLs(List resources) {
processURLs(resources, null);
}
/**
- * For each URL in resources, load the services at that location and access
- * their layers.
+ * For each URL in resources, load the services at that location and access their
+ * layers.
*
* The layers will then be added to the current map, if it exists, otherwise, a new map will be
* created in the project designated by target.
@@ -103,15 +105,17 @@ public void processURLs( List resources ) {
*
* @param resources a List of URLs pointing to services (WMS, Shapefile, etc)
* @param target Project to use if a new map is going to be created
- * @deprecated use {@link ApplicationGIS#createAndOpenMap(List, org.locationtech.udig.project.IProject)}
+ * @deprecated use
+ * {@link ApplicationGIS#createAndOpenMap(List, org.locationtech.udig.project.IProject)}
*/
- public void processURLs( List resources, Project target ) {
+ @Deprecated
+ public void processURLs(List resources, Project target) {
processURLs(resources, target, false);
}
/**
- * For each URL in resources, load the services at that location and access
- * their layers.
+ * For each URL in resources, load the services at that location and access their
+ * layers.
*
* If newMap is set to true or there is no current map, the layers
* will be added to a new map, contained in the project designated by target, or
@@ -121,10 +125,14 @@ public void processURLs( List resources, Project target ) {
* @param resources a List of URLs pointing to services (WMS, Shapefile, etc)
* @param target Project to use if a new map is going to be created
* @param newMap if true, a new map will be created even if there is one already open
- * @deprecated use {@link ApplicationGIS#addLayersToMap(org.locationtech.udig.project.IProject, List)} or {@link ApplicationGIS#createAndOpenMap(List, org.locationtech.udig.project.IProject)}
+ * @deprecated use
+ * {@link ApplicationGIS#addLayersToMap(org.locationtech.udig.project.IProject, List)}
+ * or
+ * {@link ApplicationGIS#createAndOpenMap(List, org.locationtech.udig.project.IProject)}
*
*/
- public void processURLs( List resources, Project target, boolean newMap ) {
+ @Deprecated
+ public void processURLs(List resources, Project target, boolean newMap) {
process(target, resources, newMap);
}
@@ -141,7 +149,7 @@ public void processURLs( List resources, Project target, boolean newMap ) {
* @param target Project to use if a new map is going to be created
* @param newMap if true, a new map will be created even if there is one already open
*/
- public void processResolves( List resources, Project target, boolean newMap ) {
+ public void processResolves(List resources, Project target, boolean newMap) {
process(target, resources, newMap);
}
@@ -153,22 +161,23 @@ public void processResolves( List resources, Project target, boolean n
* @param resources a List of IResolves
* @param newMap forces a new map to be created
*/
- public void process( final Project target, final List resources, final boolean newMap ) {
+ public void process(final Project target, final List resources, final boolean newMap) {
if (resources == null) {
throw new InvalidParameterException("Parameter 'resources' cannot be null."); //$NON-NLS-1$
}
- Job job = new Job(Messages.ProjectUIPlugin_loadingServices_title){
+ Job job = new Job(Messages.ProjectUIPlugin_loadingServices_title) {
+ @Override
@SuppressWarnings("unchecked")
- protected IStatus run( final IProgressMonitor monitor ) {
+ protected IStatus run(final IProgressMonitor monitor) {
- List exceptions = new ArrayList();
+ List exceptions = new ArrayList<>();
- List services = new ArrayList();
- List geoResources = new ArrayList();
- List layers = new ArrayList();
+ List services = new ArrayList<>();
+ List geoResources = new ArrayList<>();
+ List layers = new ArrayList<>();
- for( Object object : resources ) {
+ for (Object object : resources) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
@@ -178,7 +187,8 @@ protected IStatus run( final IProgressMonitor monitor ) {
services.addAll(handleURL((URL) object, monitor));
} else if (object instanceof File) {
try {
- services.addAll(handleURL(((File) object).toURL(), monitor));
+ services.addAll(
+ handleURL(((File) object).toURI().toURL(), monitor));
} catch (MalformedURLException e) {
// ignore non-URL strings
}
@@ -195,8 +205,8 @@ protected IStatus run( final IProgressMonitor monitor ) {
} else if (object instanceof Layer) {
layers.add((Layer) object);
} else if (object instanceof java.util.Map) {
- services.addAll(CatalogPlugin.getDefault().getServiceFactory().createService(
- (java.util.Map) object));
+ services.addAll(CatalogPlugin.getDefault().getServiceFactory()
+ .createService((java.util.Map) object));
}
} catch (IOException e) {
exceptions.add(e);
@@ -206,11 +216,11 @@ protected IStatus run( final IProgressMonitor monitor ) {
monitor.worked(1);
}
- List unChosenServices = new ArrayList();
+ List unChosenServices = new ArrayList<>();
- for( IResolve resolve : services ) {
- monitor.beginTask(
- Messages.ProjectUIPlugin_loadingServices_task, services.size());
+ for (IResolve resolve : services) {
+ monitor.beginTask(Messages.ProjectUIPlugin_loadingServices_task,
+ services.size());
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
@@ -239,15 +249,18 @@ protected IStatus run( final IProgressMonitor monitor ) {
Map map = new CurrentMapFinder().getCurrentMap();
boolean mapExists = (map != null); // this is used later, and I don't understand
- // what for!
+ // what for!
if (map == null || newMap) {
map = getMap(monitor, target, newMap);
}
- if( map.getBlackboard().get(ProjectBlackboardConstants.MAP__BACKGROUND_COLOR)==null ){
+ if (map.getBlackboard()
+ .get(ProjectBlackboardConstants.MAP__BACKGROUND_COLOR) == null) {
IPreferenceStore store = ProjectPlugin.getPlugin().getPreferenceStore();
- RGB background = PreferenceConverter.getColor(store, PreferenceConstants.P_BACKGROUND);
- map.getBlackboard().put(ProjectBlackboardConstants.MAP__BACKGROUND_COLOR, new Color(background.red, background.green, background.blue ));
+ RGB background = PreferenceConverter.getColor(store,
+ PreferenceConstants.P_BACKGROUND);
+ map.getBlackboard().put(ProjectBlackboardConstants.MAP__BACKGROUND_COLOR,
+ new Color(background.red, background.green, background.blue));
}
if (monitor.isCanceled()) {
@@ -263,7 +276,7 @@ protected IStatus run( final IProgressMonitor monitor ) {
return Status.CANCEL_STATUS;
}
- for( IGeoResource resource : geoResources ) {
+ for (IGeoResource resource : geoResources) {
monitor.beginTask(Messages.MapFactory_retrieveTask, geoResources.size());
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
@@ -283,8 +296,8 @@ protected IStatus run( final IProgressMonitor monitor ) {
}
monitor.worked(1);
}
- if( !layers.isEmpty() )
- map.getLayersInternal().addAll(layers);
+ if (!layers.isEmpty())
+ map.getLayersInternal().addAll(layers);
if (map.getLayersInternal().size() > 0 || newMap == true) {
ProjectExplorer.getProjectExplorer().open(map);
} else if (!mapExists) {
@@ -305,21 +318,23 @@ protected IStatus run( final IProgressMonitor monitor ) {
monitor.done();
return new Status(IStatus.OK, ProjectUIPlugin.ID, IStatus.OK,
- Messages.ProjectUIPlugin_success, null);
+ Messages.ProjectUIPlugin_success, null);
}
};
job.schedule();
}
- private List getResourcesFromUser( List unChosenServices ) {
+ private List getResourcesFromUser(List unChosenServices) {
final ResourceSelectionPage page = new ResourceSelectionPage(
- Messages.ProjectUIPlugin_resourceSelectionPage_title);
+ Messages.ProjectUIPlugin_resourceSelectionPage_title);
page.setResources(unChosenServices, null);
- final List chosenResources = new ArrayList();
+ final List chosenResources = new ArrayList<>();
- PlatformGIS.syncInDisplayThread(new Runnable(){
+ PlatformGIS.syncInDisplayThread(new Runnable() {
+ @Override
public void run() {
- Wizard wizard = new Wizard(){
+ Wizard wizard = new Wizard() {
+ @Override
public void addPages() {
addPage(page);
}
@@ -327,7 +342,7 @@ public void addPages() {
@Override
public boolean performFinish() {
List