@Test public void testResolveFileFromUri() throws Exception { final ServletContext ctx = context.mock(ServletContext.class, "ctx"); final WebAppContextIOProviderImpl io = new WebAppContextIOProviderImpl(); io.setServletContext(ctx); context.checking(new Expectations() {{ allowing(ctx).getRealPath("some/path/to/a/file"); will(returnValue(io.getOsAwarePath("/realpath"))); }}); assertOsSpecificPathMatch(io.getOsAwarePath("/realpath"), io.resolveFileFromUri("some/path/to/a/file", null).getAbsolutePath()); assertOsSpecificPathMatch(io.getOsAwarePath("/realpath"), io.resolveFileFromUri("context: }
@Override public File resolveFileFromUri(final String uri, final Map<String, Object> context) { final String absolutePath; if (uri.startsWith(PROTOCOL1)) { absolutePath = uri.substring(PROTOCOL1.length()); } else if (uri.startsWith(PROTOCOL2)) { absolutePath = uri.substring(PROTOCOL2.length()); } else { absolutePath = uri; } final String ctxPath = servletContext.getRealPath(absolutePath); if (ctxPath == null) { throw new IllegalArgumentException("Specified path cannot be resolved: " + uri); } return new File(getOsAwarePath(ctxPath)); }
WebAppContextIOProviderImpl extends AbstractFileSystemIOProviderImpl implements IOProvider, ServletContextAware { @Override public File resolveFileFromUri(final String uri, final Map<String, Object> context) { final String absolutePath; if (uri.startsWith(PROTOCOL1)) { absolutePath = uri.substring(PROTOCOL1.length()); } else if (uri.startsWith(PROTOCOL2)) { absolutePath = uri.substring(PROTOCOL2.length()); } else { absolutePath = uri; } final String ctxPath = servletContext.getRealPath(absolutePath); if (ctxPath == null) { throw new IllegalArgumentException("Specified path cannot be resolved: " + uri); } return new File(getOsAwarePath(ctxPath)); } }
WebAppContextIOProviderImpl extends AbstractFileSystemIOProviderImpl implements IOProvider, ServletContextAware { @Override public File resolveFileFromUri(final String uri, final Map<String, Object> context) { final String absolutePath; if (uri.startsWith(PROTOCOL1)) { absolutePath = uri.substring(PROTOCOL1.length()); } else if (uri.startsWith(PROTOCOL2)) { absolutePath = uri.substring(PROTOCOL2.length()); } else { absolutePath = uri; } final String ctxPath = servletContext.getRealPath(absolutePath); if (ctxPath == null) { throw new IllegalArgumentException("Specified path cannot be resolved: " + uri); } return new File(getOsAwarePath(ctxPath)); }  }
WebAppContextIOProviderImpl extends AbstractFileSystemIOProviderImpl implements IOProvider, ServletContextAware { @Override public File resolveFileFromUri(final String uri, final Map<String, Object> context) { final String absolutePath; if (uri.startsWith(PROTOCOL1)) { absolutePath = uri.substring(PROTOCOL1.length()); } else if (uri.startsWith(PROTOCOL2)) { absolutePath = uri.substring(PROTOCOL2.length()); } else { absolutePath = uri; } final String ctxPath = servletContext.getRealPath(absolutePath); if (ctxPath == null) { throw new IllegalArgumentException("Specified path cannot be resolved: " + uri); } return new File(getOsAwarePath(ctxPath)); }  @Override File resolveFileFromUri(final String uri, final Map<String, Object> context); @Override boolean supports(final String uri); @Override void setServletContext(final ServletContext servletContext); }
WebAppContextIOProviderImpl extends AbstractFileSystemIOProviderImpl implements IOProvider, ServletContextAware { @Override public File resolveFileFromUri(final String uri, final Map<String, Object> context) { final String absolutePath; if (uri.startsWith(PROTOCOL1)) { absolutePath = uri.substring(PROTOCOL1.length()); } else if (uri.startsWith(PROTOCOL2)) { absolutePath = uri.substring(PROTOCOL2.length()); } else { absolutePath = uri; } final String ctxPath = servletContext.getRealPath(absolutePath); if (ctxPath == null) { throw new IllegalArgumentException("Specified path cannot be resolved: " + uri); } return new File(getOsAwarePath(ctxPath)); }  @Override File resolveFileFromUri(final String uri, final Map<String, Object> context); @Override boolean supports(final String uri); @Override void setServletContext(final ServletContext servletContext);  }