diff options
| author | Curtis Windatt | 2012-11-08 17:52:14 +0000 |
|---|---|---|
| committer | Curtis Windatt | 2012-11-08 17:53:29 +0000 |
| commit | 637ebae68b9a222c33ab9ff4054fb2d3d76ea4f5 (patch) | |
| tree | ed6cd183c4612bab85402098b54c649312ec779c | |
| parent | c781390b7c3243e8726fcb4318236d3c6b5dd8d3 (diff) | |
| download | eclipse.pde.ui-637ebae68b9a222c33ab9ff4054fb2d3d76ea4f5.tar.gz eclipse.pde.ui-637ebae68b9a222c33ab9ff4054fb2d3d76ea4f5.tar.xz eclipse.pde.ui-637ebae68b9a222c33ab9ff4054fb2d3d76ea4f5.zip | |
Bug 393797 - Extension point schema editor opens as read-only from
plugin.xml editor
3 files changed, 85 insertions, 65 deletions
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/SourceLocationManager.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/SourceLocationManager.java index d0d25e41f0..c238af36fd 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/SourceLocationManager.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/SourceLocationManager.java @@ -11,8 +11,7 @@ package org.eclipse.pde.internal.core; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.*; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.spi.RegistryContributor; @@ -65,7 +64,7 @@ public class SourceLocationManager implements ICoreConstants { /** * Searches source locations providing source for the given plugin and then searches - * that location for the file specified by the filePath argument. A URL to this location + * that location for the file specified by the filePath argument. An unencoded URL to this location * will be returned or <code>null</code> if the file could not be found. Note that the * URL may specify a file that is inside of a jar file. * @@ -83,9 +82,14 @@ public class SourceLocationManager implements ICoreConstants { result = searchBundleManifestLocations(pluginBase); if (result != null) { try { - return new URL("jar:" + result.toFile().toURI().toURL() + "!/" + filePath.toString()); //$NON-NLS-1$ //$NON-NLS-2$ + // We use URIs to create the combined jar/path url, but URIs encode special characters + URI encodedUri = URIUtil.toURI(result.toFile().toURL()); + URI jarUri = URIUtil.toJarURI(encodedUri, filePath); + return new URL(URIUtil.toUnencodedString(jarUri)); } catch (MalformedURLException e) { PDECore.log(e); + } catch (URISyntaxException e) { + PDECore.log(e); } } result = searchExtensionLocations(relativePath); diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/SchemaUtil.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/SchemaUtil.java index 8771364a13..8135692651 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/SchemaUtil.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/SchemaUtil.java @@ -16,6 +16,7 @@ import java.io.InputStream; import java.net.*; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; +import org.eclipse.core.runtime.URIUtil; import org.eclipse.pde.internal.core.PDECore; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -38,18 +39,28 @@ public class SchemaUtil { * * @param url URL to open connection to * @return the url connection - * @throws MalformedURLException if the url is null + * @throws MalformedURLException if the url is null or malformed * @throws IOException if there is a problem accessing the resource specified by the url */ public static URLConnection getURLConnection(URL url) throws MalformedURLException, IOException { if (url == null) { throw new MalformedURLException("URL specified is null"); //$NON-NLS-1$ } - URLConnection connection = url.openConnection(); - if (connection instanceof JarURLConnection) { - connection.setUseCaches(false); + // Encode the url to handle special characters by making it a URI + URI uri; + try { + uri = URIUtil.toURI(url); + URL encodedUrl = URIUtil.toURL(uri); + + URLConnection connection = encodedUrl.openConnection(); + if (connection instanceof JarURLConnection) { + connection.setUseCaches(false); + } + return connection; + + } catch (URISyntaxException e) { + throw new MalformedURLException("Unable to encode schema url: " + url); //$NON-NLS-1$ } - return connection; } public static void parseURL(URL url, DefaultHandler handler) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/actions/OpenSchemaAction.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/actions/OpenSchemaAction.java index 58fe4f1deb..26dee04759 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/actions/OpenSchemaAction.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/actions/OpenSchemaAction.java @@ -14,7 +14,7 @@ package org.eclipse.pde.internal.ui.editor.actions; import java.io.File; import java.net.*; import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.*; import org.eclipse.jface.action.Action; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.osgi.util.NLS; @@ -30,7 +30,7 @@ import org.eclipse.pde.internal.ui.editor.schema.SchemaEditor; /** * OpenSchemaAction - * + * */ public class OpenSchemaAction extends Action { @@ -172,89 +172,94 @@ public class OpenSchemaAction extends Action { displayErrorDialog(); return; } - // Retrieve the schema URL + + // Get unencoded schema url URL schemaURL = fSchema.getURL(); - // Ensure the URL is defined if (schemaURL == null) { displayErrorDialog(); return; } - // Get the raw URL, determine if it is stored in a JAR, and handle - // accordingly - String rawURL = schemaURL.toString(); - String path = null; - try { - path = schemaURL.toURI().getPath(); - } catch (URISyntaxException e) { - } - if (path != null) { - if (rawURL.startsWith("jar")) { //$NON-NLS-1$ - // Call to getPath removes the 'jar:' qualifier - openSchemaJar(path); - } else { - openSchemaFile(path); - } + + // Check if we are dealing with a jarred bundle + if (schemaURL.getProtocol().startsWith("jar")) { //$NON-NLS-1$ + openSchemaJar(schemaURL); } else { - displayErrorDialog(); + openSchemaFile(schemaURL); } - } /** * @param path */ - private void openSchemaFile(String path) { - // Open the schema in a new editor + private void openSchemaFile(URL url) { try { - // see if schema URL is actually in workspace. If so, open it as we would if users opened file directly + // Convert url to an encoded URI, then try to get a local file out of it + URI uri = URIUtil.toURI(url); + File schemaFile = URIUtil.toFile(uri); + if (schemaFile == null || !schemaFile.exists()) { + displayErrorDialog(); + return; + } + + // See if the file is actually in the workspace so we can open the editable version + IPath schemaPath = new Path(schemaFile.getPath()); IWorkspaceRoot root = PDEPlugin.getWorkspace().getRoot(); IPath workspacePath = root.getLocation(); - String workspaceLoc = workspacePath.toFile().toURL().getPath(); - if (path.startsWith(workspaceLoc)) { - String relativeLocation = path.substring(workspaceLoc.length()); - IResource res = root.findMember(relativeLocation); + if (workspacePath.isPrefixOf(schemaPath)) { + schemaPath = schemaPath.removeFirstSegments(workspacePath.segmentCount()); + IResource res = root.findMember(schemaPath); if (res != null && res instanceof IFile && res.getProject().isOpen()) { SchemaEditor.openSchema((IFile) res); return; } } - } catch (MalformedURLException e) { - } - if (!SchemaEditor.openSchema(new File(path))) + + // Not in the workspace, open as absolute path + SchemaEditor.openSchema(schemaFile); + + } catch (URISyntaxException e) { + PDEPlugin.log(e); displayErrorDialog(); + } } /** * @param path */ - private void openSchemaJar(String path) { - // Remove the 'file:' qualifier - if (path.startsWith("file:") == false) { //$NON-NLS-1$ + private void openSchemaJar(URL url) { + try { + // The url is unencoded, so we can treat it like a path, splitting it based on the jar suffix '!' + String stringUrl = url.getPath(); + int jarSuffix = stringUrl.indexOf('!'); + if ((jarSuffix <= 0) || ((jarSuffix + 1) >= stringUrl.length())) { + displayErrorDialog(); + return; + } + + String fileUrl = stringUrl.substring(0, jarSuffix); + URI uri = URIUtil.toURI(new URL(fileUrl)); + File jarFile = URIUtil.toFile(uri); + if (jarFile == null || !jarFile.exists()) { + displayErrorDialog(); + return; + } + + String schemaEntryName = stringUrl.substring(jarSuffix + 1); + if (schemaEntryName.startsWith("/")) { //$NON-NLS-1$ + schemaEntryName = schemaEntryName.substring(1); + } + + // Open the schema in a new editor + if (!SchemaEditor.openSchema(jarFile, schemaEntryName)) { + displayErrorDialog(); + } + } catch (URISyntaxException e) { + PDEPlugin.log(e); displayErrorDialog(); - return; - } - path = path.substring(5); - // An exclaimation point separates the jar filename from the - // schema file entry in the jar file - // Get the index of the '!' - int exclPointIndex = path.indexOf('!'); - // Ensure there is an '!' and that the schema file entry is defined - // and the jar file name is defined - if ((exclPointIndex <= 0) || ((exclPointIndex + 1) >= path.length())) { + } catch (MalformedURLException e) { + PDEPlugin.log(e); displayErrorDialog(); - return; } - // Extract the jar file name - not including '!' - String jarFileName = path.substring(0, exclPointIndex); - // Extract the schema entry name - not including the '!' - String schemaEntryName = path.substring(exclPointIndex + 1); - // If the schema entry starts with a '/', remove it - if (schemaEntryName.startsWith("/")) { //$NON-NLS-1$ - schemaEntryName = schemaEntryName.substring(1); - } - // Open the schema in a new editor - if (!SchemaEditor.openSchema(new File(jarFileName), schemaEntryName)) - displayErrorDialog(); } } |
