use of com.adobe.granite.ui.clientlibs.HtmlLibrary in project acs-aem-commons by Adobe-Consulting-Services.
the class VersionedClientlibsTransformerFactoryTest method doFilter_foundInCache_md5Match.
@Test
public void doFilter_foundInCache_md5Match() throws Exception {
when(slingRequest.getRequestURI()).thenReturn("/etc/clientlibs/some.min.ACSHASH" + INPUTSTREAM_MD5 + ".js");
factory.getCache().put(new VersionedClientLibraryMd5CacheKey("/etc/clientlibs/some", LibraryType.JS), INPUTSTREAM_MD5);
HtmlLibrary htmlLibrary = mock(HtmlLibrary.class);
when(htmlLibrary.getLibraryPath()).thenReturn("/etc/clientlibs/some");
when(htmlLibraryManager.getLibrary(LibraryType.JS, "/etc/clientlibs/some")).thenReturn(htmlLibrary);
filter.doFilter(slingRequest, slingResponse, filterChain);
verifyNo404();
}
use of com.adobe.granite.ui.clientlibs.HtmlLibrary in project acs-aem-commons by Adobe-Consulting-Services.
the class VersionedClientlibsTransformerFactoryTest method doFilter_foundInCache_md5MisMatch.
@Test
public void doFilter_foundInCache_md5MisMatch() throws Exception {
when(slingRequest.getRequestURI()).thenReturn("/etc/clientlibs/some.min.ACSHASHfoobar.js");
factory.getCache().put(new VersionedClientLibraryMd5CacheKey("/etc/clientlibs/some", LibraryType.JS), INPUTSTREAM_MD5);
HtmlLibrary htmlLibrary = mock(HtmlLibrary.class);
when(htmlLibrary.getLibraryPath()).thenReturn("/etc/clientlibs/some");
when(htmlLibraryManager.getLibrary(LibraryType.JS, "/etc/clientlibs/some")).thenReturn(htmlLibrary);
filter.doFilter(slingRequest, slingResponse, filterChain);
verify404();
}
use of com.adobe.granite.ui.clientlibs.HtmlLibrary in project acs-aem-commons by Adobe-Consulting-Services.
the class VersionedClientlibsTransformerFactoryTest method doFilter_notFoundInCache_md5MisMatch.
@Test
public void doFilter_notFoundInCache_md5MisMatch() throws Exception {
when(slingRequest.getRequestURI()).thenReturn("/etc/clientlibs/some.min.ACSHASHfoobar.js");
HtmlLibrary library = mock(HtmlLibrary.class);
when(library.getInputStream(false)).thenReturn(INPUTSTREAM);
when(library.getLibraryPath()).thenReturn("/etc/clientlibs/some.js");
when(htmlLibraryManager.getLibrary(LibraryType.JS, "/etc/clientlibs/some")).thenReturn(library);
filter.doFilter(slingRequest, slingResponse, filterChain);
verify404();
}
use of com.adobe.granite.ui.clientlibs.HtmlLibrary in project acs-aem-commons by Adobe-Consulting-Services.
the class VersionedClientlibsTransformerFactory method getLibrary.
private HtmlLibrary getLibrary(LibraryType libraryType, String libraryPath, ResourceResolver resourceResolver) {
HtmlLibrary htmlLibrary = null;
if (libraryPath.startsWith(PROXY_PREFIX)) {
final String relativePath = libraryPath.substring(PROXY_PREFIX.length());
for (final String prefix : resourceResolver.getSearchPath()) {
final String absolutePath = prefix + relativePath;
htmlLibrary = htmlLibraryManager.getLibrary(libraryType, absolutePath);
if (htmlLibrary != null) {
break;
}
}
} else {
htmlLibrary = htmlLibraryManager.getLibrary(libraryType, libraryPath);
}
return htmlLibrary;
}
use of com.adobe.granite.ui.clientlibs.HtmlLibrary in project acs-aem-commons by Adobe-Consulting-Services.
the class VersionedClientlibsTransformerFactory method getVersionedPath.
private String getVersionedPath(final String originalPath, final LibraryType libraryType, final ResourceResolver resourceResolver) {
try {
boolean appendMinSelector = false;
String libraryPath = StringUtils.substringBeforeLast(originalPath, ".");
if (libraryPath.endsWith(MIN_SELECTOR_SEGMENT)) {
appendMinSelector = true;
libraryPath = StringUtils.substringBeforeLast(libraryPath, ".");
}
final HtmlLibrary htmlLibrary = getLibrary(libraryType, libraryPath, resourceResolver);
if (htmlLibrary != null) {
StringBuilder builder = new StringBuilder();
builder.append(libraryPath);
builder.append(".");
if (appendMinSelector) {
builder.append(MIN_SELECTOR).append(".");
}
if (enforceMd5) {
builder.append(MD5_PREFIX);
}
builder.append(getMd5(htmlLibrary));
builder.append(libraryType.extension);
return builder.toString();
} else {
log.debug("Could not find HtmlLibrary at path: {}", libraryPath);
return null;
}
} catch (Exception ex) {
// Handle unexpected formats of the original path
log.error("Attempting to get a versioned path for [ {} ] but could not because of: {}", originalPath, ex.getMessage());
return originalPath;
}
}
Aggregations