Skip to content

Instantly share code, notes, and snippets.

@normanzb
Created June 26, 2015 15:03
Show Gist options
  • Save normanzb/25981d675f404e2d0593 to your computer and use it in GitHub Desktop.
Save normanzb/25981d675f404e2d0593 to your computer and use it in GitHub Desktop.
disaster
<%
if(isValidConfig && (wcmMode != WCMMode.EDIT)) {
String[] mappings = resourceConfig.get("cq:mappings", new String[0]);
String[] isProfile = resourceConfig.get("cq:isprofile", new String[0]);
if ("d".equals(mboxType)) {
mboxType = wcmMode == WCMMode.DISABLED ? "s" : "a";
}
if (framework != null || mappings.length > 0) {
mboxType = "a";
}
%>
<script type="text/javascript">
<% if ("a".equals(mboxType)) { %><%
%>mboxDefine("<%= mboxId %>", "<%= mboxName %>"<%
%><% } else { %><%
%>mboxCreate("<%= mboxName %>"<%
%><% } %><%
//page parameters
for(String key: resourceConfig.keySet() ) {
if(key.indexOf(":") == -1) {
%>,<%
%>"<%= key %> =<%=resourceConfig.get(key, "") %>"<%
}
}
//static parameters
String[] staticparams = resourceConfig.get("cq:staticparams", new String[0]);
Node resNode = currentPage.adaptTo(Node.class);
for(String arr : staticparams) {
JSONArray jsonElem = new JSONArray(arr);
String key = jsonElem.getString(0);
String value = jsonElem.getString(1);
boolean isConstant = true;
if(value.startsWith("./") && resNode != null) {
try {
Property prop = resNode.getProperty(value);
value = getPropertyValue(prop);
}catch(PathNotFoundException e) {}
} else if(value.startsWith("$")) {
isConstant = false;
value = value.substring(1);
}
%>,<%
%>"<%= xssAPI.encodeForJSString(key + "=" + (isConstant ? value : ""))%>"<%= isConstant ? "" : "+eval('" + xssAPI.encodeForJSString(value) + "')" %><%
}
%>);<%
if ("a".equals(mboxType)) {
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment