use of com.eden.common.json.JSONElement in project Orchid by JavaEden.
the class IndexGenerator method generateIndexFiles.
private void generateIndexFiles() {
OrchidRootInternalIndex internalIndex = context.getInternalIndex();
Map<String, OrchidInternalIndex> mappedIndex = internalIndex.getAllIndexedPages();
OrchidIndex indices = new OrchidInternalIndex("indices");
// Render an page for each generator's individual index
mappedIndex.keySet().forEach(key -> {
OrchidResource resource = new JsonResource(new JSONElement(mappedIndex.get(key).toJSON()), new OrchidReference(context, "meta/" + key + ".index.json"));
OrchidPage page = new OrchidPage(resource);
page.renderRaw();
indices.addToIndex(indices.getOwnKey() + "/" + page.getReference().getPath(), page);
});
// Render full composite index page
OrchidResource compositeIndexResource = new JsonResource(new JSONElement(internalIndex.toJSON()), new OrchidReference(context, "meta/index.json"));
OrchidPage compositeIndexPage = new OrchidPage(compositeIndexResource);
compositeIndexPage.renderRaw();
indices.addToIndex(indices.getOwnKey() + "/" + compositeIndexPage.getReference().getPath(), compositeIndexPage);
// Render an index of all indices, so individual index pages can be found
OrchidResource indicesIndexResource = new JsonResource(new JSONElement(indices.toJSON()), new OrchidReference(context, "meta/indices.json"));
OrchidPage indicesPage = new OrchidPage(indicesIndexResource);
indicesPage.renderRaw();
}
use of com.eden.common.json.JSONElement in project Orchid by JavaEden.
the class DisabledGeneratorsOption method parseOption.
@Override
public JSONElement parseOption(String[] options) {
String[] classNames;
if (options[1].contains(File.pathSeparator)) {
classNames = options[1].split(File.pathSeparator);
} else {
classNames = new String[] { options[1] };
}
JSONArray classNamesArray = new JSONArray();
for (String className : classNames) {
classNamesArray.put(className);
}
if (classNamesArray.length() > 0) {
return new JSONElement(classNamesArray);
} else {
return null;
}
}
use of com.eden.common.json.JSONElement in project Orchid by JavaEden.
the class ThemeOption method parseOption.
@Override
public JSONElement parseOption(String[] options) {
try {
Class<? extends Theme> themeClass = (Class<? extends Theme>) Class.forName(options[1]);
Theme theme = Orchid.getInstance().getInjector().getInstance(themeClass);
if (theme != null) {
Orchid.getInstance().getContext().setTheme(theme);
return new JSONElement(options[1]);
}
} catch (Exception e) {
e.printStackTrace();
}
Clog.e("The Theme class #{$1} could not be found. Please make sure it has been registered properly.", new Object[] { options[1] });
return new JSONElement(options[1]);
}
use of com.eden.common.json.JSONElement in project Orchid by JavaEden.
the class QueryFilter method apply.
public Object apply(Object value, Object... params) {
if (params != null && params[0] != null) {
String pointer = params[0].toString();
if (value instanceof Map) {
JSONObject mapObject = new JSONObject((Map<String, ?>) value);
JSONElement el = new JSONElement(mapObject);
el = el.query(pointer);
if (el != null) {
if (el.getElement() instanceof JSONObject) {
return ((JSONObject) el.getElement()).toMap();
} else if (el.getElement() instanceof JSONArray) {
return ((JSONArray) el.getElement()).toList();
}
}
} else if (value instanceof Collection) {
JSONArray collectionObject = new JSONArray(value);
JSONElement el = new JSONElement(collectionObject).query(pointer);
if (el != null) {
if (el.getElement() instanceof JSONObject) {
return ((JSONObject) el.getElement()).toMap();
} else if (el.getElement() instanceof JSONArray) {
return ((JSONArray) el.getElement()).toList();
}
}
}
}
return null;
}
use of com.eden.common.json.JSONElement in project Orchid by JavaEden.
the class OrchidGenerators method buildExternalIndex.
private void buildExternalIndex() {
this.externalIndex = new OrchidRootExternalIndex();
JSONElement externalIndexReferences = context.query("options.data.externalIndex");
if (OrchidUtils.elementIsArray(externalIndexReferences)) {
JSONArray externalIndex = (JSONArray) externalIndexReferences.getElement();
for (int i = 0; i < externalIndex.length(); i++) {
JSONObject indexJson = this.orchidResources.loadAdditionalFile(externalIndex.getString(i));
if (indexJson != null) {
OrchidIndex index = OrchidIndex.fromJSON(context, indexJson);
this.externalIndex.addChildIndex(index);
}
}
}
}
Aggregations