private URI resolve(IResourceLocator locator) throws OseeCoreException { URI toReturn = null; StringBuilder builder = new StringBuilder(); String rawPath = locator.getRawPath(); if (!rawPath.startsWith("file:/")) { builder.append(RESOLVED_PATH); builder.append(rawPath); toReturn = new File(builder.toString()).toURI(); } else { rawPath = rawPath.replaceAll(" ", "%20"); try { toReturn = new URI(rawPath); } catch (URISyntaxException ex) { throw new MalformedLocatorException(ex); } } return toReturn; }
@Test public void testGetLocator() throws OseeCoreException { // Test Protocol not found try { manager.getResourceLocator("dummyProcotol://hello"); Assert.fail("This line should not be executed"); } catch (OseeCoreException ex) { Assert.assertTrue(ex instanceof MalformedLocatorException); } IResourceLocator locator = manager.getResourceLocator("protocol1://one/two/three"); Assert.assertEquals("protocol1", locator.getProtocol()); Assert.assertEquals("protocol1://one/two/three", locator.getRawPath()); locator = manager.getResourceLocator("protocol2://1"); Assert.assertEquals("protocol2", locator.getProtocol()); Assert.assertEquals("protocol2://1", locator.getRawPath()); locator = manager.getResourceLocator("protocol3"); Assert.assertEquals("protocol3", locator.getProtocol()); }
@Override public boolean isValid(IResourceLocator locator) { return locator != null && getSupportedProtocols().contains(locator.getProtocol()); }