Search in sources :

Example 11 with ClientLibrary

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

the class ClientLibrariesImpl method getAllClientLibraries.

/**
 * Gets all of the client libraries.
 *
 * @param resourceResolver The resource resolver.
 * @return Set of all client libraries.
 */
@NotNull
private Set<ClientLibrary> getAllClientLibraries(@NotNull final ResourceResolver resourceResolver) {
    Map<String, ClientLibrary> allLibraries = htmlLibraryManager.getLibraries();
    Set<ClientLibrary> clientLibraries = new LinkedHashSet<>();
    for (String resourceType : getAllResourceTypes(resourceResolver)) {
        Resource resource = resourceResolver.getResource(resourceType);
        if (resource != null) {
            clientLibraries.addAll(getClientLibraries(resource, allLibraries));
        }
    }
    return clientLibraries;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ClientLibrary(com.adobe.granite.ui.clientlibs.ClientLibrary) Resource(org.apache.sling.api.resource.Resource) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with ClientLibrary

use of com.adobe.granite.ui.clientlibs.ClientLibrary 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

ClientLibrary (com.adobe.granite.ui.clientlibs.ClientLibrary)12 LibraryType (com.adobe.granite.ui.clientlibs.LibraryType)4 PrintWriter (java.io.PrintWriter)3 HashSet (java.util.HashSet)3 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)3 Resource (org.apache.sling.api.resource.Resource)3 MockHtmlLibraryManager (com.adobe.cq.wcm.core.components.testing.MockHtmlLibraryManager)2 HtmlLibrary (com.adobe.granite.ui.clientlibs.HtmlLibrary)2 HtmlLibraryManager (com.adobe.granite.ui.clientlibs.HtmlLibraryManager)2 JsonWriter (com.google.gson.stream.JsonWriter)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 MockPersistenceStrategy (com.adobe.cq.wcm.core.components.testing.MockPersistenceStrategy)1 InputStream (java.io.InputStream)1 Writer (java.io.Writer)1 LinkedHashSet (java.util.LinkedHashSet)1