
com.adobe.aemds.guide.utils.TableUtils Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2014 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 java.util.Arrays;
import java.util.Iterator;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @pad.exclude Exclude from Published API.
*/
public class TableUtils {
public static final String[] DISALLOWED_PANEL_ELEMENTS_IN_TABLE = { "guidePanel", "guideTable"};
public static final String GUIDE_NODE_CLASS = "guideNodeClass";
public static final String ITEMS = "items";
private static Logger logger = LoggerFactory.getLogger(TableUtils.class);
/**
* Generic utility to find number of columns in a table
*/
public static int getColumnsCount(JSONObject table){
int columnsCount = 0;
try {
JSONObject tableItems = table.getJSONObject(ITEMS);
Iterator itr = tableItems.keys();
JSONObject item = null;
while ( itr.hasNext() ) {
item = tableItems.optJSONObject(itr.next());
if ( item != null && item.has(GUIDE_NODE_CLASS)) {
break;
}
}
JSONObject headerRow = item;
JSONObject headerRowItems = headerRow.getJSONObject(ITEMS);
itr = headerRowItems.keys();
while ( itr.hasNext() ) {
item = headerRowItems.optJSONObject(itr.next());
if ( item != null && item.has(GUIDE_NODE_CLASS)) {
columnsCount++;
}
}
} catch (JSONException e) {
logger.error("JSON exception while finding number of columns in a table", e);
}
return columnsCount;
}
/**
* Generic utility to check whether to convert a repeatable panel in adaptive forms to a table in DoR
*/
public static boolean shouldGenerateDoRTable(JSONObject panel){
try {
JSONObject panelItems = panel.getJSONObject(ITEMS);
Iterator itr = panelItems.keys();
while ( itr.hasNext() ) {
JSONObject item = panelItems.optJSONObject(itr.next());
if ( item != null && Arrays.asList(DISALLOWED_PANEL_ELEMENTS_IN_TABLE).contains(item.optString(GUIDE_NODE_CLASS))) {
logger.warn("Not converting Repeatable panel to Table as it contains a "+item.optString(GUIDE_NODE_CLASS));
return false;
}
}
} catch (JSONException e) {
logger.error("JSON exception while finding whether to convert repeatable panel to Table in DoR", e);
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy