-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1199 from justinedelson/issue/dynamic-touchui-cli…
…entlibs implementing dynamic loader for TouchUI JavaScript. fixes #989
- Loading branch information
Showing
13 changed files
with
382 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
bundle/src/main/java/com/adobe/acs/commons/wcm/impl/AbstractDynamicClientLibraryServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* #%L | ||
* ACS AEM Commons Bundle | ||
* %% | ||
* Copyright (C) 2017 Adobe | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
package com.adobe.acs.commons.wcm.impl; | ||
|
||
import com.adobe.granite.ui.clientlibs.ClientLibrary; | ||
import com.adobe.granite.ui.clientlibs.HtmlLibraryManager; | ||
import com.adobe.granite.ui.clientlibs.LibraryType; | ||
import com.google.gson.stream.JsonWriter; | ||
import org.apache.felix.scr.annotations.Activate; | ||
import org.apache.felix.scr.annotations.Property; | ||
import org.apache.felix.scr.annotations.Reference; | ||
import org.apache.felix.scr.annotations.sling.SlingServlet; | ||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.api.SlingHttpServletResponse; | ||
import org.apache.sling.api.resource.ResourceResolver; | ||
import org.apache.sling.api.servlets.SlingSafeMethodsServlet; | ||
import org.apache.sling.commons.osgi.PropertiesUtil; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.servlet.ServletException; | ||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
abstract class AbstractDynamicClientLibraryServlet extends SlingSafeMethodsServlet { | ||
|
||
|
||
private HtmlLibraryManager htmlLibraryManager; | ||
|
||
private String[] categories; | ||
private boolean excludeAll; | ||
|
||
@Override | ||
protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) throws ServletException, IOException { | ||
ResourceResolver resourceResolver = request.getResourceResolver(); | ||
response.setContentType("application/json"); | ||
JsonWriter writer = new JsonWriter(response.getWriter()); | ||
writer.beginObject(); | ||
|
||
writer.name("js"); | ||
writer.beginArray(); | ||
if (!excludeAll) { | ||
Collection<ClientLibrary> libraries = htmlLibraryManager.getLibraries(categories, LibraryType.JS, true, true); | ||
for (ClientLibrary library : libraries) { | ||
writer.value(resourceResolver.map(request, library.getIncludePath(LibraryType.JS, htmlLibraryManager.isMinifyEnabled()))); | ||
} | ||
} | ||
writer.endArray(); | ||
|
||
writer.name("css"); | ||
writer.beginArray(); | ||
if (!excludeAll) { | ||
Collection<ClientLibrary> libraries = htmlLibraryManager.getLibraries(categories, LibraryType.CSS, true, true); | ||
for (ClientLibrary library : libraries) { | ||
writer.value(resourceResolver.map(request, library.getIncludePath(LibraryType.CSS, htmlLibraryManager.isMinifyEnabled()))); | ||
} | ||
} | ||
writer.endArray(); | ||
|
||
writer.endObject(); | ||
} | ||
|
||
protected void activate(String[] categories, boolean excludeAll, HtmlLibraryManager htmlLibraryManager) { | ||
this.categories = categories; | ||
this.excludeAll = excludeAll; | ||
this.htmlLibraryManager = htmlLibraryManager; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
bundle/src/main/java/com/adobe/acs/commons/wcm/impl/DynamicTouchUiClientLibraryServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* #%L | ||
* ACS AEM Commons Bundle | ||
* %% | ||
* Copyright (C) 2017 Adobe | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
package com.adobe.acs.commons.wcm.impl; | ||
|
||
import com.adobe.granite.ui.clientlibs.HtmlLibraryManager; | ||
import org.apache.felix.scr.annotations.Activate; | ||
import org.apache.felix.scr.annotations.Property; | ||
import org.apache.felix.scr.annotations.Reference; | ||
import org.apache.felix.scr.annotations.sling.SlingServlet; | ||
import org.apache.sling.commons.osgi.PropertiesUtil; | ||
|
||
import java.util.Map; | ||
|
||
@SlingServlet(paths = "/bin/acs-commons/dynamic-touchui-clientlibs.json", | ||
label = "ACS AEM Commons - Dynamic Touch UI Client Library Loader", | ||
description = "Allows for dynamic loading of optional Touch UI Client Libraries", | ||
metatype = true) | ||
public class DynamicTouchUiClientLibraryServlet extends AbstractDynamicClientLibraryServlet { | ||
|
||
private static final String CATEGORY_LIMIT = "acs-commons.cq-authoring.add-ons.touchui-limit-parsys"; | ||
private static final String CATEGORY_PLACEHOLDER = "acs-commons.cq-authoring.add-ons.touchui-parsys-placeholder"; | ||
|
||
private static final String[] DEFAULT_CATEGORIES = new String[] { | ||
CATEGORY_LIMIT, | ||
CATEGORY_PLACEHOLDER | ||
}; | ||
|
||
private static final boolean DEFAULT_EXCLUDE_ALL = false; | ||
|
||
@Property(label = "Client Library Categories", description = "Client Library Categories", value = { | ||
CATEGORY_LIMIT, | ||
CATEGORY_PLACEHOLDER | ||
}) | ||
private static final String PROP_CATEGORIES = "categories"; | ||
|
||
@Property(label = "Exclude All", description = "Exclude all client library categories", boolValue = DEFAULT_EXCLUDE_ALL) | ||
private static final String PROP_EXCLUDE_ALL = "exclude.all"; | ||
|
||
@Reference | ||
private HtmlLibraryManager htmlLibraryManager; | ||
|
||
@Activate | ||
protected void activate(Map<String, Object> config) { | ||
super.activate(PropertiesUtil.toStringArray(config.get(PROP_CATEGORIES), DEFAULT_CATEGORIES), | ||
PropertiesUtil.toBoolean(config.get(PROP_EXCLUDE_ALL), DEFAULT_EXCLUDE_ALL), | ||
htmlLibraryManager); | ||
} | ||
} |
Oops, something went wrong.