Search in sources :

Example 11 with HtmlLibrary

use of com.adobe.granite.ui.clientlibs.HtmlLibrary in project acs-aem-commons by Adobe-Consulting-Services.

the class VersionedClientlibsTransformerFactory method getUriInfo.

@Nonnull
UriInfo getUriInfo(@Nullable final String uri, @Nonnull ResourceResolver resourceResolver) {
    if (uri != null) {
        Matcher matcher = FILTER_PATTERN.matcher(uri);
        if (matcher.matches()) {
            final String libraryPath = matcher.group(1);
            final String md5 = matcher.group(2);
            final String extension = matcher.group(3);
            LibraryType libraryType;
            if (LibraryType.CSS.extension.substring(1).equals(extension)) {
                libraryType = LibraryType.CSS;
            } else {
                libraryType = LibraryType.JS;
            }
            final HtmlLibrary htmlLibrary = getLibrary(libraryType, libraryPath, resourceResolver);
            return new UriInfo(libraryPath + "." + extension, md5, libraryType, htmlLibrary);
        }
    }
    return new UriInfo("", "", null, null);
}
Also used : Matcher(java.util.regex.Matcher) LibraryType(com.adobe.granite.ui.clientlibs.LibraryType) HtmlLibrary(com.adobe.granite.ui.clientlibs.HtmlLibrary) Nonnull(javax.annotation.Nonnull)

Example 12 with HtmlLibrary

use of com.adobe.granite.ui.clientlibs.HtmlLibrary in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ClientLibrariesImpl method getInline.

/**
 * Returns a concatenated string of the content of all the client libraries, given a library type.
 *
 * @param libraryType - the type of the library
 *
 * @return The concatenated string of the content of all the client libraries
 */
private String getInline(LibraryType libraryType) {
    Collection<ClientLibrary> clientlibs = htmlLibraryManager.getLibraries(categoriesArray, libraryType, true, false);
    // Iterate through the clientlibs and aggregate their content.
    StringBuilder output = new StringBuilder();
    for (ClientLibrary clientlib : clientlibs) {
        HtmlLibrary htmlLibrary = htmlLibraryManager.getLibrary(libraryType, clientlib.getPath());
        if (htmlLibrary != null) {
            try {
                output.append(IOUtils.toString(htmlLibrary.getInputStream(htmlLibraryManager.isMinifyEnabled()), StandardCharsets.UTF_8));
            } catch (IOException e) {
                LOG.error("Error getting input stream from clientlib with path '{}'.", clientlib.getPath());
            }
        }
    }
    return output.toString();
}
Also used : ClientLibrary(com.adobe.granite.ui.clientlibs.ClientLibrary) IOException(java.io.IOException) HtmlLibrary(com.adobe.granite.ui.clientlibs.HtmlLibrary)

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