diff --git a/plugins/org.locationtech.udig.browser/src/org/locationtech/udig/browser/ExternalCatalogueImportURLDescriptor.java b/plugins/org.locationtech.udig.browser/src/org/locationtech/udig/browser/ExternalCatalogueImportURLDescriptor.java index e9ae52f89..123645827 100644 --- a/plugins/org.locationtech.udig.browser/src/org/locationtech/udig/browser/ExternalCatalogueImportURLDescriptor.java +++ b/plugins/org.locationtech.udig.browser/src/org/locationtech/udig/browser/ExternalCatalogueImportURLDescriptor.java @@ -1,4 +1,4 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004, Refractions Research Inc. * @@ -15,33 +15,37 @@ import org.eclipse.swt.browser.LocationListener; /** - * TODO Purpose of - *
+ * TODO Purpose of this class * - *
* @author mleslie * @since 1.0.0 */ -public class ExternalCatalogueImportURLDescriptor - implements ExternalCatalogueImportDescriptor { +public class ExternalCatalogueImportURLDescriptor implements ExternalCatalogueImportDescriptor { private URL url; + private String description; + private ImageDescriptor descImage; + private ImageDescriptor icon; + private String label; + private String id; + private LocationListener listener; + private String viewName; - + /** - * @param url1 - * + * @param url1 + * */ public ExternalCatalogueImportURLDescriptor(URL url1) { super(); this.url = url1; } - + /** * * @return URL of the catalog @@ -49,11 +53,12 @@ public ExternalCatalogueImportURLDescriptor(URL url1) { public URL getUrl() { return this.url; } - + + @Override public String getID() { return this.id; } - + /** * * @param id @@ -61,11 +66,12 @@ public String getID() { public void setID(String id) { this.id = id; } - + + @Override public String getLabel() { return (this.label == null) ? "" : this.label; //$NON-NLS-1$ } - + /** * * @param label @@ -73,15 +79,18 @@ public String getLabel() { public void setLabel(String label) { this.label = label; } - + + @Override public ImageDescriptor getIcon() { return icon; } + @Override public String getDescription() { return (this.description == null) ? "" : this.description; //$NON-NLS-1$ } + @Override public ImageDescriptor getDescriptionImage() { return this.descImage; } @@ -90,7 +99,7 @@ public ImageDescriptor getDescriptionImage() { * * @param attribute */ - public void setDescription( String attribute ) { + public void setDescription(String attribute) { this.description = attribute; } @@ -98,7 +107,7 @@ public void setDescription( String attribute ) { * * @param descriptor */ - public void setDescriptionImage( ImageDescriptor descriptor ) { + public void setDescriptionImage(ImageDescriptor descriptor) { this.descImage = descriptor; } @@ -106,30 +115,27 @@ public void setDescriptionImage( ImageDescriptor descriptor ) { * * @param descriptor */ - public void setIcon( ImageDescriptor descriptor ) { + public void setIcon(ImageDescriptor descriptor) { this.icon = descriptor; } - + /** * * @param name */ public void setListener(String name) { LocationListener blah = null; - if(name != null) { + if (name != null) { try { - blah = (LocationListener)Class.forName(name).newInstance(); - } catch (InstantiationException e) { - // - } catch (IllegalAccessException e) { - // - } catch (ClassNotFoundException e) { - // + blah = (LocationListener) Class.forName(name).getDeclaredConstructor() + .newInstance(); + } catch (Exception e) { + // do nothing } } this.listener = blah; } - + /** * * @param listener @@ -137,15 +143,17 @@ public void setListener(String name) { public void setListener(LocationListener listener) { this.listener = listener; } - + + @Override public LocationListener getListener() { return this.listener; - } - + } + public void setViewName(String viewName) { this.viewName = viewName; } + @Override public String getViewName() { return this.viewName; } diff --git a/plugins/org.locationtech.udig.browser/src/org/locationtech/udig/browser/ui/BrowserContainerView.java b/plugins/org.locationtech.udig.browser/src/org/locationtech/udig/browser/ui/BrowserContainerView.java index b9cbb0d11..c25818bd3 100644 --- a/plugins/org.locationtech.udig.browser/src/org/locationtech/udig/browser/ui/BrowserContainerView.java +++ b/plugins/org.locationtech.udig.browser/src/org/locationtech/udig/browser/ui/BrowserContainerView.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. * @@ -65,9 +66,6 @@ /** * Provides a tabbed browser view using the native web browser. - *- * - *
* * @author mleslie * @since 1.0.0 @@ -244,21 +242,14 @@ public LocationListener getListener() { if (this.listener == null || this.listener.equals("DEFAULT")) //$NON-NLS-1$ return null; try { - return (LocationListener) Class.forName(this.listener).newInstance(); - } catch (InstantiationException e) { - // - } catch (IllegalAccessException e) { - // - } catch (ClassNotFoundException e) { - // + return (LocationListener) Class.forName(this.listener).getDeclaredConstructor() + .newInstance(); + } catch (Exception e) { + return null; } - return null; } } - /** - * - */ public BrowserContainerView() { super(); } @@ -299,7 +290,7 @@ public void createPartControl(Composite parent) { this.browserData = null; } else { String initialBrowserURL = System.getProperty(BROWSER_INITIAL_URL_PROPERTY, - "http://udig.github.io/data/"); + "http://udig.github.io/data/"); //$NON-NLS-1$ addTab(Messages.BrowserContainerView_tabTitle, initialBrowserURL, (Image) null, getListener()); // $NON-NLS-1$ } diff --git a/plugins/org.locationtech.udig.catalog.wmt/src/org/locationtech/udig/catalog/internal/wmt/wmtsource/WMTSourceFactory.java b/plugins/org.locationtech.udig.catalog.wmt/src/org/locationtech/udig/catalog/internal/wmt/wmtsource/WMTSourceFactory.java index 2eb9faaf6..36f742614 100644 --- a/plugins/org.locationtech.udig.catalog.wmt/src/org/locationtech/udig/catalog/internal/wmt/wmtsource/WMTSourceFactory.java +++ b/plugins/org.locationtech.udig.catalog.wmt/src/org/locationtech/udig/catalog/internal/wmt/wmtsource/WMTSourceFactory.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2010, Refractions Research Inc. * @@ -14,34 +15,33 @@ import org.locationtech.udig.catalog.internal.wmt.WMTService; public class WMTSourceFactory { - - // todo: make every WMTSource class singleton, so that the cache is reused! - public static WMTSource createSource(WMTService service, URL url, - String resourceId) throws Throwable { + + // TODO: make every WMTSource class singleton, so that the cache is reused! + public static WMTSource createSource(WMTService service, URL url, String resourceId) + throws Throwable { WMTSource source; - + String className = getClassFromUrl(url); - source = (WMTSource) Class.forName(className).newInstance(); - + source = (WMTSource) Class.forName(className).getDeclaredConstructor().newInstance(); + source.init(resourceId); source.setWmtService(service); return source; } - + /** - * Strip out the start of the url: - * - * wmt://localhost/wmt/org.locationtech.udig.catalog.internal.wmt.wmtsource.OSMSource - * --> - * org.locationtech.udig.catalog.internal.wmt.wmtsource.OSMSource + * Strip out the start of the URL: + * + * wmt://localhost/wmt/org.locationtech.udig.catalog.internal.wmt.wmtsource.OSMSource --> + * org.locationtech.udig.catalog.internal.wmt.wmtsource.OSMSource * * @param url * @return */ public static String getClassFromUrl(URL url) { String withoutId = url.toString().replace(WMTService.ID, ""); //$NON-NLS-1$ - + int posSlash = withoutId.indexOf("/"); //$NON-NLS-1$ if (posSlash >= 0) { return withoutId.substring(0, posSlash); @@ -49,7 +49,7 @@ public static String getClassFromUrl(URL url) { return withoutId; } } - + /** * Should be used only when testing! * @@ -59,16 +59,16 @@ public static String getClassFromUrl(URL url) { * @param noException * @return */ - public static WMTSource createSource(WMTService service, URL url, - String resourceId, boolean noException) { + public static WMTSource createSource(WMTService service, URL url, String resourceId, + boolean noException) { WMTSource source; - - try{ + + try { source = createSource(service, url, resourceId); } catch (Throwable exc) { source = null; } - + return source; } } diff --git a/plugins/org.locationtech.udig.catalog/src/org/locationtech/udig/catalog/ServiceParameterPersister.java b/plugins/org.locationtech.udig.catalog/src/org/locationtech/udig/catalog/ServiceParameterPersister.java index 8341b48b3..eaf9a5380 100644 --- a/plugins/org.locationtech.udig.catalog/src/org/locationtech/udig/catalog/ServiceParameterPersister.java +++ b/plugins/org.locationtech.udig.catalog/src/org/locationtech/udig/catalog/ServiceParameterPersister.java @@ -1,5 +1,5 @@ /** - * + * */ package org.locationtech.udig.catalog; @@ -20,60 +20,68 @@ import java.util.Map; import java.util.Map.Entry; -import org.locationtech.udig.catalog.IResolve.Status; -import org.locationtech.udig.core.internal.CorePlugin; - import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.preference.IPreferenceStore; +import org.locationtech.udig.catalog.IResolve.Status; +import org.locationtech.udig.core.internal.CorePlugin; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; /** - * Allows IService connection parameters to be stored - * into a preference object - and for restoring Service - * again. + * Allows IService connection parameters to be stored into a preference object - and for restoring + * Service again. *- * IResolves that are not services will be ignored; the default - * implementation of locateService( URL, Map ) will add - * the created services into the provided catalog. + * IResolves that are not services will be ignored; the default implementation of locateService( + * URL, Map ) will add the created services into the provided catalog. *
- * {@link #locateService(URL, Map)} can be overridden to not create and - * add the service to the catalog. + * {@link #locateService(URL, Map)} can be overridden to not create and add the service to the + * catalog. *
+ * * @author Jesse */ public class ServiceParameterPersister { private static final String COLON_ENCODING = "@col@"; + private static final String TYPE_QUALIFIER = "@type@"; //$NON-NLS-1$ + private static final String PROPERTIES_KEY = "_properties"; //$NON-NLS-1$ - + private static final String TITLE_KEY = "title"; //$NON-NLS-1$ + private static final String CHILD_PREFIX = "child_"; //$NON-NLS-1$ - + private static final String VALUE_ID = "value"; //$NON-NLS-1$ + private static final String TYPE_ID = "type"; //$NON-NLS-1$ + private static final String ENCODING = "UTF-8"; //$NON-NLS-1$ protected final ICatalog localCatalog; + protected final IServiceFactory serviceFactory; + /** reference directory to consider when making relative files? */ private File reference; - public ServiceParameterPersister(final ICatalog localCatalog, final IServiceFactory serviceFactory) { + public ServiceParameterPersister(final ICatalog localCatalog, + final IServiceFactory serviceFactory) { this(localCatalog, serviceFactory, null); } - - public ServiceParameterPersister(final ICatalog localCatalog, final IServiceFactory serviceFactory, File reference) { + + public ServiceParameterPersister(final ICatalog localCatalog, + final IServiceFactory serviceFactory, File reference) { this.localCatalog = localCatalog; this.serviceFactory = serviceFactory; - this.reference=reference; + this.reference = reference; } - + /** - * Using the connection parameter information in the preferences node restore the state of the local catalog. + * Using the connection parameter information in the preferences node restore the state of the + * local catalog. ** The format is roughly: - * + * *
* # for each service ID used as child node
* file://example.shp:
@@ -84,7 +92,7 @@ public ServiceParameterPersister(final ICatalog localCatalog, final IServiceFact
* (param key):
* value: (text encoding)
* type: (class name)
- *
+ *
* # service properties are in "_properties"
* _properties:
* _title:
@@ -93,7 +101,7 @@ public ServiceParameterPersister(final ICatalog localCatalog, final IServiceFact
* (property key):
* value: (text encoding)
* type: (class name)
- *
+ *
* # child properties are prefixed with "child_"
* child_file://example.shp#example:
* _title:
@@ -104,51 +112,48 @@ public ServiceParameterPersister(final ICatalog localCatalog, final IServiceFact
* value: (text encoding)
* type: (class name)
*
- *
+ *
* @param node
*/
public void restore(Preferences node) {
try {
SERVICE: for (String id : node.childrenNames()) {
- if( id == null ){
+ if (id == null) {
continue SERVICE;
}
try {
Preferences servicePref = node.node(id);
ID url = decodeID(id);
-
- Map
* This method will decode the string based ENCODING
+ *
* @param id Persisted id string
* @return URL based on provided id string
*/
- private ID decodeID( String encodedId ) {
+ private ID decodeID(String encodedId) {
ID id;
try {
String decodeId = URLDecoder.decode(encodedId, ENCODING);
String[] parts = decodeId.split(TYPE_QUALIFIER);
String qualifier = null;
- if( parts.length==2){
+ if (parts.length == 2) {
qualifier = parts[1];
}
try {
// This line just checks if the string is a valid URL. Do NOT use as parameter to ID
// as the case is often changed and will confuse the property key.
- URL url = new URL(null, parts[0], CorePlugin.RELAXED_HANDLER);
+ URL url = new URL(null, parts[0], CorePlugin.RELAXED_HANDLER);
id = new ID(parts[0], qualifier);
} catch (MalformedURLException e) {
String path = parts[0].replaceAll(COLON_ENCODING, ":");
id = new ID(new File(path), qualifier);
- }
-
+ }
+
} catch (UnsupportedEncodingException e) {
CatalogPlugin.log("Could not code preferences URL", e); //$NON-NLS-1$
throw new RuntimeException(e);
@@ -224,49 +230,52 @@ private ID decodeID( String encodedId ) {
}
/**
- * Create an IService from the provided connection parameters
- * and add them to the provided catalog.
- *
+ * Create an IService from the provided connection parameters and add them to the provided
+ * catalog.
+ *
* @Param targetID In the event of a tie favour the provided targetID
- * @param connectionParameters Used to to ask the ServiceFactory for list of candidates
- * @param resourcePropertyMap
+ * @param connectionParameters Used to to ask the ServiceFactory for list of candidates
+ * @param resourcePropertyMap
*/
- protected void locateService(ID targetID, Map
@@ -516,87 +543,91 @@ public void store(IProgressMonitor monitor, Preferences node,
*
+ * As an example:
+ *
+ *
* value:1
* type:java.lang.Integer
*
+ *
* @param prefs
* @param properties
*/
- private void storeProperties( Preferences prefs,
- Map