/** * Construct. * * @param name The webjars path to load */ public WebjarsCssResourceReference(final String name) { super(WebjarsCssResourceReference.class, useRecent(name)); this.originalName = name; }
/** * Construct. * * @param name The webjars path to load */ public WebjarsJavaScriptResourceReference(final String name) { super(WebjarsJavaScriptResourceReference.class, useRecent(name)); this.originalName = name; }
/** * Looks for a given path name along the webjars root path * * @param clazz The class requesting the resource stream * @param pathName The filename with possible path * @return The resource stream */ @Override public IResourceStream find(final Class<?> clazz, final String pathName) { IResourceStream stream = null; if (clazz != null && IWebjarsResourceReference.class.isAssignableFrom(clazz)) { String versionnedName = WebjarsVersion.useRecent(pathName); final int pos = versionnedName != null ? versionnedName.lastIndexOf(Helper.PATH_PREFIX) : -1; if (pos > -1) { try { final String webjarsPath = locator.getFullPath(versionnedName.substring(pos)); LOG.debug("webjars path: {}", webjarsPath); stream = newResourceStream(webjarsPath); } catch (Exception e) { LOG.debug("can't locate resource for: {} (actual name {}); {}", pathName, versionnedName, e.getMessage()); } if (stream == null) { LOG.debug("there is no webjars resource for: {} (actual name {})", pathName, versionnedName); } } } return stream; }
@Test public void findFileWithoutVersion() throws ResourceStreamNotFoundException, IOException { WebjarsResourceFinder finder = new WebjarsResourceFinder(WicketWebjars.settings()); IResourceStream stream = finder.find(IWebjarsResourceReference.class, useRecent("/webjars/jquery/current/jquery.min.js")); assertThat(stream, is(not(nullValue()))); assertThat(IOUtils.toString(stream.getInputStream()), startsWith("/*! jQuery v2.2.1")); }