
com.adobe.aemds.guide.utils.ExpEditorUtils Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2018 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.aemds.guide.utils;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import java.util.Iterator;
import java.util.Map;
public class ExpEditorUtils {
/**
* Returns events JSONObject having secured eventName and script model
*
* @param scriptsNode jsonNode for events provided thorugh json schema
* @return events JSONObject having secured eventName and script model
* @pad.exclude Exclude from public API.
*/
public static JSONObject getEventsObject (JsonNode scriptsNode) throws JSONException {
String key, eventModel, eventProperty;
JSONArray scriptArray = new JSONArray();
JSONObject eventsObj = new JSONObject();
if (scriptsNode != null) {
Iterator> scriptsIterator = scriptsNode.fields();
while (scriptsIterator.hasNext()) {
Map.Entry script = scriptsIterator.next();
key = script.getKey();
eventModel = getScriptModel(script.getValue().asText(), key);
eventProperty = getEventProperty(key);
scriptArray.put(eventModel);
eventsObj.put(eventProperty, scriptArray);
}
}
return eventsObj;
}
/**
* Return script model from script and eventName
*
* @param script : script provided through json Schema
* @param eventName : event provided through json Schema
* @return scriptModel for the provided script and eventName
* @pad.exclude Exclude from public API.
*/
public static String getScriptModel (String script, String eventName) {
String scriptModel = null;
if(StringUtils.isNotBlank(script) && StringUtils.isNotBlank(eventName)) {
script = StringEscapeUtils.escapeEcmaScript(script);
scriptModel = String.format(GuideConstants.SCRIPT_MODEL, script, eventName);
}
return scriptModel;
}
/**
* Returns secure event name from the map SECURE_EVENT_PROPERTY_MAPPING
*
* @param eventName : provided in the jsonSchema
* @return secure event name from SECURE_EVENT_PROPERTY_MAPPING
* @pad.exclude Exclude from public API.
*/
public static String getEventProperty (String eventName) {
String secureEventProperty = null;
if (StringUtils.isNotBlank(eventName)) {
secureEventProperty = GuideConstants.SECURE_EVENT_PROPERTY_MAPPING.get(eventName);
}
return secureEventProperty;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy