Search in sources :

Example 6 with HtmlLibrary

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();
}
Also used : HtmlLibrary(com.adobe.granite.ui.clientlibs.HtmlLibrary) Test(org.junit.Test)

Example 7 with HtmlLibrary

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();
}
Also used : HtmlLibrary(com.adobe.granite.ui.clientlibs.HtmlLibrary) Test(org.junit.Test)

Example 8 with HtmlLibrary

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();
}
Also used : HtmlLibrary(com.adobe.granite.ui.clientlibs.HtmlLibrary) Test(org.junit.Test)

Example 9 with HtmlLibrary

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;
}
Also used : HtmlLibrary(com.adobe.granite.ui.clientlibs.HtmlLibrary)

Example 10 with 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;
    }
}
Also used : HtmlLibrary(com.adobe.granite.ui.clientlibs.HtmlLibrary) ServletException(javax.servlet.ServletException) CacheMBeanException(com.adobe.acs.commons.util.impl.exception.CacheMBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) SAXException(org.xml.sax.SAXException) OpenDataException(javax.management.openmbean.OpenDataException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

HtmlLibrary (com.adobe.granite.ui.clientlibs.HtmlLibrary)12 Test (org.junit.Test)7 IOException (java.io.IOException)3 ClientLibrary (com.adobe.granite.ui.clientlibs.ClientLibrary)2 LibraryType (com.adobe.granite.ui.clientlibs.LibraryType)2 CacheMBeanException (com.adobe.acs.commons.util.impl.exception.CacheMBeanException)1 MockHtmlLibraryManager (com.adobe.cq.wcm.core.components.testing.MockHtmlLibraryManager)1 HtmlLibraryManager (com.adobe.granite.ui.clientlibs.HtmlLibraryManager)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 Matcher (java.util.regex.Matcher)1 Nonnull (javax.annotation.Nonnull)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 OpenDataException (javax.management.openmbean.OpenDataException)1 ServletException (javax.servlet.ServletException)1 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)1 Resource (org.apache.sling.api.resource.Resource)1