use of com.eden.orchid.api.theme.components.OrchidComponent in project Orchid by JavaEden.
the class OrchidContextImpl method getSiteData.
@Override
public Map<String, Object> getSiteData(Object... data) {
Map<String, Object> siteData = new HashMap<>();
Map<String, ?> root = getRoot().toMap();
for (String key : root.keySet()) {
siteData.put(key, root.get(key));
}
if (data != null && data.length > 0) {
if (data[0] instanceof OrchidPage) {
OrchidPage page = (OrchidPage) data[0];
siteData.put("page", page);
if (!EdenUtils.isEmpty(page.getType()) && !page.getType().equalsIgnoreCase("page")) {
siteData.put(page.getType(), page);
}
Map<String, OrchidComponent> pageComponents = page.getComponents();
for (Map.Entry<String, OrchidComponent> componentEntry : pageComponents.entrySet()) {
siteData.put(componentEntry.getKey(), componentEntry.getValue());
}
} else if (data[0] instanceof OrchidComponent) {
OrchidComponent component = (OrchidComponent) data[0];
siteData.put("component", component);
if (!EdenUtils.isEmpty(component.getAlias()) && !component.getAlias().equalsIgnoreCase("component")) {
siteData.put(component.getAlias(), component);
}
} else if (data[0] instanceof JSONObject) {
JSONObject jsonObject = (JSONObject) data[0];
siteData.put("data", jsonObject);
for (String key : jsonObject.keySet()) {
siteData.put(key, jsonObject.get(key));
}
} else if (data[0] instanceof Map) {
Map<String, ?> map = (Map<String, ?>) data[0];
siteData.put("data", map);
for (String key : map.keySet()) {
siteData.put(key, map.get(key));
}
} else if (data[0] instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) data[0];
siteData.put("data", jsonArray);
} else if (data[0] instanceof Collection) {
Collection collection = (Collection) data[0];
siteData.put("data", collection);
}
}
siteData.put("root", root);
siteData.put("theme", getTheme());
siteData.put("index", getIndex());
siteData.put("site", this);
return siteData;
}
Aggregations