Instantly share code, notes, and snippets.

What would you like to do?
<%@page session="false" %><%--
Copyright 1997-2008 Day Management AG
Barfuesserplatz 6, 4001 Basel, Switzerland
All Rights Reserved.
This software is the confidential and proprietary information of
Day Management AG, ("Confidential Information"). You shall not
disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement you entered into
with Day.
Tree Activation
Implements the tree activation component.
<%@ page contentType="text/html"
com.adobe.granite.ui.clientlibs.HtmlLibraryManager,,,,," %>
<%@ page import="java.util.*" %>
<%@include file="/libs/foundation/global.jsp" %>
AgentManager agentMgr = sling.getService(AgentManager.class);
I18n i18n = new I18n(slingRequest);
List<String> includeList = new ArrayList<String>();
List<String> excludeList = new ArrayList<String>();
if (properties.containsKey("includeList")) {
includeList = Arrays.asList((String[]) properties.get("includeList"));
if (properties.containsKey("excludeList")) {
excludeList = Arrays.asList((String[]) properties.get("excludeList"));
Map<String, Agent> agents = agentMgr.getAgents();
List<String> agentIdsList = new ArrayList<>();
for(Map.Entry<String, Agent> entry: agents.entrySet()){
Agent agent = entry.getValue();
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<title><%= i18n.get("AEM Replication") %> | <%= i18n.get("Activate Tree") %>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="/libs/cq/ui/resources/cq-ui.js" type="text/javascript"></script>
HtmlLibraryManager htmlMgr = sling.getService(HtmlLibraryManager.class);
if (htmlMgr != null) {
htmlMgr.writeIncludes(slingRequest, out, "cq.widgets");
<style type="text/css">
#treeProgress {
display: block;
background-color: white;
width: 100%;
min-height: 400px;
height: 100%;
border: 1px solid #888888;
overflow: scroll;
overflow-x: auto;
<h1><%= i18n.get("Activate Tree") %>
<form target="treeProgress" action="<%= xssAPI.encodeForHTMLAttr(resource.getPath()) %>.html" method="POST"
<input type="hidden" name="_charset_" value="UTF-8">
<input type="hidden" id="path" name="path" value="/content">
<table class="form">
<td><label for="fakePathField"><%= i18n.get("Start Path") %>:</label></td>
<div id="fakePath">&nbsp;</div>
<small><%= i18n.get("Select location to activate") %>
<td><label for="agent">Agent:</label></td>
<select id="agent" name="agent">
<option selected="all">All</option>
<input id="onlymodified" name="onlymodified" type="checkbox" checked value="true">
<label for="onlymodified"><%= i18n.get("Only Modified") %>
<input id="reactivate" name="reactivate" type="checkbox" value="true">
<label for="reactivate"><%= i18n.get("Only Activated") %>
<input id="ignoredeactivated" name="ignoredeactivated" type="checkbox" checked value="true">
<label for="ignoredeactivated"><%= i18n.get("Ignore Deactivated") %>
<input type="hidden" name="cmd" value="dryrun" id="cmd">
<input type="button" value="<%= i18n.get("Dry Run") %>"
onclick="document.getElementById('cmd').value='dryrun'; document.getElementById('treeProgress_form').submit();">
<input type="button" value="<%= i18n.get("Activate") %>"
onclick="document.getElementById('cmd').value='activate'; document.getElementById('treeProgress_form').submit();">
<iframe name="treeProgress" id="treeProgress">
var includes = new Array();
<% for (int i=0; i<includeList.size(); i++) { %>
includes[<%= i %>] = "<%= xssAPI.encodeForJSString(includeList.get(i)) %>";
<% } %>
var excludes = new Array();
<% for (int i=0; i<excludeList.size(); i++) { %>
excludes[<%= i %>] = "<%= xssAPI.encodeForJSString(excludeList.get(i)) %>";
<% } %>
var select = document.getElementById("agent");
<% for (int i=0; i< agentIdsList.size(); i++) { %>
var option = document.createElement("option");
var id = "<%= xssAPI.encodeForJSString(agentIdsList.get(i)) %>";
option.text = id;
option.value = id;
<% } %>
//use a SlingTreeLoader to replace the default tree loader (that uses ExtTreeServlet to render and doesn't work)
var slingTreeLoader = new CQ.tree.SlingTreeLoader({
typeIncludes: includes,
typeExcludes: excludes,
baseAttrs: {
singleClickExpand: true
// provide a path selector field with a repository browse dialog
CQ.Ext.onReady(function () {
var w = new CQ.form.PathField({
// applyTo: "path",
renderTo: "CQ",
// "content": "/content",
rootPath: "/",
predicate: "hierarchy",
hideTrigger: false,
showTitlesInTree: false,
name: "fakePathField",
value: "/content",
width: 400,
treeLoader: slingTreeLoader,
listeners: {
render: function () {
this.wrap.anchorTo("fakePath", "tl");
change: function (fld, newValue, oldValue) {
document.getElementById("path").value = newValue;
dialogselect: function (fld, newValue) {
document.getElementById("path").value = newValue;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment